Overview
| Artifact ID: | a563168c4729c3e34d3fbee62417630460466012 |
|---|---|
| Ticket: | 219393ffffffffffffffffffffffffffffffffff
[trace] should use Tcl_Preserve() |
| User & Date: | dkf on 2001-03-23 18:44:41 |
Changes
- icomment:
Logged In: YES user_id=79902 I've been looking at this in a bit more detail, and it seems that the problem stems from the fact that the standard C string returned by any variable trace function has to be static (i.e. not deallocated before it has a chance to be copied into a suitable error string for the interpreter) and yet error results spat out by traces are not at all guaranteed to be static. Currently, the work-around for this involves storing a pointer to a copy of the error string in the trace structure itself, but this is obviously susceptable to the sorts of problems described in this bug. Command traces do not have this problem at all. There are three possible workarounds: 1) Use Tcl_Preserve() and Tcl_Release() to keep hold of the structure; the only problem with this is that to keep the interface static, these operations have to be applied in tclVar.c:CallTraces (i.e. applied to the clientData prior to calling the trace itself) in order to ensure that there is sufficient guaranteed time for a temporary string to be allocated to keep a copy of the string before it vanishes. This is nasty, and requires a doc update to mention this non-obvious behaviour (which could theoretically cause all sorts of troubles...) 2) Introduce an extra flag to be passed to Tcl_TraceVar (and friends) to indicate that non-NULL results returned by the callback are actually dynamic strings that need to be released with ckfree()/Tcl_Free() when finished with. 3) Introduce an extra flag to be passed to Tcl_TraceVar (and friends) to indicate that non-NULL results returned by the callback are actually pointers to Tcl_Objs (cast to char*) that contain the error message, and can be handled by the usual lifetime management mechanisms. Solutions 2) and 3) can coexist with each other and will not cause any backward incompatabilities, but will need a short TIP to introduce. But I suppose that's true of 1) as well, and that's an alternative I don't like (it causes non-trivial leakage of behaviour that could cause problems for extension writers.)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"