diff options
Diffstat (limited to 'generic/tclExecute.c')
-rw-r--r-- | generic/tclExecute.c | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 17ad0bb..680bdd0 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -499,11 +499,11 @@ VarHashCreateVar( */ #define GetNumberFromObj(interp, objPtr, ptrPtr, tPtr) \ - (((objPtr)->typePtr == &tclIntType) \ + ((TclHasIntRep((objPtr), &tclIntType)) \ ? (*(tPtr) = TCL_NUMBER_INT, \ *(ptrPtr) = (ClientData) \ (&((objPtr)->internalRep.wideValue)), TCL_OK) : \ - ((objPtr)->typePtr == &tclDoubleType) \ + TclHasIntRep((objPtr), &tclDoubleType) \ ? (((TclIsNaN((objPtr)->internalRep.doubleValue)) \ ? (*(tPtr) = TCL_NUMBER_NAN) \ : (*(tPtr) = TCL_NUMBER_DOUBLE)), \ @@ -4768,7 +4768,7 @@ TEBCresume( */ if ((TclListObjGetElements(interp, valuePtr, &objc, &objv) == TCL_OK) - && (value2Ptr->typePtr != &tclListType) + && !TclHasIntRep(value2Ptr, &tclListType) && (TclGetIntForIndexM(NULL, value2Ptr, objc-1, &index) == TCL_OK)) { TclDecrRefCount(value2Ptr); @@ -5215,7 +5215,7 @@ TEBCresume( objResultPtr = Tcl_NewStringObj((const char *) valuePtr->bytes+index, 1); } else { - char buf[4]; + char buf[4] = ""; int ch = Tcl_GetUniChar(valuePtr, index); /* @@ -5227,8 +5227,8 @@ TEBCresume( objResultPtr = Tcl_NewObj(); } else { length = Tcl_UniCharToUtf(ch, buf); - if (!length) { - length = Tcl_UniCharToUtf(-1, buf); + if ((ch >= 0xD800) && (length < 3)) { + length += Tcl_UniCharToUtf(-1, buf + length); } objResultPtr = Tcl_NewStringObj(buf, length); } @@ -5486,8 +5486,8 @@ TEBCresume( * both. */ - if ((valuePtr->typePtr == &tclStringType) - || (value2Ptr->typePtr == &tclStringType)) { + if (TclHasIntRep(valuePtr, &tclStringType) + || TclHasIntRep(value2Ptr, &tclStringType)) { Tcl_UniChar *ustring1, *ustring2; ustring1 = Tcl_GetUnicodeFromObj(valuePtr, &length); @@ -6293,7 +6293,7 @@ TEBCresume( case INST_TRY_CVT_TO_BOOLEAN: valuePtr = OBJ_AT_TOS; - if (valuePtr->typePtr == &tclBooleanType) { + if (TclHasIntRep(valuePtr, &tclBooleanType)) { objResultPtr = TCONST(1); } else { int result = (TclSetBooleanFromAny(NULL, valuePtr) == TCL_OK); @@ -7108,7 +7108,7 @@ TEBCresume( } varPtr = LOCAL(opnd); if (varPtr->value.objPtr) { - if (varPtr->value.objPtr->typePtr == &dictIteratorType) { + if (TclHasIntRep(varPtr->value.objPtr, &dictIteratorType)) { Tcl_Panic("mis-issued dictFirst!"); } TclDecrRefCount(varPtr->value.objPtr); @@ -7985,8 +7985,8 @@ ExecuteExtendedBinaryMathOp( if (((wQuotient < (Tcl_WideInt) 0) || ((wQuotient == (Tcl_WideInt) 0) - && ((w1 < (Tcl_WideInt)0 && w2 > (Tcl_WideInt)0) - || (w1 > (Tcl_WideInt)0 && w2 < (Tcl_WideInt)0)))) + && ((w1 < 0 && w2 > 0) + || (w1 > 0 && w2 < 0)))) && (wQuotient * w2 != w1)) { wQuotient -= (Tcl_WideInt) 1; } @@ -8020,7 +8020,7 @@ ExecuteExtendedBinaryMathOp( mp_init(&bigResult); mp_init(&bigRemainder); mp_div(&big1, &big2, &bigResult, &bigRemainder); - if (!mp_iszero(&bigRemainder) && (bigRemainder.sign != big2.sign)) { + if ((bigRemainder.used != 0) && (bigRemainder.sign != big2.sign)) { /* * Convert to Tcl's integer division rules. */ @@ -8042,11 +8042,11 @@ ExecuteExtendedBinaryMathOp( switch (type2) { case TCL_NUMBER_INT: - invalid = (*((const Tcl_WideInt *)ptr2) < (Tcl_WideInt)0); + invalid = (*((const Tcl_WideInt *)ptr2) < 0); break; case TCL_NUMBER_BIG: Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2); - invalid = mp_isneg(&big2); + invalid = big2.sign != MP_ZPOS; mp_clear(&big2); break; default: @@ -8063,7 +8063,7 @@ ExecuteExtendedBinaryMathOp( * Zero shifted any number of bits is still zero. */ - if ((type1==TCL_NUMBER_INT) && (*((const Tcl_WideInt *)ptr1) == (Tcl_WideInt)0)) { + if ((type1==TCL_NUMBER_INT) && (*((const Tcl_WideInt *)ptr1) == 0)) { return constants[0]; } @@ -8121,11 +8121,11 @@ ExecuteExtendedBinaryMathOp( switch (type1) { case TCL_NUMBER_INT: - zero = (*(const Tcl_WideInt *)ptr1 > (Tcl_WideInt)0); + zero = (*(const Tcl_WideInt *)ptr1 > 0); break; case TCL_NUMBER_BIG: Tcl_TakeBignumFromObj(NULL, valuePtr, &big1); - zero = (!mp_isneg(&big1)); + zero = (big1.sign == MP_ZPOS); mp_clear(&big1); break; default: @@ -8146,7 +8146,7 @@ ExecuteExtendedBinaryMathOp( if (type1 == TCL_NUMBER_INT) { w1 = *(const Tcl_WideInt *)ptr1; if ((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideInt)) { - if (w1 >= (Tcl_WideInt)0) { + if (w1 >= 0) { return constants[0]; } WIDE_RESULT(-1); @@ -8249,9 +8249,9 @@ ExecuteExtendedBinaryMathOp( oddExponent = (int) (w2 & (Tcl_WideInt)1); } else { Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2); - negativeExponent = mp_isneg(&big2); + negativeExponent = big2.sign != MP_ZPOS; mp_mod_2d(&big2, 1, &big2); - oddExponent = !mp_iszero(&big2); + oddExponent = big2.used != 0; mp_clear(&big2); } @@ -8400,7 +8400,11 @@ ExecuteExtendedBinaryMathOp( overflowExpon: Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2); - if (big2.used > 1) { + if ((big2.used > 1) +#if DIGIT_BIT > 28 + || ((big2.used == 1) && (big2.dp[0] >= (1<<28))) +#endif + ) { mp_clear(&big2); Tcl_SetObjResult(interp, Tcl_NewStringObj( "exponent too large", -1)); @@ -8568,7 +8572,7 @@ ExecuteExtendedBinaryMathOp( mp_mul(&big1, &big2, &bigResult); break; case INST_DIV: - if (mp_iszero(&big2)) { + if (big2.used == 0) { mp_clear(&big1); mp_clear(&big2); mp_clear(&bigResult); @@ -8577,7 +8581,7 @@ ExecuteExtendedBinaryMathOp( mp_init(&bigRemainder); mp_div(&big1, &big2, &bigResult, &bigRemainder); /* TODO: internals intrusion */ - if (!mp_iszero(&bigRemainder) + if ((bigRemainder.used != 0) && (bigRemainder.sign != big2.sign)) { /* * Convert to Tcl's integer division rules. @@ -8724,7 +8728,7 @@ TclCompareTwoNumbers( goto wideCompare; case TCL_NUMBER_BIG: Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2); - if (mp_isneg(&big2)) { + if (big2.sign != MP_ZPOS) { compare = MP_GT; } else { compare = MP_LT; @@ -8761,7 +8765,7 @@ TclCompareTwoNumbers( } Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2); if ((d1 < (double)WIDE_MAX) && (d1 > (double)WIDE_MIN)) { - if (mp_isneg(&big2)) { + if (big2.sign != MP_ZPOS) { compare = MP_GT; } else { compare = MP_LT; @@ -9622,7 +9626,7 @@ EvalStatsCmd( for (i = 0; i < globalTablePtr->numBuckets; i++) { for (entryPtr = globalTablePtr->buckets[i]; entryPtr != NULL; entryPtr = entryPtr->nextPtr) { - if (entryPtr->objPtr->typePtr == &tclByteCodeType) { + if (TclHasIntRep(entryPtr->objPtr, &tclByteCodeType)) { numByteCodeLits++; } (void) TclGetStringFromObj(entryPtr->objPtr, &length); |