Re: Exception Handling in C-Language Functions? - Mailing list pgsql-general

From greg landrum
Subject Re: Exception Handling in C-Language Functions?
Date
Msg-id d6ssfv$7lp$1@news.hub.org
Whole thread Raw
In response to Re: Exception Handling in C-Language Functions?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Exception Handling in C-Language Functions?
List pgsql-general
Tom Lane wrote:
> "Felix E. Klee" <felix.klee@inka.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

pgsql-general by date:

Previous
From: Patrick.FICHE@AQSACOM.COM
Date:
Subject: Re: How to recover from : "Cache lookup failed for rela
Next
From: Douglas McNaught
Date:
Subject: Re: C++-Language Function/Process List