Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 345CB2E0059 for ; Thu, 15 May 2008 18:19:23 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 56518-06 for ; Thu, 15 May 2008 18:19:08 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.esilo.com (updates.esilo.com [63.150.152.211]) by developer.postgresql.org (Postfix) with ESMTP id F32932E005E for ; Thu, 15 May 2008 18:19:11 -0300 (ADT) Received: from [10.0.0.84] (fwext-esilo-jupiter.esilo.com [64.135.45.146]) (authenticated bits=0) by mail.esilo.com (8.13.1/8.13.1) with ESMTP id m4FLJ0hv000460; Thu, 15 May 2008 17:19:02 -0400 Message-ID: <482CA8C3.2000507@esilo.com> Date: Thu, 15 May 2008 17:18:59 -0400 From: Andrew Chernow User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: Tom Lane CC: Merlin Moncure , Andrew Dunstan , Alvaro Herrera , "Patches (PostgreSQL)" Subject: Re: libpq object hooks References: <482A58D8.2030205@dunslane.net> <20080514043313.GS6966@alvh.no-ip.org> <482AD896.4000504@dunslane.net> <19342.1210776271@sss.pgh.pa.us> <6044.1210867771@sss.pgh.pa.us> <482C77E5.1060500@esilo.com> <9458.1210875556@sss.pgh.pa.us> <482C82BA.3090100@esilo.com> <9867.1210877054@sss.pgh.pa.us> In-Reply-To: <9867.1210877054@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/297 X-Sequence-Number: 6323 Tom Lane wrote: > Andrew Chernow 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/