Skip to content

Commit f122a83

Browse files
Slight simplification of iterator definitions
1 parent 7a69d11 commit f122a83

File tree

10 files changed

+20
-54
lines changed

10 files changed

+20
-54
lines changed

src/interface/exif.i

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// python-exiv2 - Python interface to libexiv2
22
// http://github.com/jim-easterbrook/python-exiv2
3-
// Copyright (C) 2021-24 Jim Easterbrook [email protected]
3+
// Copyright (C) 2021-25 Jim Easterbrook [email protected]
44
//
55
// This program is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -61,10 +61,7 @@ INPUT_BUFFER_RO(const Exiv2::byte* buf, size_t size)
6161

6262
EXTEND_METADATUM(Exiv2::Exifdatum)
6363

64-
DATA_ITERATOR_TYPEMAPS(ExifData)
65-
#ifndef SWIGIMPORTED
66-
DATA_ITERATOR_CLASSES(ExifData, Exifdatum)
67-
#endif
64+
DATA_ITERATOR(ExifData, Exifdatum)
6865

6966
// Get the current (or default if not set) type id of a datum
7067
%fragment("get_type_id"{Exiv2::Exifdatum}, "header") {

src/interface/iptc.i

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// python-exiv2 - Python interface to libexiv2
22
// http://github.com/jim-easterbrook/python-exiv2
3-
// Copyright (C) 2021-24 Jim Easterbrook [email protected]
3+
// Copyright (C) 2021-25 Jim Easterbrook [email protected]
44
//
55
// This program is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -42,10 +42,7 @@ EXCEPTION()
4242

4343
EXTEND_METADATUM(Exiv2::Iptcdatum)
4444

45-
DATA_ITERATOR_TYPEMAPS(IptcData)
46-
#ifndef SWIGIMPORTED
47-
DATA_ITERATOR_CLASSES(IptcData, Iptcdatum)
48-
#endif
45+
DATA_ITERATOR(IptcData, Iptcdatum)
4946

5047
// Get the current (or default if not set) type id of a datum
5148
%fragment("get_type_id"{Exiv2::Iptcdatum}, "header") {

src/interface/shared/data_iterator.i

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
%include "shared/keep_reference.i"
2020

2121

22-
// Macros to wrap data iterators
23-
%define DATA_ITERATOR_CLASSES(container_type, datum_type)
22+
// Macro to wrap data iterators
23+
%define DATA_ITERATOR(container_type, datum_type)
2424
%feature("python:slot", "tp_str", functype="reprfunc")
2525
container_type##_iterator::__str__;
2626
%feature("python:slot", "tp_iter", functype="getiterfunc")
@@ -48,7 +48,6 @@ KEEP_REFERENCE(container_type##_iterator*)
4848
$typemap(out, Exiv2::datum_type*)
4949
}
5050
%inline %{
51-
// Base class implements all methods except dereferencing
5251
class container_type##_iterator {
5352
private:
5453
Exiv2::container_type::iterator ptr;
@@ -68,9 +67,7 @@ public:
6867
"container_type changed size during iteration");
6968
if (ptr == end)
7069
return NULL;
71-
Exiv2::datum_type* result = &(*ptr);
72-
ptr++;
73-
return result;
70+
return &(*ptr++);
7471
}
7572
Exiv2::container_type::iterator operator*() const { return ptr; }
7673
bool operator==(const container_type##_iterator &other) const {
@@ -106,10 +103,7 @@ public:
106103
}
107104
};
108105
%}
109-
%enddef // DATA_ITERATOR_CLASSES
110106

111-
// Declare typemaps for data iterators.
112-
%define DATA_ITERATOR_TYPEMAPS(container_type)
113107
%typemap(in) Exiv2::container_type::iterator
114108
(container_type##_iterator *argp=NULL) %{
115109
{
@@ -153,13 +147,11 @@ public:
153147
// Functions to store weak references to iterators (swig >= v4.4)
154148
%fragment("iterator_weakref_funcs", "header", fragment="private_data") {
155149
static void _process_list(PyObject* list, bool invalidate) {
156-
PyObject* ref = NULL;
157150
PyObject* iterator = NULL;
158151
for (Py_ssize_t idx = PyList_Size(list); idx > 0; idx--) {
159-
ref = PyList_GetItem(list, idx - 1);
160-
iterator = PyWeakref_GetObject(ref);
152+
iterator = PyWeakref_GetObject(PyList_GetItem(list, idx-1));
161153
if (iterator == Py_None)
162-
PyList_SetSlice(list, idx - 1, idx, NULL);
154+
PyList_SetSlice(list, idx-1, idx, NULL);
163155
else if (invalidate)
164156
Py_XDECREF(PyObject_CallMethod(iterator, "_invalidate", NULL));
165157
}
@@ -214,7 +206,8 @@ static int store_iterator_weakref(PyObject* py_self, PyObject* iterator) {
214206
%newobject Exiv2::container_type::findKey;
215207
// Assumes arg1 is the base class parent
216208
#if SWIG_VERSION >= 0x040400
217-
%typemap(out, fragment="iterator_weakref_funcs") Exiv2::container_type::iterator {
209+
%typemap(out, fragment="iterator_weakref_funcs")
210+
Exiv2::container_type::iterator {
218211
#else
219212
%typemap(out) Exiv2::container_type::iterator {
220213
#endif
@@ -231,4 +224,4 @@ static int store_iterator_weakref(PyObject* py_self, PyObject* iterator) {
231224
}
232225
// Keep a reference to the data being iterated
233226
KEEP_REFERENCE(Exiv2::container_type::iterator)
234-
%enddef // DATA_ITERATOR_TYPEMAPS
227+
%enddef // DATA_ITERATOR

src/interface/xmp.i

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// python-exiv2 - Python interface to libexiv2
22
// http://github.com/jim-easterbrook/python-exiv2
3-
// Copyright (C) 2021-24 Jim Easterbrook [email protected]
3+
// Copyright (C) 2021-25 Jim Easterbrook [email protected]
44
//
55
// This program is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -42,10 +42,7 @@ EXCEPTION()
4242

4343
EXTEND_METADATUM(Exiv2::Xmpdatum)
4444

45-
DATA_ITERATOR_TYPEMAPS(XmpData)
46-
#ifndef SWIGIMPORTED
47-
DATA_ITERATOR_CLASSES(XmpData, Xmpdatum)
48-
#endif
45+
DATA_ITERATOR(XmpData, Xmpdatum)
4946

5047
// Get the current (or default if not set) type id of a datum
5148
%fragment("get_type_id"{Exiv2::Xmpdatum}, "header") {

src/swig-0_27_7/exif_wrap.cxx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4380,7 +4380,6 @@ static void _set_python_exception() {
43804380
#endif
43814381

43824382

4383-
// Base class implements all methods except dereferencing
43844383
class ExifData_iterator {
43854384
private:
43864385
Exiv2::ExifData::iterator ptr;
@@ -4400,9 +4399,7 @@ class ExifData_iterator {
44004399
"ExifData changed size during iteration");
44014400
if (ptr == end)
44024401
return NULL;
4403-
Exiv2::Exifdatum* result = &(*ptr);
4404-
ptr++;
4405-
return result;
4402+
return &(*ptr++);
44064403
}
44074404
Exiv2::ExifData::iterator operator*() const { return ptr; }
44084405
bool operator==(const ExifData_iterator &other) const {

src/swig-0_27_7/iptc_wrap.cxx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4369,7 +4369,6 @@ static void _set_python_exception() {
43694369
};
43704370

43714371

4372-
// Base class implements all methods except dereferencing
43734372
class IptcData_iterator {
43744373
private:
43754374
Exiv2::IptcData::iterator ptr;
@@ -4389,9 +4388,7 @@ class IptcData_iterator {
43894388
"IptcData changed size during iteration");
43904389
if (ptr == end)
43914390
return NULL;
4392-
Exiv2::Iptcdatum* result = &(*ptr);
4393-
ptr++;
4394-
return result;
4391+
return &(*ptr++);
43954392
}
43964393
Exiv2::IptcData::iterator operator*() const { return ptr; }
43974394
bool operator==(const IptcData_iterator &other) const {

src/swig-0_27_7/xmp_wrap.cxx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,7 +4371,6 @@ static void _set_python_exception() {
43714371
};
43724372

43734373

4374-
// Base class implements all methods except dereferencing
43754374
class XmpData_iterator {
43764375
private:
43774376
Exiv2::XmpData::iterator ptr;
@@ -4391,9 +4390,7 @@ class XmpData_iterator {
43914390
"XmpData changed size during iteration");
43924391
if (ptr == end)
43934392
return NULL;
4394-
Exiv2::Xmpdatum* result = &(*ptr);
4395-
ptr++;
4396-
return result;
4393+
return &(*ptr++);
43974394
}
43984395
Exiv2::XmpData::iterator operator*() const { return ptr; }
43994396
bool operator==(const XmpData_iterator &other) const {

src/swig-0_28_5/exif_wrap.cxx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4380,7 +4380,6 @@ static void _set_python_exception() {
43804380
#endif
43814381

43824382

4383-
// Base class implements all methods except dereferencing
43844383
class ExifData_iterator {
43854384
private:
43864385
Exiv2::ExifData::iterator ptr;
@@ -4400,9 +4399,7 @@ class ExifData_iterator {
44004399
"ExifData changed size during iteration");
44014400
if (ptr == end)
44024401
return NULL;
4403-
Exiv2::Exifdatum* result = &(*ptr);
4404-
ptr++;
4405-
return result;
4402+
return &(*ptr++);
44064403
}
44074404
Exiv2::ExifData::iterator operator*() const { return ptr; }
44084405
bool operator==(const ExifData_iterator &other) const {

src/swig-0_28_5/iptc_wrap.cxx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4369,7 +4369,6 @@ static void _set_python_exception() {
43694369
};
43704370

43714371

4372-
// Base class implements all methods except dereferencing
43734372
class IptcData_iterator {
43744373
private:
43754374
Exiv2::IptcData::iterator ptr;
@@ -4389,9 +4388,7 @@ class IptcData_iterator {
43894388
"IptcData changed size during iteration");
43904389
if (ptr == end)
43914390
return NULL;
4392-
Exiv2::Iptcdatum* result = &(*ptr);
4393-
ptr++;
4394-
return result;
4391+
return &(*ptr++);
43954392
}
43964393
Exiv2::IptcData::iterator operator*() const { return ptr; }
43974394
bool operator==(const IptcData_iterator &other) const {

src/swig-0_28_5/xmp_wrap.cxx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,7 +4371,6 @@ static void _set_python_exception() {
43714371
};
43724372

43734373

4374-
// Base class implements all methods except dereferencing
43754374
class XmpData_iterator {
43764375
private:
43774376
Exiv2::XmpData::iterator ptr;
@@ -4391,9 +4390,7 @@ class XmpData_iterator {
43914390
"XmpData changed size during iteration");
43924391
if (ptr == end)
43934392
return NULL;
4394-
Exiv2::Xmpdatum* result = &(*ptr);
4395-
ptr++;
4396-
return result;
4393+
return &(*ptr++);
43974394
}
43984395
Exiv2::XmpData::iterator operator*() const { return ptr; }
43994396
bool operator==(const XmpData_iterator &other) const {

0 commit comments

Comments
 (0)