summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-13 12:08:52 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-13 12:08:52 +0100
commit8a1cab952f08f46182f6f86caf8edf37e477be33 (patch)
tree0d032ab1e5390a3d68414f2305a42a8172ee16bf /py
parent4b01de44ba110394cac66f83a44a037fc58ae4e8 (diff)
downloadmicropython-8a1cab952f08f46182f6f86caf8edf37e477be33.tar.gz
micropython-8a1cab952f08f46182f6f86caf8edf37e477be33.zip
py: Fix mp_get_buffer, and use it in more places.
Must use mp_obj_get_type to get the type of an object. Can't assume mp_obj_t is castable to mp_obj_base_t.
Diffstat (limited to 'py')
-rw-r--r--py/obj.c6
-rw-r--r--py/objfun.c15
2 files changed, 11 insertions, 10 deletions
diff --git a/py/obj.c b/py/obj.c
index 6eaedb3a7f..bdafc72476 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -333,11 +333,11 @@ mp_obj_t mp_identity(mp_obj_t 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) {
+ mp_obj_type_t *type = mp_obj_get_type(obj);
+ if (type->buffer_p.get_buffer == NULL) {
return false;
}
- o->type->buffer_p.get_buffer(o, bufinfo, BUFFER_READ);
+ type->buffer_p.get_buffer(obj, bufinfo, BUFFER_READ);
if (bufinfo->buf == NULL) {
return false;
}
diff --git a/py/objfun.c b/py/objfun.c
index 056789c336..8fadbc6119 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -442,14 +442,15 @@ STATIC machine_uint_t convert_obj_for_inline_asm(mp_obj_t obj) {
mp_obj_t *items;
mp_obj_list_get(obj, &len, &items);
return (machine_uint_t)items;
- } else if (type->buffer_p.get_buffer != NULL) {
- // supports the buffer protocol, get a pointer to the data
- buffer_info_t bufinfo;
- type->buffer_p.get_buffer(obj, &bufinfo, BUFFER_READ);
- return (machine_uint_t)bufinfo.buf;
} else {
- // just pass along a pointer to the object
- return (machine_uint_t)obj;
+ buffer_info_t bufinfo;
+ if (mp_get_buffer(obj, &bufinfo)) {
+ // supports the buffer protocol, return a pointer to the data
+ return (machine_uint_t)bufinfo.buf;
+ } else {
+ // just pass along a pointer to the object
+ return (machine_uint_t)obj;
+ }
}
}
}