From 3d1e5bca88149fb6ce41d0d67174795de36b157b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 17 Jul 2017 12:44:03 +1000 Subject: PyAPI: don't use deprecated PyModule_GetFilename Allows compiling with newer Python versions. Also add missing decref when compiling as a py-module. --- source/blender/python/generic/bpy_internal_import.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'source/blender/python/generic/bpy_internal_import.c') diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index ed2752d8372..7ab6447d21a 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -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); -- cgit v1.2.3 From 92272f56e67e2fa0fa6c2ad764641cbb41c92507 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 4 Oct 2017 15:54:41 +1100 Subject: PyAPI: fast keyword parsing for __import__ No functional changes. --- source/blender/python/generic/bpy_internal_import.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source/blender/python/generic/bpy_internal_import.c') diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index 7ab6447d21a..582a0d22d2f 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -285,13 +285,13 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject int found = 0; PyObject *globals = NULL, *locals = NULL, *fromlist = NULL; int level = 0; /* relative imports */ - PyObject *newmodule; - //PyObject_Print(args, stderr, 0); - static const char *kwlist[] = {"name", "globals", "locals", "fromlist", "level", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kw, "s|OOOi:bpy_import_meth", (char **)kwlist, - &name, &globals, &locals, &fromlist, &level)) + + static const char *_keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL}; + static _PyArg_Parser _parser = {"s|OOOi:bpy_import_meth", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kw, &_parser, + &name, &globals, &locals, &fromlist, &level)) { return NULL; } -- cgit v1.2.3 From 08f728a3e91a7c62946847e89632390c400d55ea Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 4 Oct 2017 16:44:45 +1100 Subject: Cleanup: redundant casts --- source/blender/python/generic/bpy_internal_import.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/python/generic/bpy_internal_import.c') diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index 582a0d22d2f..ffac09efdde 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -253,7 +253,7 @@ PyObject *bpy_text_reimport(PyObject *module, int *found) if (module_file == NULL) { return NULL; } - filepath = (char *)_PyUnicode_AsString(module_file); + filepath = _PyUnicode_AsString(module_file); Py_DECREF(module_file); if (filepath == NULL) { return NULL; -- cgit v1.2.3