Skip to content

Commit 3b28dd1

Browse files
Slight simplification of BasicIo typemaps
There's no need to store 'self' and 'isWriteable' explicitly as they are always args 1 & 2.
1 parent b119a5c commit 3b28dd1

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

src/interface/basicio.i

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,14 @@ OUTPUT_BUFFER_RW(Exiv2::byte* buf, BUFLEN_T rcount)
139139
%ignore Exiv2::BasicIo::mmap();
140140

141141
// Convert mmap() result to a Python memoryview
142-
RETURN_VIEW(Exiv2::byte* mmap, $1 ? _global_self->size() : 0,
143-
_global_writeable ? PyBUF_WRITE : PyBUF_READ,)
144-
145-
// Save self and isWriteable (and release memoryviews) when mmap or data
146-
// is called
147-
%typemap(check, fragment="memoryview_funcs")
148-
(Exiv2::BasicIo* self, bool isWriteable)
149-
(Exiv2::BasicIo* _global_self, bool _global_writeable) {
150-
_global_self = $1;
151-
_global_writeable = $2;
152-
release_views(self);
153-
}
142+
RETURN_VIEW(Exiv2::byte* mmap, $1 ? arg1->size() : 0,
143+
arg2 ? PyBUF_WRITE : PyBUF_READ,)
154144

155145
// Some methods of BasicIo release any existing memoryview
156146
%{
157147
#define RELEASE_VIEWS_BasicIo_close
148+
#define RELEASE_VIEWS_BasicIo_data
149+
#define RELEASE_VIEWS_BasicIo_mmap
158150
#define RELEASE_VIEWS_BasicIo_munmap
159151
#define RELEASE_VIEWS_BasicIo_open
160152
#define RELEASE_VIEWS_BasicIo_putb
@@ -169,8 +161,8 @@ RETURN_VIEW(Exiv2::byte* mmap, $1 ? _global_self->size() : 0,
169161

170162
// Add data() method for easy access
171163
// The callback is used to call munmap when the memoryview is deleted
172-
RETURN_VIEW(Exiv2::byte* data, $1 ? _global_self->size() : 0,
173-
_global_writeable ? PyBUF_WRITE : PyBUF_READ,)
164+
RETURN_VIEW(Exiv2::byte* data, $1 ? arg1->size() : 0,
165+
arg2 ? PyBUF_WRITE : PyBUF_READ,)
174166
%feature("docstring") Exiv2::BasicIo::data
175167
"Easy access to the IO data.
176168

src/swig-0_27_7/basicio_wrap.cxx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4334,6 +4334,8 @@ typedef Exiv2::ErrorCode ErrorCode;
43344334

43354335

43364336
#define RELEASE_VIEWS_BasicIo_close
4337+
#define RELEASE_VIEWS_BasicIo_data
4338+
#define RELEASE_VIEWS_BasicIo_mmap
43374339
#define RELEASE_VIEWS_BasicIo_munmap
43384340
#define RELEASE_VIEWS_BasicIo_open
43394341
#define RELEASE_VIEWS_BasicIo_putb
@@ -5467,8 +5469,6 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
54675469
int res1 = 0 ;
54685470
bool val2 ;
54695471
int ecode2 = 0 ;
5470-
Exiv2::BasicIo *_global_self ;
5471-
bool _global_writeable ;
54725472
PyObject * obj1 = 0 ;
54735473
Exiv2::byte *result = 0 ;
54745474

@@ -5489,9 +5489,9 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
54895489
arg2 = static_cast< bool >(val2);
54905490
}
54915491
{
5492-
_global_self = arg1;
5493-
_global_writeable = arg2;
5492+
#ifdef RELEASE_VIEWS_BasicIo_mmap
54945493
release_views(self);
5494+
#endif
54955495
}
54965496
{
54975497
try {
@@ -5507,7 +5507,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
55075507
}
55085508
}
55095509
{
5510-
resultobj = PyMemoryView_FromMemory((char*)result, result ? _global_self->size() : 0, _global_writeable ? PyBUF_WRITE : PyBUF_READ);
5510+
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, arg2 ? PyBUF_WRITE : PyBUF_READ);
55115511
if (!resultobj)
55125512
SWIG_fail;
55135513
// Store a weak ref to the new memoryview
@@ -5783,8 +5783,6 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
57835783
int res1 = 0 ;
57845784
bool val2 ;
57855785
int ecode2 = 0 ;
5786-
Exiv2::BasicIo *_global_self ;
5787-
bool _global_writeable ;
57885786
PyObject * obj1 = 0 ;
57895787
Exiv2::byte *result = 0 ;
57905788

@@ -5805,9 +5803,9 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
58055803
arg2 = static_cast< bool >(val2);
58065804
}
58075805
{
5808-
_global_self = arg1;
5809-
_global_writeable = arg2;
5806+
#ifdef RELEASE_VIEWS_BasicIo_data
58105807
release_views(self);
5808+
#endif
58115809
}
58125810
{
58135811
try {
@@ -5823,7 +5821,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
58235821
}
58245822
}
58255823
{
5826-
resultobj = PyMemoryView_FromMemory((char*)result, result ? _global_self->size() : 0, _global_writeable ? PyBUF_WRITE : PyBUF_READ);
5824+
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, arg2 ? PyBUF_WRITE : PyBUF_READ);
58275825
if (!resultobj)
58285826
SWIG_fail;
58295827
// Store a weak ref to the new memoryview

src/swig-0_28_7/basicio_wrap.cxx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4333,6 +4333,8 @@ typedef Exiv2::ErrorCode ErrorCode;
43334333

43344334

43354335
#define RELEASE_VIEWS_BasicIo_close
4336+
#define RELEASE_VIEWS_BasicIo_data
4337+
#define RELEASE_VIEWS_BasicIo_mmap
43364338
#define RELEASE_VIEWS_BasicIo_munmap
43374339
#define RELEASE_VIEWS_BasicIo_open
43384340
#define RELEASE_VIEWS_BasicIo_putb
@@ -5730,8 +5732,6 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
57305732
int res1 = 0 ;
57315733
bool val2 ;
57325734
int ecode2 = 0 ;
5733-
Exiv2::BasicIo *_global_self ;
5734-
bool _global_writeable ;
57355735
PyObject * obj1 = 0 ;
57365736
Exiv2::byte *result = 0 ;
57375737

@@ -5752,9 +5752,9 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
57525752
arg2 = static_cast< bool >(val2);
57535753
}
57545754
{
5755-
_global_self = arg1;
5756-
_global_writeable = arg2;
5755+
#ifdef RELEASE_VIEWS_BasicIo_mmap
57575756
release_views(self);
5757+
#endif
57585758
}
57595759
{
57605760
try {
@@ -5770,7 +5770,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_mmap(PyObject *self, PyObject *args) {
57705770
}
57715771
}
57725772
{
5773-
resultobj = PyMemoryView_FromMemory((char*)result, result ? _global_self->size() : 0, _global_writeable ? PyBUF_WRITE : PyBUF_READ);
5773+
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, arg2 ? PyBUF_WRITE : PyBUF_READ);
57745774
if (!resultobj)
57755775
SWIG_fail;
57765776
// Store a weak ref to the new memoryview
@@ -6048,8 +6048,6 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
60486048
int res1 = 0 ;
60496049
bool val2 ;
60506050
int ecode2 = 0 ;
6051-
Exiv2::BasicIo *_global_self ;
6052-
bool _global_writeable ;
60536051
PyObject * obj1 = 0 ;
60546052
Exiv2::byte *result = 0 ;
60556053

@@ -6070,9 +6068,9 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
60706068
arg2 = static_cast< bool >(val2);
60716069
}
60726070
{
6073-
_global_self = arg1;
6074-
_global_writeable = arg2;
6071+
#ifdef RELEASE_VIEWS_BasicIo_data
60756072
release_views(self);
6073+
#endif
60766074
}
60776075
{
60786076
try {
@@ -6088,7 +6086,7 @@ SWIGINTERN PyObject *_wrap_BasicIo_data(PyObject *self, PyObject *args) {
60886086
}
60896087
}
60906088
{
6091-
resultobj = PyMemoryView_FromMemory((char*)result, result ? _global_self->size() : 0, _global_writeable ? PyBUF_WRITE : PyBUF_READ);
6089+
resultobj = PyMemoryView_FromMemory((char*)result, result ? arg1->size() : 0, arg2 ? PyBUF_WRITE : PyBUF_READ);
60926090
if (!resultobj)
60936091
SWIG_fail;
60946092
// Store a weak ref to the new memoryview

0 commit comments

Comments
 (0)