]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Don't use the Cython IF construct
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 29 Jun 2021 15:35:21 +0000 (16:35 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 29 Jun 2021 15:44:49 +0000 (16:44 +0100)
This produces independent .c files which can be included in the sdist
and be compiled on every supported platform.

psycopg_c/psycopg_c/pq.pxd
psycopg_c/psycopg_c/pq/pgconn.pyx

index 82c4e5000dcad238e21c276d1db5c186c621639d..cead72b21b2ad7777283836e1cdca908db98b06a 100644 (file)
@@ -1,7 +1,15 @@
-IF UNAME_SYSNAME != "Windows":
-    from posix.fcntl cimport pid_t
-ELSE:
-    ctypedef int pid_t
+# Include pid_t but Windows doesn't have it
+# Don't use "IF" so that the generated C is portable and can be included
+# in the sdist.
+cdef extern from * nogil:
+    """
+#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)
+    typedef signed pid_t;
+#else
+    #include <fcntl.h>
+#endif
+    """
+    ctypedef signed pid_t
 
 from psycopg_c.pq cimport libpq
 
index 7e99112aeaaa3c3785f3db5f6891cf4707ecb6dc..570b9ab0406caab79f8dce9a0fec54703a8ec810 100644 (file)
@@ -4,13 +4,18 @@ psycopg_c.pq.PGconn object implementation.
 
 # Copyright (C) 2020-2021 The Psycopg Team
 
-IF UNAME_SYSNAME != "Windows":
-    from posix.unistd cimport getpid
-ELSE:
-    # We don't need a real definition for this because Windows is not affected
-    # by the issue caused by closing the fds after fork.
-    cdef int getpid():
-        return 0
+cdef extern from * nogil:
+    """
+#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)
+    /* We don't need a real definition for this because Windows is not affected
+     * by the issue caused by closing the fds after fork.
+     */
+    #define getpid() (0)
+#else
+    #include <unistd.h>
+#endif
+    """
+    pid_t getpid()
 
 from cpython.mem cimport PyMem_Malloc, PyMem_Free
 from cpython.bytes cimport PyBytes_AsString, PyBytes_AsStringAndSize