Skip to content

Commit 2402594

Browse files
committed
interrogatedb: Fix faulty version comparison in Python 3.10
1 parent dabab90 commit 2402594

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

dtool/src/interrogatedb/py_panda.cxx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
#ifdef HAVE_PYTHON
1212

13+
#define _STRINGIFY_VERSION(a, b) (#a "." #b)
14+
#define STRINGIFY_VERSION(a, b) _STRINGIFY_VERSION(a, b)
15+
1316
using std::string;
1417

1518
/**
@@ -531,22 +534,27 @@ Dtool_TypeMap *Dtool_GetGlobalTypeMap() {
531534
}
532535
}
533536

537+
#define PY_MAJOR_VERSION_STR #PY_MAJOR_VERSION "." #PY_MINOR_VERSION
538+
534539
#if PY_MAJOR_VERSION >= 3
535540
PyObject *Dtool_PyModuleInitHelper(const LibraryDef *defs[], PyModuleDef *module_def) {
536541
#else
537542
PyObject *Dtool_PyModuleInitHelper(const LibraryDef *defs[], const char *modulename) {
538543
#endif
539544
// Check the version so we can print a helpful error if it doesn't match.
540545
string version = Py_GetVersion();
546+
size_t version_len = version.find('.', 2);
547+
if (version_len != string::npos) {
548+
version.resize(version_len);
549+
}
541550

542-
if (version[0] != '0' + PY_MAJOR_VERSION ||
543-
version[2] != '0' + PY_MINOR_VERSION) {
551+
if (version != STRINGIFY_VERSION(PY_MAJOR_VERSION, PY_MINOR_VERSION)) {
544552
// Raise a helpful error message. We can safely do this because the
545553
// signature and behavior for PyErr_SetString has remained consistent.
546554
std::ostringstream errs;
547555
errs << "this module was compiled for Python "
548556
<< PY_MAJOR_VERSION << "." << PY_MINOR_VERSION << ", which is "
549-
<< "incompatible with Python " << version.substr(0, 3);
557+
<< "incompatible with Python " << version;
550558
string error = errs.str();
551559
PyErr_SetString(PyExc_ImportError, error.c_str());
552560
return nullptr;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy