]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Use cdll instead of pydll in ctypes pq wrapper
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 12 Jan 2021 21:47:57 +0000 (22:47 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 12 Jan 2021 22:15:16 +0000 (23:15 +0100)
cdll releases the GIL. Even for callback functions it doesn't seem a
problem.

psycopg3/psycopg3/pq/_pq_ctypes.py
tests/test_adapt.py

index 4f1cac3b245a1f9b29124fa6ee68875aedeae7e4..26137910b893c312da6218c04923f1f05a79ec38 100644 (file)
@@ -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.
 
index 048da0a49f948439c41ed315a75782dfae15809b..1f4287f5da815b91c9dfae91adf64d05b9e1b9d0 100644 (file)
@@ -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)