FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] gh-128509: Use bytes singletons in marshal (GH-157398) by miss-islington · Pull Request #157433 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 8 additions & 0 deletions Lib/test/test_marshal.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ def test_bytes(self):
for s in [b"", b"Andr\xe8 Previn", b"abc", b" "*10000]:
self.helper(s)

@support.cpython_only
def test_bytes_singleton(self):
for version in range(marshal.version + 1):
for sample in [b"", b"x"]:
new = marshal.loads(marshal.dumps(sample, version))
self.assertIs(new, sample)


class ExceptionTestCase(unittest.TestCase):
def test_exceptions(self):
new = marshal.loads(marshal.dumps(StopIteration))
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`marshal.load` and :func:`marshal.loads` can now get 1-byte string
singletons. Patch by Victor Stinner.
8 changes: 2 additions & 6 deletions Python/marshal.c
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
Original file line number Diff line number Diff line change
Expand Up @@ -1308,16 +1308,12 @@ r_object(RFILE *p)
}
break;
}
v = PyBytes_FromStringAndSize((char *)NULL, n);
if (v == NULL)
break;
ptr = r_string(n, p);
if (ptr == NULL) {
Py_DECREF(v);
break;
}
memcpy(PyBytes_AS_STRING(v), ptr, n);
retval = v;
// Get a singleton for 1-byte string
retval = PyBytes_FromStringAndSize(ptr, n); // can be NULL
R_REF(retval);
break;
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL