On Fri, Mar 12, 2010 at 5:44 PM, Gonsolo <gons...@gmail.com> wrote:

> We can't use strtof for the same reason we can't (directly) use strtod.
>>  It uses the locale, so that can make it parse numbers incorrectly.  All
>> of the users of _mesa_strtod actually want _mesa_strtof, so the right
>> fix is to change the existing _mesa_strtod to _mesa_strtof.
>>
>
> Some remarks from a beginner:
>
> 1. Isn't strtod meant to be a very basic function? Making it dependent on a
> locale isn't helpful.
>
> 2. I see strtod_l is defined in /usr/include/stdlib.h which is part of the
> package libc6-dev on my Ubuntu system, yet there is no manpage for it.
>
> 3. strtod is defined in /usr/include/stdlib.h which is in package
> libc6-dev, the manpage is in manpages-dev.
>
> From my limited view, every function should be defined in some_package, it
> should be declared in some_package-dev and documented in some_package-doc.
>
> Is there any reason for this mess except being "historical"?
>
> (Please excuse my ignorance, just a beginner :) )
>
> g
>

The code in question is:

/** Wrapper around strtod() */
double
_mesa_strtod( const char *s, char **end )
{
#ifdef _GNU_SOURCE
   static locale_t loc = NULL;
   if (!loc) {
      loc = newlocale(LC_CTYPE_MASK, "C", NULL);
   }
   return strtod_l(s, end, loc);
#else
   return strtod(s, end);
#endif
}

In some locales, a comma can be used as a decimal place.  That is, 5,2 is a
number between 5 and 6.  (I think I have that right)  I would guess that the
shader language, like C, wouldn't allow this form in code.  So, it makes
sense to force the C locale when parsing numbers from shader source code, as
the code does above.

strtof doesn't show up until C99 and not all compilers support it, including
the MSFT Windows compilers.  Ian says that all usages of this function want
a float anyway, so we may end up with something like:

float
_mesa_strtof( const char *s, char **end )
{
#ifdef _GNU_SOURCE
   static locale_t loc = NULL;
   if (!loc) {
      loc = newlocale(LC_CTYPE_MASK, "C", NULL);
   }
   return (float) strtod_l(s, end, loc);
#else
   return (float) strtod(s, end);
#endif
}

And then change all _mesa_strtod to _mesa_strtof.

If Ian doesn't care for the casts here, then I'm fine with silencing
warnings in the Studio with a compiler option.
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to