Re: [HACKERS] How do I construct a varlena?
От | Maarten Boekhold |
---|---|
Тема | Re: [HACKERS] How do I construct a varlena? |
Дата | |
Msg-id | Pine.SUN.3.91.980810091309.16261B-100000@dutepp2.et.tudelft.nl обсуждение исходный текст |
Ответ на | Re: [HACKERS] How do I construct a varlena? ("Oliver Elphick" <olly@lfix.co.uk>) |
Список | 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.Boekhold@et.tudelft.nl | -----------------------------------------------------------------------------
В списке pgsql-hackers по дате отправления: