@@ -581,11 +581,46 @@ Tkapp_New(const char *screenName, const char *className,
581581 }
582582
583583 v -> OldBooleanType = Tcl_GetObjType ("boolean" );
584- v -> BooleanType = Tcl_GetObjType ("booleanString" );
585- v -> ByteArrayType = Tcl_GetObjType ("bytearray" );
586- v -> DoubleType = Tcl_GetObjType ("double" );
587584 v -> IntType = Tcl_GetObjType ("int" );
588585 v -> WideIntType = Tcl_GetObjType ("wideInt" );
586+ {
587+ Tcl_Obj * value ;
588+ int boolValue ;
589+
590+ /* Tcl 8.5 booleanString type is not registered
591+ and is renamed to boolean in Tcl 9.0.
592+ Based on approach suggested at
593+ https://core.tcl-lang.org/tcl/info/3bb3bcf2da5b */
594+ value = Tcl_NewStringObj ("true" , -1 );
595+ Tcl_GetBooleanFromObj (NULL , value , & boolValue );
596+ //fprintf(stderr, "%s %p\n", value->typePtr->name, value->typePtr);
597+ v -> BooleanType = value -> typePtr ;
598+ Tcl_DecrRefCount (value );
599+
600+ // As suggested by TIP 484
601+ value = Tcl_NewIntObj (0 );
602+ //fprintf(stderr, "%s %p\n", value->typePtr->name, value->typePtr);
603+ v -> IntType = value -> typePtr ;
604+ Tcl_DecrRefCount (value );
605+
606+ /* Retrieve the 64-bit type, which is either "wideInt" or "int";
607+ the "wideInt" type is only available when the "int" type is 32-bit. */
608+ value = Tcl_NewWideIntObj (
609+ /* Must use a value wider than 32-bit here, otherwise
610+ Tcl_NewWideIntObj() could return a 32-bit "int". */
611+ (Tcl_WideInt )(1 ) << 32
612+ );
613+ //fprintf(stderr, "%s %p\n", value->typePtr->name, value->typePtr);
614+ v -> WideIntType = value -> typePtr ;
615+ Tcl_DecrRefCount (value );
616+
617+ // bytearray type is not registered in Tcl 9.0
618+ value = Tcl_NewByteArrayObj (NULL , 0 );
619+ //fprintf(stderr, "%s %p\n", value->typePtr->name, value->typePtr);
620+ v -> ByteArrayType = value -> typePtr ;
621+ Tcl_DecrRefCount (value );
622+ }
623+ v -> DoubleType = Tcl_GetObjType ("double" );
589624 v -> BignumType = Tcl_GetObjType ("bignum" );
590625 v -> ListType = Tcl_GetObjType ("list" );
591626 v -> ProcBodyType = Tcl_GetObjType ("procbody" );
@@ -1092,10 +1127,12 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
10921127
10931128 if (value -> typePtr == tkapp -> BooleanType ||
10941129 value -> typePtr == tkapp -> OldBooleanType ) {
1130+ //fprintf(stderr, "fromBoolean\n");
10951131 return fromBoolean (tkapp , value );
10961132 }
10971133
10981134 if (value -> typePtr == tkapp -> ByteArrayType ) {
1135+ //fprintf(stderr, "got bytearray\n");
10991136 int size ;
11001137 char * data = (char * )Tcl_GetByteArrayFromObj (value , & size );
11011138 return PyBytes_FromStringAndSize (data , size );
@@ -1105,16 +1142,9 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
11051142 return PyFloat_FromDouble (value -> internalRep .doubleValue );
11061143 }
11071144
1108- if (value -> typePtr == tkapp -> IntType ) {
1109- long longValue ;
1110- if (Tcl_GetLongFromObj (interp , value , & longValue ) == TCL_OK )
1111- return PyLong_FromLong (longValue );
1112- /* If there is an error in the long conversion,
1113- fall through to wideInt handling. */
1114- }
1115-
11161145 if (value -> typePtr == tkapp -> IntType ||
11171146 value -> typePtr == tkapp -> WideIntType ) {
1147+ //fprintf(stderr, "fromWideIntObj\n");
11181148 result = fromWideIntObj (tkapp , value );
11191149 if (result != NULL || PyErr_Occurred ())
11201150 return result ;
@@ -1165,13 +1195,6 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
11651195 return unicodeFromTclObj (value );
11661196 }
11671197
1168- if (tkapp -> BooleanType == NULL &&
1169- strcmp (value -> typePtr -> name , "booleanString" ) == 0 ) {
1170- /* booleanString type is not registered in Tcl */
1171- tkapp -> BooleanType = value -> typePtr ;
1172- return fromBoolean (tkapp , value );
1173- }
1174-
11751198 if (tkapp -> BignumType == NULL &&
11761199 strcmp (value -> typePtr -> name , "bignum" ) == 0 ) {
11771200 /* bignum type is not registered in Tcl */
0 commit comments