Remove obolete case- there aren't fdefns in immobile space
[sbcl.git] / tests / alien.impure.lisp
blob22b59306370fb5a5f261766a3a918bd5de637bc8
1 ;;;; This file is for compiler tests which have side effects (e.g.
2 ;;;; executing DEFUN) but which don't need any special side-effecting
3 ;;;; environmental stuff (e.g. DECLAIM of particular optimization
4 ;;;; settings). Similar tests which *do* expect special settings may
5 ;;;; be in files compiler-1.impure.lisp, compiler-2.impure.lisp, etc.
7 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; more information.
9 ;;;;
10 ;;;; While most of SBCL is derived from the CMU CL system, the test
11 ;;;; files (like this one) were written from scratch after the fork
12 ;;;; from CMU CL.
13 ;;;;
14 ;;;; This software is in the public domain and is provided with
15 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
16 ;;;; more information.
18 (cl:in-package :cl-user)
20 ;;; In sbcl-0.6.10, Douglas Brebner reported that (SETF EXTERN-ALIEN)
21 ;;; was messed up so badly that trying to execute expressions like
22 ;;; this signalled an error.
23 (with-test (:name (setf extern-alien))
24 (setf (sb-alien:extern-alien "thread_control_stack_size" sb-alien:unsigned)
25 (sb-alien:extern-alien "thread_control_stack_size" sb-alien:unsigned)))
27 ;;; bug 133, fixed in 0.7.0.5: Somewhere in 0.pre7.*, C void returns
28 ;;; were broken ("unable to use values types here") when
29 ;;; auto-PROCLAIM-of-return-value was added to DEFINE-ALIEN-ROUTINE.
30 (with-test (:name (define-alien-routine :bug-133))
31 (sb-alien:define-alien-routine ("free" free) void (ptr (* t) :in)))
33 ;;; Types of alien functions were being incorrectly DECLAIMED when
34 ;;; docstrings were included in the definition until sbcl-0.7.6.15.
35 (sb-alien:define-alien-routine ("getenv" ftype-correctness) c-string
36 "docstring"
37 (name c-string))
39 (with-test (:name (define-alien-routine ftype :correctness))
40 (multiple-value-bind (function failure-p warnings)
41 (checked-compile '(lambda () (ftype-correctness))
42 :allow-warnings t)
43 (declare (ignore function failure-p))
44 (assert (= (length warnings) 1)))
46 (checked-compile '(lambda () (ftype-correctness "FOO")))
48 (multiple-value-bind (function failure-p warnings)
49 (checked-compile '(lambda () (ftype-correctness "FOO" "BAR"))
50 :allow-warnings t)
51 (declare (ignore function failure-p))
52 (assert (= (length warnings) 1))))
54 ;;; This used to break due to too eager auxiliary type twiddling in
55 ;;; parse-alien-record-type.
56 (defparameter *maybe* nil)
57 (with-test (:name (with-alien struct :and alien-funcall))
58 (checked-compile
59 '(lambda ()
60 (with-alien ((x (struct bar (x unsigned) (y unsigned)))
61 ;; bogus definition, but we just need the symbol
62 (f (function int (* (struct bar))) :extern "printf"))
63 (when *maybe*
64 (alien-funcall f (addr x)))))))
66 ;;; Mutually referent structures
67 (define-alien-type struct.1 (struct struct.1 (x (* (struct struct.2))) (y int)))
68 (define-alien-type struct.2 (struct struct.2 (x (* (struct struct.1))) (y int)))
69 (with-test (:name (define-alien-type :mutually-reference-structures))
70 (let ((s1 (make-alien struct.1))
71 (s2 (make-alien struct.2)))
72 (setf (slot s1 'x) s2
73 (slot s2 'x) s1
74 (slot (slot s1 'x) 'y) 1
75 (slot (slot s2 'x) 'y) 2)
76 (assert (= 1 (slot (slot s1 'x) 'y)))
77 (assert (= 2 (slot (slot s2 'x) 'y)))))
79 ;;; "Alien bug" on sbcl-devel 2004-10-11 by Thomas F. Burdick caused
80 ;;; by recursive struct definition.
81 (with-test (:name (compile-file :nested define-alien-type struct))
82 (let ((fname (scratch-file-name "lisp")))
83 (unwind-protect
84 (progn
85 (with-open-file (f fname :direction :output :if-exists :supersede)
86 (mapc (lambda (form) (print form f))
87 '((defpackage :alien-bug
88 (:use :cl :sb-alien))
89 (in-package :alien-bug)
90 (define-alien-type objc-class
91 (struct objc-class
92 (protocols
93 (* (struct protocol-list
94 (list (array (* (struct objc-class))))))))))))
95 (load fname)
96 (load fname)
97 (load (compile-file fname))
98 (load (compile-file fname)))
99 (delete-file (compile-file-pathname fname))
100 (delete-file fname))))
102 ;;; enumerations with only one enum resulted in division-by-zero
103 ;;; reported on sbcl-help 2004-11-16 by John Morrison
104 (define-alien-type enum.1 (enum nil (:val0 0)))
106 (define-alien-type enum.2 (enum nil (zero 0) (one 1) (two 2) (three 3)
107 (four 4) (five 5) (six 6) (seven 7)
108 (eight 8) (nine 9)))
109 (with-test (:name (define-alien-type enum array cast))
110 (with-alien ((integer-array (array int 3)))
111 (let ((enum-array (cast integer-array (array enum.2 3))))
112 (setf (deref enum-array 0) 'three
113 (deref enum-array 1) 'four)
114 (setf (deref integer-array 2) (+ (deref integer-array 0)
115 (deref integer-array 1)))
116 (assert (eql (deref enum-array 2) 'seven)))))
118 ;; The code that is used for mapping from integers to symbols depends
119 ;; on the `density' of the set of used integers, so test with a sparse
120 ;; set as well.
121 (define-alien-type enum.3 (enum nil (zero 0) (one 1) (k-one 1001) (k-two 1002)))
122 (with-test (:name (define-alien-type enum :sparse-integers))
123 (with-alien ((integer-array (array int 3)))
124 (let ((enum-array (cast integer-array (array enum.3 3))))
125 (setf (deref enum-array 0) 'one
126 (deref enum-array 1) 'k-one)
127 (setf (deref integer-array 2) (+ (deref integer-array 0)
128 (deref integer-array 1)))
129 (assert (eql (deref enum-array 2) 'k-two)))))
131 ;; enums used to allow values to be used only once
132 ;; C enums allow for multiple tags to point to the same value
133 (define-alien-type enum.4
134 (enum nil (:key1 1) (:key2 2) (:keytwo 2)))
135 (with-test (:name (define-alien-type enum :repeated-integers))
136 (with-alien ((enum-array (array enum.4 3)))
137 (setf (deref enum-array 0) :key1)
138 (setf (deref enum-array 1) :key2)
139 (setf (deref enum-array 2) :keytwo)
140 (assert (and (eql (deref enum-array 1) (deref enum-array 2))
141 (eql (deref enum-array 1) :key2)))))
143 ;;; As reported by Baughn on #lisp, ALIEN-FUNCALL loops forever when
144 ;;; compiled with (DEBUG 3).
145 (with-test (:name (alien-funcall debug 3))
146 (sb-kernel::values-specifier-type-cache-clear)
147 (checked-compile-and-assert ()
148 '(lambda (v)
149 (sb-alien:alien-funcall (sb-alien:extern-alien "getenv"
150 (function (c-string) c-string))
152 (("HOME") '(or string null) :test (lambda (values expected)
153 (every #'typep values expected)))))
155 ;;; CLH: Test for non-standard alignment in alien structs
156 (sb-alien:define-alien-type align-test-struct
157 (sb-alien:union align-test-union
158 (s (sb-alien:struct nil
159 (s1 sb-alien:unsigned-char)
160 (c1 sb-alien:unsigned-char :alignment 16)
161 (c2 sb-alien:unsigned-char :alignment 32)
162 (c3 sb-alien:unsigned-char :alignment 32)
163 (c4 sb-alien:unsigned-char :alignment 8)))
164 (u (sb-alien:array sb-alien:unsigned-char 16))))
165 (with-test (:name (define-alien-type struct :alignment))
166 (let ((a1 (sb-alien:make-alien align-test-struct)))
167 (declare (type (sb-alien:alien (* align-test-struct)) a1))
168 (setf (sb-alien:slot (sb-alien:slot a1 's) 's1) 1)
169 (setf (sb-alien:slot (sb-alien:slot a1 's) 'c1) 21)
170 (setf (sb-alien:slot (sb-alien:slot a1 's) 'c2) 41)
171 (setf (sb-alien:slot (sb-alien:slot a1 's) 'c3) 61)
172 (setf (sb-alien:slot (sb-alien:slot a1 's) 'c4) 81)
173 (assert (equal '(1 21 41 61 81)
174 (list (sb-alien:deref (sb-alien:slot a1 'u) 0)
175 (sb-alien:deref (sb-alien:slot a1 'u) 2)
176 (sb-alien:deref (sb-alien:slot a1 'u) 4)
177 (sb-alien:deref (sb-alien:slot a1 'u) 8)
178 (sb-alien:deref (sb-alien:slot a1 'u) 9))))))
180 (with-test (:name (make-alien :no-note))
181 (checked-compile-and-assert (:allow-notes nil)
182 '(lambda () (sb-alien:make-alien sb-alien:int))
183 (() 'sb-alien:alien :test #'typep)))
185 ;;; Test case for unwinding an alien (Win32) exception frame
187 ;;; The basic theory here is that failing to honor a win32
188 ;;; exception frame during stack unwinding breaks the chain.
189 ;;; "And if / You don't love me now / You will never love me
190 ;;; again / I can still hear you saying / You would never break
191 ;;; the chain." If the chain is broken and another exception
192 ;;; occurs (such as an error trap caused by an OBJECT-NOT-TYPE
193 ;;; error), the system will kill our process. No mercy, no
194 ;;; appeal. So, to check that we have done our job properly, we
195 ;;; need some way to put an exception frame on the stack and then
196 ;;; unwind through it, then trigger another exception. (FUNCALL
197 ;;; 0) will suffice for the latter, and a simple test shows that
198 ;;; CallWindowProc() establishes a frame and calls a function
199 ;;; passed to it as an argument.
200 #+win32
201 (progn
202 (load-shared-object "USER32")
203 (assert
204 (eq :ok
205 (handler-case
206 (tagbody
207 (alien-funcall
208 (extern-alien "CallWindowProcW"
209 (function unsigned-int
210 (* (function int)) unsigned-int
211 unsigned-int unsigned-int unsigned-int))
212 (alien-sap
213 (sb-alien::alien-callback (function unsigned-int)
214 #'(lambda () (go up))))
215 0 0 0 0)
217 (funcall 0))
218 (error ()
219 :ok)))))
221 ;;; Unused local alien caused a compiler error
222 (with-test (:name (sb-alien:with-alien :unused :no error))
223 (checked-compile-and-assert ()
224 `(lambda ()
225 (sb-alien:with-alien ((alien1923 (array (sb-alien:unsigned 8) 72)))
226 (values)))
227 (() (values))))
229 ;;; Non-local exit from WITH-ALIEN caused alien stack to be leaked.
230 (defvar *sap-int*)
231 (defun try-to-leak-alien-stack (x)
232 (with-alien ((alien (array (sb-alien:unsigned 8) 72)))
233 (let ((sap-int (sb-sys:sap-int (alien-sap alien))))
234 (if *sap-int*
235 (assert (= *sap-int* sap-int))
236 (setf *sap-int* sap-int)))
237 (when x
238 (return-from try-to-leak-alien-stack 'going))
239 (locally (declare (muffle-conditions style-warning))
240 (never))))
242 ;;; Can't stack allocate aliens with an interpreter
243 (compile 'try-to-leak-alien-stack)
245 (with-test (:name :nlx-causes-alien-stack-leak)
246 (let ((*sap-int* nil))
247 (loop repeat 1024
248 do (try-to-leak-alien-stack t))))
250 (with-test (:name (define-alien-type struct :redefinition :bug-431)
251 :fails-on :interpreter)
252 (eval '(progn
253 (define-alien-type nil (struct mystruct (myshort short) (mychar char)))
254 (with-alien ((myst (struct mystruct)))
255 (with-alien ((mysh short (slot myst 'myshort)))
256 (assert (integerp mysh))))))
257 (let ((restarted 0))
258 (handler-bind ((error (lambda (e)
259 (let ((cont (find-restart 'continue e)))
260 (when cont
261 (incf restarted)
262 (invoke-restart cont))))))
263 (eval '(define-alien-type nil (struct mystruct (myint int) (mychar char)))))
264 (assert (= 1 restarted)))
265 (eval '(with-alien ((myst (struct mystruct)))
266 (with-alien ((myin int (slot myst 'myint)))
267 (assert (integerp myin))))))
269 ;;; void conflicted with derived type
270 (declaim (inline bug-316075))
271 ;; KLUDGE: This win32 reader conditional masks a bug, but allows the
272 ;; test to fail cleanly.
273 #-win32
274 (locally (declare (muffle-conditions style-warning))
275 (sb-alien:define-alien-routine bug-316075 void (result char :out)))
276 (with-test (:name :bug-316075 :fails-on :win32)
277 #+win32 (error "fail")
278 (checked-compile '(lambda () (multiple-value-list (bug-316075)))))
280 ;;; Bug #316325: "return values of alien calls assumed truncated to
281 ;;; correct width on x86"
282 #+x86-64
283 (define-alien-callable truncation-test (unsigned 64)
284 ((foo (unsigned 64)))
285 foo)
286 #+x86
287 (define-alien-callable truncation-test (unsigned 32)
288 ((foo (unsigned 32)))
289 foo)
291 (with-test (:name :bug-316325 :skipped-on (not (or :x86-64 :x86))
292 :fails-on :interpreter)
293 ;; This test works by defining a callback function that provides an
294 ;; identity transform over a full-width machine word, then calling
295 ;; it as if it returned a narrower type and checking to see if any
296 ;; noise in the high bits of the result are properly ignored.
297 (macrolet ((verify (type input output)
298 `(with-alien ((fun (* (function ,type
299 #+x86-64 (unsigned 64)
300 #+x86 (unsigned 32)))
301 :local (alien-sap (alien-callable-function 'truncation-test))))
302 (let ((result (alien-funcall fun ,input)))
303 (assert (= result ,output))))))
304 #+x86-64
305 (progn
306 (verify (unsigned 64) #x8000000000000000 #x8000000000000000)
307 (verify (signed 64) #x8000000000000000 #x-8000000000000000)
308 (verify (signed 64) #x7fffffffffffffff #x7fffffffffffffff)
309 (verify (unsigned 32) #x0000000180000042 #x80000042)
310 (verify (signed 32) #x0000000180000042 #x-7fffffbe)
311 (verify (signed 32) #xffffffff7fffffff #x7fffffff))
312 #+x86
313 (progn
314 (verify (unsigned 32) #x80000042 #x80000042)
315 (verify (signed 32) #x80000042 #x-7fffffbe)
316 (verify (signed 32) #x7fffffff #x7fffffff))
317 (verify (unsigned 16) #x00018042 #x8042)
318 (verify (signed 16) #x003f8042 #x-7fbe)
319 (verify (signed 16) #x003f7042 #x7042)))
321 (with-test (:name :bug-654485)
322 ;; DEBUG 2 used to prevent let-conversion of the open-coded ALIEN-FUNCALL body,
323 ;; which in turn led the dreaded %SAP-ALIEN note.
324 (checked-compile
325 `(lambda (program argv)
326 (declare (optimize (debug 2)))
327 (with-alien ((sys-execv1 (function int c-string (* c-string)) :extern
328 "exit"))
329 (values (alien-funcall sys-execv1 program argv))))
330 :allow-notes nil))
332 (with-test (:name :bug-721087 :fails-on :win32)
333 (assert (typep nil '(alien c-string)))
334 (assert (not (typep nil '(alien (c-string :not-null t)))))
335 (assert (eq :ok
336 (handler-case
337 (posix-getenv nil)
338 (type-error (e)
339 (when (and (null (type-error-datum e))
340 (equal (type-error-expected-type e)
341 '(alien (c-string :not-null t))))
342 :ok))))))
344 (with-test (:name :make-alien-string)
345 (labels ((content (alien length null-terminate)
346 (if null-terminate
347 (cast alien c-string)
348 (let ((buffer (make-array length
349 :element-type '(unsigned-byte 8))))
350 (sb-kernel:copy-ub8-from-system-area
351 (alien-sap alien) 0 buffer 0 length)
352 (sb-ext:octets-to-string buffer))))
353 (test (null-terminate)
354 (let* ((string "This comes from lisp!")
355 (length (length string)))
356 (multiple-value-bind (alien alien-length)
357 (sb-alien::make-alien-string
358 string :null-terminate null-terminate)
359 (assert (= alien-length (+ length (if null-terminate 1 0))))
360 (gc :full t)
361 ;; Copy to make sure STRING did not somehow end up in
362 ;; the alien object.
363 (assert (equal (copy-seq string)
364 (content alien length null-terminate)))
365 (free-alien alien)))))
366 (test nil)
367 (test t)))
369 ;;; Skip for MSAN. Instead of returning 0, the intercepted malloc is configured
370 ;;; to cause process termination by default on failure to allocate memory.
371 ;;; Skip also for UBSAN which has a smaller ARRAY-TOTAL-SIZE-LIMIT
372 ;;; and so doesn't get ENOMEM.
373 ;;; Unfortunately, even without an intercepted malloc, and depending on SBCL build
374 ;;; parameters (notably GC card-size) you might not get a failure right away,
375 ;;; but instead suffer process death, or cause your kernel to churn for a while
376 ;;; as it looks for swap space and then decides to OOM-kill you. This will typically
377 ;;; occur when ARRAY-TOTAL-SIZE-LIMIT is "too small" to get instant failure.
378 ;;; Instead, your malloc() thinks the request is reasonable, and tries to fulfill it.
379 ;;; But we're constrained by the maximum BYTES argument to MAKE-%ALIEN which
380 ;;; is declared as INDEX even though we want to pass something ludicrously
381 ;;; big like half the maximum value of size_t.
382 #+64-bit (unless (>= (integer-length array-total-size-limit) 45)
383 (push :skip-malloc-test *features*))
384 (with-test (:name :malloc-failure ; for lp#891268
385 :skipped-on (or :ubsan :msan :skip-malloc-test))
386 (assert (eq :enomem
387 (handler-case
388 (loop repeat 128
389 collect (sb-alien:make-alien char (1- array-total-size-limit)))
390 (storage-condition ()
391 :enomem)))))
393 (with-test (:name :bug-985505)
394 ;; Check that correct octets are reported for a c-string-decoding error.
395 (assert
396 (eq :unibyte
397 (handler-case
398 (let ((c-string (coerce #(70 111 195 182 0)
399 '(vector (unsigned-byte 8)))))
400 (sb-sys:with-pinned-objects (c-string)
401 (sb-alien::c-string-to-string (sb-sys:vector-sap c-string)
402 :ascii 'character)))
403 (sb-int:c-string-decoding-error (e)
404 (assert (equalp #(195) (sb-int:character-decoding-error-octets e)))
405 :unibyte))))
406 (assert
407 (eq :multibyte-4
408 (handler-case
409 ;; KLUDGE, sort of.
411 ;; C-STRING decoding doesn't know how long the string is, and since this
412 ;; looks like a 4-byte sequence, it will grab 4 octets off the end.
414 ;; So we pad the vector for safety's sake.
415 (let ((c-string (coerce #(70 111 246 0 0 0)
416 '(vector (unsigned-byte 8)))))
417 (sb-sys:with-pinned-objects (c-string)
418 (sb-alien::c-string-to-string (sb-sys:vector-sap c-string)
419 :utf-8 'character)))
420 (sb-int:c-string-decoding-error (e)
421 (assert (equalp #(246 0 0 0)
422 (sb-int:character-decoding-error-octets e)))
423 :multibyte-4))))
424 (assert
425 (eq :multibyte-2
426 (handler-case
427 (let ((c-string (coerce #(70 195 1 182 195 182 0) '(vector (unsigned-byte 8)))))
428 (sb-sys:with-pinned-objects (c-string)
429 (sb-alien::c-string-to-string (sb-sys:vector-sap c-string)
430 :utf-8 'character)))
431 (sb-int:c-string-decoding-error (e)
432 (assert (equalp #(195 1)
433 (sb-int:character-decoding-error-octets e)))
434 :multibyte-2)))))
436 (with-test (:name :stream-to-c-string-decoding-restart-leakage)
437 ;; Restarts for stream decoding errors didn't use to be associated with
438 ;; their conditions, so they could get confused with c-string decoding errors.
439 (assert (eq :nesting-ok
440 (catch 'out
441 (handler-bind ((sb-int:character-decoding-error
442 (lambda (stream-condition)
443 (declare (ignore stream-condition))
444 (handler-bind ((sb-int:character-decoding-error
445 (lambda (c-string-condition)
446 (throw 'out
447 (if (find-restart
448 'sb-impl::input-replacement
449 c-string-condition)
450 :bad-restart
451 :nesting-ok)))))
452 (let ((c-string (coerce #(70 195 1 182 195 182 0)
453 '(vector (unsigned-byte 8)))))
454 (sb-sys:with-pinned-objects (c-string)
455 (sb-alien::c-string-to-string
456 (sb-sys:vector-sap c-string)
457 :utf-8 'character)))))))
458 (let ((namestring (scratch-file-name)))
459 (unwind-protect
460 (progn
461 (with-open-file (f namestring
462 :element-type '(unsigned-byte 8)
463 :direction :output
464 :if-exists :supersede)
465 (dolist (b '(70 195 1 182 195 182 0))
466 (write-byte b f)))
467 (with-open-file (f namestring
468 :external-format :utf-8)
469 (read-line f)))
470 (delete-file namestring))))))))
472 ;; Previously, the error signaled by (MACROEXPANDing the) redefinition
473 ;; of an alien structure itself signaled an error. Ensure that the
474 ;; error is signaled and prints properly.
475 (sb-alien:define-alien-type nil
476 (sb-alien:struct alien-structure-redefinition (bar sb-alien:int)))
478 (with-test (:name (:alien-structure-redefinition :condition-printable))
479 (handler-case
480 (macroexpand
481 '(sb-alien:define-alien-type nil
482 (sb-alien:struct alien-structure-redefinition (bar sb-alien:c-string))))
483 (error (condition)
484 (princ-to-string condition))
485 (:no-error (&rest values)
486 (declare (ignore values))
487 (error "~@<Alien structure type redefinition failed to signal an ~
488 error~@:>"))))
490 #+largefile
491 (with-test (:name (:64-bit-return-truncation))
492 (with-open-file (stream *load-truename*)
493 (file-position stream 4294967310)
494 (assert (= 4294967310 (file-position stream)))))
496 (with-test (:name :stack-misalignment)
497 (locally (declare (optimize (debug 2)))
498 (labels ((foo ()
499 (declare (optimize speed))
500 (sb-ext:get-time-of-day)))
501 (assert (equal (multiple-value-list
502 (multiple-value-prog1
503 (apply #'values (list 1))
504 (foo)))
505 '(1))))))
507 ;; Parse (ENUM COLOR)
508 (sb-alien-internals:parse-alien-type '(enum color red blue black green) nil)
509 ;; Now reparse it as a different type
510 (with-test (:name :change-enum-type)
511 (handler-bind ((error #'continue))
512 (sb-alien-internals:parse-alien-type '(enum color yellow ochre) nil)))
514 (with-test (:name :note-local-alien-type)
515 (let ((type (sb-alien::make-local-alien-info :type
516 (sb-alien-internals:parse-alien-type 'c-string nil))))
517 (checked-compile-and-assert ()
518 `(lambda (x)
519 (let ((alien (sb-alien-internals:make-local-alien ',type)))
520 (sb-alien-internals:note-local-alien-type ',type alien)
521 (flet ((x ()
522 (setf alien x)))
523 (x))
524 alien))
525 ((31) 31))))
527 (with-test (:name :memoize-coerce-to-interpreted-fun)
528 (let* ((form1 '(lambda (x) x))
529 (form2 (copy-tree form1)))
530 (assert (eq (sb-alien::coerce-to-interpreted-function form1)
531 (sb-alien::coerce-to-interpreted-function form2)))))
533 (with-test (:name :undefined-alien-name
534 :skipped-on (not (or :x86-64 :arm64)))
535 (dolist (memspace '(:dynamic #+immobile-space :immobile))
536 (let ((lispfun
537 (let ((sb-c::*compile-to-memory-space* memspace))
538 (checked-compile `(lambda ()
539 (alien-funcall (extern-alien "bar" (function (values)))))
540 :allow-style-warnings t))))
541 (handler-case (funcall lispfun)
542 (t (c)
543 (assert (typep c 'sb-kernel::undefined-alien-function-error))
544 (assert (equal (cell-error-name c) "bar")))))))
546 (with-test (:name :undefined-alien-name-via-linkage-table-trampoline
547 :skipped-on (not (or :x86-64 :arm64)))
548 (dolist (memspace '(:dynamic #+immobile-space :immobile))
549 (let ((lispfun
550 (let ((sb-c::*compile-to-memory-space* memspace))
551 (checked-compile
552 `(lambda ()
553 (with-alien ((fn (* (function (values)))
554 (sb-sys:int-sap (sb-sys:foreign-symbol-address "baz"))))
555 (alien-funcall fn)))))))
556 (handler-case (funcall lispfun)
557 (t (c)
558 (assert (typep c 'sb-kernel::undefined-alien-function-error))
559 (assert (equal (cell-error-name c) "baz")))))))
561 (defconstant fleem 3)
562 ;; We used to expand into
563 ;; (SYMBOL-MACROLET ((FLEEM (SB-ALIEN-INTERNALS:%ALIEN-VALUE
564 ;; which conflicted with the symbol as global variable.
565 (with-test (:name :def-alien-rtn-use-gensym)
566 (checked-compile '(lambda () (define-alien-routine "fleem" int (x int)))
567 :allow-style-warnings (or #-(or :x86-64 :arm :arm64) t)))
569 (with-test (:name :no-vector-sap-of-array-nil)
570 (assert-error (sb-sys:vector-sap (opaque-identity (make-array 5 :element-type nil)))))
572 (cl:in-package "SB-KERNEL")
573 (test-util:with-test (:name :hash-consing)
574 (assert (eq (parse-alien-type '(integer 9) nil)
575 (parse-alien-type '(integer 9) nil)))
576 (assert (eq (parse-alien-type '(* (struct nil (x int) (y int))) nil)
577 (parse-alien-type '(* (struct nil (x int) (y int))) nil))))