diff options
| author | Carl Meyer <carl@oddbird.net> | 2022-10-06 17:08:00 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-07 01:08:00 +0100 |
| commit | a4b7794887929f82c532fcd055326954ff1197ce (patch) | |
| tree | 257e2dc783858251f893d75c17663913b05a0fad /Include/cpython | |
| parent | 683ab859554c34831fcecc854de35745d7fd603c (diff) | |
| download | cpython-git-a4b7794887929f82c532fcd055326954ff1197ce.tar.gz | |
GH-91052: Add C API for watching dictionaries (GH-31787)
Diffstat (limited to 'Include/cpython')
| -rw-r--r-- | Include/cpython/dictobject.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Include/cpython/dictobject.h b/Include/cpython/dictobject.h index 565ad791a6..f8a74a597b 100644 --- a/Include/cpython/dictobject.h +++ b/Include/cpython/dictobject.h @@ -83,3 +83,26 @@ typedef struct { PyAPI_FUNC(PyObject *) _PyDictView_New(PyObject *, PyTypeObject *); PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other); + +/* Dictionary watchers */ + +typedef enum { + PyDict_EVENT_ADDED, + PyDict_EVENT_MODIFIED, + PyDict_EVENT_DELETED, + PyDict_EVENT_CLONED, + PyDict_EVENT_CLEARED, + PyDict_EVENT_DEALLOCATED, +} PyDict_WatchEvent; + +// Callback to be invoked when a watched dict is cleared, dealloced, or modified. +// In clear/dealloc case, key and new_value will be NULL. Otherwise, new_value will be the +// new value for key, NULL if key is being deleted. +typedef int(*PyDict_WatchCallback)(PyDict_WatchEvent event, PyObject* dict, PyObject* key, PyObject* new_value); + +// Register/unregister a dict-watcher callback +PyAPI_FUNC(int) PyDict_AddWatcher(PyDict_WatchCallback callback); +PyAPI_FUNC(int) PyDict_ClearWatcher(int watcher_id); + +// Mark given dictionary as "watched" (callback will be called if it is modified) +PyAPI_FUNC(int) PyDict_Watch(int watcher_id, PyObject* dict); |
