r9396: add ensure-char-storage function, new tests
[uffi.git] / src / strings.lisp
index 6e7292cff8e8e89ea4f3a2f4b0a2dc8fb91fe996..89c41b2ec03a8ca4d240d449a134c33c92c2a2ef 100644 (file)
@@ -157,10 +157,11 @@ that LW/CMU automatically converts strings from c-calls."
        nil
      (if (eq ,locale :none)
         (fast-native-to-string ,obj ,length)
-       (excl:native-to-string
-       ,obj 
-       ,@(when length (list :length length))
-       :truncate (not ,null-terminated-p))))
+       (values
+       (excl:native-to-string
+        ,obj 
+        ,@(when length (list :length length))
+        :truncate (not ,null-terminated-p)))))
   #+lispworks
   `(if (fli:null-pointer-p ,obj)
        nil
@@ -188,7 +189,9 @@ that LW/CMU automatically converts strings from c-calls."
   #+mcl
   `(if (ccl:%null-ptr-p ,obj)
      nil
-     (ccl:%get-cstring ,obj 0 ,@(if length (list length) nil)))
+    #+(and mcl (not openmcl)) (ccl:%get-cstring ,obj 0 ,@(if length (list length) nil))
+    #+openmcl (let ((str (ccl:%get-cstring ,obj)))
+               ,(if length '(subseq str 0 length) 'str)))
   )
 
 
@@ -318,10 +321,10 @@ that LW/CMU automatically converts strings from c-calls."
                                    (* length sb-vm:n-byte-bits))
       result)))
 
-
-(def-function "strlen"
-    ((str (* :unsigned-char)))
-  :returning :unsigned-int)
+(eval-when (:compile-toplevel :load-toplevel :execute)
+   (def-function "strlen"
+     ((str (* :unsigned-char)))
+     :returning :unsigned-int))
 
 (def-type char-ptr-def (* :unsigned-char))