From: Daniele Varrazzo Date: Mon, 28 Dec 2020 04:28:01 +0000 (+0100) Subject: Tweaking generators.execute C code X-Git-Tag: 3.0.dev0~228^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a0d1f082a560384e0b25f5d092f3a47e89cc913;p=thirdparty%2Fpsycopg.git Tweaking generators.execute C code --- diff --git a/psycopg3_c/psycopg3_c/_psycopg3/generators.pyx b/psycopg3_c/psycopg3_c/_psycopg3/generators.pyx index d68130341..0d0eb5454 100644 --- a/psycopg3_c/psycopg3_c/_psycopg3/generators.pyx +++ b/psycopg3_c/psycopg3_c/_psycopg3/generators.pyx @@ -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, pynotify, NULL + ) else: while 1: notify = libpq.PQnotifies(pgconn_ptr) diff --git a/psycopg3_c/psycopg3_c/pq.pxd b/psycopg3_c/psycopg3_c/pq.pxd index 87e172341..3f2a1ae27 100644 --- a/psycopg3_c/psycopg3_c/pq.pxd +++ b/psycopg3_c/psycopg3_c/pq.pxd @@ -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 diff --git a/psycopg3_c/psycopg3_c/pq/pgconn.pyx b/psycopg3_c/psycopg3_c/pq/pgconn.pyx index e9112326f..48f453df2 100644 --- a/psycopg3_c/psycopg3_c/pq/pgconn.pyx +++ b/psycopg3_c/psycopg3_c/pq/pgconn.pyx @@ -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)