Use explicit struct types in tests
authorStelian Ionescu <sionescu@cddr.org>
Sat, 23 Feb 2013 18:26:07 +0000 (19:26 +0100)
committerStelian Ionescu <sionescu@cddr.org>
Sat, 23 Feb 2013 18:26:07 +0000 (19:26 +0100)
tests/struct.lisp
tests/union.lisp

index a1c08d0..683afbb 100644 (file)
@@ -58,7 +58,7 @@
 
 ;; regression test: accessing a struct through a typedef
 
-(defctype xpto timeval)
+(defctype xpto (:struct timeval))
 
 (deftest struct.4
     (with-foreign-object (tv 'xpto)
 (defcstruct s-ch
   (a-char :char))
 
+(defctype s-ch (:struct s-ch))
+
 (defcstruct s-s-ch
   (another-char :char)
   (a-s-ch s-ch))
 
+(defctype s-s-ch (:struct s-s-ch))
+
 (defcvar "the_s_s_ch" s-s-ch)
 
 (deftest struct.alignment.1
     (list 'a-char (foreign-slot-value
-                   (foreign-slot-value *the-s-s-ch* 's-s-ch 'a-s-ch)
+                   (foreign-slot-pointer *the-s-s-ch* 's-s-ch 'a-s-ch)
                    's-ch 'a-char)
           'another-char (foreign-slot-value *the-s-s-ch* 's-s-ch 'another-char))
   (a-char 1 another-char 2))
   (another-char :char)
   (a-short :short))
 
+(defctype s-short (:struct s-short))
+
 (defcstruct s-s-short
   (yet-another-char :char)
   (a-s-short s-short))
 
+(defctype s-s-short (:struct s-s-short))
+
 (defcvar "the_s_s_short" s-s-short)
 
 (deftest struct.alignment.2
   (a-double :double)
   (another-char :char))
 
+(defctype s-double (:struct s-double))
+
 (defcstruct s-s-double
   (yet-another-char :char)
   (a-s-double s-double)
   (a-short :short))
 
+(defctype s-s-double (:struct s-s-double))
+
 (defcvar "the_s_s_double" s-s-double)
 
 (deftest struct.alignment.3
   (a-s-s-double s-s-double)
   (last-char :char))
 
+(defctype s-s-s-double (:struct s-s-s-double))
+
 (defcvar "the_s_s_s_double" s-s-s-double)
 
 (deftest struct.alignment.4
   (a-double :double)
   (a-short  :short))
 
+(defctype s-double2 (:struct s-double2))
+
 (defcstruct s-s-double2
   (a-char        :char)
   (a-s-double2   s-double2)
   (another-short :short))
 
+(defctype s-s-double2 (:struct s-s-double2))
+
 (defcvar "the_s_s_double2" s-s-double2)
 
 (deftest struct.alignment.5
   (a-long-long :long-long)
   (a-short     :short))
 
+(defctype s-long-long (:struct s-long-long))
+
 (defcstruct s-s-long-long
   (a-char        :char)
   (a-s-long-long s-long-long)
   (another-short :short))
 
+(defctype s-s-long-long (:struct s-s-long-long))
+
 (defcvar "the_s_s_long_long" s-s-long-long)
 
 (deftest struct.alignment.6
   (a-s-double2   s-double2)
   (another-short :short))
 
+(defctype s-s-double3 (:struct s-s-double3))
+
 (defcstruct s-s-s-double3
   (a-s-s-double3  s-s-double3)
   (a-char         :char))
 
+(defctype s-s-s-double3 (:struct s-s-s-double3))
+
 (defcvar "the_s_s_s_double3" s-s-s-double3)
 
 (deftest struct.alignment.7
 
 (defcstruct empty-struct)
 
+(defctype empty-struct (:struct empty-struct))
+
 (defcstruct with-empty-struct
   (foo empty-struct)
   (an-int :int))
 (defcstruct s1
   (an-int :int))
 
+(defctype s1 (:struct s1))
+
 (defcstruct s2
   (an-s1 s1))
 
+(defctype s2 (:struct s2))
+
 (deftest struct.nested-setf
     (with-foreign-object (an-s2 's2)
       (setf (foreign-slot-value (foreign-slot-value an-s2 's2 'an-s1)
   (an-unsigned-long-long :unsigned-long-long)
   (a-short               :short))
 
+(defctype s-unsigned-long-long (:struct s-unsigned-long-long))
+
 (defcstruct s-s-unsigned-long-long
   (a-char                 :char)
   (a-s-unsigned-long-long s-unsigned-long-long)
   (another-short          :short))
 
+(defctype s-s-unsigned-long-long (:struct s-s-unsigned-long-long))
+
 (defcvar "the_s_s_unsigned_long_long" s-s-unsigned-long-long)
 
 (deftest struct.alignment.8
 
 (define-c-struct-wrapper timeval ())
 
-(define-c-struct-wrapper (timeval2 timeval) ()
+(define-c-struct-wrapper (timeval2 (:struct timeval)) ()
   (tv-secs))
 
 (defmacro with-example-timeval (var &body body)
   (b :int))
 
 (defctype struct-pair-typedef1 (:struct struct-pair))
-(defctype struct-pair-typedef2 struct-pair)
+(defctype struct-pair-typedef2 (:pointer (:struct struct-pair)))
 
 (deftest struct.unparse.1
     (mapcar (alexandria:compose #'cffi::unparse-type #'cffi::parse-type)
    :pointer))
 
 (defmethod translate-from-foreign (pointer (type pair))
-  (with-foreign-slots ((a b) pointer struct-pair)
+  (with-foreign-slots ((a b) pointer (:struct struct-pair))
     (cons a b)))
 
 (defmethod translate-into-foreign-memory (object (type pair) pointer)
-  (with-foreign-slots ((a b) pointer struct-pair)
+  (with-foreign-slots ((a b) pointer (:struct struct-pair))
     (setf a (car object)
           b (cdr object))))
 
 (defmethod translate-to-foreign (object (type pair))
-  (let ((p (foreign-alloc 'struct-pair)))
+  (let ((p (foreign-alloc '(:struct struct-pair))))
     (translate-into-foreign-memory object type p)
     (values p t)))
 
   (p (:pointer (:struct struct-pair)))
   (c :int))
 
+(defctype struct-pair+1 (:struct struct-pair+1))
+
 (defmethod translate-from-foreign (pointer (type pair+1))
   (with-foreign-slots ((p c) pointer struct-pair+1)
     (cons p c)))
          (foreign-type-size '(:struct single-byte-struct)))
   t)
 
-(defctype single-byte-struct-alias single-byte-struct)
+(defctype single-byte-struct-alias (:struct single-byte-struct))
 
 (deftest bare-struct-types.2
     (eql (foreign-type-size 'single-byte-struct-alias)
index bd966d8..091751b 100644 (file)
@@ -31,6 +31,8 @@
   (int-value :unsigned-int)
   (bytes :unsigned-char :count 4))
 
+(defctype uint32-bytes (:union uint32-bytes))
+
 (defun int-to-bytes (n)
   "Convert N to a list of bytes using a union."
   (with-foreign-object (obj 'uint32-bytes)