void-packages/srcpkgs/renderdoc/patches/python-3.11.patch

152 lines
4.4 KiB
Diff
Raw Normal View History

Index: renderdoc-1.21/qrenderdoc/Code/pyrenderdoc/function_conversion.h
===================================================================
--- renderdoc-1.21.orig/qrenderdoc/Code/pyrenderdoc/function_conversion.h
+++ renderdoc-1.21/qrenderdoc/Code/pyrenderdoc/function_conversion.h
@@ -301,13 +301,30 @@ funcType ConvertFunc(const char *funcnam
{
_frame *frame = PyEval_GetFrame();
2022-09-23 13:45:21 +02:00
+#if PY_VERSION_HEX >= 0x030B0000
+ Py_INCREF(frame);
+#endif
2022-09-23 13:45:21 +02:00
while(frame)
{
+#if PY_VERSION_HEX >= 0x030B0000
+ PyObject *f_globals = PyFrame_GetGlobals(frame);
+ global_internal_handle = PyDict_GetItemString(f_globals, "_renderdoc_internal");
+ Py_DECREF(f_globals);
2022-09-23 13:45:21 +02:00
+#else
global_internal_handle = PyDict_GetItemString(frame->f_globals, "_renderdoc_internal");
+#endif
if(global_internal_handle)
break;
+#if PY_VERSION_HEX >= 0x03090000
+ do {
+ PyFrameObject *f_back = PyFrame_GetBack(frame);
+ Py_DECREF(frame);
+ frame = f_back;
+ } while (0);
2022-09-23 13:45:21 +02:00
+#else
frame = frame->f_back;
+#endif
}
}
Index: renderdoc-1.21/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp
===================================================================
--- renderdoc-1.21.orig/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp
+++ renderdoc-1.21/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp
@@ -85,6 +85,33 @@ extern "C" PyObject *PyInit_qrenderdoc(v
2022-09-23 13:45:21 +02:00
extern "C" PyObject *WrapBareQWidget(QWidget *);
extern "C" QWidget *UnwrapBareQWidget(PyObject *);
+#if PY_VERSION_HEX <=0x030B0000
+static inline PyObject *
+PyFrame_GetGlobals(PyFrameObject *frame)
+{
+ PyObject *f_globals = frame->f_globals;
+ Py_INCREF(f_globals);
+ return f_globals;
+}
2022-09-23 13:45:21 +02:00
+#endif
+
+#if PY_VERSION_HEX <=0x03090000
+static inline PyFrameObject *
+PyFrame_GetBack(PyFrameObject *frame)
+{
+ PyFrameObject *f_back = frame->f_back;
+ Py_INCREF(f_back);
+ return f_back;
+}
+static inline PyCodeObject *
+PyFrame_GetCode(PyFrameObject *frame)
+{
+ PyCodeObject *f_code = frame->f_code;
+ Py_INCREF(f_code);
+ return f_code;
+}
2022-09-23 13:45:21 +02:00
+#endif
+
// little utility function to convert a PyObject * that we know is a string to a QString
static inline QString ToQStr(PyObject *value)
{
@@ -1211,21 +1238,28 @@ PyObject *PythonContext::outstream_write
{
_frame *frame = PyEval_GetFrame();
2022-09-23 13:45:21 +02:00
+ Py_XINCREF(frame);
+
2022-09-23 13:45:21 +02:00
while(frame)
{
- PyObject *globals = frame->f_globals;
+ PyFrameObject *oframe = frame;
2022-09-23 13:45:21 +02:00
+ PyObject *globals = PyFrame_GetGlobals(frame);
if(globals)
{
+ Py_DECREF(globals);
2022-09-23 13:45:21 +02:00
OutputRedirector *global =
(OutputRedirector *)PyDict_GetItemString(globals, "_renderdoc_internal");
- if(global)
+ if(global) {
context = global->context;
+ Py_DECREF(globals);
+ }
}
2022-09-23 13:45:21 +02:00
if(context)
break;
- frame = frame->f_back;
+ frame = PyFrame_GetBack(frame);
+ Py_DECREF(oframe);
2022-09-23 13:45:21 +02:00
}
}
@@ -1239,6 +1273,7 @@ PyObject *PythonContext::outstream_write
rdcstr message = text;
_frame *frame = PyEval_GetFrame();
+ Py_XINCREF(frame);
while(message.back() == '\n' || message.back() == '\r')
message.pop_back();
@@ -1248,7 +1283,9 @@ PyObject *PythonContext::outstream_write
2022-09-23 13:45:21 +02:00
if(frame)
{
- filename = ToQStr(frame->f_code->co_filename);
+ PyCodeObject *code = PyFrame_GetCode(frame);
+ filename = ToQStr(code->co_filename);
+ Py_DECREF(code);
2022-09-23 13:45:21 +02:00
line = PyFrame_GetLineNumber(frame);
}
@@ -1278,12 +1315,14 @@ int PythonContext::traceEvent(PyObject *
2022-09-23 13:45:21 +02:00
PythonContext *context = (PythonContext *)thisint;
PyObject *compiled = PyDict_GetItemString(obj, "compiled");
- if(compiled == (PyObject *)frame->f_code && what == PyTrace_LINE)
+ PyCodeObject *code = PyFrame_GetCode(frame);
+ if(compiled == (PyObject *)code && what == PyTrace_LINE)
2022-09-23 13:45:21 +02:00
{
context->location.line = PyFrame_GetLineNumber(frame);
emit context->traceLine(context->location.file, context->location.line);
}
+ Py_DECREF(code);
if(context->shouldAbort())
{
@@ -1361,7 +1400,9 @@ extern "C" void HandleException(PyObject
2022-09-23 13:45:21 +02:00
if(frame)
{
- filename = ToQStr(frame->f_code->co_filename);
+ PyCodeObject *code = PyFrame_GetCode(frame);
+ filename = ToQStr(code->co_filename);
+ Py_DECREF(code);
2022-09-23 13:45:21 +02:00
linenum = PyFrame_GetLineNumber(frame);
}