Repository navigation
Conversation
…ent of reference counts (pythonGH-159192) The marshal writer decided whether an object can be referenced later (FLAG_REF) from its reference count, so the output for the same value depended on what else in the process held a reference to its parts, and differed between the default and the free-threaded builds' view of the same objects. This is the remaining cause of pythongh-129724 and the cause of pythongh-156504. FLAG_REF is now set exactly on the objects which are written more than once in the dump. The writer still makes one pass: it records the position of the type byte of each object it remembers and of each TYPE_REF, and when the dump is complete it sets the flags and renumbers the references. A reference count of one is only used to skip the hashtable. Interned strings are no longer flagged unconditionally. The reader is unchanged and the format version is not bumped: both the old and the new output are loaded by old and new readers. PyMarshal_WriteObjectToFile() now builds the data in memory and writes it with one fwrite(), since the flags are only known at the end. Nothing is written if the object cannot be marshalled. (cherry picked from commit 48f18f0)
Documentation build overview
142 files changed ·
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(cherry picked from commit 48f18f0)
Manual backport notes
A pure cherry-pick conflicted because 3.15 does not have the marshal error handling changes of gh-156942 and gh-155907, nor gh-148653.
Python/marshal.c: keeps theWFERR_*error codes of this branch; the new allocation failures useWFERR_NOMEMORY.PyMarshal_WriteLongToFile()andPyMarshal_WriteObjectToFile()still do not report a failure to write to the file, as before on this branch.PyMarshal_WriteObjectToFile()now goes through the same code asmarshal.dumps(), so when the object cannot be marshalled it writes nothing and setsValueError. Before, it wrote partial data and usually returned without an error.test_shared_recursionuses a recursive slice.Lib/test/test_capi/test_marshal.pydoes not exist here: its new cases are inCAPI_TestCaseofLib/test/test_marshal.py, and the_testcapihelper returns the error instead of asserting there is none.Doc/c-api/marshal.rst: the notes about unreported write errors no longer say "In Python 3.15 and earlier"; theversionchangedentry describes the change.Programs/test_frozenmain.his regenerated.