MapServer / MapServer-import

3 stars 2 forks source link

reduce use of static variables in mapows.c #1311

Open tbonfort opened 12 years ago

tbonfort commented 12 years ago

Reporter: sgillies@frii.com Date: 2005/04/13 - 01:17

msOWSGetLayerExtent() and msOWSGetEPSGProj() use static strings to temporarily
hold metadata.  I'm changing these to 

  char *value;

msOWSGetEPSGProj() statically allocates memory for its return value

  static char epsgCode[20] ="";

and to be thread safe, should return a pointer to a dynamically allocated string
as is done in msOWSBuildURLFilename() (preceding function) for example.
tbonfort commented 12 years ago

Author: sgillies@frii.com Date: 2005/04/13 - 01:20

setting target to 4.6.
tbonfort commented 12 years ago

Author: dmorissette Date: 2005/04/13 - 01:34

I don't understand why msOWSGetLayerExtent() uses a static variable. It should
be enough to simply remove the static to solve this one.

With respect to msOWSGetEPSGProj(), to save unnecessary buffer allocations (i.e.
processing time) and to save us the code complexity of having to free() the
returned value everywhere, I would like to suggest an alternative approach: make
the function take a char * as argument to hold the result, like what we've done
for msBuildPath() for instance. e.g.

  char projbuffer[MS_EPSG_BUFSIZE];
  ....
  if (msOWSGetEPSGProj(projbuffer, &(map->projection),&(map->web.metadata),
                        "MO", MS_FALSE) == NULL)
   {
     ...

Internally, msOWSGetEPSGProj() would return either a ref to the "wms_epsg"
metadata or copy the first EPSG code to projbuffer. The caller doesn't need to
worry about whether his buffer is used or not, he just needs to pass a buffer of
size MS_EPSG_BUFSIZE to the function.

Makes sense?
tbonfort commented 12 years ago

Author: sgillies@frii.com Date: 2006/06/02 - 04:16

won't fix.