diff --git a/mapscript/csharp/csmodule.i b/mapscript/csharp/csmodule.i index c657a77210..91b152e3bc 100644 --- a/mapscript/csharp/csmodule.i +++ b/mapscript/csharp/csmodule.i @@ -76,6 +76,34 @@ inner exceptions. Otherwise the exception message will be concatenated*/ * C# exception redefinition *****************************************************************************/ #ifdef ALLOW_INNER_EXCEPTIONS +%exception msLoadMapFromString +{ + errorObj *ms_error; + __try { + $action + } + __except(1 /*EXCEPTION_EXECUTE_HANDLER, catch every exception so it doesn't crash IIS*/) { + msSetError(MS_MISCERR, "Unhandled exception in msLoadMapFromString 0x%08x", "msLoadMapFromString()", GetExceptionCode()); + } + ms_error = msGetErrorObj(); + if (ms_error != NULL && ms_error->code != MS_NOERR) { + if (ms_error->code != MS_NOTFOUND && ms_error->code != -1) { + int ms_errorcode = ms_error->code; + while (ms_error!=NULL && ms_error->code != MS_NOERR) { + char* msg = msAddErrorDisplayString(NULL, ms_error); + if (msg) { + SWIG_CSharpException(SWIG_SystemError, msg); + free(msg); + } + else SWIG_CSharpException(SWIG_SystemError, "MapScript unknown error"); + ms_error = ms_error->next; + } + msResetErrorList(); + return $null; + } + msResetErrorList(); + } +} %exception { errorObj *ms_error; @@ -100,6 +128,30 @@ inner exceptions. Otherwise the exception message will be concatenated*/ } } #else +%exception msLoadMapFromString +{ + errorObj *ms_error; + __try { + $action + } + __except(1 /*EXCEPTION_EXECUTE_HANDLER, catch every exception so it doesn't crash IIS*/) { + msSetError(MS_MISCERR, "Unhandled exception in msLoadMapFromString 0x%08x", "msLoadMapFromString()", GetExceptionCode()); + } + ms_error = msGetErrorObj(); + if (ms_error != NULL && ms_error->code != MS_NOERR) { + if (ms_error->code != MS_NOTFOUND && ms_error->code != -1) { + char* msg = msGetErrorString(";"); + if (msg) { + SWIG_CSharpException(SWIG_SystemError, msg); + free(msg); + } + else SWIG_CSharpException(SWIG_SystemError, "MapScript unknown error"); + msResetErrorList(); + return $null; + } + msResetErrorList(); + } +} %exception { errorObj *ms_error; @@ -478,3 +530,8 @@ DllExport void SWIGSTDCALL SWIGRegisterByteArrayCallback_$module(SWIG_CSharpByte $csclassname ret = (cPtr == System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner, ThisOwn_false());$excode return ret; } + +%typemap(in) msLoadMapFromString %{ +// test +$1 = ($1_ltype)$input; +%} \ No newline at end of file diff --git a/mapscript/mapscript.i b/mapscript/mapscript.i index 8dc3ff86a5..c54636eb78 100644 --- a/mapscript/mapscript.i +++ b/mapscript/mapscript.i @@ -53,9 +53,7 @@ %ignore layerObj::extent; #endif -#if !defined(WIN32) || !defined(SWIGCSHARP) %newobject msLoadMapFromString; -#endif %{ #include "../../mapserver.h" @@ -335,19 +333,4 @@ typedef struct { %include "rbextend.i" #endif -#if defined(WIN32) && defined(SWIGCSHARP) -%inline %{ -// Wrapper function with exception handling -mapObj *msLoadMapFromString_wrapper(char *buffer, char *new_mappath, const configObj* config) { - __try { - return msLoadMapFromString(buffer, new_mappath, config); - } - __except(EXCEPTION_EXECUTE_HANDLER) { - // Handle the exception here, e.g., set an error message - return NULL; - } -} -%} -%rename(msLoadMapFromString) msLoadMapFromString_wrapper; -#endif diff --git a/mapscript/swiginc/map.i b/mapscript/swiginc/map.i index da86fa4188..0e2b802ba4 100644 --- a/mapscript/swiginc/map.i +++ b/mapscript/swiginc/map.i @@ -53,12 +53,30 @@ mapObj(char *mapText, int isMapText /*used as signature only to differentiate this constructor from default constructor*/ ) { +#if defined(WIN32) && defined(SWIGCSHARP) + __try { + return msLoadMapFromString(mapText, NULL, NULL); + } + __except(1 /*EXCEPTION_EXECUTE_HANDLER, catch every exception so it doesn't crash IIS*/) { + msSetError(MS_MISCERR, "Unhandled exception in msLoadMapFromString 0x%08x", "msLoadMapFromString()", GetExceptionCode()); + } +#else return msLoadMapFromString(mapText, NULL, NULL); +#endif } mapObj(char *mapText, int isMapText, configObj *config) { +#if defined(WIN32) && defined(SWIGCSHARP) + __try { + return msLoadMapFromString(mapText, NULL, config); + } + __except(1 /*EXCEPTION_EXECUTE_HANDLER, catch every exception so it doesn't crash IIS*/) { + msSetError(MS_MISCERR, "Unhandled exception in msLoadMapFromString 0x%08x", "msLoadMapFromString()", GetExceptionCode()); + } +#else return msLoadMapFromString(mapText, NULL, config); +#endif } #endif