mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-28 07:48:37 -04:00
interrogatedb: Fix faulty version comparison in Python 3.10
This commit is contained in:
parent
dabab90415
commit
2402594808
@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
|
|
||||||
|
#define _STRINGIFY_VERSION(a, b) (#a "." #b)
|
||||||
|
#define STRINGIFY_VERSION(a, b) _STRINGIFY_VERSION(a, b)
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -531,6 +534,8 @@ Dtool_TypeMap *Dtool_GetGlobalTypeMap() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PY_MAJOR_VERSION_STR #PY_MAJOR_VERSION "." #PY_MINOR_VERSION
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3
|
||||||
PyObject *Dtool_PyModuleInitHelper(const LibraryDef *defs[], PyModuleDef *module_def) {
|
PyObject *Dtool_PyModuleInitHelper(const LibraryDef *defs[], PyModuleDef *module_def) {
|
||||||
#else
|
#else
|
||||||
@ -538,15 +543,18 @@ PyObject *Dtool_PyModuleInitHelper(const LibraryDef *defs[], const char *modulen
|
|||||||
#endif
|
#endif
|
||||||
// Check the version so we can print a helpful error if it doesn't match.
|
// Check the version so we can print a helpful error if it doesn't match.
|
||||||
string version = Py_GetVersion();
|
string version = Py_GetVersion();
|
||||||
|
size_t version_len = version.find('.', 2);
|
||||||
|
if (version_len != string::npos) {
|
||||||
|
version.resize(version_len);
|
||||||
|
}
|
||||||
|
|
||||||
if (version[0] != '0' + PY_MAJOR_VERSION ||
|
if (version != STRINGIFY_VERSION(PY_MAJOR_VERSION, PY_MINOR_VERSION)) {
|
||||||
version[2] != '0' + PY_MINOR_VERSION) {
|
|
||||||
// Raise a helpful error message. We can safely do this because the
|
// Raise a helpful error message. We can safely do this because the
|
||||||
// signature and behavior for PyErr_SetString has remained consistent.
|
// signature and behavior for PyErr_SetString has remained consistent.
|
||||||
std::ostringstream errs;
|
std::ostringstream errs;
|
||||||
errs << "this module was compiled for Python "
|
errs << "this module was compiled for Python "
|
||||||
<< PY_MAJOR_VERSION << "." << PY_MINOR_VERSION << ", which is "
|
<< PY_MAJOR_VERSION << "." << PY_MINOR_VERSION << ", which is "
|
||||||
<< "incompatible with Python " << version.substr(0, 3);
|
<< "incompatible with Python " << version;
|
||||||
string error = errs.str();
|
string error = errs.str();
|
||||||
PyErr_SetString(PyExc_ImportError, error.c_str());
|
PyErr_SetString(PyExc_ImportError, error.c_str());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user