r5495: *** empty log message ***
authorKevin M. Rosenberg <kevin@rosenberg.net>
Thu, 14 Aug 2003 19:35:05 +0000 (19:35 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Thu, 14 Aug 2003 19:35:05 +0000 (19:35 +0000)
13 files changed:
debian/changelog
doc/html.tar.gz
doc/ref.sgml
doc/uffi.pdf
src/libraries.lisp
src/objects.lisp
src/package.lisp
tests/casts.lisp [new file with mode: 0644]
tests/pointers.lisp [new file with mode: 0644]
tests/structs.lisp
tests/uffi-c-test-lib.c
uffi-tests.asd
uffi.asd

index 128e21070df1befbf71925a8ddd9d1ab7a7aa231..93a93eda11fb98d2f1713126c80fd8ecc774129e 100644 (file)
@@ -1,3 +1,9 @@
+cl-uffi (1.2.23-1) unstable; urgency=low
+
+  * New upstream with fixes suggested and patches submitted by Edi Weitz.
+
+ -- Kevin M. Rosenberg <kmr@debian.org>  Thu, 14 Aug 2003 12:26:07 -0600
+
 cl-uffi (1.2.22-1) unstable; urgency=low
 
   * New upstream with Lispworks patch from Edi Weitz
index e36f2ce8cd398776edb3ff71605ce4cebd0ebf69..f3dcd22acb0ab6e596be51da7a9b6bd2607c2a54 100644 (file)
Binary files a/doc/html.tar.gz and b/doc/html.tar.gz differ
index 510dd4ca3a64351ce68ad4c22e25e95db7680d9a..cbf5336613c678cbf354dee67f10c2463dac9c63 100644 (file)
@@ -759,7 +759,7 @@ the array.
       <refsect1>
        <title>Examples</title>
        <programlisting>
-(def-array ca :char)
+(def-array-pointer ca :char)
 (let ((fs (convert-to-foreign-string "ab")))
    (values (null-char-p (deref-array fs 'ca 0))
            (null-char-p (deref-array fs 'ca 2))))
@@ -767,6 +767,14 @@ the array.
    &t;
        </programlisting>
       </refsect1>
+      <refsect1>
+       <title>Notes</title>
+        <para>
+  The TYPE argument is ignored for CL implementations other than
+  AllegroCL. If you want to cast a pointer to another type use
+  WITH-CAST-POINTER together with DEREF-POINTER/DEREF-ARRAY.
+        </para>
+      </refsect1>
       <refsect1>
        <title>Side Effects</title>
        <para>None.</para>
@@ -1216,6 +1224,14 @@ much better with static allocation.
 </programlisting>
        </para>
       </refsect1>
+      <refsect1>
+       <title>Notes</title>
+        <para>
+  The TYPE argument is ignored for CL implementations other than
+  AllegroCL. If you want to cast a pointer to another type use
+  WITH-CAST-POINTER together with DEREF-POINTER/DEREF-ARRAY.
+        </para>
+      </refsect1>
       <refsect1>
        <title>Side Effects</title>
        <para>None.</para>
@@ -1266,8 +1282,9 @@ a character.
       <refsect1>
        <title>Description</title>
        <para>
-         Ensures that an object obtained by dereferencing a 
-<constant>:char</constant> pointer is a character.
+         Ensures that an objects obtained by dereferencing  
+<constant>:char</constant> and <constant>:unsigned-char</constant>
+pointers are a lisp character.
        </para>
       </refsect1>
       <refsect1>
@@ -1488,6 +1505,77 @@ if a cstring returned by a function is &null;.
       </refsect1>
     </refentry>
 
+    <refentry id="with-cast-pointer">
+      <refnamediv>
+       <refname>with-cast-pointer</refname>
+       <refpurpose>Wraps a body of code with a pointer cast to a new type.
+       </refpurpose>
+       <refclass>Macro</refclass>
+      </refnamediv>
+      <refsynopsisdiv>
+       <title>Syntax</title>
+       <synopsis>
+         <function>with-cast-pointer</function> <replaceable>binding-name ptr type &amp; body body</replaceable> => <returnvalue>value</returnvalue>
+       </synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+       <title>Arguments and Values</title>
+       <variablelist>
+         <varlistentry>
+           <term><parameter>ptr</parameter></term>
+           <listitem>
+             <para>A pointer to a foreign object.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><parameter>type</parameter></term>
+           <listitem>
+             <para>A foreign type of the object being pointed to.
+             </para>
+           </listitem>
+         </varlistentry>
+         <varlistentry>
+           <term><returnvalue>value</returnvalue></term>
+           <listitem>
+             <para>The value of the object where the pointer points.
+             </para>
+           </listitem>
+         </varlistentry>
+       </variablelist>
+      </refsect1>
+      <refsect1>
+       <title>Description</title>
+       <para>
+  Executes BODY with POINTER casted to be a pointer to type TYPE. If
+  BINDING-NAME is provided the casted pointer will be bound to this
+  name during the execution of BODY. If BINDING-NAME is not provided
+  POINTER must be a name bound to the pointer which should be
+  casted. This name will be bound to the casted pointer during the
+  execution of BODY.
+
+  This is a no-op in AllegroCL but will wrap BODY in a LET form if
+  BINDING-NAME is provided.
+
+  This macro is meant to be used in conjunction with DEREF-POINTER or
+  DEREF-ARRAY. In Allegro CL the "cast" will actually take place in
+  DEREF-POINTER or DEREF-ARRAY.
+       </para>
+      </refsect1>
+      <refsect1>
+       <title>Side Effects</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Affected by</title>
+       <para>None.</para>
+      </refsect1>
+      <refsect1>
+       <title>Exceptional Situations</title>
+       <para>None.</para>
+      </refsect1>
+    </refentry>
+
 </reference>
 
     <reference>
@@ -2074,7 +2162,7 @@ foreign function. If <constant>:void</constant> indicates module does not return
       <refsect1>
        <title>Syntax</title>
 <synopsis>
-         <function>load-foreign-library</function> <replaceable>filename &amp;key module supporting-libraries</replaceable> => <returnvalue>success</returnvalue>
+         <function>load-foreign-library</function> <replaceable>filename &amp;key module supporting-libraries force-load</replaceable> => <returnvalue>success</returnvalue>
 </synopsis>
       </refsect1>
       <refsect1>
@@ -2105,6 +2193,13 @@ link the foreign library. (Required by CMUCL)
              </para>
            </listitem>
          </varlistentry>
+         <varlistentry>
+           <term><parameter>force-load</parameter></term>
+           <listitem>
+             <para>Forces the loading of the library if it has been previously loaded. 
+             </para>
+           </listitem>
+         </varlistentry>
          <varlistentry>
            <term><returnvalue>success</returnvalue></term>
            <listitem>
@@ -2120,7 +2215,7 @@ otherwise &nil;.
        <title>Description</title>
        <para>Loads a foreign library. Applies a module name to functions
 within the library. Ensures that a library is only loaded once during
-a session.
+a session. A library can be reloaded by using the <symbol>:force-load</symbol> key.
        </para>
       </refsect1>
       <refsect1>
index 7c2530b85b8dea93d1df5812a057e04602b480d9..f2b7c6066da08518d4299c9f7032e0537735b452 100644 (file)
Binary files a/doc/uffi.pdf and b/doc/uffi.pdf differ
index ff14928674c5cd4c438b3aed24b69eacfc69ed5d..094433548d3d14532bd13dba8bdfcd9609c477d7 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: libraries.lisp,v 1.9 2003/07/08 12:37:21 kevin Exp $
+;;;; $Id: libraries.lisp,v 1.10 2003/08/14 19:35:05 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -72,7 +72,7 @@ library type if type is not specified."
 
 (defun load-foreign-library (filename &key module supporting-libraries
                                           force-load)
-  #+(or allegro lispworks mcl) (declare (ignore module supporting-libraries))
+  #+(or allegro mcl) (declare (ignore module supporting-libraries))
   #+(or cmu scl sbcl) (declare (ignore module))
   
   (when (and filename (probe-file filename))
index 4930962437287a78af3c4233be16a14d83c7ea42..9938a8eed4cca472bf58bfef7295975fd6e47bb8 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: objects.lisp,v 1.15 2003/07/08 12:37:21 kevin Exp $
+;;;; $Id: objects.lisp,v 1.16 2003/08/14 19:35:05 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -118,7 +118,11 @@ an array of TYPE with size SIZE. The TYPE parameter is evaluated."
 #+mcl
 (defsetf deref-pointer deref-pointer-set)
 
-#+(or lispworks (and mcl (not openmcl))) ;; with LW, deref is a character
+#+lispworks
+(defmacro ensure-char-character (obj)
+  `(if (characterp ,obj) ,obj (code-char ,obj)))
+
+#+(and mcl (not openmcl)) 
 (defmacro ensure-char-character (obj)
   obj)
 
@@ -197,3 +201,30 @@ an array of TYPE with size SIZE. The TYPE parameter is evaluated."
   `(with-foreign-objects ((,var ,type)) 
      ,@body))
 
+#+lispworks
+(defmacro with-cast-pointer ((binding-name pointer type) &body body)
+  `(fli:with-coerced-pointer (,binding-name
+                          :type ',(convert-from-uffi-type (eval type) :type))
+      ,pointer
+    ,@body))
+
+#+(or cmu scl sbcl)
+(defmacro with-cast-pointer ((binding-name pointer type) &body body)
+  `(let ((,binding-name
+          (#+(or cmu scl) alien:cast
+           #+sbcl sb-alien:cast
+           ,pointer (* ,(convert-from-uffi-type (eval type) :type)))))
+    ,@body))
+
+#+allegro
+(defmacro with-cast-pointer ((binding-name pointer type) &body body)
+  (declare (ignore type))
+  `(let ((,binding-name ,pointer))
+    ,@body))
+
+#-(or lispworks cmu scl sbcl allegro)
+(defmacro with-cast-pointer ((binding-name pointer type) &body body)
+  (declare (ignore binding-name pointer type))
+  '(error "WITH-CAST-POINTER not (yet) implemented for ~A"
+          (lisp-implementation-type)))
+
index 9bd1b093d747382de5be47ee4dab1671b43b8de9..7ccb110f18154627fcab29bea150437417fcb98b 100644 (file)
@@ -49,6 +49,7 @@
    #:make-null-pointer
    #:+null-cstring-pointer+
    #:char-array-to-pointer
+   #:with-cast-pointer
    
    ;; string functions
    #:convert-from-cstring
diff --git a/tests/casts.lisp b/tests/casts.lisp
new file mode 100644 (file)
index 0000000..4e19cfd
--- /dev/null
@@ -0,0 +1,47 @@
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Name:          casts
+;;;; Purpose:       Tests of with-cast-pointer
+;;;; Programmer:    Kevin M. Rosenberg / Edi Weitz
+;;;; Date Started:  Aug 2003
+;;;;
+;;;; $Id: casts.lisp,v 1.1 2003/08/14 19:35:05 kevin Exp $
+;;;;
+;;;; *************************************************************************
+
+(in-package #:uffi-tests)
+
+(uffi:def-function ("cast_test_int" cast-test-int)
+    ()
+  :returning :pointer-void)
+
+(uffi:def-function ("cast_test_float" cast-test-float)
+    ()
+  :returning :pointer-void)
+
+(deftest cast.1
+  (progn
+    (uffi:with-cast-pointer (temp (cast-test-int) :int)
+      (assert (= (uffi:deref-pointer temp :int) 23)))
+    (let ((result (cast-test-int)))
+      (uffi:with-cast-pointer (result2 result :int)
+       (assert (= (uffi:deref-pointer result2 :int) 23)))
+      (uffi:with-cast-pointer (temp result :int)
+       (assert (= (uffi:deref-pointer temp :int) 23))))
+    t)
+  t)
+
+(deftest cast.2
+    (progn
+      (uffi:with-cast-pointer (temp (cast-test-float) :double)
+       (assert (= (uffi:deref-pointer temp :double) 3.21d0)))
+      (let ((result (cast-test-float)))
+       (uffi:with-cast-pointer (result2 result :double)
+         (assert (= (uffi:deref-pointer result2 :double) 3.21d0)))
+       (uffi:with-cast-pointer (temp result :double)
+         (assert (= (uffi:deref-pointer temp :double) 3.21d0))))
+      t)
+  t)
+
diff --git a/tests/pointers.lisp b/tests/pointers.lisp
new file mode 100644 (file)
index 0000000..9f704ff
--- /dev/null
@@ -0,0 +1,41 @@
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Name:          pointers.lisp
+;;;; Purpose:       Test file for UFFI pointers
+;;;; Programmer:    Kevin M. Rosenberg
+;;;; Date Started:  Aug 2003
+;;;;
+;;;; $Id: pointers.lisp,v 1.1 2003/08/14 19:35:05 kevin Exp $
+;;;;
+;;;; This file, part of UFFI, is Copyright (c) 2003 by Kevin M. Rosenberg
+;;;;
+;;;; *************************************************************************
+
+(in-package #:uffi-tests)
+
+(deftest chptr.1
+    (let ((native-string "test string"))
+      (uffi:with-foreign-string (fs native-string)
+       (characterp
+        (ensure-char-character
+         (deref-pointer fs :char)))))
+  t)
+
+(deftest chptr.2
+    (let ((native-string "test string"))
+      (uffi:with-foreign-string (fs native-string)
+       (characterp
+        (ensure-char-character
+         (deref-pointer fs :unsigned-char)))))
+  t)
+
+(deftest chptr.3
+    (let ((native-string "test string"))
+      (uffi:with-foreign-string (fs native-string)
+       (numberp
+        (deref-pointer fs :byte))))
+  t)
+
+       
index 1522a15f04110456cf649245086ac9045a6dd276..8518eeca22073c7b3d6963af3cee99768e3582dc 100644 (file)
@@ -3,13 +3,13 @@
 ;;;; FILE IDENTIFICATION
 ;;;;
 ;;;; Name:          structs.lisp
-;;;; Purpose:       UFFI Example file to strtol, uses pointer arithmetic
+;;;; Purpose:       Test file for UFFI structures
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: structs.lisp,v 1.1 2003/08/13 18:53:42 kevin Exp $
+;;;; $Id: structs.lisp,v 1.2 2003/08/14 19:35:05 kevin Exp $
 ;;;;
-;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
+;;;; This file, part of UFFI, is Copyright (c) 2002-2003 by Kevin M. Rosenberg
 ;;;;
 ;;;; *************************************************************************
 
 
 (uffi:def-foreign-type foo-ptr (* foo))
 
-(uffi:def-function "baz"
-    ((x :int))
-  :returning foo-ptr
-  :module "frob")
-
-(defun test ()
+;; tests that compilation worked
+(deftest structs.1 
   (with-foreign-object (p 'foo)
-    (baz p)))
+    t)
+  t)
 
index d8e9b49aa152a4782fa361f2413b47ba3cd294f6..c21a6e21376412b5ae28c8f8e73a25a95a215223 100644 (file)
@@ -6,7 +6,7 @@
  *  Programer:    Kevin M. Rosenberg
  *  Date Started: Mar 2002
  *
- *  CVS Id:   $Id: uffi-c-test-lib.c,v 1.1 2003/04/29 14:08:02 kevin Exp $
+ *  CVS Id:   $Id: uffi-c-test-lib.c,v 1.2 2003/08/14 19:35:05 kevin Exp $
  *
  * This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
  *
@@ -93,3 +93,19 @@ half_double_vector (int size, double* vec)
 
     
 
+DLLEXPORT
+void *
+cast_test_int () {
+  int *x = (int *) malloc(sizeof(int));
+  *x = 23;
+  return x;
+}
+
+DLLEXPORT
+void *
+cast_test_float ()
+{
+  double *y = (double *) malloc(sizeof(double));
+  *y = 3.21;
+  return y;
+}
index 6845a74ab6569ee0ab4d9f1beb671a12f3b7ec67..fc6e7167ff396cdec048c6236d4acefef1736366 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Author:        Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2003
 ;;;;
-;;;; $Id: uffi-tests.asd,v 1.8 2003/08/13 18:53:42 kevin Exp $
+;;;; $Id: uffi-tests.asd,v 1.9 2003/08/14 19:35:05 kevin Exp $
 ;;;; *************************************************************************
 
 (defpackage #:uffi-tests-system
               (:file "union" :depends-on ("package"))
               (:file "arrays" :depends-on ("package"))
               (:file "structs" :depends-on ("package"))
+              (:file "pointers" :depends-on ("package"))
               (:file "time" :depends-on ("package"))
               (:file "foreign-loader" :depends-on ("package"))
-              (:file "compress" :depends-on ("foreign-loader"))
               (:file "uffi-c-test-lib" :depends-on ("foreign-loader"))
+              (:file "compress" :depends-on ("foreign-loader"))
+              (:file "casts" :depends-on ("foreign-loader"))
               ))))
 
 (defmethod perform ((o test-op) (c (eql (find-system :uffi-tests))))
index dbdb11c908278d5b29527ad561c9e2c9f689daaf..84ae54d50eeb7a1dcce1a94ad757cc75d5228c7a 100644 (file)
--- a/uffi.asd
+++ b/uffi.asd
@@ -7,7 +7,7 @@
 ;;;; Author:        Kevin M. Rosenberg
 ;;;; Date Started:  Aug 2002
 ;;;;
-;;;; $Id: uffi.asd,v 1.27 2003/07/18 21:33:25 kevin Exp $
+;;;; $Id: uffi.asd,v 1.28 2003/08/14 19:35:05 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -46,6 +46,6 @@
 #+(or allegro lispworks cmu mcl cormanlisp sbcl scl)
 (defmethod perform ((o test-op) (c (eql (find-system 'uffi))))
   (oos 'load-op 'uffi-tests)
-  (oos 'test-op 'uffi-tests))
+  (oos 'test-op 'uffi-tests :force t))