Use of static var in MapScript mapObj.nextLabel
Daniel Morissette
dmorissette at MAPGEARS.COM
Fri Jun 29 16:17:13 EDT 2007
While working on the implementation of label priority, I noticed that
the mapObj.nextLabel() method uses a static variable to iterate over
labels. This is not safe for multi-thread environments, and does not
allow using the function more than once per instance of label cache.
The same code is present in mapscript/swiginc/map.i and in
mapscript/php3/mapscript_i.c
labelCacheMemberObj *nextLabel() {
static int i=0;
if(i<self->labelcache.numlabels)
return &(self->labelcache.labels[i++]);
else
return NULL;
}
What do we want to do to fix it?
The simplest option would be to store the last_label_read as a member of
mapObj (or of labelCacheObj) and then add a rewindLabelCache() method or
something like that to reset the iterator.
Whatever we decide, I will for sure move this code down to the C core in
msGetNextLabel() and msRewindLabelCache() functions to avoid having it
in two places.
Any preferences on the fix?
FYI I have filed ticket 2133 about this:
https://trac.osgeo.org/mapserver/ticket/2133
Daniel
--
Daniel Morissette
http://www.mapgears.com/
More information about the mapserver-dev
mailing list