Skip to content

Multi Phase JSON Initialization #30805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 7 additions & 27 deletions pandas/_libs/src/ujson/python/ujson.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,15 @@ static PyMethodDef ujsonMethods[] = {
{NULL, NULL, 0, NULL} /* Sentinel */
};

static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"_libjson",
0, /* m_doc */
-1, /* m_size */
ujsonMethods, /* m_methods */
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL /* m_free */
static PyModuleDef moduledef = {
.m_base = PyModuleDef_HEAD_INIT,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Designated initializers are C99 standard and supported by MS since Visual Studio 2013. Orthogoanl here but I figured made things more readable and less verbose

.m_name = "_libjson",
.m_methods = ujsonMethods
};

#define PYMODINITFUNC PyMODINIT_FUNC PyInit_json(void)
#define PYMODULE_CREATE() PyModule_Create(&moduledef)
#define MODINITERROR return NULL

PYMODINITFUNC {
PyObject *module;
PyObject *version_string;
PyMODINIT_FUNC PyInit_json(void) {
initObjToJSON(); // TODO: clean up, maybe via tp_free?
return PyModuleDef_Init(&moduledef);

initObjToJSON();
module = PYMODULE_CREATE();

if (module == NULL) {
MODINITERROR;
}

version_string = PyUnicode_FromString(UJSON_VERSION);
PyModule_AddObject(module, "__version__", version_string);

return module;
}
5 changes: 0 additions & 5 deletions pandas/tests/io/json/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,6 @@ def test_loads_non_str_bytes_raises(self):
with pytest.raises(TypeError, match=msg):
ujson.loads(None)

def test_version(self):
assert re.match(
r"^\d+\.\d+(\.\d+)?$", ujson.__version__
), "ujson.__version__ must be a string like '1.4.0'"

def test_encode_numeric_overflow(self):
with pytest.raises(OverflowError):
ujson.encode(12839128391289382193812939)
Expand Down