Updated for new CFFI where struct types must be refereced as (:struct <type>) instead of just <type>.

Pascal J. Bourguignon [2014-05-13 02:21]
Updated for new CFFI where struct types must be refereced as (:struct <type>) instead of just <type>.
Filename
iolib.termios.asd
streams.lisp
wrappers.lisp
diff --git a/iolib.termios.asd b/iolib.termios.asd
index ec49218..c70cc79 100644
--- a/iolib.termios.asd
+++ b/iolib.termios.asd
@@ -14,7 +14,7 @@
   :description "Termios (3p) api wrappers"
   :maintainer "Razbegaev N.V. <marsijanin@gmail.com>"
   :licence "MIT"
-  :depends-on (:iolib.base :iolib.syscalls :iolib.streams :cffi :cffi-grovel)
+  :depends-on (:iolib.base :iolib.syscalls :iolib.streams :cffi :cffi-grovel :trivial-garbage)
   :components
   #+unix
   (#+ecl
diff --git a/streams.lisp b/streams.lisp
index 6c1fd76..0af3c1b 100644
--- a/streams.lisp
+++ b/streams.lisp
@@ -3,18 +3,22 @@

 (in-package #:iolib.serial)

+
+(defvar *default-open-mode #o666)
+
+
 (defclass dual-channel-tty-gray-stream (dual-channel-gray-stream)
   ((path :reader tty-path :initarg :path :type string)
    (original-settings :reader original-settings :initarg :original-settings))
   (:documentation "Gray stream class for serial devices"))

 (defun open-serial-stream (path &key (flag (logior isys:o-rdwr isys:o-nonblock isys:o-noctty))
-                        (mode isys:*default-open-mode*)
+                        (mode *default-open-mode*)
 			(external-format :default))
   "Return `dual-channel-tty-gray-stream' instances associated
    with serial device"
   (let ((fd (isys:open path flag mode))
-        (termios (foreign-alloc 'termios)))
+        (termios (foreign-alloc '(:struct termios))))
     (%tcgetattr fd termios)
     (let ((s (make-instance 'dual-channel-tty-gray-stream
                             :fd fd
@@ -45,7 +49,7 @@
                                       (flag (logior isys:o-rdwr
                                                     isys:o-nonblock
                                                     isys:o-noctty))
-                                      (mode isys:*default-open-mode*)
+                                      (mode *default-open-mode*)
                                       (external-format :default))
                               &body body)
   "Wrapper around `with-open-stream' with a few settings for serial device:
@@ -67,7 +71,7 @@
    Other &key parameters is:
    - flag & mode: passed to `isys:open',
      (logior isys:o-rdwr isys:o-nonblock isys:o-noctty)
-     & isys:*default-open-mode* by default.
+     & *default-open-mode* by default.
    - external-format: see babel manual.
    - stream read/write timeout values: no default values are specified.

diff --git a/wrappers.lisp b/wrappers.lisp
index 8fdf13b..b4a56d1 100644
--- a/wrappers.lisp
+++ b/wrappers.lisp
@@ -54,17 +54,17 @@
   (let ((type (which-termios-keyword flag)))
     (unless type
       (error "Unknown termios option ~a" flag))
-    (setf (foreign-slot-value termios 'termios type)
+    (setf (foreign-slot-value termios '(:struct termios) type)
             ;; value specified => set (logior), reset over otherwise
             (funcall (if setp #'logior #'logandc2)
-                     (foreign-slot-value termios 'termios type)
+                     (foreign-slot-value termios '(:struct termios) type)
                      (foreign-enum-value type flag)))))

 (defun setup-termios-control-character (termios cc value)
   "Setup corresponding control character value.
    Value can be `control-character' keyword or integer."
   (setf (mem-aref (foreign-slot-pointer termios
-                                        'termios
+                                        '(:struct termios)
                                         'control-chars)
                        'cc
                        ;; constant name is offset
@@ -149,18 +149,18 @@
          (%tcgetattr fd test)
          (and
           (every #'(lambda (flag)
-                     (=  (foreign-slot-value set  'termios flag)
-                         (foreign-slot-value test 'termios flag)))
+                     (=  (foreign-slot-value set  '(:struct termios) flag)
+                         (foreign-slot-value test '(:struct termios) flag)))
                  '(iflag oflag cflag lflag))
           (dotimes (i nccs t)
             (when
                 (/= (mem-aref (foreign-slot-pointer set
-                                                    'termios
+                                                    '(:struct termios)
                                                     'control-chars)
                               'cc
                               i)
                     (mem-aref (foreign-slot-pointer test
-                                                    'termios
+                                                    '(:struct termios)
                                                     'control-chars)
                               'cc
                               i))
@@ -209,8 +209,8 @@
           (baud  (find-if #'termios-baud-rate-p options)))
       (when (and options (oddp (length opts-w/o-baud)))
         (error "Mailformed stty options list"))
-      (with-foreign-objects ((set  'termios)
-                             (test 'termios))
+      (with-foreign-objects ((set  '(:struct termios))
+                             (test '(:struct termios)))
         (%tcgetattr fd set)
         (when baud
           (%cfsetispeed set baud)
ViewGit