summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel Sofer <miguel.sofer@gmail.com>2002-07-27 01:44:23 (GMT)
committerMiguel Sofer <miguel.sofer@gmail.com>2002-07-27 01:44:23 (GMT)
commit9f98ef6d93ba1d915a1202418cac2cb21d4f193a (patch)
tree90ef4145d5ce86bfef08fc88dcb407564d9c4ef0
parent0e05c188c12ae4f7e25c3a3d8ca1892bba59c243 (diff)
downloadtcl-9f98ef6d93ba1d915a1202418cac2cb21d4f193a.zip
tcl-9f98ef6d93ba1d915a1202418cac2cb21d4f193a.tar.gz
tcl-9f98ef6d93ba1d915a1202418cac2cb21d4f193a.tar.bz2
* generic/tclVar.c (TclObjLookupVar): leak fix and improved
comments.
-rw-r--r--ChangeLog5
-rw-r--r--generic/tclVar.c45
2 files changed, 31 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 10595a0..0505613 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2002-07-26 Miguel Sofer <msofer@users.sourceforge.net>
+
+ * generic/tclVar.c (TclObjLookupVar): leak fix and improved
+ comments.
+
2002-07-26 Jeff Hobbs <jeffh@ActiveState.com>
* generic/tclVar.c (TclLookupVar): removed early returns that
diff --git a/generic/tclVar.c b/generic/tclVar.c
index 4dcd4c4..b43778e 100644
--- a/generic/tclVar.c
+++ b/generic/tclVar.c
@@ -15,7 +15,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclVar.c,v 1.61 2002/07/26 21:41:48 hobbs Exp $
+ * RCS: @(#) $Id: tclVar.c,v 1.62 2002/07/27 01:44:24 msofer Exp $
*/
#include "tclInt.h"
@@ -461,8 +461,8 @@ TclObjLookupVar(interp, part1Ptr, part2, flags, msg, createPart1, createPart2,
}
/*
- * part1Ptr points to an array element: convert it to
- * tclParsedVarNameType.
+ * part1Ptr points to an array element; first copy
+ * the element name to a new string part2.
*/
part2 = part1 + i + 1;
@@ -474,18 +474,31 @@ TclObjLookupVar(interp, part1Ptr, part2, flags, msg, createPart1, createPart2,
*(newPart2+len2) = '\0';
part2 = newPart2;
- objPtr = part1Ptr;
- objPtr->typePtr = &tclParsedVarNameType;
-
- part1Ptr = Tcl_NewStringObj(part1, len1);
- Tcl_IncrRefCount(part1Ptr);
- typePtr = part1Ptr->typePtr;
+ /*
+ * Free the internal rep of the original part1Ptr, now
+ * renamed objPtr, and set it to tclParsedVarNameType.
+ */
+
+ objPtr = part1Ptr;
if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
typePtr->freeIntRepProc(objPtr);
}
+ objPtr->typePtr = &tclParsedVarNameType;
+
+ /*
+ * Define a new string object to hold the new part1Ptr, i.e.,
+ * the array name. Set the internal rep of objPtr, reset
+ * typePtr and part1 to contain the references to the
+ * array name.
+ */
+
+ part1Ptr = Tcl_NewStringObj(part1, len1);
+ Tcl_IncrRefCount(part1Ptr);
objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) part1Ptr;
objPtr->internalRep.twoPtrValue.ptr2 = (VOID *) part2;
+
+ typePtr = part1Ptr->typePtr;
part1 = TclGetString(part1Ptr);
break;
}
@@ -543,7 +556,6 @@ TclObjLookupVar(interp, part1Ptr, part2, flags, msg, createPart1, createPart2,
part1Ptr->internalRep.twoPtrValue.ptr1 = NULL;
part1Ptr->internalRep.twoPtrValue.ptr2 = NULL;
}
-
donePart1:
#if 0
@@ -559,23 +571,18 @@ TclObjLookupVar(interp, part1Ptr, part2, flags, msg, createPart1, createPart2,
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
- if (part2 == NULL) {
- /*
- * Scalar variable or array found, return.
- */
- return varPtr;
- } else {
+ if (part2 != NULL) {
/*
* Array element sought: look it up.
*/
part1 = TclGetString(part1Ptr);
*arrayPtrPtr = varPtr;
-
- return TclLookupArrayElement(interp, part1, part2, flags,
- msg, createPart1, createPart2, varPtr);
+ varPtr = TclLookupArrayElement(interp, part1, part2,
+ flags, msg, createPart1, createPart2, varPtr);
}
+ return varPtr;
}
/*