#leptonica #memory-safety #image

leptonica-plumbing

Safe wrapper of leptonica-sys

13 releases (6 stable)

1.4.0 Apr 12, 2024
1.3.0 Jan 19, 2024
1.1.0 Nov 4, 2023
1.0.1 Feb 26, 2023
0.1.0 Mar 10, 2021

#846 in Images

Download history 1955/week @ 2025-09-23 2528/week @ 2025-09-30 2720/week @ 2025-10-07 3183/week @ 2025-10-14 2466/week @ 2025-10-21 2724/week @ 2025-10-28 2220/week @ 2025-11-04 2065/week @ 2025-11-11 1727/week @ 2025-11-18 1460/week @ 2025-11-25 2045/week @ 2025-12-02 2285/week @ 2025-12-09 2273/week @ 2025-12-16 1733/week @ 2025-12-23 1880/week @ 2025-12-30 2072/week @ 2026-01-06

8,347 downloads per month
Used in 18 crates (via tesseract-plumbing)

MIT license

28KB
560 lines

leptonica-plumbing

Crate to expose a safe version of the leptonica-sys api.

This is designed to expose the C API of leptonica in a safe manner.

Adding value by deviating from the API is a non-goal. That is left to libraries that build on top of leptonica-plumbing.

Motivation

I'm a maintainer of both leptess and tesseract-rs.

I noticed that there was a lot of duplication in how they interact with both leptonica-sys and tesseract-sys. Having multiple layers of abstraction in leptess and tesseract-rs made it hard to reason about their memory safety.

Having a safety layer that stays simple improves the correctness and maintainability of the above libraries.

Testing

To test for memory leaks, test with valgrind.

cargo test --release && valgrind --leak-check=yes --error-exitcode=1 --leak-check=full --show-leak-kinds=all "$(find target/*/deps/ -executable -name 'leptonica_plumbing-*')"

You may find that leptonica always leaks 16B of memory.

To test with a manually compiled Leptonica, test with additional environment variables

LD_LIBRARY_PATH="$(pwd)/../../DanBloomberg/leptonica/local/lib" PKG_CONFIG_PATH="$(pwd)/../../DanBloomberg/leptonica/local/lib/pkgconfig" cargo test

The two can be combined

LD_LIBRARY_PATH="$(pwd)/../../DanBloomberg/leptonica/local/lib" PKG_CONFIG_PATH="$(pwd)/../../DanBloomberg/leptonica/local/lib/pkgconfig" bash -c 'cargo test --release && valgrind --leak-check=yes --error-exitcode=1 --leak-check=full --show-leak-kinds=all "$(find target/*/deps/ -executable -name 'leptonica_plumbing-*')"'

Dependencies

~1.4–3.5MB
~75K SLoC