projects
/
sbcl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
1.0.48.17: hopefully fix build on win32
[sbcl.git]
/
src
/
code
/
host-c-call.lisp
diff --git
a/src/code/host-c-call.lisp
b/src/code/host-c-call.lisp
index
e4187db
..
7b558af
100644
(file)
--- a/
src/code/host-c-call.lisp
+++ b/
src/code/host-c-call.lisp
@@
-13,15
+13,18
@@
(define-alien-type-class (c-string :include pointer :include-args (to))
(external-format :default :type keyword)
(define-alien-type-class (c-string :include pointer :include-args (to))
(external-format :default :type keyword)
- (element-type 'character :type (member character base-char)))
+ (element-type 'character :type (member character base-char))
+ (not-null nil :type boolean))
(define-alien-type-translator c-string
(&key (external-format :default)
(define-alien-type-translator c-string
(&key (external-format :default)
- (element-type 'character))
+ (element-type 'character)
+ (not-null nil))
(make-alien-c-string-type
:to (parse-alien-type 'char (sb!kernel:make-null-lexenv))
:element-type element-type
(make-alien-c-string-type
:to (parse-alien-type 'char (sb!kernel:make-null-lexenv))
:element-type element-type
- :external-format external-format))
+ :external-format external-format
+ :not-null not-null))
(defun c-string-external-format (type)
(let ((external-format (alien-c-string-type-external-format type)))
(defun c-string-external-format (type)
(let ((external-format (alien-c-string-type-external-format type)))
@@
-32,18
+35,23
@@
(define-alien-type-method (c-string :unparse) (type)
(let* ((external-format (alien-c-string-type-external-format type))
(element-type (alien-c-string-type-element-type type))
(define-alien-type-method (c-string :unparse) (type)
(let* ((external-format (alien-c-string-type-external-format type))
(element-type (alien-c-string-type-element-type type))
+ (not-null (alien-c-string-type-not-null type))
(tail
(append (unless (eq :default external-format)
(list :external-format external-format))
(unless (eq 'character element-type)
(tail
(append (unless (eq :default external-format)
(list :external-format external-format))
(unless (eq 'character element-type)
- (list :element-type element-type))) ))
+ (list :element-type element-type))
+ (when not-null
+ (list :not-null t)))))
(if tail
(cons 'c-string tail)
'c-string)))
(define-alien-type-method (c-string :lisp-rep) (type)
(if tail
(cons 'c-string tail)
'c-string)))
(define-alien-type-method (c-string :lisp-rep) (type)
- (declare (ignore type))
- '(or simple-string null (alien (* char)) (simple-array (unsigned-byte 8))))
+ (let ((possibilities '(simple-string (alien (* char)) (simple-array (unsigned-byte 8)))))
+ (if (alien-c-string-type-not-null type)
+ `(or ,@possibilities)
+ `(or null ,@possibilities))))
(define-alien-type-method (c-string :deport-pin-p) (type)
(declare (ignore type))
(define-alien-type-method (c-string :deport-pin-p) (type)
(declare (ignore type))
@@
-68,9
+76,18
@@
#!-sb-unicode
(eq (first (sb!impl::ef-names external-format)) :latin-1))))))
#!-sb-unicode
(eq (first (sb!impl::ef-names external-format)) :latin-1))))))
+(declaim (ftype (sfunction (t) nil) null-error))
+(defun null-error (type)
+ (aver (alien-c-string-type-not-null type))
+ (error 'type-error
+ :expected-type `(alien ,(unparse-alien-type type))
+ :datum nil))
+
(define-alien-type-method (c-string :naturalize-gen) (type alien)
`(if (zerop (sap-int ,alien))
(define-alien-type-method (c-string :naturalize-gen) (type alien)
`(if (zerop (sap-int ,alien))
- nil
+ ,(if (alien-c-string-type-not-null type)
+ `(null-error ',type)
+ nil)
;; Check whether we need to do a full external-format
;; conversion, or whether we can just do a cheap byte-by-byte
;; copy of the c-string data.
;; Check whether we need to do a full external-format
;; conversion, or whether we can just do a cheap byte-by-byte
;; copy of the c-string data.
@@
-90,17
+107,22
@@
`(%naturalize-c-string ,alien))))
(define-alien-type-method (c-string :deport-gen) (type value)
`(%naturalize-c-string ,alien))))
(define-alien-type-method (c-string :deport-gen) (type value)
- (declare (ignore type))
;; This SAP taking is safe as DEPORT callers pin the VALUE when
;; necessary.
`(etypecase ,value
;; This SAP taking is safe as DEPORT callers pin the VALUE when
;; necessary.
`(etypecase ,value
- (null (int-sap 0))
+ (null
+ ,(if (alien-c-string-type-not-null type)
+ `(null-error ',type)
+ `(int-sap 0)))
((alien (* char)) (alien-sap ,value))
(vector (vector-sap ,value))))
(define-alien-type-method (c-string :deport-alloc-gen) (type value)
`(etypecase ,value
((alien (* char)) (alien-sap ,value))
(vector (vector-sap ,value))))
(define-alien-type-method (c-string :deport-alloc-gen) (type value)
`(etypecase ,value
- (null nil)
+ (null
+ ,(if (alien-c-string-type-not-null type)
+ `(null-error ',type)
+ nil))
((alien (* char)) ,value)
(simple-base-string
,(if (c-string-needs-conversion-p type)
((alien (* char)) ,value)
(simple-base-string
,(if (c-string-needs-conversion-p type)