1 ;;;; package lock tests with side effects
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
16 (defun alien-callback (type fun)
17 (sb-alien-internals:alien-callback type fun))
22 (defvar *thunk* (alien-callback '(function c-string) #'thunk))
24 (assert (equal (with-output-to-string (*standard-output*)
25 (alien-funcall *thunk*))
28 (defun add-two-ints (arg1 arg2)
31 (defvar *add-two-ints* (alien-callback '(function int int int) 'add-two-ints))
33 (assert (= (alien-funcall *add-two-ints* 555 444444) 444999))
35 (define-alien-routine qsort void
39 (compar (function int (* double) (* double))))
41 (sb-alien::define-alien-callback double*-cmp int ((arg1 (* double)) (arg2 (* double)))
42 (let ((a1 (deref arg1))
48 (let* ((vector (coerce '(0.1d0 0.5d0 0.2d0 1.2d0 1.5d0 2.5d0 0.0d0 0.1d0 0.2d0 0.3d0)
49 '(vector double-float)))
50 (sorted (sort (copy-seq vector) #'<)))
52 (sb-sys:with-pinned-objects (vector)
53 (qsort (sb-sys:vector-sap vector)
55 (alien-size double :bytes)
57 (assert (equalp vector sorted)))
60 (sb-alien::define-alien-callback redefined-fun int ()
64 '(sb-alien::define-alien-callback redefined-fun int ()
67 (assert (= 42 (alien-funcall redefined-fun)))
69 (sb-alien::define-alien-callback return-single float ((x float))
72 (sb-alien::define-alien-callback return-double double ((x double))
75 (defconstant spi (coerce pi 'single-float))
77 (assert (= spi (alien-funcall return-single spi)))
78 (assert (= pi (alien-funcall return-double pi)))
80 (quit :unix-status 104)