Re: c-extension question
- From: Neil Madden <nem@xxxxxxxxxxxxx>
- Date: Wed, 25 Apr 2007 17:43:47 GMT
Cristian wrote:
....
pObjRet = Tcl_GetObjResult (interp);....
Tcl_SetStringObj (pObjRet, res, -1);
return TCL_OK;
Don't do this. You should create a new object to return rather than trying to mutate the current interpreter result (which may be shared):
pObjRet = Tcl_NewStringObj(res, -1);
Tcl_SetObjResult(interp, pObjRet);
return TCL_OK;
You should be able to remove the strdup now. The problem is that Tcl_GetObjResult returns whatever the result of the last command was. In your case, the last command was [set a "..."], so the result was that value (which also happens to be your input). You then fetch this result and mutate it to the new value. Because this Tcl_Obj is also stored in $a, then the value of that variable is also updated. Therefore, when you next call the command with $a you get the wrong value.
You should never call any Tcl_Set* function on a Tcl_Obj that you don't "own" (i.e., have created yourself, or otherwise know is unshared). Tcl should panic (terminate) if it detects code trying to modify a shared object -- was the segfault you mentioned actually a panic?
-- Neil
.
- References:
- c-extension question
- From: Cristian
- c-extension question
- Prev by Date: Re: Newby question about colons
- Next by Date: tclodbc, SQL Server, date nighmare
- Previous by thread: c-extension question
- Next by thread: Re: c-extension question
- Index(es):