r5062: return from san diego
authorKevin M. Rosenberg <kevin@rosenberg.net>
Fri, 6 Jun 2003 21:59:30 +0000 (21:59 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Fri, 6 Jun 2003 21:59:30 +0000 (21:59 +0000)
src/aggregates.lisp
src/functions.lisp
src/libraries.lisp
src/objects.lisp
src/os.lisp
src/package.lisp
src/primitives.lisp
src/readmacros-mcl.lisp
src/strings.lisp
uffi.asd

index 5080222aa0862c7b92bf708eca85370378746018..6ee0ac79ca072cc87e1dc4850ef180674dc2ff72 100644 (file)
@@ -2,12 +2,12 @@
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Name:          aggregates.cl
+;;;; Name:          aggregates.lisp
 ;;;; Purpose:       UFFI source to handle aggregate types
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: aggregates.lisp,v 1.6 2002/12/02 13:21:43 kevin Exp $
+;;;; $Id: aggregates.lisp,v 1.7 2003/06/06 21:59:18 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -16,8 +16,7 @@
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
-(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
-(in-package :uffi)
+(in-package #:uffi)
 
 (defmacro def-enum (enum-name args &key (separator-string "#"))
   "Creates a constants for a C type enum list, symbols are created
index 600603d2ff33ad135361feb33856e74252f29afb..9469945367265763b5814df2023dfebd351b8e05 100644 (file)
@@ -2,12 +2,12 @@
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Name:          function.cl
+;;;; Name:          function.lisp
 ;;;; Purpose:       UFFI source to C function definitions
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: functions.lisp,v 1.7 2003/02/06 06:54:22 kevin Exp $
+;;;; $Id: functions.lisp,v 1.8 2003/06/06 21:59:18 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -16,8 +16,7 @@
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
-(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
-(in-package :uffi)
+(in-package #:uffi)
 
 (defun process-function-args (args)
   (if (null args)
index 56829a0155d6a287c6e21f6c769854070c12a138..1344d9d31a39113c7f08b5d6532ca86b0d93c85a 100644 (file)
@@ -2,12 +2,12 @@
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Name:          libraries.cl
+;;;; Name:          libraries.lisp
 ;;;; Purpose:       UFFI source to load foreign libraries
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: libraries.lisp,v 1.6 2002/11/20 21:01:31 kevin Exp $
+;;;; $Id: libraries.lisp,v 1.7 2003/06/06 21:59:18 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -16,8 +16,7 @@
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
-(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
-(in-package :uffi)
+(in-package #:uffi)
 
 (defvar *loaded-libraries* nil
   "List of foreign libraries loaded. Used to prevent reloading a library")
index 51a9ce5977ecaab6929502dc3588ca3938d62d08..cb6cd7f95c9c81bd92e1ae409b4023576eb511c4 100644 (file)
@@ -2,12 +2,12 @@
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Name:          objects.cl
+;;;; Name:          objects.lisp
 ;;;; Purpose:       UFFI source to handle objects and pointers
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: objects.lisp,v 1.12 2003/05/30 18:46:45 kevin Exp $
+;;;; $Id: objects.lisp,v 1.13 2003/06/06 21:59:18 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -16,8 +16,7 @@
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
-(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
-(in-package :uffi)
+(in-package #:uffi)
 
 (defun size-of-foreign-type (type)
   #+lispworks (fli:size-of type)
index 918425cd80ccb6cd581b0b39be0b6f380ec5d1cc..3e3a60b1d9676d0dc3ddfa975c48ed53cdb727cb 100644 (file)
@@ -2,12 +2,12 @@
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Name:          os.cl
+;;;; Name:          os.lisp
 ;;;; Purpose:       Operating system interface for UFFI
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Sep 2002 
 ;;;;
-;;;; $Id: os.lisp,v 1.4 2002/10/23 19:51:20 kevin Exp $
+;;;; $Id: os.lisp,v 1.5 2003/06/06 21:59:18 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg.
 ;;;; Much of this code was taken from other open source project and copyright
@@ -18,9 +18,7 @@
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
-(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
-(in-package :uffi)
-
+(in-package #:uffi)
 
 ;; modified from function ASDF -- Copyright Dan Barlow and Contributors
 
index 14226383da860ad8e0046d99bcb75122cbacadf5..9bd1b093d747382de5be47ee4dab1671b43b8de9 100644 (file)
@@ -2,7 +2,7 @@
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Name:          package.cl
+;;;; Name:          package.lisp
 ;;;; Purpose:       Defines UFFI package
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
-(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
-(in-package :cl-user)
+(in-package #:cl-user)
 
-(defpackage :uffi
-  (:use :cl)
+(defpackage #:uffi
+  (:use #:cl)
   (:export 
    
    ;; immediate types
index 03530669ff87ed7cfc31f3756d07f6f9445bd769..1af37b4f016102ebdc9024f2bd6a0b8f5daf5950 100644 (file)
@@ -2,12 +2,12 @@
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Name:          primitives.cl
+;;;; Name:          primitives.lisp
 ;;;; Purpose:       UFFI source to handle immediate types
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: primitives.lisp,v 1.8 2002/12/15 17:11:08 kevin Exp $
+;;;; $Id: primitives.lisp,v 1.9 2003/06/06 21:59:18 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -16,8 +16,7 @@
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
-(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
-(in-package :uffi)
+(in-package #:uffi)
 
 #+mcl
 (defvar *keyword-package* (find-package "KEYWORD"))
index dc1fc6c805b87567c38418bb27a1efdfd6437b08..4eeffb21d9be7b173a682ecea9a586f9fd6d7062 100644 (file)
@@ -2,12 +2,12 @@
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Name:          readmacros-mcl.cl
+;;;; Name:          readmacros-mcl.lisp
 ;;;; Purpose:       This file holds functions using read macros for MCL
 ;;;; Programmer:    Kevin M. Rosenberg/John Desoi
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: readmacros-mcl.lisp,v 1.3 2002/09/30 10:02:36 kevin Exp $
+;;;; $Id: readmacros-mcl.lisp,v 1.4 2003/06/06 21:59:18 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -16,8 +16,7 @@
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
-(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
-(in-package :uffi)
+(in-package #:uffi)
 
 
 ;; trap macros don't work right directly in the macros
index 28ff372810792b0ca77e0c51ef224154bb167189..b4c1917a052486b358b7f5c1c757d57e30a41ff7 100644 (file)
@@ -2,12 +2,12 @@
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Name:          strings.cl
+;;;; Name:          strings.lisp
 ;;;; Purpose:       UFFI source to handle strings, cstring and foreigns
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: strings.lisp,v 1.7 2003/03/28 19:58:18 kevin Exp $
+;;;; $Id: strings.lisp,v 1.8 2003/06/06 21:59:18 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -16,8 +16,7 @@
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
-(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
-(in-package :uffi)
+(in-package #:uffi)
 
 
 (defvar +null-cstring-pointer+
@@ -151,22 +150,27 @@ that LW/CMU automatically converts strings from c-calls."
 ;; Either length or null-terminated-p must be non-nil
 (defmacro convert-from-foreign-string (obj &key
                                           length
+                                          (locale :default)
                                           (null-terminated-p t))
   #+allegro
   `(if (zerop ,obj)
        nil
-     (values (excl:native-to-string
-             ,obj 
-             ,@(if length (list :length length) (values))
-             :truncate (not ,null-terminated-p))))
+     (if (eq ,locale :none)
+        (fast-native-to-string ,obj)
+       (excl:native-to-string
+       ,obj 
+       ,@(when length (list :length length))
+       :truncate (not ,null-terminated-p))))
   #+lispworks
   `(if (fli:null-pointer-p ,obj)
        nil
-     (fli:convert-from-foreign-string 
-      ,obj
-      ,@(if length (list :length length) (values))
-      :null-terminated-p ,null-terminated-p
-      :external-format '(:latin-1 :eol-style :lf)))      
+     (if (eq ,locale :none)
+        (fast-native-to-string ,obj)
+       (fli:convert-from-foreign-string 
+       ,obj
+       ,@(when length (list :length length))
+       :null-terminated-p ,null-terminated-p
+       :external-format '(:latin-1 :eol-style :lf))))
   #+(or cmu scl)
   `(if (null-pointer-p ,obj)
     nil
@@ -188,7 +192,6 @@ that LW/CMU automatically converts strings from c-calls."
   )
 
 
-
 (defmacro allocate-foreign-string (size &key (unsigned t))
   #+(or cmu scl)
   (let ((array-def (gensym)))
@@ -299,3 +302,47 @@ that LW/CMU automatically converts strings from c-calls."
                                              sb-vm:n-word-bits)
                                    (* length sb-vm:n-byte-bits))
       result)))
+
+
+(def-function "strlen"
+    ((str (* :unsigned-char)))
+  :returning :unsigned-int)
+
+#+(or lispworks (and allegro ics))
+(defun fast-native-to-string (s)
+  (declare (optimize (speed 3) (space 0) (safety 0) (compilation-speed 0))
+          (type char-ptr-def s))
+  (let* ((len (strlen s))
+        (str (make-string len)))
+    (declare (fixnum len)
+            (simple-string str))
+    (do ((i 0))
+       ((= i len))
+      (declare (fixnum i))
+      (setf (schar str i)
+       (code-char (uffi:deref-array s '(:array :unsigned-char) i)))
+      (incf i))
+    str))
+
+#+(and allegro (not ics))
+(defun fast-native-to-string (s)
+  (declare (optimize (speed 3) (space 0) (safety 0) (compilation-speed 0))
+          (type char-ptr-def s))
+  (let* ((len (strlen s))
+        (len4 (floor len 4))
+        (str (make-string len)))
+    (declare (fixnum len)
+            (type (simple-array (signed-byte 32) (*)) str))
+    (do ((i 0))
+       ((= i len4))
+      (declare (fixnum i))
+      (setf (aref (the (simple-array (signed-byte 32) (*)) str) i)
+       (uffi:deref-array s '(:array :int) i))
+       (incf i))
+    (do ((i (* 4 len4)))
+       ((= i len))
+      (declare (fixnum i))
+      (setf (aref (the (simple-array (signed-byte 8) (*)) str) i)
+       (uffi:deref-array s '(:array :unsigned-char) i))
+      (incf i))
+    str))
index 40eb5bedd35ae2757305856d8073e9aaac5474bf..515f52a5788b461d3213f4a99a1ec69d6b4b28d7 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.24 2003/04/29 12:09:36 kevin Exp $
+;;;; $Id: uffi.asd,v 1.25 2003/06/06 21:59:18 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -44,7 +44,7 @@
    ))
 
 #+(or allegro lispworks cmu mcl cormanlisp sbcl scl)
-(defmethod perform ((o test-op) (c (eql (find-system :uffi))))
+(defmethod perform ((o test-op) (c (eql (find-system 'uffi))))
   (oos 'load-op 'uffi-tests)
   (oos 'test-op 'uffi-tests))