[geos-devel] Delocalizing the WKT writer?

Sean Gillies sgillies at frii.com
Thu Aug 28 15:27:00 EDT 2008


Yep, works. Any objections to the changes?

http://trac.osgeo.org/geos/changeset/2172

Would anyone like to see me use a macro instead?

Sean

Chris Hodgson wrote:
> Oh, now I understand - by "bracing the guts" you meant wrapping it with
> those calls - I thought you meant commenting out those calls. With
> Frank's suggested changes I expect your solution will do the job.
> 
> Chris
> 
> sgillies at frii.com wrote:
>> Chris,
>>
>> The calls below were added for illustration, they are not in the source
>> trunk. Sorry about the confusion. I haven't found any other calls to
>> setlocale.
>>
>> Sean
>>
>>  
>>> I'm no locale expert, but it looks to me like that is the code that IS
>>> de-localizing, setting to using the C locale instead of whatever the
>>> locale is set to in the system? Are there other setlocale calls in the
>>> writer code itself that undermine this?
>>>
>>> Chris
>>>
>>> sgillies at frii.com wrote:
>>>    
>>>> Can one of the C++ gurus explain why delocalizing the writer (to fix
>>>> bug
>>>> 201) isn't as simple as bracing the guts of this function with calls to
>>>> setlocale()?
>>>>
>>>> capi/geos_c.cpp:
>>>>
>>>> char*
>>>> GEOSWKTWriter_write(WKTWriter *writer, const Geometry *geom)
>>>> {
>>>>     try
>>>>     {
>>>>                 // switch to C locale
>>>>                 std::setlocale(LC_ALL, "C");
>>>>         std::string s = writer->write(geom);
>>>>
>>>>         char *result;
>>>>         result = (char*) std::malloc( s.length() + 1);
>>>>         std::strcpy(result, s.c_str() );
>>>>                 // switch back to native locale
>>>>                 std::setlocale(LC_ALL, "");
>>>>         return result;
>>>>     }
>>>>     catch (const std::exception &e)
>>>>     {
>>>>         ERROR_MESSAGE("%s", e.what());
>>>>         return NULL;
>>>>     }
>>>>
>>>>     catch (...)
>>>>     {
>>>>         ERROR_MESSAGE("Unknown exception thrown");
>>>>         return NULL;
>>>>     }
>>>> }
>>>>
>>>> Sure, it would be nice to work this down into the C++ code, but the
>>>> WKTWriter class is a nightmare.
>>>>
>>>> Sean
>>>>
>>>> _______________________________________________
>>>> geos-devel mailing list
>>>> geos-devel at lists.osgeo.org
>>>> http://lists.osgeo.org/mailman/listinfo/geos-devel
>>>>
>>>>       
>>> _______________________________________________
>>> geos-devel mailing list
>>> geos-devel at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/geos-devel
>>>
>>>     
>>
>>
>> _______________________________________________
>> geos-devel mailing list
>> geos-devel at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/geos-devel
>>   
> 
> _______________________________________________
> geos-devel mailing list
> geos-devel at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geos-devel
> 



More information about the geos-devel mailing list