diff --git a/Doc/c-api/marshal.rst b/Doc/c-api/marshal.rst --- a/Doc/c-api/marshal.rst +++ b/Doc/c-api/marshal.rst @@ -35,39 +35,45 @@ unmarshalling. Version 2 uses a binary .. c:function:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version) Return a string object containing the marshalled representation of *value*. *version* indicates the file format. The following functions allow marshalled values to be read back in. -XXX What about error detection? It appears that reading past the end of the -file will always result in a negative numeric value (where that's relevant), -but it's not clear that negative values won't be handled properly when there's -no error. What's the right way to tell? Should only non-negative values be -written using these routines? - .. c:function:: long PyMarshal_ReadLongFromFile(FILE *file) Return a C :c:type:`long` from the data stream in a :c:type:`FILE\*` opened for reading. Only a 32-bit value can be read in using this function, regardless of the native size of :c:type:`long`. - On error, raise an exception and return ``-1``. + On error, raises an exception and returns ``-1``. It is advised to check + return values of both of the ``PyMarshal_ReadLongFromFile`` and + :c:func:`PyErr_Occurred` functions:: + + if (f == -1 && PyErr_Occurred()) { + /* do something */ + } .. c:function:: int PyMarshal_ReadShortFromFile(FILE *file) Return a C :c:type:`short` from the data stream in a :c:type:`FILE\*` opened for reading. Only a 16-bit value can be read in using this function, regardless of the native size of :c:type:`short`. - On error, raise an exception and return ``-1``. + On error, raises an exception and returns ``-1``. It is advised to check + return values of both of the ``PyMarshal_ReadShortFromFile`` and + :c:func:`PyErr_Occurred` functions:: + + if (f == -1 && PyErr_Occurred()) { + /* do something */ + } .. c:function:: PyObject* PyMarshal_ReadObjectFromFile(FILE *file) Return a Python object from the data stream in a :c:type:`FILE\*` opened for reading. On error, sets the appropriate exception (:exc:`EOFError` or