@@ -81,19 +81,6 @@ OutputBuffer_OnError(_BlocksOutputBuffer *buffer)
81
81
#define RELEASE_LOCK (obj ) PyThread_release_lock((obj)->lock)
82
82
83
83
84
- typedef struct {
85
- PyTypeObject * bz2_compressor_type ;
86
- PyTypeObject * bz2_decompressor_type ;
87
- } _bz2_state ;
88
-
89
- static inline _bz2_state *
90
- get_bz2_state (PyObject * module )
91
- {
92
- void * state = PyModule_GetState (module );
93
- assert (state != NULL );
94
- return (_bz2_state * )state ;
95
- }
96
-
97
84
typedef struct {
98
85
PyObject_HEAD
99
86
bz_stream bzs ;
@@ -775,67 +762,40 @@ static PyType_Spec bz2_decompressor_type_spec = {
775
762
static int
776
763
_bz2_exec (PyObject * module )
777
764
{
778
- _bz2_state * state = get_bz2_state (module );
779
- state -> bz2_compressor_type = (PyTypeObject * )PyType_FromModuleAndSpec (module ,
765
+ PyTypeObject * bz2_compressor_type = (PyTypeObject * )PyType_FromModuleAndSpec (module ,
780
766
& bz2_compressor_type_spec , NULL );
781
- if (state -> bz2_compressor_type == NULL ) {
767
+ if (bz2_compressor_type == NULL ) {
782
768
return -1 ;
783
769
}
784
-
785
- if (PyModule_AddType (module , state -> bz2_compressor_type ) < 0 ) {
770
+ int rc = PyModule_AddType (module , bz2_compressor_type );
771
+ Py_DECREF (bz2_compressor_type );
772
+ if (rc < 0 ) {
786
773
return -1 ;
787
774
}
788
775
789
- state -> bz2_decompressor_type = (PyTypeObject * )PyType_FromModuleAndSpec (module ,
776
+ PyTypeObject * bz2_decompressor_type = (PyTypeObject * )PyType_FromModuleAndSpec (module ,
790
777
& bz2_decompressor_type_spec , NULL );
791
- if (state -> bz2_decompressor_type == NULL ) {
778
+ if (bz2_decompressor_type == NULL ) {
792
779
return -1 ;
793
780
}
794
-
795
- if (PyModule_AddType (module , state -> bz2_decompressor_type ) < 0 ) {
781
+ rc = PyModule_AddType (module , bz2_decompressor_type );
782
+ Py_DECREF (bz2_decompressor_type );
783
+ if (rc < 0 ) {
796
784
return -1 ;
797
785
}
798
786
799
787
return 0 ;
800
788
}
801
789
802
- static int
803
- _bz2_traverse (PyObject * module , visitproc visit , void * arg )
804
- {
805
- _bz2_state * state = get_bz2_state (module );
806
- Py_VISIT (state -> bz2_compressor_type );
807
- Py_VISIT (state -> bz2_decompressor_type );
808
- return 0 ;
809
- }
810
-
811
- static int
812
- _bz2_clear (PyObject * module )
813
- {
814
- _bz2_state * state = get_bz2_state (module );
815
- Py_CLEAR (state -> bz2_compressor_type );
816
- Py_CLEAR (state -> bz2_decompressor_type );
817
- return 0 ;
818
- }
819
-
820
- static void
821
- _bz2_free (void * module )
822
- {
823
- _bz2_clear ((PyObject * )module );
824
- }
825
-
826
790
static struct PyModuleDef_Slot _bz2_slots [] = {
827
791
{Py_mod_exec , _bz2_exec },
828
792
{0 , NULL }
829
793
};
830
794
831
795
static struct PyModuleDef _bz2module = {
832
- PyModuleDef_HEAD_INIT ,
796
+ . m_base = PyModuleDef_HEAD_INIT ,
833
797
.m_name = "_bz2" ,
834
- .m_size = sizeof (_bz2_state ),
835
798
.m_slots = _bz2_slots ,
836
- .m_traverse = _bz2_traverse ,
837
- .m_clear = _bz2_clear ,
838
- .m_free = _bz2_free ,
839
799
};
840
800
841
801
PyMODINIT_FUNC
0 commit comments