cpython: dbf72357cb4a (original) (raw)

Mercurial > cpython

changeset 105670:dbf72357cb4a

Issue #28959: Added private macro PyDict_GET_SIZE for retrieving the size of dict. [#28959]

Serhiy Storchaka storchaka@gmail.com
date Fri, 16 Dec 2016 16🔞57 +0200
parents 63792c2509a7
children 59eea8122df6 5fd772a20f25
files Include/dictobject.h Include/odictobject.h Modules/_ctypes/_ctypes.c Modules/_datetimemodule.c Modules/_decimal/_decimal.c Modules/_elementtree.c Modules/_functoolsmodule.c Modules/_operator.c Modules/_pickle.c Modules/_sqlite/cache.c Modules/_struct.c Modules/itertoolsmodule.c Modules/selectmodule.c Objects/abstract.c Objects/descrobject.c Objects/funcobject.c Objects/methodobject.c Objects/object.c Objects/odictobject.c Objects/setobject.c Objects/sliceobject.c Objects/typeobject.c Python/ceval.c Python/compile.c Python/getargs.c
diffstat 25 files changed, 61 insertions(+), 80 deletions(-)[+] [-] Include/dictobject.h 2 Include/odictobject.h 2 Modules/_ctypes/_ctypes.c 2 Modules/_datetimemodule.c 2 Modules/_decimal/_decimal.c 2 Modules/_elementtree.c 2 Modules/_functoolsmodule.c 10 Modules/_operator.c 13 Modules/_pickle.c 15 Modules/_sqlite/cache.c 2 Modules/_struct.c 2 Modules/itertoolsmodule.c 6 Modules/selectmodule.c 2 Objects/abstract.c 3 Objects/descrobject.c 2 Objects/funcobject.c 2 Objects/methodobject.c 9 Objects/object.c 4 Objects/odictobject.c 3 Objects/setobject.c 2 Objects/sliceobject.c 2 Objects/typeobject.c 16 Python/ceval.c 4 Python/compile.c 26 Python/getargs.c 6

line wrap: on

line diff

--- a/Include/dictobject.h +++ b/Include/dictobject.h @@ -106,6 +106,8 @@ PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObj PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp); PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject key); #ifndef Py_LIMITED_API +/ Get the number of items of a dictionary. */ +#define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),((PyDictObject *)mp)->ma_used) PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash); PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused); PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);

--- a/Include/odictobject.h +++ b/Include/odictobject.h @@ -21,7 +21,7 @@ PyAPI_DATA(PyTypeObject) PyODictValues_T #define PyODict_Check(op) PyObject_TypeCheck(op, &PyODict_Type) #define PyODict_CheckExact(op) (Py_TYPE(op) == &PyODict_Type) -#define PyODict_SIZE(op) ((PyDictObject *)op)->ma_used +#define PyODict_SIZE(op) PyDict_GET_SIZE((op)) #define PyODict_HasKey(od, key) (PyMapping_HasKey(PyObject *)od, key) PyAPI_FUNC(PyObject *) PyODict_New(void);

--- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -3684,7 +3684,7 @@ static PyObject * must be the same as len(inargs) + len(kwds), otherwise we have either too much or not enough arguments. */

--- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -3169,7 +3169,7 @@ tzinfo_reduce(PyObject *self) PyErr_Clear(); state = Py_None; dictptr = _PyObject_GetDictPtr(self);

--- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -428,7 +428,7 @@ dict_as_flags(PyObject *val) return DEC_INVALID_SIGNALS; }

--- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -150,7 +150,7 @@ list_join(PyObject* list) static int is_empty_dict(PyObject *obj) {

}

--- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -84,7 +84,7 @@ partial_new(PyTypeObject *type, PyObject } Py_DECREF(nargs);

@@ -155,7 +155,7 @@ partial_call(partialobject *pto, PyObjec assert(PyTuple_Check(argappl)); }

@@ -933,7 +933,7 @@ bounded_lru_cache_wrapper(lru_cache_obje } lru_cache_append_link(self, link); Py_INCREF(result); /* for return */

} static PyObject *

--- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -1016,16 +1016,7 @@ methodcaller_repr(methodcallerobject *mc return PyUnicode_FromFormat("%s(...)", Py_TYPE(mc)->tp_name); }

-

--- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -2787,10 +2787,10 @@ batch_dict_exact(PicklerObject *self, Py const char setitem_op = SETITEM; const char setitems_op = SETITEMS;

/* Special-case len(d) == 1 to save space. */ if (dict_size == 1) { @@ -2819,7 +2819,7 @@ batch_dict_exact(PicklerObject *self, Py } if (_Pickler_Write(self, &setitems_op, 1) < 0) return -1;

@@ -2837,6 +2837,7 @@ save_dict(PicklerObject *self, PyObject char header[3]; Py_ssize_t len; int status = 0;

if (self->fast && !fast_save_enter(self, obj)) goto error; @@ -2855,14 +2856,10 @@ save_dict(PicklerObject *self, PyObject if (_Pickler_Write(self, header, len) < 0) goto error;

- if (memo_put(self, obj) < 0) goto error;

@@ -6878,7 +6875,7 @@ Unpickler_set_memo(UnpicklerObject *self Py_ssize_t i = 0; PyObject *key, *value;

--- a/Modules/_sqlite/cache.c +++ b/Modules/_sqlite/cache.c @@ -162,7 +162,7 @@ PyObject* pysqlite_cache_get(pysqlite_Ca * entry in the cache, and make space if necessary by throwing the * least used item out of the cache. */

--- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -2048,7 +2048,7 @@ cache_struct(PyObject *fmt) s_object = PyObject_CallFunctionObjArgs((PyObject *)(&PyStructType), fmt, NULL); if (s_object != NULL) {

--- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -4180,7 +4180,7 @@ repeat_new(PyTypeObject *type, PyObject return NULL; if (kwds != NULL)

@@ -4331,9 +4331,9 @@ zip_longest_new(PyTypeObject *type, PyOb PyObject *fillvalue = Py_None; Py_ssize_t tuplesize = PySequence_Length(args);

--- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -353,7 +353,7 @@ update_ufd_array(pollObject *self) PyObject *key, *value; struct pollfd *old_ufds = self->ufds;

--- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2409,8 +2409,7 @@ PyObject ** assert(nargs >= 0); assert(kwargs == NULL || PyDict_CheckExact(kwargs));

--- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1173,7 +1173,7 @@ wrapper_call(wrapperobject *wp, PyObject return (*wk)(self, args, wp->descr->d_wrapped, kwds); }

--- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -583,7 +583,7 @@ function_call(PyObject *func, PyObject * if (kw != NULL && PyDict_Check(kw)) { Py_ssize_t pos, i;

--- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -87,6 +87,7 @@ PyCFunction_Call(PyObject *func, PyObjec Py_ssize_t size; int flags;

@@ -176,7 +177,7 @@ PyObject * switch (flags) { case METH_NOARGS:

@@ -193,7 +194,7 @@ PyObject * break; case METH_O:

@@ -215,7 +216,7 @@ PyObject / Slow-path: create a temporary tuple */ PyObject *tuple;

--- a/Objects/object.c +++ b/Objects/object.c @@ -1454,7 +1454,7 @@ none_dealloc(PyObject* ignore) static PyObject * none_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) {

--- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -2423,8 +2423,7 @@ mutablemapping_update(PyObject self, Py / now handle kwargs */ assert(kwargs == NULL || PyDict_Check(kwargs));

--- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -981,7 +981,7 @@ set_update_internal(PySetObject *so, PyO PyObject *value; Py_ssize_t pos = 0; Py_hash_t hash;

/* Do one big resize at the start, rather than * incrementally resizing as we insert new keys. Expect

--- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -19,7 +19,7 @@ this type and there is exactly one in ex static PyObject * ellipsis_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) {

--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -902,7 +902,7 @@ type_call(PyTypeObject *type, PyObject * if (type == &PyType_Type && PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 && (kwds == NULL ||

/* If the returned object is not an instance of type, @@ -1585,7 +1585,7 @@ set_mro_error(PyObject *to_merge, int *r } } }

off = PyOS_snprintf(buf, sizeof(buf), "Cannot create a [](#l22.19) consistent method resolution\norder (MRO) for bases"); @@ -2187,7 +2187,7 @@ type_init(PyObject *cls, PyObject *args, assert(kwds == NULL || PyDict_Check(kwds)); if (kwds != NULL && PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 &&

@@ -2272,7 +2272,7 @@ type_new(PyTypeObject *metatype, PyObjec Note: We don't call PyType_CheckExact as that also allows subclasses */ if (metatype == &PyType_Type) { const Py_ssize_t nargs = PyTuple_GET_SIZE(args);

if (nargs == 1 && nkwds == 0) { PyObject *x = PyTuple_GET_ITEM(args, 0); @@ -3416,7 +3416,7 @@ static int excess_args(PyObject *args, PyObject *kwds) { return PyTuple_GET_SIZE(args) ||

} static int @@ -3894,7 +3894,7 @@ static PyObject * We also return None if the dict is empty to make the behavior consistent regardless whether the dict was initialized or not. This make unit testing easier. */

@@ -3983,7 +3983,7 @@ static PyObject / If we found some slot attributes, pack them in a tuple along the original attribute dictionary. */

state2 = PyTuple_Pack(2, state, slots); @@ -4175,7 +4175,7 @@ reduce_newobj(PyObject *obj) return NULL; } hasargs = (args != NULL);

--- a/Python/ceval.c +++ b/Python/ceval.c @@ -5010,7 +5010,7 @@ PyObject * assert(kwargs == NULL || PyDict_Check(kwargs)); if (co->co_kwonlyargcount == 0 &&

@@ -5028,7 +5028,7 @@ PyObject * if (kwargs != NULL) { Py_ssize_t pos, i;

kwtuple = PyTuple_New(2 * nk); if (kwtuple == NULL) {

--- a/Python/compile.c +++ b/Python/compile.c @@ -564,7 +564,7 @@ compiler_enter_scope(struct compiler *c, PyObject *tuple, *name, *zero; int res; assert(u->u_scope_type == COMPILER_SCOPE_CLASS);

@@ -591,7 +591,7 @@ compiler_enter_scope(struct compiler *c, } u->u_freevars = dictbytype(u->u_ste->ste_symbols, FREE, DEF_FREE_CLASS,

@@ -1128,7 +1128,7 @@ compiler_add_o(struct compiler *c, PyObj Py_DECREF(t); return -1; }

@@ -1999,7 +1999,7 @@ compiler_class(struct compiler c, stmt_ } else { / No methods referenced class, so just return None */

@@ -5179,7 +5179,7 @@ static PyObject * dict_keys_inorder(PyObject *dict, Py_ssize_t offset) { PyObject *tuple, *k, *v;

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;

@@ -5223,16 +5222,9 @@ compute_code_flags(struct compiler c) / (Only) inherit compilerflags in PyCF_MASK */ flags |= (c->c_flags->cf_flags & PyCF_MASK);

--- a/Python/getargs.c +++ b/Python/getargs.c @@ -1650,7 +1650,7 @@ vgetargskeywords(PyObject *args, PyObjec } nargs = PyTuple_GET_SIZE(args);

@@ -2034,7 +2034,7 @@ vgetargskeywordsfast_impl(PyObject **arg } if (keywords != NULL) {

@@ -2421,7 +2421,7 @@ int PyErr_BadInternalCall(); return 0; }

PyErr_Format(PyExc_TypeError, "%s does not take keyword arguments",