;;;; *************************************************************************
;;;; 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
;;;;
;;;; (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
;;;; *************************************************************************
;;;; 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
;;;;
;;;; (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)
;;;; *************************************************************************
;;;; 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
;;;;
;;;; (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")
;;;; *************************************************************************
;;;; 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
;;;;
;;;; (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)
;;;; *************************************************************************
;;;; 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
;;;; (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
;;;; *************************************************************************
;;;; 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
;;;; *************************************************************************
;;;; 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
;;;;
;;;; (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"))
;;;; *************************************************************************
;;;; 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
;;;;
;;;; (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
;;;; *************************************************************************
;;;; 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
;;;;
;;;; (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+
;; 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
)
-
(defmacro allocate-foreign-string (size &key (unsigned t))
#+(or cmu scl)
(let ((array-def (gensym)))
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))
;;;; 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
;;;;
))
#+(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))