summaryrefslogtreecommitdiff
path: root/py/objstr.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-18 22:29:21 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-18 22:29:21 +0100
commit57a4b4f178698435b584892f69db5d5f2ea396dc (patch)
treeb38aac7f18d31f714c2029a0a6e3f93e36447295 /py/objstr.c
parent3fd2d7fad2022e3f26304fbc6ad74e6d8dd66e5f (diff)
py: Add typecode to buffer protocol.
When querying an object that supports the buffer protocol, that object must now return a typecode (as per binary.[ch]). This does not have to be honoured by the caller, but can be useful for determining element size.
Diffstat (limited to 'py/objstr.c')
-rw-r--r--py/objstr.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/py/objstr.c b/py/objstr.c
index e444ec7d4..a682144b8 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -1326,16 +1326,18 @@ STATIC mp_obj_t str_encode(uint n_args, const mp_obj_t *args) {
}
#endif
-STATIC machine_int_t str_get_buffer(mp_obj_t self_in, buffer_info_t *bufinfo, int flags) {
- if (flags == BUFFER_READ) {
+STATIC machine_int_t str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, int flags) {
+ if (flags == MP_BUFFER_READ) {
GET_STR_DATA_LEN(self_in, str_data, str_len);
bufinfo->buf = (void*)str_data;
bufinfo->len = str_len;
+ bufinfo->typecode = 'b';
return 0;
} else {
// can't write to a string
bufinfo->buf = NULL;
bufinfo->len = 0;
+ bufinfo->typecode = -1;
return 1;
}
}