44/* Doc strings: Mitch Chapman */
55
66#define PY_SSIZE_T_CLEAN
7- #define NEEDS_PY_IDENTIFIER
87#include "Python.h"
98#include "gdbm.h"
109
@@ -21,6 +20,7 @@ extern const char * gdbm_strerror(gdbm_error);
2120typedef struct {
2221 PyTypeObject * gdbm_type ;
2322 PyObject * gdbm_error ;
23+ PyObject * str_close ;
2424} _gdbm_state ;
2525
2626static inline _gdbm_state *
@@ -545,8 +545,9 @@ gdbm__enter__(PyObject *self, PyObject *args)
545545static PyObject *
546546gdbm__exit__ (PyObject * self , PyObject * args )
547547{
548- _Py_IDENTIFIER (close );
549- return _PyObject_CallMethodIdNoArgs (self , & PyId_close );
548+ _gdbm_state * state = PyType_GetModuleState (Py_TYPE (self ));
549+ assert (state != NULL );
550+ return PyObject_CallMethodNoArgs (self , state -> str_close );
550551}
551552
552553static PyMethodDef gdbm_methods [] = {
@@ -740,6 +741,11 @@ _gdbm_exec(PyObject *module)
740741 return -1 ;
741742 }
742743#endif
744+ PyObject * str_close = PyUnicode_InternFromString ("close" );
745+ if (str_close == NULL ) {
746+ return -1 ;
747+ }
748+ state -> str_close = str_close ;
743749 return 0 ;
744750}
745751
@@ -749,6 +755,7 @@ _gdbm_module_traverse(PyObject *module, visitproc visit, void *arg)
749755 _gdbm_state * state = get_gdbm_state (module );
750756 Py_VISIT (state -> gdbm_error );
751757 Py_VISIT (state -> gdbm_type );
758+ Py_VISIT (state -> str_close );
752759 return 0 ;
753760}
754761
@@ -758,6 +765,7 @@ _gdbm_module_clear(PyObject *module)
758765 _gdbm_state * state = get_gdbm_state (module );
759766 Py_CLEAR (state -> gdbm_error );
760767 Py_CLEAR (state -> gdbm_type );
768+ Py_CLEAR (state -> str_close );
761769 return 0 ;
762770}
763771
0 commit comments