Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 97f46db

Browse files
Issue python#25410: Made testing that od_fast_nodes and dk_entries are in sync more
reliable.
1 parent 4981dd2 commit 97f46db

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Objects/odictobject.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,12 @@ struct _odictobject {
481481
PyDictObject od_dict; /* the underlying dict */
482482
_ODictNode *od_first; /* first node in the linked list, if any */
483483
_ODictNode *od_last; /* last node in the linked list, if any */
484-
/* od_fast_nodes and od_resize_sentinel are managed by _odict_resize()
484+
/* od_fast_nodes, od_fast_nodes_size and od_resize_sentinel are managed
485+
* by _odict_resize().
485486
* Note that we rely on implementation details of dict for both. */
486487
_ODictNode **od_fast_nodes; /* hash table that mirrors the dict table */
487-
Py_uintptr_t od_resize_sentinel; /* changes if odict should be resized */
488+
Py_ssize_t od_fast_nodes_size;
489+
void *od_resize_sentinel; /* changes if odict should be resized */
488490

489491
size_t od_state; /* incremented whenever the LL changes */
490492
PyObject *od_inst_dict; /* OrderedDict().__dict__ */
@@ -573,7 +575,8 @@ _odict_resize(PyODictObject *od) {
573575
/* Replace the old fast nodes table. */
574576
_odict_free_fast_nodes(od);
575577
od->od_fast_nodes = fast_nodes;
576-
od->od_resize_sentinel = (Py_uintptr_t)(((PyDictObject *)od)->ma_keys);
578+
od->od_fast_nodes_size = size;
579+
od->od_resize_sentinel = ((PyDictObject *)od)->ma_keys;
577580
return 0;
578581
}
579582

@@ -591,7 +594,8 @@ _odict_get_index(PyODictObject *od, PyObject *key)
591594
keys = ((PyDictObject *)od)->ma_keys;
592595

593596
/* Ensure od_fast_nodes and dk_entries are in sync. */
594-
if (od->od_resize_sentinel != (Py_uintptr_t)keys) {
597+
if (od->od_resize_sentinel != keys ||
598+
od->od_fast_nodes_size != keys->dk_size) {
595599
int resize_res = _odict_resize(od);
596600
if (resize_res < 0)
597601
return -1;

0 commit comments

Comments
 (0)