[HACKERS] C Extension woes

2008-08-13 Thread Tim Hawes
Hello all, I am trying to write an extension in C that returns a simple environment variable. The code compiles without any complaint or warning, and it loads fine into the database, however, when I run the function, I get disconnected from the server. Here is my C code: #include

Re: [HACKERS] C Extension woes

2008-08-13 Thread Jan Urbański
Tim Hawes wrote: Hello all, I am trying to write an extension in C that returns a simple environment variable. The code compiles without any complaint or warning, and it loads fine into the database, however, when I run the function, I get disconnected from the server. Here is my C code:

Re: [HACKERS] C Extension woes

2008-08-13 Thread Andrew Chernow
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

Re: [HACKERS] C Extension woes

2008-08-13 Thread Tom Lane
Andrew Chernow [EMAIL PROTECTED] writes: Tim Hawes wrote: 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

Re: [HACKERS] C Extension woes

2008-08-13 Thread Tim Hawes
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,

Re: [HACKERS] C Extension woes

2008-08-13 Thread Jan Urbański
Tim Hawes wrote: @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 Oh, I'm sorry, I forgot about that. cstring_to_text has been added only recently (it's not even it 8.3, silly me). Datum

Re: [HACKERS] C Extension woes

2008-08-13 Thread Tim Hawes
Ok, that worked! Thank you very much, Jan and others who gave their input. I did see Tom's input for the VARHDRSZ and tried that, but forgot to add that again when I called VARATT_SIZEP Jan Urbański wrote: Tim Hawes wrote: @Jan: It appears the cstring_to_text function is unique to the