Skip to content

Track GC work for all managed bigarray allocations #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions ocaml/runtime/bigarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,31 @@ CAMLexport value
caml_ba_alloc(int flags, int num_dims, void * data, intnat * dim)
{
uintnat num_elts, asize, size;
int i;
int i, is_managed;
value res;
struct caml_ba_array * b;
intnat dimcopy[CAML_BA_MAX_NUM_DIMS];

CAMLassert(num_dims >= 0 && num_dims <= CAML_BA_MAX_NUM_DIMS);
CAMLassert((flags & CAML_BA_KIND_MASK) <= CAML_BA_CHAR);
for (i = 0; i < num_dims; i++) dimcopy[i] = dim[i];
size = 0;
if (data == NULL) {
num_elts = 1;
for (i = 0; i < num_dims; i++) {
if (caml_umul_overflow(num_elts, dimcopy[i], &num_elts))
caml_raise_out_of_memory();
}
if (caml_umul_overflow(num_elts,
caml_ba_element_size[flags & CAML_BA_KIND_MASK],
&size))
num_elts = 1;
for (i = 0; i < num_dims; i++) {
if (caml_umul_overflow(num_elts, dimcopy[i], &num_elts))
caml_raise_out_of_memory();
}
if (caml_umul_overflow(num_elts,
caml_ba_element_size[flags & CAML_BA_KIND_MASK],
&size))
caml_raise_out_of_memory();
if (data == NULL) {
data = malloc(size);
if (data == NULL && size != 0) caml_raise_out_of_memory();
flags |= CAML_BA_MANAGED;
}
asize = SIZEOF_BA_ARRAY + num_dims * sizeof(intnat);
res = caml_alloc_custom_mem(&caml_ba_ops, asize, size);
is_managed = ((flags & CAML_BA_MANAGED_MASK) == CAML_BA_MANAGED);
res = caml_alloc_custom_mem(&caml_ba_ops, asize, is_managed ? size : 0);
b = Caml_ba_array_val(res);
b->data = data;
b->num_dims = num_dims;
Expand Down