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:
Campbell Barton 2017-07-17 12:44:03 +10:00
parent 4e22e24689
commit 3d1e5bca88
3 changed files with 20 additions and 3 deletions

@ -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 */

@ -869,6 +869,7 @@ static void bpy_module_delay_init(PyObject *bpy_proxy)
BLI_strncpy(filename_abs, filename_rel, sizeof(filename_abs));
BLI_path_cwd(filename_abs, sizeof(filename_abs));
Py_DECREF(filename_obj);
argv[0] = filename_abs;
argv[1] = NULL;