Skip to content

Commit

Permalink
Fix segmentation fault
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Feb 10, 2025
1 parent 069ed49 commit 61d4364
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions docs/source/how-to.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ Encoding protocol-based objects

Required methods:

- ``"bool"``: :meth:`~object.__bool__` or :meth:`~object.__len__`
- ``"float"``: :meth:`~object.__float__`
- ``"int"``: :meth:`~object.__int__`
- ``"bool"``: :meth:`~object.__bool__`, :meth:`~object.__len__` or absent for ``true``
- ``"float"``: :meth:`~object.__float__` or :meth:`~object.__index__`
- ``"int"``: :meth:`~object.__int__` or :meth:`~object.__index__`
- ``"mapping"``: :meth:`~object.__len__`, :meth:`!keys`, :meth:`!values` and :meth:`!items`
- ``"sequence"``: :meth:`~object.__len__`, and :meth:`~object.__iter__`
- ``"str"``: :meth:`~object.__str__`
- ``"str"``: :meth:`~object.__str__` or :meth:`~object.__repr__`

Example with :mod:`numpy`:

Expand Down
4 changes: 2 additions & 2 deletions src/jsonyx/_speedups.c
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ encoder_listencode_obj(PyEncoderObject *s, PyObject *markers, _PyUnicodeWriter *
else if (PyLong_Check(obj) || PyObject_IsInstance(obj, s->int_types)) {
if (PyErr_Occurred())
return -1;
new_obj = Py_TYPE(obj)->tp_as_number->nb_int(obj);
new_obj = PyNumber_Long(obj);
if (new_obj == NULL)
return -1;
PyObject *encoded = PyLong_Type.tp_repr(new_obj);
Expand All @@ -1710,7 +1710,7 @@ encoder_listencode_obj(PyEncoderObject *s, PyObject *markers, _PyUnicodeWriter *
else if (PyFloat_Check(obj) || PyObject_IsInstance(obj, s->float_types)) {
if (PyErr_Occurred())
return -1;
new_obj = Py_TYPE(obj)->tp_as_number->nb_float(obj);
new_obj = PyNumber_Float(obj);
if (new_obj == NULL)
return -1;
PyObject *encoded = encoder_encode_float(s, new_obj);
Expand Down

0 comments on commit 61d4364

Please sign in to comment.