diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-16 16:18:57 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-16 16:18:57 +0200 |
commit | 5ab81d787f455ba28367b5b71606cea376283574 (patch) | |
tree | e78623a175940cb3d25d950812d0079021b178b7 /Python | |
parent | 1d59a0aacf1ddd000b6c6e231cf82ddf74afe3b4 (diff) | |
download | cpython-git-5ab81d787f455ba28367b5b71606cea376283574.tar.gz |
Issue #28959: Added private macro PyDict_GET_SIZE for retrieving the size of dict.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 4 | ||||
-rw-r--r-- | Python/compile.c | 26 | ||||
-rw-r--r-- | Python/getargs.c | 6 |
3 files changed, 14 insertions, 22 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 0f1f36e80d..fc11117109 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5010,7 +5010,7 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, assert(kwargs == NULL || PyDict_Check(kwargs)); if (co->co_kwonlyargcount == 0 && - (kwargs == NULL || PyDict_Size(kwargs) == 0) && + (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) && co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { /* Fast paths */ @@ -5028,7 +5028,7 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, if (kwargs != NULL) { Py_ssize_t pos, i; - nk = PyDict_Size(kwargs); + nk = PyDict_GET_SIZE(kwargs); kwtuple = PyTuple_New(2 * nk); if (kwtuple == NULL) { diff --git a/Python/compile.c b/Python/compile.c index 25179faa3e..17fef31482 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -564,7 +564,7 @@ compiler_enter_scope(struct compiler *c, identifier name, PyObject *tuple, *name, *zero; int res; assert(u->u_scope_type == COMPILER_SCOPE_CLASS); - assert(PyDict_Size(u->u_cellvars) == 0); + assert(PyDict_GET_SIZE(u->u_cellvars) == 0); name = _PyUnicode_FromId(&PyId___class__); if (!name) { compiler_unit_free(u); @@ -591,7 +591,7 @@ compiler_enter_scope(struct compiler *c, identifier name, } u->u_freevars = dictbytype(u->u_ste->ste_symbols, FREE, DEF_FREE_CLASS, - PyDict_Size(u->u_cellvars)); + PyDict_GET_SIZE(u->u_cellvars)); if (!u->u_freevars) { compiler_unit_free(u); return 0; @@ -1128,7 +1128,7 @@ compiler_add_o(struct compiler *c, PyObject *dict, PyObject *o) Py_DECREF(t); return -1; } - arg = PyDict_Size(dict); + arg = PyDict_GET_SIZE(dict); v = PyLong_FromSsize_t(arg); if (!v) { Py_DECREF(t); @@ -1999,7 +1999,7 @@ compiler_class(struct compiler *c, stmt_ty s) } else { /* No methods referenced __class__, so just return None */ - assert(PyDict_Size(c->u->u_cellvars) == 0); + assert(PyDict_GET_SIZE(c->u->u_cellvars) == 0); ADDOP_O(c, LOAD_CONST, Py_None, consts); } ADDOP_IN_SCOPE(c, RETURN_VALUE); @@ -5179,7 +5179,7 @@ static PyObject * dict_keys_inorder(PyObject *dict, Py_ssize_t offset) { PyObject *tuple, *k, *v; - Py_ssize_t i, pos = 0, size = PyDict_Size(dict); + Py_ssize_t i, pos = 0, size = PyDict_GET_SIZE(dict); tuple = PyTuple_New(size); if (tuple == NULL) @@ -5203,7 +5203,6 @@ compute_code_flags(struct compiler *c) { PySTEntryObject *ste = c->u->u_ste; int flags = 0; - Py_ssize_t n; if (ste->ste_type == FunctionBlock) { flags |= CO_NEWLOCALS | CO_OPTIMIZED; if (ste->ste_nested) @@ -5223,16 +5222,9 @@ compute_code_flags(struct compiler *c) /* (Only) inherit compilerflags in PyCF_MASK */ flags |= (c->c_flags->cf_flags & PyCF_MASK); - n = PyDict_Size(c->u->u_freevars); - if (n < 0) - return -1; - if (n == 0) { - n = PyDict_Size(c->u->u_cellvars); - if (n < 0) - return -1; - if (n == 0) { - flags |= CO_NOFREE; - } + if (!PyDict_GET_SIZE(c->u->u_freevars) && + !PyDict_GET_SIZE(c->u->u_cellvars)) { + flags |= CO_NOFREE; } return flags; @@ -5273,7 +5265,7 @@ makecode(struct compiler *c, struct assembler *a) if (!freevars) goto error; - nlocals = PyDict_Size(c->u->u_varnames); + nlocals = PyDict_GET_SIZE(c->u->u_varnames); assert(nlocals < INT_MAX); nlocals_int = Py_SAFE_DOWNCAST(nlocals, Py_ssize_t, int); diff --git a/Python/getargs.c b/Python/getargs.c index c552d0fe27..49888d11b6 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1650,7 +1650,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format, } nargs = PyTuple_GET_SIZE(args); - nkeywords = (keywords == NULL) ? 0 : PyDict_Size(keywords); + nkeywords = (keywords == NULL) ? 0 : PyDict_GET_SIZE(keywords); if (nargs + nkeywords > len) { PyErr_Format(PyExc_TypeError, "%s%s takes at most %d argument%s (%zd given)", @@ -2034,7 +2034,7 @@ vgetargskeywordsfast_impl(PyObject **args, Py_ssize_t nargs, } if (keywords != NULL) { - nkeywords = PyDict_Size(keywords); + nkeywords = PyDict_GET_SIZE(keywords); } else if (kwnames != NULL) { nkeywords = PyTuple_GET_SIZE(kwnames); @@ -2421,7 +2421,7 @@ _PyArg_NoKeywords(const char *funcname, PyObject *kw) PyErr_BadInternalCall(); return 0; } - if (PyDict_Size(kw) == 0) + if (PyDict_GET_SIZE(kw) == 0) return 1; PyErr_Format(PyExc_TypeError, "%s does not take keyword arguments", |