Skip to content

1.7.2: ndarray_get_buffer() thinks ->array is a python object #328

@dhalbert

Description

@dhalbert

ulab 1.7.2 still defines the routine ndarray_get_buffer(). This code calls mp_get_buffer(self->array, ...). However, my understanding from reading create_zeros_ones_full() is that self->array is the raw array of values. It is not a Python object. mp_get_buffer() expects its first arg to be a Python object, so bad things happen.

https://github.com/v923z/micropython-ulab/blob/743d86487c83e42024ed508ed50499ad0a527d5d/code/ndarray.c#L1989-L1994

mp_int_t ndarray_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
    ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
    // buffer_p.get_buffer() returns zero for success, while mp_get_buffer returns true for success
    return !mp_get_buffer(self->array, bufinfo, flags);
}

I had some code similar to this in CircuitPython:

a = ulab.zeros(10, dtype=ulab.uint16)
some_bleio_characteristic.value = a

_bleio.Characteristic.value expects the value coming in to obey buffer protocol, and calls mp_get_buffer() on the ndarray. That in turn calls ndarray_get_buffer(), which tries to call mp_get_buffer() on the array itself, and things go wrong.

ndarray_get_buffer() seems to have disappeared in 2.x ulab, so I'm not sure how to fix 1.7.2. Is there something new to backport to 1.7.x? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcriticalcritical bug, requires speedy fixlegacyAffects the "legacy" branch

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions