summaryrefslogtreecommitdiffstats
path: root/generic/tclBasic.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2007-02-24 18:55:42 (GMT)
committerdgp <dgp@users.sourceforge.net>2007-02-24 18:55:42 (GMT)
commitf3533a9258ecec84b776d21653f7d91abdf67831 (patch)
treef723d3e8039a85dd9ef7a2b6fb219fc521969795 /generic/tclBasic.c
parent3ca3d6597115aa1983bd3504e95769eadba4a594 (diff)
downloadtcl-f3533a9258ecec84b776d21653f7d91abdf67831.zip
tcl-f3533a9258ecec84b776d21653f7d91abdf67831.tar.gz
tcl-f3533a9258ecec84b776d21653f7d91abdf67831.tar.bz2
* generic/tclBasic.c: Use new interface in Tcl_EvalObjEx so that
the recounting logic of the List internal rep need not be repeated there. Better encapsulation of internal details. * generic/tclInt.h: New internal routine TclListObjCopy() used * generic/tclListObj.c: to efficiently do the equivalent of [lrange $list 0 end]. After some experience with this, might be a good candidate for exposure as a public interface. It's useful for callers of Tcl_ListObjGetElements() who want to control the ongoing validity of the returned objv pointer.
Diffstat (limited to 'generic/tclBasic.c')
-rw-r--r--generic/tclBasic.c39
1 files changed, 10 insertions, 29 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index cf57f69..5e9b082 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclBasic.c,v 1.235 2007/02/20 23:24:02 nijtmans Exp $
+ * RCS: @(#) $Id: tclBasic.c,v 1.236 2007/02/24 18:55:42 dgp Exp $
*/
#include "tclInt.h"
@@ -4557,9 +4557,8 @@ TclEvalObjEx(
*/
if (objPtr->typePtr == &tclListType) { /* is a list... */
- List *listRepPtr;
-
- listRepPtr = (List *) objPtr->internalRep.twoPtrValue.ptr1;
+ List *listRepPtr =
+ (List *) objPtr->internalRep.twoPtrValue.ptr1;
if (objPtr->bytes == NULL || /* ...without a string rep */
listRepPtr->canonicalFlag) {/* ...or that is canonical */
@@ -4572,14 +4571,17 @@ TclEvalObjEx(
int line, i;
char *w;
CmdFrame eoFrame;
- Tcl_Obj **elements = &listRepPtr->elements;
+ Tcl_Obj *copyPtr = TclListObjCopy(NULL, objPtr);
+ Tcl_Obj **elements;
eoFrame.type = TCL_LOCATION_EVAL_LIST;
eoFrame.level = (iPtr->cmdFramePtr == NULL?
1 : iPtr->cmdFramePtr->level + 1);
eoFrame.framePtr = iPtr->framePtr;
eoFrame.nextPtr = iPtr->cmdFramePtr;
- eoFrame.nline = listRepPtr->elemCount;
+
+ Tcl_ListObjGetElements(NULL, copyPtr,
+ &eoFrame.nline, &elements);
eoFrame.line = (int *) ckalloc(eoFrame.nline * sizeof(int));
eoFrame.cmd.listPtr = objPtr;
@@ -4587,16 +4589,10 @@ TclEvalObjEx(
eoFrame.data.eval.path = NULL;
/*
- * Increase the reference count of the List structure, to
- * avoid a segfault if objPtr loses its List internal rep [Bug
- * 1119369]
- *
* TIP #280 Computes all the line numbers for the words in the
* command.
*/
- listRepPtr->refCount++;
-
line = 1;
for (i=0; i < eoFrame.nline; i++) {
eoFrame.line[i] = line;
@@ -4605,26 +4601,11 @@ TclEvalObjEx(
}
iPtr->cmdFramePtr = &eoFrame;
- result = Tcl_EvalObjv(interp, listRepPtr->elemCount,
- &listRepPtr->elements, flags);
+ result = Tcl_EvalObjv(interp, eoFrame.nline, elements, flags);
+ Tcl_DecrRefCount(copyPtr);
iPtr->cmdFramePtr = iPtr->cmdFramePtr->nextPtr;
Tcl_DecrRefCount(eoFrame.cmd.listPtr);
-
- /*
- * If we are the last users of listRepPtr, free it.
- */
-
- if (--listRepPtr->refCount <= 0) {
- int i, elemCount = listRepPtr->elemCount;
- Tcl_Obj **elements = &listRepPtr->elements;
-
- for (i=0; i<elemCount; i++) {
- Tcl_DecrRefCount(elements[i]);
- }
- ckfree((char *) listRepPtr);
- }
-
ckfree((char *) eoFrame.line);
eoFrame.line = NULL;
eoFrame.nline = 0;