After doing a bit of serial device programming with the sb-posix:termios
interface, I discovered that the cfsetispeed and cfsetospeed weren't
working.

>From looking at the interface.lisp, it appears that the
define-protocol-class macro is just a bad idea.  Well, it puts a nice facade
on the alien object, but it drops any data in the alien object that is
not explicitly defined in define-protocol-class.

For reference...
Linux bump 3.12.3-1-ARCH #1 SMP PREEMPT Wed Dec 4 21:59:02 CET 2013 i686 GNU/Linux

In my case, /usr/bits/termios.h defines the struct termios:
typedef unsigned char   cc_t;
typedef unsigned int    speed_t;
typedef unsigned int    tcflag_t;

#define NCCS 32
struct termios
  {
    tcflag_t c_iflag;           /* input mode flags */
    tcflag_t c_oflag;           /* output mode flags */
    tcflag_t c_cflag;           /* control mode flags */
    tcflag_t c_lflag;           /* local mode flags */
    cc_t c_line;                        /* line discipline */
    cc_t c_cc[NCCS];            /* control characters */
    speed_t c_ispeed;           /* input speed */
    speed_t c_ospeed;           /* output speed */
#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
#define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
  };

The constants.lisp file grovels it into this alien type:
(STRUCT ALIEN-TERMIOS (IFLAG (UNSIGNED 32) :OFFSET 0)
    (OFLAG (UNSIGNED 32) :OFFSET 32)
    (CFLAG (UNSIGNED 32) :OFFSET 64)
    (LFLAG (UNSIGNED 32) :OFFSET 96)
    (PADDING-1-16 (ARRAY (SIGNED 8) 1) :OFFSET 128)
    (CC (ARRAY (UNSIGNED 8) 32) :OFFSET 136)
    (PADDING-11-49 (ARRAY (SIGNED 8) 11) :OFFSET 392))

interface.lisp uses the define-protocol-class helper translation
functions to pack and unpack the alien object like this:
SB-POSIX> (with-alien-termios a-termios ()
            (describe (alien-to-termios a-termios)))
#<TERMIOS {C84B7C1}>
  [standard-object]

Slots with :INSTANCE allocation:
  IFLAG  = 0
  OFLAG  = 0
  CFLAG  = 0
  LFLAG  = 0
  CC     = #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0)

As you can see, the termios object has all of the components defined in
the define-protocol-class macro, but nothing in the way of the extra
groveled information.

The termios interface functions (tcsetattr, tcgetattr, cfsetispeed,
cfsetospeed, cfgetispeed, cfgetospeed) all use termios-to-alien or
alien-to-termios to pack or unpack data and will all result in dropping
the c_line, c_ispeed and c_ospeed data.

There are other interfaces in interface.lisp that make use of
define-protocol-class that may have the same problem now or in the
future.  I'm not sure what the best solution is.  My current best guess
would be to rip define-protocol-class out and expose the alien objects.

Any thoughts?

Nick Patrick
npatrick04@gmail.com