diff options
author | Campbell Barton <campbell@blender.org> | 2022-05-03 10:54:37 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-05-03 11:22:54 +0300 |
commit | 74dfb7ca23b73b714b73bfaf3553d05fbbc2a29c (patch) | |
tree | 9325eafff8b5771183b2d31dc388be6e8106bb61 /source/blender/python/generic | |
parent | a821a2db3d5e4c5a302de677a127a662942c46ae (diff) |
Fix T97731: Python traceback no longer includes line-numbers
Regression caused by [0] that caused the error message to be
created based on a normalized exception (which hid line numbers).
PyC_ExceptionBuffer{_Simple} & BPy_errors_to_report
no longer clears the exception.
This could have been resolved by changing python_script_error_jump
however that would involve changes to reference counting that are more
risky (noted in code-comment).
[0]: 2d2baeaf04d481f284bc2f098fb6d7ee9268151f
Diffstat (limited to 'source/blender/python/generic')
-rw-r--r-- | source/blender/python/generic/py_capi_utils.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 3b64fb23460..d2e3c44c1b6 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -892,6 +892,10 @@ PyObject *PyC_ExceptionBuffer(void) PySys_SetObject("stderr", string_io); PyErr_Restore(error_type, error_value, error_traceback); + /* Printing clears (call #PyErr_Clear as well to ensure it's cleared). */ + Py_XINCREF(error_type); + Py_XINCREF(error_value); + Py_XINCREF(error_traceback); PyErr_Print(); /* print the error */ PyErr_Clear(); @@ -907,17 +911,18 @@ PyObject *PyC_ExceptionBuffer(void) Py_DECREF(string_io_getvalue); Py_DECREF(string_io); /* free the original reference */ - PyErr_Clear(); + PyErr_Restore(error_type, error_value, error_traceback); + return string_io_buf; error_cleanup: - /* could not import the module so print the error and close */ + /* 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(); + PyErr_Restore(error_type, error_value, error_traceback); return NULL; } @@ -925,19 +930,15 @@ error_cleanup: PyObject *PyC_ExceptionBuffer_Simple(void) { - PyObject *string_io_buf = NULL; - - PyObject *error_type, *error_value, *error_traceback; - if (!PyErr_Occurred()) { return NULL; } - PyErr_Fetch(&error_type, &error_value, &error_traceback); + PyObject *string_io_buf = NULL; - if (error_value == NULL) { - return NULL; - } + PyObject *error_type, *error_value, *error_traceback; + + PyErr_Fetch(&error_type, &error_value, &error_traceback); if (PyErr_GivenExceptionMatches(error_type, PyExc_SyntaxError)) { /* Special exception for syntax errors, @@ -959,7 +960,6 @@ PyObject *PyC_ExceptionBuffer_Simple(void) PyErr_Restore(error_type, error_value, error_traceback); - PyErr_Clear(); return string_io_buf; } |