Mapscript module initialization (Re: Need for msInit() and msFinish())

Sean Gillies sgillies at FRII.COM
Mon Feb 13 12:24:33 EST 2006


On Feb 13, 2006, at 10:07 AM, Frank Warmerdam wrote:

> Steve Lime wrote:
>> I think I'd just default to calling it msCleanup if that name is  
>> already out
>> there and being used (although I like msFinish better ;-) ). I  
>> don't believe
>> msCleanup is being exposed to MapScript though.
>
> Steve,
>
> It is declared in map.h and I have confirmed that it is available
> in Python mapscript as "mapscript.msCleanup()".

That's right. SWIG is greedy and exposes everything that is not  
explicitly hidden.

>
>>> Can you avoid msInit() by having the geos interface do the  
>>> initialization
>>> the first time it is entered?
>>
>> Tht's how the C++ interface works but that was with our own global  
>> factory.
>> I don't know how to detect that the library has already been  
>> initialized. Hopefully
>> repeated calls to GEOSInit() are ok.
>
> Well, there is always the hacky:
>
>     static int bInitialized = FALSE;
>
>     if( !bInitialized )
>     {
>          GEOSInit();
>          bInitialized = TRUE;
>     }
>
> at some suitable point.

>
>>> I wonder if we are going to have any conflicts with GDAL/OGR also  
>>> doing
>>> GEOS init/cleanup stuff.
>>
>> Where is the GDAL/OGR GEOS cleanup happening? msCleanup?
>
> msCleanup() calls the GDAL/OGR cleanup functions which ought to call
> the GEOS cleanup function, though I'm pretty sure I don't yet.
>
>>>> Hence the need. We could hide calls in the mapfile load/free  
>>>> code, but there are
>>>> some cases where MapScript scripts don't need a mapfile so we'd  
>>>> need to expose
>>>> 'em for those cases.
>>
>>> I don't think we ought to cleanup geos just because a mapfile is
>>> destroyed.  And of course sometimes we use many maps in a single
>>> run.
>>
>> I agree. If folks got in the habit of starting each script with  
>> msInit() and ending with
>> msCleanup() that would be excellent. However, that would break  
>> every MapScript
>> script out there which would make this a 5.0 type change.
>
> Sean pointed out that the python mapscript already calls msSetup()
> in the Python %init block, so it is automatic for Python.  He is
> setting python mapscript to register an "atexit" handler for  
> msCleanup().
> I believe this auto-setup stuff needs to be implemented custom for  
> each
> swig wrapped language to make it automatic.

See mapscript/python/pymodule.i (r 1.18) around line 159 for an  
example of a SWIG %init% block that calls msSetup() and registers  
msCleanup(). Something like this will need to be implemented  
appropriately for each language binding.

Sean



More information about the mapserver-dev mailing list