Skip to content

Commit 3cbdf70

Browse files
committed
Use Py_ssize_t more consistently as dictionary index.
1 parent 02221e6 commit 3cbdf70

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Include/internal/pycore_dict.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ extern uint64_t _pydict_global_version;
138138
PyObject *_PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values);
139139

140140
static inline void
141-
_PyDictValues_AddToInsertionOrder(PyDictValues *values, int ix)
141+
_PyDictValues_AddToInsertionOrder(PyDictValues *values, Py_ssize_t ix)
142142
{
143143
assert(ix < SHARED_KEYS_MAX_SIZE);
144144
uint8_t *size_ptr = ((uint8_t *)values)-2;

Objects/dictobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ insertion_resize(PyDictObject *mp)
10381038
return dictresize(mp, calculate_log2_keysize(GROWTH_RATE(mp)));
10391039
}
10401040

1041-
static int
1041+
static Py_ssize_t
10421042
insert_into_dictkeys(PyDictKeysObject *keys, PyObject *name)
10431043
{
10441044
assert(PyUnicode_CheckExact(name));
@@ -1069,7 +1069,7 @@ insert_into_dictkeys(PyDictKeysObject *keys, PyObject *name)
10691069
keys->dk_nentries++;
10701070
}
10711071
assert (ix < SHARED_KEYS_MAX_SIZE);
1072-
return (int)ix;
1072+
return ix;
10731073
}
10741074

10751075
/*
@@ -3051,7 +3051,7 @@ PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj)
30513051
ep->me_key = key;
30523052
ep->me_hash = hash;
30533053
if (_PyDict_HasSplitTable(mp)) {
3054-
int index = (int)mp->ma_keys->dk_nentries;
3054+
Py_ssize_t index = (int)mp->ma_keys->dk_nentries;
30553055
assert(index < SHARED_KEYS_MAX_SIZE);
30563056
assert(mp->ma_values->values[index] == NULL);
30573057
mp->ma_values->values[index] = value;
@@ -5068,7 +5068,7 @@ _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
50685068
assert(keys != NULL);
50695069
assert(values != NULL);
50705070
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
5071-
int ix = insert_into_dictkeys(keys, name);
5071+
Py_ssize_t ix = insert_into_dictkeys(keys, name);
50725072
if (ix == DKIX_EMPTY) {
50735073
if (value == NULL) {
50745074
PyErr_SetObject(PyExc_AttributeError, name);

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3573,7 +3573,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
35733573
PyDictValues *values = *_PyObject_ValuesPointer(owner);
35743574
DEOPT_IF(values == NULL, STORE_ATTR);
35753575
STAT_INC(STORE_ATTR, hit);
3576-
int index = cache0->index;
3576+
Py_ssize_t index = cache0->index;
35773577
STACK_SHRINK(1);
35783578
PyObject *value = POP();
35793579
PyObject *old_value = values->values[index];

0 commit comments

Comments
 (0)