Re: [TCLCORE] The end for Tcl_PrintDouble in Tk?
by Joe English other posts by this author
May 20 2009 9:51AM messages near this date
[TCLCORE] The end for Tcl_PrintDouble in Tk?
|
Re: [TCLCORE] The end for Tcl_PrintDouble in Tk?
Jeff Hobbs wrote:
> In looking into the best solution for 2790615
> https://sourceforge.net/tracker/?func=detail&atid=112997&aid=2790615&group_id
> =12997
> Don noted that Tcl_ObjPrintf (added in 8.5) or Tcl_AppendFormatToObj
> would be good alternatives to the coding changes I was using.
>
> This would change, eg tkEntry.c:EntryUpdateScrollbar from (partial):
> [ ... Tcl_PrintDouble ... ]
> to:
> EntryVisibleRange(entryPtr, &first, &last);
> objPtr = Tcl_ObjPrintf("%s %f %f", entryPtr->scrollCmd, first, last);
> Tcl_IncrRefCount(objPtr);
> code = Tcl_EvalObjEx(interp, objPtr, TCL_EVAL_GLOBAL|TCL_EVAL_DIRECT);
> ...
See also #2112563:
<URL: http://sourceforge.net/tracker/index.php?func=detail&aid=2112563&group_id=12997&atid=1
12997 >
> the problem is that Tcl_PrintDouble takes into account the (now
> deprecated) tcl_precision variable. The above causes errors in the test
> suite for where "scrollCmd 0.0 1.0" was expected, it now receives
> "scrollCmd 0.000000 1.000000". These are error cases that have exact
> expectations on the string output.
The format should be "%s %g %g" instead of "%s %f %f".
That's what Tk used to use -- but see also #2112563.
> Most uses of the ~25 Tcl_PrintDoubles in Tk relate to scrolling, and
> that the values passed are moved through Tcl_PD, whereas the above goes
> to the raw sprintf handling of %f.
The problem with *that* is, if a buggy extension (or buggy
Windows printer driver, or buggy embedder...) calls setlocale(),
then sprintf(... "%g" ...); can -- depending on LC_NUMERIC --
produce output that can't be reparsed by Tcl as a floating point number.
The ::tcl_precision-induced breakage is a less severe problem --
in fact, it's not really even breakage, it only affects code
(like the test suite) that compares numbers as strings instead
of as numbers. And there is a simple fix for any applications
that might be affected by this: stop setting ::tcl_precision,
and stop comparing numbers as strings.
The setlocale()-induced breakage is much harder to work around.
For one, it _completely_ breaks the application -- scrollbars
simply stop working. And although calling setlocale() is also
a "Don't Do That" situation, applications don't always have
as much control over that. (Buggy Windows printer drivers
have been known to cause this problem a couple times in the past.)
--Joe English
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables
unlimited royalty-free distribution of the report engine
for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Tcl-Core mailing list
Tcl-Core@[...].net
https://lists.sourceforge.net/lists/listinfo/tcl-core
Thread:
Jeff Hobbs
Joe English
dgp
Jeff Hobbs
Joe English
Michael Kirkham
Joe English
Jeff Hobbs
|