| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
… mutation (pythongh-142851) User callbacks invoked during JSON encoding (e.g. the `default` callback or a custom string encoder) can mutate or clear the dict or sequence being encoded, invalidating borrowed references to items, keys, and values. Hold strong references unconditionally while iterating. Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org> (cherry picked from commit 235fa72)
| Back | FazBrowse Home | New Git URL |
Manual backport of #142851 to 3.14 (the bot couldn't cleanly cherry-pick due to refactors in main).
The fix had to be adapted because in 3.14 the dict/list iteration loops were not yet extracted into the _encoder_iterate_*_lock_held helpers introduced later in main. Added the Py_INCREF/Py_DECREF around each borrowed item/key/value inline in encoder_listencode_dict (both the PyMapping_Items and PyDict_Next paths) and encoder_listencode_list.
The two regression tests from the original PR were cherry-picked as-is.
Built --with-pydebug and ran ./python -m test test_json -v locally — all 218 tests pass.