mupdf-rs icon indicating copy to clipboard operation
mupdf-rs copied to clipboard

Improve `unsafe` comments/documentation/encapsulation

Open itsjunetime opened this issue 11 months ago • 0 comments

As I've been poking through the code of this library recently, I've noticed that there are a lot of undocumented unsafe fns and blocks. I'd like to go through and improve documentation and encapsulation for a lot of these areas, if that's alright.

The specific steps that I feel could help with this a lot:

  • Apply the unsafe_op_in_unsafe_fn, clippy::multiple_unsafe_ops_per_block, and clippy::undocumented_unsafe_blocks lints in the Cargo.toml (and fix what they warn)
  • Replace a lot of the inner: *mut _ fields with inner: NonNull<_> instead to ensure the inner ptrs aren't null when we dereference them
  • Add utility fns that utilize NonNull::as_ref to get valid references to inner (for a lot of these wrapping structs) to avoid needing an unsafe block per-function

Do these all sound like reasonable steps? Would you accept PRs that take these steps?

itsjunetime avatar Feb 10 '25 20:02 itsjunetime