| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…shal data Reading marshalled data from a FILE* did not check ferror() nor signals, so an I/O error or a Ctrl-C was reported as EOFError. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Documentation build overview77 files changed · + 1 added · ± 76 modified + Added ± Modified |
Sorry, something went wrong.
|
Failure on Windows is expected -- this is a bug #155905. |
Sorry, something went wrong.
PyMarshal_WriteObjectToFile() and PyMarshal_WriteLongToFile() now set the error indicator when writing to the underlying FILE* fails or is interrupted by a signal, instead of ignoring the failure. PyMarshal_WriteObjectToFile() now also sets the error indicator when the value cannot be marshalled. r_byte() no longer replaces an exception raised by a signal handler with EOFError. Document which exceptions the marshalling functions can raise. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
| Previously, in functions taking a :c:expr:`FILE*`, | ||
| the reading functions raised :exc:`EOFError` | ||
| instead of :exc:`OSError` and :exc:`KeyboardInterrupt`, | ||
| and the writing functions ignored I/O errors and interruptions. |
There was a problem hiding this comment.
marshal.load() and marshal.dump() error handling also changes and should be documented in Doc/library/marshal.rst.
Sorry, something went wrong.
There was a problem hiding this comment.
No, they are not affected. They do not use FILE* based C API.
Sorry, something went wrong.
There was a problem hiding this comment.
I checked again your change, you're right and I'm wrong. marshal.load() and marshal.dump() are not affected.
Sorry, something went wrong.
Preserve errno across PyErr_CheckSignals() when reporting a read error, rename w_set_error() to w_set_exception(), handle a PyNumber_AsSsize_t() failure explicitly, and check the error message in the test. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
LGTM. I just suggest renaming WFERR_ERROR_SET to WFERR_EXCEPTION_SET.
Sorry, something went wrong.
| #define WFERR_NESTEDTOODEEP 2 | ||
| #define WFERR_NOMEMORY 3 | ||
| #define WFERR_CODE_NOT_ALLOWED 4 | ||
| #define WFERR_ERROR_SET 5 /* An exception has already been raised. */ |
There was a problem hiding this comment.
You should rename the constant WFERR_EXCEPTION_SET since it's an "exception set", not an "error set".
Sorry, something went wrong.
| Previously, in functions taking a :c:expr:`FILE*`, | ||
| the reading functions raised :exc:`EOFError` | ||
| instead of :exc:`OSError` and :exc:`KeyboardInterrupt`, | ||
| and the writing functions ignored I/O errors and interruptions. |
There was a problem hiding this comment.
I checked again your change, you're right and I'm wrong. marshal.load() and marshal.dump() are not affected.
Sorry, something went wrong.
I don't think that it's a good idea to backport this change. Some projects can rely on the current exact exception raised by these C functions. It's ok to change them in Python 3.16, but IMO it's too risky to backport the change to stable versions. |
Sorry, something went wrong.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Thank you for your review. Initially it was smaller change, but it grew more after discovering more silenced/overridden errors. I plannet to fix the writing part in a separate issue, but is better for documentation if fix them together. |
Sorry, something went wrong.
…5909) Functions reading marshalled data from a FILE* now raise OSError for I/O errors and KeyboardInterrupt for interrupted reading, instead of EOFError. PyMarshal_WriteObjectToFile() and PyMarshal_WriteLongToFile() now detect I/O errors and interrupted writing instead of ignoring them. PyMarshal_WriteObjectToFile() now also sets the error indicator if the value cannot be marshalled. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
| Back | FazBrowse Home | New Git URL |
r_string(), r_byte() and PyMarshal_ReadLastObjectFromFile() did not check ferror() nor call PyErr_CheckSignals(), so a genuine I/O error or a read interrupted by Ctrl-C was reported as EOFError, as if the file had simply ended.
The writing side had the same gap: w_flush() and w_string() discarded the result of fwrite(), so a failed or interrupted write to a FILE* was ignored. PyMarshal_WriteObjectToFile() also never turned the recorded WFERR_* code into an exception, so even an unmarshallable value was ignored.
The WFERR_* to exception mapping is factored out of PyMarshal_WriteObjectToString() into w_set_error(), and all three writers now use it. This removes the note above PyMarshal_WriteLongToFile() saying that it never sets an exception and that doing so "should be regarded as an API-breaking change": detecting write errors makes it set one, which is what its documentation has promised since gh-105184.
The documentation of these functions listed only EOFError, ValueError and TypeError, which was inaccurate even before this change (MemoryError is raised when the read buffer cannot be allocated), so the per-function lists are replaced by one list for the whole section.