@@ -136,14 +136,48 @@ weakref_functions[] = {
136
136
{NULL , NULL , 0 , NULL }
137
137
};
138
138
139
+ static int
140
+ weakref_exec (PyObject * module )
141
+ {
142
+ Py_INCREF (& _PyWeakref_RefType );
143
+ if (PyModule_AddObject (module , "ref" , (PyObject * ) & _PyWeakref_RefType ) < 0 ) {
144
+ Py_DECREF (& _PyWeakref_RefType );
145
+ return -1 ;
146
+ }
147
+ Py_INCREF (& _PyWeakref_RefType );
148
+ if (PyModule_AddObject (module , "ReferenceType" ,
149
+ (PyObject * ) & _PyWeakref_RefType ) < 0 ) {
150
+ Py_DECREF (& _PyWeakref_RefType );
151
+ return -1 ;
152
+ }
153
+ Py_INCREF (& _PyWeakref_ProxyType );
154
+ if (PyModule_AddObject (module , "ProxyType" ,
155
+ (PyObject * ) & _PyWeakref_ProxyType ) < 0 ) {
156
+ Py_DECREF (& _PyWeakref_ProxyType );
157
+ return -1 ;
158
+ }
159
+ Py_INCREF (& _PyWeakref_CallableProxyType );
160
+ if (PyModule_AddObject (module , "CallableProxyType" ,
161
+ (PyObject * ) & _PyWeakref_CallableProxyType ) < 0 ) {
162
+ Py_DECREF (& _PyWeakref_CallableProxyType );
163
+ return -1 ;
164
+ }
165
+
166
+ return 0 ;
167
+ }
168
+
169
+ static struct PyModuleDef_Slot weakref_slots [] = {
170
+ {Py_mod_exec , weakref_exec },
171
+ {0 , NULL }
172
+ };
139
173
140
174
static struct PyModuleDef weakrefmodule = {
141
175
PyModuleDef_HEAD_INIT ,
142
176
"_weakref" ,
143
177
"Weak-reference support module." ,
144
- -1 ,
178
+ 0 ,
145
179
weakref_functions ,
146
- NULL ,
180
+ weakref_slots ,
147
181
NULL ,
148
182
NULL ,
149
183
NULL
@@ -152,23 +186,5 @@ static struct PyModuleDef weakrefmodule = {
152
186
PyMODINIT_FUNC
153
187
PyInit__weakref (void )
154
188
{
155
- PyObject * m ;
156
-
157
- m = PyModule_Create (& weakrefmodule );
158
-
159
- if (m != NULL ) {
160
- Py_INCREF (& _PyWeakref_RefType );
161
- PyModule_AddObject (m , "ref" ,
162
- (PyObject * ) & _PyWeakref_RefType );
163
- Py_INCREF (& _PyWeakref_RefType );
164
- PyModule_AddObject (m , "ReferenceType" ,
165
- (PyObject * ) & _PyWeakref_RefType );
166
- Py_INCREF (& _PyWeakref_ProxyType );
167
- PyModule_AddObject (m , "ProxyType" ,
168
- (PyObject * ) & _PyWeakref_ProxyType );
169
- Py_INCREF (& _PyWeakref_CallableProxyType );
170
- PyModule_AddObject (m , "CallableProxyType" ,
171
- (PyObject * ) & _PyWeakref_CallableProxyType );
172
- }
173
- return m ;
189
+ return PyModuleDef_Init (& weakrefmodule );
174
190
}
0 commit comments