;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Feb 2002
;;;;
-;;;; $Id: strings.lisp,v 1.8 2003/06/06 21:59:18 kevin Exp $
+;;;; $Id$
;;;;
;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
`(if (zerop ,obj)
nil
(if (eq ,locale :none)
- (fast-native-to-string ,obj)
+ (fast-native-to-string ,obj ,length)
(excl:native-to-string
,obj
,@(when length (list :length length))
`(if (fli:null-pointer-p ,obj)
nil
(if (eq ,locale :none)
- (fast-native-to-string ,obj)
+ (fast-native-to-string ,obj ,length)
(fli:convert-from-foreign-string
,obj
,@(when length (list :length length))
((str (* :unsigned-char)))
:returning :unsigned-int)
-#+(or lispworks (and allegro ics))
-(defun fast-native-to-string (s)
+(def-type char-ptr-def (* :unsigned-char))
+
+#+(or lispworks (and allegro (not ics)))
+(defun fast-native-to-string (s len)
(declare (optimize (speed 3) (space 0) (safety 0) (compilation-speed 0))
(type char-ptr-def s))
- (let* ((len (strlen s))
- (str (make-string len)))
+ (let* ((len (or 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))
+ (type (simple-array (signed-byte 8) (*)) str))
+ (dotimes (i len str)
+ (setf (aref str i)
+ (uffi:deref-array s '(:array :char) i)))))
-#+(and allegro (not ics))
-(defun fast-native-to-string (s)
+#+(and allegro ics)
+(defun fast-native-to-string (s len)
(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))
+ (let* ((len (or len (strlen s)))
+ (str (make-string len)))
+ (dotimes (i len str)
+ (setf (schar str i) (code-char (uffi:deref-array s '(:array :byte) i))))))