summaryrefslogtreecommitdiffstats
path: root/generic/tclResult.c
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-04-14 15:01:18 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-04-14 15:01:18 (GMT)
commit0db2f11f15f912f0e79b915e2f2af197b7c3be20 (patch)
treed687a0578a3abc79fe9d4a121f91e407208cf9ff /generic/tclResult.c
parent4307d0a739ddfd9545e59a0ccf16067fc2dab2a2 (diff)
parentf7c3a988274b5e8026bf4836028bfd6831e6a615 (diff)
downloadtcl-0db2f11f15f912f0e79b915e2f2af197b7c3be20.zip
tcl-0db2f11f15f912f0e79b915e2f2af197b7c3be20.tar.gz
tcl-0db2f11f15f912f0e79b915e2f2af197b7c3be20.tar.bz2
Merge trunk
Diffstat (limited to 'generic/tclResult.c')
-rw-r--r--generic/tclResult.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/generic/tclResult.c b/generic/tclResult.c
index ba97472..29c36d1 100644
--- a/generic/tclResult.c
+++ b/generic/tclResult.c
@@ -10,6 +10,7 @@
*/
#include "tclInt.h"
+#include <assert.h>
/*
* Indices of the standard return options dictionary keys.
@@ -211,40 +212,36 @@ Tcl_DiscardInterpState(
*----------------------------------------------------------------------
*
* Tcl_SetObjResult --
- *
- * Arrange for objPtr to be an interpreter's result value.
+ * Makes objPtr the interpreter's result value.
*
* Results:
* None.
*
* Side effects:
- * interp->objResultPtr is left pointing to the object referenced by
- * objPtr. The object's reference count is incremented since there is now
- * a new reference to it. The reference count for any old objResultPtr
- * value is decremented. Also, the string result is reset.
+ * Stores objPtr interp->objResultPtr, increments its reference count, and
+ * decrements the reference count of any existing interp->objResultPtr.
+ *
+ * The string result is reset.
*
*----------------------------------------------------------------------
*/
void
Tcl_SetObjResult(
- Tcl_Interp *interp, /* Interpreter with which to associate the
- * return object value. */
- Tcl_Obj *objPtr) /* Tcl object to be returned. If NULL, the obj
- * result is made an empty string object. */
+ Tcl_Interp *interp, /* Interpreter to set the result for. */
+ Tcl_Obj *objPtr) /* The value to set as the result. */
{
Interp *iPtr = (Interp *) interp;
Tcl_Obj *oldObjResult = iPtr->objResultPtr;
-
- iPtr->objResultPtr = objPtr;
- Tcl_IncrRefCount(objPtr); /* since interp result is a reference */
-
- /*
- * We wait until the end to release the old object result, in case we are
- * setting the result to itself.
- */
-
- TclDecrRefCount(oldObjResult);
+ if (objPtr == oldObjResult) {
+ /* This should be impossible */
+ assert(objPtr->refCount != 0);
+ return;
+ } else {
+ iPtr->objResultPtr = objPtr;
+ Tcl_IncrRefCount(objPtr);
+ TclDecrRefCount(oldObjResult);
+ }
}
/*