Tcl_SetStringObj called with shared object
Closed / Fixed1988779fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2008-06-09 10:30:30
We're occasionally seeing panics with Thread.2.6.5 and Tcl.8.5.2:
Tcl_SetStringObj called with shared object
A typical stack trace is
IOT/Abort trap in pthread_kill at 0xd005aaf4 ($t8)
0xd005aaf4 (pthread_kill+0xa8) 80410014 lwz r2,0x14(r1)
(dbx) where
pthread_kill(??, ??) at 0xd005aaf4
_p_raise(??) at 0xd005a100
raise.raise(??) at 0xd01e367c
abort.abort() at 0xd01f2280
Tcl_PanicVA() at 0xd4f14c78
Tcl_Panic() at 0xd4f14cf4
Tcl_SetStringObj() at 0xd4f3293c
ThreadSend() at 0xd5ded484
ThreadSendObjCmd() at 0xd5dea548
TclEvalObjvInternal() at 0xd4f4b1c8
(...)
The implementation of ThreadSend in file thread2.6.5/generic/threadCmd.c contains the lines
code = resultPtr->code;
Tcl_SetStringObj(Tcl_GetObjResult(interp), resultPtr->result, -1);
which seems suspicious. I see no compelling reason why Tcl_GetObjResult(interp) should be unshared at that point, so a plain
Tcl_SetResult(interp, resultPtr->result, TCL_VOLATILE);
should be used instead.
Note: there's also a similar line in SvObjObjCmd in file
thread2.6.5/generic/threadSvCmd.c
dkfplain2008-06-10 20:30:21
Logged In: YES user_id=79902 Originator: NO I prefer this: Tcl_SetObjResult(interp, Tcl_NewStringObj(resultPtr->result, -1)); though I'd even more strongly prefer it if the resultPtr pointed to a structure that knew the length of the string being transferred.
vasiljevicplain2008-06-12 11:19:11
Logged In: YES user_id=95086 Originator: NO I personally do not care as long as it works. I believe this pattern is left in the code by mistake as I tried to change that behaviour long time ago. And, I haven't sucked it out of my finger. This stood (perhaps still stays) in the Tcl docs as a preffered way how to handle result object. Do not ask me where and when I read that. I can't remember. I just now I read that and wrote it accodring to the recomendation, just to find out that this brought lots of problems down the road. So I wholesale changed all my code to scrap those out. Obviously in the threading extension there are places where this is still used. I will go thru and remove all those parts. Instead of Tcl_SetStringObj(Tcl_GetObjResult(interp), resultPtr->result, -1); it will read Tcl_SetObjResult(interp, Tcl_NewStringObj(resultPtr->result, -1)); The original "idea" was that the former should save us the need to create new Tcl_Obj as Tcl result should already point to a good one. And that one should not be shared. This is sometimes not true for whatever reasons, I do not know. Thanks for the report. Zoran
hobbsplain2008-11-04 06:47:47
Fixed to use safest Tcl_SetObjResult(interp, Tcl_NewStringObj(...))
hobbs Closed ticket [1988779fff].
[History diff]2008-11-04 06:47:51
Log in (anonymous is fine) to add a comment.