@@ -1967,56 +1967,91 @@ _multibytecodec___create_codec(PyObject *module, PyObject *arg)
1967
1967
return (PyObject * )self ;
1968
1968
}
1969
1969
1970
- static struct PyMethodDef __methods [] = {
1971
- _MULTIBYTECODEC___CREATE_CODEC_METHODDEF
1972
- {NULL , NULL },
1973
- };
1970
+ static int
1971
+ _multibytecodec_traverse (PyObject * mod , visitproc visit , void * arg )
1972
+ {
1973
+ _multibytecodec_state * state = _multibytecodec_get_state (mod );
1974
+ Py_VISIT (state -> multibytecodec_type );
1975
+ Py_VISIT (state -> encoder_type );
1976
+ Py_VISIT (state -> decoder_type );
1977
+ Py_VISIT (state -> reader_type );
1978
+ Py_VISIT (state -> writer_type );
1979
+ return 0 ;
1980
+ }
1974
1981
1982
+ static int
1983
+ _multibytecodec_clear (PyObject * mod )
1984
+ {
1985
+ _multibytecodec_state * state = _multibytecodec_get_state (mod );
1986
+ Py_CLEAR (state -> multibytecodec_type );
1987
+ Py_CLEAR (state -> encoder_type );
1988
+ Py_CLEAR (state -> decoder_type );
1989
+ Py_CLEAR (state -> reader_type );
1990
+ Py_CLEAR (state -> writer_type );
1991
+ return 0 ;
1992
+ }
1975
1993
1976
- static struct PyModuleDef _multibytecodecmodule = {
1977
- .m_base = PyModuleDef_HEAD_INIT ,
1978
- .m_name = "_multibytecodec" ,
1979
- .m_size = sizeof (_multibytecodec_state ),
1980
- .m_methods = __methods ,
1981
- };
1994
+ static void
1995
+ _multibytecodec_free (void * m )
1996
+ {
1997
+ _multibytecodec_clear ((PyObject * )m );
1998
+ }
1982
1999
1983
2000
#define CREATE_TYPE (module , type , spec ) \
1984
2001
do { \
1985
2002
type = (PyTypeObject *)PyType_FromModuleAndSpec(module, spec, NULL); \
1986
2003
if (!type) { \
1987
- goto error; \
2004
+ return -1; \
1988
2005
} \
1989
2006
} while (0)
1990
2007
1991
2008
#define ADD_TYPE (module , type ) \
1992
2009
do { \
1993
2010
if (PyModule_AddType(module, type) < 0) { \
1994
- goto error; \
2011
+ return -1; \
1995
2012
} \
1996
2013
} while (0)
1997
2014
2015
+ static int
2016
+ _multibytecodec_exec (PyObject * mod )
2017
+ {
2018
+ _multibytecodec_state * state = _multibytecodec_get_state (mod );
2019
+ CREATE_TYPE (mod , state -> multibytecodec_type , & multibytecodec_spec );
2020
+ CREATE_TYPE (mod , state -> encoder_type , & encoder_spec );
2021
+ CREATE_TYPE (mod , state -> decoder_type , & decoder_spec );
2022
+ CREATE_TYPE (mod , state -> reader_type , & reader_spec );
2023
+ CREATE_TYPE (mod , state -> writer_type , & writer_spec );
2024
+
2025
+ ADD_TYPE (mod , state -> encoder_type );
2026
+ ADD_TYPE (mod , state -> decoder_type );
2027
+ ADD_TYPE (mod , state -> reader_type );
2028
+ ADD_TYPE (mod , state -> writer_type );
2029
+ return 0 ;
2030
+ }
2031
+
2032
+ static struct PyMethodDef __methods [] = {
2033
+ _MULTIBYTECODEC___CREATE_CODEC_METHODDEF
2034
+ {NULL , NULL },
2035
+ };
2036
+
2037
+ static PyModuleDef_Slot _multibytecodec_slots [] = {
2038
+ {Py_mod_exec , _multibytecodec_exec },
2039
+ {0 , NULL }
2040
+ };
2041
+
2042
+ static struct PyModuleDef _multibytecodecmodule = {
2043
+ .m_base = PyModuleDef_HEAD_INIT ,
2044
+ .m_name = "_multibytecodec" ,
2045
+ .m_size = sizeof (_multibytecodec_state ),
2046
+ .m_methods = __methods ,
2047
+ .m_slots = _multibytecodec_slots ,
2048
+ .m_traverse = _multibytecodec_traverse ,
2049
+ .m_clear = _multibytecodec_clear ,
2050
+ .m_free = _multibytecodec_free ,
2051
+ };
2052
+
1998
2053
PyMODINIT_FUNC
1999
2054
PyInit__multibytecodec (void )
2000
2055
{
2001
- PyObject * m = PyModule_Create (& _multibytecodecmodule );
2002
- if (m == NULL )
2003
- goto error ;
2004
-
2005
- _multibytecodec_state * state = _multibytecodec_get_state (m );
2006
- CREATE_TYPE (m , state -> multibytecodec_type , & multibytecodec_spec );
2007
- CREATE_TYPE (m , state -> encoder_type , & encoder_spec );
2008
- CREATE_TYPE (m , state -> decoder_type , & decoder_spec );
2009
- CREATE_TYPE (m , state -> reader_type , & reader_spec );
2010
- CREATE_TYPE (m , state -> writer_type , & writer_spec );
2011
-
2012
- ADD_TYPE (m , state -> encoder_type );
2013
- ADD_TYPE (m , state -> decoder_type );
2014
- ADD_TYPE (m , state -> reader_type );
2015
- ADD_TYPE (m , state -> writer_type );
2016
-
2017
- return m ;
2018
-
2019
- error :
2020
- Py_XDECREF (m );
2021
- return NULL ;
2056
+ return PyModuleDef_Init (& _multibytecodecmodule );
2022
2057
}
0 commit comments