Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
fa2edabc
Commit
fa2edabc
authored
Nov 16, 2014
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
stmhal: Switch to file.seek() implementation using stream ioctl.
parent
c7d55001
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
stmhal/file.c
+30
-36
30 additions, 36 deletions
stmhal/file.c
stmhal/mpconfigport.h
+1
-0
1 addition, 0 deletions
stmhal/mpconfigport.h
with
31 additions
and
36 deletions
stmhal/file.c
+
30
−
36
View file @
fa2edabc
...
...
@@ -114,45 +114,38 @@ mp_obj_t file_obj___exit__(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
file_obj___exit___obj
,
4
,
4
,
file_obj___exit__
);
mp_obj_t
file_obj_seek
(
mp_uint_t
n_args
,
const
mp_obj_t
*
args
)
{
pyb_file_obj_t
*
self
=
args
[
0
];
mp_int_t
offset
=
mp_obj_get_int
(
args
[
1
]);
mp_int_t
whence
=
0
;
if
(
n_args
==
3
)
{
whence
=
mp_obj_get_int
(
args
[
2
]);
}
STATIC
mp_uint_t
file_obj_ioctl
(
mp_obj_t
o_in
,
mp_uint_t
request
,
mp_uint_t
arg
,
int
*
errcode
)
{
pyb_file_obj_t
*
self
=
o_in
;
if
(
request
==
MP_STREAM_SEEK
)
{
struct
mp_stream_seek_t
*
s
=
(
struct
mp_stream_seek_t
*
)
arg
;
switch
(
whence
)
{
switch
(
s
->
whence
)
{
case
0
:
// SEEK_SET
f_lseek
(
&
self
->
fp
,
offset
);
f_lseek
(
&
self
->
fp
,
s
->
offset
);
break
;
case
1
:
// SEEK_CUR
if
(
offset
!=
0
)
{
goto
error
;
if
(
s
->
offset
!=
0
)
{
*
errcode
=
ENOTSUP
;
return
MP_STREAM_ERROR
;
}
// no-operation
break
;
case
2
:
// SEEK_END
if
(
offset
!=
0
)
{
goto
error
;
}
f_lseek
(
&
self
->
fp
,
f_size
(
&
self
->
fp
));
f_lseek
(
&
self
->
fp
,
f_size
(
&
self
->
fp
)
+
s
->
offset
);
break
;
default:
goto
error
;
}
return
mp_obj_new_int_from_uint
(
f_tell
(
&
self
->
fp
));
s
->
offset
=
f_tell
(
&
self
->
fp
);
return
0
;
error:
// A bad whence is a ValueError, while offset!=0 is an io.UnsupportedOperation.
// But the latter inherits ValueError (as well as IOError), so we just raise ValueError.
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_ValueError
,
"invalid whence and/or offset"
));
}
else
{
*
errcode
=
EINVAL
;
return
MP_STREAM_ERROR
;
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
file_obj_seek_obj
,
2
,
3
,
file_obj_seek
);
mp_obj_t
file_obj_tell
(
mp_obj_t
self_in
)
{
pyb_file_obj_t
*
self
=
self_in
;
...
...
@@ -236,7 +229,7 @@ STATIC const mp_map_elem_t rawfile_locals_dict_table[] = {
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_write
),
(
mp_obj_t
)
&
mp_stream_write_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_flush
),
(
mp_obj_t
)
&
file_obj_flush_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_close
),
(
mp_obj_t
)
&
file_obj_close_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_seek
),
(
mp_obj_t
)
&
file_obj
_seek_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_seek
),
(
mp_obj_t
)
&
mp_stream
_seek_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_tell
),
(
mp_obj_t
)
&
file_obj_tell_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR___del__
),
(
mp_obj_t
)
&
file_obj_close_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR___enter__
),
(
mp_obj_t
)
&
mp_identity_obj
},
...
...
@@ -249,6 +242,7 @@ STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table);
STATIC
const
mp_stream_p_t
fileio_stream_p
=
{
.
read
=
file_obj_read
,
.
write
=
file_obj_write
,
.
ioctl
=
file_obj_ioctl
,
};
const
mp_obj_type_t
mp_type_fileio
=
{
...
...
This diff is collapsed.
Click to expand it.
stmhal/mpconfigport.h
+
1
−
0
View file @
fa2edabc
...
...
@@ -124,6 +124,7 @@ typedef int mp_int_t; // must be pointer size
typedef
unsigned
int
mp_uint_t
;
// must be pointer size
typedef
void
*
machine_ptr_t
;
// must be of pointer size
typedef
const
void
*
machine_const_ptr_t
;
// must be of pointer size
typedef
long
mp_off_t
;
// We have inlined IRQ functions for efficiency (they are generally
// 1 machine instruction).
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment