svn merge -r39834:40222 https://svn.blender.org/svnroot/bf-blender/trunk/blender
This commit is contained in:
@@ -344,7 +344,7 @@ void bpy_text_clear_modules(int clear_all)
|
||||
|
||||
/* looping over the dict */
|
||||
PyObject *key, *value;
|
||||
int pos= 0;
|
||||
Py_ssize_t pos= 0;
|
||||
|
||||
/* new list */
|
||||
PyObject *list;
|
||||
@@ -374,7 +374,7 @@ void bpy_text_clear_modules(int clear_all)
|
||||
}
|
||||
|
||||
/* remove all our modules */
|
||||
for(pos=0; pos < PyList_Size(list); pos++) {
|
||||
for(pos=0; pos < PyList_GET_SIZE(list); pos++) {
|
||||
/* PyObject_Print(key, stderr, 0); */
|
||||
key= PyList_GET_ITEM(list, pos);
|
||||
PyDict_DelItem(modules, key);
|
||||
|
@@ -208,7 +208,77 @@ PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...)
|
||||
return item;
|
||||
}
|
||||
|
||||
/* returns the exception string as a new PyUnicode object, depends on external StringIO module */
|
||||
/* similar to PyErr_Format(),
|
||||
*
|
||||
* implimentation - we cant actually preprend the existing exception,
|
||||
* because it could have _any_ argiments given to it, so instead we get its
|
||||
* __str__ output and raise our own exception including it.
|
||||
*/
|
||||
PyObject *PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *format, ...)
|
||||
{
|
||||
PyObject *error_value_prefix;
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
error_value_prefix= PyUnicode_FromFormatV(format, args); /* can fail and be NULL */
|
||||
va_end(args);
|
||||
|
||||
if(PyErr_Occurred()) {
|
||||
PyObject *error_type, *error_value, *error_traceback;
|
||||
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
||||
PyErr_Format(exception_type_prefix,
|
||||
"%S, %.200s(%S)",
|
||||
error_value_prefix,
|
||||
Py_TYPE(error_value)->tp_name,
|
||||
error_value
|
||||
);
|
||||
}
|
||||
else {
|
||||
PyErr_SetObject(exception_type_prefix,
|
||||
error_value_prefix
|
||||
);
|
||||
}
|
||||
|
||||
Py_XDECREF(error_value_prefix);
|
||||
|
||||
/* dumb to always return NULL but matches PyErr_Format */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* returns the exception string as a new PyUnicode object, depends on external traceback module */
|
||||
#if 0
|
||||
|
||||
/* this version uses traceback module but somehow fails on UI errors */
|
||||
|
||||
PyObject *PyC_ExceptionBuffer(void)
|
||||
{
|
||||
PyObject *traceback_mod= NULL;
|
||||
PyObject *format_tb_func= NULL;
|
||||
PyObject *ret= NULL;
|
||||
|
||||
if(! (traceback_mod= PyImport_ImportModule("traceback")) ) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
else if (! (format_tb_func= PyObject_GetAttrString(traceback_mod, "format_exc"))) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
ret= PyObject_CallObject(format_tb_func, NULL);
|
||||
|
||||
if(ret == Py_None) {
|
||||
Py_DECREF(ret);
|
||||
ret= NULL;
|
||||
}
|
||||
|
||||
error_cleanup:
|
||||
/* could not import the module so print the error and close */
|
||||
Py_XDECREF(traceback_mod);
|
||||
Py_XDECREF(format_tb_func);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#else /* verbose, non-threadsafe version */
|
||||
PyObject *PyC_ExceptionBuffer(void)
|
||||
{
|
||||
PyObject *stdout_backup = PySys_GetObject("stdout"); /* borrowed */
|
||||
@@ -217,20 +287,20 @@ PyObject *PyC_ExceptionBuffer(void)
|
||||
PyObject *string_io_buf = NULL;
|
||||
PyObject *string_io_mod= NULL;
|
||||
PyObject *string_io_getvalue= NULL;
|
||||
|
||||
|
||||
PyObject *error_type, *error_value, *error_traceback;
|
||||
|
||||
|
||||
if (!PyErr_Occurred())
|
||||
return NULL;
|
||||
|
||||
|
||||
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
||||
|
||||
|
||||
PyErr_Clear();
|
||||
|
||||
|
||||
/* import io
|
||||
* string_io = io.StringIO()
|
||||
*/
|
||||
|
||||
|
||||
if(! (string_io_mod= PyImport_ImportModule("io")) ) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
@@ -240,44 +310,45 @@ PyObject *PyC_ExceptionBuffer(void)
|
||||
else if (! (string_io_getvalue= PyObject_GetAttrString(string_io, "getvalue"))) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
|
||||
Py_INCREF(stdout_backup); // since these were borrowed we dont want them freed when replaced.
|
||||
Py_INCREF(stderr_backup);
|
||||
|
||||
|
||||
PySys_SetObject("stdout", string_io); // both of these are free'd when restoring
|
||||
PySys_SetObject("stderr", string_io);
|
||||
|
||||
|
||||
PyErr_Restore(error_type, error_value, error_traceback);
|
||||
PyErr_Print(); /* print the error */
|
||||
PyErr_Clear();
|
||||
|
||||
|
||||
string_io_buf = PyObject_CallObject(string_io_getvalue, NULL);
|
||||
|
||||
|
||||
PySys_SetObject("stdout", stdout_backup);
|
||||
PySys_SetObject("stderr", stderr_backup);
|
||||
|
||||
|
||||
Py_DECREF(stdout_backup); /* now sys owns the ref again */
|
||||
Py_DECREF(stderr_backup);
|
||||
|
||||
|
||||
Py_DECREF(string_io_mod);
|
||||
Py_DECREF(string_io_getvalue);
|
||||
Py_DECREF(string_io); /* free the original reference */
|
||||
|
||||
|
||||
PyErr_Clear();
|
||||
return string_io_buf;
|
||||
|
||||
|
||||
|
||||
|
||||
error_cleanup:
|
||||
/* could not import the module so print the error and close */
|
||||
Py_XDECREF(string_io_mod);
|
||||
Py_XDECREF(string_io);
|
||||
|
||||
|
||||
PyErr_Restore(error_type, error_value, error_traceback);
|
||||
PyErr_Print(); /* print the error */
|
||||
PyErr_Clear();
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* string conversion, escape non-unicode chars, coerce must be set to NULL */
|
||||
|
@@ -34,6 +34,7 @@ void PyC_ObSpit(const char *name, PyObject *var);
|
||||
void PyC_LineSpit(void);
|
||||
PyObject * PyC_ExceptionBuffer(void);
|
||||
PyObject * PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...);
|
||||
PyObject * PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *format, ...);
|
||||
void PyC_FileAndNum(const char **filename, int *lineno);
|
||||
int PyC_AsArray(void *array, PyObject *value, const int length, const PyTypeObject *type, const short is_double, const char *error_prefix);
|
||||
|
||||
|
Reference in New Issue
Block a user