The second problem is now solved !
> Second problem:
> When I try to give the output table, only the first line is correctly
> returned.
> I have introduced an analyse stage which reveals that the problem comes from
> the loss of the information in my matrix data structure when the function is
> called for the second time.
>
> My matrix data structure is the following :
>
> typedef struct puissance_matrix
> {
> int nl; //number of lines
> int nc; //number of columns
> int** data; //2D integer data
> } puissance_m;
>
> I use palloc to allocate space to the element called data.
>
> At the second call of the function, the element funcctx->user_fctx (that I
> use
> to store my matrix data structure) references the good memory block.
> Moreover,
> the nl and nc element references the good memory block too. But, in the block
> pointed by nl and nc, the values stored have changed ! I dont understand
> why.
> I try to use malloc or pgport_palloc instead of palloc: it doesnt work !
>
> Example:
>
> At the first call of my function:
>
> 1: BLOCK ANALYSE
> 1: pointer value of pm [11784980]
> 1: pointer value of pm->nc [11785068] stores (4)
> 1: pointer value of pm->nl [11785064] stores (4)
> 1: pointer value of pm->data [] and stored value () ::
> [19517544] (0) ::
> [19517548] (1) ::
> [19517552] (0) ::
> [19517556] (2) ::
> [19517568] (0) ::
> [19517572] (0) ::
> [19517576] (1) ::
> [19517580] (0) ::
> etc
>
> At the second call of my function:
>
> 1: pointer value of pm [11784980]
> 1: pointer value of pm->nc [11785068] stores (0)
> 1: pointer value of pm->nl [11785064] stores (0)
>
> If you are interested to read the code:
> Look at the function called: puissance_table
> At the line containing : DBG("PROBLEMATIK at step %i\n" , call_cntr);
> --------------------
In fact, SPI_finish releases memory allocated by palloc !!!!!!
Then, by using SPI_palloc insted of palloc I solved my second problem !!!!!
I think it would be interesting to add this in the documentation of the SPI !
Thnaks for your reading.