Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
5694cc54
Commit
5694cc54
authored
Nov 16, 2014
by
Damien George
Browse files
py: Make stream seek correctly check for ioctl fn; add seek for textio.
parent
91386eee
Changes
4
Hide whitespace changes
Inline
Side-by-side
py/stream.c
View file @
5694cc54
...
...
@@ -382,7 +382,7 @@ mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self) {
STATIC
mp_obj_t
stream_seek
(
mp_uint_t
n_args
,
const
mp_obj_t
*
args
)
{
struct
_mp_obj_base_t
*
o
=
(
struct
_mp_obj_base_t
*
)
args
[
0
];
if
(
o
->
type
->
stream_p
==
NULL
||
o
->
type
->
stream_p
->
read
==
NULL
)
{
if
(
o
->
type
->
stream_p
==
NULL
||
o
->
type
->
stream_p
->
ioctl
==
NULL
)
{
// CPython: io.UnsupportedOperation, OSError subclass
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_OSError
,
"Operation not supported"
));
}
...
...
stmhal/file.c
View file @
5694cc54
...
...
@@ -260,6 +260,7 @@ const mp_obj_type_t mp_type_fileio = {
STATIC
const
mp_stream_p_t
textio_stream_p
=
{
.
read
=
file_obj_read
,
.
write
=
file_obj_write
,
.
ioctl
=
file_obj_ioctl
,
.
is_text
=
true
,
};
...
...
tests/io/file_seek.py
View file @
5694cc54
...
...
@@ -10,3 +10,11 @@ print(f.read(20))
print
(
f
.
seek
(
0
,
0
))
print
(
f
.
read
(
5
))
f
.
close
()
# test text mode
f
=
open
(
"io/data/file1"
,
"rt"
)
print
(
f
.
seek
(
6
))
print
(
f
.
read
(
5
))
f
.
close
()
unix/file.c
View file @
5694cc54
...
...
@@ -240,6 +240,7 @@ const mp_obj_type_t mp_type_fileio = {
STATIC
const
mp_stream_p_t
textio_stream_p
=
{
.
read
=
fdfile_read
,
.
write
=
fdfile_write
,
.
ioctl
=
fdfile_ioctl
,
.
is_text
=
true
,
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment