Skip site navigation (1) Skip section navigation (2)

Re: libpq object hooks

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: libpq object hooks
Date: 2008-05-15 21:18:59
Message-ID: 482CA8C3.2000507@esilo.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
Tom Lane wrote:
> Andrew Chernow <ac(at)esilo(dot)com> writes:
>> Which callback do we use as the key?  Currently, none are required (only 
>> the name was required).  We have to choose one callback that must be 
>> provided.
> 
> What?  I thought what you wanted back was the void * pointer that had
> been registered with a particular callback function.  So you use that
> callback function.  If it's not actually registered, you get a NULL.
> 
>> This is what is passed to PQaddObjectHooks, along with a conn:
> 
> This is all wrong IMHO, not least because it creates ABI problems if you
> want to add another hook type later.  Register each hook separately, eg
> 
> typedef void (*PGCRHook) (PGconn *conn, void *passthrough);
> 
> void PQregisterConnResetHook(PGconn *conn, PQCRHook func, void *passthrough);
> 
> ... repeat for each possible hook ...
> 
> 			regards, tom lane
> 
> 

One can make a case to break apart the obj hooks structure into 
individual register functions, but I think you have a different idea in 
your head than what is being proposed.  For starters, there is no 
passthru pointer to register with a callback (there could be but that is 
different than hook data...your register looks more like a user_ptr). 
The passthru pointer, what we call hookData, is allocated with a PGconn 
(not provided by the user).  This is the point of the initHookData callback.

typedef void *(*PGinitHookData)(const PGconn *conn);

PQregisterInitHookData((PGconn *)NULL, (PGinitHookData)func);
PQregisterConnResetHook((PGconn *)NULL, (PGCRHook)func);
//etc...
conn = PQconnectdb();

When connectdb returns, initHookData has already been called.  So, a 
call to PQhookData(conn, ????) will work.  BUT, what is still missing 
from the equation is how to uniquely reference hookData on a conn.

What I was previously suggesting was to use the address of initHookData, 
since w/o this address there wouldn't be any hook data to get.  Seemed 
like a logical choice.

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

In response to

pgsql-hackers by date

Next:From: Jan UrbaƄskiDate: 2008-05-15 23:54:42
Subject: deadlock while doing VACUUM and DROP
Previous:From: Josh BerkusDate: 2008-05-15 21:04:52
Subject: Re: WAL file naming sequence definition

pgsql-patches by date

Next:From: David FetterDate: 2008-05-15 22:06:26
Subject: Re: Patch to change psql default banner v6
Previous:From: Bruce MomjianDate: 2008-05-15 21:17:40
Subject: Re: Patch to change psql default banner v6

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group