Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e817acd

Browse files
committed
Patch by Jack Jansen:
If we attempt to import a dynamic module in a newer (or older) version of Python give an error message tailored to the situation (Python too new/old).
1 parent a505812 commit e817acd

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Python/dynload_mac.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
114114
err = GetDiskFragment(&libspec, 0, 0, fragname,
115115
kLoadCFrag, &connID, &mainAddr,
116116
errMessage);
117+
if ( err == cfragImportTooOldErr || err == cfragImportTooNewErr ) {
118+
/*
119+
** Special-case code: if PythonCore is too old or too new this means
120+
** the dynamic module was meant for a different Python.
121+
*/
122+
if (errMessage[0] == 10 && strncmp((char *)errMessage+1, "PythonCore", 10) == 0 ) {
123+
sprintf(buf, "Dynamic module was built for %s version of MacPython",
124+
(err == cfragImportTooOldErr ? "a newer" : "an older"));
125+
PyErr_SetString(PyExc_ImportError, buf);
126+
return NULL;
127+
}
128+
}
117129
if ( err ) {
118130
sprintf(buf, "%.*s: %.200s",
119131
errMessage[0], errMessage+1,

0 commit comments

Comments
 (0)