Update of /usr/cvs/Public/pygresql/module
In directory druid.net:/tmp/cvs-serv2928

Modified Files:
        pgmodule.c 
Log Message:
Release GIL during PQfinish(). Take some precautions for old PG versions with 
kerberos.
To see the diffs for this commit:
   
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/pgmodule.c.diff?r1=1.79&r2=1.80

Index: pgmodule.c
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/pgmodule.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -r1.79 -r1.80
--- pgmodule.c  17 Sep 2008 09:00:08 -0000      1.79
+++ pgmodule.c  22 Sep 2008 19:21:01 -0000      1.80
@@ -1,5 +1,5 @@
 /*
- * $Id: pgmodule.c,v 1.79 2008/09/17 09:00:08 cito Exp $
+ * $Id: pgmodule.c,v 1.80 2008/09/22 19:21:01 cito Exp $
  * PyGres, version 2.2 A Python interface for PostgreSQL database. Written by
  * D'Arcy J.M. Cain, ([EMAIL PROTECTED]).  Based heavily on code written by
  * Pascal Andre, [EMAIL PROTECTED] Copyright (c) 1995, Pascal Andre
@@ -103,6 +103,11 @@
 #define PQfreemem PQfreeNotify
 #endif
 
+/* Before 8.0, PQsetdbLogin was not thread-safe with kerberos. */
+#if defined(PQnoPasswordSupplied) || !(defined(KRB4) || defined(KRB5))
+#define PQsetdbLoginIsThreadSafe 1
+#endif
+
 /* --------------------------------------------------------------------- */
 
 /* MODULE GLOBAL VARIABLES */
@@ -536,7 +541,7 @@
 
        /* gets result */
        Py_BEGIN_ALLOW_THREADS
-               self->last_result = PQexec(self->pgcnx->cnx, query);
+       self->last_result = PQexec(self->pgcnx->cnx, query);
        Py_END_ALLOW_THREADS
 
        /* checks result validity */
@@ -1618,10 +1623,14 @@
                sprintf(port_buffer, "%d", pgport);
        }
 
+#ifdef PQsetdbLoginIsThreadSafe
        Py_BEGIN_ALLOW_THREADS
+#endif
        npgobj->cnx = PQsetdbLogin(pghost, pgport == -1 ? NULL : port_buffer,
                pgopt, pgtty, pgdbname, pguser, pgpasswd);
+#ifdef PQsetdbLoginIsThreadSafe
        Py_END_ALLOW_THREADS
+#endif
 
        if (PQstatus(npgobj->cnx) == CONNECTION_BAD)
        {
@@ -1640,8 +1649,11 @@
 pg_dealloc(pgobject * self)
 {
        if (self->cnx)
+       {
+               Py_BEGIN_ALLOW_THREADS
                PQfinish(self->cnx);
-
+               Py_END_ALLOW_THREADS
+       }
        PyObject_Del(self);
 }
 
@@ -1668,7 +1680,10 @@
                return NULL;
        }
 
+       Py_BEGIN_ALLOW_THREADS
        PQfinish(self->cnx);
+       Py_END_ALLOW_THREADS
+
        self->cnx = NULL;
        Py_INCREF(Py_None);
        return Py_None;
@@ -2157,7 +2172,7 @@
         * query
         */
        Py_BEGIN_ALLOW_THREADS
-               result = PQexec(self->cnx, " ");
+       result = PQexec(self->cnx, " ");
        Py_END_ALLOW_THREADS
 
                if ((notify = PQnotifies(self->cnx)) != NULL)
@@ -2255,7 +2270,7 @@
 
        /* gets result */
        Py_BEGIN_ALLOW_THREADS
-               result = PQexec(self->cnx, query);
+       result = PQexec(self->cnx, query);
        Py_END_ALLOW_THREADS
 
        /* checks result validity */
@@ -2501,7 +2516,7 @@
        sprintf(buffer, "copy %s from stdin", table);
 
        Py_BEGIN_ALLOW_THREADS
-               result = PQexec(self->cnx, buffer);
+       result = PQexec(self->cnx, buffer);
        Py_END_ALLOW_THREADS
 
        if (!result)

_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to