forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
py/objstringio: If created from immutable object, follow copy on writ…
…e policy. Don't create copy of immutable object's contents until .write() is called on BytesIO.
- Loading branch information
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,20 @@ | ||
# Make sure that write operations on io.BytesIO don't | ||
# change original object it was constructed from. | ||
try: | ||
import uio as io | ||
except ImportError: | ||
import io | ||
|
||
b = b"foobar" | ||
|
||
a = io.BytesIO(b) | ||
a.write(b"1") | ||
print(b) | ||
print(a.getvalue()) | ||
|
||
b = bytearray(b"foobar") | ||
|
||
a = io.BytesIO(b) | ||
a.write(b"1") | ||
print(b) | ||
print(a.getvalue()) |
This file contains 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,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)) |
This file contains 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 @@ | ||
True |