diff -r dbf72357cb4a Include/dictobject.h --- a/Include/dictobject.h Fri Dec 16 16:18:57 2016 +0200 +++ b/Include/dictobject.h Fri Dec 16 16:46:38 2016 +0200 @@ -21,10 +21,7 @@ typedef struct _dictkeysobject PyDictKey * or points to an array of PyObject* for a split table */ typedef struct { - PyObject_HEAD - - /* Number of items in the dictionary */ - Py_ssize_t ma_used; + PyObject_VAR_HEAD /* Dictionary version: globally unique, value change each time the dictionary is modified */ @@ -107,7 +104,7 @@ PyAPI_FUNC(PyObject *) PyDict_Copy(PyObj 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) +#define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),Py_SIZE(mp)) 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); diff -r dbf72357cb4a Include/setobject.h --- a/Include/setobject.h Fri Dec 16 16:18:57 2016 +0200 +++ b/Include/setobject.h Fri Dec 16 16:46:38 2016 +0200 @@ -40,10 +40,9 @@ Invariants for frozensets: */ typedef struct { - PyObject_HEAD + PyObject_VAR_HEAD Py_ssize_t fill; /* Number active and dummy entries*/ - Py_ssize_t used; /* Number active entries */ /* The table contains mask + 1 slots, and that's a power of 2. * We store the mask instead of the size because the mask is more @@ -64,7 +63,7 @@ typedef struct { PyObject *weakreflist; /* List of weak references */ } PySetObject; -#define PySet_GET_SIZE(so) (((PySetObject *)(so))->used) +#define PySet_GET_SIZE(so) (assert(PyAnySet_Check(so)),Py_SIZE(so)) PyAPI_DATA(PyObject *) _PySet_Dummy; diff -r dbf72357cb4a Objects/dictobject.c --- a/Objects/dictobject.c Fri Dec 16 16:18:57 2016 +0200 +++ b/Objects/dictobject.c Fri Dec 16 16:46:38 2016 +0200 @@ -97,7 +97,7 @@ dk_indices, we can't increment dk_usable decremented. In split table, inserting into pending entry is allowed only for dk_entries[ix] -where ix == mp->ma_used. Inserting into other index and deleting item cause +where ix == PyDict_GET_SIZE(mp). Inserting into other index and deleting item cause converting the dict to the combined table. */ @@ -409,7 +409,7 @@ dk_set_index(PyDictKeysObject *keys, Py_ * GROWTH_RATE was set to used*4 up to version 3.2. * GROWTH_RATE was set to used*2 in version 3.3.0 */ -#define GROWTH_RATE(d) (((d)->ma_used*2)+((d)->ma_keys->dk_size>>1)) +#define GROWTH_RATE(d) (PyDict_GET_SIZE(d)*2+((d)->ma_keys->dk_size>>1)) #define ENSURE_ALLOWS_DELETIONS(d) \ if ((d)->ma_keys->dk_lookup == lookdict_unicode_nodummy) { \ @@ -449,7 +449,7 @@ static int Py_ssize_t i; #endif - assert(0 <= mp->ma_used && mp->ma_used <= usable); + assert(0 <= PyDict_GET_SIZE(mp) && PyDict_GET_SIZE(mp) <= usable); assert(IS_POWER_OF_2(keys->dk_size)); assert(0 <= keys->dk_usable && keys->dk_usable <= usable); @@ -494,7 +494,7 @@ static int if (splitted) { /* splitted table */ - for (i=0; i < mp->ma_used; i++) { + for (i=0; i < PyDict_GET_SIZE(mp); i++) { assert(mp->ma_values[i] != NULL); } } @@ -593,7 +593,7 @@ new_dict(PyDictKeysObject *keys, PyObjec } mp->ma_keys = keys; mp->ma_values = values; - mp->ma_used = 0; + Py_SIZE(mp) = 0; mp->ma_version_tag = DICT_NEXT_VERSION(); assert(_PyDict_CheckConsistency(mp)); return (PyObject *)mp; @@ -1124,8 +1124,8 @@ insertdict(PyDictObject *mp, PyObject *k * the key anymore. Convert this instance to combine table. */ if (_PyDict_HasSplitTable(mp) && - ((ix >= 0 && old_value == NULL && mp->ma_used != ix) || - (ix == DKIX_EMPTY && mp->ma_used != mp->ma_keys->dk_nentries))) { + ((ix >= 0 && old_value == NULL && PyDict_GET_SIZE(mp) != ix) || + (ix == DKIX_EMPTY && PyDict_GET_SIZE(mp) != mp->ma_keys->dk_nentries))) { if (insertion_resize(mp) < 0) { Py_DECREF(value); return -1; @@ -1157,7 +1157,7 @@ insertdict(PyDictObject *mp, PyObject *k else { ep->me_value = value; } - mp->ma_used++; + Py_SIZE(mp)++; mp->ma_version_tag = DICT_NEXT_VERSION(); mp->ma_keys->dk_usable--; mp->ma_keys->dk_nentries++; @@ -1170,8 +1170,8 @@ insertdict(PyDictObject *mp, PyObject *k mp->ma_values[ix] = value; if (old_value == NULL) { /* pending state */ - assert(ix == mp->ma_used); - mp->ma_used++; + assert(ix == PyDict_GET_SIZE(mp)); + Py_SIZE(mp)++; } } else { @@ -1245,11 +1245,11 @@ dictresize(PyDictObject *mp, Py_ssize_t return -1; } // New table must be large enough. - assert(mp->ma_keys->dk_usable >= mp->ma_used); + assert(mp->ma_keys->dk_usable >= PyDict_GET_SIZE(mp)); if (oldkeys->dk_lookup == lookdict) mp->ma_keys->dk_lookup = lookdict; - numentries = mp->ma_used; + numentries = PyDict_GET_SIZE(mp); oldentries = DK_ENTRIES(oldkeys); newentries = DK_ENTRIES(mp->ma_keys); oldvalues = mp->ma_values; @@ -1633,7 +1633,7 @@ int } assert(old_value != NULL); - mp->ma_used--; + Py_SIZE(mp)--; mp->ma_version_tag = DICT_NEXT_VERSION(); ep = &DK_ENTRIES(mp->ma_keys)[ix]; dk_set_index(mp->ma_keys, hashpos, DKIX_DUMMY); @@ -1667,7 +1667,7 @@ PyDict_Clear(PyObject *op) DK_INCREF(Py_EMPTY_KEYS); mp->ma_keys = Py_EMPTY_KEYS; mp->ma_values = empty_values; - mp->ma_used = 0; + Py_SIZE(mp) = 0; mp->ma_version_tag = DICT_NEXT_VERSION(); /* ...then clear the keys and values */ if (oldvalues != NULL) { @@ -1703,7 +1703,7 @@ int mp = (PyDictObject *)op; i = *ppos; if (mp->ma_values) { - if (i < 0 || i >= mp->ma_used) + if (i < 0 || i >= PyDict_GET_SIZE(mp)) return 0; /* values of split table is always dense */ entry_ptr = &DK_ENTRIES(mp->ma_keys)[i]; @@ -1770,7 +1770,7 @@ PyObject * assert(PyDict_Check(dict)); mp = (PyDictObject *)dict; - if (mp->ma_used == 0) { + if (PyDict_GET_SIZE(mp) == 0) { if (deflt) { Py_INCREF(deflt); return deflt; @@ -1806,7 +1806,7 @@ PyObject * } assert(old_value != NULL); - mp->ma_used--; + Py_SIZE(mp)--; mp->ma_version_tag = DICT_NEXT_VERSION(); dk_set_index(mp->ma_keys, hashpos, DKIX_DUMMY); ep = &DK_ENTRIES(mp->ma_keys)[ix]; @@ -1833,7 +1833,7 @@ PyObject * if (d == NULL) return NULL; - if (PyDict_CheckExact(d) && ((PyDictObject *)d)->ma_used == 0) { + if (PyDict_CheckExact(d) && PyDict_GET_SIZE(d) == 0) { if (PyDict_CheckExact(iterable)) { PyDictObject *mp = (PyDictObject *)d; PyObject *oldvalue; @@ -1952,7 +1952,7 @@ dict_repr(PyDictObject *mp) return i > 0 ? PyUnicode_FromString("{...}") : NULL; } - if (mp->ma_used == 0) { + if (PyDict_GET_SIZE(mp) == 0) { Py_ReprLeave((PyObject *)mp); return PyUnicode_FromString("{}"); } @@ -1960,7 +1960,7 @@ dict_repr(PyDictObject *mp) _PyUnicodeWriter_Init(&writer); writer.overallocate = 1; /* "{" + "1: 2" + ", 3: 4" * (len - 1) + "}" */ - writer.min_length = 1 + 4 + (2 + 4) * (mp->ma_used - 1) + 1; + writer.min_length = 1 + 4 + (2 + 4) * (PyDict_GET_SIZE(mp) - 1) + 1; if (_PyUnicodeWriter_WriteChar(&writer, '{') < 0) goto error; @@ -2025,7 +2025,7 @@ error: static Py_ssize_t dict_length(PyDictObject *mp) { - return mp->ma_used; + return PyDict_GET_SIZE(mp); } static PyObject * @@ -2091,11 +2091,11 @@ dict_keys(PyDictObject *mp) PyObject **value_ptr; again: - n = mp->ma_used; + n = PyDict_GET_SIZE(mp); v = PyList_New(n); if (v == NULL) return NULL; - if (n != mp->ma_used) { + if (n != PyDict_GET_SIZE(mp)) { /* Durnit. The allocations caused the dict to resize. * Just start over, this shouldn't normally happen. */ @@ -2135,11 +2135,11 @@ dict_values(PyDictObject *mp) PyObject **value_ptr; again: - n = mp->ma_used; + n = PyDict_GET_SIZE(mp); v = PyList_New(n); if (v == NULL) return NULL; - if (n != mp->ma_used) { + if (n != PyDict_GET_SIZE(mp)) { /* Durnit. The allocations caused the dict to resize. * Just start over, this shouldn't normally happen. */ @@ -2184,7 +2184,7 @@ dict_items(PyDictObject *mp) * could resize the dict. :-( */ again: - n = mp->ma_used; + n = PyDict_GET_SIZE(mp); v = PyList_New(n); if (v == NULL) return NULL; @@ -2196,7 +2196,7 @@ dict_items(PyDictObject *mp) } PyList_SET_ITEM(v, i, item); } - if (n != mp->ma_used) { + if (n != PyDict_GET_SIZE(mp)) { /* Durnit. The allocations caused the dict to resize. * Just start over, this shouldn't normally happen. */ @@ -2384,10 +2384,10 @@ dict_merge(PyObject *a, PyObject *b, int mp = (PyDictObject*)a; if (PyDict_Check(b)) { other = (PyDictObject*)b; - if (other == mp || other->ma_used == 0) + if (other == mp || PyDict_GET_SIZE(other) == 0) /* a.update(a) or a.update({}); nothing to do */ return 0; - if (mp->ma_used == 0) + if (PyDict_GET_SIZE(mp) == 0) /* Since the target dict is empty, PyDict_GetItem() * always returns NULL. Setting override to 1 * skips the unnecessary test. @@ -2397,8 +2397,8 @@ dict_merge(PyObject *a, PyObject *b, int * incrementally resizing as we insert new items. Expect * that there will be no (or few) overlapping keys. */ - if (USABLE_FRACTION(mp->ma_keys->dk_size) < other->ma_used) { - if (dictresize(mp, ESTIMATE_SIZE(mp->ma_used + other->ma_used))) { + if (USABLE_FRACTION(mp->ma_keys->dk_size) < PyDict_GET_SIZE(other)) { + if (dictresize(mp, ESTIMATE_SIZE(PyDict_GET_SIZE(mp) + PyDict_GET_SIZE(other)))) { return -1; } } @@ -2552,7 +2552,7 @@ PyDict_Copy(PyObject *o) } split_copy->ma_values = newvalues; split_copy->ma_keys = mp->ma_keys; - split_copy->ma_used = mp->ma_used; + Py_SIZE(split_copy) = Py_SIZE(mp); DK_INCREF(mp->ma_keys); for (i = 0, n = size; i < n; i++) { PyObject *value = mp->ma_values[i]; @@ -2579,7 +2579,7 @@ PyDict_Size(PyObject *mp) PyErr_BadInternalCall(); return -1; } - return ((PyDictObject *)mp)->ma_used; + return PyDict_GET_SIZE(mp); } PyObject * @@ -2621,7 +2621,7 @@ dict_equal(PyDictObject *a, PyDictObject { Py_ssize_t i; - if (a->ma_used != b->ma_used) + if (PyDict_GET_SIZE(a) != PyDict_GET_SIZE(b)) /* can't be equal if # of entries differ */ return 0; /* Same # of entries -- check all of 'em. Exit early on any diff. */ @@ -2772,8 +2772,8 @@ PyDict_SetDefault(PyObject *d, PyObject return NULL; if (_PyDict_HasSplitTable(mp) && - ((ix >= 0 && value == NULL && mp->ma_used != ix) || - (ix == DKIX_EMPTY && mp->ma_used != mp->ma_keys->dk_nentries))) { + ((ix >= 0 && value == NULL && PyDict_GET_SIZE(mp) != ix) || + (ix == DKIX_EMPTY && PyDict_GET_SIZE(mp) != mp->ma_keys->dk_nentries))) { if (insertion_resize(mp) < 0) { return NULL; } @@ -2805,7 +2805,7 @@ PyDict_SetDefault(PyObject *d, PyObject else { ep->me_value = value; } - mp->ma_used++; + Py_SIZE(mp)++; mp->ma_version_tag = DICT_NEXT_VERSION(); mp->ma_keys->dk_usable--; mp->ma_keys->dk_nentries++; @@ -2814,11 +2814,11 @@ PyDict_SetDefault(PyObject *d, PyObject else if (value == NULL) { value = defaultobj; assert(_PyDict_HasSplitTable(mp)); - assert(ix == mp->ma_used); + assert(ix == PyDict_GET_SIZE(mp)); Py_INCREF(value); MAINTAIN_TRACKING(mp, key, value); mp->ma_values[ix] = value; - mp->ma_used++; + Py_SIZE(mp)++; mp->ma_version_tag = DICT_NEXT_VERSION(); } @@ -2877,7 +2877,7 @@ dict_popitem(PyDictObject *mp) res = PyTuple_New(2); if (res == NULL) return NULL; - if (mp->ma_used == 0) { + if (PyDict_GET_SIZE(mp) == 0) { Py_DECREF(res); PyErr_SetString(PyExc_KeyError, "popitem(): dictionary is empty"); @@ -2912,7 +2912,7 @@ dict_popitem(PyDictObject *mp) ep->me_value = NULL; /* We can't dk_usable++ since there is DKIX_DUMMY in indices */ mp->ma_keys->dk_nentries = i; - mp->ma_used--; + Py_SIZE(mp)--; mp->ma_version_tag = DICT_NEXT_VERSION(); assert(_PyDict_CheckConsistency(mp)); return res; @@ -3132,7 +3132,7 @@ dict_new(PyTypeObject *type, PyObject *a if (type == &PyDict_Type) _PyObject_GC_UNTRACK(d); - d->ma_used = 0; + Py_SIZE(d) = 0; d->ma_version_tag = DICT_NEXT_VERSION(); d->ma_keys = new_keys_object(PyDict_MINSIZE); if (d->ma_keys == NULL) { @@ -3303,9 +3303,9 @@ dictiter_new(PyDictObject *dict, PyTypeO return NULL; Py_INCREF(dict); di->di_dict = dict; - di->di_used = dict->ma_used; + di->di_used = PyDict_GET_SIZE(dict); di->di_pos = 0; - di->len = dict->ma_used; + di->len = PyDict_GET_SIZE(dict); if (itertype == &PyDictIterItem_Type) { di->di_result = PyTuple_Pack(2, Py_None, Py_None); if (di->di_result == NULL) { @@ -3339,7 +3339,7 @@ static PyObject * dictiter_len(dictiterobject *di) { Py_ssize_t len = 0; - if (di->di_dict != NULL && di->di_used == di->di_dict->ma_used) + if (di->di_dict != NULL && di->di_used == PyDict_GET_SIZE(di->di_dict)) len = di->len; return PyLong_FromSize_t(len); } @@ -3372,7 +3372,7 @@ dictiter_iternextkey(dictiterobject *di) return NULL; assert (PyDict_Check(d)); - if (di->di_used != d->ma_used) { + if (di->di_used != PyDict_GET_SIZE(d)) { PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); di->di_used = -1; /* Make this state sticky */ @@ -3383,7 +3383,7 @@ dictiter_iternextkey(dictiterobject *di) k = d->ma_keys; assert(i >= 0); if (d->ma_values) { - if (i >= d->ma_used) + if (i >= PyDict_GET_SIZE(d)) goto fail; key = DK_ENTRIES(k)[i].me_key; assert(d->ma_values[i] != NULL); @@ -3454,7 +3454,7 @@ dictiter_iternextvalue(dictiterobject *d return NULL; assert (PyDict_Check(d)); - if (di->di_used != d->ma_used) { + if (di->di_used != PyDict_GET_SIZE(d)) { PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); di->di_used = -1; /* Make this state sticky */ @@ -3464,7 +3464,7 @@ dictiter_iternextvalue(dictiterobject *d i = di->di_pos; assert(i >= 0); if (d->ma_values) { - if (i >= d->ma_used) + if (i >= PyDict_GET_SIZE(d)) goto fail; value = d->ma_values[i]; assert(value != NULL); @@ -3535,7 +3535,7 @@ dictiter_iternextitem(dictiterobject *di return NULL; assert (PyDict_Check(d)); - if (di->di_used != d->ma_used) { + if (di->di_used != PyDict_GET_SIZE(d)) { PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); di->di_used = -1; /* Make this state sticky */ @@ -3545,7 +3545,7 @@ dictiter_iternextitem(dictiterobject *di i = di->di_pos; assert(i >= 0); if (d->ma_values) { - if (i >= d->ma_used) + if (i >= PyDict_GET_SIZE(d)) goto fail; key = DK_ENTRIES(d->ma_keys)[i].me_key; value = d->ma_values[i]; @@ -3692,7 +3692,7 @@ dictview_len(_PyDictViewObject *dv) { Py_ssize_t len = 0; if (dv->dv_dict != NULL) - len = dv->dv_dict->ma_used; + len = PyDict_GET_SIZE(dv->dv_dict); return len; } diff -r dbf72357cb4a Objects/setobject.c --- a/Objects/setobject.c Fri Dec 16 16:18:57 2016 +0200 +++ b/Objects/setobject.c Fri Dec 16 16:46:38 2016 +0200 @@ -224,19 +224,19 @@ set_add_entry(PySetObject *so, PyObject found_unused_or_dummy: if (freeslot == NULL) goto found_unused; - so->used++; + Py_SIZE(so)++; freeslot->key = key; freeslot->hash = hash; return 0; found_unused: so->fill++; - so->used++; + Py_SIZE(so)++; entry->key = key; entry->hash = hash; if ((size_t)so->fill*3 < mask*2) return 0; - return set_table_resize(so, so->used); + return set_table_resize(so, PySet_GET_SIZE(so)); found_active: Py_DECREF(key); @@ -297,7 +297,7 @@ set_table_resize(PySetObject *so, Py_ssi Py_ssize_t newsize; setentry *oldtable, *newtable, *entry; Py_ssize_t oldfill = so->fill; - Py_ssize_t oldused = so->used; + Py_ssize_t oldused = PySet_GET_SIZE(so); Py_ssize_t oldmask = so->mask; size_t newmask; int is_oldtable_malloced; @@ -326,7 +326,7 @@ set_table_resize(PySetObject *so, Py_ssi /* A large table is shrinking, or we can't get any smaller. */ newtable = so->smalltable; if (newtable == oldtable) { - if (so->fill == so->used) { + if (so->fill == PySet_GET_SIZE(so)) { /* No dummies, so no point doing anything. */ return 0; } @@ -336,7 +336,7 @@ set_table_resize(PySetObject *so, Py_ssi as set_lookkey needs at least one virgin slot to terminate failing searches. If fill < size, it's merely desirable, as dummies slow searches. */ - assert(so->fill > so->used); + assert(so->fill > PySet_GET_SIZE(so)); memcpy(small_copy, oldtable, sizeof(small_copy)); oldtable = small_copy; } @@ -353,7 +353,7 @@ set_table_resize(PySetObject *so, Py_ssi assert(newtable != oldtable); memset(newtable, 0, sizeof(setentry) * newsize); so->fill = oldused; - so->used = oldused; + Py_SIZE(so) = oldused; so->mask = newsize - 1; so->table = newtable; @@ -407,7 +407,7 @@ set_discard_entry(PySetObject *so, PyObj old_key = entry->key; entry->key = dummy; entry->hash = -1; - so->used--; + Py_SIZE(so)--; Py_DECREF(old_key); return DISCARD_FOUND; } @@ -459,7 +459,7 @@ set_empty_to_minsize(PySetObject *so) { memset(so->smalltable, 0, sizeof(so->smalltable)); so->fill = 0; - so->used = 0; + Py_SIZE(so) = 0; so->mask = PySet_MINSIZE - 1; so->table = so->smalltable; so->hash = -1; @@ -471,7 +471,7 @@ set_clear_internal(PySetObject *so) setentry *entry; setentry *table = so->table; Py_ssize_t fill = so->fill; - Py_ssize_t used = so->used; + Py_ssize_t used = PySet_GET_SIZE(so); int table_is_malloced = table != so->smalltable; setentry small_copy[PySet_MINSIZE]; @@ -555,7 +555,7 @@ static void set_dealloc(PySetObject *so) { setentry *entry; - Py_ssize_t used = so->used; + Py_ssize_t used = PySet_GET_SIZE(so); PyObject_GC_UnTrack(so); Py_TRASHCAN_SAFE_BEGIN(so) @@ -587,7 +587,7 @@ set_repr(PySetObject *so) } /* shortcut for the empty set */ - if (!so->used) { + if (!PySet_GET_SIZE(so)) { Py_ReprLeave((PyObject*)so); return PyUnicode_FromFormat("%s()", Py_TYPE(so)->tp_name); } @@ -622,7 +622,7 @@ done: static Py_ssize_t set_len(PyObject *so) { - return ((PySetObject *)so)->used; + return PySet_GET_SIZE(so); } static int @@ -638,15 +638,15 @@ set_merge(PySetObject *so, PyObject *oth assert (PyAnySet_Check(otherset)); other = (PySetObject*)otherset; - if (other == so || other->used == 0) + if (other == so || PySet_GET_SIZE(other) == 0) /* a.update(a) or a.update(set()); nothing to do */ return 0; /* Do one big resize at the start, rather than * incrementally resizing as we insert new keys. Expect * that there will be no (or few) overlapping keys. */ - if ((so->fill + other->used)*3 >= so->mask*2) { - if (set_table_resize(so, so->used + other->used) != 0) + if ((so->fill + PySet_GET_SIZE(other))*3 >= so->mask*2) { + if (set_table_resize(so, PySet_GET_SIZE(so) + PySet_GET_SIZE(other)) != 0) return -1; } so_entry = so->table; @@ -654,7 +654,7 @@ set_merge(PySetObject *so, PyObject *oth /* If our table is empty, and both tables have the same size, and there are no dummies to eliminate, then just copy the pointers. */ - if (so->fill == 0 && so->mask == other->mask && other->fill == other->used) { + if (so->fill == 0 && so->mask == other->mask && other->fill == PySet_GET_SIZE(other)) { for (i = 0; i <= other->mask; i++, so_entry++, other_entry++) { key = other_entry->key; if (key != NULL) { @@ -665,7 +665,7 @@ set_merge(PySetObject *so, PyObject *oth } } so->fill = other->fill; - so->used = other->used; + Py_SIZE(so) = PySet_GET_SIZE(other); return 0; } @@ -673,8 +673,8 @@ set_merge(PySetObject *so, PyObject *oth if (so->fill == 0) { setentry *newtable = so->table; size_t newmask = (size_t)so->mask; - so->fill = other->used; - so->used = other->used; + so->fill = PySet_GET_SIZE(other); + Py_SIZE(so) = PySet_GET_SIZE(other); for (i = other->mask + 1; i > 0 ; i--, other_entry++) { key = other_entry->key; if (key != NULL && key != dummy) { @@ -706,7 +706,7 @@ set_pop(PySetObject *so) PyObject *key; assert (PyAnySet_Check(so)); - if (so->used == 0) { + if (PySet_GET_SIZE(so) == 0) { PyErr_SetString(PyExc_KeyError, "pop from an empty set"); return NULL; } @@ -719,7 +719,7 @@ set_pop(PySetObject *so) key = entry->key; entry->key = dummy; entry->hash = -1; - so->used--; + Py_SIZE(so)--; so->finger = i + 1; /* next place to start */ return key; } @@ -783,7 +783,7 @@ frozenset_hash(PyObject *self) hash ^= _shuffle_bits(0); /* Remove the effect of an odd number of dummy entries */ - if ((so->fill - so->used) & 1) + if ((so->fill - PySet_GET_SIZE(so)) & 1) hash ^= _shuffle_bits(-1); /* Factor in the number of active entries */ @@ -828,7 +828,7 @@ static PyObject * setiter_len(setiterobject *si) { Py_ssize_t len = 0; - if (si->si_set != NULL && si->si_used == si->si_set->used) + if (si->si_set != NULL && si->si_used == PySet_GET_SIZE(si->si_set)) len = si->len; return PyLong_FromSsize_t(len); } @@ -894,7 +894,7 @@ static PyObject *setiter_iternext(setite return NULL; assert (PyAnySet_Check(so)); - if (si->si_used != so->used) { + if (si->si_used != PySet_GET_SIZE(so)) { PyErr_SetString(PyExc_RuntimeError, "Set changed size during iteration"); si->si_used = -1; /* Make this state sticky */ @@ -962,9 +962,9 @@ set_iter(PySetObject *so) return NULL; Py_INCREF(so); si->si_set = so; - si->si_used = so->used; + si->si_used = PySet_GET_SIZE(so); si->si_pos = 0; - si->len = so->used; + si->len = PySet_GET_SIZE(so); _PyObject_GC_TRACK(si); return (PyObject *)si; } @@ -990,7 +990,7 @@ set_update_internal(PySetObject *so, PyO if (dictsize < 0) return -1; if ((so->fill + dictsize)*3 >= so->mask*2) { - if (set_table_resize(so, so->used + dictsize) != 0) + if (set_table_resize(so, PySet_GET_SIZE(so) + dictsize) != 0) return -1; } while (_PyDict_Next(other, &pos, &key, &value, &hash)) { @@ -1050,7 +1050,7 @@ make_new_set(PyTypeObject *type, PyObjec return NULL; so->fill = 0; - so->used = 0; + Py_SIZE(so) = 0; so->mask = PySet_MINSIZE - 1; so->table = so->smalltable; so->hash = -1; @@ -1141,7 +1141,7 @@ set_swap_bodies(PySetObject *a, PySetObj Py_hash_t h; t = a->fill; a->fill = b->fill; b->fill = t; - t = a->used; a->used = b->used; b->used = t; + t = PySet_GET_SIZE(a); Py_SIZE(a) = PySet_GET_SIZE(b); Py_SIZE(b) = t; t = a->mask; a->mask = b->mask; b->mask = t; u = a->table; @@ -1509,9 +1509,9 @@ set_difference_update_internal(PySetObje return -1; } /* If more than 1/4th are dummies, then resize them away. */ - if ((size_t)(so->fill - so->used) <= (size_t)so->mask / 4) + if ((size_t)(so->fill - PySet_GET_SIZE(so)) <= (size_t)so->mask / 4) return 0; - return set_table_resize(so, so->used); + return set_table_resize(so, PySet_GET_SIZE(so)); } static PyObject *