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
2da9830b
Commit
2da9830b
authored
Mar 09, 2014
by
Damien George
Browse files
py: Make objstr support buffer protocol (read only).
parent
0ec6bd47
Changes
1
Hide whitespace changes
Inline
Side-by-side
py/objstr.c
View file @
2da9830b
...
...
@@ -487,6 +487,20 @@ STATIC mp_obj_t str_replace(uint n_args, const mp_obj_t *args) {
return
mp_obj_str_builder_end
(
replaced_str
);
}
STATIC
machine_int_t
str_get_buffer
(
mp_obj_t
self_in
,
buffer_info_t
*
bufinfo
,
int
flags
)
{
if
(
flags
==
BUFFER_READ
)
{
GET_STR_DATA_LEN
(
self_in
,
str_data
,
str_len
);
bufinfo
->
buf
=
(
void
*
)
str_data
;
bufinfo
->
len
=
str_len
;
return
0
;
}
else
{
// can't write to a string
bufinfo
->
buf
=
NULL
;
bufinfo
->
len
=
0
;
return
1
;
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
str_find_obj
,
2
,
4
,
str_find
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
str_join_obj
,
str_join
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
str_split_obj
,
1
,
3
,
str_split
);
...
...
@@ -513,6 +527,7 @@ const mp_obj_type_t str_type = {
.
binary_op
=
str_binary_op
,
.
getiter
=
mp_obj_new_str_iterator
,
.
methods
=
str_type_methods
,
.
buffer_p
=
{
.
get_buffer
=
str_get_buffer
},
};
// Reuses most of methods from str
...
...
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