Commit acc01ab4 authored by Lisandro Dalcin's avatar Lisandro Dalcin

better __Pyx_check_binary_version()

parent b8a62b05
...@@ -1758,7 +1758,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1758,7 +1758,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("#endif") code.putln("#endif")
env.use_utility_code(check_binary_version_utility_code) env.use_utility_code(check_binary_version_utility_code)
code.putln("__Pyx_check_binary_version();") code.putln("if ( __Pyx_check_binary_version() < 0) %s" % code.error_goto(self.pos))
code.putln("%s = PyTuple_New(0); %s" % (Naming.empty_tuple, code.error_goto_if_null(Naming.empty_tuple, self.pos))); code.putln("%s = PyTuple_New(0); %s" % (Naming.empty_tuple, code.error_goto_if_null(Naming.empty_tuple, self.pos)));
code.putln("%s = PyBytes_FromStringAndSize(\"\", 0); %s" % (Naming.empty_bytes, code.error_goto_if_null(Naming.empty_bytes, self.pos))); code.putln("%s = PyBytes_FromStringAndSize(\"\", 0); %s" % (Naming.empty_bytes, code.error_goto_if_null(Naming.empty_bytes, self.pos)));
...@@ -2858,34 +2858,24 @@ check_binary_version_utility_code = UtilityCode(proto=""" ...@@ -2858,34 +2858,24 @@ check_binary_version_utility_code = UtilityCode(proto="""
static int __Pyx_check_binary_version(void); static int __Pyx_check_binary_version(void);
""", impl=""" """, impl="""
static int __Pyx_check_binary_version(void) { static int __Pyx_check_binary_version(void) {
int res = -1; long version_hex, major_version, minor_version;
PyObject *major_info = NULL; PyObject *sys_hexversion = PySys_GetObject((char*)"hexversion");
PyObject *minor_info = NULL; if (sys_hexversion == NULL) return -1;
PyObject *version_info = PySys_GetObject("version_info"); version_hex = PyInt_AsLong(sys_hexversion);
if (version_info == NULL) goto bad; if (version_hex == -1 && PyErr_Occurred()) return -1;
major_info = PySequence_GetItem(version_info, 0); major_version = ((unsigned long)version_hex >> 24);
if (major_info == NULL || !PyInt_CheckExact(major_info)) goto bad; minor_version = ((unsigned long)version_hex >> 16) & 0x00FF;
minor_info = PySequence_GetItem(version_info, 1); if (!(major_version == PY_MAJOR_VERSION && minor_version == PY_MINOR_VERSION)) {
if (minor_info == NULL || !PyInt_CheckExact(minor_info)) goto bad; char message[200];
if (PyInt_AsLong(major_info) == PY_MAJOR_VERSION && PyInt_AsLong(minor_info) == PY_MINOR_VERSION) { PyOS_snprintf(message, sizeof(message),
res = 0; "compiletime version (%d, %d) of module '%.100s' does not match runtime version (%d, %d).",
} else { PY_MAJOR_VERSION, PY_MINOR_VERSION, __Pyx_MODULE_NAME, (int)major_version, (int)minor_version);
char warning[200];
PyOS_snprintf(warning, sizeof(warning),
"compiletime version (%d, %d) of module %s does not match runtime version (%ld, %ld)",
PY_MAJOR_VERSION, PY_MINOR_VERSION,
__Pyx_MODULE_NAME,
PyInt_AsLong(major_info), PyInt_AsLong(minor_info));
#if PY_VERSION_HEX < 0x02050000 #if PY_VERSION_HEX < 0x02050000
PyErr_Warn(NULL, warning); return PyErr_Warn(NULL, message);
#else #else
PyErr_WarnEx(NULL, warning, 0); return PyErr_WarnEx(NULL, message, 1);
#endif #endif
res = 1;
} }
bad: return 0;
Py_XDECREF(major_info);
Py_XDECREF(minor_info);
return res;
} }
""") """)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment