diff --git a/Cython/Includes/cpython/longintrepr.pxd b/Cython/Includes/cpython/longintrepr.pxd index 45fe81e6cd6..57691c41284 100644 --- a/Cython/Includes/cpython/longintrepr.pxd +++ b/Cython/Includes/cpython/longintrepr.pxd @@ -1,7 +1,14 @@ # Internals of the "long" type (Python 2) or "int" type (Python 3). # This is not part of Python's published API. -cdef extern from "longintrepr.h": +cdef extern from *: + """" + #if PY_VERSION_HEX >= 0x03000000 + #include "Python.h" + #else + #include "longintrepr.h" + #endif + """ ctypedef unsigned int digit ctypedef int sdigit # Python >= 2.7 only diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c index 758ce7f86e7..8aabef3dd45 100644 --- a/Cython/Utility/ModuleSetupCode.c +++ b/Cython/Utility/ModuleSetupCode.c @@ -263,7 +263,11 @@ #define CYTHON_BACKPORT_VECTORCALL (CYTHON_METH_FASTCALL && PY_VERSION_HEX < 0x030800B1) #if CYTHON_USE_PYLONG_INTERNALS - #include "longintrepr.h" + #if PY_VERSION_HEX >= 0x03000000 + #include "Python.h" + #else + #include "longintrepr.h" + #endif /* These short defines can easily conflict with other code */ #undef SHIFT #undef BASE diff --git a/tests/compile/pylong.pyx b/tests/compile/pylong.pyx index f4938fab9f8..40b26cffaa7 100644 --- a/tests/compile/pylong.pyx +++ b/tests/compile/pylong.pyx @@ -1,6 +1,13 @@ # mode: compile -cdef extern from "Python.h": +cdef extern from *: + """" + #if PY_VERSION_HEX >= 0x03000000 + #include "Python.h" + #else + #include "longintrepr.h" + #endif + """ ctypedef struct PyTypeObject: pass @@ -8,7 +15,7 @@ cdef extern from "Python.h": Py_ssize_t ob_refcnt PyTypeObject *ob_type -cdef extern from "longintrepr.h": +cdef extern from "Python.h": cdef struct _longobject: int ob_refcnt PyTypeObject *ob_type