From 84baf39ecd385023aecf0f30212d70da2998602c Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 19 Mar 2020 00:26:11 +1300 Subject: [PATCH] Fixed checking for NULL results in ctypes layer Also check null result from connection functions. --- psycopg3/pq/pq_ctypes.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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) -- 2.47.3