Use macros instead of corresponding functions (they never fail) in _tkinter.c.

This commit is contained in:
Serhiy Storchaka 2016-06-19 11:22:47 +03:00
parent b8d3e40567
commit 696c8af41f
1 changed files with 26 additions and 22 deletions

View File

@ -462,7 +462,7 @@ Split(const char *list)
v = NULL; v = NULL;
break; break;
} }
PyTuple_SetItem(v, i, w); PyTuple_SET_ITEM(v, i, w);
} }
} }
Tcl_Free(FREECAST argv); Tcl_Free(FREECAST argv);
@ -480,13 +480,13 @@ SplitObj(PyObject *arg)
Py_ssize_t i, size; Py_ssize_t i, size;
PyObject *elem, *newelem, *result; PyObject *elem, *newelem, *result;
size = PyTuple_Size(arg); size = PyTuple_GET_SIZE(arg);
result = NULL; result = NULL;
/* Recursively invoke SplitObj for all tuple items. /* Recursively invoke SplitObj for all tuple items.
If this does not return a new object, no action is If this does not return a new object, no action is
needed. */ needed. */
for(i = 0; i < size; i++) { for(i = 0; i < size; i++) {
elem = PyTuple_GetItem(arg, i); elem = PyTuple_GET_ITEM(arg, i);
newelem = SplitObj(elem); newelem = SplitObj(elem);
if (!newelem) { if (!newelem) {
Py_XDECREF(result); Py_XDECREF(result);
@ -502,12 +502,12 @@ SplitObj(PyObject *arg)
if (!result) if (!result)
return NULL; return NULL;
for(k = 0; k < i; k++) { for(k = 0; k < i; k++) {
elem = PyTuple_GetItem(arg, k); elem = PyTuple_GET_ITEM(arg, k);
Py_INCREF(elem); Py_INCREF(elem);
PyTuple_SetItem(result, k, elem); PyTuple_SET_ITEM(result, k, elem);
} }
} }
PyTuple_SetItem(result, i, newelem); PyTuple_SET_ITEM(result, i, newelem);
} }
if (result) if (result)
return result; return result;
@ -529,7 +529,7 @@ SplitObj(PyObject *arg)
Py_XDECREF(result); Py_XDECREF(result);
return NULL; return NULL;
} }
PyTuple_SetItem(result, i, newelem); PyTuple_SET_ITEM(result, i, newelem);
} }
return result; return result;
} }
@ -551,7 +551,7 @@ SplitObj(PyObject *arg)
else if (PyBytes_Check(arg)) { else if (PyBytes_Check(arg)) {
int argc; int argc;
const char **argv; const char **argv;
char *list = PyBytes_AsString(arg); char *list = PyBytes_AS_STRING(arg);
if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
Py_INCREF(arg); Py_INCREF(arg);
@ -559,7 +559,7 @@ SplitObj(PyObject *arg)
} }
Tcl_Free(FREECAST argv); Tcl_Free(FREECAST argv);
if (argc > 1) if (argc > 1)
return Split(PyBytes_AsString(arg)); return Split(PyBytes_AS_STRING(arg));
/* Fall through, returning arg. */ /* Fall through, returning arg. */
} }
Py_INCREF(arg); Py_INCREF(arg);
@ -758,7 +758,7 @@ Tkapp_New(const char *screenName, const char *className,
} }
Tcl_SetVar(v->interp, Tcl_SetVar(v->interp,
"tcl_library", "tcl_library",
PyBytes_AsString(utf8_path), PyBytes_AS_STRING(utf8_path),
TCL_GLOBAL_ONLY); TCL_GLOBAL_ONLY);
Py_DECREF(utf8_path); Py_DECREF(utf8_path);
} }
@ -1306,7 +1306,7 @@ FromObj(PyObject* tkapp, Tcl_Obj *value)
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;
} }
PyTuple_SetItem(result, i, elem); PyTuple_SET_ITEM(result, i, elem);
} }
return result; return result;
} }
@ -1517,8 +1517,8 @@ Tkapp_Call(PyObject *selfptr, PyObject *args)
int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL; int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL;
/* If args is a single tuple, replace with contents of tuple */ /* If args is a single tuple, replace with contents of tuple */
if (1 == PyTuple_Size(args)){ if (PyTuple_GET_SIZE(args) == 1) {
PyObject* item = PyTuple_GetItem(args, 0); PyObject *item = PyTuple_GET_ITEM(args, 0);
if (PyTuple_Check(item)) if (PyTuple_Check(item))
args = item; args = item;
} }
@ -1728,12 +1728,12 @@ varname_converter(PyObject *in, void *_out)
char *s; char *s;
const char **out = (const char**)_out; const char **out = (const char**)_out;
if (PyBytes_Check(in)) { if (PyBytes_Check(in)) {
if (PyBytes_Size(in) > INT_MAX) { if (PyBytes_GET_SIZE(in) > INT_MAX) {
PyErr_SetString(PyExc_OverflowError, "bytes object is too long"); PyErr_SetString(PyExc_OverflowError, "bytes object is too long");
return 0; return 0;
} }
s = PyBytes_AsString(in); s = PyBytes_AS_STRING(in);
if (strlen(s) != (size_t)PyBytes_Size(in)) { if (strlen(s) != (size_t)PyBytes_GET_SIZE(in)) {
PyErr_SetString(PyExc_ValueError, "embedded null byte"); PyErr_SetString(PyExc_ValueError, "embedded null byte");
return 0; return 0;
} }
@ -2274,10 +2274,11 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg)
return NULL; return NULL;
for (i = 0; i < objc; i++) { for (i = 0; i < objc; i++) {
PyObject *s = FromObj((PyObject*)self, objv[i]); PyObject *s = FromObj((PyObject*)self, objv[i]);
if (!s || PyTuple_SetItem(v, i, s)) { if (!s) {
Py_DECREF(v); Py_DECREF(v);
return NULL; return NULL;
} }
PyTuple_SET_ITEM(v, i, s);
} }
return v; return v;
} }
@ -2304,11 +2305,12 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg)
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
PyObject *s = unicodeFromTclString(argv[i]); PyObject *s = unicodeFromTclString(argv[i]);
if (!s || PyTuple_SetItem(v, i, s)) { if (!s) {
Py_DECREF(v); Py_DECREF(v);
v = NULL; v = NULL;
goto finally; goto finally;
} }
PyTuple_SET_ITEM(v, i, s);
} }
finally: finally:
@ -2349,10 +2351,11 @@ _tkinter_tkapp_split(TkappObject *self, PyObject *arg)
return NULL; return NULL;
for (i = 0; i < objc; i++) { for (i = 0; i < objc; i++) {
PyObject *s = FromObj((PyObject*)self, objv[i]); PyObject *s = FromObj((PyObject*)self, objv[i]);
if (!s || PyTuple_SetItem(v, i, s)) { if (!s) {
Py_DECREF(v); Py_DECREF(v);
return NULL; return NULL;
} }
PyTuple_SET_ITEM(v, i, s);
} }
return v; return v;
} }
@ -2410,10 +2413,11 @@ PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[
for (i = 0; i < (argc - 1); i++) { for (i = 0; i < (argc - 1); i++) {
PyObject *s = unicodeFromTclString(argv[i + 1]); PyObject *s = unicodeFromTclString(argv[i + 1]);
if (!s || PyTuple_SetItem(arg, i, s)) { if (!s) {
Py_DECREF(arg); Py_DECREF(arg);
return PythonCmd_Error(interp); return PythonCmd_Error(interp);
} }
PyTuple_SET_ITEM(arg, i, s);
} }
res = PyEval_CallObject(func, arg); res = PyEval_CallObject(func, arg);
Py_DECREF(arg); Py_DECREF(arg);
@ -3622,14 +3626,14 @@ PyInit__tkinter(void)
} }
} }
Tcl_FindExecutable(PyBytes_AsString(cexe)); Tcl_FindExecutable(PyBytes_AS_STRING(cexe));
if (set_var) { if (set_var) {
SetEnvironmentVariableW(L"TCL_LIBRARY", NULL); SetEnvironmentVariableW(L"TCL_LIBRARY", NULL);
PyMem_Free(wcs_path); PyMem_Free(wcs_path);
} }
#else #else
Tcl_FindExecutable(PyBytes_AsString(cexe)); Tcl_FindExecutable(PyBytes_AS_STRING(cexe));
#endif /* MS_WINDOWS */ #endif /* MS_WINDOWS */
} }
Py_XDECREF(cexe); Py_XDECREF(cexe);