Skip to content

Commit

Permalink
Upgrade to simdjson 0.8. Fix a segfault reported by bishopfox.com.
Browse files Browse the repository at this point in the history
  • Loading branch information
TkTech committed Feb 4, 2021
1 parent 82938fc commit 19726b6
Show file tree
Hide file tree
Showing 5 changed files with 19,520 additions and 7,961 deletions.
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def __str__(self):
'-std=c++11'
])

if 'DEBUG' in os.environ:
extra_compile_args.append('-g')
extra_link_args.append('-g')


setup(
name='pysimdjson',
Expand Down
35 changes: 29 additions & 6 deletions simdjson/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ static inline py::object sv_to_unicode(std::string_view sv) {
/* pybind11 doesn't build in its string_view support if you're
* targeting c++11, even if string_view is available. So we do it
* ourselves. */
return py::reinterpret_steal<py::object>(
PyUnicode_FromStringAndSize(sv.data(), sv.size())
);
PyObject *obj = PyUnicode_FromStringAndSize(sv.data(), sv.size());
if (!obj) {
throw py::error_already_set();
}
return py::reinterpret_steal<py::object>(obj);
}

static inline py::dict object_to_dict(dom::object obj, bool recursive) {
Expand Down Expand Up @@ -353,17 +355,38 @@ PYBIND11_MODULE(csimdjson, m) {
" python objects instead of pysimdjson proxies."
)
.def("parse",
[](dom::parser &self, const std::string &s, bool recursive = false) {
[](dom::parser &self, py::buffer src, bool recursive = false) {
py::buffer_info info = src.request();

if (info.format != py::format_descriptor<uint8_t>::format()) {
throw py::value_error(
"buffer passed to parse() is an invalid format"
);
}

if (info.ndim != 1) {
throw py::value_error(
"buffer passed to parse() must be flat."
);
}

return element_to_primitive(
self.parse(padded_string(s)),
self.parse(
padded_string(
std::string_view(
(const char *)info.ptr,
info.itemsize * info.size
)
)
),
recursive
);
},
py::arg("s"),
py::arg("recursive") = false,
"Parse a JSON document from the byte string `s`.\n"
"\n"
":param s: The document to parse.\n"
":param buff: The document to parse.\n"
":param recursive: Recursively turn the document into real\n"
" python objects instead of pysimdjson proxies."
)
Expand Down
Loading

0 comments on commit 19726b6

Please sign in to comment.