Skip to content
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

Question: "cannot use mapped file" #32

Open
yilinwei opened this issue Dec 24, 2022 · 2 comments · May be fixed by #41
Open

Question: "cannot use mapped file" #32

yilinwei opened this issue Dec 24, 2022 · 2 comments · May be fixed by #41

Comments

@yilinwei
Copy link

Hi,

I'm currently playing around with using ocaml-cairo as the renderer for a toy GUI project and calling of_data32 I get the error that a mapped file cannot be used.

Why is this the case? Is it a fundamental limitation with the cairo library, or with the Bigarray representation or something else?

@Chris00
Copy link
Owner

Chris00 commented Feb 5, 2023

Frankly, I do not remember. Maybe you want to try and, if it works, open a PR?

@talex5
Copy link

talex5 commented Dec 5, 2024

I just hit this too. I suspect the restriction is because of this:

ocaml-cairo/src/cairo_stubs.c

Lines 1573 to 1578 in 918ef6e

proxy = malloc(sizeof(struct caml_ba_proxy));
if (proxy == NULL) return(CAIRO_STATUS_NO_MEMORY);
proxy->refcount = 2; /* original array + surface */
proxy->data = b->data;
proxy->size = 0; /* CAML_BA_MAPPED_FILE excluded by the calling fun */
b->proxy = proxy;

The proxy needs to know the size so that it can unmap it.

The corresponding code in OCaml is https://github.com/ocaml/ocaml/blob/061adb721511a5d387e67c56abbfa57c34e9efe0/runtime/bigarray.c#L1083-L1090:

    proxy = malloc(sizeof(struct caml_ba_proxy));
    if (proxy == NULL) caml_raise_out_of_memory();
    caml_atomic_counter_init(&proxy->refcount, 2);
    /* initial refcount: 2 = original array + sub array */
    proxy->data = b1->data;
    proxy->size =
      b1->flags & CAML_BA_MAPPED_FILE ? caml_ba_byte_size(b1) : 0;
    b1->proxy = proxy;

Another possible reason is that file access might be slow, so possibly the runtime lock should be released during Cairo operations. But the file is likely to be an in-memory shm file anyway.

And also, caml_cairo_image_bigarray_finalize calls free instead of munmap, which goes badly.

@talex5 talex5 linked a pull request Dec 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants