[SOLVED]first arg - mp_binary_get_size('@',...)

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

[SOLVED]first arg - mp_binary_get_size('@',...)

Post by jickster » Thu Apr 12, 2018 7:28 pm

What is meaning of the first argument of mp_binary_get_size?

Code: Select all

STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
    mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in);
    size_t sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
    bufinfo->buf = o->items;
    bufinfo->len = o->len * sz;
    bufinfo->typecode = o->typecode & TYPECODE_MASK;
    #if MICROPY_PY_BUILTINS_MEMORYVIEW
    if (o->base.type == &mp_type_memoryview) {
        if ((o->typecode & 0x80) == 0 && (flags & MP_BUFFER_WRITE)) {
            // read-only memoryview
            return 1;
        }
        bufinfo->buf = (uint8_t*)bufinfo->buf + (size_t)o->free * sz;
    }
    #else
    (void)flags;
    #endif
    return 0;
}
Last edited by jickster on Fri Apr 13, 2018 4:32 pm, edited 1 time in total.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: first arg - mp_binary_get_size('@',...)

Post by dhylands » Fri Apr 13, 2018 12:16 am

The documentation for ustruct http://docs.micropython.org/en/latest/w ... le-ustruct mentions the subset of CPython's struct which is supported. The first argument passed to mp_binary_get_size is the "size/byte order prefixes" which you can find documented in CPython here: https://docs.python.org/3/library/struc ... -alignment

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: first arg - mp_binary_get_size('@',...)

Post by jickster » Fri Apr 13, 2018 4:32 pm

dhylands wrote:
Fri Apr 13, 2018 12:16 am
The documentation for ustruct http://docs.micropython.org/en/latest/w ... le-ustruct mentions the subset of CPython's struct which is supported. The first argument passed to mp_binary_get_size is the "size/byte order prefixes" which you can find documented in CPython here: https://docs.python.org/3/library/struc ... -alignment
Cool. Thanks.

Post Reply