Skip to content

Issue/107 Reuse cached SANE_Parameters in SaneDev_snap instead of a second sane_get_parameters call - #109

Open
carygravel wants to merge 2 commits into
python-pillow:mainfrom
carygravel:issue/107
Open

Issue/107 Reuse cached SANE_Parameters in SaneDev_snap instead of a second sane_get_parameters call#109
carygravel wants to merge 2 commits into
python-pillow:mainfrom
carygravel:issue/107

Conversation

@carygravel

@carygravel carygravel commented Aug 23, 2026

Copy link
Copy Markdown

Some SANE backends (e.g. Epson's epsonscan2) return SANE_STATUS_INVAL on a second sane_get_parameters() call after sane_start. The Python wrapper's get_parameters() already retrieves the parameters successfully, but snap() then calls sane_get_parameters() again internally and fails on those backends, raising _sane.error: Invalid argument.

Cache the parameters from the most recent get_parameters() call in the SaneDevObject and reuse them in SaneDev_snap, falling back to sane_get_parameters() only when the cache is empty (snap called without a prior get_parameters). Invalidate the cache on sane_start() and update it when a subsequent frame is started.

…_get_parameters call

Some SANE backends (e.g. Epson's epsonscan2) return SANE_STATUS_INVAL on a
second sane_get_parameters() call after sane_start. The Python wrapper's
get_parameters() already retrieves the parameters successfully, but snap()
then calls sane_get_parameters() again internally and fails on those
backends, raising `_sane.error: Invalid argument`.

Cache the parameters from the most recent get_parameters() call in the
SaneDevObject and reuse them in SaneDev_snap, falling back to
sane_get_parameters() only when the cache is empty (snap called without a
prior get_parameters). Invalidate the cache on sane_start() and update it
when a subsequent frame is started.
Add a mock libsane backend (tests/mock/libsane_mock.c) that replicates the
INVAL-on-second-sane_get_parameters behavior and a regression test that
fails without the fix (tests/test_snap_params_cache.py). The test exercises
snap() through the cached-params path at depth-8, depth-1, and snap without
a prior get_parameters. Wire the test into CI.
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.

1 participant