8000 top: Simplify buffer protocol to just a "get buffer" callback. · jimmo/micropython@47f8eb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 47f8eb8

Browse files
committed
top: Simplify buffer protocol to just a "get buffer" callback.
The buffer protocol type only has a single member, and this layout creates problems for the upcoming split/slot-index mp_obj_type_t layout optimisations. If we need to make the buffer protocol more sophisticated in the future either we can rely on the mp_obj_type_t optimisations to just add additional slots to mp_obj_type_t or re-visit the buffer protocol then. This change is a no-op in terms of generated code. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent 0e8c220 commit 47f8eb8

File tree

14 files changed

+19
-24
lines changed

14 files changed

+19
-24
lines changed

examples/natmod/framebuf/framebuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
2121
mp_type_framebuf.base.type = (void*)&mp_type_type;
2222
mp_type_framebuf.name = MP_QSTR_FrameBuffer;
2323
mp_type_framebuf.make_new = framebuf_make_new;
24-
mp_type_framebuf.buffer_p.get_buffer = framebuf_get_buffer;
24+
mp_type_framebuf.buffer = framebuf_get_buffer;
2525
framebuf_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_fill), MP_OBJ_FROM_PTR(&framebuf_fill_obj) };
2626
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) };
2727
framebuf_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_pixel), MP_OBJ_FROM_PTR(&framebuf_pixel_obj) };

extmod/modbluetooth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ const mp_obj_type_t mp_type_bluetooth_uuid = {
248248
.binary_op = bluetooth_uuid_binary_op,
249249
.locals_dict = NULL,
250250
.print = bluetooth_uuid_print,
251-
.buffer_p = { .get_buffer = bluetooth_uuid_get_buffer },
251+
.buffer = bluetooth_uuid_get_buffer,
252252
};
253253

254254
// ----------------------------------------------------------------------------

extmod/modframebuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = {
833833
{ &mp_type_type },
834834
.name = MP_QSTR_FrameBuffer,
835835
.make_new = framebuf_make_new,
836-
.buffer_p = { .get_buffer = framebuf_get_buffer },
836+
.buffer = framebuf_get_buffer,
837837
.locals_dict = (mp_obj_dict_t *)&framebuf_locals_dict,
838838
};
839839
#endif

extmod/moductypes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ STATIC const mp_obj_type_t uctypes_struct_type = {
642642
.attr = uctypes_struct_attr,
643643
.subscr = uctypes_struct_subscr,
644644
.unary_op = uctypes_struct_unary_op,
645-
.buffer_p = { .get_buffer = uctypes_get_buffer },
645+
.buffer = uctypes_get_buffer,
646646
};
647647

648648
STATIC const mp_rom_map_elem_t mp_module_uctypes_globals_table[] = {

ports/nrf/boards/microbit/modules/iters.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const mp_obj_type_t microbit_repeat_iterator_type = {
5555
.subscr = NULL,
5656
.getiter = mp_identity_getiter,
5757
.iternext = microbit_repeat_iter_next,
58-
.buffer_p = {NULL},
5958
MP_OBJ_NULL
6059
};
6160

ports/nrf/boards/microbit/modules/microbitdisplay.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ const mp_obj_type_t microbit_display_type = {
554554
.subscr = NULL,
555555
.getiter = NULL,
556556
.iternext = NULL,
557-
.buffer_p = {NULL},
558557
.locals_dict = (mp_obj_dict_t*)&microbit_display_locals_dict,
559558
};
560559

ports/nrf/boards/microbit/modules/microbitimage.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,6 @@ const mp_obj_type_t microbit_image_type = {
690690
.subscr = NULL,
691691
.getiter = NULL,
692692
.iternext = NULL,
693-
.buffer_p = {NULL},
694693
.locals_dict = (mp_obj_dict_t*)&microbit_image_locals_dict,
695694
};
696695

ports/unix/modffi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,10 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
505505
} else if (mp_obj_is_str(a)) {
506506
const char *s = mp_obj_str_get_str(a);
507507
values[i].ffi = (ffi_arg)(intptr_t)s;
508-
} else if (((mp_obj_base_t *)MP_OBJ_TO_PTR(a))->type->buffer_p.get_buffer != NULL) {
508+
} else if (((mp_obj_base_t *)MP_OBJ_TO_PTR(a))->type->buffer != NULL) {
509509
mp_obj_base_t *o = (mp_obj_base_t *)MP_OBJ_TO_PTR(a);
510510
mp_buffer_info_t bufinfo;
511-
int ret = o->type->buffer_p.get_buffer(MP_OBJ_FROM_PTR(o), &bufinfo, MP_BUFFER_READ); // TODO: MP_BUFFER_READ?
511+
int ret = o->type->buffer(MP_OBJ_FROM_PTR(o), &bufinfo, MP_BUFFER_READ); // TODO: MP_BUFFER_READ?
512512
if (ret != 0) {
513513
goto error;
514514
}

py/obj.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,10 @@ mp_obj_t mp_identity_getiter(mp_obj_t self, mp_obj_iter_buf_t *iter_buf) {
579579

580580
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
581581
const mp_obj_type_t *type = mp_obj_get_type(obj);
582-
if (type->buffer_p.get_buffer == NULL) {
582+
if (type->buffer == NULL) {
583583
return false;
584584
}
585-
int ret = type->buffer_p.get_buffer(obj, bufinfo, flags);
585+
int ret = type->buffer(obj, bufinfo, flags);
586586
if (ret != 0) {
587587
return false;
588588
}

py/obj.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,7 @@ typedef struct _mp_buffer_info_t {
557557
#define MP_BUFFER_READ (1)
558558
#define MP_BUFFER_WRITE (2)
559559
#define MP_BUFFER_RW (MP_BUFFER_READ | MP_BUFFER_WRITE)
560-
typedef struct _mp_buffer_p_t {
561-
mp_int_t (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
562-
} mp_buffer_p_t;
560+
typedef mp_int_t (*mp_buffer_fun_t)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
563561
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
564562
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
565563

@@ -618,7 +616,7 @@ struct _mp_obj_type_t {
618616
mp_fun_1_t iternext;
619617

620618
// Implements the buffer protocol if supported by this type.
621-
mp_buffer_p_t buffer_p;
619+
mp_buffer_fun_t buffer;
622620

623621
// One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
624622
const void *protocol;

0 commit comments

Comments
 (0)
0