X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dd9f7fea29e3f8bb61861f52984b7943512346ac..ae04c0f15694193c3f6e62dfd16f1c5da86e03f7:/wxPython/src/_streams.i diff --git a/wxPython/src/_streams.i b/wxPython/src/_streams.i index 59ff7d7d4a..a918d91470 100644 --- a/wxPython/src/_streams.i +++ b/wxPython/src/_streams.i @@ -23,29 +23,44 @@ %newgroup -// typemaps for wxInputStream -%typemap(in) wxInputStream* (wxPyInputStream* temp, bool created) { +// Typemaps for wxInputStream +// +// We assume that input params taking a wxInputStream& will *not* take +// ownership of the stream and so we manage it in the typemaps. On the other +// hand, when a paramter expects a wxInputStream* then it does take ownership +// (such as wxFSFile) and so the typemap will make a copy of the stream object +// to give to it. + +%typemap(in) wxInputStream& (wxPyInputStream* temp, bool created) { if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) { $1 = temp->m_wxis; - created = False; + created = false; } else { PyErr_Clear(); // clear the failure of the wxPyConvert above - $1 = wxPyCBInputStream_create($input, False); + $1 = wxPyCBInputStream_create($input, false); if ($1 == NULL) { - PyErr_SetString(PyExc_TypeError, "Expected wxInputStream or Python file-like object."); + PyErr_SetString(PyExc_TypeError, "Expected wx.InputStream or Python file-like object."); SWIG_fail; } - created = True; + created = true; } } -%typemap(freearg) wxInputStream* { - if (created$argnum) - delete $1; -} +%typemap(freearg) wxInputStream& { if (created$argnum) delete $1; } -%typemap(in) wxInputStream& = wxInputStream*; -%typemap(freearg) wxInputStream& = wxInputStream*; +%typemap(in) wxInputStream* (wxPyInputStream* temp) { + if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) { + $1 = wxPyCBInputStream_copy((wxPyCBInputStream*)temp->m_wxis); + } else { + PyErr_Clear(); // clear the failure of the wxPyConvert above + $1 = wxPyCBInputStream_create($input, true); + if ($1 == NULL) { + PyErr_SetString(PyExc_TypeError, "Expected wx.InputStream or Python file-like object."); + SWIG_fail; + } + } +} + %typemap(out) wxInputStream* { @@ -54,7 +69,7 @@ if ($1) { _ptr = new wxPyInputStream($1); } - $result = wxPyConstructObject(_ptr, wxT("wxPyInputStream"), True); + $result = wxPyConstructObject(_ptr, wxT("wxPyInputStream"), $owner); } @@ -68,8 +83,9 @@ enum wxSeekMode }; - -%name(InputStream) class wxPyInputStream { +%rename(InputStream) wxPyInputStream; +class wxPyInputStream +{ public: %extend { wxPyInputStream(PyObject* p) { @@ -80,7 +96,8 @@ public: return NULL; } } - + ~wxPyInputStream(); + void close(); void flush(); bool eof(); @@ -142,6 +159,7 @@ public: Py_DECREF(str); } } + size_t LastWrite() const; };