@@ -16,6 +16,20 @@ Numeric values are stored with the least significant byte first.
1616The module supports several versions of the data format; see
1717the :py:mod: `Python module documentation <marshal> ` for details.
1818
19+ The following exceptions can be raised by these functions:
20+ :exc: `ValueError ` if the value cannot be marshalled,
21+ :exc: `ValueError ` or :exc: `TypeError ` if the data is malformed,
22+ :exc: `EOFError ` if the end of the data is reached before the value is complete,
23+ :exc: `OSError ` if reading from or writing to a :c:expr: `FILE* ` fails,
24+ :exc: `KeyboardInterrupt ` if reading or writing is interrupted by a signal,
25+ and :exc: `MemoryError ` if memory allocation fails.
26+
27+ .. versionchanged :: next
28+ Previously, in functions taking a :c:expr: `FILE* `,
29+ the reading functions raised :exc: `EOFError `
30+ instead of :exc: `OSError ` and :exc: `KeyboardInterrupt `,
31+ and the writing functions ignored I/O errors and interruptions.
32+
1933.. c :macro :: Py_MARSHAL_VERSION
2034
2135 The current format version. See :py:data: `marshal.version `.
@@ -42,6 +56,8 @@ the :py:mod:`Python module documentation <marshal>` for details.
4256 Return a bytes object containing the marshalled representation of *value *.
4357 *version * indicates the file format.
4458
59+ On error, raises an exception and returns ``NULL ``.
60+
4561
4662The following functions allow marshalled values to be read back in.
4763
@@ -52,8 +68,7 @@ The following functions allow marshalled values to be read back in.
5268 for reading. Only a 32-bit value can be read in using this function,
5369 regardless of the native size of :c:expr: `long `.
5470
55- On error, sets the appropriate exception (:exc: `EOFError `) and returns
56- ``-1``.
71+ On error, raises an exception and returns ``-1 ``.
5772
5873
5974.. c :function :: int PyMarshal_ReadShortFromFile (FILE *file)
@@ -62,17 +77,15 @@ The following functions allow marshalled values to be read back in.
6277 for reading. Only a 16-bit value can be read in using this function,
6378 regardless of the native size of :c:expr: `short `.
6479
65- On error, sets the appropriate exception (:exc: `EOFError `) and returns
66- ``-1``.
80+ On error, raises an exception and returns ``-1 ``.
6781
6882
6983.. c :function :: PyObject* PyMarshal_ReadObjectFromFile (FILE *file)
7084
7185 Return a Python object from the data stream in a :c:expr: `FILE* ` opened for
7286 reading.
7387
74- On error, sets the appropriate exception (:exc: `EOFError `, :exc: `ValueError `
75- or :exc: `TypeError `) and returns ``NULL``.
88+ On error, raises an exception and returns ``NULL ``.
7689
7790
7891.. c :function :: PyObject* PyMarshal_ReadLastObjectFromFile (FILE *file)
@@ -85,15 +98,13 @@ The following functions allow marshalled values to be read back in.
8598 file. Only use this variant if you are certain that you won't be reading
8699 anything else from the file.
87100
88- On error, sets the appropriate exception (:exc: `EOFError `, :exc: `ValueError `
89- or :exc: `TypeError `) and returns ``NULL``.
101+ On error, raises an exception and returns ``NULL ``.
90102
91103
92104.. c :function :: PyObject* PyMarshal_ReadObjectFromString (const char *data, Py_ssize_t len)
93105
94106 Return a Python object from the data stream in a byte buffer
95107 containing *len * bytes pointed to by *data *.
96108
97- On error, sets the appropriate exception (:exc: `EOFError `, :exc: `ValueError `
98- or :exc: `TypeError `) and returns ``NULL``.
109+ On error, raises an exception and returns ``NULL ``.
99110
0 commit comments