10000 gh-103194: Fix Tkinter’s Tcl value type handling for Tcl 8.7/9.0 by chrstphrchvz · Pull Request #103846 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-103194: Fix Tkinter’s Tcl value type handling for Tcl 8.7/9.0 #103846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
May 31, 2024
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-103194: Fix value type handling for Tcl 8.7/9.0
  • Loading branch information
chrstphrchvz committed Apr 25, 2023
commit e3e844472178eb68ac69261f90bc4ef1623d4809
59 changes: 40 additions & 19 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,44 @@ Tkapp_New(const char *screenName, const char *className,
}

v->OldBooleanType = Tcl_GetObjType("boolean");
v->BooleanType = Tcl_GetObjType("booleanString");
v->ByteArrayType = Tcl_GetObjType("bytearray");
{
Tcl_Obj *value;
int boolValue;

/* Tcl 8.5 booleanString type is not registered
and is renamed to boolean in Tcl 9.0.
Based on approach suggested at
https://core.tcl-lang.org/tcl/info/3bb3bcf2da5b */
value = Tcl_NewStringObj("true", -1);
Tcl_GetBooleanFromObj(NULL, value, &boolValue);
//fprintf(stderr, "%s %p\n", value->typePtr->name, value->typePtr);
v->BooleanType = value->typePtr;
Tcl_DecrRefCount(value);

// As suggested by TIP 484
value = Tcl_NewIntObj(0);
//fprintf(stderr, "%s %p\n", value->typePtr->name, value->typePtr);
v->IntType = value->typePtr;
Tcl_DecrRefCount(value);

/* Retrieve the 64-bit type, which is either "wideInt" or "int";
the "wideInt" type is only available when the "int" type is 32-bit. */
value = Tcl_NewWideIntObj(
/* Must use a value wider than 32-bit here, otherwise
Tcl_NewWideIntObj() could return a 32-bit "int". */
(Tcl_WideInt)(1) << 32
);
//fprintf(stderr, "%s %p\n", value->typePtr->name, value->typePtr);
v->WideIntType = value->typePtr;
Tcl_DecrRefCount(value);

// bytearray type is not registered in Tcl 9.0
value = Tcl_NewByteArrayObj(NULL, 0);
//fprintf(stderr, "%s %p\n", value->typePtr->name, value->typePtr);
v->ByteArrayType = value->typePtr;
Tcl_DecrRefCount(value);
}
v->DoubleType = Tcl_GetObjType("double");
v->IntType = Tcl_GetObjType("int");
v->WideIntType = Tcl_GetObjType("wideInt");
v->BignumType = Tcl_GetObjType("bignum");
v->ListType = Tcl_GetObjType("list");
v->ProcBodyType = Tcl_GetObjType("procbody");
Expand Down Expand Up @@ -1092,10 +1125,12 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)

if (value->typePtr == tkapp->BooleanType ||
value->typePtr == tkapp->OldBooleanType) {
//fprintf(stderr, "fromBoolean\n");
return fromBoolean(tkapp, value);
}

if (value->typePtr == tkapp->ByteArrayType) {
//fprintf(stderr, "got bytearray\n");
int size;
char *data = (char*)Tcl_GetByteArrayFromObj(value, &size);
return PyBytes_FromStringAndSize(data, size);
Expand All @@ -1105,16 +1140,9 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
return PyFloat_FromDouble(value->internalRep.doubleValue);
}

if (value->typePtr == tkapp->IntType) {
long longValue;
if (Tcl_GetLongFromObj(interp, value, &longValue) == TCL_OK)
return PyLong_FromLong(longValue);
/* If there is an error in the long conversion,
fall through to wideInt handling. */
}

if (value->typePtr == tkapp->IntType ||
value->typePtr == tkapp->WideIntType) {
//fprintf(stderr, "fromWideIntObj\n");
result = fromWideIntObj(tkapp, value);
if (result != NULL || PyErr_Occurred())
return result;
Expand Down Expand Up @@ -1165,13 +1193,6 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
return unicodeFromTclObj(value);
}

if (tkapp->BooleanType == NULL &&
strcmp(value->typePtr->name, "booleanString") == 0) {
/* booleanString type is not registered in Tcl */
tkapp->BooleanType = value->typePtr;
return fromBoolean(tkapp, value);
}

if (tkapp->BignumType == NULL &&
strcmp(value->typePtr->name, "bignum") == 0) {
/* bignum type is not registered in Tcl */
Expand Down
0