Revert "bpo-1635741: Port _weakref extension module to multiphase ini… · python/cpython@188078c
@@ -136,48 +136,14 @@ weakref_functions[] = {
136136 {NULL, NULL, 0, NULL}
137137};
138138139-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-};
173139174140static struct PyModuleDef weakrefmodule = {
175141PyModuleDef_HEAD_INIT,
176142"_weakref",
177143"Weak-reference support module.",
178-0,
144+-1,
179145weakref_functions,
180-weakref_slots,
146+NULL,
181147NULL,
182148NULL,
183149NULL
@@ -186,5 +152,23 @@ static struct PyModuleDef weakrefmodule = {
186152PyMODINIT_FUNC
187153PyInit__weakref(void)
188154{
189-return PyModuleDef_Init(&weakrefmodule);
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;
190174}