diff options
Diffstat (limited to 'generic/tclExecute.c')
-rw-r--r-- | generic/tclExecute.c | 124 |
1 files changed, 88 insertions, 36 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 60c166f..3efd610 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.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: tclExecute.c,v 1.285.2.21 2007/10/24 12:52:52 dgp Exp $ + * RCS: @(#) $Id: tclExecute.c,v 1.285.2.22 2007/11/12 19:18:16 dgp Exp $ */ #include "tclInt.h" @@ -1180,7 +1180,7 @@ Tcl_ExprObj( /* TIP #280: No invoker (yet) - Expression compilation. */ int length; - const char *string = Tcl_GetStringFromObj(objPtr, &length); + const char *string = TclGetStringFromObj(objPtr, &length); TclInitCompileEnv(interp, &compEnv, string, length, NULL, 0); TclCompileExpr(interp, string, length, &compEnv); @@ -1218,7 +1218,7 @@ Tcl_ExprObj( saveObjPtr = Tcl_GetObjResult(interp); Tcl_IncrRefCount(saveObjPtr); - Tcl_ResetResult(interp); + TclResetResult(interp); /* * Increment the code's ref count while it is being executed. If @@ -1416,11 +1416,11 @@ TclIncrObj( if (GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK) { /* Produce error message (reparse?!) */ - return Tcl_GetIntFromObj(interp, valuePtr, &type1); + return TclGetIntFromObj(interp, valuePtr, &type1); } if (GetNumberFromObj(NULL, incrPtr, &ptr2, &type2) != TCL_OK) { /* Produce error message (reparse?!) */ - Tcl_GetIntFromObj(interp, incrPtr, &type1); + TclGetIntFromObj(interp, incrPtr, &type1); Tcl_AddErrorInfo(interp, "\n (reading increment)"); return TCL_ERROR; } @@ -1461,14 +1461,14 @@ TclIncrObj( * Produce error message (reparse?!) */ - return Tcl_GetIntFromObj(interp, valuePtr, &type1); + return TclGetIntFromObj(interp, valuePtr, &type1); } if ((type2 == TCL_NUMBER_DOUBLE) || (type2 == TCL_NUMBER_NAN)) { /* * Produce error message (reparse?!) */ - Tcl_GetIntFromObj(interp, incrPtr, &type1); + TclGetIntFromObj(interp, incrPtr, &type1); Tcl_AddErrorInfo(interp, "\n (reading increment)"); return TCL_ERROR; } @@ -1734,7 +1734,7 @@ TclExecuteByteCode( * ASYNC_CHECK_COUNT_MASK instruction, of the form (2**n-<1). */ - if (Tcl_AsyncReady()) { + if (TclAsyncReady(iPtr)) { int localResult; DECACHE_STACK_INFO(); @@ -1965,7 +1965,7 @@ TclExecuteByteCode( */ for (currPtr=&OBJ_AT_DEPTH(opnd-2); currPtr<=&OBJ_AT_TOS; currPtr++) { - bytes = Tcl_GetStringFromObj(*currPtr, &length); + bytes = TclGetStringFromObj(*currPtr, &length); if (bytes != NULL) { appendLen += length; } @@ -1994,7 +1994,7 @@ TclExecuteByteCode( */ objResultPtr = OBJ_AT_DEPTH(opnd-1); - bytes = Tcl_GetStringFromObj(objResultPtr, &length); + bytes = TclGetStringFromObj(objResultPtr, &length); #if !TCL_COMPILE_DEBUG if (!Tcl_IsShared(objResultPtr)) { Tcl_SetObjLength(objResultPtr, (length + appendLen)); @@ -2016,7 +2016,7 @@ TclExecuteByteCode( */ for (; currPtr <= &OBJ_AT_TOS; currPtr++) { - bytes = Tcl_GetStringFromObj(*currPtr, &length); + bytes = TclGetStringFromObj(*currPtr, &length); if (bytes != NULL) { memcpy(p, bytes, (size_t) length); p += length; @@ -2063,7 +2063,7 @@ TclExecuteByteCode( */ valuePtr = OBJ_AT_TOS; - if (Tcl_ListObjGetElements(interp, valuePtr, &objc, &objv) != TCL_OK){ + if (TclListObjGetElements(interp, valuePtr, &objc, &objv) != TCL_OK){ TRACE_WITH_OBJ(("%.30s => ERROR: ", O2S(valuePtr)), Tcl_GetObjResult(interp)); result = TCL_ERROR; @@ -3317,7 +3317,7 @@ TclExecuteByteCode( opnd = TclGetInt4AtPtr(pc+1); jtPtr = (JumptableInfo *) codePtr->auxDataArrayPtr[opnd].clientData; TRACE(("%d => %.20s ", opnd, O2S(OBJ_AT_TOS))); - hPtr = Tcl_FindHashEntry(&jtPtr->hashTable, Tcl_GetString(OBJ_AT_TOS)); + hPtr = Tcl_FindHashEntry(&jtPtr->hashTable, TclGetString(OBJ_AT_TOS)); if (hPtr != NULL) { int jumpOffset = PTR2INT(Tcl_GetHashValue(hPtr)); @@ -3397,7 +3397,7 @@ TclExecuteByteCode( valuePtr = OBJ_AT_TOS; - result = Tcl_ListObjLength(interp, valuePtr, &length); + result = TclListObjLength(interp, valuePtr, &length); if (result == TCL_OK) { TclNewIntObj(objResultPtr, length); TRACE(("%.20s => %d\n", O2S(valuePtr), length)); @@ -3412,6 +3412,10 @@ TclExecuteByteCode( case INST_LIST_INDEX: { /*** lindex with objc == 3 ***/ + /* Variables also for INST_LIST_INDEX_IMM */ + + int listc, idx, opnd, pcAdjustment; + Tcl_Obj **listv; Tcl_Obj *valuePtr, *value2Ptr; /* @@ -3425,6 +3429,15 @@ TclExecuteByteCode( * Extract the desired list element. */ + result = TclListObjGetElements(interp, valuePtr, &listc, &listv); + if ((result == TCL_OK) && (value2Ptr->typePtr != &tclListType) + && (TclGetIntForIndexM(NULL , value2Ptr, listc-1, &idx) == TCL_OK)) { + Tcl_DecrRefCount(value2Ptr); + tosPtr--; + pcAdjustment = 1; + goto lindexFastPath; + } + objResultPtr = TclLindexList(interp, valuePtr, value2Ptr); if (objResultPtr) { /* @@ -3440,14 +3453,11 @@ TclExecuteByteCode( result = TCL_ERROR; goto checkForCatch; } - } - case INST_LIST_INDEX_IMM: { + case INST_LIST_INDEX_IMM: /*** lindex with objc==3 and index in bytecode stream ***/ - int listc, idx, opnd; - Tcl_Obj **listv; - Tcl_Obj *valuePtr; + pcAdjustment = 5; /* * Pop the list and get the index. @@ -3461,7 +3471,8 @@ TclExecuteByteCode( * in the process. */ - result = Tcl_ListObjGetElements(interp, valuePtr, &listc, &listv); + result = TclListObjGetElements(interp, valuePtr, &listc, &listv); + if (result == TCL_OK) { /* * Select the list item based on the index. Negative operand means @@ -3473,6 +3484,8 @@ TclExecuteByteCode( } else { idx = opnd; } + + lindexFastPath: if (idx >= 0 && idx < listc) { objResultPtr = listv[idx]; } else { @@ -3481,7 +3494,7 @@ TclExecuteByteCode( TRACE_WITH_OBJ(("\"%.30s\" %d => ", O2S(valuePtr), opnd), objResultPtr); - NEXT_INST_F(5, 1, 1); + NEXT_INST_F(pcAdjustment, 1, 1); } else { TRACE_WITH_OBJ(("\"%.30s\" %d => ERROR: ", O2S(valuePtr), opnd), Tcl_GetObjResult(interp)); @@ -3645,8 +3658,7 @@ TclExecuteByteCode( * Get the contents of the list, making sure that it really is a list * in the process. */ - - result = Tcl_ListObjGetElements(interp, valuePtr, &listc, &listv); + result = TclListObjGetElements(interp, valuePtr, &listc, &listv); /* * Skip a lot of work if we're about to throw the result away (common @@ -3723,8 +3735,8 @@ TclExecuteByteCode( valuePtr = OBJ_UNDER_TOS; /* TODO: Consider more efficient tests than strcmp() */ - s1 = Tcl_GetStringFromObj(valuePtr, &s1len); - result = Tcl_ListObjLength(interp, value2Ptr, &llen); + s1 = TclGetStringFromObj(valuePtr, &s1len); + result = TclListObjLength(interp, value2Ptr, &llen); if (result != TCL_OK) { TRACE_WITH_OBJ(("\"%.30s\" \"%.30s\" => ERROR: ", O2S(valuePtr), O2S(value2Ptr)), Tcl_GetObjResult(interp)); @@ -3740,7 +3752,7 @@ TclExecuteByteCode( do { Tcl_ListObjIndex(NULL, value2Ptr, i, &o); if (o != NULL) { - s2 = Tcl_GetStringFromObj(o, &s2len); + s2 = TclGetStringFromObj(o, &s2len); } else { s2 = ""; } @@ -3809,8 +3821,8 @@ TclExecuteByteCode( char *s1, *s2; int s1len, s2len; - s1 = Tcl_GetStringFromObj(valuePtr, &s1len); - s2 = Tcl_GetStringFromObj(value2Ptr, &s2len); + s1 = TclGetStringFromObj(valuePtr, &s1len); + s2 = TclGetStringFromObj(value2Ptr, &s2len); if (s1len == s2len) { /* * We only need to check (in)equality when we have equal @@ -3907,8 +3919,8 @@ TclExecuteByteCode( * \xC0\x80 null encoding for utf-8. */ - s1 = Tcl_GetStringFromObj(valuePtr, &s1len); - s2 = Tcl_GetStringFromObj(value2Ptr, &s2len); + s1 = TclGetStringFromObj(valuePtr, &s1len); + s2 = TclGetStringFromObj(value2Ptr, &s2len); iResult = TclpUtfNcmp2(s1, s2, (size_t) ((s1len < s2len) ? s1len : s2len)); } @@ -4005,7 +4017,7 @@ TclExecuteByteCode( length = Tcl_GetCharLength(valuePtr); } - result = TclGetIntForIndex(interp, value2Ptr, length - 1, &index); + result = TclGetIntForIndexM(interp, value2Ptr, length - 1, &index); if (result != TCL_OK) { goto checkForCatch; } @@ -4063,6 +4075,13 @@ TclExecuteByteCode( ustring2 = Tcl_GetUnicodeFromObj(value2Ptr, &length2); match = TclUniCharMatch(ustring1, length1, ustring2, length2, nocase); + } else if ((valuePtr->typePtr == &tclByteArrayType) && !nocase) { + unsigned char *string1, *string2; + int length1, length2; + + string1 = Tcl_GetByteArrayFromObj(valuePtr, &length1); + string2 = Tcl_GetByteArrayFromObj(value2Ptr, &length2); + match = TclByteArrayMatch(string1, length1, string2, length2); } else { match = Tcl_StringCaseMatch(TclGetString(valuePtr), TclGetString(value2Ptr), nocase); @@ -4079,6 +4098,39 @@ TclExecuteByteCode( NEXT_INST_F(2, 2, 1); } + case INST_REGEXP: { + int nocase, match; + Tcl_Obj *valuePtr, *value2Ptr; + Tcl_RegExp regExpr; + + nocase = TclGetInt1AtPtr(pc+1); + valuePtr = OBJ_AT_TOS; /* String */ + value2Ptr = OBJ_UNDER_TOS; /* Pattern */ + + regExpr = Tcl_GetRegExpFromObj(interp, value2Ptr, + TCL_REG_ADVANCED | (nocase ? TCL_REG_NOCASE : 0)); + if (regExpr == NULL) { + match = -1; + } else { + match = Tcl_RegExpExecObj(interp, regExpr, valuePtr, 0, 0, 0); + } + + /* + * Adjustment is 2 due to the nocase byte + */ + + if (match < 0) { + objResultPtr = Tcl_GetObjResult(interp); + TRACE_WITH_OBJ(("%.20s %.20s => ERROR: ", O2S(valuePtr), O2S(value2Ptr)), objResultPtr); + result = TCL_ERROR; + goto checkForCatch; + } else { + TRACE(("%.20s %.20s => %d\n", O2S(valuePtr), O2S(value2Ptr), match)); + objResultPtr = constants[match]; + NEXT_INST_F(2, 2, 1); + } + } + case INST_EQ: case INST_NEQ: case INST_LT: @@ -6178,7 +6230,7 @@ TclExecuteByteCode( listVarPtr = &(compiledLocals[listTmpIndex]); listPtr = listVarPtr->value.objPtr; - result = Tcl_ListObjLength(interp, listPtr, &listLen); + result = TclListObjLength(interp, listPtr, &listLen); if (result == TCL_OK) { if (listLen > (iterNum * numVars)) { continueLoop = 1; @@ -6208,7 +6260,7 @@ TclExecuteByteCode( listVarPtr = &(compiledLocals[listTmpIndex]); listPtr = TclListObjCopy(NULL, listVarPtr->value.objPtr); - Tcl_ListObjGetElements(NULL, listPtr, &listLen, &elements); + TclListObjGetElements(interp, listPtr, &listLen, &elements); valIndex = (iterNum * numVars); for (j = 0; j < numVars; j++) { @@ -6284,7 +6336,7 @@ TclExecuteByteCode( case INST_END_CATCH: catchTop--; - Tcl_ResetResult(interp); + TclResetResult(interp); result = TCL_OK; TRACE(("=> catchTop=%d\n", (catchTop - initCatchTop - 1))); NEXT_INST_F(1, 0, 0); @@ -6702,7 +6754,7 @@ TclExecuteByteCode( goto dictUpdateStartFailed; } } - if (Tcl_ListObjGetElements(interp, OBJ_AT_TOS, &length, + if (TclListObjGetElements(interp, OBJ_AT_TOS, &length, &keyPtrPtr) != TCL_OK) { goto dictUpdateStartFailed; } @@ -6757,7 +6809,7 @@ TclExecuteByteCode( NEXT_INST_F(9, 1, 0); } if (Tcl_DictObjSize(interp, dictPtr, &length) != TCL_OK - || Tcl_ListObjGetElements(interp, OBJ_AT_TOS, &length, + || TclListObjGetElements(interp, OBJ_AT_TOS, &length, &keyPtrPtr) != TCL_OK) { result = TCL_ERROR; goto checkForCatch; |