diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-08 23:11:51 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-08 23:11:51 +0100 |
commit | 803b9263ab1049d19d62d9a09e5f82084b7afa41 (patch) | |
tree | 1f97f3f4a1fabea34327d1af4db520a348f29dbe /py/obj.c | |
parent | eec91057b827013a3e02c51b60e46c8597295132 (diff) | |
parent | a985b4593d3f0c788c5e6ef0066bf82ae550cfb8 (diff) |
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'py/obj.c')
-rw-r--r-- | py/obj.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -330,3 +330,21 @@ mp_obj_t mp_identity(mp_obj_t self) { return self; } MP_DEFINE_CONST_FUN_OBJ_1(mp_identity_obj, mp_identity); + +bool mp_get_buffer(mp_obj_t obj, buffer_info_t *bufinfo) { + mp_obj_base_t *o = (mp_obj_base_t *)obj; + if (o->type->buffer_p.get_buffer == NULL) { + return false; + } + o->type->buffer_p.get_buffer(o, bufinfo, BUFFER_READ); + if (bufinfo->buf == NULL) { + return false; + } + return true; +} + +void mp_get_buffer_raise(mp_obj_t obj, buffer_info_t *bufinfo) { + if (!mp_get_buffer(obj, bufinfo)) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Object with buffer protocol required")); + } +} |