From 783e7d47a5e9128e8fff6b7d5eda37d4c25eb717 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 20 Feb 2025 16:13:52 +0000 Subject: [PATCH] Make python extension loading more robust to missing register/unregister --- qrenderdoc/Code/pyrenderdoc/PythonContext.cpp | 84 +++++++++++++------ 1 file changed, 60 insertions(+), 24 deletions(-) diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp index 73370cd9e..238f482cd 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp @@ -142,6 +142,15 @@ static QMutex decrefQueueMutex; static QList decrefQueue; extern "C" void ProcessDecRefQueue(); +// helper overload to give us the semantics we want - return NULL without an exception if the attr doesn't exist +PyObject *PyObject_SafeGetAttrString(PyObject *obj, const char *string) +{ + if(PyObject_HasAttrString(obj, string) == 0) + return NULL; + + return PyObject_GetAttrString(obj, string); +} + void FetchException(QString &typeStr, QString &valueStr, int &finalLine, QList &frames) { PyObject *exObj = NULL, *valueObj = NULL, *tracebackObj = NULL; @@ -170,7 +179,7 @@ void FetchException(QString &typeStr, QString &valueStr, int &finalLine, QList