Re: libpq object hooks (libpq events) - Mailing list pgsql-patches

From Andrew Chernow
Subject Re: libpq object hooks (libpq events)
Date
Msg-id 48323593.4060302@esilo.com
Whole thread Raw
In response to Re: libpq object hooks (libpq events)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: libpq object hooks (libpq events)
List pgsql-patches
Will make all of those changes.  We appreciate the help.

1. remove global registration :(

2. New Name: PGCallback

3. use instanceData and passThrough names (passThrough with upper 'T')

3. separate getters for conn/result instanceData and passthrough

4. add a setter for result instance data
   - There should also be a PQsetInstanceData(PGconn*, ...)
   - I see no need for a passThrough setter

5. move callback stuff to its own header, maybe pgcallback.h?

No issue with any of them.  Although, small issue below:

> Maybe instead of having the ResultCreate
> callback scribble on the event data structure, provide an additional
> API routine to store the pointer:
>     PQresultSetInstanceData(PGresult *res, PGeventProc proc,
>                 void *instanceData);

Adding PQresultSetInstanceData doesn't removes the need for a resultcreate
callback event.  This is an event the callbacks are informed about (instanceData
or not).  It does remove the need for an instance data member in all event info
structures, just use the getter/setter when desired.  If the passThrough is
needed, one can use the public getters.

 > hooks registered.  Also, meseems you need such a callback anyway:
 > what if the hook library desires to realloc its instance data
 > larger?
 >

With your suggestions, this would work:

res = PQexec(conn, "blah");
data = PQresultInstanceData(res, cbfunc);
data = realloc(data, 1024);
PQresultSetInstanceData(res, cbfunc, data);

The API user should have a valid instanceData whenever libpq returns a result,
assuming they registered a callback that allocates instance data during a
resultcreate event.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Simplify formatting.c
Next
From: Tom Lane
Date:
Subject: Re: Simplify formatting.c