• Jim Mussared's avatar
    py/misc: Change sizeof to offsetof for variable-length alloc. · b6a97784
    Jim Mussared authored
    
    
    This fixes the case where e.g.
    
        struct foo_t {
          mp_obj_t x;
          uint16_t y;
          char buf[];
        };
    
    will have `sizeof(struct foo_t)==8`, but `offsetof(struct foo_t, buf)==6`.
    
    When computing the size to allocate for `m_new_obj_var` we need to use
    offsetof to avoid over-allocating. This is important especially when it
    might cause it to spill over into another GC block.
    
    This work was funded through GitHub Sponsors.
    Signed-off-by: default avatarJim Mussared <jim.mussared@gmail.com>
    b6a97784
modthread.c 10.6 KB