Overview
| Artifact ID: | 20f9023384145ba2452cfb1c684c361124f7a1b5 |
|---|---|
| Ticket: | 449094ffffffffffffffffffffffffffffffffff
Read trace on arrays (ex "Tcl_TraceVar") |
| User & Date: | davidw on 2001-08-08 12:46:16 |
Changes
- assignee changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
[ I hate this f**** web interface - go read the original thread at: http://groups.google.com/groups?hl=en&safe=off&th=f37901b5fe0e58d3,3&seekm=87zo9u79oa.fsf%40apache.org#p ] char *traceproc(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) { Tcl_SetVar2(interp, "rotvar", "foo", "1", 0); return NULL; } int Rotvar_tcl_Init(Tcl_Interp *interp) { Tcl_TraceVar(interp, "rotvar", TCL_TRACE_READS|TCL_TRACE_ARRAY, traceproc, NULL); return TCL_OK; } then... @ashland [~/workshop] $ gcc -c sicktcl.c ; ld -fPIC -shared -o libRotVar_tcl.so sicktcl.o -ltcl8.3 @ashland [~/workshop] $ tclsh tclsh8.3 [~/workshop]load ./libRotVar_tcl.so tclsh8.3 [~/workshop]puts [array get rotvar ] tclsh8.3 [~/workshop]puts [array get rotvar ] foo 1 tclsh8.3 [~/workshop] Excusing me for the odd names, why isn't this filling in the value *before* the first [array get] ? The man page says: When array tracing has been specified, the trace procedure will be invoked at the beginning of the array command implementation, before any of the operations like get, set, or names have been invoked. The trace procedure can modify the array elements with Tcl_SetVar and Tcl_SetVar2. Ideas? -- David N. Welton Free Software: http://people.debian.org/~davidw/ Apache Tcl: http://tcl.apache.org/ Personal: http://www.efn.org/~davidw/ Post a follow-up to this message Message 2 in thread From: David N. Welton ([email protected]) Subject: Re: Tcl_TraceVar wierdness Newsgroups: comp.lang.tcl Date: 2001-07-24 06:13:05 PST [email protected] (David N. Welton) writes: > @ashland [~/workshop] $ gcc -c sicktcl.c ; ld -fPIC -shared -o libRotVar_tcl.so sicktcl.o -ltcl8.3 > @ashland [~/workshop] $ tclsh tclsh8.3 [~/workshop]load ./libRotVar_tcl.so > tclsh8.3 [~/workshop]puts [array get rotvar ] > > tclsh8.3 [~/workshop]puts [array get rotvar ] > foo 1 > tclsh8.3 [~/workshop] > > Excusing me for the odd names, why isn't this filling in the value > *before* the first [array get] ? Interestingly enough: tclsh8.3 [~/workshop]load ./libRotVar_tcl.so tclsh8.3 [~/workshop]array set rotvar {a b} tclsh8.3 [~/workshop]array get rotvar foo 1 a b So, it looks as if it's important that it be defined as an array... Hrm... -- David N. Welton Free Software: http://people.debian.org/~davidw/ Apache Tcl: http://tcl.apache.org/ Personal: http://www.efn.org/~davidw/ Post a follow-up to this message Message 3 in thread From: David N. Welton ([email protected]) Subject: Re: Tcl_TraceVar wierdness Newsgroups: comp.lang.tcl Date: 2001-07-24 08:15:32 PST This seems like a logical fix to me. Basically, we move the check to see if it's an array untill after the trace. In my case, the variable is indeed undefined, but after the trace it is an array. =================================================================== RCS file: /cvsroot/tcl/tcl/generic/tclVar.c,v retrieving revision 1.32 diff -u -r1.32 tclVar.c --- generic/tclVar.c 2001/05/17 02:13:03 1.32 +++ generic/tclVar.c 2001/07/24 15:12:15 @@ -3002,12 +3002,6 @@ varPtr = TclLookupVar(interp, varName, (char *) NULL, /*flags*/ 0, /*msg*/ 0, /*createPart1*/ 0, /*createPart2*/ 0, &arrayPtr); - notArray = 0; - if ((varPtr == NULL) || !TclIsVarArray(varPtr) - || TclIsVarUndefined(varPtr)) { - notArray = 1; - } - /* * Special array trace used to keep the env array in sync for * array names, array get, etc. @@ -3024,6 +3018,12 @@ } } + notArray = 0; + if ((varPtr == NULL) || !TclIsVarArray(varPtr) + || TclIsVarUndefined(varPtr)) { + notArray = 1; + } + /* * We have to wait to get the resultPtr until here because * CallTraces can affect the result. And infact: % load /home/davidw/workshop/libRotVar_tcl.so % array get rotvar foo 1 Works on the first try... -- David N. Welton Free Software: http://people.debian.org/~davidw/ Apache Tcl: http://tcl.apache.org/ Personal: http://www.efn.org/~davidw/ - foundin changed to: "None"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "davidw"
- subsystem changed to: ""
- title changed to: "Tcl_TraceVar"
- type changed to: "Bug"