diff options
author | dgp <dgp@users.sourceforge.net> | 2004-10-06 15:59:22 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2004-10-06 15:59:22 (GMT) |
commit | b0e29724338467351f10a4b11e317a5866ac658f (patch) | |
tree | d861bb4c44fd414c034f6faa23c736648d498e29 /generic/tclIOCmd.c | |
parent | a57d7ac68eaafc7de2e3f9d05a148384f3716f52 (diff) | |
download | tcl-b0e29724338467351f10a4b11e317a5866ac658f.zip tcl-b0e29724338467351f10a4b11e317a5866ac658f.tar.gz tcl-b0e29724338467351f10a4b11e317a5866ac658f.tar.bz2 |
* generic/tclBasic.c:
* generic/tclBinary.c:
* generic/tclCmdAH.c:
* generic/tclCmdIL.c:
* generic/tclCmdMZ.c:
* generic/tclCompExpr.c:
* generic/tclDictObj.c:
* generic/tclEncoding.c:
* generic/tclExecute.c:
* generic/tclFCmd.c:
* generic/tclHistory.c:
* generic/tclIndexObj.c:
* generic/tclInterp.c:
* generic/tclIO.c:
* generic/tclIOCmd.c:
* generic/tclNamesp.c:
* generic/tclObj.c:
* generic/tclPkg.c:
* generic/tclResult.c:
* generic/tclScan.c:
* generic/tclTimer.c:
* generic/tclTrace.c:
* generic/tclUtil.c:
* generic/tclVar.c:
It is a poor practice to directly set or append to the value
of the objResult of an interp, because that value might be
shared, and in that circumstance a Tcl_Panic() will be the
result. Searched for example of this practice and replaced
with safer alternatives, often using the Tcl_AppendResult()
routine that dkf just rehabilitated.
Diffstat (limited to 'generic/tclIOCmd.c')
-rw-r--r-- | generic/tclIOCmd.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c index 1c6c8ae..73af20a 100644 --- a/generic/tclIOCmd.c +++ b/generic/tclIOCmd.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIOCmd.c,v 1.20 2004/07/16 22:37:28 andreas_kupries Exp $ + * RCS: @(#) $Id: tclIOCmd.c,v 1.21 2004/10/06 15:59:24 dgp Exp $ */ #include "tclInt.h" @@ -263,8 +263,7 @@ Tcl_GetsObjCmd(dummy, interp, objc, objv) Tcl_DecrRefCount(linePtr); return TCL_ERROR; } - resultPtr = Tcl_GetObjResult(interp); - Tcl_SetIntObj(resultPtr, lineLen); + Tcl_SetObjResult(interp, Tcl_NewIntObj(lineLen)); return TCL_OK; } else { Tcl_SetObjResult(interp, linePtr); @@ -497,7 +496,7 @@ Tcl_TellObjCmd(clientData, interp, objc, objv) if (chan == (Tcl_Channel) NULL) { return TCL_ERROR; } - Tcl_SetWideIntObj(Tcl_GetObjResult(interp), Tcl_Tell(chan)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(Tcl_Tell(chan))); return TCL_OK; } @@ -557,6 +556,10 @@ Tcl_CloseObjCmd(clientData, interp, objc, objv) int len; resultPtr = Tcl_GetObjResult(interp); + if (Tcl_IsShared(resultPtr)) { + resultPtr = Tcl_DuplicateObj(resultPtr); + Tcl_SetObjResult(interp, resultPtr); + } string = Tcl_GetStringFromObj(resultPtr, &len); if ((len > 0) && (string[len - 1] == '\n')) { Tcl_SetObjLength(resultPtr, len - 1); @@ -679,7 +682,7 @@ Tcl_EofObjCmd(unused, interp, objc, objv) return TCL_ERROR; } - Tcl_SetBooleanObj(Tcl_GetObjResult(interp), Tcl_Eof(chan)); + Tcl_SetObjResult(interp, Tcl_NewBooleanObj(Tcl_Eof(chan))); return TCL_OK; } @@ -831,8 +834,7 @@ Tcl_ExecObjCmd(dummy, interp, objc, objv) */ result = Tcl_Close(interp, chan); - string = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &length); - Tcl_AppendToObj(resultPtr, string, length); + Tcl_AppendObjToObj(resultPtr, Tcl_GetObjResult(interp)); /* * If the last character of the result is a newline, then remove @@ -891,12 +893,12 @@ Tcl_FblockedObjCmd(unused, interp, objc, objv) return TCL_ERROR; } if ((mode & TCL_READABLE) == 0) { - Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "channel \"", + Tcl_AppendResult(interp, "channel \"", arg, "\" wasn't opened for reading", (char *) NULL); return TCL_ERROR; } - Tcl_SetBooleanObj(Tcl_GetObjResult(interp), Tcl_InputBlocked(chan)); + Tcl_SetObjResult(interp, Tcl_NewBooleanObj(Tcl_InputBlocked(chan))); return TCL_OK; } @@ -1497,8 +1499,7 @@ Tcl_FcopyObjCmd(dummy, interp, objc, objv) return TCL_ERROR; } if ((mode & TCL_READABLE) == 0) { - Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "channel \"", - arg, + Tcl_AppendResult(interp, "channel \"", arg, "\" wasn't opened for reading", (char *) NULL); return TCL_ERROR; } @@ -1508,8 +1509,7 @@ Tcl_FcopyObjCmd(dummy, interp, objc, objv) return TCL_ERROR; } if ((mode & TCL_WRITABLE) == 0) { - Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "channel \"", - arg, + Tcl_AppendResult(interp, "channel \"", arg, "\" wasn't opened for writing", (char *) NULL); return TCL_ERROR; } |