8000 gh-112672: use `Tcl_Size` to avoid incompatible pointer type warnings by chrstphrchvz · Pull Request #112681 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-112672: use Tcl_Size to avoid incompatible pointer type warnings #112681

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 8 commits into from
Jun 4, 2024
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Use Tcl_Size where needed
  • Loading branch information
chrstphrchvz authored Dec 4, 2023
commit f8aee7addb52a73e93ea30a18e628d760da2ee19
30 changes: 18 additions & 12 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ Copyright (C) 1994 Steen Lumholt.
#define USE_DEPRECATED_TOMMATH_API 1
#endif

// As suggested by https://core.tcl-lang.org/tcl/wiki?name=Migrating+C+extensions+to+Tcl+9
#ifndef TCL_SIZE_MAX
typedef Tcl_Size int;
#define TCL_SIZE_MAX INT_MAX
#endif

#if !(defined(MS_WINDOWS) || defined(__CYGWIN__))
#define HAVE_CREATEFILEHANDLER
#endif
Expand Down Expand Up @@ -487,7 +493,7 @@ unicodeFromTclString(const char *s)
static PyObject *
unicodeFromTclObj(Tcl_Obj *value)
{
int len;
Tcl_Size len;
#if USE_TCL_UNICODE
int byteorder = NATIVE_BYTEORDER;
const Tcl_UniChar *u = Tcl_GetUnicodeFromObj(value, &len);
Expand Down Expand Up @@ -1107,7 +1113,7 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
}

if (value->typePtr == tkapp->ByteArrayType) {
int size;
Tcl_Size size;
char *data = (char*)Tcl_GetByteArrayFromObj(value, &size);
return PyBytes_FromStringAndSize(data, size);
}
Expand Down Expand Up @@ -1141,7 +1147,7 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value)
}

if (value->typePtr == tkapp->ListType) {
int i, size;
Tcl_Size i, size;
int status;
PyObject *elem;
Tcl_Obj *tcl_elem;
Expand Down Expand Up @@ -1203,9 +1209,9 @@ typedef struct Tkapp_CallEvent {
} Tkapp_CallEvent;

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++)
Copy link
Contributor Author
@chrstphrchvz chrstphrchvz Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch out for conflict with #112679. I wonder if this function should iterate backwards over objv[] since it is deallocating.

Tcl_DecrRefCount(objv[i]);
if (objv != objStore)
Expand All @@ -1216,7 +1222,7 @@ Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc)
interpreter thread, which may or may not be the calling thread. */

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;
Py_ssize_t objc = 0, i;
Expand Down Expand Up @@ -1264,10 +1270,10 @@ Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc)
Tcl_IncrRefCount(objv[i]);
}
}
*pobjc = (int)objc;
*pobjc = (Tcl_Size)objc;
return objv;
finally:
Tkapp_CallDeallocArgs(objv, objStore, (int)objc);
Tkapp_CallDeallocArgs(objv, objStore, (Tcl_Size)objc);
return NULL;
}

Expand Down Expand Up @@ -1310,7 +1316,7 @@ Tkapp_CallProc(Tkapp_CallEvent *e, int flags)
{
Tcl_Obj *objStore[ARGSZ];
Tcl_Obj **objv;
int objc;
Tcl_Size objc;
int i;
ENTER_PYTHON
objv = Tkapp_CallArgs(e->args, objStore, &objc);
Expand Down Expand Up @@ -1361,7 +1367,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args)
{
Tcl_Obj *objStore[ARGSZ];
Tcl_Obj **objv = NULL;
int objc;
Tcl_Size objc;
PyObject *res = NULL;
TkappObject *self = (TkappObject*)selfptr;
int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL;
Expand Down Expand Up @@ -2080,12 +2086,12 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg)
/*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/
{
char *list;
int argc, i;
Tcl_Size argc, i;
const char **argv;
PyObject *v;

if (PyTclObject_Check(arg)) {
int objc;
Tcl_Size objc;
Tcl_Obj **objv;
if (Tcl_ListObjGetElements(Tkapp_Interp(self),
((PyTclObject*)arg)->value,
Expand Down
0