From 4a598d1c9c438e59c71b3431f39b1350c5d611cb Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Wed, 23 Feb 2011 12:14:01 -0300 Subject: [PATCH] even better __Pyx_check_binary_version() --- Cython/Compiler/ModuleNode.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 40010aed..b26c6e9c 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2858,18 +2858,15 @@ check_binary_version_utility_code = UtilityCode(proto=""" static int __Pyx_check_binary_version(void); """, impl=""" static int __Pyx_check_binary_version(void) { - 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 ctversion[4], rtversion[4]; + PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); + PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); + if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { 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); + "compiletime version %s of module '%.100s' " + "does not match runtime version %s", + ctversion, __Pyx_MODULE_NAME, rtversion); #if PY_VERSION_HEX < 0x02050000 return PyErr_Warn(NULL, message); #else -- 2.26.2