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 /Modules | |
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 'Modules')
-rw-r--r-- | Modules/_io/_iomodule.c | 10 | ||||
-rw-r--r-- | Modules/_io/stringio.c | 4 | ||||
-rw-r--r-- | Modules/_io/textio.c | 10 | ||||
-rw-r--r-- | Modules/itertoolsmodule.c | 6 | ||||
-rw-r--r-- | Modules/main.c | 2 | ||||
-rw-r--r-- | Modules/parsermodule.c | 11 |
6 files changed, 20 insertions, 23 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 96426e0..162b288 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -383,8 +383,10 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, encoding = "utf-8"; } #endif - raw = PyObject_CallFunction(RawIO_class, - "OsiO", path_or_fd, rawmode, closefd, opener); + raw = PyObject_CallFunction(RawIO_class, "OsOO", + path_or_fd, rawmode, + closefd ? Py_True : Py_False, + opener); } if (raw == NULL) @@ -476,10 +478,10 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, /* wraps into a TextIOWrapper */ wrapper = PyObject_CallFunction((PyObject *)&PyTextIOWrapper_Type, - "Osssi", + "OsssO", buffer, encoding, errors, newline, - line_buffering); + line_buffering ? Py_True : Py_False); if (wrapper == NULL) goto error; result = wrapper; diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c index 3f7afad..89b29bb 100644 --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -714,9 +714,9 @@ _io_StringIO___init___impl(stringio *self, PyObject *value, } if (self->readuniversal) { - self->decoder = PyObject_CallFunction( + self->decoder = PyObject_CallFunctionObjArgs( (PyObject *)&PyIncrementalNewlineDecoder_Type, - "Oi", Py_None, (int) self->readtranslate); + Py_None, self->readtranslate ? Py_True : Py_False, NULL); if (self->decoder == NULL) return -1; } diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 7ddac80..1db8d94 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -880,9 +880,9 @@ _textiowrapper_set_decoder(textio *self, PyObject *codec_info, return -1; if (self->readuniversal) { - PyObject *incrementalDecoder = PyObject_CallFunction( + PyObject *incrementalDecoder = PyObject_CallFunctionObjArgs( (PyObject *)&PyIncrementalNewlineDecoder_Type, - "Oi", self->decoder, (int)self->readtranslate); + self->decoder, self->readtranslate ? Py_True : Py_False, NULL); if (incrementalDecoder == NULL) return -1; Py_CLEAR(self->decoder); @@ -2591,8 +2591,8 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) } Py_XSETREF(self->snapshot, snapshot); - decoded = _PyObject_CallMethodId(self->decoder, &PyId_decode, - "Oi", input_chunk, (int)cookie.need_eof); + decoded = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_decode, + input_chunk, cookie.need_eof ? Py_True : Py_False, NULL); if (check_decoded(decoded) < 0) goto fail; @@ -2819,7 +2819,7 @@ _io_TextIOWrapper_tell_impl(textio *self) if (input == input_end) { /* We didn't get enough decoded data; signal EOF to get more. */ PyObject *decoded = _PyObject_CallMethodId( - self->decoder, &PyId_decode, "yi", "", /* final = */ 1); + self->decoder, &PyId_decode, "yO", "", /* final = */ Py_True); if (check_decoded(decoded) < 0) goto fail; chars_decoded += PyUnicode_GET_LENGTH(decoded); diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index ab473e2..2e39842 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -1059,10 +1059,10 @@ cycle_reduce(cycleobject *lz, PyObject *Py_UNUSED(ignored)) } Py_DECREF(res); } - return Py_BuildValue("O(N)(Oi)", Py_TYPE(lz), it, lz->saved, 1); + return Py_BuildValue("O(N)(OO)", Py_TYPE(lz), it, lz->saved, Py_True); } - return Py_BuildValue("O(O)(Oi)", Py_TYPE(lz), lz->it, lz->saved, - lz->firstpass); + return Py_BuildValue("O(O)(OO)", Py_TYPE(lz), lz->it, lz->saved, + lz->firstpass ? Py_True : Py_False); } static PyObject * diff --git a/Modules/main.c b/Modules/main.c index b8a1c9b..fdc7e0d 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -292,7 +292,7 @@ pymain_run_module(const wchar_t *modname, int set_argv0) Py_DECREF(runmodule); return pymain_exit_err_print(); } - runargs = Py_BuildValue("(Oi)", module, set_argv0); + runargs = PyTuple_Pack(2, module, set_argv0 ? Py_True : Py_False); if (runargs == NULL) { fprintf(stderr, "Could not create arguments for runpy._run_module_as_main\n"); diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index b2495fc..ef63ca9 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -1080,25 +1080,20 @@ parser__pickler(PyObject *self, PyObject *args) NOTE(ARGUNUSED(self)) PyObject *result = NULL; PyObject *st = NULL; - PyObject *empty_dict = NULL; if (PyArg_ParseTuple(args, "O!:_pickler", &PyST_Type, &st)) { PyObject *newargs; PyObject *tuple; - if ((empty_dict = PyDict_New()) == NULL) - goto finally; - if ((newargs = Py_BuildValue("Oi", st, 1)) == NULL) - goto finally; - tuple = parser_st2tuple((PyST_Object*)NULL, newargs, empty_dict); + if ((newargs = PyTuple_Pack(2, st, Py_True)) == NULL) + return NULL; + tuple = parser_st2tuple((PyST_Object*)NULL, newargs, NULL); if (tuple != NULL) { result = Py_BuildValue("O(O)", pickle_constructor, tuple); Py_DECREF(tuple); } Py_DECREF(newargs); } - finally: - Py_XDECREF(empty_dict); return (result); } |