@@ -318,6 +318,7 @@ typedef struct {
318
318
const Tcl_ObjType * BignumType ;
319
319
const Tcl_ObjType * ListType ;
320
320
const Tcl_ObjType * StringType ;
321
+ const Tcl_ObjType * UTF32StringType ;
321
322
} TkappObject ;
322
323
323
324
#define Tkapp_Interp (v ) (((TkappObject *) (v))->interp)
@@ -588,14 +589,40 @@ Tkapp_New(const char *screenName, const char *className,
588
589
}
589
590
590
591
v -> OldBooleanType = Tcl_GetObjType ("boolean" );
591
- v -> BooleanType = Tcl_GetObjType ("booleanString" );
592
- v -> ByteArrayType = Tcl_GetObjType ("bytearray" );
592
+ {
593
+ Tcl_Obj * value ;
594
+ int boolValue ;
595
+
596
+ /* Tcl 8.5 "booleanString" type is not registered
597
+ and is renamed to "boolean" in Tcl 9.0.
598
+ Based on approach suggested at
599
+ https://core.tcl-lang.org/tcl/info/3bb3bcf2da5b */
600
+ value = Tcl_NewStringObj ("true" , -1 );
601
+ Tcl_GetBooleanFromObj (NULL , value , & boolValue );
602
+ v -> BooleanType = value -> typePtr ;
603
+ Tcl_DecrRefCount (value );
604
+
605
+ // "bytearray" type is not registered in Tcl 9.0
606
+ value = Tcl_NewByteArrayObj (NULL , 0 );
607
+ v -> ByteArrayType = value -> typePtr ;
608
+ Tcl_DecrRefCount (value );
609
+ }
593
610
v -> DoubleType = Tcl_GetObjType ("double" );
611
+ /* TIP 484 suggests retrieving the "int" type without Tcl_GetObjType("int")
612
+ since it is no longer registered in Tcl 9.0. But even though Tcl 8.7
613
+ only uses the "wideInt" type on platforms with 32-bit long, it still has
614
+ a registered "int" type, which FromObj() should recognize just in case. */
594
615
v -> IntType = Tcl_GetObjType ("int" );
616
+ if (v -> IntType == NULL ) {
617
+ Tcl_Obj * value = Tcl_NewIntObj (0 );
618
+ v -> IntType = value -> typePtr ;
619
+ Tcl_DecrRefCount (value );
620
+ }
595
621
v -> WideIntType = Tcl_GetObjType ("wideInt" );
596
622
v -> BignumType = Tcl_GetObjType ("bignum" );
597
623
v -> ListType = Tcl_GetObjType ("list" );
598
624
v -> StringType = Tcl_GetObjType ("string" );
625
+ v -> UTF32StringType = Tcl_GetObjType ("utf32string" );
599
626
600
627
/* Delete the 'exit' command, which can screw things up */
601
628
Tcl_DeleteCommand (v -> interp , "exit" );
@@ -1124,14 +1151,6 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
1124
1151
return PyFloat_FromDouble (value -> internalRep .doubleValue );
1125
1152
}
1126
1153
1127
- if (value -> typePtr == tkapp -> IntType ) {
1128
- long longValue ;
1129
- if (Tcl_GetLongFromObj (interp , value , & longValue ) == TCL_OK )
1130
- return PyLong_FromLong (longValue );
1131
- /* If there is an error in the long conversion,
1132
- fall through to wideInt handling. */
1133
- }
1134
-
1135
1154
if (value -> typePtr == tkapp -> IntType ||
1136
1155
value -> typePtr == tkapp -> WideIntType ) {
1137
1156
result = fromWideIntObj (tkapp , value );
@@ -1176,17 +1195,12 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
1176
1195
return result ;
1177
1196
}
1178
1197
1179
- if (value -> typePtr == tkapp -> StringType ) {
1198
+ if (value -> typePtr == tkapp -> StringType ||
1199
+ value -> typePtr == tkapp -> UTF32StringType )
1200
+ {
1180
1201
return unicodeFromTclObj (value );
1181
1202
}
1182
1203
1183
- if (tkapp -> BooleanType == NULL &&
1184
- strcmp (value -> typePtr -> name , "booleanString" ) == 0 ) {
1185
- /* booleanString type is not registered in Tcl */
1186
- tkapp -> BooleanType = value -> typePtr ;
1187
- return fromBoolean (tkapp , value );
1188
- }
1189
-
1190
1204
if (tkapp -> BignumType == NULL &&
1191
1205
strcmp (value -> typePtr -> name , "bignum" ) == 0 ) {
1192
1206
/* bignum type is not registered in Tcl */
0 commit comments