1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
From 7a2c9f9348e1bf6bd95033d0b4da09a243fd9e6d Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Mon, 8 Jul 2019 14:34:55 +0200
Subject: [PATCH] Python bindings: add compatibility with SWIG 4.0 (based on
patch by @perestoronin, fixes #1702)
---
gdal/swig/include/gdal_array.i | 6 ++++++
gdal/swig/include/python/typemaps_python.i | 9 ++++++++-
gdal/swig/python/extensions/gdal_array_wrap.cpp | 15 ++++++++++++++-
gdal/swig/python/extensions/gdal_wrap.cpp | 9 ++++++++-
4 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/swig/include/gdal_array.i b/swig/include/gdal_array.i
index c4f6f19b610..bf053eb2476 100644
--- a/swig/include/gdal_array.i
+++ b/swig/include/gdal_array.i
@@ -899,12 +899,18 @@ retStringAndCPLFree* GetArrayFilename(PyArrayObject *psArray)
}
/* Keep a reference to the VirtualMem object */
+%#if SWIGVERSION >= 0x040000
+%#define obj0 swig_obj[0]
+%#endif
%#if NPY_API_VERSION >= 0x00000007
PyArray_SetBaseObject(ar, obj0);
%#else
PyArray_BASE(ar) = obj0;
%#endif
Py_INCREF(obj0);
+%#if SWIGVERSION >= 0x040000
+%#undef obj0
+%#endif
Py_DECREF($result);
$result = (PyObject*) ar;
}
diff --git a/swig/include/python/typemaps_python.i b/swig/include/python/typemaps_python.i
index 5c9f36ab278..9266422e9c4 100644
--- a/swig/include/python/typemaps_python.i
+++ b/swig/include/python/typemaps_python.i
@@ -2104,7 +2104,14 @@ DecomposeSequenceOf4DCoordinates( PyObject *seq, int nCount, double *x, double *
%#if PY_VERSION_HEX >= 0x02070000
/* %typemap(argout) (void** pptr, size_t* pnsize, GDALDataType* pdatatype, int* preadonly)*/
Py_buffer *buf=(Py_buffer*)malloc(sizeof(Py_buffer));
- if (PyBuffer_FillInfo(buf, obj0, *($1), *($2), *($4), PyBUF_ND)) {
+
+ if (PyBuffer_FillInfo(buf,
+%#if SWIGVERSION >= 0x040000
+ swig_obj[0],
+%#else
+ obj0,
+%#endif
+ *($1), *($2), *($4), PyBUF_ND)) {
// error, handle
}
if( *($3) == GDT_Byte )
diff --git a/swig/python/extensions/gdal_array_wrap.cpp b/swig/python/extensions/gdal_array_wrap.cpp
index 807e12dd4a0..4435803e6d9 100644
--- a/swig/python/extensions/gdal_array_wrap.cpp
+++ b/swig/python/extensions/gdal_array_wrap.cpp
@@ -4598,7 +4598,14 @@ SWIGINTERN PyObject *_wrap_VirtualMem_GetAddr(PyObject *SWIGUNUSEDPARM(self), Py
#if PY_VERSION_HEX >= 0x02070000
/* %typemap(argout) (void** pptr, size_t* pnsize, GDALDataType* pdatatype, int* preadonly)*/
Py_buffer *buf=(Py_buffer*)malloc(sizeof(Py_buffer));
- if (PyBuffer_FillInfo(buf, obj0, *(arg2), *(arg3), *(arg5), PyBUF_ND)) {
+
+ if (PyBuffer_FillInfo(buf,
+ #if SWIGVERSION >= 0x040000
+ swig_obj[0],
+ #else
+ obj0,
+ #endif
+ *(arg2), *(arg3), *(arg5), PyBUF_ND)) {
// error, handle
}
if( *(arg4) == GDT_Byte )
@@ -5597,12 +5604,18 @@ SWIGINTERN PyObject *_wrap_VirtualMemGetArray(PyObject *SWIGUNUSEDPARM(self), Py
}
/* Keep a reference to the VirtualMem object */
+#if SWIGVERSION >= 0x040000
+#define obj0 swig_obj[0]
+#endif
#if NPY_API_VERSION >= 0x00000007
PyArray_SetBaseObject(ar, obj0);
#else
PyArray_BASE(ar) = obj0;
#endif
Py_INCREF(obj0);
+#if SWIGVERSION >= 0x040000
+#undef obj0
+#endif
Py_DECREF(resultobj);
resultobj = (PyObject*) ar;
}
diff --git a/swig/python/extensions/gdal_wrap.cpp b/swig/python/extensions/gdal_wrap.cpp
index 37cb635339e..f2f014fd0b5 100644
--- a/swig/python/extensions/gdal_wrap.cpp
+++ b/swig/python/extensions/gdal_wrap.cpp
@@ -15238,7 +15238,14 @@ SWIGINTERN PyObject *_wrap_VirtualMem_GetAddr(PyObject *SWIGUNUSEDPARM(self), Py
#if PY_VERSION_HEX >= 0x02070000
/* %typemap(argout) (void** pptr, size_t* pnsize, GDALDataType* pdatatype, int* preadonly)*/
Py_buffer *buf=(Py_buffer*)malloc(sizeof(Py_buffer));
- if (PyBuffer_FillInfo(buf, obj0, *(arg2), *(arg3), *(arg5), PyBUF_ND)) {
+
+ if (PyBuffer_FillInfo(buf,
+ #if SWIGVERSION >= 0x040000
+ swig_obj[0],
+ #else
+ obj0,
+ #endif
+ *(arg2), *(arg3), *(arg5), PyBUF_ND)) {
// error, handle
}
if( *(arg4) == GDT_Byte )
|