From 57a4b4f178698435b584892f69db5d5f2ea396dc Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 18 Apr 2014 22:29:21 +0100 Subject: 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. --- py/obj.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'py/obj.c') diff --git a/py/obj.c b/py/obj.c index 514a6941b..e0a712cb0 100644 --- a/py/obj.c +++ b/py/obj.c @@ -357,20 +357,20 @@ 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) { +bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo) { mp_obj_type_t *type = mp_obj_get_type(obj); if (type->buffer_p.get_buffer == NULL) { return false; } - type->buffer_p.get_buffer(obj, bufinfo, BUFFER_READ); - if (bufinfo->buf == NULL) { + int ret = type->buffer_p.get_buffer(obj, bufinfo, MP_BUFFER_READ); + if (ret != 0 || bufinfo->buf == NULL) { return false; } return true; } -void mp_get_buffer_raise(mp_obj_t obj, buffer_info_t *bufinfo) { +void mp_get_buffer_raise(mp_obj_t obj, mp_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")); + nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "object with buffer protocol required")); } } -- cgit v1.2.3