PyAPI: don't use deprecated PyModule_GetFilename
Allows compiling with newer Python versions. Also add missing decref when compiling as a py-module.
This commit is contained in:
@@ -248,8 +248,17 @@ PyObject *bpy_text_reimport(PyObject *module, int *found)
|
||||
if ((name = PyModule_GetName(module)) == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((filepath = (char *)PyModule_GetFilename(module)) == NULL)
|
||||
return NULL;
|
||||
{
|
||||
PyObject *module_file = PyModule_GetFilenameObject(module);
|
||||
if (module_file == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
filepath = (char *)_PyUnicode_AsString(module_file);
|
||||
Py_DECREF(module_file);
|
||||
if (filepath == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* look up the text object */
|
||||
text = BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2);
|
||||
|
@@ -300,7 +300,14 @@ void PyC_FileAndNum(const char **filename, int *lineno)
|
||||
if (mod_name) {
|
||||
PyObject *mod = PyDict_GetItem(PyImport_GetModuleDict(), mod_name);
|
||||
if (mod) {
|
||||
*filename = PyModule_GetFilename(mod);
|
||||
PyObject *mod_file = PyModule_GetFilenameObject(mod);
|
||||
if (mod_file) {
|
||||
*filename = _PyUnicode_AsString(mod_name);
|
||||
Py_DECREF(mod_file);
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/* unlikely, fallback */
|
||||
|
Reference in New Issue
Block a user