@@ -140,6 +140,8 @@ typedef struct py_hmac_hinfo {
140140typedef struct hmacmodule_state {
141141 _Py_hashtable_t * hinfo_table ;
142142 PyObject * unknown_hash_error ;
143+ /* interned strings */
144+ PyObject * str_lower ;
143145} hmacmodule_state ;
144146
145147static inline hmacmodule_state *
@@ -352,6 +354,21 @@ hmacmodule_init_exceptions(PyObject *module, hmacmodule_state *state)
352354 return 0 ;
353355}
354356
357+ static int
358+ hmacmodule_init_strings (hmacmodule_state * state )
359+ {
360+ #define ADD_STR (ATTR , STRING ) \
361+ do { \
362+ state->ATTR = PyUnicode_FromString(STRING); \
363+ if (state->ATTR == NULL) { \
364+ return -1; \
365+ } \
366+ } while (0)
367+ ADD_STR (str_lower , "lower" );
368+ #undef ADD_STR
369+ return 0 ;
370+ }
371+
355372static int
356373hmacmodule_exec (PyObject * module )
357374{
@@ -362,6 +379,9 @@ hmacmodule_exec(PyObject *module)
362379 if (hmacmodule_init_exceptions (module , state ) < 0 ) {
363380 return -1 ;
364381 }
382+ if (hmacmodule_init_strings (state ) < 0 ) {
383+ return -1 ;
384+ }
365385 return 0 ;
366386}
367387
@@ -371,6 +391,7 @@ hmacmodule_traverse(PyObject *mod, visitproc visit, void *arg)
371391 Py_VISIT (Py_TYPE (mod ));
372392 hmacmodule_state * state = get_hmacmodule_state (mod );
373393 Py_VISIT (state -> unknown_hash_error );
394+ Py_VISIT (state -> str_lower );
374395 return 0 ;
375396}
376397
@@ -383,6 +404,7 @@ hmacmodule_clear(PyObject *mod)
383404 state -> hinfo_table = NULL ;
384405 }
385406 Py_CLEAR (state -> unknown_hash_error );
407+ Py_CLEAR (state -> str_lower );
386408 return 0 ;
387409}
388410
0 commit comments