[sane-devel] option size = 0 allowed ?

Henning Meier-Geinitz henning@meier-geinitz.de
Wed, 18 Dec 2002 17:45:22 +0100


On Wed, Dec 18, 2002 at 04:46:44PM +0100, Oliver Rauch wrote:
> On Wednesday 18 December 2002 11:55, Henning Meier-Geinitz wrote:
> > Hi,
> > > Furthermore, the umax backend changes the option size later. IMHO, that
> > > at least isn't allowed, because only the availablity or value of an
> > > option may change.
> >
> > It's not allowed. But at least the mustek backend does it also.
> Please can you point me to the paragraph where you think it is
> mentioned that it is not allowed to change constraints and option sizes?

See below.

This was discussed on sane-devel some times:

> "The returned option descriptor is guaranteed to
> remain valid (and at the returned address) until the device is closed."
> As long as the option descriptor (=pointer)

I think the phrase "option descriptor" refers to the data, not to
the pointer itsself. Otherwise the phrase "(and at the returned
address)" wouldn't make any sense. However, validity isn't defined.

> keeps valid (points
> to a memory block of the size of the structur and contains correct data)
>  I do not see a reason why it should not be allowed to change anything
>  in the option.

The intention of this sentence is to stop backends from overwriting
the same area of memory with option descriptors of different options.
At least that's what David Mosberger and A. Beck wrote on sane-devel.
So "correct data" means at least data for the option that was
specified when calling sane_get_option_descriptor.
I don't think it was written with the thought about changing option
constraints/sizes etc. in mind. So it doesn't help much here.

> The setting of an option may affect the value or availability of one or more
> {other} options. When this happens, the SANE backend sets this member in
> *i to indicate that the application should reload all options. This member may
> be set if and only if at least one option changed. 
> Here it is said that the value or availability of on option may have changed.
> I understand this as an example. It is not said (or I do not find it anywhere) 
> that it is not allowed to change the size of an option or the contents of a 
> constraint.

I don't think it's an example because everywhere else in the standard
examples are stated explicitely (e.g. ...). But I wasn't there when
the standard was written so I don't know.

During the discussion of SANE2 we explicitely added that the
constraint of the option can be changed here so this also assumes that
these are not only examples. 

Anyway: We should make it more clear in SANE2 and I think the correct
place to do this is in the definition of sane_get_option_descriptor.

There are several issues:

1) What is allowed to change in an option descriptor?
   - constraint (but not constraint type?)
   - size
   - availability (but not other capabilities?)
2) If SANE_INFO_RELOAD_OPTIONS is set, the options should be
   reloaded. In reality this means to parse the option descriptors
   again and call sane_control_option for each value.
   Calling sane_get_option_descriptor is not necessary, because the
   address of the option descriptor isn't allowed to change.
   So we should change the "should relaod" to a "must reload" because
   otherwise the frontend may crash when the size was decreased.