Skip to content

Commit 1e6e15e

Browse files
Use INIT_ERROR_RETURN macro in initialisation
In SWIG v4.4 the error return value is -1 instead of NULL. Using a macro makes it easy to adapt.
1 parent a910c66 commit 1e6e15e

34 files changed

Lines changed: 211 additions & 111 deletions

src/interface/error.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ static void log_to_python(int level, const char* msg) {
5555
{
5656
PyObject *module = PyImport_ImportModule("logging");
5757
if (!module)
58-
return NULL;
58+
return INIT_ERROR_RETURN;
5959
logger = PyObject_CallMethod(module, "getLogger", "(s)", "exiv2");
6060
Py_DECREF(module);
6161
if (!logger) {
6262
PyErr_SetString(PyExc_RuntimeError, "logging.getLogger failed.");
63-
return NULL;
63+
return INIT_ERROR_RETURN;
6464
}
6565
Exiv2::LogMsg::setHandler(&log_to_python);
6666
}

src/interface/shared/enum.i

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static PyObject* exiv2_module = NULL;
2626
{
2727
exiv2_module = PyImport_ImportModule("exiv2");
2828
if (!exiv2_module)
29-
return NULL;
29+
return INIT_ERROR_RETURN;
3030
}
3131
}
3232

@@ -143,12 +143,12 @@ static PyObject* Py_IntEnum = NULL;
143143
{
144144
PyObject* module = PyImport_ImportModule("enum");
145145
if (!module)
146-
return NULL;
146+
return INIT_ERROR_RETURN;
147147
Py_IntEnum = PyObject_GetAttrString(module, "IntEnum");
148148
Py_DECREF(module);
149149
if (!Py_IntEnum) {
150150
PyErr_SetString(PyExc_RuntimeError, "Import error: enum.IntEnum.");
151-
return NULL;
151+
return INIT_ERROR_RETURN;
152152
}
153153
}
154154
}

src/interface/shared/exception.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static PyObject* PyExc_Exiv2Error = NULL;
3333
if (!PyExc_Exiv2Error) {
3434
PyErr_SetString(PyExc_RuntimeError,
3535
"Import error: exiv2.Exiv2Error not found.");
36-
return NULL;
36+
return INIT_ERROR_RETURN;
3737
}
3838
}
3939
}

src/interface/shared/preamble.i

Lines changed: 11 additions & 1 deletion
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 jim@jim-easterbrook.me.uk
3+
// Copyright (C) 2021-25 Jim Easterbrook jim@jim-easterbrook.me.uk
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
@@ -19,6 +19,16 @@
1919
#include "exiv2/exiv2.hpp"
2020
%}
2121

22+
#if SWIG_VERSION < 0x040400
23+
%{
24+
#define INIT_ERROR_RETURN NULL
25+
%}
26+
#else
27+
%{
28+
#define INIT_ERROR_RETURN -1
29+
%}
30+
#endif
31+
2232
// EXIV2API prepends every function declaration
2333
#define EXIV2API
2434
// Some have this instead

src/swig-0_27_7/basicio_wrap.cxx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4205,6 +4205,9 @@ SWIG_FromCharPtr(const char *cptr)
42054205
#include "exiv2/exiv2.hpp"
42064206

42074207

4208+
#define INIT_ERROR_RETURN NULL
4209+
4210+
42084211
#include <string>
42094212

42104213

@@ -6777,7 +6780,7 @@ SWIG_init(void) {
67776780
{
67786781
exiv2_module = PyImport_ImportModule("exiv2");
67796782
if (!exiv2_module)
6780-
return NULL;
6783+
return INIT_ERROR_RETURN;
67816784
}
67826785

67836786

@@ -6786,7 +6789,7 @@ SWIG_init(void) {
67866789
if (!PyExc_Exiv2Error) {
67876790
PyErr_SetString(PyExc_RuntimeError,
67886791
"Import error: exiv2.Exiv2Error not found.");
6789-
return NULL;
6792+
return INIT_ERROR_RETURN;
67906793
}
67916794
}
67926795

@@ -6797,12 +6800,12 @@ SWIG_init(void) {
67976800
{
67986801
PyObject* module = PyImport_ImportModule("enum");
67996802
if (!module)
6800-
return NULL;
6803+
return INIT_ERROR_RETURN;
68016804
Py_IntEnum = PyObject_GetAttrString(module, "IntEnum");
68026805
Py_DECREF(module);
68036806
if (!Py_IntEnum) {
68046807
PyErr_SetString(PyExc_RuntimeError, "Import error: enum.IntEnum.");
6805-
return NULL;
6808+
return INIT_ERROR_RETURN;
68066809
}
68076810
}
68086811

src/swig-0_27_7/datasets_wrap.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4230,6 +4230,9 @@ SWIG_FromCharPtr(const char *cptr)
42304230
#include "exiv2/exiv2.hpp"
42314231

42324232

4233+
#define INIT_ERROR_RETURN NULL
4234+
4235+
42334236
static PyObject* PyExc_Exiv2Error = NULL;
42344237

42354238

@@ -7865,7 +7868,7 @@ SWIG_init(void) {
78657868
{
78667869
exiv2_module = PyImport_ImportModule("exiv2");
78677870
if (!exiv2_module)
7868-
return NULL;
7871+
return INIT_ERROR_RETURN;
78697872
}
78707873

78717874

@@ -7874,7 +7877,7 @@ SWIG_init(void) {
78747877
if (!PyExc_Exiv2Error) {
78757878
PyErr_SetString(PyExc_RuntimeError,
78767879
"Import error: exiv2.Exiv2Error not found.");
7877-
return NULL;
7880+
return INIT_ERROR_RETURN;
78787881
}
78797882
}
78807883

src/swig-0_27_7/easyaccess_wrap.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,6 +4186,9 @@ SWIG_FromCharPtr(const char *cptr)
41864186
#include "exiv2/exiv2.hpp"
41874187

41884188

4189+
#define INIT_ERROR_RETURN NULL
4190+
4191+
41894192
static PyObject* PyExc_Exiv2Error = NULL;
41904193

41914194

@@ -6386,7 +6389,7 @@ SWIG_init(void) {
63866389
{
63876390
exiv2_module = PyImport_ImportModule("exiv2");
63886391
if (!exiv2_module)
6389-
return NULL;
6392+
return INIT_ERROR_RETURN;
63906393
}
63916394

63926395

@@ -6395,7 +6398,7 @@ SWIG_init(void) {
63956398
if (!PyExc_Exiv2Error) {
63966399
PyErr_SetString(PyExc_RuntimeError,
63976400
"Import error: exiv2.Exiv2Error not found.");
6398-
return NULL;
6401+
return INIT_ERROR_RETURN;
63996402
}
64006403
}
64016404

src/swig-0_27_7/error_wrap.cxx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4188,6 +4188,9 @@ SWIG_FromCharPtr(const char *cptr)
41884188
#include "exiv2/exiv2.hpp"
41894189

41904190

4191+
#define INIT_ERROR_RETURN NULL
4192+
4193+
41914194
#include <typeinfo>
41924195
#include <stdexcept>
41934196

@@ -5552,7 +5555,7 @@ SWIG_init(void) {
55525555
{
55535556
exiv2_module = PyImport_ImportModule("exiv2");
55545557
if (!exiv2_module)
5555-
return NULL;
5558+
return INIT_ERROR_RETURN;
55565559
}
55575560

55585561
SWIG_Python_SetConstant(d, d == md ? public_interface : NULL, "Exiv2Error",PyObject_GetAttrString(
@@ -5561,12 +5564,12 @@ SWIG_init(void) {
55615564
{
55625565
PyObject *module = PyImport_ImportModule("logging");
55635566
if (!module)
5564-
return NULL;
5567+
return INIT_ERROR_RETURN;
55655568
logger = PyObject_CallMethod(module, "getLogger", "(s)", "exiv2");
55665569
Py_DECREF(module);
55675570
if (!logger) {
55685571
PyErr_SetString(PyExc_RuntimeError, "logging.getLogger failed.");
5569-
return NULL;
5572+
return INIT_ERROR_RETURN;
55705573
}
55715574
Exiv2::LogMsg::setHandler(&log_to_python);
55725575
}
@@ -5575,12 +5578,12 @@ SWIG_init(void) {
55755578
{
55765579
PyObject* module = PyImport_ImportModule("enum");
55775580
if (!module)
5578-
return NULL;
5581+
return INIT_ERROR_RETURN;
55795582
Py_IntEnum = PyObject_GetAttrString(module, "IntEnum");
55805583
Py_DECREF(module);
55815584
if (!Py_IntEnum) {
55825585
PyErr_SetString(PyExc_RuntimeError, "Import error: enum.IntEnum.");
5583-
return NULL;
5586+
return INIT_ERROR_RETURN;
55845587
}
55855588
}
55865589

src/swig-0_27_7/exif_wrap.cxx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4240,6 +4240,9 @@ SWIG_FromCharPtr(const char *cptr)
42404240
#include "exiv2/exiv2.hpp"
42414241

42424242

4243+
#define INIT_ERROR_RETURN NULL
4244+
4245+
42434246
#include <stdint.h> // Use the C99 official header
42444247

42454248

@@ -13558,7 +13561,7 @@ SWIG_init(void) {
1355813561
{
1355913562
exiv2_module = PyImport_ImportModule("exiv2");
1356013563
if (!exiv2_module)
13561-
return NULL;
13564+
return INIT_ERROR_RETURN;
1356213565
}
1356313566

1356413567

@@ -13567,7 +13570,7 @@ SWIG_init(void) {
1356713570
if (!PyExc_Exiv2Error) {
1356813571
PyErr_SetString(PyExc_RuntimeError,
1356913572
"Import error: exiv2.Exiv2Error not found.");
13570-
return NULL;
13573+
return INIT_ERROR_RETURN;
1357113574
}
1357213575
}
1357313576

@@ -13598,12 +13601,12 @@ SWIG_init(void) {
1359813601
{
1359913602
PyObject* module = PyImport_ImportModule("enum");
1360013603
if (!module)
13601-
return NULL;
13604+
return INIT_ERROR_RETURN;
1360213605
Py_IntEnum = PyObject_GetAttrString(module, "IntEnum");
1360313606
Py_DECREF(module);
1360413607
if (!Py_IntEnum) {
1360513608
PyErr_SetString(PyExc_RuntimeError, "Import error: enum.IntEnum.");
13606-
return NULL;
13609+
return INIT_ERROR_RETURN;
1360713610
}
1360813611
}
1360913612

src/swig-0_27_7/image_wrap.cxx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,6 +4256,9 @@ SWIG_FromCharPtr(const char *cptr)
42564256
#include "exiv2/exiv2.hpp"
42574257

42584258

4259+
#define INIT_ERROR_RETURN NULL
4260+
4261+
42594262
#include <string>
42604263

42614264

@@ -9188,7 +9191,7 @@ SWIG_init(void) {
91889191
{
91899192
exiv2_module = PyImport_ImportModule("exiv2");
91909193
if (!exiv2_module)
9191-
return NULL;
9194+
return INIT_ERROR_RETURN;
91929195
}
91939196

91949197

@@ -9197,7 +9200,7 @@ SWIG_init(void) {
91979200
if (!PyExc_Exiv2Error) {
91989201
PyErr_SetString(PyExc_RuntimeError,
91999202
"Import error: exiv2.Exiv2Error not found.");
9200-
return NULL;
9203+
return INIT_ERROR_RETURN;
92019204
}
92029205
}
92039206

@@ -9210,12 +9213,12 @@ SWIG_init(void) {
92109213
{
92119214
PyObject* module = PyImport_ImportModule("enum");
92129215
if (!module)
9213-
return NULL;
9216+
return INIT_ERROR_RETURN;
92149217
Py_IntEnum = PyObject_GetAttrString(module, "IntEnum");
92159218
Py_DECREF(module);
92169219
if (!Py_IntEnum) {
92179220
PyErr_SetString(PyExc_RuntimeError, "Import error: enum.IntEnum.");
9218-
return NULL;
9221+
return INIT_ERROR_RETURN;
92199222
}
92209223
}
92219224

0 commit comments

Comments
 (0)