Skip to content

Commit d348176

Browse files
Tidied up iterator input typemaps
1 parent ca602c5 commit d348176

File tree

8 files changed

+126
-114
lines changed

8 files changed

+126
-114
lines changed

src/interface/shared/data_iterator.i

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,6 @@
2222

2323
// Macro to wrap data iterators
2424
%define DATA_ITERATOR(container_type, datum_type)
25-
// Creating a new iterator keeps a reference to the current one
26-
KEEP_REFERENCE(container_type##_iterator*)
27-
28-
#if SWIG_VERSION < 0x040400
29-
// erase() invalidates the iterator
30-
%typemap(in) (Exiv2::container_type::iterator pos)
31-
(container_type##_iterator *argp=NULL),
32-
(Exiv2::container_type::iterator beg)
33-
(container_type##_iterator *argp=NULL) {
34-
{
35-
container_type##_iterator* arg$argnum = NULL;
36-
$typemap(in, container_type##_iterator*)
37-
argp = arg$argnum;
38-
}
39-
$1 = argp->_ptr();
40-
argp->_invalidate();
41-
}
42-
#endif
43-
// XmpData::eraseFamily takes an iterator reference (and invalidates it)
44-
%typemap(in) Exiv2::container_type::iterator&
45-
(Exiv2::container_type::iterator it,
46-
container_type##_iterator* argp = NULL) {
47-
{
48-
container_type##_iterator* arg$argnum = NULL;
49-
$typemap(in, container_type##_iterator*)
50-
argp = arg$argnum;
51-
}
52-
it = argp->_ptr();
53-
$1 = &it;
54-
#if SWIG_VERSION < 0x040400
55-
argp->_invalidate();
56-
#endif
57-
}
5825

5926
#if SWIG_VERSION >= 0x040400
6027
// Functions to store weak references to iterators (swig >= v4.4)
@@ -134,6 +101,17 @@ static int store_iterator(PyObject* py_self, PyObject* iterator) {
134101
}
135102
#endif
136103

104+
#if SWIG_VERSION < 0x040400
105+
// erase() and eraseFamily() invalidate the iterator passed to them
106+
%typemap(check) (Exiv2::container_type::iterator pos),
107+
(Exiv2::container_type::iterator beg) {
108+
argp$argnum->_invalidate();
109+
}
110+
%typemap(check) Exiv2::container_type::iterator& {
111+
argp$argnum->_invalidate();
112+
}
113+
#endif
114+
137115
#if SWIG_VERSION >= 0x040400
138116
// clear() invalidates all iterators
139117
%typemap(ret, fragment="iterator_store") void clear {
@@ -155,7 +133,4 @@ static int store_iterator(PyObject* py_self, PyObject* iterator) {
155133
}
156134
#endif // SWIG_VERSION
157135

158-
// Keep a reference to the data being iterated
159-
KEEP_REFERENCE(Exiv2::container_type::iterator)
160-
161136
%enddef // DATA_ITERATOR

src/interface/shared/metadatum_wrappers.i

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
*/
2020

2121

22+
%include "shared/keep_reference.i"
23+
24+
2225
// Macro to wrap metadatum iterators and pointers
2326
%define METADATUM_WRAPPERS(container_type, datum_type)
2427

@@ -97,6 +100,10 @@ data it points to."
97100
}
98101
$typemap(out, Exiv2::datum_type*)
99102
}
103+
// Keep a reference to the data being iterated
104+
KEEP_REFERENCE(Exiv2::container_type::iterator)
105+
// Creating a new iterator keeps a reference to the current one
106+
KEEP_REFERENCE(container_type##_iterator*)
100107
%inline %{
101108
class container_type##_iterator: public datum_type##_pointer {
102109
private:
@@ -148,6 +155,17 @@ public:
148155
}
149156
$1 = argp->_ptr();
150157
%}
158+
%typemap(in) Exiv2::container_type::iterator&
159+
(Exiv2::container_type::iterator it,
160+
container_type##_iterator* argp = NULL) {
161+
{
162+
container_type##_iterator* arg$argnum = NULL;
163+
$typemap(in, container_type##_iterator*)
164+
argp = arg$argnum;
165+
}
166+
it = argp->_ptr();
167+
$1 = &it;
168+
}
151169
%newobject Exiv2::container_type::begin;
152170
%newobject Exiv2::container_type::end;
153171
%newobject Exiv2::container_type::erase;
@@ -180,6 +198,8 @@ public:
180198
Python wrapper for an :class:`" #datum_type "` reference. It has most of
181199
the methods of :class:`" #datum_type "` allowing easy access to the
182200
data it points to."
201+
// Keep a reference to the data being referred to
202+
KEEP_REFERENCE(Exiv2::datum_type&)
183203
%inline %{
184204
class datum_type##_reference: public datum_type##_pointer {
185205
private:
@@ -216,4 +236,5 @@ public:
216236
SWIG_as_voidptr(new datum_type##_reference($1)),
217237
$descriptor(datum_type##_reference*), SWIG_POINTER_OWN);
218238
}
239+
219240
%enddef // METADATUM_WRAPPERS

src/swig-0_27_7/exif_wrap.cxx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9700,17 +9700,19 @@ SWIGINTERN PyObject *_wrap_ExifData_erase__SWIG_0(PyObject *self, PyObject *args
97009700
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ExifData_erase" "', argument " "1"" of type '" "Exiv2::ExifData *""'");
97019701
}
97029702
arg1 = reinterpret_cast< Exiv2::ExifData * >(argp1);
9703+
97039704
{
9704-
{
9705-
ExifData_iterator* arg2 = NULL;
9706-
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_ExifData_iterator, 0 | 0 );
9707-
if (!SWIG_IsOK(res10)) {
9708-
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "ExifData_erase" "', argument " "1"" of type '" "ExifData_iterator *""'");
9709-
}
9710-
arg2 = reinterpret_cast< ExifData_iterator * >(argp10);
9711-
argp2 = arg2;
9705+
ExifData_iterator* arg2 = NULL;
9706+
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_ExifData_iterator, 0 | 0 );
9707+
if (!SWIG_IsOK(res10)) {
9708+
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "ExifData_erase" "', argument " "1"" of type '" "ExifData_iterator *""'");
97129709
}
9713-
arg2 = argp2->_ptr();
9710+
arg2 = reinterpret_cast< ExifData_iterator * >(argp10);
9711+
argp2 = arg2;
9712+
}
9713+
arg2 = argp2->_ptr();
9714+
9715+
{
97149716
argp2->_invalidate();
97159717
}
97169718
{
@@ -9769,19 +9771,18 @@ SWIGINTERN PyObject *_wrap_ExifData_erase__SWIG_1(PyObject *self, PyObject *args
97699771
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ExifData_erase" "', argument " "1"" of type '" "Exiv2::ExifData *""'");
97709772
}
97719773
arg1 = reinterpret_cast< Exiv2::ExifData * >(argp1);
9774+
97729775
{
9773-
{
9774-
ExifData_iterator* arg2 = NULL;
9775-
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_ExifData_iterator, 0 | 0 );
9776-
if (!SWIG_IsOK(res10)) {
9777-
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "ExifData_erase" "', argument " "1"" of type '" "ExifData_iterator *""'");
9778-
}
9779-
arg2 = reinterpret_cast< ExifData_iterator * >(argp10);
9780-
argp2 = arg2;
9776+
ExifData_iterator* arg2 = NULL;
9777+
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_ExifData_iterator, 0 | 0 );
9778+
if (!SWIG_IsOK(res10)) {
9779+
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "ExifData_erase" "', argument " "1"" of type '" "ExifData_iterator *""'");
97819780
}
9782-
arg2 = argp2->_ptr();
9783-
argp2->_invalidate();
9781+
arg2 = reinterpret_cast< ExifData_iterator * >(argp10);
9782+
argp2 = arg2;
97849783
}
9784+
arg2 = argp2->_ptr();
9785+
97859786

97869787
{
97879788
ExifData_iterator* arg3 = NULL;
@@ -9794,6 +9795,9 @@ SWIGINTERN PyObject *_wrap_ExifData_erase__SWIG_1(PyObject *self, PyObject *args
97949795
}
97959796
arg3 = argp3->_ptr();
97969797

9798+
{
9799+
argp2->_invalidate();
9800+
}
97979801
{
97989802
try {
97999803
result = (arg1)->erase(SWIG_STD_MOVE(arg2),SWIG_STD_MOVE(arg3));

src/swig-0_27_7/iptc_wrap.cxx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8759,17 +8759,19 @@ SWIGINTERN PyObject *_wrap_IptcData_erase(PyObject *self, PyObject *args) {
87598759
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "IptcData_erase" "', argument " "1"" of type '" "Exiv2::IptcData *""'");
87608760
}
87618761
arg1 = reinterpret_cast< Exiv2::IptcData * >(argp1);
8762+
87628763
{
8763-
{
8764-
IptcData_iterator* arg2 = NULL;
8765-
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_IptcData_iterator, 0 | 0 );
8766-
if (!SWIG_IsOK(res10)) {
8767-
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "IptcData_erase" "', argument " "1"" of type '" "IptcData_iterator *""'");
8768-
}
8769-
arg2 = reinterpret_cast< IptcData_iterator * >(argp10);
8770-
argp2 = arg2;
8764+
IptcData_iterator* arg2 = NULL;
8765+
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_IptcData_iterator, 0 | 0 );
8766+
if (!SWIG_IsOK(res10)) {
8767+
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "IptcData_erase" "', argument " "1"" of type '" "IptcData_iterator *""'");
87718768
}
8772-
arg2 = argp2->_ptr();
8769+
arg2 = reinterpret_cast< IptcData_iterator * >(argp10);
8770+
argp2 = arg2;
8771+
}
8772+
arg2 = argp2->_ptr();
8773+
8774+
{
87738775
argp2->_invalidate();
87748776
}
87758777
{

src/swig-0_27_7/xmp_wrap.cxx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8613,17 +8613,19 @@ SWIGINTERN PyObject *_wrap_XmpData_erase(PyObject *self, PyObject *args) {
86138613
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "XmpData_erase" "', argument " "1"" of type '" "Exiv2::XmpData *""'");
86148614
}
86158615
arg1 = reinterpret_cast< Exiv2::XmpData * >(argp1);
8616+
86168617
{
8617-
{
8618-
XmpData_iterator* arg2 = NULL;
8619-
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_XmpData_iterator, 0 | 0 );
8620-
if (!SWIG_IsOK(res10)) {
8621-
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "XmpData_erase" "', argument " "1"" of type '" "XmpData_iterator *""'");
8622-
}
8623-
arg2 = reinterpret_cast< XmpData_iterator * >(argp10);
8624-
argp2 = arg2;
8618+
XmpData_iterator* arg2 = NULL;
8619+
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_XmpData_iterator, 0 | 0 );
8620+
if (!SWIG_IsOK(res10)) {
8621+
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "XmpData_erase" "', argument " "1"" of type '" "XmpData_iterator *""'");
86258622
}
8626-
arg2 = argp2->_ptr();
8623+
arg2 = reinterpret_cast< XmpData_iterator * >(argp10);
8624+
argp2 = arg2;
8625+
}
8626+
arg2 = argp2->_ptr();
8627+
8628+
{
86278629
argp2->_invalidate();
86288630
}
86298631
{
@@ -8689,9 +8691,9 @@ SWIGINTERN PyObject *_wrap_XmpData_eraseFamily(PyObject *self, PyObject *args) {
86898691
}
86908692
it2 = argp2->_ptr();
86918693
arg2 = &it2;
8692-
8694+
}
8695+
{
86938696
argp2->_invalidate();
8694-
86958697
}
86968698
{
86978699
try {

src/swig-0_28_5/exif_wrap.cxx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9904,17 +9904,19 @@ SWIGINTERN PyObject *_wrap_ExifData_erase__SWIG_0(PyObject *self, PyObject *args
99049904
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ExifData_erase" "', argument " "1"" of type '" "Exiv2::ExifData *""'");
99059905
}
99069906
arg1 = reinterpret_cast< Exiv2::ExifData * >(argp1);
9907+
99079908
{
9908-
{
9909-
ExifData_iterator* arg2 = NULL;
9910-
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_ExifData_iterator, 0 | 0 );
9911-
if (!SWIG_IsOK(res10)) {
9912-
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "ExifData_erase" "', argument " "1"" of type '" "ExifData_iterator *""'");
9913-
}
9914-
arg2 = reinterpret_cast< ExifData_iterator * >(argp10);
9915-
argp2 = arg2;
9909+
ExifData_iterator* arg2 = NULL;
9910+
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_ExifData_iterator, 0 | 0 );
9911+
if (!SWIG_IsOK(res10)) {
9912+
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "ExifData_erase" "', argument " "1"" of type '" "ExifData_iterator *""'");
99169913
}
9917-
arg2 = argp2->_ptr();
9914+
arg2 = reinterpret_cast< ExifData_iterator * >(argp10);
9915+
argp2 = arg2;
9916+
}
9917+
arg2 = argp2->_ptr();
9918+
9919+
{
99189920
argp2->_invalidate();
99199921
}
99209922
{
@@ -9973,19 +9975,18 @@ SWIGINTERN PyObject *_wrap_ExifData_erase__SWIG_1(PyObject *self, PyObject *args
99739975
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ExifData_erase" "', argument " "1"" of type '" "Exiv2::ExifData *""'");
99749976
}
99759977
arg1 = reinterpret_cast< Exiv2::ExifData * >(argp1);
9978+
99769979
{
9977-
{
9978-
ExifData_iterator* arg2 = NULL;
9979-
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_ExifData_iterator, 0 | 0 );
9980-
if (!SWIG_IsOK(res10)) {
9981-
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "ExifData_erase" "', argument " "1"" of type '" "ExifData_iterator *""'");
9982-
}
9983-
arg2 = reinterpret_cast< ExifData_iterator * >(argp10);
9984-
argp2 = arg2;
9980+
ExifData_iterator* arg2 = NULL;
9981+
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_ExifData_iterator, 0 | 0 );
9982+
if (!SWIG_IsOK(res10)) {
9983+
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "ExifData_erase" "', argument " "1"" of type '" "ExifData_iterator *""'");
99859984
}
9986-
arg2 = argp2->_ptr();
9987-
argp2->_invalidate();
9985+
arg2 = reinterpret_cast< ExifData_iterator * >(argp10);
9986+
argp2 = arg2;
99889987
}
9988+
arg2 = argp2->_ptr();
9989+
99899990

99909991
{
99919992
ExifData_iterator* arg3 = NULL;
@@ -9998,6 +9999,9 @@ SWIGINTERN PyObject *_wrap_ExifData_erase__SWIG_1(PyObject *self, PyObject *args
99989999
}
999910000
arg3 = argp3->_ptr();
1000010001

10002+
{
10003+
argp2->_invalidate();
10004+
}
1000110005
{
1000210006
try {
1000310007
result = (arg1)->erase(SWIG_STD_MOVE(arg2),SWIG_STD_MOVE(arg3));

src/swig-0_28_5/iptc_wrap.cxx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8970,17 +8970,19 @@ SWIGINTERN PyObject *_wrap_IptcData_erase(PyObject *self, PyObject *args) {
89708970
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "IptcData_erase" "', argument " "1"" of type '" "Exiv2::IptcData *""'");
89718971
}
89728972
arg1 = reinterpret_cast< Exiv2::IptcData * >(argp1);
8973+
89738974
{
8974-
{
8975-
IptcData_iterator* arg2 = NULL;
8976-
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_IptcData_iterator, 0 | 0 );
8977-
if (!SWIG_IsOK(res10)) {
8978-
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "IptcData_erase" "', argument " "1"" of type '" "IptcData_iterator *""'");
8979-
}
8980-
arg2 = reinterpret_cast< IptcData_iterator * >(argp10);
8981-
argp2 = arg2;
8975+
IptcData_iterator* arg2 = NULL;
8976+
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_IptcData_iterator, 0 | 0 );
8977+
if (!SWIG_IsOK(res10)) {
8978+
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "IptcData_erase" "', argument " "1"" of type '" "IptcData_iterator *""'");
89828979
}
8983-
arg2 = argp2->_ptr();
8980+
arg2 = reinterpret_cast< IptcData_iterator * >(argp10);
8981+
argp2 = arg2;
8982+
}
8983+
arg2 = argp2->_ptr();
8984+
8985+
{
89848986
argp2->_invalidate();
89858987
}
89868988
{

src/swig-0_28_5/xmp_wrap.cxx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8876,17 +8876,19 @@ SWIGINTERN PyObject *_wrap_XmpData_erase(PyObject *self, PyObject *args) {
88768876
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "XmpData_erase" "', argument " "1"" of type '" "Exiv2::XmpData *""'");
88778877
}
88788878
arg1 = reinterpret_cast< Exiv2::XmpData * >(argp1);
8879+
88798880
{
8880-
{
8881-
XmpData_iterator* arg2 = NULL;
8882-
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_XmpData_iterator, 0 | 0 );
8883-
if (!SWIG_IsOK(res10)) {
8884-
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "XmpData_erase" "', argument " "1"" of type '" "XmpData_iterator *""'");
8885-
}
8886-
arg2 = reinterpret_cast< XmpData_iterator * >(argp10);
8887-
argp2 = arg2;
8881+
XmpData_iterator* arg2 = NULL;
8882+
res10 = SWIG_ConvertPtr(obj1, &argp10,SWIGTYPE_p_XmpData_iterator, 0 | 0 );
8883+
if (!SWIG_IsOK(res10)) {
8884+
SWIG_exception_fail(SWIG_ArgError(res10), "in method '" "XmpData_erase" "', argument " "1"" of type '" "XmpData_iterator *""'");
88888885
}
8889-
arg2 = argp2->_ptr();
8886+
arg2 = reinterpret_cast< XmpData_iterator * >(argp10);
8887+
argp2 = arg2;
8888+
}
8889+
arg2 = argp2->_ptr();
8890+
8891+
{
88908892
argp2->_invalidate();
88918893
}
88928894
{
@@ -8952,9 +8954,9 @@ SWIGINTERN PyObject *_wrap_XmpData_eraseFamily(PyObject *self, PyObject *args) {
89528954
}
89538955
it2 = argp2->_ptr();
89548956
arg2 = &it2;
8955-
8957+
}
8958+
{
89568959
argp2->_invalidate();
8957-
89588960
}
89598961
{
89608962
try {

0 commit comments

Comments
 (0)