Skip to content

Commit 5694cc5

Browse files
committed
py: Make stream seek correctly check for ioctl fn; add seek for textio.
1 parent 91386ee commit 5694cc5

4 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎py/stream.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self) {
382382

383383
STATIC mp_obj_t stream_seek(mp_uint_t n_args, const mp_obj_t *args) {
384384
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)args[0];
385-
if (o->type->stream_p == NULL || o->type->stream_p->read == NULL) {
385+
if (o->type->stream_p == NULL || o->type->stream_p->ioctl == NULL) {
386386
// CPython: io.UnsupportedOperation, OSError subclass
387387
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Operation not supported"));
388388
}

‎stmhal/file.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ const mp_obj_type_t mp_type_fileio = {
260260
STATIC const mp_stream_p_t textio_stream_p = {
261261
.read = file_obj_read,
262262
.write = file_obj_write,
263+
.ioctl = file_obj_ioctl,
263264
.is_text = true,
264265
};
265266

‎tests/io/file_seek.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@
1010

1111
print(f.seek(0, 0))
1212
print(f.read(5))
13+
14+
f.close()
15+
16+
# test text mode
17+
f = open("io/data/file1", "rt")
18+
print(f.seek(6))
19+
print(f.read(5))
20+
f.close()

‎unix/file.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ const mp_obj_type_t mp_type_fileio = {
240240
STATIC const mp_stream_p_t textio_stream_p = {
241241
.read = fdfile_read,
242242
.write = fdfile_write,
243+
.ioctl = fdfile_ioctl,
243244
.is_text = true,
244245
};
245246

0 commit comments

Comments
 (0)