gh-128509: Use bytes singleton in marshal - #157398
Conversation
Replace soft deprecated PyBytes_FromStringAndSize(NULL, n) with PyBytes_FromStringAndSize(str, n) so marshal can get bytes singleton.
|
Create a script def func():
constant_obj = b'x'
runtime_obj = 'x'.encode()
if constant_obj is not runtime_obj:
print("marshal failed to get the singleton")
else:
print("all good")
func()The script works as expected when run with When using |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM, but please test for different marshal versions.
|
Good idea! I add a loop on all marshal versions! |
|
Merged. Thanks for the review @serhiy-storchaka, as usual! |
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-157432 is a backport of this pull request to the 3.14 branch. |
|
GH-157433 is a backport of this pull request to the 3.15 branch. |
gh-128509: Use bytes singletons in marshal (GH-157398) Replace soft deprecated PyBytes_FromStringAndSize(NULL, n) with PyBytes_FromStringAndSize(str, n) so marshal can get bytes singleton. (cherry picked from commit 658612a) Co-authored-by: Victor Stinner <[email protected]>
Replace soft deprecated PyBytes_FromStringAndSize(NULL, n) with PyBytes_FromStringAndSize(str, n) so marshal can get bytes singleton.