Overview
| Artifact ID: | adc59ae86e2ac9c0b1ff5c1b28b39fc515289715 |
|---|---|
| Ticket: | 39f6304c2e90549c209cd11a7920dc9921b9f48e
Tcl_LinkVar is not tolerant to minus, plus, dot |
| User & Date: | fvogel on 2016-12-17 14:16:20 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
Tcl_LinkVar is not tolerant to minus, plus, dot This was reported privately first and published on Tcl-Core list later. The originally problem reported by a user is that typing a bare minus sign ('-') into a Tk entry (or anything except a number) with a -textvariable <b>bound to a C int or C double variable</b> raises an error in Tcl/Tk 8.5.19, which was not the case with 8.5.18. Example of such error: <verbatim> ############################################## can't set "fthresh": variable must have real value variable must have real value (write trace on "fthresh") invoked from within "$w insert insert $s" (procedure "tk::EntryInsert" line 12) invoked from within "tk::EntryInsert .display.le.fthresh.e -" (command bound to event) ############################################## </verbatim> The OP C code looks like this: <verbatim> ############################################## double fthresh; static Tcl_Interp *interp; int main(int argc, char **argv) { ... interp = Tcl_CreateInterp(); ... Tcl_LinkVar(interp,"fthresh",(char *)&fthresh, TCL_LINK_DOUBLE); ... } ############################################## </verbatim> And his Tcl code looks like this: <verbatim> ############################################## entry .a -textvariable fthresh ... ############################################## </verbatim> A complete bug reproduction package (C code, Tcl code and instructions to run it) was provided by the OP and is attached to the present ticket. Investigation of the issue revealed that: 1. Tcl_LinkVar does its job through a variable trace. 2. Fixing [http://core.tcl.tk/tk/info/1700065|Tk bug 1700065] made the issue apparent because since that fix, when a write trace is set on a textvariable of an entry, and there is an error in that write trace proc, the behavior changed. The error became reported instead of being silently ignored. 3. The ttk::entry has and always had (AFAIK) this issue, even before fixing Tk bug 1700065 (which did not touch ttk::entry anyway). 4. Problem is not limited to inserting a bare minus (-) sign, it happens when inserting a bare plus (+) or dot (.) sign as well. All being potentially realistic actions you could want to do in an entry widget. 5. Looking in the Tcl source code, LinkTraceProc() simply checks if Tcl_GetIntFromObj() returns TCL_OK or not. And similarly for other types (wide int, double, short...). A bare -, +, or . makes this call return TCL_ERROR. In conclusion, I believe that LinkTraceProc() could be more tolerant to what could be an integer or double. Donald Arseneau proposed the following change: <i>If string converts to proper numeric, then apply value <p>else if string with "0" appended converts to proper numeric, <p>don't apply value, but don't give error either. <p>else raise error </i> - foundin changed to: "All"
- is_private changed to: "0"
- login: "fvogel"
- priority changed to: "5 Medium"
- private_contact changed to: "fbd2cca1b0c719fdaddfc7388b5609d917e5fdc5"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "fvogel"
- subsystem changed to: "09. Linked C Variables"
- title changed to: "Tcl_LinkVar is not tolerant to minus, plus, dot"
- type changed to: "Bug"