Don't create copy of immutable object's contents until .write() is called on BytesIO.crypto-aes
parent
b24ccfc639
commit
07241cd37a
@ -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())
|
@ -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))
|
@ -0,0 +1 @@
|
||||
True
|
Loading…
Reference in new issue