summaryrefslogtreecommitdiffstatshomepage
path: root/py/stream.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-22 14:35:10 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-22 14:35:10 +0000
commit5fa93b67557f21c22a41449c3266571c427f6798 (patch)
tree3e009ed9369b7aba8cf5212509a784ecd86e06a3 /py/stream.c
parent8ae1c1beacc56d440b2cc1e4bd010b100ad4fdd0 (diff)
downloadmicropython-5fa93b67557f21c22a41449c3266571c427f6798.tar.gz
micropython-5fa93b67557f21c22a41449c3266571c427f6798.zip
Second stage of qstr revamp: uPy str object can be qstr or not.
Diffstat (limited to 'py/stream.c')
-rw-r--r--py/stream.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/py/stream.c b/py/stream.c
index be560d3c22..d47d7e4196 100644
--- a/py/stream.c
+++ b/py/stream.c
@@ -23,15 +23,15 @@ static mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
if (n_args == 1 || ((sz = mp_obj_get_int(args[1])) == -1)) {
return stream_readall(args[0]);
}
- char *buf = m_new(char, sz);
+ byte *buf = m_new(byte, sz);
int error;
machine_int_t out_sz = o->type->stream_p.read(o, buf, sz, &error);
if (out_sz == -1) {
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[Errno %d]", error));
} else {
- // TODO don't intern this string
- buf = m_realloc(buf, sz, out_sz);
- return mp_obj_new_str(qstr_from_strn_take(buf, out_sz, out_sz));
+ mp_obj_t s = mp_obj_new_str(buf, out_sz, false); // will reallocate to use exact size
+ m_free(buf, sz);
+ return s;
}
}
@@ -43,7 +43,7 @@ static mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) {
}
uint sz;
- const byte *buf = qstr_data(mp_obj_get_qstr(arg), &sz);
+ const byte *buf = mp_obj_str_get_data(arg, &sz);
int error;
machine_int_t out_sz = o->type->stream_p.write(self_in, buf, sz, &error);
if (out_sz == -1) {
@@ -92,9 +92,10 @@ static mp_obj_t stream_readall(mp_obj_t self_in) {
}
}
}
- // TODO don't intern this string
- vstr_set_size(vstr, total_size);
- return mp_obj_new_str(qstr_from_strn_take(vstr->buf, vstr->alloc, total_size));
+
+ mp_obj_t s = mp_obj_new_str((byte*)vstr->buf, total_size, false);
+ vstr_free(vstr);
+ return s;
}
// Unbuffered, inefficient implementation of readline() for raw I/O files.