summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-07-12 11:38:08 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-07-12 11:38:08 (GMT)
commit56aabaf032b4af6a32c3aac8906804cd33bec298 (patch)
tree56bbc444e4e598ab113945584e3ab4c9b7688018
parent38d334f8f2161cba6634b26b7f4fa7f6b1b7811f (diff)
downloadtcl-56aabaf032b4af6a32c3aac8906804cd33bec298.zip
tcl-56aabaf032b4af6a32c3aac8906804cd33bec298.tar.gz
tcl-56aabaf032b4af6a32c3aac8906804cd33bec298.tar.bz2
Consider 3 more types as special in TclDuplicatePureObj(). Updated comment for the reason why.
-rw-r--r--generic/tclIndexObj.c24
-rw-r--r--generic/tclInt.h1
-rw-r--r--generic/tclObj.c6
-rw-r--r--tests/utfext.test4
4 files changed, 21 insertions, 14 deletions
diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c
index 652853c..537a600 100644
--- a/generic/tclIndexObj.c
+++ b/generic/tclIndexObj.c
@@ -36,7 +36,7 @@ static void PrintUsage(Tcl_Interp *interp,
* that can be invoked by generic object code.
*/
-static const Tcl_ObjType indexType = {
+const Tcl_ObjType tclIndexType = {
"index", /* name */
FreeIndex, /* freeIntRepProc */
DupIndex, /* dupIntRepProc */
@@ -116,7 +116,7 @@ Tcl_GetIndexFromObj(
* the common case where the result is cached).
*/
- const Tcl_ObjInternalRep *irPtr = TclFetchInternalRep(objPtr, &indexType);
+ const Tcl_ObjInternalRep *irPtr = TclFetchInternalRep(objPtr, &tclIndexType);
if (irPtr) {
IndexRep *indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
@@ -278,7 +278,7 @@ Tcl_GetIndexFromObjStruct(
*/
if (objPtr && !(flags & TCL_INDEX_TEMP_TABLE)) {
- irPtr = TclFetchInternalRep(objPtr, &indexType);
+ irPtr = TclFetchInternalRep(objPtr, &tclIndexType);
if (irPtr) {
indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
if ((indexRep->tablePtr == tablePtr)
@@ -347,7 +347,7 @@ Tcl_GetIndexFromObjStruct(
*/
if (objPtr && (index >= 0) && !(flags & TCL_INDEX_TEMP_TABLE)) {
- irPtr = TclFetchInternalRep(objPtr, &indexType);
+ irPtr = TclFetchInternalRep(objPtr, &tclIndexType);
if (irPtr) {
indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
} else {
@@ -355,7 +355,7 @@ Tcl_GetIndexFromObjStruct(
indexRep = (IndexRep*)ckalloc(sizeof(IndexRep));
ir.twoPtrValue.ptr1 = indexRep;
- Tcl_StoreInternalRep(objPtr, &indexType, &ir);
+ Tcl_StoreInternalRep(objPtr, &tclIndexType, &ir);
}
indexRep->tablePtr = (void *) tablePtr;
indexRep->offset = offset;
@@ -447,7 +447,7 @@ static void
UpdateStringOfIndex(
Tcl_Obj *objPtr)
{
- IndexRep *indexRep = (IndexRep *)TclFetchInternalRep(objPtr, &indexType)->twoPtrValue.ptr1;
+ IndexRep *indexRep = (IndexRep *)TclFetchInternalRep(objPtr, &tclIndexType)->twoPtrValue.ptr1;
const char *indexStr = EXPAND_OF(indexRep);
Tcl_InitStringRep(objPtr, indexStr, strlen(indexStr));
@@ -479,11 +479,11 @@ DupIndex(
Tcl_ObjInternalRep ir;
IndexRep *dupIndexRep = (IndexRep *)ckalloc(sizeof(IndexRep));
- memcpy(dupIndexRep, TclFetchInternalRep(srcPtr, &indexType)->twoPtrValue.ptr1,
+ memcpy(dupIndexRep, TclFetchInternalRep(srcPtr, &tclIndexType)->twoPtrValue.ptr1,
sizeof(IndexRep));
ir.twoPtrValue.ptr1 = dupIndexRep;
- Tcl_StoreInternalRep(dupPtr, &indexType, &ir);
+ Tcl_StoreInternalRep(dupPtr, &tclIndexType, &ir);
}
/*
@@ -507,7 +507,7 @@ static void
FreeIndex(
Tcl_Obj *objPtr)
{
- ckfree(TclFetchInternalRep(objPtr, &indexType)->twoPtrValue.ptr1);
+ ckfree(TclFetchInternalRep(objPtr, &tclIndexType)->twoPtrValue.ptr1);
objPtr->typePtr = NULL;
}
@@ -950,7 +950,7 @@ Tcl_WrongNumArgs(
*/
const Tcl_ObjInternalRep *irPtr;
- if ((irPtr = TclFetchInternalRep(origObjv[i], &indexType))) {
+ if ((irPtr = TclFetchInternalRep(origObjv[i], &tclIndexType))) {
IndexRep *indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
elementStr = EXPAND_OF(indexRep);
@@ -999,7 +999,7 @@ Tcl_WrongNumArgs(
*/
const Tcl_ObjInternalRep *irPtr;
- if ((irPtr = TclFetchInternalRep(objv[i], &indexType))) {
+ if ((irPtr = TclFetchInternalRep(objv[i], &tclIndexType))) {
IndexRep *indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
Tcl_AppendStringsToObj(objPtr, EXPAND_OF(indexRep), NULL);
@@ -1445,7 +1445,7 @@ TclGetCompletionCodeFromObj(
"ok", "error", "return", "break", "continue", NULL
};
- if (!TclHasInternalRep(value, &indexType)
+ if (!TclHasInternalRep(value, &tclIndexType)
&& TclGetIntFromObj(NULL, value, codePtr) == TCL_OK) {
return TCL_OK;
}
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 5b1d15d..ffceb5c 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -2937,6 +2937,7 @@ MODULE_SCOPE const Tcl_ObjType tclByteArrayType;
MODULE_SCOPE const Tcl_ObjType tclByteCodeType;
MODULE_SCOPE const Tcl_ObjType tclDoubleType;
MODULE_SCOPE const Tcl_ObjType tclIntType;
+MODULE_SCOPE const Tcl_ObjType tclIndexType;
MODULE_SCOPE const Tcl_ObjType tclListType;
MODULE_SCOPE const Tcl_ObjType tclArithSeriesType;
MODULE_SCOPE const Tcl_ObjType tclDictType;
diff --git a/generic/tclObj.c b/generic/tclObj.c
index b02279e..731196f 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -1667,12 +1667,18 @@ int SetDuplicatePureObj(
*
* Perhaps in the future this can be remedied and this special treatment
* removed.
+ *
+ * Similar problem with the integer (0x0A vs 10), double (1e-1 vs 0.1) and
+ * index types ("coord" vs "coords", see bug [a34733451b])
*/
if (bytes && (dupPtr->typePtr == NULL
|| dupPtr->typePtr->updateStringProc == NULL
|| typePtr == &tclUniCharStringType
+ || typePtr == &tclDoubleType
+ || typePtr == &tclIntType
+ || typePtr == &tclIndexType
)
) {
if (!TclAttemptInitStringRep(dupPtr, bytes, objPtr->length)) {
diff --git a/tests/utfext.test b/tests/utfext.test
index 70ef2bc..ce50666 100644
--- a/tests/utfext.test
+++ b/tests/utfext.test
@@ -75,8 +75,8 @@ test xx-bufferoverflow {buffer overflow Tcl_ExternalToUtf} -body {
# nospace {} abcÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
test TableToUtf-bug-5be203d6ca {Bug 5be203d6ca - truncated prefix in table encoding} -body {
- set src \x82\x4f\x82\x50\x82
- lassign [testencoding Tcl_ExternalToUtf shiftjis $src {start} 0 16 srcRead dstWritten charsWritten] buf
+ set src \x82\x4f\x82\x50\x82
+ lassign [testencoding Tcl_ExternalToUtf shiftjis $src {start} 0 16 srcRead dstWritten charsWritten] buf
set result [list [testencoding Tcl_ExternalToUtf shiftjis $src {start} 0 16 srcRead dstWritten charsWritten] $srcRead $dstWritten $charsWritten]
lappend result {*}[list [testencoding Tcl_ExternalToUtf shiftjis [string range $src $srcRead end] {end} 0 10 srcRead dstWritten charsWritten] $srcRead $dstWritten $charsWritten]
} -result [list [list multibyte 0 \xEF\xBC\x90\xEF\xBC\x91\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF] 4 6 2 [list ok 0 \xC2\x82\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF] 1 2 1]