From c91cd7f6b7ddb43f03ff703158ec70af6c801f30 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 10 Nov 2003 22:33:06 +0000 Subject: [PATCH] Handle the GIL properly in the %addmethods git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@24515 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/src/image.i | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/wxPython/src/image.i b/wxPython/src/image.i index 0c2883883f..4909025364 100644 --- a/wxPython/src/image.i +++ b/wxPython/src/image.i @@ -170,28 +170,35 @@ public: PyObject* GetDataBuffer() { unsigned char* data = self->GetData(); int len = self->GetWidth() * self->GetHeight() * 3; - return PyBuffer_FromReadWriteMemory(data, len); + PyObject* rv; + wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) ); + return rv; } PyObject* GetData() { unsigned char* data = self->GetData(); int len = self->GetWidth() * self->GetHeight() * 3; - return PyString_FromStringAndSize((char*)data, len); + PyObject* rv; + wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len)); + return rv; } void SetDataBuffer(PyObject* data) { unsigned char* buffer; int size; - if (!PyArg_Parse(data, "w#", &buffer, &size)) - return; + wxPyBeginBlockThreads(); + if (!PyArg_Parse(data, "t#", &buffer, &size)) + goto done; if (size != self->GetWidth() * self->GetHeight() * 3) { PyErr_SetString(PyExc_TypeError, "Incorrect buffer size"); - return; + goto done; } self->SetData(buffer); + done: + wxPyEndBlockThreads(); } void SetData(PyObject* data) { @@ -204,7 +211,7 @@ public: size_t len = self->GetWidth() * self->GetHeight() * 3; dataPtr = (unsigned char*) malloc(len); - memcpy(dataPtr, PyString_AsString(data), len); + wxPyBLOCK_THREADS( memcpy(dataPtr, PyString_AsString(data), len) ); self->SetData(dataPtr); // wxImage takes ownership of dataPtr... }