From 212c72eddd98429e534df4b44a07eb283dde2581 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 1 Jun 2023 10:39:17 +0100 Subject: [PATCH 1/3] gh-105184: document that marshal functions can fail and need to be checked with PyErr_Occurred --- Doc/c-api/marshal.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/c-api/marshal.rst b/Doc/c-api/marshal.rst index 8e25968c6909fd..69d6994d1a3d62 100644 --- a/Doc/c-api/marshal.rst +++ b/Doc/c-api/marshal.rst @@ -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 ``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 ``PyErr_Occurred()`` to check for that. .. c:function:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version) From df93125004f87736b46d58dad61671cc4bb9a063 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 1 Jun 2023 11:06:29 +0100 Subject: [PATCH 2/3] add comment --- Python/marshal.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Python/marshal.c b/Python/marshal.c index 208996b05fc484..6439503d2c6879 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -625,6 +625,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) { From a2c72fbc8be78d9bb9a88136ae74d890b71d4012 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Thu, 1 Jun 2023 23:01:34 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Erlend E. Aasland --- Doc/c-api/marshal.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/marshal.rst b/Doc/c-api/marshal.rst index 69d6994d1a3d62..489f1580a414b2 100644 --- a/Doc/c-api/marshal.rst +++ b/Doc/c-api/marshal.rst @@ -26,7 +26,7 @@ unmarshalling. Version 2 uses a binary format for floating point numbers. native :c:expr:`long` type. *version* indicates the file format. This function can fail, in which case it sets the error indicator. - Use ``PyErr_Occurred()`` to check for that. + Use :c:func:`PyErr_Occurred` to check for that. .. c:function:: void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version) @@ -34,7 +34,7 @@ unmarshalling. Version 2 uses a binary format for floating point numbers. *version* indicates the file format. This function can fail, in which case it sets the error indicator. - Use ``PyErr_Occurred()`` to check for that. + Use :c:func:`PyErr_Occurred` to check for that. .. c:function:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version)