From: Jeff H. <je...@ac...> - 2009-05-20 03:39:28
|
On 19/05/2009 8:08 PM, Michael Kirkham wrote: > This may not be a direct opinion as to your specific question, but both > of those look (IMHO) like throwbacks from the days before objects. > Assuming the precision change isn't an issue, why wouldn't you use... > > EntryVisibleRange(entryPtr, &first, &last); > objPtr = Tcl_DuplicateObj(entryPtr->scrollCmd); > Tcl_ListObjAppendElement(interp, objPtr, Tcl_NewDoubleObj(first)); > Tcl_ListObjAppendElement(interp, objPtr, Tcl_NewDoubleObj(last)); > code = Tcl_EvalObjEx(interp, objPtr, TCL_EVAL_GLOBAL|TCL_EVAL_DIRECT); > ...? This is a very good question with a very good answer. For the long version see the very recent discussion on tcl chat logs again, but the short of it is this works for command prefixes, where you might do: -scrollcmd [list myCommand opt1 opt2] or -scrollcmd [list $widget xview] but it would break for the (currently legal) script prefix case of: -scrollcmd "puts foo ; # ignore the rest" There is relatively strong agreement amongst Tk dev that Tk 9 should disallow the latter (if we can't sneak it in earlier ...). Jeff > On Tue, 19 May 2009, Jeff Hobbs wrote: > >> Date: Tue, 19 May 2009 19:57:06 -0700 >> From: Jeff Hobbs <je...@ac...> >> To: Tcl Core List <tcl...@li...> >> Subject: [TCLCORE] The end for Tcl_PrintDouble in Tk? >> >> 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): >> >> EntryVisibleRange(entryPtr, &first, &last); >> Tcl_PrintDouble(NULL, first, firstStr); >> Tcl_PrintDouble(NULL, last, lastStr); >> objPtr = Tcl_NewStringObj(entryPtr->scrollCmd, -1); >> Tcl_IncrRefCount(objPtr); >> Tcl_AppendStringsToObj(objPtr, " ", firstStr, " ", lastStr, NULL); >> code = Tcl_EvalObjEx(interp, objPtr, >> TCL_EVAL_GLOBAL|TCL_EVAL_DIRECT); >> ... >> >> 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); >> ... >> >> 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. >> >> 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 Tcl_PDs exist from the time that we sanitized everything and EIAS >> was always true in Tk. Would changing this be considered a compat >> issue, or just clean-up? >> >> Jeff |