]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/streams.i
use the new wxSystemSettings API everywhere
[wxWidgets.git] / wxPython / src / streams.i
index 2e87f237a90733138ea5c968e8dfb7915b05c0bf..e87a10cb2a91cbd3268c21b462f2ddaab8e8fc34 100644 (file)
     if ($source) {
         _ptr = new wxPyInputStream($source);
     }
-    if (_ptr) {
-        char    swigptr[64];
-        SWIG_MakePtr(swigptr, _ptr, "_wxPyInputStream_p");
-
-        PyObject* classobj = PyDict_GetItemString(wxPython_dict, "wxInputStreamPtr");
-        if (! classobj) {
-            Py_INCREF(Py_None);
-            $target = Py_None;
-        } else {
-            PyObject* arg = Py_BuildValue("(s)", swigptr);
-            $target = PyInstance_New(classobj, arg, NULL);
-            Py_DECREF(arg);
-
-            // set ThisOwn
-            PyObject_SetAttrString($target, "thisown", PyInt_FromLong(1));
-        }
-    } else {
-        Py_INCREF(Py_None);
-        $target = Py_None;
-    }
+    $target = wxPyConstructObject(_ptr, "wxInputStream", TRUE);
 }
 
 //----------------------------------------------------------------------
@@ -128,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) {
@@ -152,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) {
@@ -185,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) {
@@ -216,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();
@@ -228,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) {
@@ -265,7 +238,7 @@ protected:
         if (bufsize == 0)
             return 0;
 
-        bool doSave = wxPyRestoreThread();
+        wxPyBeginBlockThreads();
         PyObject* arglist = Py_BuildValue("(i)", bufsize);
         PyObject* result = PyEval_CallObject(read, arglist);
         Py_DECREF(arglist);
@@ -283,7 +256,7 @@ protected:
         }
         else
             m_lasterror = wxSTREAM_READ_ERROR;
-        wxPySaveThread(doSave);
+        wxPyEndBlockThreads();
         m_lastcount = o;
         return o;
     }
@@ -294,17 +267,17 @@ protected:
     }
 
     virtual off_t OnSysSeek(off_t off, wxSeekMode mode){
-        bool doSave = wxPyRestoreThread();
+        wxPyBeginBlockThreads();
         PyObject*arglist = Py_BuildValue("(ii)", off, mode);
         PyObject*result = PyEval_CallObject(seek, arglist);
         Py_DECREF(arglist);
         Py_XDECREF(result);
-        wxPySaveThread(doSave);
+        wxPyEndBlockThreads();
         return OnSysTell();
     }
 
     virtual off_t OnSysTell() const{
-        bool doSave = wxPyRestoreThread();
+        wxPyBeginBlockThreads();
         PyObject* arglist = Py_BuildValue("()");
         PyObject* result = PyEval_CallObject(tell, arglist);
         Py_DECREF(arglist);
@@ -313,7 +286,7 @@ protected:
             o = PyInt_AsLong(result);
             Py_DECREF(result);
         };
-        wxPySaveThread(doSave);
+        wxPyEndBlockThreads();
         return o;
     }
 
@@ -323,12 +296,12 @@ protected:
 
 public:
     ~wxPyCBInputStream() {
-        bool doSave = wxPyRestoreThread();
+        wxPyBeginBlockThreads();
         Py_XDECREF(py);
         Py_XDECREF(read);
         Py_XDECREF(seek);
         Py_XDECREF(tell);
-        wxPySaveThread(doSave);
+        wxPyEndBlockThreads();
     }
 
     virtual size_t GetSize() {
@@ -371,8 +344,10 @@ public:
         if (!PyObject_HasAttrString(py, name))
             return NULL;
         PyObject* o = PyObject_GetAttrString(py, name);
-        if (!PyMethod_Check(o) && !PyCFunction_Check(o))
+        if (!PyMethod_Check(o) && !PyCFunction_Check(o)) {
+            Py_DECREF(o);
             return NULL;
+        }
         return o;
     }
 
@@ -384,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) {
@@ -408,7 +377,6 @@ protected:
 }
 
 
-// transport exceptions via %target=0
 %typemap(python, out) wxPyInputStream* {
     char _ptemp[128];
     if ($source) {
@@ -420,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 {
@@ -491,13 +449,12 @@ 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;
-}
 
 
+//----------------------------------------------------------------------
+
+%init %{
+    wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
+%}
+
+//----------------------------------------------------------------------