PyAPI: don't use deprecated PyModule_GetFilename
authorCampbell Barton <ideasman42@gmail.com>
Mon, 17 Jul 2017 02:44:03 +0000 (12:44 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 17 Jul 2017 02:53:55 +0000 (12:53 +1000)
Allows compiling with newer Python versions.
Also add missing decref when compiling as a py-module.

source/blender/python/generic/bpy_internal_import.c
source/blender/python/generic/py_capi_utils.c
source/blender/python/intern/bpy_interface.c

index ed2752d..7ab6447 100644 (file)
@@ -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);
index 2e789d6..861e2db 100644 (file)
@@ -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 */
index 7b0daa9..20cfd36 100644 (file)
@@ -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;