> 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.Boekhold@et.tudelft.nl |
-----------------------------------------------------------------------------