Remove dllist.c from libpq. It's overkill for what libpq needs; we can

just stick a list-link into struct PGnotify instead.  Result is a smaller
faster and more robust library (mainly because we reduce the number of
malloc's and free's involved in notify processing), plus less pollution
of application link-symbol namespace.
This commit is contained in:
Tom Lane 2004-10-16 22:52:55 +00:00
parent b3d58ea7ec
commit cc6a90e4af
10 changed files with 44 additions and 40 deletions

View File

@ -4,7 +4,7 @@
#
# 'make install' installs whole contents of src/include.
#
# $PostgreSQL: pgsql/src/include/Makefile,v 1.14 2004/10/07 16:23:28 momjian Exp $
# $PostgreSQL: pgsql/src/include/Makefile,v 1.15 2004/10/16 22:52:39 tgl Exp $
#
#-------------------------------------------------------------------------
@ -33,7 +33,6 @@ install: all installdirs remove-old-headers
$(INSTALL_DATA) $(srcdir)/port.h $(DESTDIR)$(includedir_internal)
$(INSTALL_DATA) $(srcdir)/postgres_fe.h $(DESTDIR)$(includedir_internal)
$(INSTALL_DATA) $(srcdir)/libpq/pqcomm.h $(DESTDIR)$(includedir_internal)/libpq
$(INSTALL_DATA) $(srcdir)/lib/dllist.h $(DESTDIR)$(includedir_internal)/lib
# These headers are needed for server-side development
$(INSTALL_DATA) pg_config.h $(DESTDIR)$(includedir_server)
$(INSTALL_DATA) pg_config_os.h $(DESTDIR)$(includedir_server)
@ -71,7 +70,7 @@ remove-old-headers:
uninstall:
rm -f $(addprefix $(DESTDIR)$(includedir)/, pg_config.h pg_config_os.h postgres_ext.h libpq/libpq-fs.h)
rm -f $(addprefix $(DESTDIR)$(includedir_internal)/, c.h postgres_fe.h lib/dllist.h libpq/pqcomm.h)
rm -f $(addprefix $(DESTDIR)$(includedir_internal)/, c.h postgres_fe.h libpq/pqcomm.h)
# heuristic...
rm -rf $(addprefix $(DESTDIR)$(includedir_server)/, $(SUBDIRS) *.h)

View File

@ -5,7 +5,7 @@
# Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.119 2004/10/16 20:10:56 tgl Exp $
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.120 2004/10/16 22:52:49 tgl Exp $
#
#-------------------------------------------------------------------------
@ -28,7 +28,7 @@ LIBS := $(patsubst -lpgport,, $(LIBS))
OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
dllist.o md5.o ip.o wchar.o encnames.o noblock.o pgstrcasecmp.o thread.o \
md5.o ip.o wchar.o encnames.o noblock.o pgstrcasecmp.o thread.o \
$(filter crypt.o getaddrinfo.o inet_aton.o open.o snprintf.o strerror.o, $(LIBOBJS))
ifeq ($(PORTNAME), win32)
@ -73,9 +73,6 @@ crypt.c getaddrinfo.c inet_aton.c noblock.c pgstrcasecmp.c snprintf.c strerror.c
md5.c ip.c: % : $(backend_src)/libpq/%
rm -f $@ && $(LN_S) $< .
dllist.c: $(backend_src)/lib/dllist.c
rm -f $@ && $(LN_S) $< .
encnames.c wchar.c : % : $(backend_src)/utils/mb/%
rm -f $@ && $(LN_S) $< .
@ -137,7 +134,7 @@ uninstall: uninstall-lib
rm -f $(DESTDIR)$(includedir)/libpq-fe.h $(DESTDIR)$(includedir_internal)/libpq-int.h $(DESTDIR)$(includedir_internal)/pqexpbuffer.h
clean distclean: clean-lib
rm -f $(OBJS) crypt.c getaddrinfo.c inet_aton.c noblock.c pgstrcasecmp.c snprintf.c strerror.c open.c thread.c dllist.c md5.c ip.c encnames.c wchar.c pthread.h
rm -f $(OBJS) crypt.c getaddrinfo.c inet_aton.c noblock.c pgstrcasecmp.c snprintf.c strerror.c open.c thread.c md5.c ip.c encnames.c wchar.c pthread.h
maintainer-clean: distclean
rm -f $(srcdir)/libpqdll.def $(srcdir)/libpqddll.def $(srcdir)/blibpqdll.def

View File

@ -69,7 +69,6 @@ LIB32_OBJS= \
"$(INTDIR)\crypt.obj" \
"$(INTDIR)\noblock.obj" \
"$(INTDIR)\pgstrcasecmp.obj" \
"$(INTDIR)\dllist.obj" \
"$(INTDIR)\md5.obj" \
"$(INTDIR)\ip.obj" \
"$(INTDIR)\fe-auth.obj" \
@ -100,7 +99,6 @@ CLEAN :
-@erase "$(INTDIR)\thread.obj"
-@erase "$(INTDIR)\inet_aton.obj"
-@erase "$(INTDIR)\crypt.obj"
-@erase "$(INTDIR)\dllist.obj"
-@erase "$(INTDIR)\md5.obj"
-@erase "$(INTDIR)\ip.obj"
-@erase "$(INTDIR)\fe-auth.obj"

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.284 2004/08/29 05:07:00 momjian Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.285 2004/10/16 22:52:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1967,7 +1967,6 @@ makeEmptyPGconn(void)
conn->setenv_state = SETENV_STATE_IDLE;
conn->client_encoding = PG_SQL_ASCII;
conn->verbosity = PQERRORS_DEFAULT;
conn->notifyList = DLNewList();
conn->sock = -1;
#ifdef USE_SSL
conn->allow_ssl_try = true;
@ -2013,6 +2012,7 @@ makeEmptyPGconn(void)
static void
freePGconn(PGconn *conn)
{
PGnotify *notify;
pgParameterStatus *pstatus;
if (!conn)
@ -2047,8 +2047,14 @@ freePGconn(PGconn *conn)
if (conn->sslmode)
free(conn->sslmode);
/* Note that conn->Pfdebug is not ours to close or free */
if (conn->notifyList)
DLFreeList(conn->notifyList);
notify = conn->notifyHead;
while (notify != NULL)
{
PGnotify *prev = notify;
notify = notify->next;
free(prev);
}
freeaddrinfo_all(conn->addrlist_family, conn->addrlist);
pstatus = conn->pstatus;
while (pstatus != NULL)

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.162 2004/08/30 02:54:41 momjian Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.163 2004/10/16 22:52:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1323,7 +1323,6 @@ PQexecFinish(PGconn *conn)
PGnotify *
PQnotifies(PGconn *conn)
{
Dlelem *e;
PGnotify *event;
if (!conn)
@ -1332,12 +1331,14 @@ PQnotifies(PGconn *conn)
/* Parse any available data to see if we can extract NOTIFY messages. */
parseInput(conn);
/* RemHead returns NULL if list is empty */
e = DLRemHead(conn->notifyList);
if (!e)
return NULL;
event = (PGnotify *) DLE_VAL(e);
DLFreeElem(e);
event = conn->notifyHead;
if (event)
{
conn->notifyHead = event->next;
if (!conn->notifyHead)
conn->notifyTail = NULL;
event->next = NULL; /* don't let app see the internal state */
}
return event;
}

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.14 2004/08/30 02:54:41 momjian Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.15 2004/10/16 22:52:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -937,7 +937,12 @@ getNotify(PGconn *conn)
/* fake up an empty-string extra field */
newNotify->extra = newNotify->relname + nmlen;
newNotify->be_pid = be_pid;
DLAddTail(conn->notifyList, DLNewElem(newNotify));
newNotify->next = NULL;
if (conn->notifyTail)
conn->notifyTail->next = newNotify;
else
conn->notifyHead = newNotify;
conn->notifyTail = newNotify;
}
return 0;

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.17 2004/10/12 21:54:45 petere Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.18 2004/10/16 22:52:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -791,7 +791,12 @@ getNotify(PGconn *conn)
newNotify->extra = newNotify->relname + nmlen + 1;
strcpy(newNotify->extra, conn->workBuffer.data);
newNotify->be_pid = be_pid;
DLAddTail(conn->notifyList, DLNewElem(newNotify));
newNotify->next = NULL;
if (conn->notifyTail)
conn->notifyTail->next = newNotify;
else
conn->notifyHead = newNotify;
conn->notifyTail = newNotify;
}
free(svname);

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.110 2004/10/16 03:26:43 momjian Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.111 2004/10/16 22:52:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -127,6 +127,8 @@ typedef struct pgNotify
char *relname; /* notification condition name */
int be_pid; /* process ID of server process */
char *extra; /* notification parameter */
/* Fields below here are private to libpq; apps should not use 'em */
struct pgNotify *next; /* list link */
} PGnotify;
/* Function types for notice-handling callbacks */

View File

@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.93 2004/10/05 15:09:41 momjian Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.94 2004/10/16 22:52:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -41,7 +41,6 @@ typedef int ssize_t; /* ssize_t doesn't exist in VC (at least
/* include stuff common to fe and be */
#include "getaddrinfo.h"
#include "libpq/pqcomm.h"
#include "lib/dllist.h"
/* include stuff found in fe only */
#include "pqexpbuffer.h"
@ -272,8 +271,8 @@ struct pg_conn
char copy_is_binary; /* 1 = copy binary, 0 = copy text */
int copy_already_done; /* # bytes already returned in
* COPY OUT */
Dllist *notifyList; /* Notify msgs not yet handed to
* application */
PGnotify *notifyHead; /* oldest unreported Notify msg */
PGnotify *notifyTail; /* newest unreported Notify msg */
/* Connection data */
int sock; /* Unix FD for socket, -1 if not connected */

View File

@ -50,7 +50,6 @@ CLEAN :
-@erase "$(INTDIR)\inet_aton.obj"
-@erase "$(INTDIR)\crypt.obj"
-@erase "$(INTDIR)\noblock.obj"
-@erase "$(INTDIR)\dllist.obj"
-@erase "$(INTDIR)\md5.obj"
-@erase "$(INTDIR)\ip.obj"
-@erase "$(INTDIR)\fe-auth.obj"
@ -117,7 +116,6 @@ LIB32_OBJS= \
"$(INTDIR)\inet_aton.obj" \
"$(INTDIR)\crypt.obj" \
"$(INTDIR)\noblock.obj" \
"$(INTDIR)\dllist.obj" \
"$(INTDIR)\md5.obj" \
"$(INTDIR)\ip.obj" \
"$(INTDIR)\fe-auth.obj" \
@ -192,12 +190,6 @@ LINK32_OBJS= \
$(CPP_PROJ) ..\..\port\noblock.c
<<
"$(INTDIR)\dllist.obj" : ..\..\backend\lib\dllist.c
$(CPP) @<<
$(CPP_PROJ) ..\..\backend\lib\dllist.c
<<
"$(INTDIR)\md5.obj" : ..\..\backend\libpq\md5.c
$(CPP) @<<
$(CPP_PROJ) ..\..\backend\libpq\md5.c