]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Tweaking generators.execute C code
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 28 Dec 2020 04:28:01 +0000 (05:28 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 29 Dec 2020 17:13:09 +0000 (18:13 +0100)
psycopg3_c/psycopg3_c/_psycopg3/generators.pyx
psycopg3_c/psycopg3_c/pq.pxd
psycopg3_c/psycopg3_c/pq/pgconn.pyx

index d68130341a70db5d4f388e45e4d75de646cb47d4..0d0eb545440643634bee47b0d288aa451f69360c 100644 (file)
@@ -4,6 +4,8 @@ C implementation of generators for the communication protocols with the libpq
 
 # Copyright (C) 2020 The Psycopg Team
 
+from cpython.object cimport PyObject_CallFunctionObjArgs
+
 import logging
 from typing import List
 
@@ -64,7 +66,7 @@ def execute(pq.PGconn pgconn) -> PQGen[List[proto.PGresult]]:
     Return the list of results returned by the database (whether success
     or error).
     """
-    results: List[proto.PGresult] = []
+    cdef list results = []
     cdef libpq.PGconn *pgconn_ptr = pgconn.pgconn_ptr
     cdef int status
     cdef libpq.PGnotify *notify
@@ -87,6 +89,8 @@ def execute(pq.PGconn pgconn) -> PQGen[List[proto.PGresult]]:
                     f"consuming input failed: {error_message(pgconn)}")
         continue
 
+    cdef object notify_handler = pgconn.notify_handler
+
     # Fetching the result
     while 1:
         with nogil:
@@ -102,12 +106,14 @@ def execute(pq.PGconn pgconn) -> PQGen[List[proto.PGresult]]:
             continue
 
         # Consume notifies
-        if pgconn.notify_handler:
+        if notify_handler is not None:
             while 1:
                 pynotify = pgconn.notifies()
                 if pynotify is None:
                     break
-                pgconn.notify_handler(pynotify)
+                PyObject_CallFunctionObjArgs(
+                    notify_handler, <PyObject *>pynotify, NULL
+                )
         else:
             while 1:
                 notify = libpq.PQnotifies(pgconn_ptr)
index 87e17234188e26559a3c11be67edcaa3b4c51a84..3f2a1ae27a6350ac6bc4a30e0b20713a30c89f98 100644 (file)
@@ -15,6 +15,7 @@ cdef class PGconn:
     @staticmethod
     cdef PGconn _from_ptr(libpq.PGconn *ptr)
 
+    cpdef object notifies(self)
 
 cdef class PGresult:
     cdef libpq.PGresult* pgresult_ptr
index e9112326faa2e9c0460b03e91ab9408240dc3d0b..48f453df29564d1a6944530635d29a1c5d5ef94b 100644 (file)
@@ -411,7 +411,7 @@ cdef class PGconn:
             raise PQerror("couldn't create cancel object")
         return PGcancel._from_ptr(ptr)
 
-    def notifies(self) -> Optional[PGnotify]:
+    cpdef object notifies(self):
         cdef libpq.PGnotify *ptr
         with nogil:
             ptr = libpq.PQnotifies(self.pgconn_ptr)