Tcl Source Code

Check-in [b81fc362ed]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Some fixes. Still broken on 64-bit systems
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-312-new
Files: files | file ages | folders
SHA3-256:b81fc362ed6f1f0d39d71a2f9301f8800cd09de05823c805d9425399f12a92f5
User & Date: dkf 2019-04-03 09:08:37
Context
2019-04-03
09:36
refactor; mark broken tests as broken check-in: b3ffd86e9b user: dkf tags: tip-312-new
09:08
Some fixes. Still broken on 64-bit systems check-in: b81fc362ed user: dkf tags: tip-312-new
07:58
Import of TIP 312 implementation check-in: 39413ccd4f user: dkf tags: tip-312-new
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclLink.c.

28
29
30
31
32
33
34
35


36
37
38
39
40
41
42
..
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
...
168
169
170
171
172
173
174

175
176
177
178
179
180
181
...
230
231
232
233
234
235
236

237
238
239
240
241
242
243
...
561
562
563
564
565
566
567

568
569
570
571
572
573
574
...
593
594
595
596
597
598
599

600
601
602
603
604
605
606
...
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
....
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068

1069

1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080

1081

1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092

1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104

1105

1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116

1117

1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128

1129

1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140

1141

1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152

1153

1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164

1165

1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177

1178

1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189

1190

1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202

1203

1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219


1220
1221
1222

1223
1224
1225
1226
1227
1228
1229
    Tcl_Obj *varName;		/* Name of variable (must be global). This is
				 * needed during trace callbacks, since the
				 * actual variable may be aliased at that time
				 * via upvar. */
    char *addr;			/* Location of C variable. */
    int bytes;			/* Size of C variable array. This is 0 when
				 * single variables, and >0 used for array
				 * variables */


    int type;			/* Type of link (TCL_LINK_INT, etc.). */
    union {
	char c;
	unsigned char uc;
	int i;
	unsigned int ui;
	short s;
................................................................................
	long l;
	unsigned long ul;
#endif
	Tcl_WideInt w;
	Tcl_WideUInt uw;
	float f;
	double d;
	void *aryPtr;
	char *pc;
	unsigned char *puc;
	int *pi;
	unsigned int *pui;
	short *ps;
	unsigned short *pus;
	long *pl;
................................................................................
#endif
    if (type & TCL_LINK_READ_ONLY) {
	linkPtr->flags = LINK_READ_ONLY;
    } else {
	linkPtr->flags = 0;
    }
    linkPtr->bytes = 0;

    objPtr = ObjValue(linkPtr);
    if (Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, objPtr,
	    TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG) == NULL) {
	Tcl_DecrRefCount(linkPtr->varName);
	LinkFree(linkPtr);
	return TCL_ERROR;
    }
................................................................................
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"wrong array size given", -1));
	return TCL_ERROR;
    }

    linkPtr = ckalloc(sizeof(Link));
    linkPtr->type = type & ~TCL_LINK_READ_ONLY;

    if (type & TCL_LINK_READ_ONLY) {
	linkPtr->flags = LINK_READ_ONLY;
    } else {
	linkPtr->flags = 0;
    }

    switch (linkPtr->type) {
................................................................................
	    /* single variables */
	    switch (linkPtr->type) {
	    case TCL_LINK_INT:
	    case TCL_LINK_BOOLEAN:
		changed = (LinkedVar(int) != linkPtr->lastValue.i);
		break;
	    case TCL_LINK_DOUBLE:

		changed = (LinkedVar(double) != linkPtr->lastValue.d);
		break;
	    case TCL_LINK_WIDE_INT:
		changed = (LinkedVar(Tcl_WideInt) != linkPtr->lastValue.w);
		break;
	    case TCL_LINK_WIDE_UINT:
		changed = (LinkedVar(Tcl_WideUInt) != linkPtr->lastValue.uw);
................................................................................
		changed = (LinkedVar(long) != linkPtr->lastValue.l);
		break;
	    case TCL_LINK_ULONG:
		changed = (LinkedVar(unsigned long) != linkPtr->lastValue.ul);
		break;
#endif
	    case TCL_LINK_FLOAT:

		changed = (LinkedVar(float) != linkPtr->lastValue.f);
		break;
	    case TCL_LINK_STRING:
	    case TCL_LINK_CHARS:
	    case TCL_LINK_BINARY:
		changed = 1;
		break;
................................................................................

    /*
     * A couple of helper macros. 
     */

#define CheckHaveList(valueObj, underlyingType)				\
    if (Tcl_ListObjGetElements(NULL, (valueObj), &objc, &objv) == TCL_ERROR \
	    || objc != linkPtr->bytes / sizeof(underlyingType)) { \
	return (char *) "wrong dimension";			  \
    }
#define InRange(lowerLimit, value, upperLimit)	\
    ((value) >= (lowerLimit) && (value) <= (upperLimit))

    switch (linkPtr->type) {
    case TCL_LINK_INT:
................................................................................
 */

static Tcl_Obj *
ObjValue(
    Link *linkPtr)		/* Structure describing linked variable. */
{
    char *p;
    Tcl_Obj *resultObj;
    int objc;
    static Tcl_Obj **objv = NULL; // WTF?
    int i;

    switch (linkPtr->type) {
    case TCL_LINK_INT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(int);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj *));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewIntObj(linkPtr->lastValue.pi[i]);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.i = LinkedVar(int);
	return Tcl_NewIntObj(linkPtr->lastValue.i);
    case TCL_LINK_WIDE_INT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(Tcl_WideInt);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj *));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewWideIntObj(linkPtr->lastValue.pw[i]);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.w = LinkedVar(Tcl_WideInt);
	return Tcl_NewWideIntObj(linkPtr->lastValue.w);
    case TCL_LINK_DOUBLE:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(double);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj *));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewDoubleObj(linkPtr->lastValue.pd[i]);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.d = LinkedVar(double);
	return Tcl_NewDoubleObj(linkPtr->lastValue.d);
    case TCL_LINK_BOOLEAN:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes/sizeof(int);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj *));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewBooleanObj(linkPtr->lastValue.pi[i] != 0);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.i = LinkedVar(int);
	return Tcl_NewBooleanObj(linkPtr->lastValue.i);
    case TCL_LINK_CHAR:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(char);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj *));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewIntObj(linkPtr->lastValue.pc[i]);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.c = LinkedVar(char);
	return Tcl_NewIntObj(linkPtr->lastValue.c);
    case TCL_LINK_UCHAR:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(unsigned char);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj *));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewIntObj(linkPtr->lastValue.puc[i]);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.uc = LinkedVar(unsigned char);
	return Tcl_NewIntObj(linkPtr->lastValue.uc);
    case TCL_LINK_SHORT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(short);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj*));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewIntObj(linkPtr->lastValue.ps[i]);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.s = LinkedVar(short);
	return Tcl_NewIntObj(linkPtr->lastValue.s);
    case TCL_LINK_USHORT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(unsigned short);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj*));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewIntObj(linkPtr->lastValue.pus[i]);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.us = LinkedVar(unsigned short);
	return Tcl_NewIntObj(linkPtr->lastValue.us);
    case TCL_LINK_UINT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(unsigned int);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj *));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewWideIntObj(linkPtr->lastValue.pui[i]);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.ui = LinkedVar(unsigned int);
	return Tcl_NewWideIntObj((Tcl_WideInt) linkPtr->lastValue.ui);
#if !defined(TCL_WIDE_INT_IS_LONG) && !defined(_WIN32) && !defined(__CYGWIN__)
    case TCL_LINK_LONG:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(long);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj *));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewWideIntObj(linkPtr->lastValue.pl[i]);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.l = LinkedVar(long);
	return Tcl_NewWideIntObj((Tcl_WideInt) linkPtr->lastValue.l);
    case TCL_LINK_ULONG:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(unsigned long);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj *));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewWideIntObj(linkPtr->lastValue.pul[i]);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.ul = LinkedVar(unsigned long);
	return Tcl_NewWideIntObj((Tcl_WideInt) linkPtr->lastValue.ul);
#endif
    case TCL_LINK_FLOAT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(float);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj *));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewDoubleObj(linkPtr->lastValue.pf[i]);
	    }

	    return Tcl_NewListObj(objc, objv);

	}
	linkPtr->lastValue.f = LinkedVar(float);
	return Tcl_NewDoubleObj(linkPtr->lastValue.f);
    case TCL_LINK_WIDE_UINT:
	/*
	 * FIXME: represent as a bignum.
	 */
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objc = linkPtr->bytes / sizeof(Tcl_WideUInt);
	    objv = ckrealloc(objv, objc * sizeof(Tcl_Obj *));
	    for (i=0; i < objc; i++) {
		objv[i] = Tcl_NewWideIntObj((Tcl_WideInt)
			linkPtr->lastValue.puw[i]);
	    }
	    return Tcl_NewListObj(objc, objv);


	}
	linkPtr->lastValue.uw = LinkedVar(Tcl_WideUInt);
	return Tcl_NewWideIntObj((Tcl_WideInt) linkPtr->lastValue.uw);

    case TCL_LINK_STRING:
	p = LinkedVar(char *);
	if (p == NULL) {
	    TclNewLiteralStringObj(resultObj, "NULL");
	    return resultObj;
	}
	return Tcl_NewStringObj(p, -1);






|
>
>







 







|







 







>







 







>







 







>







 







>







 







|







 







|
<
<






<
|
|


>
|
>






<
|
|


>
|
>






<
|
|


>
|
>






<
|
|


>
|
>






<
|
|


>
|
>






<
|
|


>
|
>






|
<
|


>
|
>






|
<
|


>
|
>






<
|
|


>
|
>







<
|
|


>
|
>






<
|
|


>
|
>







<
|
|


>
|
>









<
|
|



|
>
>



>







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
..
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
...
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
...
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
....
1054
1055
1056
1057
1058
1059
1060
1061


1062
1063
1064
1065
1066
1067

1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080

1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106

1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119

1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132

1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146

1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159

1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171

1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185

1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198

1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212

1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228

1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
    Tcl_Obj *varName;		/* Name of variable (must be global). This is
				 * needed during trace callbacks, since the
				 * actual variable may be aliased at that time
				 * via upvar. */
    char *addr;			/* Location of C variable. */
    int bytes;			/* Size of C variable array. This is 0 when
				 * single variables, and >0 used for array
				 * variables. */
    int numElems;		/* Number of elements in C variable array.
				 * Zero for single variables. */
    int type;			/* Type of link (TCL_LINK_INT, etc.). */
    union {
	char c;
	unsigned char uc;
	int i;
	unsigned int ui;
	short s;
................................................................................
	long l;
	unsigned long ul;
#endif
	Tcl_WideInt w;
	Tcl_WideUInt uw;
	float f;
	double d;
	void *aryPtr;		/* Generic array. */
	char *pc;
	unsigned char *puc;
	int *pi;
	unsigned int *pui;
	short *ps;
	unsigned short *pus;
	long *pl;
................................................................................
#endif
    if (type & TCL_LINK_READ_ONLY) {
	linkPtr->flags = LINK_READ_ONLY;
    } else {
	linkPtr->flags = 0;
    }
    linkPtr->bytes = 0;
    linkPtr->numElems = 0;
    objPtr = ObjValue(linkPtr);
    if (Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, objPtr,
	    TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG) == NULL) {
	Tcl_DecrRefCount(linkPtr->varName);
	LinkFree(linkPtr);
	return TCL_ERROR;
    }
................................................................................
	Tcl_SetObjResult(interp, Tcl_NewStringObj(
		"wrong array size given", -1));
	return TCL_ERROR;
    }

    linkPtr = ckalloc(sizeof(Link));
    linkPtr->type = type & ~TCL_LINK_READ_ONLY;
    linkPtr->numElems = size;
    if (type & TCL_LINK_READ_ONLY) {
	linkPtr->flags = LINK_READ_ONLY;
    } else {
	linkPtr->flags = 0;
    }

    switch (linkPtr->type) {
................................................................................
	    /* single variables */
	    switch (linkPtr->type) {
	    case TCL_LINK_INT:
	    case TCL_LINK_BOOLEAN:
		changed = (LinkedVar(int) != linkPtr->lastValue.i);
		break;
	    case TCL_LINK_DOUBLE:
		/* FIXME: handle NaN */
		changed = (LinkedVar(double) != linkPtr->lastValue.d);
		break;
	    case TCL_LINK_WIDE_INT:
		changed = (LinkedVar(Tcl_WideInt) != linkPtr->lastValue.w);
		break;
	    case TCL_LINK_WIDE_UINT:
		changed = (LinkedVar(Tcl_WideUInt) != linkPtr->lastValue.uw);
................................................................................
		changed = (LinkedVar(long) != linkPtr->lastValue.l);
		break;
	    case TCL_LINK_ULONG:
		changed = (LinkedVar(unsigned long) != linkPtr->lastValue.ul);
		break;
#endif
	    case TCL_LINK_FLOAT:
		/* FIXME: handle NaN */
		changed = (LinkedVar(float) != linkPtr->lastValue.f);
		break;
	    case TCL_LINK_STRING:
	    case TCL_LINK_CHARS:
	    case TCL_LINK_BINARY:
		changed = 1;
		break;
................................................................................

    /*
     * A couple of helper macros. 
     */

#define CheckHaveList(valueObj, underlyingType)				\
    if (Tcl_ListObjGetElements(NULL, (valueObj), &objc, &objv) == TCL_ERROR \
	    || objc != linkPtr->numElems) { \
	return (char *) "wrong dimension";			  \
    }
#define InRange(lowerLimit, value, upperLimit)	\
    ((value) >= (lowerLimit) && (value) <= (upperLimit))

    switch (linkPtr->type) {
    case TCL_LINK_INT:
................................................................................
 */

static Tcl_Obj *
ObjValue(
    Link *linkPtr)		/* Structure describing linked variable. */
{
    char *p;
    Tcl_Obj *resultObj, **objv;


    int i;

    switch (linkPtr->type) {
    case TCL_LINK_INT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);

	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));
	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewIntObj(linkPtr->lastValue.pi[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.i = LinkedVar(int);
	return Tcl_NewIntObj(linkPtr->lastValue.i);
    case TCL_LINK_WIDE_INT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);

	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));
	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewWideIntObj(linkPtr->lastValue.pw[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.w = LinkedVar(Tcl_WideInt);
	return Tcl_NewWideIntObj(linkPtr->lastValue.w);
    case TCL_LINK_DOUBLE:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);

	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));
	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewDoubleObj(linkPtr->lastValue.pd[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.d = LinkedVar(double);
	return Tcl_NewDoubleObj(linkPtr->lastValue.d);
    case TCL_LINK_BOOLEAN:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);

	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));
	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewBooleanObj(linkPtr->lastValue.pi[i] != 0);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.i = LinkedVar(int);
	return Tcl_NewBooleanObj(linkPtr->lastValue.i);
    case TCL_LINK_CHAR:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);

	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));
	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewIntObj(linkPtr->lastValue.pc[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.c = LinkedVar(char);
	return Tcl_NewIntObj(linkPtr->lastValue.c);
    case TCL_LINK_UCHAR:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);

	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));
	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewIntObj(linkPtr->lastValue.puc[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.uc = LinkedVar(unsigned char);
	return Tcl_NewIntObj(linkPtr->lastValue.uc);
    case TCL_LINK_SHORT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));

	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewIntObj(linkPtr->lastValue.ps[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.s = LinkedVar(short);
	return Tcl_NewIntObj(linkPtr->lastValue.s);
    case TCL_LINK_USHORT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);
	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));

	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewIntObj(linkPtr->lastValue.pus[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.us = LinkedVar(unsigned short);
	return Tcl_NewIntObj(linkPtr->lastValue.us);
    case TCL_LINK_UINT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);

	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));
	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewWideIntObj(linkPtr->lastValue.pui[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.ui = LinkedVar(unsigned int);
	return Tcl_NewWideIntObj((Tcl_WideInt) linkPtr->lastValue.ui);
#if !defined(TCL_WIDE_INT_IS_LONG) && !defined(_WIN32) && !defined(__CYGWIN__)
    case TCL_LINK_LONG:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);

	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));
	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewWideIntObj(linkPtr->lastValue.pl[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.l = LinkedVar(long);
	return Tcl_NewWideIntObj((Tcl_WideInt) linkPtr->lastValue.l);
    case TCL_LINK_ULONG:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);

	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));
	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewWideIntObj(linkPtr->lastValue.pul[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.ul = LinkedVar(unsigned long);
	return Tcl_NewWideIntObj((Tcl_WideInt) linkPtr->lastValue.ul);
#endif
    case TCL_LINK_FLOAT:
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);

	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));
	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewDoubleObj(linkPtr->lastValue.pf[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.f = LinkedVar(float);
	return Tcl_NewDoubleObj(linkPtr->lastValue.f);
    case TCL_LINK_WIDE_UINT:
	/*
	 * FIXME: represent as a bignum.
	 */
	if (linkPtr->flags & LINK_ALLOC_LAST) {
	    memcpy(linkPtr->lastValue.aryPtr, linkPtr->addr, linkPtr->bytes);

	    objv = ckalloc(linkPtr->numElems * sizeof(Tcl_Obj *));
	    for (i=0; i < linkPtr->numElems; i++) {
		objv[i] = Tcl_NewWideIntObj((Tcl_WideInt)
			linkPtr->lastValue.puw[i]);
	    }
	    resultObj = Tcl_NewListObj(linkPtr->numElems, objv);
	    ckfree(objv);
	    return resultObj;
	}
	linkPtr->lastValue.uw = LinkedVar(Tcl_WideUInt);
	return Tcl_NewWideIntObj((Tcl_WideInt) linkPtr->lastValue.uw);

    case TCL_LINK_STRING:
	p = LinkedVar(char *);
	if (p == NULL) {
	    TclNewLiteralStringObj(resultObj, "NULL");
	    return resultObj;
	}
	return Tcl_NewStringObj(p, -1);

Changes to tests/link.test.

396
397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426


427
428
429
430
431
432
433
434
435
436

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456



457
458
459
460
461
462

463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485


486
487
488
489
490
491
492
493
494

495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520


521
522
523
524
525
526
527
528
529
530

531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553


554
555
556
557
558
559
560
561
562

563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588


589
590
591
592
593
594
595
596
597
598

599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621


622
623
624
625
626
627
628
629
630

631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656


657
658
659
660
661
662
663
664
665
666

667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689


690
691
692
693
694
695
696
697
698

699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724


725
726
727
728
729
730
731
732
733
734

735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757


758
759
760
761
762
763
764
765
766

767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792


793
794
795
796
797
798
799
800
801
802

803
804
805
806
807
808
809
810
811
812
813
814


815
816
817
818
819
820
821

822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845


846
847
848
849
850
851
852
853
test link-8.3 {Tcl_UpdateLinkedVar procedure, read-only variable} {testlink} {
    testlink create 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    list [catch {
	testlink update 47 {} {} {} {} {} {} {} {} {} {} {} {} {}
    } msg] $msg $int
} {0 {} 47}

test link-9.1 {linkarray usage messages} {
    set mylist [list]

    catch {testlinkarray} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {testlinkarray x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {testlinkarray update} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {testlinkarray remove} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {testlinkarray create} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {testlinkarray create xx 1 my} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {testlinkarray create char* 0 my} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    join $mylist "\n"


} {wrong # args: should be "testlinkarray option args"
bad option "x": must be update, remove, or create


wrong # args: should be "testlinkarray create ?-readonly? type size name ?address?"
bad type "xx": must be char, uchar, short, ushort, int, uint, long, ulong, wide, uwide, float, double, string, char*, or binary
wrong array size given}

test link-10.1 {linkarray char*} {
    set mylist [list]

    testlinkarray create char* 1 ::my(var)
    lappend mylist [set ::my(var) ""]
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create char* 4 ::my(var)
    set ::my(var) x
    catch {set ::my(var) xyzz} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create -r char* 4 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"
} {



can't set "::my(var)": wrong size of char* value
can't set "::my(var)": wrong size of char* value
can't set "::my(var)": linked variable is read-only}

test link-11.1 {linkarray char} {
    set mylist [list]

    testlinkarray create char 1 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1234} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create char 4 ::my(var)
    catch {set ::my(var) {1 2 3}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r char 2 ::my(var)
    catch {set ::my(var) {1 2}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {can't set "::my(var)": variable must have char value
120
can't set "::my(var)": variable must have char value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-12.1 {linkarray unsigned char} {
    set mylist [list]

    testlinkarray create uchar 1 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1234} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {set ::my(var) -1} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create uchar 4 ::my(var)
    catch {set ::my(var) {1 2 3}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r uchar 2 ::my(var)
    catch {set ::my(var) {1 2}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {can't set "::my(var)": variable must have unsigned char value
120
can't set "::my(var)": variable must have unsigned char value
can't set "::my(var)": variable must have unsigned char value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-13.1 {linkarray short} {
    set mylist [list]

    testlinkarray create short 1 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 123456} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create short 4 ::my(var)
    catch {set ::my(var) {1 2 3}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r short 2 ::my(var)
    catch {set ::my(var) {1 2}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {can't set "::my(var)": variable must have short value
120
can't set "::my(var)": variable must have short value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-14.1 {linkarray unsigned short} {
    set mylist [list]

    testlinkarray create ushort 1 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 123456} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {set ::my(var) -1} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create ushort 4 ::my(var)
    catch {set ::my(var) {1 2 3}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r ushort 2 ::my(var)
    catch {set ::my(var) {1 2}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {can't set "::my(var)": variable must have unsigned short value
120
can't set "::my(var)": variable must have unsigned short value
can't set "::my(var)": variable must have unsigned short value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-15.1 {linkarray int} {
    set mylist [list]

    testlinkarray create int 1 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e3} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create int 4 ::my(var)
    catch {set ::my(var) {1 2 3}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r int 2 ::my(var)
    catch {set ::my(var) {1 2}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {can't set "::my(var)": variable must have integer value
120
can't set "::my(var)": variable must have integer value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-16.1 {linkarray unsigned int} {
    set mylist [list]

    testlinkarray create uint 1 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e33} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {set ::my(var) -1} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create uint 4 ::my(var)
    catch {set ::my(var) {1 2 3}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r uint 2 ::my(var)
    catch {set ::my(var) {1 2}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {can't set "::my(var)": variable must have unsigned int value
120
can't set "::my(var)": variable must have unsigned int value
can't set "::my(var)": variable must have unsigned int value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-17.1 {linkarray long} {
    set mylist [list]

    testlinkarray create long 1 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e33} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create long 4 ::my(var)
    catch {set ::my(var) {1 2 3}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r long 2 ::my(var)
    catch {set ::my(var) {1 2}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {can't set "::my(var)": variable must have long value
120
can't set "::my(var)": variable must have long value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-18.1 {linkarray unsigned long} {
    set mylist [list]

    testlinkarray create ulong 1 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e33} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {set ::my(var) -1} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create ulong 4 ::my(var)
    catch {set ::my(var) {1 2 3}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r ulong 2 ::my(var)
    catch {set ::my(var) {1 2}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {can't set "::my(var)": variable must have unsigned long value
120
can't set "::my(var)": variable must have unsigned long value
can't set "::my(var)": variable must have unsigned long value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-19.1 {linkarray wide} {
    set mylist [list]

    testlinkarray create wide 1 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e33} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create wide 4 ::my(var)
    catch {set ::my(var) {1 2 3}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r wide 2 ::my(var)
    catch {set ::my(var) {1 2}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {can't set "::my(var)": variable must have wide integer value
120
can't set "::my(var)": variable must have wide integer value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-20.1 {linkarray unsigned wide} {
    set mylist [list]

    testlinkarray create uwide 1 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e33} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {set ::my(var) -1} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    testlinkarray create uwide 4 ::my(var)
    catch {set ::my(var) {1 2 3}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r uwide 2 ::my(var)
    catch {set ::my(var) {1 2}} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {can't set "::my(var)": variable must have unsigned wide int value
120
can't set "::my(var)": variable must have unsigned wide int value
can't set "::my(var)": variable must have unsigned wide int value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-21.1 {linkarray string} {
    set mylist [list]

    testlinkarray create string 1 ::my(var)
    lappend mylist [set ::my(var) ""]
    lappend mylist [set ::my(var) "xyz"]
    lappend mylist $::my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r string 4 ::my(var)
    catch {set ::my(var) x} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {
xyz
xyz
can't set "::my(var)": linked variable is read-only}

test link-22.1 {linkarray binary} {
    set mylist [list]

    testlinkarray create binary 1 ::my(var)
    set ::my(var) x
    catch {set ::my(var) xy} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    lappend mylist $::my(var)
    testlinkarray remove ::my(var)
    testlinkarray create binary 4 ::my(var)
    catch {set ::my(var) abc} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    catch {set ::my(var) abcde} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    set ::my(var) abcd
    lappend mylist $::my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r binary 4 ::my(var)
    catch {set ::my(var) xyzv} my(msg)
    lappend mylist $my(msg)
    unset my(msg)
    testlinkarray remove ::my(var)
    unset my
    join $mylist "\n"


} {can't set "::my(var)": wrong size of binary value
x
can't set "::my(var)": wrong size of binary value
can't set "::my(var)": wrong size of binary value
abcd
can't set "::my(var)": linked variable is read-only}
 
catch {testlink set 0 0 0 - 0 0 0 0 0 0 0 0 0 0}






|

>
|
|
<
|
|
<
|
|
<
|
|
<
|
|
<
|
|
<
|
|
<

>
>
|







|

>


|
|
<



|
|
<


|
|
<

<

<
>
>
>




|

>

|
|
<

|
|
<


|
|
<




|
|
<

<

>
>
|






|

>

|
|
<

|
|
<
|
|
<


|
|
<




|
|
<

<

>
>
|







|

>

|
|
<

|
|
<


|
|
<




|
|
<

<

>
>
|






|

>

|
|
<

|
|
<
|
|
<


|
|
<




|
|
<

<

>
>
|







|

>

|
|
<

|
|
<


|
|
<




|
|
<

<

>
>
|






|

>

|
|
<

|
|
<
|
|
<


|
|
<




|
|
<

<

>
>
|







|

>

|
|
<

|
|
<


|
|
<




|
|
<

<

>
>
|

|




|

>

|
|
<

|
|
<
|
|
<


|
|
<




|
|
<

<

>
>
|

|
|




|

>

|
|
<

|
|
<


|
|
<




|
|
<

<

>
>
|






|

>

|
|
<

|
|
<
|
|
<


|
|
<




|
|
<

<

>
>
|







|

>






|
|
<

<

>
>
|




|

>


|
|
<



|
|
<
|
|
<




|
|
<

<

>
>
|







396
397
398
399
400
401
402
403
404
405
406
407

408
409

410
411

412
413

414
415

416
417

418
419

420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437

438
439
440
441
442

443
444
445
446

447

448

449
450
451
452
453
454
455
456
457
458
459
460
461

462
463
464

465
466
467
468

469
470
471
472
473
474

475

476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491

492
493
494

495
496

497
498
499
500

501
502
503
504
505
506

507

508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524

525
526
527

528
529
530
531

532
533
534
535
536
537

538

539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554

555
556
557

558
559

560
561
562
563

564
565
566
567
568
569

570

571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587

588
589
590

591
592
593
594

595
596
597
598
599
600

601

602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617

618
619
620

621
622

623
624
625
626

627
628
629
630
631
632

633

634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650

651
652
653

654
655
656
657

658
659
660
661
662
663

664

665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680

681
682
683

684
685

686
687
688
689

690
691
692
693
694
695

696

697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713

714
715
716

717
718
719
720

721
722
723
724
725
726

727

728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743

744
745
746

747
748

749
750
751
752

753
754
755
756
757
758

759

760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781

782

783
784
785
786
787
788
789
790
791
792
793
794
795
796
797

798
799
800
801
802

803
804

805
806
807
808
809
810

811

812
813
814
815
816
817
818
819
820
821
822
test link-8.3 {Tcl_UpdateLinkedVar procedure, read-only variable} {testlink} {
    testlink create 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    list [catch {
	testlink update 47 {} {} {} {} {} {} {} {} {} {} {} {} {}
    } msg] $msg $int
} {0 {} 47}

test link-9.1 {linkarray usage messages} -setup {
    set mylist [list]
} -body {
    catch {testlinkarray} msg
    lappend mylist $msg

    catch {testlinkarray x} msg
    lappend mylist $msg

    catch {testlinkarray update} msg
    lappend mylist $msg

    catch {testlinkarray remove} msg
    lappend mylist $msg

    catch {testlinkarray create} msg
    lappend mylist $msg

    catch {testlinkarray create xx 1 my} msg
    lappend mylist $msg

    catch {testlinkarray create char* 0 my} msg
    lappend mylist $msg

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -result {wrong # args: should be "testlinkarray option args"
bad option "x": must be update, remove, or create


wrong # args: should be "testlinkarray create ?-readonly? type size name ?address?"
bad type "xx": must be char, uchar, short, ushort, int, uint, long, ulong, wide, uwide, float, double, string, char*, or binary
wrong array size given}

test link-10.1 {linkarray char*} -setup {
    set mylist [list]
} -body {
    testlinkarray create char* 1 ::my(var)
    lappend mylist [set ::my(var) ""]
    catch {set ::my(var) x} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create char* 4 ::my(var)
    set ::my(var) x
    catch {set ::my(var) xyzz} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create -r char* 4 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"

} -cleanup {
    unset -nocomplain my
} -result {
can't set "::my(var)": wrong size of char* value
can't set "::my(var)": wrong size of char* value
can't set "::my(var)": linked variable is read-only}

test link-11.1 {linkarray char} -setup {
    set mylist [list]
} -body {
    testlinkarray create char 1 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1234} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create char 4 ::my(var)
    catch {set ::my(var) {1 2 3}} msg
    lappend mylist $msg

    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r char 2 ::my(var)
    catch {set ::my(var) {1 2}} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -result {can't set "::my(var)": variable must have char value
120
can't set "::my(var)": variable must have char value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-12.1 {linkarray unsigned char} -setup {
    set mylist [list]
} -body {
    testlinkarray create uchar 1 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1234} msg
    lappend mylist $msg

    catch {set ::my(var) -1} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create uchar 4 ::my(var)
    catch {set ::my(var) {1 2 3}} msg
    lappend mylist $msg

    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r uchar 2 ::my(var)
    catch {set ::my(var) {1 2}} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -result {can't set "::my(var)": variable must have unsigned char value
120
can't set "::my(var)": variable must have unsigned char value
can't set "::my(var)": variable must have unsigned char value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-13.1 {linkarray short} -setup {
    set mylist [list]
} -body {
    testlinkarray create short 1 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 123456} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create short 4 ::my(var)
    catch {set ::my(var) {1 2 3}} msg
    lappend mylist $msg

    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r short 2 ::my(var)
    catch {set ::my(var) {1 2}} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -result {can't set "::my(var)": variable must have short value
120
can't set "::my(var)": variable must have short value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-14.1 {linkarray unsigned short} -setup {
    set mylist [list]
} -body {
    testlinkarray create ushort 1 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 123456} msg
    lappend mylist $msg

    catch {set ::my(var) -1} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create ushort 4 ::my(var)
    catch {set ::my(var) {1 2 3}} msg
    lappend mylist $msg

    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r ushort 2 ::my(var)
    catch {set ::my(var) {1 2}} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -result {can't set "::my(var)": variable must have unsigned short value
120
can't set "::my(var)": variable must have unsigned short value
can't set "::my(var)": variable must have unsigned short value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-15.1 {linkarray int} -setup {
    set mylist [list]
} -body {
    testlinkarray create int 1 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e3} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create int 4 ::my(var)
    catch {set ::my(var) {1 2 3}} msg
    lappend mylist $msg

    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r int 2 ::my(var)
    catch {set ::my(var) {1 2}} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -result {can't set "::my(var)": variable must have integer value
120
can't set "::my(var)": variable must have integer value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-16.1 {linkarray unsigned int} -setup {
    set mylist [list]
} -body {
    testlinkarray create uint 1 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e33} msg
    lappend mylist $msg

    catch {set ::my(var) -1} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create uint 4 ::my(var)
    catch {set ::my(var) {1 2 3}} msg
    lappend mylist $msg

    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r uint 2 ::my(var)
    catch {set ::my(var) {1 2}} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -result {can't set "::my(var)": variable must have unsigned int value
120
can't set "::my(var)": variable must have unsigned int value
can't set "::my(var)": variable must have unsigned int value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-17.1 {linkarray long} -setup {
    set mylist [list]
} -body {
    testlinkarray create long 1 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e33} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create long 4 ::my(var)
    catch {set ::my(var) {1 2 3}} msg
    lappend mylist $msg

    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r long 2 ::my(var)
    catch {set ::my(var) {1 2}} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -match glob -result {can't set "::my(var)": variable must have * value
120
can't set "::my(var)": variable must have * value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-18.1 {linkarray unsigned long} -setup {
    set mylist [list]
} -body {
    testlinkarray create ulong 1 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e33} msg
    lappend mylist $msg

    catch {set ::my(var) -1} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create ulong 4 ::my(var)
    catch {set ::my(var) {1 2 3}} msg
    lappend mylist $msg

    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r ulong 2 ::my(var)
    catch {set ::my(var) {1 2}} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -match glob -result {can't set "::my(var)": variable must have unsigned * value
120
can't set "::my(var)": variable must have unsigned * value
can't set "::my(var)": variable must have unsigned * value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-19.1 {linkarray wide} -setup {
    set mylist [list]
} -body {
    testlinkarray create wide 1 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e33} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create wide 4 ::my(var)
    catch {set ::my(var) {1 2 3}} msg
    lappend mylist $msg

    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r wide 2 ::my(var)
    catch {set ::my(var) {1 2}} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -result {can't set "::my(var)": variable must have wide integer value
120
can't set "::my(var)": variable must have wide integer value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-20.1 {linkarray unsigned wide} -setup {
    set mylist [list]
} -body {
    testlinkarray create uwide 1 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    lappend mylist [set ::my(var) 120]
    catch {set ::my(var) 1e33} msg
    lappend mylist $msg

    catch {set ::my(var) -1} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)
    testlinkarray create uwide 4 ::my(var)
    catch {set ::my(var) {1 2 3}} msg
    lappend mylist $msg

    set ::my(var) {1 2 3 4}
    lappend mylist $my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r uwide 2 ::my(var)
    catch {set ::my(var) {1 2}} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -result {can't set "::my(var)": variable must have unsigned wide int value
120
can't set "::my(var)": variable must have unsigned wide int value
can't set "::my(var)": variable must have unsigned wide int value
can't set "::my(var)": wrong dimension
1 2 3 4
can't set "::my(var)": linked variable is read-only}

test link-21.1 {linkarray string} -setup {
    set mylist [list]
} -body {
    testlinkarray create string 1 ::my(var)
    lappend mylist [set ::my(var) ""]
    lappend mylist [set ::my(var) "xyz"]
    lappend mylist $::my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r string 4 ::my(var)
    catch {set ::my(var) x} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -result {
xyz
xyz
can't set "::my(var)": linked variable is read-only}

test link-22.1 {linkarray binary} -setup {
    set mylist [list]
} -body {
    testlinkarray create binary 1 ::my(var)
    set ::my(var) x
    catch {set ::my(var) xy} msg
    lappend mylist $msg

    lappend mylist $::my(var)
    testlinkarray remove ::my(var)
    testlinkarray create binary 4 ::my(var)
    catch {set ::my(var) abc} msg
    lappend mylist $msg

    catch {set ::my(var) abcde} msg
    lappend mylist $msg

    set ::my(var) abcd
    lappend mylist $::my(var)
    testlinkarray remove ::my(var)
    testlinkarray create -r binary 4 ::my(var)
    catch {set ::my(var) xyzv} msg
    lappend mylist $msg

    testlinkarray remove ::my(var)

    join $mylist "\n"
} -cleanup {
    unset -nocomplain my
} -result {can't set "::my(var)": wrong size of binary value
x
can't set "::my(var)": wrong size of binary value
can't set "::my(var)": wrong size of binary value
abcd
can't set "::my(var)": linked variable is read-only}
 
catch {testlink set 0 0 0 - 0 0 0 0 0 0 0 0 0 0}