- 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.
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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) );
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user