@@ -4526,6 +4526,63 @@ SWIGINTERNINLINE PyObject*
45264526}
45274527
45284528
4529+ static PyObject* _get_store (PyObject* py_self, bool create) {
4530+ if (!PyObject_HasAttrString (py_self, " _private_data_" )) {
4531+ if (!create)
4532+ return NULL ;
4533+ PyObject* dict = PyDict_New ();
4534+ if (!dict)
4535+ return NULL ;
4536+ int error = PyObject_SetAttrString (py_self, " _private_data_" , dict);
4537+ Py_DECREF (dict);
4538+ if (error)
4539+ return NULL ;
4540+ }
4541+ return PyObject_GetAttrString (py_self, " _private_data_" );
4542+ };
4543+ static int store_private (PyObject* py_self, const char * name,
4544+ PyObject* val, bool take_ownership=false ) {
4545+ int result = 0 ;
4546+ PyObject* dict = _get_store (py_self, true );
4547+ if (dict) {
4548+ if (val)
4549+ result = PyDict_SetItemString (dict, name, val);
4550+ else if (PyDict_GetItemString (dict, name))
4551+ result = PyDict_DelItemString (dict, name);
4552+ Py_DECREF (dict);
4553+ }
4554+ else
4555+ result = -1 ;
4556+ if (take_ownership && val)
4557+ Py_DECREF (val);
4558+ return result;
4559+ };
4560+ static PyObject* fetch_private (PyObject* py_self, const char * name) {
4561+ PyObject* dict = _get_store (py_self, false );
4562+ if (!dict)
4563+ return NULL ;
4564+ PyObject* result = PyDict_GetItemString (dict, name);
4565+ if (result) {
4566+ Py_INCREF (result);
4567+ PyDict_DelItemString (dict, name);
4568+ }
4569+ Py_DECREF (dict);
4570+ return result;
4571+ };
4572+
4573+
4574+ static int release_view (PyObject* py_self) {
4575+ PyObject* ref = fetch_private (py_self, " view" );
4576+ if (!ref)
4577+ return 0 ;
4578+ PyObject* view = PyWeakref_GetObject (ref);
4579+ if (PyMemoryView_Check (view))
4580+ Py_XDECREF (PyObject_CallMethod (view, " release" , NULL ));
4581+ Py_DECREF (ref);
4582+ return 0 ;
4583+ };
4584+
4585+
45294586SWIGINTERN int
45304587SWIG_AsVal_double (PyObject *obj, double *val)
45314588{
@@ -4831,33 +4888,6 @@ SWIGINTERN char const *Exiv2_BasicIo_ioType(Exiv2::BasicIo *self){
48314888SWIGINTERN DataContext *Exiv2_BasicIo_data (Exiv2::BasicIo *self,bool isWriteable){
48324889 return new DataContext (self, isWriteable);
48334890 }
4834-
4835- static PyObject* _get_store (PyObject* py_self) {
4836- if (!PyObject_HasAttrString (py_self, " _private_data_" )) {
4837- PyObject* dict = PyDict_New ();
4838- if (!dict)
4839- return NULL ;
4840- int error = PyObject_SetAttrString (py_self, " _private_data_" , dict);
4841- Py_DECREF (dict);
4842- if (error)
4843- return NULL ;
4844- }
4845- return PyObject_GetAttrString (py_self, " _private_data_" );
4846- };
4847- static int store_private (PyObject* py_self, const char * name,
4848- PyObject* val) {
4849- PyObject* dict = _get_store (py_self);
4850- if (!dict)
4851- return -1 ;
4852- int result = 0 ;
4853- if (val)
4854- result = PyDict_SetItemString (dict, name, val);
4855- else if (PyDict_GetItemString (dict, name))
4856- result = PyDict_DelItemString (dict, name);
4857- Py_DECREF (dict);
4858- return result;
4859- };
4860-
48614891#ifdef __cplusplus
48624892extern " C" {
48634893#endif
@@ -5063,6 +5093,9 @@ SWIGINTERN PyObject *_wrap_BasicIo_close(PyObject *self, PyObject *args) {
50635093 }
50645094 }
50655095 resultobj = SWIG_From_int (static_cast < int >(result));
5096+
5097+ release_view (self);
5098+
50665099 return resultobj;
50675100fail:
50685101 return NULL ;
@@ -5114,6 +5147,9 @@ SWIGINTERN PyObject *_wrap_BasicIo_write__SWIG_0(PyObject *self, PyObject *args)
51145147
51155148 Py_XDECREF (_global_view);
51165149
5150+
5151+ release_view (self);
5152+
51175153 return resultobj;
51185154fail:
51195155
@@ -5162,6 +5198,9 @@ SWIGINTERN PyObject *_wrap_BasicIo_write__SWIG_1(PyObject *self, PyObject *args)
51625198 }
51635199 }
51645200 resultobj = SWIG_From_long (static_cast < long >(result));
5201+
5202+ release_view (self);
5203+
51655204 return resultobj;
51665205fail:
51675206 return NULL ;
@@ -5571,6 +5610,13 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
55715610 }
55725611
55735612 resultobj = PyMemoryView_FromMemory ((char *)result, result ? arg1->size () : 0 , arg2 ? PyBUF_WRITE : PyBUF_READ);
5613+ if (!resultobj)
5614+ SWIG_fail;
5615+ // Release any existing memoryview
5616+ release_view (self);
5617+ // Store a weak ref to the new memoryview
5618+ if (store_private (self, " view" , PyWeakref_NewRef (resultobj, NULL ), true ))
5619+ SWIG_fail;
55745620
55755621 return resultobj;
55765622fail:
@@ -5605,6 +5651,9 @@ SWIGINTERN PyObject *_wrap_BasicIo_munmap(PyObject *self, PyObject *args) {
56055651 }
56065652 }
56075653 resultobj = SWIG_From_int (static_cast < int >(result));
5654+
5655+ release_view (self);
5656+
56085657 return resultobj;
56095658fail:
56105659 return NULL ;
0 commit comments