Complile/runtime version mismatch warning.
authorRobert Bradshaw <robertwb@math.washington.edu>
Sat, 19 Feb 2011 23:12:51 +0000 (15:12 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sat, 19 Feb 2011 23:12:51 +0000 (15:12 -0800)
Cython/Compiler/ModuleNode.py
Cython/Compiler/Options.py

index 72721b6ac8fb7f095643f156e503d167bda1786a..5d13c35d7302f4dc8f0577233e68ef2609457c86 100644 (file)
@@ -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;
+}
+""")
index 52b26b8d28d0351ef411e0fd9bc072fd055f7c78..2c8c9735757ecf6ca918ee1ae00e1993ac915c6f 100644 (file)
@@ -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