diff -r 741ef17e9b86 Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c Sun Oct 18 09:54:42 2015 +0300 +++ b/Modules/_io/_iomodule.c Sun Oct 18 18:40:35 2015 +0300 @@ -351,7 +351,8 @@ static PyObject * /* Create the Raw file stream */ raw = PyObject_CallFunction((PyObject *)&PyFileIO_Type, - "OsiO", file, rawmode, closefd, opener); + "OsOO", file, rawmode, + closefd ? Py_True : Py_False, opener); if (raw == NULL) return NULL; result = raw; @@ -438,10 +439,10 @@ static PyObject * /* 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 -r 741ef17e9b86 Modules/_io/stringio.c --- a/Modules/_io/stringio.c Sun Oct 18 09:54:42 2015 +0300 +++ b/Modules/_io/stringio.c Sun Oct 18 18:40:35 2015 +0300 @@ -759,7 +759,7 @@ static int if (self->readuniversal) { self->decoder = PyObject_CallFunction( (PyObject *)&PyIncrementalNewlineDecoder_Type, - "Oi", Py_None, (int) self->readtranslate); + "OO", Py_None, self->readtranslate ? Py_True : Py_False); if (self->decoder == NULL) return -1; } diff -r 741ef17e9b86 Modules/_io/textio.c --- a/Modules/_io/textio.c Sun Oct 18 09:54:42 2015 +0300 +++ b/Modules/_io/textio.c Sun Oct 18 18:40:35 2015 +0300 @@ -992,7 +992,7 @@ static int if (self->readuniversal) { PyObject *incrementalDecoder = PyObject_CallFunction( (PyObject *)&PyIncrementalNewlineDecoder_Type, - "Oi", self->decoder, (int)self->readtranslate); + "OO", self->decoder, self->readtranslate ? Py_True : Py_False); if (incrementalDecoder == NULL) goto error; Py_CLEAR(self->decoder); diff -r 741ef17e9b86 Modules/_json.c --- a/Modules/_json.c Sun Oct 18 09:54:42 2015 +0300 +++ b/Modules/_json.c Sun Oct 18 18:40:35 2015 +0300 @@ -18,7 +18,7 @@ static PyTypeObject PyEncoderType; typedef struct _PyScannerObject { PyObject_HEAD - PyObject *strict; + char strict; PyObject *object_hook; PyObject *object_pairs_hook; PyObject *parse_float; @@ -28,7 +28,7 @@ typedef struct _PyScannerObject { } PyScannerObject; static PyMemberDef scanner_members[] = { - {"strict", T_OBJECT, offsetof(PyScannerObject, strict), READONLY, "strict"}, + {"strict", T_BOOL, offsetof(PyScannerObject, strict), READONLY, "strict"}, {"object_hook", T_OBJECT, offsetof(PyScannerObject, object_hook), READONLY, "object_hook"}, {"object_pairs_hook", T_OBJECT, offsetof(PyScannerObject, object_pairs_hook), READONLY}, {"parse_float", T_OBJECT, offsetof(PyScannerObject, parse_float), READONLY, "parse_float"}, @@ -45,8 +45,8 @@ typedef struct _PyEncoderObject { PyObject *indent; PyObject *key_separator; PyObject *item_separator; - PyObject *sort_keys; - PyObject *skipkeys; + char sort_keys; + char skipkeys; PyCFunction fast_encode; int allow_nan; } PyEncoderObject; @@ -58,8 +58,8 @@ static PyMemberDef encoder_members[] = { {"indent", T_OBJECT, offsetof(PyEncoderObject, indent), READONLY, "indent"}, {"key_separator", T_OBJECT, offsetof(PyEncoderObject, key_separator), READONLY, "key_separator"}, {"item_separator", T_OBJECT, offsetof(PyEncoderObject, item_separator), READONLY, "item_separator"}, - {"sort_keys", T_OBJECT, offsetof(PyEncoderObject, sort_keys), READONLY, "sort_keys"}, - {"skipkeys", T_OBJECT, offsetof(PyEncoderObject, skipkeys), READONLY, "skipkeys"}, + {"sort_keys", T_BOOL, offsetof(PyEncoderObject, sort_keys), READONLY, "sort_keys"}, + {"skipkeys", T_BOOL, offsetof(PyEncoderObject, skipkeys), READONLY, "skipkeys"}, {NULL} }; @@ -672,7 +672,6 @@ scanner_traverse(PyObject *self, visitpr PyScannerObject *s; assert(PyScanner_Check(self)); s = (PyScannerObject *)self; - Py_VISIT(s->strict); Py_VISIT(s->object_hook); Py_VISIT(s->object_pairs_hook); Py_VISIT(s->parse_float); @@ -687,7 +686,6 @@ scanner_clear(PyObject *self) PyScannerObject *s; assert(PyScanner_Check(self)); s = (PyScannerObject *)self; - Py_CLEAR(s->strict); Py_CLEAR(s->object_hook); Py_CLEAR(s->object_pairs_hook); Py_CLEAR(s->parse_float); @@ -712,13 +710,9 @@ static PyObject * PyObject *val = NULL; PyObject *rval = NULL; PyObject *key = NULL; - int strict = PyObject_IsTrue(s->strict); int has_pairs_hook = (s->object_pairs_hook != Py_None); Py_ssize_t next_idx; - if (strict < 0) - return NULL; - if (PyUnicode_READY(pystr) == -1) return NULL; @@ -746,7 +740,7 @@ static PyObject * raise_errmsg("Expecting property name enclosed in double quotes", pystr, idx); goto bail; } - key = scanstring_unicode(pystr, idx + 1, strict, &next_idx); + key = scanstring_unicode(pystr, idx + 1, s->strict, &next_idx); if (key == NULL) goto bail; memokey = PyDict_GetItem(s->memo, key); @@ -1064,7 +1058,6 @@ scan_once_unicode(PyScannerObject *s, Py void *str; int kind; Py_ssize_t length; - int strict; if (PyUnicode_READY(pystr) == -1) return NULL; @@ -1085,10 +1078,7 @@ scan_once_unicode(PyScannerObject *s, Py switch (PyUnicode_READ(kind, str, idx)) { case '"': /* string */ - strict = PyObject_IsTrue(s->strict); - if (strict < 0) - return NULL; - return scanstring_unicode(pystr, idx + 1, strict, next_idx_ptr); + return scanstring_unicode(pystr, idx + 1, s->strict, next_idx_ptr); case '{': /* object */ if (Py_EnterRecursiveCall(" while decoding a JSON object " @@ -1205,7 +1195,6 @@ scanner_new(PyTypeObject *type, PyObject PyScannerObject *s; s = (PyScannerObject *)type->tp_alloc(type, 0); if (s != NULL) { - s->strict = NULL; s->object_hook = NULL; s->object_pairs_hook = NULL; s->parse_float = NULL; @@ -1220,6 +1209,7 @@ scanner_init(PyObject *self, PyObject *a { /* Initialize Scanner object */ PyObject *ctx; + PyObject *strict; static char *kwlist[] = {"context", NULL}; PyScannerObject *s; @@ -1235,10 +1225,14 @@ scanner_init(PyObject *self, PyObject *a goto bail; } + strict = PyObject_GetAttrString(ctx, "strict"); + if (strict == NULL) + goto bail; + s->strict = PyObject_IsTrue(strict); + Py_DECREF(strict); + if (s->strict < 0) + goto bail; /* All of these will fail "gracefully" so we don't need to verify them */ - s->strict = PyObject_GetAttrString(ctx, "strict"); - if (s->strict == NULL) - goto bail; s->object_hook = PyObject_GetAttrString(ctx, "object_hook"); if (s->object_hook == NULL) goto bail; @@ -1258,7 +1252,6 @@ scanner_init(PyObject *self, PyObject *a return 0; bail: - Py_CLEAR(s->strict); Py_CLEAR(s->object_hook); Py_CLEAR(s->object_pairs_hook); Py_CLEAR(s->parse_float); @@ -1324,8 +1317,6 @@ encoder_new(PyTypeObject *type, PyObject s->indent = NULL; s->key_separator = NULL; s->item_separator = NULL; - s->sort_keys = NULL; - s->skipkeys = NULL; } return (PyObject *)s; } @@ -1338,13 +1329,13 @@ encoder_init(PyObject *self, PyObject *a PyEncoderObject *s; PyObject *markers, *defaultfn, *encoder, *indent, *key_separator; - PyObject *item_separator, *sort_keys, *skipkeys; - int allow_nan; + PyObject *item_separator; + int sort_keys, skipkeys, allow_nan; assert(PyEncoder_Check(self)); s = (PyEncoderObject *)self; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOUUOOp:make_encoder", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOUUppp:make_encoder", kwlist, &markers, &defaultfn, &encoder, &indent, &key_separator, &item_separator, &sort_keys, &skipkeys, &allow_nan)) @@ -1381,8 +1372,6 @@ encoder_init(PyObject *self, PyObject *a Py_INCREF(s->indent); Py_INCREF(s->key_separator); Py_INCREF(s->item_separator); - Py_INCREF(s->sort_keys); - Py_INCREF(s->skipkeys); return 0; } @@ -1641,8 +1630,6 @@ encoder_listencode_dict(PyEncoderObject PyObject *it = NULL; PyObject *items; PyObject *item = NULL; - int skipkeys; - int sortkeys; Py_ssize_t idx; if (open_dict == NULL || close_dict == NULL || empty_dict == NULL) { @@ -1687,16 +1674,12 @@ encoder_listencode_dict(PyEncoderObject items = PyMapping_Items(dct); if (items == NULL) goto bail; - sortkeys = PyObject_IsTrue(s->sort_keys); - if (sortkeys < 0 || (sortkeys && PyList_Sort(items) < 0)) + if (s->sort_keys && PyList_Sort(items) < 0) goto bail; it = PyObject_GetIter(items); Py_DECREF(items); if (it == NULL) goto bail; - skipkeys = PyObject_IsTrue(s->skipkeys); - if (skipkeys < 0) - goto bail; idx = 0; while ((item = PyIter_Next(it)) != NULL) { PyObject *encoded, *key, *value; @@ -1727,7 +1710,7 @@ encoder_listencode_dict(PyEncoderObject goto bail; } } - else if (skipkeys) { + else if (s->skipkeys) { Py_DECREF(item); continue; } @@ -1895,8 +1878,6 @@ encoder_traverse(PyObject *self, visitpr Py_VISIT(s->indent); Py_VISIT(s->key_separator); Py_VISIT(s->item_separator); - Py_VISIT(s->sort_keys); - Py_VISIT(s->skipkeys); return 0; } @@ -1913,8 +1894,6 @@ encoder_clear(PyObject *self) Py_CLEAR(s->indent); Py_CLEAR(s->key_separator); Py_CLEAR(s->item_separator); - Py_CLEAR(s->sort_keys); - Py_CLEAR(s->skipkeys); return 0; } diff -r 741ef17e9b86 Modules/_tkinter.c --- a/Modules/_tkinter.c Sun Oct 18 09:54:42 2015 +0300 +++ b/Modules/_tkinter.c Sun Oct 18 18:40:35 2015 +0300 @@ -3060,7 +3060,7 @@ Tkapp_WantObjects(PyObject *self, PyObje { int wantobjects = -1; - if (!PyArg_ParseTuple(args, "|i:wantobjects", &wantobjects)) + if (!PyArg_ParseTuple(args, "|p:wantobjects", &wantobjects)) return NULL; if (wantobjects == -1) return PyBool_FromLong(((TkappObject*)self)->wantobjects); @@ -3207,11 +3207,11 @@ static PyObject * screenName: str(accept={str, NoneType}) = NULL baseName: str = NULL className: str = "Tk" - interactive: int(c_default="0") = False - wantobjects: int(c_default="0") = False - wantTk: int(c_default="1") = True + interactive: bool = False + wantobjects: bool = False + wantTk: bool = True if false, then Tk_Init() doesn't get called - sync: int(c_default="0") = False + sync: bool = False if true, then pass -sync to wish use: str(accept={str, NoneType}) = NULL if not None, then pass -use to wish diff -r 741ef17e9b86 Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c Sun Oct 18 09:54:42 2015 +0300 +++ b/Modules/itertoolsmodule.c Sun Oct 18 18:40:35 2015 +0300 @@ -974,10 +974,10 @@ cycle_reduce(cycleobject *lz) } 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 -r 741ef17e9b86 Modules/main.c --- a/Modules/main.c Sun Oct 18 09:54:42 2015 +0300 +++ b/Modules/main.c Sun Oct 18 18:40:35 2015 +0300 @@ -195,7 +195,7 @@ static int RunModule(wchar_t *modname, i Py_DECREF(runmodule); return -1; } - runargs = Py_BuildValue("(Oi)", module, set_argv0); + runargs = Py_BuildValue("(OO)", module, set_argv0 ? Py_True : Py_False); if (runargs == NULL) { fprintf(stderr, "Could not create arguments for runpy._run_module_as_main\n"); diff -r 741ef17e9b86 Objects/fileobject.c --- a/Objects/fileobject.c Sun Oct 18 09:54:42 2015 +0300 +++ b/Objects/fileobject.c Sun Oct 18 18:40:35 2015 +0300 @@ -35,9 +35,9 @@ PyFile_FromFd(int fd, const char *name, io = PyImport_ImportModule("io"); if (io == NULL) return NULL; - stream = _PyObject_CallMethodId(io, &PyId_open, "isisssi", fd, mode, + stream = _PyObject_CallMethodId(io, &PyId_open, "isisssO", fd, mode, buffering, encoding, errors, - newline, closefd); + newline, closefd ? Py_True : Py_False); Py_DECREF(io); if (stream == NULL) return NULL; diff -r 741ef17e9b86 Objects/longobject.c --- a/Objects/longobject.c Sun Oct 18 09:54:42 2015 +0300 +++ b/Objects/longobject.c Sun Oct 18 18:40:35 2015 +0300 @@ -4981,16 +4981,15 @@ static PyObject * long_to_bytes(PyLongObject *v, PyObject *args, PyObject *kwds) { PyObject *byteorder_str; - PyObject *is_signed_obj = NULL; Py_ssize_t length; int little_endian; - int is_signed; + int is_signed = 0; PyObject *bytes; static char *kwlist[] = {"length", "byteorder", "signed", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "nU|O:to_bytes", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "nU|p:to_bytes", kwlist, &length, &byteorder_str, - &is_signed_obj)) + &is_signed)) return NULL; if (args != NULL && Py_SIZE(args) > 2) { @@ -5009,18 +5008,6 @@ long_to_bytes(PyLongObject *v, PyObject return NULL; } - if (is_signed_obj != NULL) { - int cmp = PyObject_IsTrue(is_signed_obj); - if (cmp < 0) - return NULL; - is_signed = cmp ? 1 : 0; - } - else { - /* If the signed argument was omitted, use False as the - default. */ - is_signed = 0; - } - if (length < 0) { PyErr_SetString(PyExc_ValueError, "length argument must be non-negative"); @@ -5063,17 +5050,16 @@ static PyObject * long_from_bytes(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *byteorder_str; - PyObject *is_signed_obj = NULL; int little_endian; - int is_signed; + int is_signed = 0; PyObject *obj; PyObject *bytes; PyObject *long_obj; static char *kwlist[] = {"bytes", "byteorder", "signed", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "OU|O:from_bytes", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "OU|p:from_bytes", kwlist, &obj, &byteorder_str, - &is_signed_obj)) + &is_signed)) return NULL; if (args != NULL && Py_SIZE(args) > 2) { @@ -5092,18 +5078,6 @@ long_from_bytes(PyTypeObject *type, PyOb return NULL; } - if (is_signed_obj != NULL) { - int cmp = PyObject_IsTrue(is_signed_obj); - if (cmp < 0) - return NULL; - is_signed = cmp ? 1 : 0; - } - else { - /* If the signed argument was omitted, use False as the - default. */ - is_signed = 0; - } - bytes = PyObject_Bytes(obj); if (bytes == NULL) return NULL; diff -r 741ef17e9b86 Python/bltinmodule.c --- a/Python/bltinmodule.c Sun Oct 18 09:54:42 2015 +0300 +++ b/Python/bltinmodule.c Sun Oct 18 18:40:35 2015 +0300 @@ -1697,12 +1697,13 @@ builtin_print(PyObject *self, PyObject * { static char *kwlist[] = {"sep", "end", "file", "flush", 0}; static PyObject *dummy_args; - PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL; + PyObject *sep = NULL, *end = NULL, *file = NULL; + int flush = 0; int i, err; if (dummy_args == NULL && !(dummy_args = PyTuple_New(0))) return NULL; - if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOOO:print", + if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOOp:print", kwlist, &sep, &end, &file, &flush)) return NULL; if (file == NULL || file == Py_None) { @@ -1759,18 +1760,12 @@ builtin_print(PyObject *self, 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_CallMethodId(file, &PyId_flush, ""); + if (tmp == NULL) return NULL; - else if (do_flush) { - tmp = _PyObject_CallMethodId(file, &PyId_flush, ""); - if (tmp == NULL) - return NULL; - else - Py_DECREF(tmp); - } + else + Py_DECREF(tmp); } Py_RETURN_NONE; diff -r 741ef17e9b86 Python/pylifecycle.c --- a/Python/pylifecycle.c Sun Oct 18 09:54:42 2015 +0300 +++ b/Python/pylifecycle.c Sun Oct 18 18:40:35 2015 +0300 @@ -1014,9 +1014,9 @@ create_stdio(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, Py_None, 0); + Py_None, Py_None, Py_None, Py_False); if (buf == NULL) goto error;