</sect2>
<sect2>
<title>Cross-Implementation Optimization</title>
-<para>To fully optimize across platforms, both explicit type information
-must be passed to dereferencing of pointers and arrays. Though this
-optimization only helps with &acl;, &uffi; is designed to require this
-type information be passed the dereference functions. Second, declarations
-of type should be made in functions, structures, and classes where
-foreign objects will be help. This will optimize access for &lw;
-</para>
-</sect2>
+ <para>
+ To fully optimize across platforms, both explicit type
+ information must be passed to dereferencing of pointers and
+ arrays. Though this optimization only helps with &acl;, &uffi;
+ is designed to require this type information be passed the
+ dereference functions. Second, declarations of type should be
+ made in functions, structures, and classes where foreign
+ objects will be help. This will optimize access for &lw;
+ </para>
+ <para>
+ Here is an example that should both methods being used for
+ maximum cross-implementation optimization:
+ <programlisting>
+(let ((a-foreign-struct (allocate-foreign-object 'the-struct-type)))
+ (uffi-declare 'the-struct-type a-foreign-struct)
+ (get-slot-value a-foreign-struct 'the-struct-type 'field-name))
+ </programlisting>
+ </para>
+ </sect2>
</sect1>
</chapter>
<refsect1>
<title>Examples</title>
<programlisting>
- (load-foreign-library #p"/usr/lib/libmysqlclient.so" "mysql" '("c"))
+ (load-foreign-library #p"/usr/lib/libmysqlclient.so"
+ :module "mysql"
+ :supporting-libraries '("c"))
=> T
</programlisting>
</refsect1>
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: gettime.cl,v 1.3 2002/03/10 04:15:33 kevin Exp $
+;;;; $Id: gettime.cl,v 1.4 2002/03/10 22:29:47 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
(defun gettime ()
"Returns the local time"
(let* ((time (uffi:allocate-foreign-object time-t)))
+;; (uffi:uffi-declare time-t time)
(c-time time)
- (let* ((tm-ptr (c-localtime time))
- (time-string (format nil "~2d/~2,'0d/~d ~2d:~2,'0d:~2,'0d"
- (1+ (uffi:get-slot-value tm-ptr 'mon 'tm))
- (uffi:get-slot-value tm-ptr 'mday 'tm)
- (+ 1900 (uffi:get-slot-value tm-ptr 'year 'tm))
- (uffi:get-slot-value tm-ptr 'hour 'tm)
- (uffi:get-slot-value tm-ptr 'min 'tm)
- (uffi:get-slot-value tm-ptr 'sec 'tm)
- )))
- (uffi:free-foreign-object time)
- time-string)
+ (let ((tm-ptr (c-localtime time)))
+;; (uffi:uffi-declare (* tm) tm-ptr)
+ (let ((time-string (format nil "~2d/~2,'0d/~d ~2d:~2,'0d:~2,'0d"
+ (1+ (uffi:get-slot-value tm-ptr 'tm 'mon))
+ (uffi:get-slot-value tm-ptr 'tm 'mday)
+ (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year))
+ (uffi:get-slot-value tm-ptr 'tm 'hour)
+ (uffi:get-slot-value tm-ptr 'tm 'min)
+ (uffi:get-slot-value tm-ptr 'tm 'sec)
+ )))
+ (uffi:free-foreign-object time)
+ time-string))
))
#+test-uffi
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: aggregates.cl,v 1.2 2002/03/10 11:13:07 kevin Exp $
+;;;; $Id: aggregates.cl,v 1.3 2002/03/10 22:29:47 kevin Exp $
;;;;
;;;; This file is part of the UFFI.
;;;;
)
-(defmacro get-slot-value (obj slot type)
+(defmacro get-slot-value (obj type slot)
#+(or lispworks cmu) (declare (ignore type))
#+allegro
`(ff:fslot-value-typed ,type :c ,obj ,slot)
`(alien:slot ,obj ,slot)
)
-(defmacro get-slot-pointer (obj slot type)
+(defmacro get-slot-pointer (obj type slot)
#+(or lispworks cmu) (declare (ignore type))
#+allegro
`(ff:fslot-value-typed ,type :c ,obj ,slot)
`(alien:slot ,obj ,slot)
)
-(defmacro deref-array (obj i type)
+(defmacro deref-array (obj type i)
"Returns a field from a row"
#+(or lispworks cmu) (declare (ignore type))
#+cmu `(alien:deref ,obj ,i)
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: primitives.cl,v 1.1 2002/03/10 21:48:50 kevin Exp $
+;;;; $Id: primitives.cl,v 1.2 2002/03/10 22:29:47 kevin Exp $
;;;;
;;;; This file is part of the UFFI.
;;;;
#+(or lispworks allegro)
(declare (ignore type name))
#+cmu
- `(declare (type (alien ,type) ,name))
+ `(declare (type (alien:alien ,type)) ,name)
)
(defmacro slot-type (type)
'((* . *) (:void . c-call:void)
(:short . c-call:short)
(:pointer-void . (* t))
- (:cstring . c-call:cstring)
+ (:cstring . c-call:c-string)
(:char . c-call:char)
(:unsigned-char . (alien:unsigned 8))
(:byte . (alien:unsigned 8))
;;;;
;;;; Copyright (c) 2002 Kevin M. Rosenberg
;;;;
-;;;; $Id: gettime.cl,v 1.3 2002/03/10 04:15:33 kevin Exp $
+;;;; $Id: gettime.cl,v 1.4 2002/03/10 22:29:47 kevin Exp $
;;;;
;;;; This file is part of UFFI.
;;;;
(defun gettime ()
"Returns the local time"
(let* ((time (uffi:allocate-foreign-object time-t)))
+;; (uffi:uffi-declare time-t time)
(c-time time)
- (let* ((tm-ptr (c-localtime time))
- (time-string (format nil "~2d/~2,'0d/~d ~2d:~2,'0d:~2,'0d"
- (1+ (uffi:get-slot-value tm-ptr 'mon 'tm))
- (uffi:get-slot-value tm-ptr 'mday 'tm)
- (+ 1900 (uffi:get-slot-value tm-ptr 'year 'tm))
- (uffi:get-slot-value tm-ptr 'hour 'tm)
- (uffi:get-slot-value tm-ptr 'min 'tm)
- (uffi:get-slot-value tm-ptr 'sec 'tm)
- )))
- (uffi:free-foreign-object time)
- time-string)
+ (let ((tm-ptr (c-localtime time)))
+;; (uffi:uffi-declare (* tm) tm-ptr)
+ (let ((time-string (format nil "~2d/~2,'0d/~d ~2d:~2,'0d:~2,'0d"
+ (1+ (uffi:get-slot-value tm-ptr 'tm 'mon))
+ (uffi:get-slot-value tm-ptr 'tm 'mday)
+ (+ 1900 (uffi:get-slot-value tm-ptr 'tm 'year))
+ (uffi:get-slot-value tm-ptr 'tm 'hour)
+ (uffi:get-slot-value tm-ptr 'tm 'min)
+ (uffi:get-slot-value tm-ptr 'tm 'sec)
+ )))
+ (uffi:free-foreign-object time)
+ time-string))
))
#+test-uffi