@@ -24,7 +24,7 @@ The following exceptions can be raised by these functions:
2424:exc: `KeyboardInterrupt ` if reading or writing is interrupted by a signal,
2525and :exc: `MemoryError ` if memory allocation fails.
2626
27- .. versionchanged :: next
27+ .. versionchanged :: 3.16
2828 Previously, in functions taking a :c:expr: `FILE* `,
2929 the reading functions raised :exc: `EOFError `
3030 instead of :exc: `OSError ` and :exc: `KeyboardInterrupt `,
@@ -43,14 +43,40 @@ and :exc:`MemoryError` if memory allocation fails.
4343 This function can fail, in which case it sets the error indicator.
4444 Use :c:func: `PyErr_Occurred ` to check for that.
4545
46+ .. note ::
47+
48+ In Python 3.15 and earlier, this function does not set the error
49+ indicator if writing to *file * fails.
50+ The same caveat applies as for :c:func: `PyMarshal_WriteObjectToFile `.
51+
4652.. c :function :: void PyMarshal_WriteObjectToFile (PyObject *value, FILE *file, int version)
4753
4854 Marshal a Python object, *value *, to *file *.
4955 *version * indicates the file format.
5056
57+ The marshalled representation of *value * is built in memory
58+ and then written to *file *.
59+ Nothing is written if *value * cannot be marshalled.
60+
5161 This function can fail, in which case it sets the error indicator.
5262 Use :c:func: `PyErr_Occurred ` to check for that.
5363
64+ .. note ::
65+
66+ In Python 3.15 and earlier, this function can write only part of the
67+ data to *file * and return without setting the error indicator, for
68+ example if *value * contains an object which cannot be marshalled or
69+ if writing to *file * fails (see :gh: `155907 `).
70+ Code which has to support these versions cannot rely on
71+ :c:func:`PyErr_Occurred` alone to know that all the data was written.
72+ It can use :c:func:`PyMarshal_WriteObjectToString` and write the
73+ result itself, or validate what was written.
74+
75+ .. versionchanged:: 3.16
76+ Previously, the data was written to *file* as it was produced,
77+ using a buffer of constant size,
78+ and incomplete data was written if *value* could not be marshalled.
79+
5480.. c:function:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version)
5581
5682 Return a bytes object containing the marshalled representation of *value *.
0 commit comments