Skip to content

Commit bf76499

Browse files
Slightly safer use of isWriteable in BasicIo funcs
1 parent c224269 commit bf76499

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/interface/basicio.i

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ OUTPUT_BUFFER_RW(Exiv2::byte* buf, size_t rcount)
132132
%typemap(default) bool isWriteable {$1 = false;}
133133
%ignore Exiv2::BasicIo::mmap();
134134

135-
// Convert mmap() result to a Python memoryview, assumes arg2 = isWriteable
135+
// Convert mmap() result to a Python memoryview
136136
RETURN_VIEW(Exiv2::byte* mmap, $1 ? arg1->size() : 0,
137-
arg2 ? PyBUF_WRITE : PyBUF_READ,)
137+
_global_writeable ? PyBUF_WRITE : PyBUF_READ,)
138138

139-
// Release memoryviews when mmap or data is called
140-
%typemap(check, fragment="memoryview_funcs") bool isWriteable {
139+
// Release memoryviews (and save isWriteable) when mmap or data is called
140+
%typemap(check, fragment="memoryview_funcs") bool isWriteable
141+
(bool _global_writeable) {
142+
_global_writeable = $1;
141143
release_views(self);
142144
}
143145

@@ -151,7 +153,7 @@ RETURN_VIEW(Exiv2::byte* mmap, $1 ? arg1->size() : 0,
151153
// Add data() method for easy access
152154
// The callback is used to call munmap when the memoryview is deleted
153155
RETURN_VIEW_CB(Exiv2::byte* data, $1 ? arg1->size() : 0,
154-
arg2 ? PyBUF_WRITE : PyBUF_READ,
156+
_global_writeable ? PyBUF_WRITE : PyBUF_READ,
155157
PyObject_GetAttrString(self, "_release"),)
156158
%extend Exiv2::BasicIo {
157159
Exiv2::byte* data(bool isWriteable) {

src/swig-0_27_7/basicio_wrap.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5469,6 +5469,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
54695469
int res1 = 0 ;
54705470
bool val2 ;
54715471
int ecode2 = 0 ;
5472+
bool _global_writeable ;
54725473
PyObject * obj1 = 0 ;
54735474
Exiv2::byte *result = 0 ;
54745475

@@ -5489,6 +5490,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
54895490
arg2 = static_cast< bool >(val2);
54905491
}
54915492
{
5493+
_global_writeable = arg2;
54925494
release_views(self);
54935495
}
54945496
{
@@ -5505,7 +5507,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
55055507
}
55065508
}
55075509

5508-
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, arg2 ? PyBUF_WRITE : PyBUF_READ);
5510+
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, _global_writeable ? PyBUF_WRITE : PyBUF_READ);
55095511
if (!resultobj)
55105512
SWIG_fail;
55115513
// Store a weak ref to the new memoryview
@@ -5734,6 +5736,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
57345736
int res1 = 0 ;
57355737
bool val2 ;
57365738
int ecode2 = 0 ;
5739+
bool _global_writeable ;
57375740
PyObject * obj1 = 0 ;
57385741
Exiv2::byte *result = 0 ;
57395742

@@ -5754,6 +5757,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
57545757
arg2 = static_cast< bool >(val2);
57555758
}
57565759
{
5760+
_global_writeable = arg2;
57575761
release_views(self);
57585762
}
57595763
{
@@ -5770,7 +5774,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
57705774
}
57715775
}
57725776

5773-
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, arg2 ? PyBUF_WRITE : PyBUF_READ);
5777+
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, _global_writeable ? PyBUF_WRITE : PyBUF_READ);
57745778
if (!resultobj)
57755779
SWIG_fail;
57765780
// Store a weak ref to the new memoryview

src/swig-0_28_5/basicio_wrap.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5736,6 +5736,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
57365736
int res1 = 0 ;
57375737
bool val2 ;
57385738
int ecode2 = 0 ;
5739+
bool _global_writeable ;
57395740
PyObject * obj1 = 0 ;
57405741
Exiv2::byte *result = 0 ;
57415742

@@ -5756,6 +5757,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
57565757
arg2 = static_cast< bool >(val2);
57575758
}
57585759
{
5760+
_global_writeable = arg2;
57595761
release_views(self);
57605762
}
57615763
{
@@ -5772,7 +5774,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
57725774
}
57735775
}
57745776

5775-
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, arg2 ? PyBUF_WRITE : PyBUF_READ);
5777+
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, _global_writeable ? PyBUF_WRITE : PyBUF_READ);
57765778
if (!resultobj)
57775779
SWIG_fail;
57785780
// Store a weak ref to the new memoryview
@@ -6002,6 +6004,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
60026004
int res1 = 0 ;
60036005
bool val2 ;
60046006
int ecode2 = 0 ;
6007+
bool _global_writeable ;
60056008
PyObject * obj1 = 0 ;
60066009
Exiv2::byte *result = 0 ;
60076010

@@ -6022,6 +6025,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
60226025
arg2 = static_cast< bool >(val2);
60236026
}
60246027
{
6028+
_global_writeable = arg2;
60256029
release_views(self);
60266030
}
60276031
{
@@ -6038,7 +6042,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
60386042
}
60396043
}
60406044

6041-
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, arg2 ? PyBUF_WRITE : PyBUF_READ);
6045+
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, _global_writeable ? PyBUF_WRITE : PyBUF_READ);
60426046
if (!resultobj)
60436047
SWIG_fail;
60446048
// Store a weak ref to the new memoryview

0 commit comments

Comments
 (0)