https://github.com/python/cpython/commit/9ad86052ece309e34e496829ba8588f6e6d69ba0 commit: 9ad86052ece309e34e496829ba8588f6e6d69ba0 branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: gpshead <[email protected]> date: 2026-10-11T21:58:18Z summary:
[3.15] gh-159185: Document that PyMarshal_WriteObjectToFile can silently truncate before 3.16 (GH-159201) (#159202) gh-159185: Document that PyMarshal_WriteObjectToFile can silently truncate before 3.16 (GH-159201) gh-159185: Document that the PyMarshal file writers can fail silently before 3.16 In Python 3.15 and earlier, PyMarshal_WriteObjectToFile() ignores most marshalling errors and all I/O errors: it returns without setting the error indicator after writing only part of the data. PyMarshal_WriteLongToFile() ignores I/O errors in the same way. That was fixed in 3.16 by gh-155907, which is not backported. Tell the users of the older versions so that they can check what was written. (cherry picked from commit b3714a5fb7a3aadd72134ee0710b22519c1df09a) Co-authored-by: Gregory P. Smith <[email protected]> files: M Doc/c-api/marshal.rst diff --git a/Doc/c-api/marshal.rst b/Doc/c-api/marshal.rst index 668a163b2df5a1..e430aa66518f37 100644 --- a/Doc/c-api/marshal.rst +++ b/Doc/c-api/marshal.rst @@ -29,6 +29,12 @@ the :py:mod:`Python module documentation <marshal>` for details. This function can fail, in which case it sets the error indicator. Use :c:func:`PyErr_Occurred` to check for that. + .. note:: + + In Python 3.15 and earlier, this function does not set the error + indicator if writing to *file* fails. + The same caveat applies as for :c:func:`PyMarshal_WriteObjectToFile`. + .. c:function:: void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version) Marshal a Python object, *value*, to *file*. @@ -37,6 +43,17 @@ the :py:mod:`Python module documentation <marshal>` for details. This function can fail, in which case it sets the error indicator. Use :c:func:`PyErr_Occurred` to check for that. + .. note:: + + In Python 3.15 and earlier, this function can write only part of the + data to *file* and return without setting the error indicator, for + example if *value* contains an object which cannot be marshalled or + if writing to *file* fails (see :gh:`155907`). + Code which has to support these versions cannot rely on + :c:func:`PyErr_Occurred` alone to know that all the data was written. + It can use :c:func:`PyMarshal_WriteObjectToString` and write the + result itself, or validate what was written. + .. c:function:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version) Return a bytes object containing the marshalled representation of *value*. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
