Changed (again) how the Python global interpreter lock is handled as
well as the Python thread state. This time it works on SMP machines without barfing and is also still compatible with Python debuggers. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13097 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -109,14 +109,12 @@ wxString* wxPyInputStream::read(int size) {
|
||||
}
|
||||
|
||||
// read until EOF
|
||||
wxPy_BEGIN_ALLOW_THREADS;
|
||||
while (! wxi->Eof()) {
|
||||
wxi->Read(buf, BUFSIZE);
|
||||
//*s += wxString(buf, wxi->LastRead());
|
||||
s->Append(buf, wxi->LastRead());
|
||||
}
|
||||
delete buf;
|
||||
wxPy_END_ALLOW_THREADS;
|
||||
|
||||
// error check
|
||||
if (wxi->LastError() == wxSTREAM_READ_ERROR) {
|
||||
@@ -133,10 +131,8 @@ wxString* wxPyInputStream::read(int size) {
|
||||
}
|
||||
|
||||
// read size bytes
|
||||
wxPy_BEGIN_ALLOW_THREADS;
|
||||
wxi->Read(s->GetWriteBuf(size+1), size);
|
||||
s->UngetWriteBuf(wxi->LastRead());
|
||||
wxPy_END_ALLOW_THREADS;
|
||||
|
||||
// error check
|
||||
if (wxi->LastError() == wxSTREAM_READ_ERROR) {
|
||||
@@ -166,11 +162,9 @@ wxString* wxPyInputStream::readline (int size) {
|
||||
}
|
||||
|
||||
// read until \n or byte limit reached
|
||||
wxPy_BEGIN_ALLOW_THREADS;
|
||||
for (i=ch=0; (ch != '\n') && (!wxi->Eof()) && ((size < 0) || (i < size)); i++) {
|
||||
*s += ch = wxi->GetC();
|
||||
}
|
||||
wxPy_END_ALLOW_THREADS;
|
||||
|
||||
// errorcheck
|
||||
if (wxi->LastError() == wxSTREAM_READ_ERROR) {
|
||||
@@ -197,7 +191,6 @@ wxStringPtrList* wxPyInputStream::readlines (int sizehint) {
|
||||
}
|
||||
|
||||
// read sizehint bytes or until EOF
|
||||
wxPy_BEGIN_ALLOW_THREADS;
|
||||
int i;
|
||||
for (i=0; (!wxi->Eof()) && ((sizehint < 0) || (i < sizehint));) {
|
||||
wxString* s = readline();
|
||||
@@ -209,7 +202,6 @@ wxStringPtrList* wxPyInputStream::readlines (int sizehint) {
|
||||
l->Append(s);
|
||||
i = i + s->Length();
|
||||
}
|
||||
wxPy_END_ALLOW_THREADS;
|
||||
|
||||
// error check
|
||||
if (wxi->LastError() == wxSTREAM_READ_ERROR) {
|
||||
@@ -246,7 +238,7 @@ protected:
|
||||
if (bufsize == 0)
|
||||
return 0;
|
||||
|
||||
wxPyTState* state = wxPyBeginBlockThreads();
|
||||
wxPyBeginBlockThreads();
|
||||
PyObject* arglist = Py_BuildValue("(i)", bufsize);
|
||||
PyObject* result = PyEval_CallObject(read, arglist);
|
||||
Py_DECREF(arglist);
|
||||
@@ -264,7 +256,7 @@ protected:
|
||||
}
|
||||
else
|
||||
m_lasterror = wxSTREAM_READ_ERROR;
|
||||
wxPyEndBlockThreads(state);
|
||||
wxPyEndBlockThreads();
|
||||
m_lastcount = o;
|
||||
return o;
|
||||
}
|
||||
@@ -275,17 +267,17 @@ protected:
|
||||
}
|
||||
|
||||
virtual off_t OnSysSeek(off_t off, wxSeekMode mode){
|
||||
wxPyTState* state = wxPyBeginBlockThreads();
|
||||
wxPyBeginBlockThreads();
|
||||
PyObject*arglist = Py_BuildValue("(ii)", off, mode);
|
||||
PyObject*result = PyEval_CallObject(seek, arglist);
|
||||
Py_DECREF(arglist);
|
||||
Py_XDECREF(result);
|
||||
wxPyEndBlockThreads(state);
|
||||
wxPyEndBlockThreads();
|
||||
return OnSysTell();
|
||||
}
|
||||
|
||||
virtual off_t OnSysTell() const{
|
||||
wxPyTState* state = wxPyBeginBlockThreads();
|
||||
wxPyBeginBlockThreads();
|
||||
PyObject* arglist = Py_BuildValue("()");
|
||||
PyObject* result = PyEval_CallObject(tell, arglist);
|
||||
Py_DECREF(arglist);
|
||||
@@ -294,7 +286,7 @@ protected:
|
||||
o = PyInt_AsLong(result);
|
||||
Py_DECREF(result);
|
||||
};
|
||||
wxPyEndBlockThreads(state);
|
||||
wxPyEndBlockThreads();
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -304,12 +296,12 @@ protected:
|
||||
|
||||
public:
|
||||
~wxPyCBInputStream() {
|
||||
wxPyTState* state = wxPyBeginBlockThreads();
|
||||
wxPyBeginBlockThreads();
|
||||
Py_XDECREF(py);
|
||||
Py_XDECREF(read);
|
||||
Py_XDECREF(seek);
|
||||
Py_XDECREF(tell);
|
||||
wxPyEndBlockThreads(state);
|
||||
wxPyEndBlockThreads();
|
||||
}
|
||||
|
||||
virtual size_t GetSize() {
|
||||
@@ -367,12 +359,6 @@ protected:
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
// block threads for wxPyInputStream **** WHY?
|
||||
%except(python) {
|
||||
$function
|
||||
}
|
||||
|
||||
|
||||
// wxStringPtrList* to python list of strings typemap
|
||||
%typemap(python, out) wxStringPtrList* {
|
||||
if ($source) {
|
||||
@@ -391,7 +377,6 @@ protected:
|
||||
}
|
||||
|
||||
|
||||
// transport exceptions via %target=0
|
||||
%typemap(python, out) wxPyInputStream* {
|
||||
char _ptemp[128];
|
||||
if ($source) {
|
||||
@@ -403,16 +388,6 @@ protected:
|
||||
}
|
||||
|
||||
|
||||
// transport exceptions via %target=0
|
||||
%typemap(python, out) wxString* {
|
||||
if ($source) {
|
||||
$target = PyString_FromStringAndSize($source->c_str(), $source->Len());
|
||||
delete $source;
|
||||
}
|
||||
else
|
||||
$target=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
%name(wxInputStream) class wxPyInputStream {
|
||||
@@ -474,14 +449,6 @@ public:
|
||||
// restore except and typemaps
|
||||
%typemap(python,out) wxStringPtrList*;
|
||||
%typemap(python,out) wxPyInputStream*;
|
||||
%typemap(python, out) wxString* {
|
||||
$target = PyString_FromStringAndSize($source->c_str(), $source->Len());
|
||||
}
|
||||
%except(python) {
|
||||
wxPy_BEGIN_ALLOW_THREADS;
|
||||
$function
|
||||
wxPy_END_ALLOW_THREADS;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user