mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
Issue #28959: Added private macro PyDict_GET_SIZE for retrieving the size of dict.
This commit is contained in:
parent
1d59a0aacf
commit
5ab81d787f
25 changed files with 61 additions and 80 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue