Merge pull request #2571 from openmv/py_ml_fix

modues/py_ml: Round-up dynamic alloc size.
This commit is contained in:
Ibrahim Abdelkader 2024-12-31 09:45:34 +02:00 committed by GitHub
commit 8c0eaa86b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -379,8 +379,9 @@ mp_obj_t py_ml_model_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
// The model's data will Not be free'd on exceptions.
fb_alloc_mark_permanent();
} else {
// Keeps a reference to the GC block.
model->_raw = xalloc(model->size + IMLIB_ML_MODEL_ALIGN);
// Align size and memory and keep a reference to the GC block.
size_t size = (model->size + IMLIB_ML_MODEL_ALIGN) & ~IMLIB_ML_MODEL_ALIGN;
model->_raw = xalloc(size + IMLIB_ML_MODEL_ALIGN);
model->data = (void *) (((uintptr_t) model->_raw + IMLIB_ML_MODEL_ALIGN) & ~IMLIB_ML_MODEL_ALIGN);
}
file_read(&fp, model->data, model->size);