Blame fix-wxcustomdataobject-getdata.patch

7a9cb25
From e5e34262c0ee9b6b4f3eda371fd0a206a05da2d0 Mon Sep 17 00:00:00 2001
7a9cb25
From: Scott Talbert <swt@techie.net>
7a9cb25
Date: Fri, 30 Oct 2020 20:32:52 -0400
7a9cb25
Subject: [PATCH] Avoid releasing the GIL in wxCustomDataObject.GetData
7a9cb25
7a9cb25
This avoids a crash because GetData calls i_wxPyMakeBuffer which calls
7a9cb25
Python C API, for which the GIL needs to be held.
7a9cb25
---
7a9cb25
 etg/dataobj.py            |  2 +-
7a9cb25
 etgtools/sip_generator.py | 12 ++++++++----
7a9cb25
 2 files changed, 9 insertions(+), 5 deletions(-)
7a9cb25
7a9cb25
diff --git a/etg/dataobj.py b/etg/dataobj.py
7a9cb25
index e59632df..a8adc980 100644
7a9cb25
--- a/etg/dataobj.py
7a9cb25
+++ b/etg/dataobj.py
7a9cb25
@@ -335,7 +335,7 @@ def run():
7a9cb25
     c.find('TakeData').ignore()
7a9cb25
 
7a9cb25
     c.find('GetData').ignore()
7a9cb25
-    c.addCppMethod('PyObject*', 'GetData', '()', isConst=True,
7a9cb25
+    c.addCppMethod('PyObject*', 'GetData', '()', isConst=True, pyHoldGIL=True,
7a9cb25
         doc="Returns a reference to the data buffer.",
7a9cb25
         body="return wxPyMakeBuffer(self->GetData(), self->GetSize());")
7a9cb25
 
7a9cb25
diff --git a/etgtools/sip_generator.py b/etgtools/sip_generator.py
7a9cb25
index 4fd119ac..778642c8 100644
7a9cb25
--- a/etgtools/sip_generator.py
7a9cb25
+++ b/etgtools/sip_generator.py
7a9cb25
@@ -863,7 +863,8 @@ from .%s import *
7a9cb25
 
7a9cb25
         else:
7a9cb25
             stream.write('PyErr_Clear();\n')
7a9cb25
-            stream.write('%sPy_BEGIN_ALLOW_THREADS\n' % (indent+' '*4))
7a9cb25
+            if not method.pyHoldGIL:
7a9cb25
+                stream.write('%sPy_BEGIN_ALLOW_THREADS\n' % (indent+' '*4))
7a9cb25
             stream.write(indent+' '*4)
7a9cb25
             if method.type != 'void':
7a9cb25
                 stream.write('sipRes = ')
7a9cb25
@@ -882,7 +883,8 @@ from .%s import *
7a9cb25
                     stream.write('%s(%s%s);\n' % (fname, argname, pnames))
7a9cb25
             else:
7a9cb25
                 stream.write('%s(%s);\n' % (fname, pnames))
7a9cb25
-            stream.write('%sPy_END_ALLOW_THREADS\n' % (indent+' '*4))
7a9cb25
+            if not method.pyHoldGIL:
7a9cb25
+                stream.write('%sPy_END_ALLOW_THREADS\n' % (indent+' '*4))
7a9cb25
             stream.write('%sif (PyErr_Occurred()) sipIsErr = 1;\n' % (indent+' '*4))
7a9cb25
         stream.write('%s%%End\n' % indent)
7a9cb25
 
7a9cb25
-- 
7a9cb25
2.26.2
7a9cb25