@@ -322,6 +322,7 @@ typedef struct {
322
322
const Tcl_ObjType * ListType ;
323
323
const Tcl_ObjType * ProcBodyType ;
324
324
const Tcl_ObjType * StringType ;
325
+ const Tcl_ObjType * UTF32StringType ;
325
326
} TkappObject ;
326
327
327
328
#define Tkapp_Interp (v ) (((TkappObject *) (v))->interp)
@@ -592,15 +593,41 @@ Tkapp_New(const char *screenName, const char *className,
592
593
}
593
594
594
595
v -> OldBooleanType = Tcl_GetObjType ("boolean" );
595
- v -> BooleanType = Tcl_GetObjType ("booleanString" );
596
- v -> ByteArrayType = Tcl_GetObjType ("bytearray" );
596
+ {
597
+ Tcl_Obj * value ;
598
+ int boolValue ;
599
+
600
+ /* Tcl 8.5 "booleanString" type is not registered
601
+ and is renamed to "boolean" in Tcl 9.0.
602
+ Based on approach suggested at
603
+ https://core.tcl-lang.org/tcl/info/3bb3bcf2da5b */
604
+ value = Tcl_NewStringObj ("true" , -1 );
605
+ Tcl_GetBooleanFromObj (NULL , value , & boolValue );
606
+ v -> BooleanType = value -> typePtr ;
607
+ Tcl_DecrRefCount (value );
608
+
609
+ // "bytearray" type is not registered in Tcl 9.0
610
+ value = Tcl_NewByteArrayObj (NULL , 0 );
611
+ v -> ByteArrayType = value -> typePtr ;
612
+ Tcl_DecrRefCount (value );
613
+ }
597
614
v -> DoubleType = Tcl_GetObjType ("double" );
615
+ /* TIP 484 suggests retrieving the "int" type without Tcl_GetObjType("int")
616
+ since it is no longer registered in Tcl 9.0. But even though Tcl 8.7
617
+ only uses the "wideInt" type on platforms with 32-bit long, it still has
618
+ a registered "int" type, which FromObj() should recognize just in case. */
598
619
v -> IntType = Tcl_GetObjType ("int" );
620
+ if (v -> IntType == NULL ) {
621
+ Tcl_Obj * value = Tcl_NewIntObj (0 );
622
+ v -> IntType = value -> typePtr ;
623
+ Tcl_DecrRefCount (value );
624
+ }
599
625
v -> WideIntType = Tcl_GetObjType ("wideInt" );
600
626
v -> BignumType = Tcl_GetObjType ("bignum" );
601
627
v -> ListType = Tcl_GetObjType ("list" );
602
628
v -> ProcBodyType = Tcl_GetObjType ("procbody" );
603
629
v -> StringType = Tcl_GetObjType ("string" );
630
+ v -> UTF32StringType = Tcl_GetObjType ("utf32string" );
604
631
605
632
/* Delete the 'exit' command, which can screw things up */
606
633
Tcl_DeleteCommand (v -> interp , "exit" );
@@ -1130,14 +1157,6 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
1130
1157
return PyFloat_FromDouble (value -> internalRep .doubleValue );
1131
1158
}
1132
1159
1133
- if (value -> typePtr == tkapp -> IntType ) {
1134
- long longValue ;
1135
- if (Tcl_GetLongFromObj (interp , value , & longValue ) == TCL_OK )
1136
- return PyLong_FromLong (longValue );
1137
- /* If there is an error in the long conversion,
1138
- fall through to wideInt handling. */
1139
- }
1140
-
1141
1160
if (value -> typePtr == tkapp -> IntType ||
1142
1161
value -> typePtr == tkapp -> WideIntType ) {
1143
1162
result = fromWideIntObj (tkapp , value );
@@ -1182,21 +1201,12 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
1182
1201
return result ;
1183
1202
}
1184
1203
1185
- if (value -> typePtr == tkapp -> ProcBodyType ) {
1186
- /* fall through: return tcl object. */
1187
- }
1188
-
1189
- if (value -> typePtr == tkapp -> StringType ) {
1204
+ if (value -> typePtr == tkapp -> StringType ||
1205
+ value -> typePtr == tkapp -> UTF32StringType )
1206
+ {
1190
1207
return unicodeFromTclObj (value );
1191
1208
}
1192
1209
1193
- if (tkapp -> BooleanType == NULL &&
1194
- strcmp (value -> typePtr -> name , "booleanString" ) == 0 ) {
1195
- /* booleanString type is not registered in Tcl */
1196
- tkapp -> BooleanType = value -> typePtr ;
1197
- return fromBoolean (tkapp , value );
1198
- }
1199
-
1200
1210
if (tkapp -> BignumType == NULL &&
1201
1211
strcmp (value -> typePtr -> name , "bignum" ) == 0 ) {
1202
1212
/* bignum type is not registered in Tcl */
0 commit comments