modues/py_ml: Round-up dynamic alloc size.

This commit is contained in:
iabdalkader 2024-12-31 08:38:57 +01:00
parent 22d75c6726
commit 96e4dfe6b3

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. // The model's data will Not be free'd on exceptions.
fb_alloc_mark_permanent(); fb_alloc_mark_permanent();
} else { } else {
// Keeps a reference to the GC block. // Align size and memory and keep a reference to the GC block.
model->_raw = xalloc(model->size + IMLIB_ML_MODEL_ALIGN); 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); model->data = (void *) (((uintptr_t) model->_raw + IMLIB_ML_MODEL_ALIGN) & ~IMLIB_ML_MODEL_ALIGN);
} }
file_read(&fp, model->data, model->size); file_read(&fp, model->data, model->size);