Skip to content

Commit

Permalink
Updates to build MapScript with SWIG 4.0.1 (#5983)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
geographika authored Feb 8, 2020
1 parent f681af9 commit edafd27
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 80 deletions.
12 changes: 8 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ image: Visual Studio 2017
cache:
- '%LOCALAPPDATA%\pip\Cache'
- '%APPVEYOR_BUILD_FOLDER%\swigwin-3.0.12.zip'

- '%APPVEYOR_BUILD_FOLDER%\swigwin-4.0.1.zip'

environment:
# VS 2017
VS_VERSION: Visual Studio 15 2017
matrix:
- platform: x86
PYTHON_EXECUTABLE: c:/python27/python.exe
SWIG_VER: swigwin-3.0.12
- platform: x64
PYTHON_EXECUTABLE: c:/python27-x64/python.exe
SWIG_VER: swigwin-4.0.1
- platform: x64
PYTHON_EXECUTABLE: c:/python36-x64/python.exe
SWIG_VER: swigwin-4.0.1

matrix:
fast_finish: true
Expand All @@ -33,21 +37,21 @@ build_script:
- if "%platform%" == "x64" call "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build/vcvars64.bat"
- if "%platform%" == "x86" call "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build/vcvars32.bat"
- echo "%VS_FULL%"
- 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
- if not exist %SWIG_VER%.zip appveyor DownloadFile https://sourceforge.net/projects/swig/files/swigwin/%SWIG_VER%/%SWIG_VER%.zip
- set SDK_ZIP=%SDK%-dev.zip
- set SDK_URL=http://download.gisinternals.com/sdk/downloads/%SDK_ZIP%
- echo "%SDK_ZIP%"
- echo "%SDK_URL%"
- mkdir sdk
- 7z x swigwin-3.0.12.zip -osdk > nul
- 7z x %SWIG_VER%.zip -osdk > nul
- cd sdk
- appveyor DownloadFile "%SDK_URL%"
- 7z x "%SDK_ZIP%" > nul
- set SDK_PREFIX=%BUILD_FOLDER%/sdk/%SDK%
- set SDK_INC=%BUILD_FOLDER%/sdk/%SDK%/include
- set SDK_LIB=%BUILD_FOLDER%/sdk/%SDK%/lib
- set SDK_BIN=%BUILD_FOLDER%/sdk/%SDK%/bin
- set SWIG_EXECUTABLE=%BUILD_FOLDER%/sdk/swigwin-3.0.12/swig.exe
- set SWIG_EXECUTABLE=%BUILD_FOLDER%/sdk/%SWIG_VER%/swig.exe
- set REGEX_DIR=%BUILD_FOLDER%/sdk/regex-0.12
- if "%platform%" == "x86" SET PYTHON_EXECUTABLE=c:/python27/python.exe
- if "%platform%" == "x64" SET PYTHON_EXECUTABLE=c:/python27-x64/python.exe
Expand Down
4 changes: 4 additions & 0 deletions mapscript/csharp/swig_csharp_extensions.i
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,20 @@
}
%}

#if SWIG_VERSION < 0x040000
%typemap(csfinalize) SWIGTYPE %{
/* %typemap(csfinalize) SWIGTYPE */
~$csclassname() {
Dispose();
}
%}
#endif

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

#if SWIG_VERSION < 0x040000
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
lock(this) {
if(swigCPtr.Handle != System.IntPtr.Zero && swigCMemOwn) {
Expand All @@ -246,6 +249,7 @@
System.GC.SuppressFinalize(this);
}
}
#endif

%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE {
lock(this) {
Expand Down
24 changes: 6 additions & 18 deletions mapscript/python/pyextend.i
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
*****************************************************************************/


/* fromstring: Factory for mapfile objects */

%pythoncode %{
Expand Down Expand Up @@ -222,19 +223,17 @@ def fromstring(data, mappath=None):
}
}

def getItemDefinitions(self):
@property
def itemdefinitions(self):
return self._item_definitions

def setItemDefinitions(self, item_definitions):
@itemdefinitions.setter
def itemdefinitions(self, item_definitions):
self._item_definitions = item_definitions

__swig_getmethods__["itemdefinitions"] = getItemDefinitions
__swig_setmethods__["itemdefinitions"] = setItemDefinitions

%}
}


/******************************************************************************
* Extensions to mapObj
*****************************************************************************/
Expand Down Expand Up @@ -425,25 +424,14 @@ def fromstring(data, mappath=None):
memcpy( *argout, self->pattern, sizeof(double) * *pnListSize);
}

void patternlength_set2(int patternlength)
{
msSetError(MS_MISCERR, "pattern is read-only", "patternlength_set()");
}

%pythoncode %{

__swig_setmethods__["patternlength"] = _mapscript.styleObj_patternlength_set2
__swig_getmethods__["patternlength"] = _mapscript.styleObj_patternlength_get
if _newclass:patternlength = _swig_property(_mapscript.styleObj_patternlength_get, _mapscript.styleObj_patternlength_set2)
pattern = property(pattern_get, pattern_set)

__swig_setmethods__["pattern"] = _mapscript.styleObj_pattern_set
__swig_getmethods__["pattern"] = _mapscript.styleObj_pattern_get
if _newclass:pattern = _swig_property(_mapscript.styleObj_pattern_get, _mapscript.styleObj_pattern_set)
%}

}


/******************************************************************************
* Extensions to hashTableObj - add dict methods
*****************************************************************************/
Expand Down
38 changes: 10 additions & 28 deletions mapscript/python/pymodule.i
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*****************************************************************************/

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

/* To support imageObj::getBytes */
%typemap(out) gdBuffer {
Expand Down Expand Up @@ -250,33 +250,15 @@ MapServerError = _mapscript.MapServerError
MapServerChildError = _mapscript.MapServerChildError
%}

/* The bogus "if 1:" is to introduce a new scope to work around indentation
handling with pythonappend in different versions. (#3180) */
%feature("pythonappend") layerObj %{if 1:
self.p_map=None
try:
# python 2.5
if args and len(args)!=0:
self.p_map=args[0]
except NameError:
# python 2.6
if map:
self.p_map=map
%}

/* The bogus "if 1:" is to introduce a new scope to work around indentation
handling with pythonappend in different versions. (#3180) */
%feature("pythonappend") classObj %{if 1:
self.p_layer =None
try:
# python 2.5
if args and len(args)!=0:
self.p_layer=args[0]
except NameError:
# python 2.6
if layer:
self.p_layer=layer
%}
%feature("pythonappend") layerObj %{
self.p_map = None
if map:
self.p_map = map%}

%feature("pythonappend") classObj %{
self.p_layer = None
if layer:
self.p_layer = layer%}

%feature("shadow") insertClass %{
def insertClass(*args):
Expand Down
47 changes: 47 additions & 0 deletions mapscript/python/tests/cases/style_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,53 @@ def testInsertNULLStyle(self):
self.assertRaises(mapscript.MapServerChildError,
class0.insertStyle, None)

def testPattern(self):
"""See https://github.com/mapserver/mapserver/issues/4943"""

si = mapscript.styleObj()
assert si.pattern == ()
assert si.patternlength == 0

def testPattern2(self):

si = mapscript.styleObj()
si.pattern = [2.0, 3, 4]
assert si.pattern == (2.0, 3.0, 4.0)
assert si.patternlength == 3

def testPattern3(self):
"""a pattern must have at least 2 elements"""

si = mapscript.styleObj()
exception = None
try:
si.pattern = [1.0]
except Exception:
exception = True
assert exception is True

def testPattern4(self):
"""a pattern can have a max of 10 elements
This is set in mapsymbol.h with #define MS_MAXPATTERNLENGTH 10"""

si = mapscript.styleObj()
exception = None
try:
si.pattern = [i for i in range(11)]
except Exception:
exception = True
assert exception is True

def testPattern5(self):
"""pattern length is read-only"""
si = mapscript.styleObj()
exception = None
try:
si.patternlength = 0
except Exception:
exception = True
assert exception is True


class BrushCachingTestCase(MapTestCase):

Expand Down
30 changes: 0 additions & 30 deletions msautotest/mspython/test_bug_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,6 @@ def test_bug_673():

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

###############################################################################
# Test https://github.com/mapserver/mapserver/issues/4943

def test_pattern():

si = mapscript.styleObj()
assert len(si.pattern) == 0
assert si.patternlength == 0

si.pattern = [2.0,3,4]
assert si.pattern == (2.0, 3.0, 4.0)
assert si.patternlength == 3

try:
si.pattern = [1.0]
assert False
except mapscript.MapServerError:
pass

try:
si.pattern = [i for i in range(11)]
assert False
except mapscript.MapServerError:
pass

try:
si.patternlength = 0
assert False
except mapscript.MapServerError:
pass

###############################################################################
# Test reprojection of lines from Polar Stereographic and crossing the antimerdian
Expand Down

0 comments on commit edafd27

Please sign in to comment.