From: Daniele Varrazzo Date: Tue, 12 Jan 2021 21:47:57 +0000 (+0100) Subject: Use cdll instead of pydll in ctypes pq wrapper X-Git-Tag: 3.0.dev0~172 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69fbbec4337494550d76de9837717534e6f70e9b;p=thirdparty%2Fpsycopg.git Use cdll instead of pydll in ctypes pq wrapper cdll releases the GIL. Even for callback functions it doesn't seem a problem. --- diff --git a/psycopg3/psycopg3/pq/_pq_ctypes.py b/psycopg3/psycopg3/pq/_pq_ctypes.py index 4f1cac3b2..26137910b 100644 --- a/psycopg3/psycopg3/pq/_pq_ctypes.py +++ b/psycopg3/psycopg3/pq/_pq_ctypes.py @@ -20,7 +20,7 @@ else: if not libname: raise ImportError("libpq library not found") -pq = ctypes.pydll.LoadLibrary(libname) +pq = ctypes.cdll.LoadLibrary(libname) # Get the libpq version to define what functions are available. diff --git a/tests/test_adapt.py b/tests/test_adapt.py index 048da0a49..1f4287f5d 100644 --- a/tests/test_adapt.py +++ b/tests/test_adapt.py @@ -161,8 +161,8 @@ def test_load_cursor_ctx_nested(conn, sql, obj, fmt_out): @pytest.mark.parametrize("fmt_out", [Format.TEXT, Format.BINARY]) -def test_array_dumper(fmt_out): - t = Transformer() +def test_array_dumper(conn, fmt_out): + t = Transformer(conn) dint = t.get_dumper([0], fmt_out) assert dint.oid == builtins["int8"].array_oid assert dint.sub_oid == builtins["int8"].oid @@ -173,9 +173,18 @@ def test_array_dumper(fmt_out): assert dstr is not dint assert t.get_dumper([1], fmt_out) is dint - assert t.get_dumper([], fmt_out) is dstr assert t.get_dumper([None, [1]], fmt_out) is dint - assert t.get_dumper([None, [None]], fmt_out) is dstr + + dempty = t.get_dumper([], fmt_out) + assert t.get_dumper([None, [None]], fmt_out) is dempty + if fmt_out == Format.TEXT: + if conn.pgconn.server_version >= 100000: + assert dempty.oid == 0 + else: + assert dempty.oid == builtins["text"].oid + else: + assert dempty.oid == builtins["text"].array_oid + assert dempty.sub_oid == builtins["text"].oid L = [] L.append(L)