Re: C function accepting/returning cstring vs. text

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: C function accepting/returning cstring vs. text
Date: 2010-01-27 13:14:36
Message-ID: 20100127141436.3fb33633@dawn.webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 25 Jan 2010 16:36:46 -0600
"Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov> wrote:

> Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it> wrote:
>
> The README files might be a good place to start, then browse code.

Is there a book?

The more I read the source and the few info about it, the more I
have questions that should have been answered by documenting the
function or data structure in spite of looking for some code that
use it and see if I can infer what is expecting, what should be the
best context to use it in, if there are better candidates to do the
same thing etc...

> > - example of returning text (especially if size of out>in)
> > - what should I take care of for encoding (what's really inside a
> > tsvector, text, cstring)?

> src/backend/utils/fmgr/README

I just learned there is a "return all row" mode for returning set
functions:
"
There are currently two modes in which a function can return a set
result: value-per-call, or materialize. In value-per-call mode, the
function returns one value each time it is called, and finally
reports "done" when it has no more values to return. In materialize
mode, the function's output set is instantiated in a Tuplestore
object; all the values are returned in one call. Additional modes
might be added in future.
"

There is no example of a function working in this mode.
I'd guess it should be suited for quick operation and small return.
But... what should be considered quick and small?
When someone should use a "row at a time" function and a "return all
row" function?

I haven't been able to understand the difference between function
returning cstring and text and if there is any need to be careful
about encoding and escaping when copying from the lexeme to a buffer
that will return a cstring or text.

Is there any difference from function returning text and function
returning cstring?

Can I make direct changes to input parameters and return pointers to
internal parts of these structures?
Or should I always allocate my char*, make the modification there
and then return my "copy"?

Is there any operation that should take care of encoding when
dealing with cstring or text?

thanks

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thom Brown 2010-01-27 13:17:28 Re: Patch: psql \whoami option
Previous Message Thom Brown 2010-01-27 13:14:04 Re: Patch: psql \whoami option