It worked today with me and I discovered what is the problem. The problem is
that I have 2 structures that contain pointers. I inistiate variables from
these structures as static. I can't declare the pointers inside the struct
as static. Now the problem is that when the function is called a second
time, it returns set of records, it finds the static pointers in the
function but the pointers inside the struct are deleted. Here is a portion
of the code:
typedef struct
{
int value;
struct TuplesList *next;
}TuplesList;
typedef struct
{
TuplesList *tuplesHead;
TuplesList *tuplesTail;
struct AggrQuery *nextQuery;
}AggrQuery;
Datum AggrFn(PG_FUNCTION_ARGS)
{
static AggrQuery *queriesHead;
static AggrQuery *queriesTail;
}
First call to AggrFn is correct, in the second call queriesHead and
queriesTail are preserved but queriesHead->tuplesHead, for example, is
rubbish from memory. I read in the PostgreSQL documentation 'However, if you
want to allocate any data structures to live across calls, you need to put
them somewhere else. The memory context referenced by multi_call_memory_ctx
is a suitable location for any data that needs to survive until the SRF is
finished running'. I don't understand this statement so I created the
variables as static but it is not working with struct....
Regards
Islam Hegazy
----- Original Message -----
From: "Gregory Stark" <stark@xxxxxxxxxxxxxxxx>
To: "Islam Hegazy" <islheg@xxxxxxxxx>
Cc: "Tom Lane" <tgl@xxxxxxxxxxxxx>; "Joe Conway" <mail@xxxxxxxxxxxxx>;
<pgsql-general@xxxxxxxxxxxxxx>
Sent: Monday, June 04, 2007 5:50 AM
Subject: Re: [GENERAL] debugging C functions
"Islam Hegazy" <islheg@xxxxxxxxx> writes:
I do the same but I use the ddd debugger
1) Load the shared library from the SQL
2) Open the .c file of my function
3) Place the break points
4) Execute the sql statement 'Select * from Myfn(...);'
The result is displayed and the debugger doesn't stop at the breakpoints.
Are you sure you're attaching to the right process?
One way to do it is to run select pg_backend_pid() from psql and attach to
that pid.
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com