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
This commit is contained in:
@@ -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...
|
||||
}
|
||||
|
Reference in New Issue
Block a user