Skip to content

Commit 5b71796

Browse files
committed
use '<MOD>state' and 'get_<MOD>module_state' naming
1 parent 0dcc799 commit 5b71796

5 files changed

Lines changed: 93 additions & 92 deletions

File tree

Modules/blake2module.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,23 @@ typedef struct {
7777
PyTypeObject *blake2s_type;
7878
bool can_run_simd128;
7979
bool can_run_simd256;
80-
} Blake2State;
80+
} blake2module_state;
8181

82-
static inline Blake2State *
83-
blake2_get_state(PyObject *module)
82+
static inline blake2module_state *
83+
get_blake2module_state(PyObject *module)
8484
{
8585
void *state = _PyModule_GetState(module);
8686
assert(state != NULL);
87-
return (Blake2State *)state;
87+
return (blake2module_state *)state;
8888
}
8989

9090
#if defined(HACL_CAN_COMPILE_SIMD128) || defined(HACL_CAN_COMPILE_SIMD256)
91-
static inline Blake2State *
91+
static inline blake2module_state *
9292
blake2_get_state_from_type(PyTypeObject *module)
9393
{
9494
void *state = _PyType_GetModuleState(module);
9595
assert(state != NULL);
96-
return (Blake2State *)state;
96+
return (blake2module_state *)state;
9797
}
9898
#endif
9999

@@ -104,7 +104,7 @@ static struct PyMethodDef blake2mod_functions[] = {
104104
static int
105105
_blake2_traverse(PyObject *module, visitproc visit, void *arg)
106106
{
107-
Blake2State *state = blake2_get_state(module);
107+
blake2module_state *state = get_blake2module_state(module);
108108
Py_VISIT(state->blake2b_type);
109109
Py_VISIT(state->blake2s_type);
110110
return 0;
@@ -113,7 +113,7 @@ _blake2_traverse(PyObject *module, visitproc visit, void *arg)
113113
static int
114114
_blake2_clear(PyObject *module)
115115
{
116-
Blake2State *state = blake2_get_state(module);
116+
blake2module_state *state = get_blake2module_state(module);
117117
Py_CLEAR(state->blake2b_type);
118118
Py_CLEAR(state->blake2s_type);
119119
return 0;
@@ -126,7 +126,7 @@ _blake2_free(void *module)
126126
}
127127

128128
static void
129-
blake2module_init_cpu_features(Blake2State *state)
129+
blake2module_init_cpu_features(blake2module_state *state)
130130
{
131131
/* This must be kept in sync with hmacmodule_init_cpu_features()
132132
* in hmacmodule.c */
@@ -204,8 +204,8 @@ blake2module_init_cpu_features(Blake2State *state)
204204
static int
205205
blake2_exec(PyObject *m)
206206
{
207-
Blake2State *st = blake2_get_state(m);
208-
blake2module_init_cpu_features(st);
207+
blake2module_state *state = get_blake2module_state(m);
208+
blake2module_init_cpu_features(state);
209209

210210
#define ADD_INT(DICT, NAME, VALUE) \
211211
do { \
@@ -229,17 +229,17 @@ blake2_exec(PyObject *m)
229229

230230
ADD_INT_CONST("_GIL_MINSIZE", HASHLIB_GIL_MINSIZE);
231231

232-
st->blake2b_type = (PyTypeObject *)PyType_FromModuleAndSpec(
232+
state->blake2b_type = (PyTypeObject *)PyType_FromModuleAndSpec(
233233
m, &blake2b_type_spec, NULL);
234234

235-
if (st->blake2b_type == NULL) {
235+
if (state->blake2b_type == NULL) {
236236
return -1;
237237
}
238-
if (PyModule_AddType(m, st->blake2b_type) < 0) {
238+
if (PyModule_AddType(m, state->blake2b_type) < 0) {
239239
return -1;
240240
}
241241

242-
PyObject *d = st->blake2b_type->tp_dict;
242+
PyObject *d = state->blake2b_type->tp_dict;
243243
ADD_INT(d, "SALT_SIZE", HACL_HASH_BLAKE2B_SALT_BYTES);
244244
ADD_INT(d, "PERSON_SIZE", HACL_HASH_BLAKE2B_PERSONAL_BYTES);
245245
ADD_INT(d, "MAX_KEY_SIZE", HACL_HASH_BLAKE2B_KEY_BYTES);
@@ -251,17 +251,17 @@ blake2_exec(PyObject *m)
251251
ADD_INT_CONST("BLAKE2B_MAX_DIGEST_SIZE", HACL_HASH_BLAKE2B_OUT_BYTES);
252252

253253
/* BLAKE2s */
254-
st->blake2s_type = (PyTypeObject *)PyType_FromModuleAndSpec(
254+
state->blake2s_type = (PyTypeObject *)PyType_FromModuleAndSpec(
255255
m, &blake2s_type_spec, NULL);
256256

257-
if (st->blake2s_type == NULL) {
257+
if (state->blake2s_type == NULL) {
258258
return -1;
259259
}
260-
if (PyModule_AddType(m, st->blake2s_type) < 0) {
260+
if (PyModule_AddType(m, state->blake2s_type) < 0) {
261261
return -1;
262262
}
263263

264-
d = st->blake2s_type->tp_dict;
264+
d = state->blake2s_type->tp_dict;
265265
ADD_INT(d, "SALT_SIZE", HACL_HASH_BLAKE2S_SALT_BYTES);
266266
ADD_INT(d, "PERSON_SIZE", HACL_HASH_BLAKE2S_PERSONAL_BYTES);
267267
ADD_INT(d, "MAX_KEY_SIZE", HACL_HASH_BLAKE2S_KEY_BYTES);
@@ -288,7 +288,7 @@ static struct PyModuleDef blake2_module = {
288288
.m_base = PyModuleDef_HEAD_INIT,
289289
.m_name = "_blake2",
290290
.m_doc = blake2mod__doc__,
291-
.m_size = sizeof(Blake2State),
291+
.m_size = sizeof(blake2module_state),
292292
.m_methods = blake2mod_functions,
293293
.m_slots = _blake2_slots,
294294
.m_traverse = _blake2_traverse,
@@ -332,18 +332,18 @@ static inline blake2_impl
332332
type_to_impl(PyTypeObject *type)
333333
{
334334
#if defined(HACL_CAN_COMPILE_SIMD128) || defined(HACL_CAN_COMPILE_SIMD256)
335-
Blake2State *st = blake2_get_state_from_type(type);
335+
blake2module_state *state = blake2_get_state_from_type(type);
336336
#endif
337337
if (!strcmp(type->tp_name, blake2b_type_spec.name)) {
338338
#if HACL_CAN_COMPILE_SIMD256
339-
return st->can_run_simd256 ? Blake2b_256 : Blake2b;
339+
return state->can_run_simd256 ? Blake2b_256 : Blake2b;
340340
#else
341341
return Blake2b;
342342
#endif
343343
}
344344
else if (!strcmp(type->tp_name, blake2s_type_spec.name)) {
345345
#if HACL_CAN_COMPILE_SIMD128
346-
return st->can_run_simd128 ? Blake2s_128 : Blake2s;
346+
return state->can_run_simd128 ? Blake2s_128 : Blake2s;
347347
#else
348348
return Blake2s;
349349
#endif

Modules/md5module.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ typedef struct {
4949

5050

5151
typedef struct {
52-
PyTypeObject* md5_type;
53-
} MD5State;
52+
PyTypeObject *md5_type;
53+
} md5module_state;
5454

55-
static inline MD5State*
56-
md5_get_state(PyObject *module)
55+
static inline md5module_state *
56+
get_md5module_state(PyObject *module)
5757
{
5858
void *state = PyModule_GetState(module);
5959
assert(state != NULL);
60-
return (MD5State *)state;
60+
return (md5module_state *)state;
6161
}
6262

6363
static MD5object *
64-
newMD5object(MD5State * st)
64+
newMD5object(md5module_state *state)
6565
{
66-
MD5object *md5 = PyObject_GC_New(MD5object, st->md5_type);
66+
MD5object *md5 = PyObject_GC_New(MD5object, state->md5_type);
6767
if (!md5) {
6868
return NULL;
6969
}
@@ -107,10 +107,10 @@ static PyObject *
107107
MD5Type_copy_impl(MD5object *self, PyTypeObject *cls)
108108
/*[clinic end generated code: output=bf055e08244bf5ee input=d89087dcfb2a8620]*/
109109
{
110-
MD5State *st = PyType_GetModuleState(cls);
110+
md5module_state *state = PyType_GetModuleState(cls);
111111

112112
MD5object *newobj;
113-
if ((newobj = newMD5object(st)) == NULL) {
113+
if ((newobj = newMD5object(state)) == NULL) {
114114
return NULL;
115115
}
116116

@@ -299,8 +299,8 @@ _md5_md5_impl(PyObject *module, PyObject *data, int usedforsecurity,
299299
GET_BUFFER_VIEW_OR_ERROUT(string, &buf);
300300
}
301301

302-
MD5State *st = md5_get_state(module);
303-
if ((new = newMD5object(st)) == NULL) {
302+
md5module_state *state = get_md5module_state(module);
303+
if ((new = newMD5object(state)) == NULL) {
304304
if (string) {
305305
PyBuffer_Release(&buf);
306306
}
@@ -344,15 +344,15 @@ static struct PyMethodDef MD5_functions[] = {
344344
static int
345345
_md5_traverse(PyObject *module, visitproc visit, void *arg)
346346
{
347-
MD5State *state = md5_get_state(module);
347+
md5module_state *state = get_md5module_state(module);
348348
Py_VISIT(state->md5_type);
349349
return 0;
350350
}
351351

352352
static int
353353
_md5_clear(PyObject *module)
354354
{
355-
MD5State *state = md5_get_state(module);
355+
md5module_state *state = get_md5module_state(module);
356356
Py_CLEAR(state->md5_type);
357357
return 0;
358358
}
@@ -367,12 +367,12 @@ _md5_free(void *module)
367367
static int
368368
md5_exec(PyObject *m)
369369
{
370-
MD5State *st = md5_get_state(m);
370+
md5module_state *state = get_md5module_state(m);
371371

372-
st->md5_type = (PyTypeObject *)PyType_FromModuleAndSpec(
372+
state->md5_type = (PyTypeObject *)PyType_FromModuleAndSpec(
373373
m, &md5_type_spec, NULL);
374374

375-
if (PyModule_AddObjectRef(m, "MD5Type", (PyObject *)st->md5_type) < 0) {
375+
if (PyModule_AddObjectRef(m, "MD5Type", (PyObject *)state->md5_type) < 0) {
376376
return -1;
377377
}
378378
if (PyModule_AddIntConstant(m, "_GIL_MINSIZE", HASHLIB_GIL_MINSIZE) < 0) {
@@ -393,7 +393,7 @@ static PyModuleDef_Slot _md5_slots[] = {
393393
static struct PyModuleDef _md5module = {
394394
PyModuleDef_HEAD_INIT,
395395
.m_name = "_md5",
396-
.m_size = sizeof(MD5State),
396+
.m_size = sizeof(md5module_state),
397397
.m_methods = MD5_functions,
398398
.m_slots = _md5_slots,
399399
.m_traverse = _md5_traverse,

Modules/sha1module.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ typedef struct {
4949

5050

5151
typedef struct {
52-
PyTypeObject* sha1_type;
53-
} SHA1State;
52+
PyTypeObject *sha1_type;
53+
} sha1module_state;
5454

55-
static inline SHA1State*
56-
sha1_get_state(PyObject *module)
55+
static inline sha1module_state *
56+
get_sha1module_state(PyObject *module)
5757
{
5858
void *state = PyModule_GetState(module);
5959
assert(state != NULL);
60-
return (SHA1State *)state;
60+
return (sha1module_state *)state;
6161
}
6262

6363
static SHA1object *
64-
newSHA1object(SHA1State *st)
64+
newSHA1object(sha1module_state *state)
6565
{
66-
SHA1object *sha = PyObject_GC_New(SHA1object, st->sha1_type);
66+
SHA1object *sha = PyObject_GC_New(SHA1object, state->sha1_type);
6767
if (sha == NULL) {
6868
return NULL;
6969
}
@@ -111,10 +111,10 @@ static PyObject *
111111
SHA1Type_copy_impl(SHA1object *self, PyTypeObject *cls)
112112
/*[clinic end generated code: output=b32d4461ce8bc7a7 input=6c22e66fcc34c58e]*/
113113
{
114-
SHA1State *st = _PyType_GetModuleState(cls);
114+
sha1module_state *state = _PyType_GetModuleState(cls);
115115

116116
SHA1object *newobj;
117-
if ((newobj = newSHA1object(st)) == NULL) {
117+
if ((newobj = newSHA1object(state)) == NULL) {
118118
return NULL;
119119
}
120120

@@ -293,8 +293,8 @@ _sha1_sha1_impl(PyObject *module, PyObject *data, int usedforsecurity,
293293
GET_BUFFER_VIEW_OR_ERROUT(string, &buf);
294294
}
295295

296-
SHA1State *st = sha1_get_state(module);
297-
if ((new = newSHA1object(st)) == NULL) {
296+
sha1module_state *state = get_sha1module_state(module);
297+
if ((new = newSHA1object(state)) == NULL) {
298298
if (string) {
299299
PyBuffer_Release(&buf);
300300
}
@@ -338,15 +338,15 @@ static struct PyMethodDef SHA1_functions[] = {
338338
static int
339339
_sha1_traverse(PyObject *module, visitproc visit, void *arg)
340340
{
341-
SHA1State *state = sha1_get_state(module);
341+
sha1module_state *state = get_sha1module_state(module);
342342
Py_VISIT(state->sha1_type);
343343
return 0;
344344
}
345345

346346
static int
347347
_sha1_clear(PyObject *module)
348348
{
349-
SHA1State *state = sha1_get_state(module);
349+
sha1module_state *state = get_sha1module_state(module);
350350
Py_CLEAR(state->sha1_type);
351351
return 0;
352352
}
@@ -360,13 +360,13 @@ _sha1_free(void *module)
360360
static int
361361
_sha1_exec(PyObject *module)
362362
{
363-
SHA1State* st = sha1_get_state(module);
363+
sha1module_state *state = get_sha1module_state(module);
364364

365-
st->sha1_type = (PyTypeObject *)PyType_FromModuleAndSpec(
365+
state->sha1_type = (PyTypeObject *)PyType_FromModuleAndSpec(
366366
module, &sha1_type_spec, NULL);
367367
if (PyModule_AddObjectRef(module,
368368
"SHA1Type",
369-
(PyObject *)st->sha1_type) < 0)
369+
(PyObject *)state->sha1_type) < 0)
370370
{
371371
return -1;
372372
}
@@ -393,7 +393,7 @@ static PyModuleDef_Slot _sha1_slots[] = {
393393
static struct PyModuleDef _sha1module = {
394394
PyModuleDef_HEAD_INIT,
395395
.m_name = "_sha1",
396-
.m_size = sizeof(SHA1State),
396+
.m_size = sizeof(sha1module_state),
397397
.m_methods = SHA1_functions,
398398
.m_slots = _sha1_slots,
399399
.m_traverse = _sha1_traverse,

0 commit comments

Comments
 (0)