[Python-checkins] [3.8] gh-105184: document that marshal functions can fail and need to be checked with PyErr_Occurred (GH-105185) (#105222)
ambv
webhook-mailer at python.org
Mon Jun 5 11:41:26 EDT 2023
https://github.com/python/cpython/commit/c43c50e07ec35e4f66b6893fd940b8e098a12eb2
commit: c43c50e07ec35e4f66b6893fd940b8e098a12eb2
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2023-06-05T17:41:14+02:00
summary:
[3.8] gh-105184: document that marshal functions can fail and need to be checked with PyErr_Occurred (GH-105185) (#105222)
(cherry picked from commit ee26ca13a129da8cf549409d0a1b2e892ff2b4ec)
Co-authored-by: Irit Katriel <1055913+iritkatriel at users.noreply.github.com>
files:
M Doc/c-api/marshal.rst
M Python/marshal.c
diff --git a/Doc/c-api/marshal.rst b/Doc/c-api/marshal.rst
index 7bb0dad2b6b6d..027ffd5812413 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:type:`long` type. *version* indicates the file format.
+ This function can fail, in which case it sets the error indicator.
+ Use :c:func:`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 :c:func:`PyErr_Occurred` to check for that.
.. c:function:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version)
diff --git a/Python/marshal.c b/Python/marshal.c
index a9ba7a436fd19..99075b1081020 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -601,6 +601,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)
{
More information about the Python-checkins
mailing list