Skip to content

Commit 7c7f401

Browse files
committed
add HMAC module state
This adds the `hmacmodule_state` structure. This structure will grow later, containing interned strings, specific exception types, object types as well as internal data.
1 parent 2e5ee67 commit 7c7f401

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Modules/hmacmodule.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919

2020
#include "Python.h"
2121

22+
// --- HMAC module state ------------------------------------------------------
23+
24+
typedef struct hmacmodule_state {
25+
} hmacmodule_state;
26+
27+
static inline hmacmodule_state *
28+
get_hmacmodule_state(PyObject *module)
29+
{
30+
void *state = PyModule_GetState(module);
31+
assert(state != NULL);
32+
return (hmacmodule_state *)state;
33+
}
34+
2235
// --- HMAC module clinic configuration ---------------------------------------
2336

2437
/*[clinic input]
@@ -34,7 +47,36 @@ static PyMethodDef hmacmodule_methods[] = {
3447

3548
// --- HMAC module initialization and finalization functions ------------------
3649

50+
static int
51+
hmacmodule_exec(PyObject *module)
52+
{
53+
hmacmodule_state *state = get_hmacmodule_state(module);
54+
return 0;
55+
}
56+
57+
static int
58+
hmacmodule_traverse(PyObject *mod, visitproc visit, void *arg)
59+
{
60+
Py_VISIT(Py_TYPE(mod));
61+
hmacmodule_state *state = get_hmacmodule_state(mod);
62+
return 0;
63+
}
64+
65+
static int
66+
hmacmodule_clear(PyObject *mod)
67+
{
68+
hmacmodule_state *state = get_hmacmodule_state(mod);
69+
return 0;
70+
}
71+
72+
static inline void
73+
hmacmodule_free(void *mod)
74+
{
75+
(void)hmacmodule_clear((PyObject *)mod);
76+
}
77+
3778
static struct PyModuleDef_Slot hmacmodule_slots[] = {
79+
{Py_mod_exec, hmacmodule_exec},
3880
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
3981
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
4082
{0, NULL} /* sentinel */
@@ -46,6 +88,9 @@ static struct PyModuleDef _hmacmodule = {
4688
.m_size = sizeof(hmacmodule_state),
4789
.m_methods = hmacmodule_methods,
4890
.m_slots = hmacmodule_slots,
91+
.m_traverse = hmacmodule_traverse,
92+
.m_clear = hmacmodule_clear,
93+
.m_free = hmacmodule_free,
4994
};
5095

5196
PyMODINIT_FUNC

0 commit comments

Comments
 (0)