From f3533a9258ecec84b776d21653f7d91abdf67831 Mon Sep 17 00:00:00 2001 From: dgp Date: Sat, 24 Feb 2007 18:55:42 +0000 Subject: * 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. --- ChangeLog | 13 +++++++++++++ generic/tclBasic.c | 39 ++++++++++----------------------------- generic/tclInt.h | 3 ++- generic/tclListObj.c | 42 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 66 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4224546..6fda366 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2007-02-24 Don Porter + + * 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. + 2007-02-22 Andreas Kupries * tests/pkg.test: Added tests for the case of an alpha package 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; itypePtr != &tclListType) { + if (SetListFromAny(interp, listPtr) != TCL_OK) { + return NULL; + } + } + TclNewObj(copyPtr); + TclInvalidateStringRep(copyPtr); + DupListInternalRep(listPtr, copyPtr); + return copyPtr; +} + +/* + *---------------------------------------------------------------------- + * * Tcl_ListObjGetElements -- * * This function returns an (objc,objv) array of the elements in a list -- cgit v0.12