From: Robert Bradshaw Date: Sat, 19 Feb 2011 23:12:51 +0000 (-0800) Subject: Complile/runtime version mismatch warning. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4fc682ab92315394df9d1e1551ea67e3a7bbbbb3;p=cython.git Complile/runtime version mismatch warning. --- diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 72721b6a..5d13c35d 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -1744,6 +1744,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("#endif") code.putln("{") tempdecl_code = code.insertion_point() + + env.use_utility_code(check_binary_version_utility_code) + code.putln("__Pyx_check_binary_version();") code.putln("#if CYTHON_REFNANNY") code.putln("void* __pyx_refnanny = NULL;") @@ -2850,3 +2853,40 @@ packed_struct_utility_code = UtilityCode(proto=""" #define __Pyx_PACKED #endif """, impl="", proto_block='utility_code_proto_before_types') + +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)); + #if PY_VERSION_HEX < 0x02050000 + PyErr_Warn(NULL, warning); + #else + PyErr_WarnEx(NULL, warning, 0); + #endif + res = 1; + } +bad: + Py_XDECREF(version_info); + Py_XDECREF(major_info); + Py_XDECREF(minor_info); + return res; +} +""") diff --git a/Cython/Compiler/Options.py b/Cython/Compiler/Options.py index 52b26b8d..2c8c9735 100644 --- a/Cython/Compiler/Options.py +++ b/Cython/Compiler/Options.py @@ -45,7 +45,8 @@ init_local_none = 1 # Whether or not to embed the Python interpreter, for use in making a # standalone executable or calling from external libraries. -# This will provide a method which simply executes the body of this module. +# This will provide a method which initalizes the interpreter and +# executes the body of this module. embed = None # Disables function redefinition, allowing all functions to be declared at