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
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
3990b171
Commit
3990b171
authored
8 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
py/objstringio: Implement MP_STREAM_SEEK ioctl and add seek() method.
parent
f039ac5b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
py/objstringio.c
+24
-3
24 additions, 3 deletions
py/objstringio.c
with
24 additions
and
3 deletions
py/objstringio.c
+
24
−
3
View file @
3990b171
...
...
@@ -75,13 +75,18 @@ STATIC mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size,
(
void
)
errcode
;
mp_obj_stringio_t
*
o
=
MP_OBJ_TO_PTR
(
o_in
);
check_stringio_is_open
(
o
);
mp_uint_t
remaining
=
o
->
vstr
->
alloc
-
o
->
pos
;
if
(
size
>
remaining
)
{
mp_int_t
remaining
=
o
->
vstr
->
alloc
-
o
->
pos
;
mp_uint_t
org_len
=
o
->
vstr
->
len
;
if
((
mp_int_t
)
size
>
remaining
)
{
// Take all what's already allocated...
o
->
vstr
->
len
=
o
->
vstr
->
alloc
;
// ... and add more
vstr_add_len
(
o
->
vstr
,
size
-
remaining
);
}
// If there was a seek past EOF, clear the hole
if
(
o
->
pos
>
org_len
)
{
memset
(
o
->
vstr
->
buf
+
org_len
,
0
,
o
->
pos
-
org_len
);
}
memcpy
(
o
->
vstr
->
buf
+
o
->
pos
,
buf
,
size
);
o
->
pos
+=
size
;
if
(
o
->
pos
>
o
->
vstr
->
len
)
{
...
...
@@ -92,8 +97,23 @@ STATIC mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size,
STATIC
mp_uint_t
stringio_ioctl
(
mp_obj_t
o_in
,
mp_uint_t
request
,
uintptr_t
arg
,
int
*
errcode
)
{
(
void
)
errcode
;
//
mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in);
mp_obj_stringio_t
*
o
=
MP_OBJ_TO_PTR
(
o_in
);
switch
(
request
)
{
case
MP_STREAM_SEEK
:
{
struct
mp_stream_seek_t
*
s
=
(
struct
mp_stream_seek_t
*
)
arg
;
mp_uint_t
ref
=
0
;
switch
(
s
->
whence
)
{
case
1
:
// SEEK_CUR
ref
=
o
->
pos
;
break
;
case
2
:
// SEEK_END
ref
=
o
->
vstr
->
len
;
break
;
}
o
->
pos
=
ref
+
s
->
offset
;
s
->
offset
=
o
->
pos
;
return
0
;
}
case
MP_STREAM_FLUSH
:
return
0
;
default:
...
...
@@ -160,6 +180,7 @@ STATIC const mp_rom_map_elem_t stringio_locals_dict_table[] = {
{
MP_ROM_QSTR
(
MP_QSTR_readall
),
MP_ROM_PTR
(
&
mp_stream_readall_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_readline
),
MP_ROM_PTR
(
&
mp_stream_unbuffered_readline_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_write
),
MP_ROM_PTR
(
&
mp_stream_write_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_seek
),
MP_ROM_PTR
(
&
mp_stream_seek_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_flush
),
MP_ROM_PTR
(
&
mp_stream_flush_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_close
),
MP_ROM_PTR
(
&
stringio_close_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_getvalue
),
MP_ROM_PTR
(
&
stringio_getvalue_obj
)
},
...
...
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