Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add get-state helpers
  • Loading branch information
erlend-aasland committed Mar 29, 2023
commit 3349ad3e6d7e02af53dec2365b61a0da7e2457d0
2 changes: 1 addition & 1 deletion Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3279,7 +3279,7 @@ DisableEventHook(void)
}


static struct PyModuleDef _tkintermodule = {
struct PyModuleDef _tkintermodule = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_tkinter",
.m_size = sizeof(module_state),
Expand Down
26 changes: 26 additions & 0 deletions Modules/tkinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,30 @@ extern module_state global_state;

#define GLOBAL_STATE() (&global_state)

static inline module_state *
get_module_state(PyObject *mod)
{
void *state = _PyModule_GetState(mod);
assert(state != NULL);
return (module_state *)state;
}

static inline module_state *
get_module_state_by_cls(PyTypeObject *cls)
{
void *state = _PyType_GetModuleState(cls);
assert(state != NULL);
return (module_state *)state;
}

extern struct PyModuleDef _tkintermodule;

static inline module_state *
find_module_state_by_type(PyTypeObject *tp)
{
PyObject *mod = PyType_GetModuleByDef(tp, &_tkintermodule);
assert(mod != NULL);
return get_module_state(mod);
}

#endif /* !TKINTER_H */