From 07241cd37a732e4219257e6b2fc67a84085b37f6 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 5 Jun 2017 23:54:21 +0300 Subject: py/objstringio: If created from immutable object, follow copy on write policy. Don't create copy of immutable object's contents until .write() is called on BytesIO. --- tests/micropython/heapalloc_bytesio2.py | 20 ++++++++++++++++++++ tests/micropython/heapalloc_bytesio2.py.exp | 1 + 2 files changed, 21 insertions(+) create mode 100644 tests/micropython/heapalloc_bytesio2.py create mode 100644 tests/micropython/heapalloc_bytesio2.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_bytesio2.py b/tests/micropython/heapalloc_bytesio2.py new file mode 100644 index 000000000..cd76f5807 --- /dev/null +++ b/tests/micropython/heapalloc_bytesio2.py @@ -0,0 +1,20 @@ +# Creating BytesIO from immutable object should not immediately +# copy its content. +try: + import uio + import micropython + micropython.mem_total +except (ImportError, AttributeError): + print("SKIP") + raise SystemExit + + +data = b"1234" * 256 + +before = micropython.mem_total() + +buf = uio.BytesIO(data) + +after = micropython.mem_total() + +print(after - before < len(data)) diff --git a/tests/micropython/heapalloc_bytesio2.py.exp b/tests/micropython/heapalloc_bytesio2.py.exp new file mode 100644 index 000000000..0ca95142b --- /dev/null +++ b/tests/micropython/heapalloc_bytesio2.py.exp @@ -0,0 +1 @@ +True -- cgit v1.2.3