[3.13] gh-112672: Fix builtin Tkinter with Tcl 9.0 (GH-112681) (GH-120208)

* Add declaration of Tcl_AppInit(), missing in Tcl 9.0.
* Use Tcl_Size instead of int where needed.

(cherry picked from commit e079935282)

Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-06-07 12:12:31 +02:00 committed by GitHub
parent ffa7d82a04
commit f0165d00b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 14 deletions

View File

@ -0,0 +1 @@
Support building :mod:`tkinter` with Tcl 9.0.

View File

@ -69,6 +69,12 @@ Copyright (C) 1994 Steen Lumholt.
#define USE_DEPRECATED_TOMMATH_API 1 #define USE_DEPRECATED_TOMMATH_API 1
#endif #endif
// As suggested by https://core.tcl-lang.org/tcl/wiki?name=Migrating+C+extensions+to+Tcl+9
#ifndef TCL_SIZE_MAX
typedef int Tcl_Size;
#define TCL_SIZE_MAX INT_MAX
#endif
#if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) #if !(defined(MS_WINDOWS) || defined(__CYGWIN__))
#define HAVE_CREATEFILEHANDLER #define HAVE_CREATEFILEHANDLER
#endif #endif
@ -489,7 +495,7 @@ unicodeFromTclString(const char *s)
static PyObject * static PyObject *
unicodeFromTclObj(Tcl_Obj *value) unicodeFromTclObj(Tcl_Obj *value)
{ {
int len; Tcl_Size len;
#if USE_TCL_UNICODE #if USE_TCL_UNICODE
int byteorder = NATIVE_BYTEORDER; int byteorder = NATIVE_BYTEORDER;
const Tcl_UniChar *u = Tcl_GetUnicodeFromObj(value, &len); const Tcl_UniChar *u = Tcl_GetUnicodeFromObj(value, &len);
@ -517,6 +523,10 @@ class _tkinter.tktimertoken "TkttObject *" "&Tktt_Type_spec"
/**** Tkapp Object ****/ /**** Tkapp Object ****/
#if TK_MAJOR_VERSION >= 9
int Tcl_AppInit(Tcl_Interp *);
#endif
#ifndef WITH_APPINIT #ifndef WITH_APPINIT
int int
Tcl_AppInit(Tcl_Interp *interp) Tcl_AppInit(Tcl_Interp *interp)
@ -1142,7 +1152,7 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
} }
if (value->typePtr == tkapp->ByteArrayType) { if (value->typePtr == tkapp->ByteArrayType) {
int size; Tcl_Size size;
char *data = (char*)Tcl_GetByteArrayFromObj(value, &size); char *data = (char*)Tcl_GetByteArrayFromObj(value, &size);
return PyBytes_FromStringAndSize(data, size); return PyBytes_FromStringAndSize(data, size);
} }
@ -1168,8 +1178,8 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
} }
if (value->typePtr == tkapp->ListType) { if (value->typePtr == tkapp->ListType) {
int size; Tcl_Size i, size;
int i, status; int status;
PyObject *elem; PyObject *elem;
Tcl_Obj *tcl_elem; Tcl_Obj *tcl_elem;
@ -1225,9 +1235,9 @@ typedef struct Tkapp_CallEvent {
} Tkapp_CallEvent; } Tkapp_CallEvent;
static void static void
Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, Tcl_Size objc)
{ {
int i; Tcl_Size i;
for (i = 0; i < objc; i++) for (i = 0; i < objc; i++)
Tcl_DecrRefCount(objv[i]); Tcl_DecrRefCount(objv[i]);
if (objv != objStore) if (objv != objStore)
@ -1238,7 +1248,7 @@ Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc)
interpreter thread, which may or may not be the calling thread. */ interpreter thread, which may or may not be the calling thread. */
static Tcl_Obj** static Tcl_Obj**
Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, Tcl_Size *pobjc)
{ {
Tcl_Obj **objv = objStore; Tcl_Obj **objv = objStore;
Py_ssize_t objc = 0, i; Py_ssize_t objc = 0, i;
@ -1286,10 +1296,10 @@ Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc)
Tcl_IncrRefCount(objv[i]); Tcl_IncrRefCount(objv[i]);
} }
} }
*pobjc = (int)objc; *pobjc = (Tcl_Size)objc;
return objv; return objv;
finally: finally:
Tkapp_CallDeallocArgs(objv, objStore, (int)objc); Tkapp_CallDeallocArgs(objv, objStore, (Tcl_Size)objc);
return NULL; return NULL;
} }
@ -1356,7 +1366,7 @@ Tkapp_CallProc(Tcl_Event *evPtr, int flags)
Tkapp_CallEvent *e = (Tkapp_CallEvent *)evPtr; Tkapp_CallEvent *e = (Tkapp_CallEvent *)evPtr;
Tcl_Obj *objStore[ARGSZ]; Tcl_Obj *objStore[ARGSZ];
Tcl_Obj **objv; Tcl_Obj **objv;
int objc; Tcl_Size objc;
int i; int i;
ENTER_PYTHON ENTER_PYTHON
if (e->self->trace && !Tkapp_Trace(e->self, PyTuple_Pack(1, e->args))) { if (e->self->trace && !Tkapp_Trace(e->self, PyTuple_Pack(1, e->args))) {
@ -1412,7 +1422,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args)
{ {
Tcl_Obj *objStore[ARGSZ]; Tcl_Obj *objStore[ARGSZ];
Tcl_Obj **objv = NULL; Tcl_Obj **objv = NULL;
int objc, i; Tcl_Size objc;
PyObject *res = NULL; PyObject *res = NULL;
TkappObject *self = (TkappObject*)selfptr; TkappObject *self = (TkappObject*)selfptr;
int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL; int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL;
@ -1459,6 +1469,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args)
{ {
TRACE(self, ("(O)", args)); TRACE(self, ("(O)", args));
int i;
objv = Tkapp_CallArgs(args, objStore, &objc); objv = Tkapp_CallArgs(args, objStore, &objc);
if (!objv) if (!objv)
return NULL; return NULL;
@ -2193,13 +2204,12 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg)
/*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/ /*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/
{ {
char *list; char *list;
int argc; Tcl_Size argc, i;
const char **argv; const char **argv;
PyObject *v; PyObject *v;
int i;
if (PyTclObject_Check(arg)) { if (PyTclObject_Check(arg)) {
int objc; Tcl_Size objc;
Tcl_Obj **objv; Tcl_Obj **objv;
if (Tcl_ListObjGetElements(Tkapp_Interp(self), if (Tcl_ListObjGetElements(Tkapp_Interp(self),
((PyTclObject*)arg)->value, ((PyTclObject*)arg)->value,