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
0914371f
Commit
0914371f
authored
11 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
file.readline(): Use mp_obj_str_get_data() and fix off-by-one error on EOF.
parent
5fa93b67
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/stream.c
+12
-4
12 additions, 4 deletions
py/stream.c
with
12 additions
and
4 deletions
py/stream.c
+
12
−
4
View file @
0914371f
...
...
@@ -130,7 +130,15 @@ static mp_obj_t stream_unbuffered_readline(uint n_args, const mp_obj_t *args) {
if
(
out_sz
==
-
1
)
{
nlr_jump
(
mp_obj_new_exception_msg_varg
(
MP_QSTR_OSError
,
"[Errno %d]"
,
error
));
}
if
(
out_sz
==
0
||
*
p
==
'\n'
)
{
if
(
out_sz
==
0
)
{
// Back out previously added byte
// TODO: This is a bit hacky, does it supported by vstr API contract?
// Consider, what's better - read a char and get OutOfMemory (so read
// char is lost), or allocate first as we do.
vstr_add_len
(
vstr
,
-
1
);
break
;
}
if
(
*
p
==
'\n'
)
{
break
;
}
}
...
...
@@ -141,9 +149,9 @@ static mp_obj_t stream_unbuffered_readline(uint n_args, const mp_obj_t *args) {
mp_obj_t
mp_stream_unbuffered_iter
(
mp_obj_t
self
)
{
mp_obj_t
l_in
=
stream_unbuffered_readline
(
1
,
&
self
);
const
char
*
l
=
qstr_str
(
MP_OBJ_QSTR_VALUE
(
l_in
))
;
// TODO: \0
if
(
*
l
!=
0
)
{
uint
sz
;
mp_obj_str_get_data
(
l_in
,
&
sz
);
if
(
sz
!=
0
)
{
return
l_in
;
}
return
mp_const_stop_iteration
;
...
...
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