[sane-devel] Re: dc240 only works with GCC

Peter Fales peter@fales-lorenz.net
Sat, 12 Oct 2002 21:20:30 -0500


Abel,

Thanks for the suggesting those changes.  When I said I didn't see
any easy way to fix it, I had your method in mind as the "hard" way.
It sure is a lot easier to let the compiler take care of the little
details like that.  But I guess that's the price you have to 
pay for portability.  I went ahead and tested your changes, and since
the structures are referenced too many times, it wasn't as bad as I
thought.  Other than changing "4+" to "2+" in your defines, your
code worked pretty much out of the box.  

The new code seems to work OK, but I don't think it's a good idea
to submit it just before the 1.0.9 code freeze.  I'll commit
the CVS changes to the next release.

-- 
Peter Fales

On Sat, Oct 12, 2002 at 12:04:39PM +0200, abel deuring wrote:
> Peter Fales wrote:
> >I've made this change.  I don't see any easy way to fix it
> >in portable way, and more importantly I don't have any way to 
> >test it.   I'll be glad to take patches if someone wants to supply
> >them.
> >
> >
> >On Fri, Oct 11, 2002 at 06:50:14PM +0200, Petter Reinholdtsen wrote:
> >
> >>
> >>I just discovered this code when trying to find out why the CVS
> >>version of sane-backends fail to compile on HP/UX using the native
> >>compiler.
> >>
> >>  #ifdef __GNUC__
> >>  #define UNUSEDARG __attribute__ ((unused))
> >>  #define PACKED    __attribute__ ((packed))
> >>  #else
> >>  #define UNUSEDARG
> >>  /* You need to figure out a way to ensure that there are no holes
> >>   * in the following dir_buf structure - it has to match data read from
> >>   * the camera.  gcc does this with __attribute__ ((packed))
> >>   */
> >>  #error
> >>  #endif
> >>
> >>
> 
> Well, perhaps I don't get the point -- but looking through dc240.h, it 
> seems to me that all you want to achieve is that struct dir_buf does not 
> have any padding bytes between members of the struct.
> 
> All the SCSI backends have to deal with the same problem for SCSI 
> command and data buffers: you may have non-32-bit-aligned 32 bit 
> integers, and the integers are perhaps not in the "native" byte order of 
> the machine.
> 
> Regading struct dir_buf, what about the following (written without a 
> serious look into dc240.c -- please bear with me, if I'm writing 
> nonsense...):
> 
> #define CAMDIRENTRYSIZE 20
> #define DIRENTRIES 1000
> 
> SANE_Byte dir_buf[2 + CAMDIRENTRYSIZE * DIRENTRIES];
> 
> #define get_name(entry) (SANE_Char*) &dir_buf[4+CAMDIRENTRYSIZE*(entry)]
> #define get_attr(entry) dir_buf[4+11+CAMDIRENTRYSIZE*(entry)]
> #define get_create_time(entry) \
>    (  dir_buf[4+12+CAMDIRENTRYSIZE*(entry)] << 8 \
>     + dir_buf[4+13+CAMDIRENTRYSIZE*(entry)])
> 
> 
> Abel