Skip to content

Commit 2092192

Browse files
authored
gh-150490: Raise PyType_Modified for insertion into split dictionary (take 2) (#152914)
Raise PyType_Modified for insertion into split dictionary - now with better locking discipline in free-threaded builds
1 parent 28aa32d commit 2092192

14 files changed

Lines changed: 1395 additions & 1419 deletions

File tree

Include/internal/pycore_dict.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ typedef struct {
9090
} PyDictUnicodeEntry;
9191

9292
extern PyDictKeysObject *_PyDict_NewKeysForClass(PyHeapTypeObject *);
93+
extern void _PyDict_RemoveKeysForClass(PyHeapTypeObject *);
9394
extern PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
9495

9596
/* Implementations of the `|` and `|=` operators for dict, used by the
@@ -239,6 +240,17 @@ struct _dictkeysobject {
239240
see the DK_ENTRIES() / DK_UNICODE_ENTRIES() functions below */
240241
};
241242

243+
struct _instancekeysobject {
244+
PyTypeObject* dsk_owning_type;
245+
struct _dictkeysobject dsk_keys;
246+
};
247+
248+
static inline struct _instancekeysobject *_PyDictKeys_AsSharedKeys(struct _dictkeysobject *keys)
249+
{
250+
assert(keys->dk_kind == DICT_KEYS_SPLIT);
251+
return _Py_CONTAINER_OF(keys, struct _instancekeysobject, dsk_keys);
252+
}
253+
242254
/* This must be no more than 250, for the prefix size to fit in one byte. */
243255
#define SHARED_KEYS_MAX_SIZE 30
244256
#define NEXT_LOG2_SHARED_KEYS_MAX_SIZE 6

Include/internal/pycore_opcode_metadata.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_typeobject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ extern int _PyType_AddMethod(PyTypeObject *, PyMethodDef *);
148148
extern void _PyType_SetFlagsRecursive(PyTypeObject *self, unsigned long mask,
149149
unsigned long flags);
150150

151+
// Raise PyType_Modified with the type lock already held.
152+
extern void _PyType_Modified_Unlocked(PyTypeObject *type);
153+
151154
PyAPI_FUNC(void) _PyType_SetVersion(PyTypeObject *tp, unsigned int version);
152155
PyTypeObject *_PyType_LookupByVersion(unsigned int version);
153156

0 commit comments

Comments
 (0)