summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-12-16 14:18:57 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-12-16 14:18:57 (GMT)
commit5ab81d787f455ba28367b5b71606cea376283574 (patch)
treee78623a175940cb3d25d950812d0079021b178b7 /Modules
parent1d59a0aacf1ddd000b6c6e231cf82ddf74afe3b4 (diff)
downloadcpython-5ab81d787f455ba28367b5b71606cea376283574.zip
cpython-5ab81d787f455ba28367b5b71606cea376283574.tar.gz
cpython-5ab81d787f455ba28367b5b71606cea376283574.tar.bz2
Issue #28959: Added private macro PyDict_GET_SIZE for retrieving the size of dict.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c2
-rw-r--r--Modules/_datetimemodule.c2
-rw-r--r--Modules/_decimal/_decimal.c2
-rw-r--r--Modules/_elementtree.c2
-rw-r--r--Modules/_functoolsmodule.c10
-rw-r--r--Modules/_operator.c13
-rw-r--r--Modules/_pickle.c15
-rw-r--r--Modules/_sqlite/cache.c2
-rw-r--r--Modules/_struct.c2
-rw-r--r--Modules/itertoolsmodule.c6
-rw-r--r--Modules/selectmodule.c2
11 files changed, 23 insertions, 35 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 47d8f56..4908dde 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -3684,7 +3684,7 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes,
must be the same as len(inargs) + len(kwds), otherwise we have
either too much or not enough arguments. */
- actual_args = PyTuple_GET_SIZE(inargs) + (kwds ? PyDict_Size(kwds) : 0);
+ actual_args = PyTuple_GET_SIZE(inargs) + (kwds ? PyDict_GET_SIZE(kwds) : 0);
if (actual_args != inargs_index) {
/* When we have default values or named parameters, this error
message is misleading. See unittests/test_paramflags.py
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 254e595..d11f4a9 100644
--- 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);
- if (dictptr && *dictptr && PyDict_Size(*dictptr)) {
+ if (dictptr && *dictptr && PyDict_GET_SIZE(*dictptr)) {
state = *dictptr;
}
Py_INCREF(state);
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index 9e8625d..feaef2e 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -428,7 +428,7 @@ dict_as_flags(PyObject *val)
return DEC_INVALID_SIGNALS;
}
- if (PyDict_Size(val) != SIGNAL_MAP_LEN) {
+ if (PyDict_GET_SIZE(val) != SIGNAL_MAP_LEN) {
PyErr_SetString(PyExc_KeyError,
"invalid signal dict");
return DEC_INVALID_SIGNALS;
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index ba827e6..9e6f63b 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -150,7 +150,7 @@ list_join(PyObject* list)
static int
is_empty_dict(PyObject *obj)
{
- return PyDict_CheckExact(obj) && PyDict_Size(obj) == 0;
+ return PyDict_CheckExact(obj) && PyDict_GET_SIZE(obj) == 0;
}
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 19ca65b..6b5c008 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -84,7 +84,7 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
}
Py_DECREF(nargs);
- if (pkw == NULL || PyDict_Size(pkw) == 0) {
+ if (pkw == NULL || PyDict_GET_SIZE(pkw) == 0) {
if (kw == NULL) {
pto->kw = PyDict_New();
}
@@ -155,7 +155,7 @@ partial_call(partialobject *pto, PyObject *args, PyObject *kw)
assert(PyTuple_Check(argappl));
}
- if (PyDict_Size(pto->kw) == 0) {
+ if (PyDict_GET_SIZE(pto->kw) == 0) {
kwappl = kw;
Py_XINCREF(kwappl);
}
@@ -713,7 +713,7 @@ lru_cache_make_key(PyObject *args, PyObject *kwds, int typed)
return args;
}
- if (kwds && PyDict_Size(kwds) > 0) {
+ if (kwds && PyDict_GET_SIZE(kwds) > 0) {
sorted_items = PyDict_Items(kwds);
if (!sorted_items)
return NULL;
@@ -933,7 +933,7 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
}
lru_cache_append_link(self, link);
Py_INCREF(result); /* for return */
- self->full = (PyDict_Size(self->cache) >= self->maxsize);
+ self->full = (PyDict_GET_SIZE(self->cache) >= self->maxsize);
}
self->misses++;
return result;
@@ -1062,7 +1062,7 @@ lru_cache_cache_info(lru_cache_object *self, PyObject *unused)
{
return PyObject_CallFunction(self->cache_info_type, "nnOn",
self->hits, self->misses, self->maxsize_O,
- PyDict_Size(self->cache));
+ PyDict_GET_SIZE(self->cache));
}
static PyObject *
diff --git a/Modules/_operator.c b/Modules/_operator.c
index fb8eafc..f5b8612 100644
--- 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);
}
- if (mc->kwds != NULL) {
- numkwdargs = PyDict_Size(mc->kwds);
- if (numkwdargs < 0) {
- Py_ReprLeave((PyObject *)mc);
- return NULL;
- }
- } else {
- numkwdargs = 0;
- }
-
+ numkwdargs = mc->kwds != NULL ? PyDict_GET_SIZE(mc->kwds) : 0;
numposargs = PyTuple_GET_SIZE(mc->args);
numtotalargs = numposargs + numkwdargs;
@@ -1092,7 +1083,7 @@ static PyObject *
methodcaller_reduce(methodcallerobject *mc)
{
PyObject *newargs;
- if (!mc->kwds || PyDict_Size(mc->kwds) == 0) {
+ if (!mc->kwds || PyDict_GET_SIZE(mc->kwds) == 0) {
Py_ssize_t i;
Py_ssize_t callargcount = PyTuple_GET_SIZE(mc->args);
newargs = PyTuple_New(1 + callargcount);
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 947069a..b1e1d49 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -2787,10 +2787,10 @@ batch_dict_exact(PicklerObject *self, PyObject *obj)
const char setitem_op = SETITEM;
const char setitems_op = SETITEMS;
- assert(obj != NULL);
+ assert(obj != NULL && PyDict_CheckExact(obj));
assert(self->proto > 0);
- dict_size = PyDict_Size(obj);
+ dict_size = PyDict_GET_SIZE(obj);
/* Special-case len(d) == 1 to save space. */
if (dict_size == 1) {
@@ -2819,7 +2819,7 @@ batch_dict_exact(PicklerObject *self, PyObject *obj)
}
if (_Pickler_Write(self, &setitems_op, 1) < 0)
return -1;
- if (PyDict_Size(obj) != dict_size) {
+ if (PyDict_GET_SIZE(obj) != dict_size) {
PyErr_Format(
PyExc_RuntimeError,
"dictionary changed size during iteration");
@@ -2837,6 +2837,7 @@ save_dict(PicklerObject *self, PyObject *obj)
char header[3];
Py_ssize_t len;
int status = 0;
+ assert(PyDict_Check(obj));
if (self->fast && !fast_save_enter(self, obj))
goto error;
@@ -2855,14 +2856,10 @@ save_dict(PicklerObject *self, PyObject *obj)
if (_Pickler_Write(self, header, len) < 0)
goto error;
- /* Get dict size, and bow out early if empty. */
- if ((len = PyDict_Size(obj)) < 0)
- goto error;
-
if (memo_put(self, obj) < 0)
goto error;
- if (len != 0) {
+ if (PyDict_GET_SIZE(obj)) {
/* Save the dict items. */
if (PyDict_CheckExact(obj) && self->proto > 0) {
/* We can take certain shortcuts if we know this is a dict and
@@ -6878,7 +6875,7 @@ Unpickler_set_memo(UnpicklerObject *self, PyObject *obj)
Py_ssize_t i = 0;
PyObject *key, *value;
- new_memo_size = PyDict_Size(obj);
+ new_memo_size = PyDict_GET_SIZE(obj);
new_memo = _Unpickler_NewMemo(new_memo_size);
if (new_memo == NULL)
return -1;
diff --git a/Modules/_sqlite/cache.c b/Modules/_sqlite/cache.c
index 62c5893..72b1f2c 100644
--- a/Modules/_sqlite/cache.c
+++ b/Modules/_sqlite/cache.c
@@ -162,7 +162,7 @@ PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args)
* entry in the cache, and make space if necessary by throwing the
* least used item out of the cache. */
- if (PyDict_Size(self->mapping) == self->size) {
+ if (PyDict_GET_SIZE(self->mapping) == self->size) {
if (self->last) {
node = self->last;
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 1d7a935..d621789 100644
--- 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) {
- if (PyDict_Size(cache) >= MAXCACHE)
+ if (PyDict_GET_SIZE(cache) >= MAXCACHE)
PyDict_Clear(cache);
/* Attempt to cache the result */
if (PyDict_SetItem(cache, fmt, s_object) == -1)
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 6bf04cb..7cbee2b 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -4180,7 +4180,7 @@ repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
if (kwds != NULL)
- n_kwds = PyDict_Size(kwds);
+ n_kwds = PyDict_GET_SIZE(kwds);
/* Does user supply times argument? */
if ((PyTuple_Size(args) + n_kwds == 2) && cnt < 0)
cnt = 0;
@@ -4331,9 +4331,9 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *fillvalue = Py_None;
Py_ssize_t tuplesize = PySequence_Length(args);
- if (kwds != NULL && PyDict_CheckExact(kwds) && PyDict_Size(kwds) > 0) {
+ if (kwds != NULL && PyDict_CheckExact(kwds) && PyDict_GET_SIZE(kwds) > 0) {
fillvalue = PyDict_GetItemString(kwds, "fillvalue");
- if (fillvalue == NULL || PyDict_Size(kwds) > 1) {
+ if (fillvalue == NULL || PyDict_GET_SIZE(kwds) > 1) {
PyErr_SetString(PyExc_TypeError,
"zip_longest() got an unexpected keyword argument");
return NULL;
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 79cf199..0206651 100644
--- 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;
- self->ufd_len = PyDict_Size(self->dict);
+ self->ufd_len = PyDict_GET_SIZE(self->dict);
PyMem_RESIZE(self->ufds, struct pollfd, self->ufd_len);
if (self->ufds == NULL) {
self->ufds = old_ufds;