chiark / gitweb /
Fix compilation for Gtk with the new, stricter inheritance
[clg] / gffi / interface.lisp
index 0df9387e8d6025c0c231a0bcd4d91a0378abb792..d89e9a783dc291c40effa41004ff606ed7eb4c74 100644 (file)
@@ -20,7 +20,7 @@
 ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-;; $Id: interface.lisp,v 1.7 2007-10-17 17:04:15 espen Exp $
+;; $Id: interface.lisp,v 1.10 2008-12-10 02:40:18 espen Exp $
 
 (in-package "GFFI")
 
@@ -72,15 +72,19 @@ (defun default-alien-type-name (type-name)
       #'string-capitalize    
       (cons prefix (split-string (symbol-name type-name) :delimiter #\-))))))
 
-(defun default-type-name (alien-name)
-  (let ((parts
-        (mapcar
-         #'string-upcase
-         (split-string-if alien-name #'upper-case-p))))
-    (intern
-     (concatenate-strings (rest parts) #\-)
-     (find-prefix-package (first parts)))))
+(defun split-alien-name (alien-name)
+  (let ((parts (split-string-if alien-name #'upper-case-p)))
+    (do ((prefix (first parts) (concatenate 'string prefix (first rest)))
+         (rest (rest parts) (cdr rest)))
+        ((null rest)
+         (error "Couldn't split alien name '~A' to find a registered prefix"
+                alien-name))
+      (when (find-prefix-package prefix)
+        (return (values (string-upcase (concatenate-strings rest #\-))
+                        (find-prefix-package prefix)))))))
 
+(defun default-type-name (alien-name)
+  (multiple-value-call #'intern (split-alien-name alien-name)))
 
 (defun in-arg-p (style)
   (find style '(:in :in/out :in/return :in-out :return)))
@@ -128,8 +132,15 @@ (defmacro defbinding (name lambda-list return-type &rest args)
                     (list 
                      (cond 
                       ((and (namep expr) (not (in-arg-p style))) expr)
-                      ((namep expr) (make-symbol (string expr)))
-                      ((gensym)))
+                      ((namep expr)                    
+                       #-clisp(make-symbol (string expr))
+                       ;; The above used to work in CLISP, but I'm
+                       ;; not sure exactly at which version it
+                       ;; broke. The following could potentially
+                       ;; cause variable capturing
+                       #+clisp(intern (format nil "~A-~A" (string expr) (gensym))))
+                      (#-clisp(gensym)
+                       #+clisp(intern (string (gensym)))))
                      (or aux expr) type style out-type))))
             args)))
   
@@ -209,7 +220,8 @@ (defun %defbinding (cname lisp-name lambda-list declare-p arg-types aux-bindings
                     when (out-arg-p style)
                     collect (return-type out-type)
                     when (return-arg-p style)
-                    collect (return-type type)))))))
+                    collect (return-type type))))
+               ,lisp-name)))
          (defun ,lisp-name ,lambda-list
          ,doc
          (let ,aux-bindings
@@ -437,6 +449,8 @@ (defun type-expand-to (type form)
                   (error "~A can not be expanded to ~A" form type))))))
     (expand form)))
 
+(defun type-equal-p (type1 type2)
+  (and (subtypep type1 type2) (subtypep type2 type1)))
 
 
 ;;;; Type methods