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):
code.putln("#endif")
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 = 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="""
static int __Pyx_check_binary_version(void);
""", impl="""
static int __Pyx_check_binary_version(void) {
int res = -1;
PyObject *major_info = NULL;
PyObject *minor_info = NULL;
PyObject *version_info = PySys_GetObject("version_info");
if (version_info == NULL) goto bad;
major_info = PySequence_GetItem(version_info, 0);
if (major_info == NULL || !PyInt_CheckExact(major_info)) goto bad;
minor_info = PySequence_GetItem(version_info, 1);
if (minor_info == NULL || !PyInt_CheckExact(minor_info)) goto bad;
if (PyInt_AsLong(major_info) == PY_MAJOR_VERSION && PyInt_AsLong(minor_info) == PY_MINOR_VERSION) {
res = 0;
} else {
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));
long version_hex, major_version, minor_version;
PyObject *sys_hexversion = PySys_GetObject((char*)"hexversion");
if (sys_hexversion == NULL) return -1;
version_hex = PyInt_AsLong(sys_hexversion);
if (version_hex == -1 && PyErr_Occurred()) return -1;
major_version = ((unsigned long)version_hex >> 24);
minor_version = ((unsigned long)version_hex >> 16) & 0x00FF;
if (!(major_version == PY_MAJOR_VERSION && minor_version == PY_MINOR_VERSION)) {
char message[200];
PyOS_snprintf(message, sizeof(message),
"compiletime version (%d, %d) of module '%.100s' does not match runtime version (%d, %d).",
PY_MAJOR_VERSION, PY_MINOR_VERSION, __Pyx_MODULE_NAME, (int)major_version, (int)minor_version);
#if PY_VERSION_HEX < 0x02050000
PyErr_Warn(NULL, warning);
return PyErr_Warn(NULL, message);
#else
PyErr_WarnEx(NULL, warning, 0);
return PyErr_WarnEx(NULL, message, 1);
#endif
res = 1;
}
bad:
Py_XDECREF(major_info);
Py_XDECREF(minor_info);
return res;
return 0;
}
""")
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