Re: Exception Handling in C-Language Functions?

From: greg landrum <greg(dot)landrum(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Exception Handling in C-Language Functions?
Date: 2005-05-23 15:22:43
Message-ID: d6ssfv$7lp$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
> "Felix E. Klee" <felix(dot)klee(at)inka(dot)de> writes:
>
> BTW, a more future-proof way of doing what you want:
>
>
>> VarChar *text = PG_GETARG_VARCHAR_P(0);
>> int text_len = VARSIZE(text)-VARHDRSZ;
>> char *tmp_text = (char *)malloc(text_len+1);
>> if (tmp_text == NULL)
>> ; /* What now? */
>> strncpy(tmp_text, VARDATA(text), text_len);
>> tmp_text[text_len] = '\0';
>
>
> is to let the varchar output routine do it:
>
> Datum text_datum = PG_GETARG_DATUM(0);
> char *text;
>
> text = DatumGetCString(DirectFunctionCall1(varcharout, text_datum));
>
> This avoids assuming that you know the internal representation of
> varchar (and if you think that's frozen for eternity, you haven't
> been reading the discussions of ramping up our locale support...)

This form of dealing with arguments is interesting to learn about. Is
there any documentation of this stuff or do I need to dive into the source?

-greg

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-05-23 15:39:21 Re: How to recover from : "Cache lookup failed for rela tion "
Previous Message Douglas McNaught 2005-05-23 15:16:35 Re: C++-Language Function/Process List