Skip to content

Conversation

benjerming
Copy link

Hi, I am very thankyou import libmupdf into Rust community.
Now I am planning to add a feture to extract various path from fz_device::{fill_path, stroke_path} to fz_pixmap or image file, just mostly like source/fitz/draw-device.c does.
Unfortunately, source/fitz/draw-device.c depend on many functions in private header:

#include "context-imp.h"
#include "color-imp.h"
#include "draw-imp.h"
#include "glyph-imp.h"
#include "pixmap-imp.h"

So I want to import these useful functions in source/fitz directory.
Can this pr be merge into main repo? thanks very much.

@benjerming benjerming changed the title wrap some functions in imp header wrap some functions which in imp header Oct 11, 2025
@itsjunetime
Copy link
Collaborator

I think we generally try to manually write wrappers for all C(++) functions in wrapper.c so that we can catch thrown errors and handle them in C (since unwinding over ffi boundaries is ub iirc), so I don't think we want to manually expose more functions without wrappers.

Also, could you explain the changes to the function blocklists? It isn't immediately evident.

@ginnyTheCat
Copy link
Collaborator

since unwinding over ffi boundaries is ub iirc

Unwinding over ffi boundarys just aborts, but what mupdf does is implementing throwing/unwinding using long jump, which is not allowed in rust, but fz_throwing without having a fz_try up in the chain is undefined afaik, since there is no long jump target. Therefore having a wrapper in wrapper.c is essential for all functions that call fz_throw somewhere down the chain.

so I don't think we want to manually expose more functions without wrappers.

We already export all functions we have wrappers (mupdf_* functions) for without wrappers (fz_* functions) as well, you're just i guess just not allowed to call them with input that could error i guess.

@messense
Copy link
Owner

Now I am planning to add a feture to extract various path from fz_device::{fill_path, stroke_path} to fz_pixmap or image file, just mostly like source/fitz/draw-device.c does.
Unfortunately, source/fitz/draw-device.c depend on many functions in private header:

I'd suggest write it in C wrapper.{h,c} then expose the API in Rust side such that we don't need to expose imp headers.

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 this pull request may close these issues.

4 participants