Skip to content

Commit

Permalink
[3.10] gh-105184: document that marshal functions can fail and need t…
Browse files Browse the repository at this point in the history
…o be checked with PyErr_Occurred (GH-105185) (#105220)

(cherry picked from commit ee26ca1)

Co-authored-by: Irit Katriel <[email protected]>
  • Loading branch information
miss-islington and iritkatriel authored Jun 5, 2023
1 parent 6cae236 commit f12502b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Doc/c-api/marshal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ unmarshalling. Version 2 uses a binary format for floating point numbers.
the least-significant 32 bits of *value*; regardless of the size of the
native :c:expr:`long` type. *version* indicates the file format.
This function can fail, in which case it sets the error indicator.
Use :c:func:`PyErr_Occurred` to check for that.
.. c:function:: void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version)
Marshal a Python object, *value*, to *file*.
*version* indicates the file format.
This function can fail, in which case it sets the error indicator.
Use :c:func:`PyErr_Occurred` to check for that.
.. c:function:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version)
Expand Down
4 changes: 4 additions & 0 deletions Python/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,10 @@ w_clear_refs(WFILE *wf)
}

/* version currently has no effect for writing ints. */
/* Note that while the documentation states that this function
* can error, currently it never does. Setting an exception in
* this function should be regarded as an API-breaking change.
*/
void
PyMarshal_WriteLongToFile(long x, FILE *fp, int version)
{
Expand Down

0 comments on commit f12502b

Please sign in to comment.