cmp: fix coercion between lisp types and representation types

Signal an error if there is no function that coerces some C variable
c_object to a lisp object instead of emitting invalid C code like
`ECL_NIL(c_object)`.

Moreover, fix the table of representation types:

:object needs no coercion which is correctly implemented by using an
empty string for the function name.

:void should not use `nil` as the lisp type since nil is a subtype of
fixnum which lead to us previously choosing "ecl_fixnum" as the
coercion function in unsafe code. By using `t` as the lisp type we
avoid this.
This commit is contained in:
Marius Gerbershagen 2023-08-03 15:02:42 +02:00
parent c33f40a3db
commit 7761d0b27a
2 changed files with 7 additions and 6 deletions

View file

@ -114,11 +114,11 @@
(:double-sse-pack ext::double-sse-pack "__m128d" "ecl_make_double_sse_pack" "ecl_unbox_double_sse_pack" "ecl_unbox_double_sse_pack_unsafe")
;; intentional v
(:int-sse-pack ext::sse-pack "__m128i" "ecl_make_int_sse_pack" "ecl_unbox_int_sse_pack" "ecl_unbox_int_sse_pack_unsafe")
(:object t "cl_object" nil nil nil)
(:object t "cl_object" "" "" "")
(:bool t "bool" "ecl_make_bool" "ecl_to_bool" "ecl_to_bool")
;; These types are never selected to unbox data.
;; They are here, because we need to know how to print them.
(:void nil "void" nil nil nil)
(:void t "void" nil nil nil)
(:pointer-void si::foreign-data "void*" "ecl_make_pointer" "ecl_to_pointer" "ecl_to_pointer")
(:cstring string "char*" "ecl_cstring_to_base_string_or_nil" nil nil)
(:char* string "char*" nil nil nil)

View file

@ -226,10 +226,11 @@
clfloat-value)))
(wt (third loc)) ;; VV index
(return-from wt-to-object-conversion))
(let ((record (rep-type-record loc-rep-type)))
(unless record
(cmperr "Cannot coerce C variable of type ~A to lisp object" loc-rep-type))
(wt (rep-type-to-lisp record) "(" loc ")")))
(let* ((record (rep-type-record loc-rep-type))
(coercer (and record (rep-type-to-lisp record))))
(unless coercer
(cmperr "Cannot coerce C variable of type ~S to lisp object" loc-rep-type))
(wt coercer "(" loc ")")))
(defun wt-from-object-conversion (dest-type loc-type rep-type loc)
(let* ((record (rep-type-record rep-type))