diff --git a/examples/natmod/framebuf/framebuf.c b/examples/natmod/framebuf/framebuf.c index 53fb90c625..2eff61c817 100644 --- a/examples/natmod/framebuf/framebuf.c +++ b/examples/natmod/framebuf/framebuf.c @@ -21,7 +21,7 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a mp_type_framebuf.base.type = (void*)&mp_type_type; mp_type_framebuf.name = MP_QSTR_FrameBuffer; mp_type_framebuf.make_new = framebuf_make_new; - mp_type_framebuf.buffer_p.get_buffer = framebuf_get_buffer; + mp_type_framebuf.buffer = framebuf_get_buffer; framebuf_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_fill), MP_OBJ_FROM_PTR(&framebuf_fill_obj) }; framebuf_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_fill_rect), MP_OBJ_FROM_PTR(&framebuf_fill_rect_obj) }; framebuf_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_pixel), MP_OBJ_FROM_PTR(&framebuf_pixel_obj) }; diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index bd4d9b7179..4cc57b3d55 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -248,7 +248,7 @@ const mp_obj_type_t mp_type_bluetooth_uuid = { .binary_op = bluetooth_uuid_binary_op, .locals_dict = NULL, .print = bluetooth_uuid_print, - .buffer_p = { .get_buffer = bluetooth_uuid_get_buffer }, + .buffer = bluetooth_uuid_get_buffer, }; // ---------------------------------------------------------------------------- diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index bb1f4f6310..9542d4303e 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -833,7 +833,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = { { &mp_type_type }, .name = MP_QSTR_FrameBuffer, .make_new = framebuf_make_new, - .buffer_p = { .get_buffer = framebuf_get_buffer }, + .buffer = framebuf_get_buffer, .locals_dict = (mp_obj_dict_t *)&framebuf_locals_dict, }; #endif diff --git a/extmod/moductypes.c b/extmod/moductypes.c index 547453c48e..25578dd6b0 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -642,7 +642,7 @@ STATIC const mp_obj_type_t uctypes_struct_type = { .attr = uctypes_struct_attr, .subscr = uctypes_struct_subscr, .unary_op = uctypes_struct_unary_op, - .buffer_p = { .get_buffer = uctypes_get_buffer }, + .buffer = uctypes_get_buffer, }; STATIC const mp_rom_map_elem_t mp_module_uctypes_globals_table[] = { diff --git a/ports/nrf/boards/microbit/modules/iters.c b/ports/nrf/boards/microbit/modules/iters.c index 8ae4b698fe..e9c4ae3c72 100644 --- a/ports/nrf/boards/microbit/modules/iters.c +++ b/ports/nrf/boards/microbit/modules/iters.c @@ -55,7 +55,6 @@ const mp_obj_type_t microbit_repeat_iterator_type = { .subscr = NULL, .getiter = mp_identity_getiter, .iternext = microbit_repeat_iter_next, - .buffer_p = {NULL}, MP_OBJ_NULL }; diff --git a/ports/nrf/boards/microbit/modules/microbitdisplay.c b/ports/nrf/boards/microbit/modules/microbitdisplay.c index b35703ad6f..04b8602879 100644 --- a/ports/nrf/boards/microbit/modules/microbitdisplay.c +++ b/ports/nrf/boards/microbit/modules/microbitdisplay.c @@ -554,7 +554,6 @@ const mp_obj_type_t microbit_display_type = { .subscr = NULL, .getiter = NULL, .iternext = NULL, - .buffer_p = {NULL}, .locals_dict = (mp_obj_dict_t*)µbit_display_locals_dict, }; diff --git a/ports/nrf/boards/microbit/modules/microbitimage.c b/ports/nrf/boards/microbit/modules/microbitimage.c index a028df8282..5d2896c383 100644 --- a/ports/nrf/boards/microbit/modules/microbitimage.c +++ b/ports/nrf/boards/microbit/modules/microbitimage.c @@ -690,7 +690,6 @@ const mp_obj_type_t microbit_image_type = { .subscr = NULL, .getiter = NULL, .iternext = NULL, - .buffer_p = {NULL}, .locals_dict = (mp_obj_dict_t*)µbit_image_locals_dict, }; diff --git a/ports/unix/modffi.c b/ports/unix/modffi.c index d82d5270fa..6417b5d3b3 100644 --- a/ports/unix/modffi.c +++ b/ports/unix/modffi.c @@ -505,10 +505,10 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const } else if (mp_obj_is_str(a)) { const char *s = mp_obj_str_get_str(a); values[i].ffi = (ffi_arg)(intptr_t)s; - } else if (((mp_obj_base_t *)MP_OBJ_TO_PTR(a))->type->buffer_p.get_buffer != NULL) { + } else if (((mp_obj_base_t *)MP_OBJ_TO_PTR(a))->type->buffer != NULL) { mp_obj_base_t *o = (mp_obj_base_t *)MP_OBJ_TO_PTR(a); mp_buffer_info_t bufinfo; - int ret = o->type->buffer_p.get_buffer(MP_OBJ_FROM_PTR(o), &bufinfo, MP_BUFFER_READ); // TODO: MP_BUFFER_READ? + int ret = o->type->buffer(MP_OBJ_FROM_PTR(o), &bufinfo, MP_BUFFER_READ); // TODO: MP_BUFFER_READ? if (ret != 0) { goto error; } diff --git a/py/obj.c b/py/obj.c index b461fe50aa..eeadd3eedd 100644 --- a/py/obj.c +++ b/py/obj.c @@ -579,10 +579,10 @@ mp_obj_t mp_identity_getiter(mp_obj_t self, mp_obj_iter_buf_t *iter_buf) { bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) { const mp_obj_type_t *type = mp_obj_get_type(obj); - if (type->buffer_p.get_buffer == NULL) { + if (type->buffer == NULL) { return false; } - int ret = type->buffer_p.get_buffer(obj, bufinfo, flags); + int ret = type->buffer(obj, bufinfo, flags); if (ret != 0) { return false; } diff --git a/py/obj.h b/py/obj.h index 8949830282..0bf5b58f81 100644 --- a/py/obj.h +++ b/py/obj.h @@ -557,9 +557,7 @@ typedef struct _mp_buffer_info_t { #define MP_BUFFER_READ (1) #define MP_BUFFER_WRITE (2) #define MP_BUFFER_RW (MP_BUFFER_READ | MP_BUFFER_WRITE) -typedef struct _mp_buffer_p_t { - mp_int_t (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags); -} mp_buffer_p_t; +typedef mp_int_t (*mp_buffer_fun_t)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags); bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags); void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags); @@ -618,7 +616,7 @@ struct _mp_obj_type_t { mp_fun_1_t iternext; // Implements the buffer protocol if supported by this type. - mp_buffer_p_t buffer_p; + mp_buffer_fun_t buffer; // One of disjoint protocols (interfaces), like mp_stream_p_t, etc. const void *protocol; diff --git a/py/objarray.c b/py/objarray.c index ecaffeb6a2..dca41c2931 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -580,7 +580,7 @@ const mp_obj_type_t mp_type_array = { .unary_op = array_unary_op, .binary_op = array_binary_op, .subscr = array_subscr, - .buffer_p = { .get_buffer = array_get_buffer }, + .buffer_p = array_get_buffer, .locals_dict = (mp_obj_dict_t *)&mp_obj_array_locals_dict, }; #endif @@ -596,7 +596,7 @@ const mp_obj_type_t mp_type_bytearray = { .unary_op = array_unary_op, .binary_op = array_binary_op, .subscr = array_subscr, - .buffer_p = { .get_buffer = array_get_buffer }, + .buffer = array_get_buffer, .locals_dict = (mp_obj_dict_t *)&mp_obj_bytearray_locals_dict, }; #endif @@ -617,7 +617,7 @@ const mp_obj_type_t mp_type_memoryview = { .locals_dict = (mp_obj_dict_t *)&mp_obj_memoryview_locals_dict, #endif .subscr = array_subscr, - .buffer_p = { .get_buffer = array_get_buffer }, + .buffer = array_get_buffer, }; #endif diff --git a/py/objstr.c b/py/objstr.c index 683d035e44..9dd7f65e66 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -2151,7 +2151,7 @@ const mp_obj_type_t mp_type_str = { .binary_op = mp_obj_str_binary_op, .subscr = bytes_subscr, .getiter = mp_obj_new_str_iterator, - .buffer_p = { .get_buffer = mp_obj_str_get_buffer }, + .buffer = mp_obj_str_get_buffer, .locals_dict = (mp_obj_dict_t *)&mp_obj_str_locals_dict, }; #endif // !MICROPY_PY_BUILTINS_STR_UNICODE @@ -2165,7 +2165,7 @@ const mp_obj_type_t mp_type_bytes = { .binary_op = mp_obj_str_binary_op, .subscr = bytes_subscr, .getiter = mp_obj_new_bytes_iterator, - .buffer_p = { .get_buffer = mp_obj_str_get_buffer }, + .buffer = mp_obj_str_get_buffer, .locals_dict = (mp_obj_dict_t *)&mp_obj_bytes_locals_dict, }; diff --git a/py/objstrunicode.c b/py/objstrunicode.c index d36dd8b137..fef0353683 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -238,7 +238,7 @@ const mp_obj_type_t mp_type_str = { .binary_op = mp_obj_str_binary_op, .subscr = str_subscr, .getiter = mp_obj_new_str_iterator, - .buffer_p = { .get_buffer = mp_obj_str_get_buffer }, + .buffer = mp_obj_str_get_buffer, .locals_dict = (mp_obj_dict_t *)&mp_obj_str_locals_dict, }; diff --git a/py/objtype.c b/py/objtype.c index fe1918bd37..c0f6857809 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -913,14 +913,14 @@ STATIC mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, struct class_lookup_data lookup = { .obj = self, .attr = MP_QSTR_, // don't actually look for a method - .meth_offset = offsetof(mp_obj_type_t, buffer_p.get_buffer), + .meth_offset = offsetof(mp_obj_type_t, buffer), .dest = member, .is_type = false, }; mp_obj_class_lookup(&lookup, self->base.type); if (member[0] == MP_OBJ_SENTINEL) { const mp_obj_type_t *type = mp_obj_get_type(self->subobj[0]); - return type->buffer_p.get_buffer(self->subobj[0], bufinfo, flags); + return type->buffer(self->subobj[0], bufinfo, flags); } else { return 1; // object does not support buffer protocol } @@ -1160,7 +1160,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) o->subscr = instance_subscr; o->getiter = mp_obj_instance_getiter; // o->iternext = ; not implemented - o->buffer_p.get_buffer = instance_get_buffer; + o->buffer = instance_get_buffer; if (bases_len > 0) { // Inherit protocol from a base class. This allows to define an