diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-09-01 09:16:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-01 09:16:51 (GMT) |
commit | 1f21eaa15e8a0d2b0f78d0e3f2b9e5b458eb0a70 (patch) | |
tree | 8db3de2421c1d45d018a7a1dc03f42a0797acee2 /Python | |
parent | 5eca7f3f3836cc734dfe8dc5ec669f3b4e9333fe (diff) | |
download | cpython-1f21eaa15e8a0d2b0f78d0e3f2b9e5b458eb0a70.zip cpython-1f21eaa15e8a0d2b0f78d0e3f2b9e5b458eb0a70.tar.gz cpython-1f21eaa15e8a0d2b0f78d0e3f2b9e5b458eb0a70.tar.bz2 |
bpo-15999: Clean up of handling boolean arguments. (GH-15610)
* Use the 'p' format unit instead of manually called PyObject_IsTrue().
* Pass boolean value instead 0/1 integers to functions that needs boolean.
* Convert some arguments to boolean only once.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 20 | ||||
-rw-r--r-- | Python/pylifecycle.c | 4 |
2 files changed, 9 insertions, 15 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 5053f7a..3b0d64f 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1820,8 +1820,9 @@ static PyObject * builtin_print(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { static const char * const _keywords[] = {"sep", "end", "file", "flush", 0}; - static struct _PyArg_Parser _parser = {"|OOOO:print", _keywords, 0}; - PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL; + static struct _PyArg_Parser _parser = {"|OOOp:print", _keywords, 0}; + PyObject *sep = NULL, *end = NULL, *file = NULL; + int flush = 0; int i, err; if (kwnames != NULL && @@ -1883,18 +1884,11 @@ builtin_print(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject if (err) return NULL; - if (flush != NULL) { - PyObject *tmp; - int do_flush = PyObject_IsTrue(flush); - if (do_flush == -1) + if (flush) { + PyObject *tmp = _PyObject_CallMethodIdNoArgs(file, &PyId_flush); + if (tmp == NULL) return NULL; - else if (do_flush) { - tmp = _PyObject_CallMethodIdNoArgs(file, &PyId_flush); - if (tmp == NULL) - return NULL; - else - Py_DECREF(tmp); - } + Py_DECREF(tmp); } Py_RETURN_NONE; diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 7cda44d..ea89b3a 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1735,10 +1735,10 @@ create_stdio(const PyConfig *config, PyObject* io, mode = "wb"; else mode = "rb"; - buf = _PyObject_CallMethodId(io, &PyId_open, "isiOOOi", + buf = _PyObject_CallMethodId(io, &PyId_open, "isiOOOO", fd, mode, buffering, Py_None, Py_None, /* encoding, errors */ - Py_None, 0); /* newline, closefd */ + Py_None, Py_False); /* newline, closefd */ if (buf == NULL) goto error; |