From: Daniele Varrazzo Date: Tue, 29 Jun 2021 15:35:21 +0000 (+0100) Subject: Don't use the Cython IF construct X-Git-Tag: 3.0.dev0~4^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=396460f4366d0d2217beb4b68cca804a8e6696e9;p=thirdparty%2Fpsycopg.git Don't use the Cython IF construct This produces independent .c files which can be included in the sdist and be compiled on every supported platform. --- diff --git a/psycopg_c/psycopg_c/pq.pxd b/psycopg_c/psycopg_c/pq.pxd index 82c4e5000..cead72b21 100644 --- a/psycopg_c/psycopg_c/pq.pxd +++ b/psycopg_c/psycopg_c/pq.pxd @@ -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 +#endif + """ + ctypedef signed pid_t from psycopg_c.pq cimport libpq diff --git a/psycopg_c/psycopg_c/pq/pgconn.pyx b/psycopg_c/psycopg_c/pq/pgconn.pyx index 7e99112ae..570b9ab04 100644 --- a/psycopg_c/psycopg_c/pq/pgconn.pyx +++ b/psycopg_c/psycopg_c/pq/pgconn.pyx @@ -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 +#endif + """ + pid_t getpid() from cpython.mem cimport PyMem_Malloc, PyMem_Free from cpython.bytes cimport PyBytes_AsString, PyBytes_AsStringAndSize