From: Daniele Varrazzo Date: Wed, 18 Mar 2020 11:26:11 +0000 (+1300) Subject: Fixed checking for NULL results in ctypes layer X-Git-Tag: 3.0.dev0~700 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=84baf39ecd385023aecf0f30212d70da2998602c;p=thirdparty%2Fpsycopg.git Fixed checking for NULL results in ctypes layer Also check null result from connection functions. --- diff --git a/psycopg3/pq/pq_ctypes.py b/psycopg3/pq/pq_ctypes.py index 9d56007c9..31f2b9189 100644 --- a/psycopg3/pq/pq_ctypes.py +++ b/psycopg3/pq/pq_ctypes.py @@ -44,6 +44,8 @@ class PGconn: ) pgconn_ptr = impl.PQconnectdb(conninfo) + if not pgconn_ptr: + raise MemoryError("couldn't allocate PGconn") return cls(pgconn_ptr) @classmethod @@ -54,6 +56,8 @@ class PGconn: ) pgconn_ptr = impl.PQconnectStart(conninfo) + if not pgconn_ptr: + raise MemoryError("couldn't allocate PGconn") return cls(pgconn_ptr) def connect_poll(self): @@ -188,7 +192,7 @@ class PGconn: "bytes expected, got %s instead" % type(command).__name__ ) rv = impl.PQexec(self.pgconn_ptr, command) - if rv is None: + if not rv: raise MemoryError("couldn't allocate PGresult") return PGresult(rv) @@ -251,7 +255,7 @@ class PGconn: aformats, result_format, ) - if rv is None: + if not rv: raise MemoryError("couldn't allocate PGresult") return PGresult(rv) @@ -277,7 +281,7 @@ class PGconn: atypes = (impl.Oid * nparams)(*param_types) rv = impl.PQprepare(self.pgconn_ptr, name, command, nparams, atypes,) - if rv is None: + if not rv: raise MemoryError("couldn't allocate PGresult") return PGresult(rv) @@ -317,7 +321,7 @@ class PGconn: aformats, result_format, ) - if rv is None: + if not rv: raise MemoryError("couldn't allocate PGresult") return PGresult(rv) @@ -327,7 +331,7 @@ class PGconn: "'name' must be bytes, got %s instead" % type(name).__name__ ) rv = impl.PQdescribePrepared(self.pgconn_ptr, name) - if rv is None: + if not rv: raise MemoryError("couldn't allocate PGresult") return PGresult(rv) @@ -337,7 +341,7 @@ class PGconn: "'name' must be bytes, got %s instead" % type(name).__name__ ) rv = impl.PQdescribePortal(self.pgconn_ptr, name) - if rv is None: + if not rv: raise MemoryError("couldn't allocate PGresult") return PGresult(rv)