Use of static var in MapScript mapObj.nextLabel

Tamas Szekeres szekerest at GMAIL.COM
Fri Jun 29 18:09:04 EDT 2007


Isn't that exposing labelCacheMemberObj *getLabel(int i) along with
numlabels are enough to perform the iteration? Why do we have to allow
redundant approaches for the same thing?

In any case if we would eventually keep nextLabel I would prefer
passing back something to the client rather than maintaining the state
inside mapObj.

I hope that at least one TODO will disappear in RFC-15 with this addition.

Best regards,

Tamas


2007/6/29, Daniel Morissette <dmorissette at mapgears.com>:
> 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