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
ac736f15
Commit
ac736f15
authored
10 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
stream: Factor out mp_stream_write() method to write a memstring to stream.
parent
122c9db3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/stream.c
+9
-6
9 additions, 6 deletions
py/stream.c
py/stream.h
+2
-0
2 additions, 0 deletions
py/stream.h
with
11 additions
and
6 deletions
py/stream.c
+
9
−
6
View file @
ac736f15
...
...
@@ -98,18 +98,15 @@ STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
}
}
STATIC
mp_obj_t
stream_write
(
mp_obj_t
self_in
,
mp_obj_t
arg
)
{
mp_obj_t
mp_
stream_write
(
mp_obj_t
self_in
,
const
void
*
buf
,
mp_uint_t
len
)
{
struct
_mp_obj_base_t
*
o
=
(
struct
_mp_obj_base_t
*
)
self_in
;
if
(
o
->
type
->
stream_p
==
NULL
||
o
->
type
->
stream_p
->
write
==
NULL
)
{
// CPython: io.UnsupportedOperation, OSError subclass
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_OSError
,
"Operation not supported"
));
}
mp_buffer_info_t
bufinfo
;
mp_get_buffer_raise
(
arg
,
&
bufinfo
,
MP_BUFFER_READ
);
int
error
;
mp_int_t
out_sz
=
o
->
type
->
stream_p
->
write
(
self_in
,
buf
info
.
buf
,
bufinfo
.
len
,
&
error
);
mp_int_t
out_sz
=
o
->
type
->
stream_p
->
write
(
self_in
,
buf
,
len
,
&
error
);
if
(
out_sz
==
-
1
)
{
if
(
is_nonblocking_error
(
error
))
{
// http://docs.python.org/3/library/io.html#io.RawIOBase.write
...
...
@@ -125,6 +122,12 @@ STATIC mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) {
}
}
STATIC
mp_obj_t
stream_write_method
(
mp_obj_t
self_in
,
mp_obj_t
arg
)
{
mp_buffer_info_t
bufinfo
;
mp_get_buffer_raise
(
arg
,
&
bufinfo
,
MP_BUFFER_READ
);
return
mp_stream_write
(
self_in
,
bufinfo
.
buf
,
bufinfo
.
len
);
}
STATIC
mp_obj_t
stream_readall
(
mp_obj_t
self_in
)
{
struct
_mp_obj_base_t
*
o
=
(
struct
_mp_obj_base_t
*
)
self_in
;
if
(
o
->
type
->
stream_p
==
NULL
||
o
->
type
->
stream_p
->
read
==
NULL
)
{
...
...
@@ -248,4 +251,4 @@ mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self) {
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mp_stream_read_obj
,
1
,
2
,
stream_read
);
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_stream_readall_obj
,
stream_readall
);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mp_stream_unbuffered_readline_obj
,
1
,
2
,
stream_unbuffered_readline
);
MP_DEFINE_CONST_FUN_OBJ_2
(
mp_stream_write_obj
,
stream_write
);
MP_DEFINE_CONST_FUN_OBJ_2
(
mp_stream_write_obj
,
stream_write
_method
);
This diff is collapsed.
Click to expand it.
py/stream.h
+
2
−
0
View file @
ac736f15
...
...
@@ -32,3 +32,5 @@ MP_DECLARE_CONST_FUN_OBJ(mp_stream_write_obj);
// Iterator which uses mp_stream_unbuffered_readline_obj
mp_obj_t
mp_stream_unbuffered_iter
(
mp_obj_t
self
);
mp_obj_t
mp_stream_write
(
mp_obj_t
self_in
,
const
void
*
buf
,
mp_uint_t
len
);
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