FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use macros instead of corresponding functions (they never fail) in _t… · python-emscripten/cpython@696c8af · GitHub

Repository navigation

Commit 696c8af

Browse files
Use macros instead of corresponding functions (they never fail) in _tkinter.c.
1 parent b8d3e40 commit 696c8af

1 file changed

Lines changed: 26 additions & 22 deletions

File tree

‎Modules/_tkinter.c‎

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ Split(const char *list)
462462
v = NULL;
463463
break;
464464
}
465-
PyTuple_SetItem(v, i, w);
465+
PyTuple_SET_ITEM(v, i, w);
466466
}
467467
}
468468
Tcl_Free(FREECAST argv);
@@ -480,13 +480,13 @@ SplitObj(PyObject *arg)
480480
Py_ssize_t i, size;
481481
PyObject *elem, *newelem, *result;
482482

483-
size = PyTuple_Size(arg);
483+
size = PyTuple_GET_SIZE(arg);
484484
result = NULL;
485485
/* Recursively invoke SplitObj for all tuple items.
486486
If this does not return a new object, no action is
487487
needed. */
488488
for(i = 0; i < size; i++) {
489-
elem = PyTuple_GetItem(arg, i);
489+
elem = PyTuple_GET_ITEM(arg, i);
490490
newelem = SplitObj(elem);
491491
if (!newelem) {
492492
Py_XDECREF(result);
@@ -502,12 +502,12 @@ SplitObj(PyObject *arg)
502502
if (!result)
503503
return NULL;
504504
for(k = 0; k < i; k++) {
505-
elem = PyTuple_GetItem(arg, k);
505+
elem = PyTuple_GET_ITEM(arg, k);
506506
Py_INCREF(elem);
507-
PyTuple_SetItem(result, k, elem);
507+
PyTuple_SET_ITEM(result, k, elem);
508508
}
509509
}
510-
PyTuple_SetItem(result, i, newelem);
510+
PyTuple_SET_ITEM(result, i, newelem);
511511
}
512512
if (result)
513513
return result;
@@ -529,7 +529,7 @@ SplitObj(PyObject *arg)
529529
Py_XDECREF(result);
530530
return NULL;
531531
}
532-
PyTuple_SetItem(result, i, newelem);
532+
PyTuple_SET_ITEM(result, i, newelem);
533533
}
534534
return result;
535535
}
@@ -551,15 +551,15 @@ SplitObj(PyObject *arg)
551551
else if (PyBytes_Check(arg)) {
552552
int argc;
553553
const char **argv;
554-
char *list = PyBytes_AsString(arg);
554+
char *list = PyBytes_AS_STRING(arg);
555555

556556
if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
557557
Py_INCREF(arg);
558558
return arg;
559559
}
560560
Tcl_Free(FREECAST argv);
561561
if (argc > 1)
562-
return Split(PyBytes_AsString(arg));
562+
return Split(PyBytes_AS_STRING(arg));
563563
/* Fall through, returning arg. */
564564
}
565565
Py_INCREF(arg);
@@ -758,7 +758,7 @@ Tkapp_New(const char *screenName, const char *className,
758758
}
759759
Tcl_SetVar(v->interp,
760760
"tcl_library",
761-
PyBytes_AsString(utf8_path),
761+
PyBytes_AS_STRING(utf8_path),
762762
TCL_GLOBAL_ONLY);
763763
Py_DECREF(utf8_path);
764764
}
@@ -1306,7 +1306,7 @@ FromObj(PyObject* tkapp, Tcl_Obj *value)
13061306
Py_DECREF(result);
13071307
return NULL;
13081308
}
1309-
PyTuple_SetItem(result, i, elem);
1309+
PyTuple_SET_ITEM(result, i, elem);
13101310
}
13111311
return result;
13121312
}
@@ -1517,8 +1517,8 @@ Tkapp_Call(PyObject *selfptr, PyObject *args)
15171517
int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL;
15181518

15191519
/* If args is a single tuple, replace with contents of tuple */
1520-
if (1 == PyTuple_Size(args)){
1521-
PyObject* item = PyTuple_GetItem(args, 0);
1520+
if (PyTuple_GET_SIZE(args) == 1) {
1521+
PyObject *item = PyTuple_GET_ITEM(args, 0);
15221522
if (PyTuple_Check(item))
15231523
args = item;
15241524
}
@@ -1728,12 +1728,12 @@ varname_converter(PyObject *in, void *_out)
17281728
char *s;
17291729
const char **out = (const char**)_out;
17301730
if (PyBytes_Check(in)) {
1731-
if (PyBytes_Size(in) > INT_MAX) {
1731+
if (PyBytes_GET_SIZE(in) > INT_MAX) {
17321732
PyErr_SetString(PyExc_OverflowError, "bytes object is too long");
17331733
return 0;
17341734
}
1735-
s = PyBytes_AsString(in);
1736-
if (strlen(s) != (size_t)PyBytes_Size(in)) {
1735+
s = PyBytes_AS_STRING(in);
1736+
if (strlen(s) != (size_t)PyBytes_GET_SIZE(in)) {
17371737
PyErr_SetString(PyExc_ValueError, "embedded null byte");
17381738
return 0;
17391739
}
@@ -2274,10 +2274,11 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg)
22742274
return NULL;
22752275
for (i = 0; i < objc; i++) {
22762276
PyObject *s = FromObj((PyObject*)self, objv[i]);
2277-
if (!s || PyTuple_SetItem(v, i, s)) {
2277+
if (!s) {
22782278
Py_DECREF(v);
22792279
return NULL;
22802280
}
2281+
PyTuple_SET_ITEM(v, i, s);
22812282
}
22822283
return v;
22832284
}
@@ -2304,11 +2305,12 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg)
23042305

23052306
for (i = 0; i < argc; i++) {
23062307
PyObject *s = unicodeFromTclString(argv[i]);
2307-
if (!s || PyTuple_SetItem(v, i, s)) {
2308+
if (!s) {
23082309
Py_DECREF(v);
23092310
v = NULL;
23102311
goto finally;
23112312
}
2313+
PyTuple_SET_ITEM(v, i, s);
23122314
}
23132315

23142316
finally:
@@ -2349,10 +2351,11 @@ _tkinter_tkapp_split(TkappObject *self, PyObject *arg)
23492351
return NULL;
23502352
for (i = 0; i < objc; i++) {
23512353
PyObject *s = FromObj((PyObject*)self, objv[i]);
2352-
if (!s || PyTuple_SetItem(v, i, s)) {
2354+
if (!s) {
23532355
Py_DECREF(v);
23542356
return NULL;
23552357
}
2358+
PyTuple_SET_ITEM(v, i, s);
23562359
}
23572360
return v;
23582361
}
@@ -2410,10 +2413,11 @@ PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[
24102413

24112414
for (i = 0; i < (argc - 1); i++) {
24122415
PyObject *s = unicodeFromTclString(argv[i + 1]);
2413-
if (!s || PyTuple_SetItem(arg, i, s)) {
2416+
if (!s) {
24142417
Py_DECREF(arg);
24152418
return PythonCmd_Error(interp);
24162419
}
2420+
PyTuple_SET_ITEM(arg, i, s);
24172421
}
24182422
res = PyEval_CallObject(func, arg);
24192423
Py_DECREF(arg);
@@ -3622,14 +3626,14 @@ PyInit__tkinter(void)
36223626
}
36233627
}
36243628

3625-
Tcl_FindExecutable(PyBytes_AsString(cexe));
3629+
Tcl_FindExecutable(PyBytes_AS_STRING(cexe));
36263630

36273631
if (set_var) {
36283632
SetEnvironmentVariableW(L"TCL_LIBRARY", NULL);
36293633
PyMem_Free(wcs_path);
36303634
}
36313635
#else
3632-
Tcl_FindExecutable(PyBytes_AsString(cexe));
3636+
Tcl_FindExecutable(PyBytes_AS_STRING(cexe));
36333637
#endif /* MS_WINDOWS */
36343638
}
36353639
Py_XDECREF(cexe);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL