Commit: 397cec6a4dad6784604622ee707bb74a2e6a92a1
Author: Campbell Barton
Date:   Mon Aug 17 17:21:11 2020 +1000
Branches: master
https://developer.blender.org/rB397cec6a4dad6784604622ee707bb74a2e6a92a1

Cleanup: Pass 'FILE *' instead of 'void *' for BPY_python_backtrace

This was committed as a temporary workaround in 82150f5641364
as release builds were failing (only debug builds worked).

This adds `stdio.h` to the header which is now split into a file that
contains more specialized functionality.

Also move function body inside BPY_python_backtrace,
removing PyC_StackPrint as we have PyC_StackSpit() for
similar functionality that can be called from a debugger.

===================================================================

M       source/blender/python/BPY_extern_python.h
M       source/blender/python/generic/py_capi_utils.c
M       source/blender/python/generic/py_capi_utils.h
M       source/blender/python/intern/bpy_interface.c

===================================================================

diff --git a/source/blender/python/BPY_extern_python.h 
b/source/blender/python/BPY_extern_python.h
index d6033f86d37..348f6986863 100644
--- a/source/blender/python/BPY_extern_python.h
+++ b/source/blender/python/BPY_extern_python.h
@@ -28,12 +28,15 @@ struct bContext;
 extern "C" {
 #endif
 
+/* For 'FILE'. */
+#include <stdio.h>
+
 /* bpy_interface.c */
 void BPY_python_start(int argc, const char **argv);
 void BPY_python_end(void);
 void BPY_python_reset(struct bContext *C);
 void BPY_python_use_system_env(void);
-void BPY_python_backtrace(/* FILE */ void *file);
+void BPY_python_backtrace(FILE *file);
 
 #ifdef __cplusplus
 } /* extern "C" */
diff --git a/source/blender/python/generic/py_capi_utils.c 
b/source/blender/python/generic/py_capi_utils.c
index caae5c4e122..838a1239210 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -382,20 +382,6 @@ void PyC_StackSpit(void)
   PyGILState_Release(gilstate);
 }
 
-void PyC_StackPrint(/* FILE */ void *fp)
-{
-  PyThreadState *tstate = PyGILState_GetThisThreadState();
-  if (tstate != NULL && tstate->frame != NULL) {
-    PyFrameObject *frame = tstate->frame;
-    do {
-      const int line = PyCode_Addr2Line(frame->f_code, frame->f_lasti);
-      const char *filename = _PyUnicode_AsString(frame->f_code->co_filename);
-      const char *funcname = _PyUnicode_AsString(frame->f_code->co_name);
-      fprintf(fp, "  File \"%s\", line %d in %s\n", filename, line, funcname);
-    } while ((frame = frame->f_back));
-  }
-}
-
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/python/generic/py_capi_utils.h 
b/source/blender/python/generic/py_capi_utils.h
index dde450012d0..e8b2e8ff502 100644
--- a/source/blender/python/generic/py_capi_utils.h
+++ b/source/blender/python/generic/py_capi_utils.h
@@ -28,7 +28,6 @@ void PyC_ObSpit(const char *name, PyObject *var);
 void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var);
 void PyC_LineSpit(void);
 void PyC_StackSpit(void);
-void PyC_StackPrint(/* FILE */ void *fp);
 PyObject *PyC_ExceptionBuffer(void);
 PyObject *PyC_ExceptionBuffer_Simple(void);
 PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...);
diff --git a/source/blender/python/intern/bpy_interface.c 
b/source/blender/python/intern/bpy_interface.c
index 098f6202d9b..81e1905bed7 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -25,6 +25,7 @@
  */
 
 #include <Python.h>
+#include <frameobject.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -439,10 +440,19 @@ static void python_script_error_jump_text(struct Text 
*text)
   }
 }
 
-void BPY_python_backtrace(/* FILE */ void *fp)
+void BPY_python_backtrace(FILE *fp)
 {
   fputs("\n# Python backtrace\n", fp);
-  PyC_StackPrint(fp);
+  PyThreadState *tstate = PyGILState_GetThisThreadState();
+  if (tstate != NULL && tstate->frame != NULL) {
+    PyFrameObject *frame = tstate->frame;
+    do {
+      const int line = PyCode_Addr2Line(frame->f_code, frame->f_lasti);
+      const char *filename = _PyUnicode_AsString(frame->f_code->co_filename);
+      const char *funcname = _PyUnicode_AsString(frame->f_code->co_name);
+      fprintf(fp, "  File \"%s\", line %d in %s\n", filename, line, funcname);
+    } while ((frame = frame->f_back));
+  }
 }
 
 /* super annoying, undo _PyModule_Clear(), bug [#23871] */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to