Skip to content

Commit 56aabaf

Browse files
author
jan.nijtmans
committed
Consider 3 more types as special in TclDuplicatePureObj(). Updated comment for the reason why.
1 parent 38d334f commit 56aabaf

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

generic/tclIndexObj.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void PrintUsage(Tcl_Interp *interp,
3636
* that can be invoked by generic object code.
3737
*/
3838

39-
static const Tcl_ObjType indexType = {
39+
const Tcl_ObjType tclIndexType = {
4040
"index", /* name */
4141
FreeIndex, /* freeIntRepProc */
4242
DupIndex, /* dupIntRepProc */
@@ -116,7 +116,7 @@ Tcl_GetIndexFromObj(
116116
* the common case where the result is cached).
117117
*/
118118

119-
const Tcl_ObjInternalRep *irPtr = TclFetchInternalRep(objPtr, &indexType);
119+
const Tcl_ObjInternalRep *irPtr = TclFetchInternalRep(objPtr, &tclIndexType);
120120

121121
if (irPtr) {
122122
IndexRep *indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
@@ -278,7 +278,7 @@ Tcl_GetIndexFromObjStruct(
278278
*/
279279

280280
if (objPtr && !(flags & TCL_INDEX_TEMP_TABLE)) {
281-
irPtr = TclFetchInternalRep(objPtr, &indexType);
281+
irPtr = TclFetchInternalRep(objPtr, &tclIndexType);
282282
if (irPtr) {
283283
indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
284284
if ((indexRep->tablePtr == tablePtr)
@@ -347,15 +347,15 @@ Tcl_GetIndexFromObjStruct(
347347
*/
348348

349349
if (objPtr && (index >= 0) && !(flags & TCL_INDEX_TEMP_TABLE)) {
350-
irPtr = TclFetchInternalRep(objPtr, &indexType);
350+
irPtr = TclFetchInternalRep(objPtr, &tclIndexType);
351351
if (irPtr) {
352352
indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
353353
} else {
354354
Tcl_ObjInternalRep ir;
355355

356356
indexRep = (IndexRep*)ckalloc(sizeof(IndexRep));
357357
ir.twoPtrValue.ptr1 = indexRep;
358-
Tcl_StoreInternalRep(objPtr, &indexType, &ir);
358+
Tcl_StoreInternalRep(objPtr, &tclIndexType, &ir);
359359
}
360360
indexRep->tablePtr = (void *) tablePtr;
361361
indexRep->offset = offset;
@@ -447,7 +447,7 @@ static void
447447
UpdateStringOfIndex(
448448
Tcl_Obj *objPtr)
449449
{
450-
IndexRep *indexRep = (IndexRep *)TclFetchInternalRep(objPtr, &indexType)->twoPtrValue.ptr1;
450+
IndexRep *indexRep = (IndexRep *)TclFetchInternalRep(objPtr, &tclIndexType)->twoPtrValue.ptr1;
451451
const char *indexStr = EXPAND_OF(indexRep);
452452

453453
Tcl_InitStringRep(objPtr, indexStr, strlen(indexStr));
@@ -479,11 +479,11 @@ DupIndex(
479479
Tcl_ObjInternalRep ir;
480480
IndexRep *dupIndexRep = (IndexRep *)ckalloc(sizeof(IndexRep));
481481

482-
memcpy(dupIndexRep, TclFetchInternalRep(srcPtr, &indexType)->twoPtrValue.ptr1,
482+
memcpy(dupIndexRep, TclFetchInternalRep(srcPtr, &tclIndexType)->twoPtrValue.ptr1,
483483
sizeof(IndexRep));
484484

485485
ir.twoPtrValue.ptr1 = dupIndexRep;
486-
Tcl_StoreInternalRep(dupPtr, &indexType, &ir);
486+
Tcl_StoreInternalRep(dupPtr, &tclIndexType, &ir);
487487
}
488488

489489
/*
@@ -507,7 +507,7 @@ static void
507507
FreeIndex(
508508
Tcl_Obj *objPtr)
509509
{
510-
ckfree(TclFetchInternalRep(objPtr, &indexType)->twoPtrValue.ptr1);
510+
ckfree(TclFetchInternalRep(objPtr, &tclIndexType)->twoPtrValue.ptr1);
511511
objPtr->typePtr = NULL;
512512
}
513513

@@ -950,7 +950,7 @@ Tcl_WrongNumArgs(
950950
*/
951951
const Tcl_ObjInternalRep *irPtr;
952952

953-
if ((irPtr = TclFetchInternalRep(origObjv[i], &indexType))) {
953+
if ((irPtr = TclFetchInternalRep(origObjv[i], &tclIndexType))) {
954954
IndexRep *indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
955955

956956
elementStr = EXPAND_OF(indexRep);
@@ -999,7 +999,7 @@ Tcl_WrongNumArgs(
999999
*/
10001000
const Tcl_ObjInternalRep *irPtr;
10011001

1002-
if ((irPtr = TclFetchInternalRep(objv[i], &indexType))) {
1002+
if ((irPtr = TclFetchInternalRep(objv[i], &tclIndexType))) {
10031003
IndexRep *indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
10041004

10051005
Tcl_AppendStringsToObj(objPtr, EXPAND_OF(indexRep), NULL);
@@ -1445,7 +1445,7 @@ TclGetCompletionCodeFromObj(
14451445
"ok", "error", "return", "break", "continue", NULL
14461446
};
14471447

1448-
if (!TclHasInternalRep(value, &indexType)
1448+
if (!TclHasInternalRep(value, &tclIndexType)
14491449
&& TclGetIntFromObj(NULL, value, codePtr) == TCL_OK) {
14501450
return TCL_OK;
14511451
}

generic/tclInt.h

+1
Original file line numberDiff line numberDiff line change
@@ -2937,6 +2937,7 @@ MODULE_SCOPE const Tcl_ObjType tclByteArrayType;
29372937
MODULE_SCOPE const Tcl_ObjType tclByteCodeType;
29382938
MODULE_SCOPE const Tcl_ObjType tclDoubleType;
29392939
MODULE_SCOPE const Tcl_ObjType tclIntType;
2940+
MODULE_SCOPE const Tcl_ObjType tclIndexType;
29402941
MODULE_SCOPE const Tcl_ObjType tclListType;
29412942
MODULE_SCOPE const Tcl_ObjType tclArithSeriesType;
29422943
MODULE_SCOPE const Tcl_ObjType tclDictType;

generic/tclObj.c

+6
Original file line numberDiff line numberDiff line change
@@ -1667,12 +1667,18 @@ int SetDuplicatePureObj(
16671667
*
16681668
* Perhaps in the future this can be remedied and this special treatment
16691669
* removed.
1670+
*
1671+
* Similar problem with the integer (0x0A vs 10), double (1e-1 vs 0.1) and
1672+
* index types ("coord" vs "coords", see bug [a34733451b])
16701673
*/
16711674

16721675

16731676
if (bytes && (dupPtr->typePtr == NULL
16741677
|| dupPtr->typePtr->updateStringProc == NULL
16751678
|| typePtr == &tclUniCharStringType
1679+
|| typePtr == &tclDoubleType
1680+
|| typePtr == &tclIntType
1681+
|| typePtr == &tclIndexType
16761682
)
16771683
) {
16781684
if (!TclAttemptInitStringRep(dupPtr, bytes, objPtr->length)) {

tests/utfext.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ test xx-bufferoverflow {buffer overflow Tcl_ExternalToUtf} -body {
7575
# nospace {} abcÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
7676

7777
test TableToUtf-bug-5be203d6ca {Bug 5be203d6ca - truncated prefix in table encoding} -body {
78-
set src \x82\x4f\x82\x50\x82
79-
lassign [testencoding Tcl_ExternalToUtf shiftjis $src {start} 0 16 srcRead dstWritten charsWritten] buf
78+
set src \x82\x4f\x82\x50\x82
79+
lassign [testencoding Tcl_ExternalToUtf shiftjis $src {start} 0 16 srcRead dstWritten charsWritten] buf
8080
set result [list [testencoding Tcl_ExternalToUtf shiftjis $src {start} 0 16 srcRead dstWritten charsWritten] $srcRead $dstWritten $charsWritten]
8181
lappend result {*}[list [testencoding Tcl_ExternalToUtf shiftjis [string range $src $srcRead end] {end} 0 10 srcRead dstWritten charsWritten] $srcRead $dstWritten $charsWritten]
8282
} -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]

0 commit comments

Comments
 (0)