Re: C Extension woes

From: Tim Hawes <thawes(at)novadine(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: C Extension woes
Date: 2008-08-13 14:39:29
Message-ID: 48A2F221.4090307@novadine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thank you for your replies, however, it still is not working, see below...

Andrew Chernow wrote:
> Tim Hawes wrote:
>>
>> text * pl_masterkey(PG_FUNCTION_ARGS)
>> {
>> char *e_var = getenv("PGMASTERKEY");
>> size_t length = VARSIZE(e_var) - VARHDRSZ;
>>
>>
>
> The VARSIZE macro is for variable length structures, like a text or
> bytea which contains a length and data member. You are using this
> macro on a regular C string "e_var". Try this instead:
>
> size_t length = e_var != NULL ? strlen(e_var) : 0;
>
@Jan:
It appears the cstring_to_text function is unique to the latest
PostgreSQL code. I do not have a def for that for PostgreSQL 8.2, and
currently I am stuck working with that version. I changed the return
value to Datum, and I had previously only copied from the examples at:
http://www.postgresql.org/docs/8.2/interactive/xfunc-c.html

@Andrew:
here is my new code:
Datum pl_masterkey(PG_FUNCTION_ARGS)
{
char *e_var = getenv("PGMASTERKEY");
size_t length = e_var != NULL ? strlen(e_var) : 0;

text * mkey = (text *) palloc(length);
VARATT_SIZEP(mkey) = length;
memcpy(VARDATA(mkey), e_var, length);

PG_RETURN_TEXT_P(mkey);
}
now gets:
select pl_masterkey();
ERROR: invalid memory alloc request size 4294967293

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2008-08-13 15:03:19 Re: Uncopied parameters on CREATE TABLE LIKE
Previous Message Michael Nacos 2008-08-13 14:38:05 Re: Overhauling GUCS