diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-08-14 09:33:20 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-08-14 09:33:20 +0400 |
commit | 04f619d8af6ddc7de541488f77713818e18a886e (patch) | |
tree | 9c78fc1f7cb6a7bc4544bd7e1f4f2bbf39ee8752 /source | |
parent | ae6a63253499eb83f5e6c260e598e7f8fd0cae13 (diff) |
- PyLineSpit() - used to print the filename and line number for internal errors now works when executing class functions in a module.
- replaced PySys_GetObject("modules") with PyImport_GetModuleDict()
- use defaults for keymap import/export rather then setting the same value every time from the UI scripts.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/generic/bgl.c | 2 | ||||
-rw-r--r-- | source/blender/python/generic/blf_api.c | 2 | ||||
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.c | 2 | ||||
-rw-r--r-- | source/blender/python/generic/geometry.c | 2 | ||||
-rw-r--r-- | source/blender/python/generic/mathutils.c | 2 | ||||
-rw-r--r-- | source/blender/python/generic/noise.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_props.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_util.c | 26 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_util.h | 2 |
11 files changed, 33 insertions, 13 deletions
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index bb0b3a43186..8ac2107f8d2 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -1117,7 +1117,7 @@ PyObject *BGL_Init(void) { PyObject *mod, *dict, *item; mod = PyModule_Create(&BGL_module_def); - PyDict_SetItemString(PySys_GetObject("modules"), BGL_module_def.m_name, mod); + PyDict_SetItemString(PyImport_GetModuleDict(), BGL_module_def.m_name, mod); dict= PyModule_GetDict(mod); if( PyType_Ready( &BGL_bufferType) < 0) diff --git a/source/blender/python/generic/blf_api.c b/source/blender/python/generic/blf_api.c index 9e4ce1f057d..762153b8349 100644 --- a/source/blender/python/generic/blf_api.c +++ b/source/blender/python/generic/blf_api.c @@ -394,7 +394,7 @@ PyObject *BLF_Init(void) PyObject *submodule; submodule = PyModule_Create(&BLF_module_def); - PyDict_SetItemString(PySys_GetObject("modules"), BLF_module_def.m_name, submodule); + PyDict_SetItemString(PyImport_GetModuleDict(), BLF_module_def.m_name, submodule); PyModule_AddIntConstant(submodule, "ROTATION", BLF_ROTATION); PyModule_AddIntConstant(submodule, "CLIPPING", BLF_CLIPPING); diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index 0bcecafd23c..1951e72567c 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -304,7 +304,7 @@ PyMethodDef bpy_reload_meth[] = { {"bpy_reload_meth", (PyCFunction)blender_reloa void bpy_text_clear_modules(int clear_all) { - PyObject *modules= PySys_GetObject("modules"); + PyObject *modules= PyImport_GetModuleDict(); char *fname; char *file_extension; diff --git a/source/blender/python/generic/geometry.c b/source/blender/python/generic/geometry.c index 1e8436ed5ae..0e98760314d 100644 --- a/source/blender/python/generic/geometry.c +++ b/source/blender/python/generic/geometry.c @@ -835,7 +835,7 @@ PyObject *Geometry_Init(void) PyObject *submodule; submodule = PyModule_Create(&M_Geometry_module_def); - PyDict_SetItemString(PySys_GetObject("modules"), M_Geometry_module_def.m_name, submodule); + PyDict_SetItemString(PyImport_GetModuleDict(), M_Geometry_module_def.m_name, submodule); return (submodule); } diff --git a/source/blender/python/generic/mathutils.c b/source/blender/python/generic/mathutils.c index ada5bac8c2a..a643e6621b2 100644 --- a/source/blender/python/generic/mathutils.c +++ b/source/blender/python/generic/mathutils.c @@ -258,7 +258,7 @@ PyObject *Mathutils_Init(void) return NULL; submodule = PyModule_Create(&M_Mathutils_module_def); - PyDict_SetItemString(PySys_GetObject("modules"), M_Mathutils_module_def.m_name, submodule); + PyDict_SetItemString(PyImport_GetModuleDict(), M_Mathutils_module_def.m_name, submodule); /* each type has its own new() function */ PyModule_AddObject( submodule, "Vector", (PyObject *)&vector_Type ); diff --git a/source/blender/python/generic/noise.c b/source/blender/python/generic/noise.c index b07950099a3..4a09cbb58d8 100644 --- a/source/blender/python/generic/noise.c +++ b/source/blender/python/generic/noise.c @@ -658,7 +658,7 @@ static struct PyModuleDef noise_module_def = { PyObject *Noise_Init(void) { PyObject *submodule = PyModule_Create(&noise_module_def); - PyDict_SetItemString(PySys_GetObject("modules"), noise_module_def.m_name, submodule); + PyDict_SetItemString(PyImport_GetModuleDict(), noise_module_def.m_name, submodule); /* use current time as seed for random number generator by default */ setRndSeed(0); diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c index 7ca1b365c6f..c86ebc7f691 100644 --- a/source/blender/python/intern/bpy.c +++ b/source/blender/python/intern/bpy.c @@ -158,7 +158,7 @@ void BPy_init_modules( void ) mod = PyModule_New("_bpy"); /* add the module so we can import it */ - PyDict_SetItemString(PySys_GetObject("modules"), "_bpy", mod); + PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy", mod); Py_DECREF(mod); /* run first, initializes rna types */ diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index d92044b027e..c6c34fbcaf5 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -259,7 +259,7 @@ PyObject *BPY_operator_module( void ) static PyMethodDef pyop_macro_def_meth ={"macro_define", (PyCFunction) PYOP_wrap_macro_define, METH_VARARGS, NULL}; PyObject *submodule = PyModule_New("_bpy.ops"); - PyDict_SetItemString(PySys_GetObject("modules"), "_bpy.ops", submodule); + PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy.ops", submodule); PyModule_AddObject( submodule, "call", PyCFunction_New(&pyop_call_meth, NULL) ); PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth,NULL) ); diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index c278ad56ab9..9afe638908c 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -919,7 +919,7 @@ PyObject *BPY_rna_props( void ) { PyObject *submodule; submodule= PyModule_Create(&props_module); - PyDict_SetItemString(PySys_GetObject("modules"), props_module.m_name, submodule); + PyDict_SetItemString(PyImport_GetModuleDict(), props_module.m_name, submodule); /* INCREF since its its assumed that all these functions return the * module with a new ref like PyDict_New, since they are passed to diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c index 38462d1b176..1d14ab67510 100644 --- a/source/blender/python/intern/bpy_util.c +++ b/source/blender/python/intern/bpy_util.c @@ -54,7 +54,7 @@ void PyObSpit(char *name, PyObject *var) { } void PyLineSpit(void) { - char *filename; + const char *filename; int lineno; PyErr_Clear(); @@ -63,7 +63,7 @@ void PyLineSpit(void) { fprintf(stderr, "%s:%d\n", filename, lineno); } -void BPY_getFileAndNum(char **filename, int *lineno) +void BPY_getFileAndNum(const char **filename, int *lineno) { PyObject *getframe, *frame; PyObject *f_lineno= NULL, *co_filename= NULL; @@ -83,6 +83,7 @@ void BPY_getFileAndNum(char **filename, int *lineno) return; } + /* when executing a script */ if (filename) { co_filename= PyObject_GetAttrStringArgs(frame, 1, "f_code", "co_filename"); if (co_filename==NULL) { @@ -95,6 +96,25 @@ void BPY_getFileAndNum(char **filename, int *lineno) Py_DECREF(co_filename); } + /* when executing a module */ + if(filename && *filename == NULL) { + /* try an alternative method to get the filename - module based + * references below are all borrowed (double checked) */ + PyObject *mod_name= PyDict_GetItemString(PyEval_GetGlobals(), "__name__"); + if(mod_name) { + PyObject *mod= PyDict_GetItem(PyImport_GetModuleDict(), mod_name); + if(mod) { + *filename= PyModule_GetFilename(mod); + } + + /* unlikely, fallback */ + if(*filename == NULL) { + *filename= _PyUnicode_AsString(mod_name); + } + } + } + + if (lineno) { f_lineno= PyObject_GetAttrString(frame, "f_lineno"); if (f_lineno==NULL) { @@ -330,7 +350,7 @@ int BPy_errors_to_report(ReportList *reports) PyObject *pystring_format= NULL; // workaround, see below char *cstring; - char *filename; + const char *filename; int lineno; if (!PyErr_Occurred()) diff --git a/source/blender/python/intern/bpy_util.h b/source/blender/python/intern/bpy_util.h index e7e7bb09419..cfe820b53b0 100644 --- a/source/blender/python/intern/bpy_util.h +++ b/source/blender/python/intern/bpy_util.h @@ -38,7 +38,7 @@ struct ReportList; void PyObSpit(char *name, PyObject *var); void PyLineSpit(void); -void BPY_getFileAndNum(char **filename, int *lineno); +void BPY_getFileAndNum(const char **filename, int *lineno); PyObject *BPY_exception_buffer(void); |