summaryrefslogtreecommitdiff
path: root/Cython/Compiler/ModuleNode.py
diff options
context:
space:
mode:
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r--Cython/Compiler/ModuleNode.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index 502175402..cc291430e 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -506,6 +506,27 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("/* Generated by Cython %s */" % Version.watermark)
code.putln("")
code.putln("#define PY_SSIZE_T_CLEAN")
+
+ # sizeof(PyLongObject.ob_digit[0]) may have been determined dynamically
+ # at compile time in CPython, in which case we can't know the correct
+ # storage size for an installed system. We can rely on it only if
+ # pyconfig.h defines it statically, i.e. if it was set by "configure".
+ # Once we include "Python.h", it will come up with its own idea about
+ # a suitable value, which may or may not match the real one.
+ code.putln("#ifndef CYTHON_USE_PYLONG_INTERNALS")
+ code.putln("#ifdef PYLONG_BITS_IN_DIGIT")
+ # assume it's an incorrect left-over
+ code.putln("#define CYTHON_USE_PYLONG_INTERNALS 0")
+ code.putln("#else")
+ code.putln('#include "pyconfig.h"')
+ code.putln("#ifdef PYLONG_BITS_IN_DIGIT")
+ code.putln("#define CYTHON_USE_PYLONG_INTERNALS 1")
+ code.putln("#else")
+ code.putln("#define CYTHON_USE_PYLONG_INTERNALS 0")
+ code.putln("#endif")
+ code.putln("#endif")
+ code.putln("#endif")
+
for filename in env.python_include_files:
code.putln('#include "%s"' % filename)
code.putln("#ifndef Py_PYTHON_H")