all: Simplify buffer protocol to just a "get buffer" callback.

The buffer protocol type only has a single member, and this existing 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>
This commit is contained in:
Jim Mussared
2021-07-15 14:31:06 +10:00
committed by Damien George
parent ca51d63c37
commit fb2a57800a
14 changed files with 19 additions and 24 deletions

View File

@@ -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