summaryrefslogtreecommitdiffstats
path: root/generic/tclLiteral.c
diff options
context:
space:
mode:
authorstanton <stanton>1999-04-28 01:56:39 (GMT)
committerstanton <stanton>1999-04-28 01:56:39 (GMT)
commit7d3a9223f3868397777b097cf72566413d6dbb31 (patch)
tree5a6ad39a22e57a87179bc1df5782626ef72ebcad /generic/tclLiteral.c
parentd6f3ad620713ca2ff8a9b7cb854cdc28aa20ea64 (diff)
downloadtcl-7d3a9223f3868397777b097cf72566413d6dbb31.zip
tcl-7d3a9223f3868397777b097cf72566413d6dbb31.tar.gz
tcl-7d3a9223f3868397777b097cf72566413d6dbb31.tar.bz2
* generic/tclLiteral.c (TclHideLiteral): Fixed so hidden literals
get duplicated to avoid accidental sharing in the global object table.
Diffstat (limited to 'generic/tclLiteral.c')
-rw-r--r--generic/tclLiteral.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/generic/tclLiteral.c b/generic/tclLiteral.c
index 1141155..f180d11 100644
--- a/generic/tclLiteral.c
+++ b/generic/tclLiteral.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclLiteral.c,v 1.3 1999/04/22 22:57:07 stanton Exp $
+ * RCS: @(#) $Id: tclLiteral.c,v 1.4 1999/04/28 01:56:39 stanton Exp $
*/
#include "tclInt.h"
@@ -407,19 +407,23 @@ TclHideLiteral(interp, envPtr, index)
LiteralTable *localTablePtr = &(envPtr->localLitTable);
int localHash, length;
char *bytes;
+ Tcl_Obj *newObjPtr;
lPtr = &(envPtr->literalArrayPtr[index]);
/*
- * We need to bump the object refcount to avoid having the object freed
- * when we remove the last global reference.
+ * To avoid unwanted sharing we need to copy the object and remove it from
+ * the local and global literal tables. It still has a slot in the literal
+ * array so it can be referred to by byte codes, but it will not be matched
+ * by literal searches.
*/
- Tcl_IncrRefCount(lPtr->objPtr);
-
+ newObjPtr = Tcl_DuplicateObj(lPtr->objPtr);
+ Tcl_IncrRefCount(newObjPtr);
TclReleaseLiteral(interp, lPtr->objPtr);
+ lPtr->objPtr = newObjPtr;
- bytes = Tcl_GetStringFromObj(lPtr->objPtr, &length);
+ bytes = Tcl_GetStringFromObj(newObjPtr, &length);
localHash = (HashString(bytes, length) & localTablePtr->mask);
nextPtrPtr = &localTablePtr->buckets[localHash];