Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port _json extension module to multiphase initialization(PEP 489).
52 changes: 30 additions & 22 deletions Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1863,40 +1863,48 @@ static PyMethodDef speedups_methods[] = {
PyDoc_STRVAR(module_doc,
"json speedups\n");

static struct PyModuleDef jsonmodule = {
PyModuleDef_HEAD_INIT,
"_json",
module_doc,
-1,
speedups_methods,
NULL,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC
PyInit__json(void)
static int
_json_exec(PyObject *module)
{
PyObject *m = PyModule_Create(&jsonmodule);
if (!m)
return NULL;
if (PyType_Ready(&PyScannerType) < 0)
goto fail;
if (PyType_Ready(&PyEncoderType) < 0)
goto fail;
Py_INCREF((PyObject*)&PyScannerType);
if (PyModule_AddObject(m, "make_scanner", (PyObject*)&PyScannerType) < 0) {
if (PyModule_AddObject(module, "make_scanner", (PyObject*)&PyScannerType) < 0) {
Py_DECREF((PyObject*)&PyScannerType);
goto fail;
}
Py_INCREF((PyObject*)&PyEncoderType);
if (PyModule_AddObject(m, "make_encoder", (PyObject*)&PyEncoderType) < 0) {
if (PyModule_AddObject(module, "make_encoder", (PyObject*)&PyEncoderType) < 0) {
Py_DECREF((PyObject*)&PyEncoderType);
goto fail;
}
return m;
return 0;
fail:
Py_DECREF(m);
return NULL;
Py_DECREF(module);
return -1;
}

static PyModuleDef_Slot _json_slots[] = {
{Py_mod_exec, _json_exec},
{0, NULL}
};

static struct PyModuleDef jsonmodule = {
PyModuleDef_HEAD_INIT,
"_json",
module_doc,
0,
speedups_methods,
_json_slots,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC
PyInit__json(void)
{
return PyModuleDef_Init(&jsonmodule);
}