Here is an updated version of the object hooks patch. It now supports a
list of hooks for a PGconn, and PGresult. This had to re-introduce the
concept of hook name. Being that there is now a list, you need a way to
reference an item of that list.

Advertising

Also added PQobjectHooks and PQresultObjectHooks, to get a pointer to
the conn or result hook list. PQmakeResult must allow the ability to
pass a list of object hooks in. So, PQresultObjectHooks was born.
pqtypes doesn't need (at least at this time) PQobjectHooks but leaving
it out felt unbalanced.

Note: PQhookData and PQresultHookData can be removed. There
functionality can be reproduced by an API user issuing PQobjectHooks or
PQresultObjectHooks and manually looking for there hook (normaly to get
at the hook->data). Basically, an API user would do themselves what
PQhookData is doing.

Made some changes:

1. Removed the hookName argument to PQaddObjectHooks, since its in the
supplied PQobjectHooks struct. I think the argument was lingering from
a previous patch.

2. Added the ability to install global object hooks:
PQaddGlobalObjectHooks(PGobjectHooks*). The header docs for this
function warns that it should only be used before calling libpq
functions or creating application threads. There are no management
functions for global hooks, like get or remove. If you add global
object hooks, your stuck with them until process death.

3. There is a new internal pqInitObjectHooks(PGconn *) that installs the
global object hooks on new conns in the CONNECTION_OK status. I call
this function within PQconnectPoll (3 different locations). This will
call PQaddObjectHooks(conn) for each global hook (so global hooks are
always at the front of a conn's hook list). pqInitObjectHooks checks to
see if conn->objHooksCount > 0 and if it is, the request is ignored and
the function returns success. This only happens during a PQreset and
PQresetPoll.

Since the existing list of object hooks is scanned for duplicate names
when adding them, you will never run into duplicate object hooks in a
connection (or in the global list). If the two examples above were both
called by an application, the per-conn call would fail.