Remove dllist.c from libpq. It's overkill for what libpq needs; we can
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 16 Oct 2004 22:52:55 +0000 (22:52 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 16 Oct 2004 22:52:55 +0000 (22:52 +0000)
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.

src/include/Makefile
src/interfaces/libpq/Makefile
src/interfaces/libpq/bcc32.mak
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-exec.c
src/interfaces/libpq/fe-protocol2.c
src/interfaces/libpq/fe-protocol3.c
src/interfaces/libpq/libpq-fe.h
src/interfaces/libpq/libpq-int.h
src/interfaces/libpq/win32.mak

index 642ff0ec333567207041e4c0a5e3db31676e03ea..50f71ed4328cb5c9c8ee98c45869e5c379dd014d 100644 (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)
 
index 2dca2202ae1a5186ade65a404557c4d36ac7b63d..2de4ac5b4335c63bb48e90409796a51212e2d9fb 100644 (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
index ac3e09cc38dcbc7c7fe28cbc8ce80d0c5c9528f0..871752d22fa7b449ae12b81158200539f3091aaa 100644 (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"
index 625de2a53316181ef18f544a9cbb726e1446274a..76f811e28f29622bb94f75d71f0432dde766fa37 100644 (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)
index 5ac115fe792b5f688427c1b1bfd7da6f11f9c138..5e19d78b37adc48fe5d122ebd1bb9326219e3c86 100644 (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;
 }
 
index aeb5e0faf032ab695efcb142aac078c270e3b933..8d87a2af0ddc01fc8007b1b0445e9c1bdc47e2ff 100644 (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;
index 548d036e712c9d31ab20162a4892cf49e48d8297..cec7a6720585a01e97b49f29365864bf00491511 100644 (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);
index 7bf7afc102409dec2ba935fa06a5db1d91ab2494..55e288b417ab86280f2ac326cac4ebe1903ad64e 100644 (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 */
index e38e78b06f48a39c79089f93a2adcfa5bf922949..e0992c4103ad6dc51f62e9ee423065eb52682797 100644 (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 */
index 2fbc76dd32e39e28a357529a12617b9a81847db1..c8c5af54a87dda7e4b8c238f6040b8b4a9550d0c 100644 (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