Closed bodograumann closed 8 years ago
oh, and here is the documentation link (“Code Flow”): http://www.sane-project.org/html/doc013.html
Not sure I'm covinced by this. The question is always where to draw the line between trying to prevent users to shoot themselves in the foot and simple code. From my point of view the code behaves correctly and works as documented (true, one can always argue that "should" is not equal to "must", however from my experience what in an API documentation is written as "should" almost always effectively means "must"). If you feel strongly about this however, feel free to open a pull request with a proposal.
I agree that most of what I suggested is debatable and it’s a question of project policy. But I think the actual cause of the segfault is a true bug. I.e. sane_close
should not implicitly be called if sane_exit
was called before. If we assume the user properly uses the sequence
sane.init
,sane.open
,SaneDev.close
,sane.exit
,there would be no need for an implicit SaneDev.close
.
So basically something like https://github.com/python-pillow/Sane/commit/37cd9f78cc78c362db1f48028c848ab8954cbdf8 (untested)?
Yes, this works for me.
Committed, thanks for testing.
I forgot to close the
SaneDev
that I opened, but I did issue asane.exit
. This caused a segfault when exiting python. E.g.:The reason is, that when the
SaneDev
is destroyed on exit,sane_close
is called implicitly, even ifsane_exit
was already called.I don’t know if it should be valid to skip
sane_close
, as the documentation only says:In any case, I think that
sane.exit
should complain about any open devices, because it does invalidate theSaneDev
instances.Aside, the documentation goes on to say:
So
sane.exit
should probably also be called implicitly on exit.