Add copy ctor for wxPyCBInputStream and use it to prevent double
deletion of the wxInputStream passed to wxFSFile git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32589 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
c8547e17ca
commit
d02ea46cad
@ -74,6 +74,8 @@ public:
|
|||||||
// factory function
|
// factory function
|
||||||
static wxPyCBInputStream* create(PyObject *py, bool block=true);
|
static wxPyCBInputStream* create(PyObject *py, bool block=true);
|
||||||
|
|
||||||
|
wxPyCBInputStream(const wxPyCBInputStream& other);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// can only be created via the factory
|
// can only be created via the factory
|
||||||
wxPyCBInputStream(PyObject *r, PyObject *s, PyObject *t, bool block);
|
wxPyCBInputStream(PyObject *r, PyObject *s, PyObject *t, bool block);
|
||||||
|
@ -111,6 +111,7 @@ inline wxPyCoreAPI* wxPyGetCoreAPIPtr()
|
|||||||
#define wxPyOORClientData_dtor(a) (wxPyGetCoreAPIPtr()->p_wxPyOORClientData_dtor(a))
|
#define wxPyOORClientData_dtor(a) (wxPyGetCoreAPIPtr()->p_wxPyOORClientData_dtor(a))
|
||||||
|
|
||||||
#define wxPyCBInputStream_create(a, b) (wxPyGetCoreAPIPtr()->p_wxPyCBInputStream_create(a, b))
|
#define wxPyCBInputStream_create(a, b) (wxPyGetCoreAPIPtr()->p_wxPyCBInputStream_create(a, b))
|
||||||
|
#define wxPyCBInputStream_copy(a) (wxPyGetCoreAPIPtr()->p_wxPyCBInputStream_copy(a))
|
||||||
|
|
||||||
#define wxPyInstance_Check(a) (wxPyGetCoreAPIPtr()->p_wxPyInstance_Check(a))
|
#define wxPyInstance_Check(a) (wxPyGetCoreAPIPtr()->p_wxPyInstance_Check(a))
|
||||||
#define wxPySwigInstance_Check(a) (wxPyGetCoreAPIPtr()->p_wxPySwigInstance_Check(a))
|
#define wxPySwigInstance_Check(a) (wxPyGetCoreAPIPtr()->p_wxPySwigInstance_Check(a))
|
||||||
|
@ -323,7 +323,7 @@ void wxPyClientData_dtor(wxPyClientData* self);
|
|||||||
void wxPyUserData_dtor(wxPyUserData* self);
|
void wxPyUserData_dtor(wxPyUserData* self);
|
||||||
void wxPyOORClientData_dtor(wxPyOORClientData* self);
|
void wxPyOORClientData_dtor(wxPyOORClientData* self);
|
||||||
wxPyCBInputStream* wxPyCBInputStream_create(PyObject *py, bool block);
|
wxPyCBInputStream* wxPyCBInputStream_create(PyObject *py, bool block);
|
||||||
|
wxPyCBInputStream* wxPyCBInputStream_copy(wxPyCBInputStream* other);
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// Export a C API in a struct. Other modules will be able to load this from
|
// Export a C API in a struct. Other modules will be able to load this from
|
||||||
@ -389,6 +389,7 @@ struct wxPyCoreAPI {
|
|||||||
void (*p_wxPyOORClientData_dtor)(wxPyOORClientData*);
|
void (*p_wxPyOORClientData_dtor)(wxPyOORClientData*);
|
||||||
|
|
||||||
wxPyCBInputStream* (*p_wxPyCBInputStream_create)(PyObject *py, bool block);
|
wxPyCBInputStream* (*p_wxPyCBInputStream_create)(PyObject *py, bool block);
|
||||||
|
wxPyCBInputStream* (*p_wxPyCBInputStream_copy)(wxPyCBInputStream* other);
|
||||||
|
|
||||||
bool (*p_wxPyInstance_Check)(PyObject* obj);
|
bool (*p_wxPyInstance_Check)(PyObject* obj);
|
||||||
bool (*p_wxPySwigInstance_Check)(PyObject* obj);
|
bool (*p_wxPySwigInstance_Check)(PyObject* obj);
|
||||||
|
@ -183,6 +183,7 @@ static wxPyCoreAPI API = {
|
|||||||
wxPyOORClientData_dtor,
|
wxPyOORClientData_dtor,
|
||||||
|
|
||||||
wxPyCBInputStream_create,
|
wxPyCBInputStream_create,
|
||||||
|
wxPyCBInputStream_copy,
|
||||||
|
|
||||||
wxPyInstance_Check,
|
wxPyInstance_Check,
|
||||||
wxPySwigInstance_Check,
|
wxPySwigInstance_Check,
|
||||||
|
@ -27,7 +27,7 @@ class wxFSFile : public wxObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
%pythonAppend wxFSFile
|
%pythonAppend wxFSFile
|
||||||
"self.thisown = 0 # It will normally be deleted by the user of the wxFileSystem";
|
"self.thisown = 0 # It will normally be deleted by the user of the wx.FileSystem";
|
||||||
|
|
||||||
wxFSFile(wxInputStream *stream, const wxString& loc,
|
wxFSFile(wxInputStream *stream, const wxString& loc,
|
||||||
const wxString& mimetype, const wxString& anchor,
|
const wxString& mimetype, const wxString& anchor,
|
||||||
|
@ -23,8 +23,15 @@
|
|||||||
%newgroup
|
%newgroup
|
||||||
|
|
||||||
|
|
||||||
// typemaps for wxInputStream
|
// Typemaps for wxInputStream
|
||||||
%typemap(in) wxInputStream* (wxPyInputStream* temp, bool created) {
|
//
|
||||||
|
// 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"))) {
|
if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
|
||||||
$1 = temp->m_wxis;
|
$1 = temp->m_wxis;
|
||||||
created = false;
|
created = false;
|
||||||
@ -32,21 +39,29 @@
|
|||||||
PyErr_Clear(); // clear the failure of the wxPyConvert above
|
PyErr_Clear(); // clear the failure of the wxPyConvert above
|
||||||
$1 = wxPyCBInputStream_create($input, false);
|
$1 = wxPyCBInputStream_create($input, false);
|
||||||
if ($1 == NULL) {
|
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;
|
SWIG_fail;
|
||||||
}
|
}
|
||||||
created = true;
|
created = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
%typemap(freearg) wxInputStream* {
|
%typemap(freearg) wxInputStream& { if (created$argnum) delete $1; }
|
||||||
if (created$argnum)
|
|
||||||
delete $1;
|
|
||||||
|
%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(in) wxInputStream& = wxInputStream*;
|
|
||||||
%typemap(freearg) wxInputStream& = wxInputStream*;
|
|
||||||
|
|
||||||
|
|
||||||
%typemap(out) wxInputStream* {
|
%typemap(out) wxInputStream* {
|
||||||
wxPyInputStream * _ptr = NULL;
|
wxPyInputStream * _ptr = NULL;
|
||||||
|
@ -1343,6 +1343,17 @@ wxPyCBInputStream::wxPyCBInputStream(PyObject *r, PyObject *s, PyObject *t, bool
|
|||||||
: wxInputStream(), m_read(r), m_seek(s), m_tell(t), m_block(block)
|
: wxInputStream(), m_read(r), m_seek(s), m_tell(t), m_block(block)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
wxPyCBInputStream::wxPyCBInputStream(const wxPyCBInputStream& other)
|
||||||
|
{
|
||||||
|
m_read = other.m_read;
|
||||||
|
m_seek = other.m_seek;
|
||||||
|
m_tell = other.m_tell;
|
||||||
|
m_block = other.m_block;
|
||||||
|
Py_INCREF(m_read);
|
||||||
|
Py_INCREF(m_seek);
|
||||||
|
Py_INCREF(m_tell);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
wxPyCBInputStream::~wxPyCBInputStream() {
|
wxPyCBInputStream::~wxPyCBInputStream() {
|
||||||
bool blocked=false;
|
bool blocked=false;
|
||||||
@ -1380,6 +1391,10 @@ wxPyCBInputStream* wxPyCBInputStream_create(PyObject *py, bool block) {
|
|||||||
return wxPyCBInputStream::create(py, block);
|
return wxPyCBInputStream::create(py, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxPyCBInputStream* wxPyCBInputStream_copy(wxPyCBInputStream* other) {
|
||||||
|
return new wxPyCBInputStream(*other);
|
||||||
|
}
|
||||||
|
|
||||||
PyObject* wxPyCBInputStream::getMethod(PyObject* py, char* name) {
|
PyObject* wxPyCBInputStream::getMethod(PyObject* py, char* name) {
|
||||||
if (!PyObject_HasAttrString(py, name))
|
if (!PyObject_HasAttrString(py, name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user