Re: C-Function: Returning Rows - Mailing list pgsql-novice

From Tom Lane
Subject Re: C-Function: Returning Rows
Date
Msg-id 11969.1273509896@sss.pgh.pa.us
Whole thread Raw
In response to Re: C-Function: Returning Rows  (Carel Combrink <s25291930@tuks.co.za>)
Responses Re: C-Function: Returning Rows  (Carel Combrink <s25291930@tuks.co.za>)
List pgsql-novice
Carel Combrink <s25291930@tuks.co.za> writes:
> I've added a line to initialize the values like follow:
>     malloc(pNulls, false, iTup_Length * sizeof(bool));
> and it works perfectly each time.

malloc?  malloc doesn't guarantee to deliver pre-zeroed storage, though
it might happen to look like that if you don't test very thoroughly.
You've likely also got a problem with leaking the storage, unless you
remember to free it explicitly.  Personally I'd have used palloc0.

> I noted, if using fixed-length nulls array I should set the array to
> false also otherwise the same is experienced. Is this supposed to
> happen this way? Is there documentation on this, I tried googling the
> function with no success?

As a general rule, passing an uninitialized input parameter to a
function isn't a good thing ;-).  I can't say how helpful google
might be, but there are certainly plenty of examples of using
heap_form_tuple in the PG source code.

            regards, tom lane

pgsql-novice by date:

Previous
From: Carel Combrink
Date:
Subject: Re: C-Function: Returning Rows
Next
From: Carel Combrink
Date:
Subject: Re: C-Function: Returning Rows