Skip to content

Commit edafd27

Browse files
authored
Updates to build MapScript with SWIG 4.0.1 (#5983)
* Fixes to work with SWIG4 * Move pattern tests to Python test suite * Test with both SWIG 3 and 4 * Comment out deprecated typemaps * Exclude C# typemaps only for < v4
1 parent f681af9 commit edafd27

6 files changed

Lines changed: 75 additions & 80 deletions

File tree

appveyor.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@ image: Visual Studio 2017
77
cache:
88
- '%LOCALAPPDATA%\pip\Cache'
99
- '%APPVEYOR_BUILD_FOLDER%\swigwin-3.0.12.zip'
10-
10+
- '%APPVEYOR_BUILD_FOLDER%\swigwin-4.0.1.zip'
11+
1112
environment:
1213
# VS 2017
1314
VS_VERSION: Visual Studio 15 2017
1415
matrix:
1516
- platform: x86
1617
PYTHON_EXECUTABLE: c:/python27/python.exe
18+
SWIG_VER: swigwin-3.0.12
1719
- platform: x64
1820
PYTHON_EXECUTABLE: c:/python27-x64/python.exe
21+
SWIG_VER: swigwin-4.0.1
1922
- platform: x64
2023
PYTHON_EXECUTABLE: c:/python36-x64/python.exe
24+
SWIG_VER: swigwin-4.0.1
2125

2226
matrix:
2327
fast_finish: true
@@ -33,21 +37,21 @@ build_script:
3337
- if "%platform%" == "x64" call "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build/vcvars64.bat"
3438
- if "%platform%" == "x86" call "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build/vcvars32.bat"
3539
- echo "%VS_FULL%"
36-
- if not exist swigwin-3.0.12.zip appveyor DownloadFile https://sourceforge.net/projects/swig/files/swigwin/swigwin-3.0.12/swigwin-3.0.12.zip
40+
- if not exist %SWIG_VER%.zip appveyor DownloadFile https://sourceforge.net/projects/swig/files/swigwin/%SWIG_VER%/%SWIG_VER%.zip
3741
- set SDK_ZIP=%SDK%-dev.zip
3842
- set SDK_URL=http://download.gisinternals.com/sdk/downloads/%SDK_ZIP%
3943
- echo "%SDK_ZIP%"
4044
- echo "%SDK_URL%"
4145
- mkdir sdk
42-
- 7z x swigwin-3.0.12.zip -osdk > nul
46+
- 7z x %SWIG_VER%.zip -osdk > nul
4347
- cd sdk
4448
- appveyor DownloadFile "%SDK_URL%"
4549
- 7z x "%SDK_ZIP%" > nul
4650
- set SDK_PREFIX=%BUILD_FOLDER%/sdk/%SDK%
4751
- set SDK_INC=%BUILD_FOLDER%/sdk/%SDK%/include
4852
- set SDK_LIB=%BUILD_FOLDER%/sdk/%SDK%/lib
4953
- set SDK_BIN=%BUILD_FOLDER%/sdk/%SDK%/bin
50-
- set SWIG_EXECUTABLE=%BUILD_FOLDER%/sdk/swigwin-3.0.12/swig.exe
54+
- set SWIG_EXECUTABLE=%BUILD_FOLDER%/sdk/%SWIG_VER%/swig.exe
5155
- set REGEX_DIR=%BUILD_FOLDER%/sdk/regex-0.12
5256
- if "%platform%" == "x86" SET PYTHON_EXECUTABLE=c:/python27/python.exe
5357
- if "%platform%" == "x64" SET PYTHON_EXECUTABLE=c:/python27-x64/python.exe

mapscript/csharp/swig_csharp_extensions.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,20 @@
224224
}
225225
%}
226226

227+
#if SWIG_VERSION < 0x040000
227228
%typemap(csfinalize) SWIGTYPE %{
228229
/* %typemap(csfinalize) SWIGTYPE */
229230
~$csclassname() {
230231
Dispose();
231232
}
232233
%}
234+
#endif
233235

234236
%typemap(csconstruct, excode=SWIGEXCODE) SWIGTYPE %{: this($imcall, true, null) {$excode
235237
}
236238
%}
237239

240+
#if SWIG_VERSION < 0x040000
238241
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
239242
lock(this) {
240243
if(swigCPtr.Handle != System.IntPtr.Zero && swigCMemOwn) {
@@ -246,6 +249,7 @@
246249
System.GC.SuppressFinalize(this);
247250
}
248251
}
252+
#endif
249253

250254
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE {
251255
lock(this) {

mapscript/python/pyextend.i

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*
1414
*****************************************************************************/
1515

16+
1617
/* fromstring: Factory for mapfile objects */
1718

1819
%pythoncode %{
@@ -222,19 +223,17 @@ def fromstring(data, mappath=None):
222223
}
223224
}
224225

225-
def getItemDefinitions(self):
226+
@property
227+
def itemdefinitions(self):
226228
return self._item_definitions
227229

228-
def setItemDefinitions(self, item_definitions):
230+
@itemdefinitions.setter
231+
def itemdefinitions(self, item_definitions):
229232
self._item_definitions = item_definitions
230233

231-
__swig_getmethods__["itemdefinitions"] = getItemDefinitions
232-
__swig_setmethods__["itemdefinitions"] = setItemDefinitions
233-
234234
%}
235235
}
236236

237-
238237
/******************************************************************************
239238
* Extensions to mapObj
240239
*****************************************************************************/
@@ -425,25 +424,14 @@ def fromstring(data, mappath=None):
425424
memcpy( *argout, self->pattern, sizeof(double) * *pnListSize);
426425
}
427426

428-
void patternlength_set2(int patternlength)
429-
{
430-
msSetError(MS_MISCERR, "pattern is read-only", "patternlength_set()");
431-
}
432427

433428
%pythoncode %{
434429

435-
__swig_setmethods__["patternlength"] = _mapscript.styleObj_patternlength_set2
436-
__swig_getmethods__["patternlength"] = _mapscript.styleObj_patternlength_get
437-
if _newclass:patternlength = _swig_property(_mapscript.styleObj_patternlength_get, _mapscript.styleObj_patternlength_set2)
430+
pattern = property(pattern_get, pattern_set)
438431

439-
__swig_setmethods__["pattern"] = _mapscript.styleObj_pattern_set
440-
__swig_getmethods__["pattern"] = _mapscript.styleObj_pattern_get
441-
if _newclass:pattern = _swig_property(_mapscript.styleObj_pattern_get, _mapscript.styleObj_pattern_set)
442432
%}
443-
444433
}
445434

446-
447435
/******************************************************************************
448436
* Extensions to hashTableObj - add dict methods
449437
*****************************************************************************/

mapscript/python/pymodule.i

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*****************************************************************************/
1818

1919
/* Translates Python None to C NULL for strings */
20-
%typemap(in,parse="z") char * "";
20+
//%typemap(in,parse="z") char * "";
2121

2222
/* To support imageObj::getBytes */
2323
%typemap(out) gdBuffer {
@@ -250,33 +250,15 @@ MapServerError = _mapscript.MapServerError
250250
MapServerChildError = _mapscript.MapServerChildError
251251
%}
252252

253-
/* The bogus "if 1:" is to introduce a new scope to work around indentation
254-
handling with pythonappend in different versions. (#3180) */
255-
%feature("pythonappend") layerObj %{if 1:
256-
self.p_map=None
257-
try:
258-
# python 2.5
259-
if args and len(args)!=0:
260-
self.p_map=args[0]
261-
except NameError:
262-
# python 2.6
263-
if map:
264-
self.p_map=map
265-
%}
266-
267-
/* The bogus "if 1:" is to introduce a new scope to work around indentation
268-
handling with pythonappend in different versions. (#3180) */
269-
%feature("pythonappend") classObj %{if 1:
270-
self.p_layer =None
271-
try:
272-
# python 2.5
273-
if args and len(args)!=0:
274-
self.p_layer=args[0]
275-
except NameError:
276-
# python 2.6
277-
if layer:
278-
self.p_layer=layer
279-
%}
253+
%feature("pythonappend") layerObj %{
254+
self.p_map = None
255+
if map:
256+
self.p_map = map%}
257+
258+
%feature("pythonappend") classObj %{
259+
self.p_layer = None
260+
if layer:
261+
self.p_layer = layer%}
280262

281263
%feature("shadow") insertClass %{
282264
def insertClass(*args):

mapscript/python/tests/cases/style_test.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,53 @@ def testInsertNULLStyle(self):
175175
self.assertRaises(mapscript.MapServerChildError,
176176
class0.insertStyle, None)
177177

178+
def testPattern(self):
179+
"""See https://github.com/mapserver/mapserver/issues/4943"""
180+
181+
si = mapscript.styleObj()
182+
assert si.pattern == ()
183+
assert si.patternlength == 0
184+
185+
def testPattern2(self):
186+
187+
si = mapscript.styleObj()
188+
si.pattern = [2.0, 3, 4]
189+
assert si.pattern == (2.0, 3.0, 4.0)
190+
assert si.patternlength == 3
191+
192+
def testPattern3(self):
193+
"""a pattern must have at least 2 elements"""
194+
195+
si = mapscript.styleObj()
196+
exception = None
197+
try:
198+
si.pattern = [1.0]
199+
except Exception:
200+
exception = True
201+
assert exception is True
202+
203+
def testPattern4(self):
204+
"""a pattern can have a max of 10 elements
205+
This is set in mapsymbol.h with #define MS_MAXPATTERNLENGTH 10"""
206+
207+
si = mapscript.styleObj()
208+
exception = None
209+
try:
210+
si.pattern = [i for i in range(11)]
211+
except Exception:
212+
exception = True
213+
assert exception is True
214+
215+
def testPattern5(self):
216+
"""pattern length is read-only"""
217+
si = mapscript.styleObj()
218+
exception = None
219+
try:
220+
si.patternlength = 0
221+
except Exception:
222+
exception = True
223+
assert exception is True
224+
178225

179226
class BrushCachingTestCase(MapTestCase):
180227

msautotest/mspython/test_bug_check.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,6 @@ def test_bug_673():
8585

8686
pmstestlib.compare_and_report( 'bug673.png', this_path = os.path.dirname(__file__) )
8787

88-
###############################################################################
89-
# Test https://github.com/mapserver/mapserver/issues/4943
90-
91-
def test_pattern():
92-
93-
si = mapscript.styleObj()
94-
assert len(si.pattern) == 0
95-
assert si.patternlength == 0
96-
97-
si.pattern = [2.0,3,4]
98-
assert si.pattern == (2.0, 3.0, 4.0)
99-
assert si.patternlength == 3
100-
101-
try:
102-
si.pattern = [1.0]
103-
assert False
104-
except mapscript.MapServerError:
105-
pass
106-
107-
try:
108-
si.pattern = [i for i in range(11)]
109-
assert False
110-
except mapscript.MapServerError:
111-
pass
112-
113-
try:
114-
si.patternlength = 0
115-
assert False
116-
except mapscript.MapServerError:
117-
pass
11888

11989
###############################################################################
12090
# Test reprojection of lines from Polar Stereographic and crossing the antimerdian

0 commit comments

Comments
 (0)