Skip to content

Commit 9720442

Browse files
WillAydjreback
authored andcommitted
multi phase json init (#30805)
1 parent ac9901b commit 9720442

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

pandas/_libs/src/ujson/python/ujson.c

+7-27
Original file line numberDiff line numberDiff line change
@@ -65,35 +65,15 @@ static PyMethodDef ujsonMethods[] = {
6565
{NULL, NULL, 0, NULL} /* Sentinel */
6666
};
6767

68-
static struct PyModuleDef moduledef = {
69-
PyModuleDef_HEAD_INIT,
70-
"_libjson",
71-
0, /* m_doc */
72-
-1, /* m_size */
73-
ujsonMethods, /* m_methods */
74-
NULL, /* m_reload */
75-
NULL, /* m_traverse */
76-
NULL, /* m_clear */
77-
NULL /* m_free */
68+
static PyModuleDef moduledef = {
69+
.m_base = PyModuleDef_HEAD_INIT,
70+
.m_name = "_libjson",
71+
.m_methods = ujsonMethods
7872
};
7973

80-
#define PYMODINITFUNC PyMODINIT_FUNC PyInit_json(void)
81-
#define PYMODULE_CREATE() PyModule_Create(&moduledef)
82-
#define MODINITERROR return NULL
8374

84-
PYMODINITFUNC {
85-
PyObject *module;
86-
PyObject *version_string;
75+
PyMODINIT_FUNC PyInit_json(void) {
76+
initObjToJSON(); // TODO: clean up, maybe via tp_free?
77+
return PyModuleDef_Init(&moduledef);
8778

88-
initObjToJSON();
89-
module = PYMODULE_CREATE();
90-
91-
if (module == NULL) {
92-
MODINITERROR;
93-
}
94-
95-
version_string = PyUnicode_FromString(UJSON_VERSION);
96-
PyModule_AddObject(module, "__version__", version_string);
97-
98-
return module;
9979
}

pandas/tests/io/json/test_ujson.py

-5
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,6 @@ def test_loads_non_str_bytes_raises(self):
559559
with pytest.raises(TypeError, match=msg):
560560
ujson.loads(None)
561561

562-
def test_version(self):
563-
assert re.match(
564-
r"^\d+\.\d+(\.\d+)?$", ujson.__version__
565-
), "ujson.__version__ must be a string like '1.4.0'"
566-
567562
def test_encode_numeric_overflow(self):
568563
with pytest.raises(OverflowError):
569564
ujson.encode(12839128391289382193812939)

0 commit comments

Comments
 (0)