On 2009-09-06 09:09-0700 Alan W. Irwin wrote: > So finally, I think I am on the right track for the > correct way to save and restore locale. There are some more implementation > details to do, but it should not be too long after the release today before > I can commit this, and get it tested on all our platforms.
DONE as of revision 10380 (aside from the non-Linux testing part which I leave to those with access to such platforms). The implementation of the locale saving and restoring infrastructure (plsave_set_locale and plrestore_locale) uses the setlocale function from the C library. I assume that is present and works the same way on OS X and Windows, but please check that assumption by attempting to build PLplot and running example 16 on those platforms. The palette file reading routines already use the new infrastruture and will automatically be exercised by that example. After you establish plsave_set_locale and plrestore_locale work as expected on your platform using example 16 further testing would be a good idea. The ability of PLplot to handle external locale changes is tested with the -locale option for example 1. This currently works well for me (comma-separated [!] decimal separators for the axis labelling and valgrind clean) for qt devices, e.g., LC_NUMERIC='nl_NL.utf8' examples/c/x01c -locale -cmap1 \ cmap1_gray.pal -cmap0 cmap0_black_on_white.pal -dev epsqt -o test.psc This also works for the interactive devices I have tried such as qtwidget and xwin, but not for any cairo device (both interactive and file cairo devices just plot the box of the first subplot of example 1 when the -locale option is used for that example). I have also found the psc device craps out with -locale for C example 1. The PostScript file is filled with commas rather than periods for all floating-point PostScript quantities for -dev psc (as you would expect if you think about how ps.c is implemented.) This vulnerability against locale changes in apps that call the PLplot library (such as occurs for the -locale option for C example 1) is nothing new, and it is going to take some effort to sort out these issues for all our devices. We are not alone in being vulnerable this way. Our competitor, gnuplot, has garnered a number of bug reports concerning locale issues. The obvious fix for ps.c is to protect all the file writes in ps.c against external locale changes by surrounding them with plsave_set_locale(); and plrestore_locale();. I have applied that pair of functions to my local version of ps.c before the file open and after the file close, and that works, but it also suppresses PLplot's ability to to use comma separators for axis labels. Thus, using those functions in a finer-grained way is indicated (probably from the PLplot core library to deal with all file devices at once). BTW, plsave_set_locale and plrestore_locale are the antithesis of functional programming because they have no arguments and return nothing. That is, they cause nothing but side effects. However, that is the name of the game when dealing with POSIX locale issues. plsave_set_locale simply saves the original locale string (set by external code such as x01c.c) in a global way and sets locale to "C". plrestore_locale restores the original locale, and frees the memory where the original global locale string was stored. I think this is the best way to implement this pair of functions because I think we will always need them to communicate with each other between different routines. (Note, the file open and close are in different routines in ps.c if we want to block all locale changes when writing the output PostScript file from ps.c as above.) However, my C skills are not as good as I would like them to be so I would be interested in discussing changes in the implementation of these two functions if someone has some better ideas. Alan __________________________ Alan W. Irwin Astronomical research affiliation with Department of Physics and Astronomy, University of Victoria (astrowww.phys.uvic.ca). Programming affiliations with the FreeEOS equation-of-state implementation for stellar interiors (freeeos.sf.net); PLplot scientific plotting software package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project (lbproject.sf.net). __________________________ Linux-powered Science __________________________ ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Plplot-devel mailing list Plplot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-devel