From: | Gregory Stark <stark(at)enterprisedb(dot)com> |
---|---|
To: | <jason(at)mbi(dot)ucla(dot)edu> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: interaction with postgres defined types in custom c functions |
Date: | 2007-07-17 10:14:14 |
Message-ID: | 87bqebcp6x.fsf@oxford.xeocode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Jason Nerothin" <jasonnerothin(at)gmail(dot)com> writes:
> PG_FUNCTION_INFO_V1(par);
> Datum par(PG_FUNCTION_ARGS) // pete and repeat! takes text struct pointer
> {
> text *t = PG_GETARG_TEXT_P(0);
> text *new_t = (text*) palloc(VARSIZE(t));
> VARATT_SIZEP(new_t) = VARSIZE(t);
> memcpy((void*) VARDATA(new_t),(void*)VARDATA(t),VARSIZE(t) - VARHDRSZ);
> char *ptr = (char*) VARDATA(new_t);
> *ptr = 'Q'; // NO EFFECT
> PG_RETURN_TEXT(new_t);
> }
That looks correct to me (well aside from it being an error to define ptr in
the middle of a block in C and replacing the first character with Q will be
wrong if the string is 0-bytes or the first byte is a multibyte character).
> The "no effect" comment applies to trying to rewrite to the same memory,
> write from some static type I define, etc, etc.
I think you've simplified away the mistake in your code. Have you actually
tried the above code? Send an actual example and describe what actually
happens.
The only thing I wonder about is whether you're compiling with optimizations
and without -fno-strict-aliasing which may be necessary for Postgres's code
style to compile correctly. What compiler are you compiling with?
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2007-07-17 10:14:19 | Re: ERROR: a column definition list is required for functions returning "record" |
Previous Message | Zlatko Matić | 2007-07-17 09:56:52 | ERROR: a column definition list is required for functions returning "record" |