Re: [HACKERS] How do I construct a varlena?

From: Maarten Boekhold <maartenb(at)dutepp2(dot)et(dot)tudelft(dot)nl>
To: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
Cc: M(dot)Boekhold(at)ITS(dot)TUDelft(dot)NL, hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] How do I construct a varlena?
Date: 1998-08-10 07:20:17
Message-ID: Pine.SUN.3.91.980810091309.16261B-100000@dutepp2.et.tudelft.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> My problem is in how to get the compiler to treat the malloced space as
> a varlena.
>
> I have this (abridged) C code, to be used with
> CREATE FUNCTION cname(bpchar, bpchar, bpchar) returns bpchar ...:
>
>
> char *cxname;
>
> text cname (text s, text t, text f)
> {
> text *result;
> ...
> cxname = realloc((void *) cxname, strlen(tmp)+sizeof(struct varlena));
> strcpy(cxname+sizeof(int32), tmp);
> -> result = &((struct varlena) cxname);
> result->vl_len = strlen(tmp);
>
> return *result;
> }
>
> but the compiler gives the error `conversion to non-scalar type requested'
> at the marked line.

I gues something like this should work:

struct varlena *cxname

cxname = (struct varlena *)
realloc(cxname, strlen(tmp) + VARHDRSZ);
strcpy(cxname->vl_dat, tmp); /* maybe '&cxname->vl_dat' */
return cxname;

I don't think it's possible to 'return *cxname', cos the compiler will
only return the part of your data.

Most of this is from head, so check on things if they don't work immediately.

Maarten

_____________________________________________________________________________
| TU Delft, The Netherlands, Faculty of Information Technology and Systems |
| Department of Electrical Engineering |
| Computer Architecture and Digital Technique section |
| M(dot)Boekhold(at)et(dot)tudelft(dot)nl |
-----------------------------------------------------------------------------

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1998-08-10 13:55:08 Re: [HACKERS] Re: type coersion (was OR clause status)
Previous Message Bruce Momjian 1998-08-10 05:09:10 Re: [HACKERS] Re: type coersion (was OR clause status)