Overview
| Artifact ID: | 3c91321c9b02bc2eb4235d30f1238c18a2672cae |
|---|---|
| Ticket: | 3030870fffffffffffffffffffffffffffffffff
make itcl 3.x built with pre-8.6 work in 8.6 |
| User & Date: | nijtmans on 2010-07-18 12:42:53 |
Changes
- icomment:
See the following comment in tcl.h: ========================================================================== A call frame is initialized and pushed using Tcl_PushCallFrame and popped using Tcl_PopCallFrame. Storage for a Tcl_CallFrame must be provided by the Tcl_PushCallFrame caller, and callers typically allocate them on the C call stack for efficiency. For this reason, Tcl_CallFrame is defined as a structure and not as an opaque token. However, most Tcl_CallFrame fields are hidden since applications should not access them directly; others are declared as "dummyX". ========================================================================== Example extension code: Tcl_CallFrame frame; int somevar; Tcl_PushCallFrame(interp, &frame, ....); .... Tcl_PopCallFrame(interp); The functions Tcl_PushCallFrame and Tcl_PopCallFrame are functions that look like public, but in fact they are in the private stub table. The Tcl_CallFrame structure looks like a public structure, but in fact is was never documented. As far as I know, the only extension using it is Itcl. So, is it really public?.... Just because Tcl 8.5 added two fields to the Tcl_CallFrame structure this caused [incr Tcl Bug #1725219]. Tcl 8.6 did it again with one additional field. So, yes, you are right that "Adjusting the size of any public structure is a recipe for problems". That's exactly what caused [incr Tcl Bug #1725219]. The problem is caused by overwriting variables that come immediately afther the Tcl_CallFrame structure on the stack, that that's exactly what this patch is not doing. So, what happens if the above example code is compiled against Tcl 8.4.19? The "frame" variable is allocated on the stack, and is used to hold the old callframe between the Tcl_PushCallFrame and Tcl_PopCallFrame calls. Now we are running it in Tcl 8.5 or Tcl 8.6. The Tcl_CallFrame structure got some extra fields, so the result is that the "frame" variable is not big enough any more to hold the information stored by Tcl. The effect will be that the "somevar" variable is overwritten. So, now we run it in Tcl 8.4.20 (with this patch). Yes, the Tcl_CallFrame got some extra fields. But Tcl never reads or writes those dummy fields, so the "somevar" variable will never be overwritten. Now what happens if we compile the above sample code using Tcl 8.4.20 (with this patch). The effect is that the "frame" variable gets some extra space, and the the "somevar" variable is moved farther away on the stack. When running it on Tcl 8.4.19, this extra space is not used. But when running it on Tcl 8.5 or Tcl 8.6, this space will be used by the Tcl_PushCallFrame function! But this patch prevents that the "somevar" is overwritten, so the bug is solved.
- login: "nijtmans"
- mimetype: "text/plain"
- username: "nijtmans"