@@ -120,18 +120,6 @@ typedef struct {
120
120
access_mode access ;
121
121
} mmap_object ;
122
122
123
- typedef struct {
124
- PyTypeObject * mmap_object_type ;
125
- } mmap_state ;
126
-
127
- static mmap_state *
128
- get_mmap_state (PyObject * module )
129
- {
130
- mmap_state * state = PyModule_GetState (module );
131
- assert (state );
132
- return state ;
133
- }
134
-
135
123
static int
136
124
mmap_object_traverse (mmap_object * m_obj , visitproc visit , void * arg )
137
125
{
@@ -1555,46 +1543,23 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
1555
1543
}
1556
1544
#endif /* MS_WINDOWS */
1557
1545
1558
- static int
1559
- mmap_traverse (PyObject * module , visitproc visit , void * arg )
1560
- {
1561
- mmap_state * state = get_mmap_state (module );
1562
- Py_VISIT (state -> mmap_object_type );
1563
- return 0 ;
1564
- }
1565
-
1566
- static int
1567
- mmap_clear (PyObject * module )
1568
- {
1569
- mmap_state * state = get_mmap_state (module );
1570
- Py_CLEAR (state -> mmap_object_type );
1571
- return 0 ;
1572
- }
1573
-
1574
- static void
1575
- mmap_free (void * module )
1576
- {
1577
- mmap_clear ((PyObject * )module );
1578
- }
1579
-
1580
1546
static int
1581
1547
mmap_exec (PyObject * module )
1582
1548
{
1583
- mmap_state * state = get_mmap_state (module );
1584
-
1585
1549
Py_INCREF (PyExc_OSError );
1586
1550
if (PyModule_AddObject (module , "error" , PyExc_OSError ) < 0 ) {
1587
1551
Py_DECREF (PyExc_OSError );
1588
1552
return -1 ;
1589
1553
}
1590
1554
1591
- state -> mmap_object_type = (PyTypeObject * )PyType_FromModuleAndSpec (module ,
1592
- & mmap_object_spec ,
1593
- NULL );
1594
- if (state -> mmap_object_type == NULL ) {
1555
+ PyObject * mmap_object_type = PyType_FromModuleAndSpec (module ,
1556
+ & mmap_object_spec , NULL );
1557
+ if (mmap_object_type == NULL ) {
1595
1558
return -1 ;
1596
1559
}
1597
- if (PyModule_AddType (module , state -> mmap_object_type ) < 0 ) {
1560
+ int rc = PyModule_AddType (module , (PyTypeObject * )mmap_object_type );
1561
+ Py_DECREF (mmap_object_type );
1562
+ if (rc < 0 ) {
1598
1563
return -1 ;
1599
1564
}
1600
1565
@@ -1744,13 +1709,10 @@ static PyModuleDef_Slot mmap_slots[] = {
1744
1709
};
1745
1710
1746
1711
static struct PyModuleDef mmapmodule = {
1747
- PyModuleDef_HEAD_INIT ,
1712
+ . m_base = PyModuleDef_HEAD_INIT ,
1748
1713
.m_name = "mmap" ,
1749
- .m_size = sizeof ( mmap_state ) ,
1714
+ .m_size = 0 ,
1750
1715
.m_slots = mmap_slots ,
1751
- .m_traverse = mmap_traverse ,
1752
- .m_clear = mmap_clear ,
1753
- .m_free = mmap_free ,
1754
1716
};
1755
1717
1756
1718
PyMODINIT_FUNC
0 commit comments