Skip to content

Commit

Permalink
manual: use explicit struct types
Browse files Browse the repository at this point in the history
  • Loading branch information
sionescu committed Feb 23, 2013
1 parent 1325b3d commit 3397cf9
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions doc/cffi-manual.texinfo
Expand Up @@ -3175,7 +3175,7 @@ has no particular order.
(tv-secs :long)
(tv-usecs :long))
CFFI> (foreign-slot-names 'timeval)
CFFI> (foreign-slot-names '(:struct timeval))
@result{} (TV-SECS TV-USECS)
@end lisp

Expand Down Expand Up @@ -3218,9 +3218,9 @@ bytes of a slot in a foreign struct type.
(tv-secs :long)
(tv-usecs :long))
CFFI> (foreign-slot-offset 'timeval 'tv-secs)
CFFI> (foreign-slot-offset '(:struct timeval) 'tv-secs)
@result{} 0
CFFI> (foreign-slot-offset 'timeval 'tv-usecs)
CFFI> (foreign-slot-offset '(:struct timeval) 'tv-usecs)
@result{} 4
@end lisp

Expand Down Expand Up @@ -3272,8 +3272,8 @@ For aggregate slots, this is the same value returned by
(x :int)
(y :int))
CFFI> (with-foreign-object (ptr 'point)
(foreign-slot-pointer ptr 'point 'x))
CFFI> (with-foreign-object (ptr '(:struct point))
(foreign-slot-pointer ptr '(:struct point) 'x))
@result{} #<FOREIGN-ADDRESS #xBFFF6E60>
;; @lispcmt{Note: the exact pointer representation varies from lisp to lisp.}
@end lisp
Expand Down Expand Up @@ -3331,12 +3331,12 @@ There are compiler macros for @code{foreign-slot-value} and its
(x :int)
(y :int))
CFFI> (with-foreign-object (ptr 'point)
CFFI> (with-foreign-object (ptr '(:struct point))
;; @lispcmt{Initialize the slots}
(setf (foreign-slot-value ptr 'point 'x) 42
(foreign-slot-value ptr 'point 'y) 42)
(setf (foreign-slot-value ptr '(:struct point) 'x) 42
(foreign-slot-value ptr '(:struct point) 'y) 42)
;; @lispcmt{Return a list with the coordinates}
(with-foreign-slots ((x y) ptr point)
(with-foreign-slots ((x y) ptr (:struct point))
(list x y)))
@result{} (42 42)
@end lisp
Expand Down Expand Up @@ -3387,7 +3387,7 @@ CFFI> (foreign-type-alignment :int)
(defcstruct foo
(a :char))
CFFI> (foreign-type-alignment 'foo)
CFFI> (foreign-type-alignment '(:struct foo))
@result{} 1
@end lisp

Expand Down Expand Up @@ -3431,7 +3431,7 @@ CFFI> (foreign-type-size :double)
@result{} 8
CFFI> (foreign-type-size :char)
@result{} 1
CFFI> (foreign-type-size 'foo)
CFFI> (foreign-type-size '(:struct foo))
@result{} 16
@end lisp

Expand Down Expand Up @@ -3715,9 +3715,9 @@ each var in @var{vars} to reference foreign slots in @var{ptr} of
CFFI> (with-foreign-object (time :int)
(setf (mem-ref time :int)
(foreign-funcall "time" :pointer (null-pointer) :int))
(foreign-funcall "gmtime" :pointer time tm))
(foreign-funcall "gmtime" :pointer time (:pointer (:struct tm))))
@result{} #<A Mac Pointer #x102A30>
CFFI> (with-foreign-slots ((sec min hour mday mon year) * tm)
CFFI> (with-foreign-slots ((sec min hour mday mon year) * (:struct tm))
(format nil "~A:~A:~A, ~A/~A/~A"
hour min sec (+ 1900 year) mon mday))
@result{} "7:22:47, 2005/8/2"
Expand Down

0 comments on commit 3397cf9

Please sign in to comment.