describing how to get text
[CommonLispStat.git] / external / cffi.darcs / tests / callbacks.lisp
blob04c0dc8b55ce6d089014289690cb14c034447450
1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; callbacks.lisp --- Tests on callbacks.
4 ;;;
5 ;;; Copyright (C) 2005-2006, Luis Oliveira <loliveira(@)common-lisp.net>
6 ;;;
7 ;;; Permission is hereby granted, free of charge, to any person
8 ;;; obtaining a copy of this software and associated documentation
9 ;;; files (the "Software"), to deal in the Software without
10 ;;; restriction, including without limitation the rights to use, copy,
11 ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
12 ;;; of the Software, and to permit persons to whom the Software is
13 ;;; furnished to do so, subject to the following conditions:
14 ;;;
15 ;;; The above copyright notice and this permission notice shall be
16 ;;; included in all copies or substantial portions of the Software.
17 ;;;
18 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 ;;; DEALINGS IN THE SOFTWARE.
26 ;;;
28 (in-package #:cffi-tests)
30 (defcfun "expect_char_sum" :int (f :pointer))
31 (defcfun "expect_unsigned_char_sum" :int (f :pointer))
32 (defcfun "expect_short_sum" :int (f :pointer))
33 (defcfun "expect_unsigned_short_sum" :int (f :pointer))
34 (defcfun "expect_int_sum" :int (f :pointer))
35 (defcfun "expect_unsigned_int_sum" :int (f :pointer))
36 (defcfun "expect_long_sum" :int (f :pointer))
37 (defcfun "expect_unsigned_long_sum" :int (f :pointer))
38 (defcfun "expect_float_sum" :int (f :pointer))
39 (defcfun "expect_double_sum" :int (f :pointer))
40 (defcfun "expect_pointer_sum" :int (f :pointer))
41 (defcfun "expect_strcat" :int (f :pointer))
43 #-cffi-features:no-long-long
44 (progn
45 (defcfun "expect_long_long_sum" :int (f :pointer))
46 (defcfun "expect_unsigned_long_long_sum" :int (f :pointer)))
48 #+(and scl long-float)
49 (defcfun "expect_long_double_sum" :int (f :pointer))
51 (defcallback sum-char :char ((a :char) (b :char))
52 "Test if the named block is present and the docstring too."
53 ;(format t "~%}}} a: ~A, b: ~A {{{~%" a b)
54 (return-from sum-char (+ a b)))
56 (defcallback sum-unsigned-char :unsigned-char
57 ((a :unsigned-char) (b :unsigned-char))
58 ;(format t "~%}}} a: ~A, b: ~A {{{~%" a b)
59 (+ a b))
61 (defcallback sum-short :short ((a :short) (b :short))
62 ;(format t "~%}}} a: ~A, b: ~A {{{~%" a b)
63 (+ a b))
65 (defcallback sum-unsigned-short :unsigned-short
66 ((a :unsigned-short) (b :unsigned-short))
67 ;(format t "~%}}} a: ~A, b: ~A {{{~%" a b)
68 (+ a b))
70 (defcallback sum-int :int ((a :int) (b :int))
71 (+ a b))
73 (defcallback sum-unsigned-int :unsigned-int
74 ((a :unsigned-int) (b :unsigned-int))
75 (+ a b))
77 (defcallback sum-long :long ((a :long) (b :long))
78 (+ a b))
80 (defcallback sum-unsigned-long :unsigned-long
81 ((a :unsigned-long) (b :unsigned-long))
82 (+ a b))
84 #-cffi-features:no-long-long
85 (progn
86 (defcallback sum-long-long :long-long
87 ((a :long-long) (b :long-long))
88 (+ a b))
90 (defcallback sum-unsigned-long-long :unsigned-long-long
91 ((a :unsigned-long-long) (b :unsigned-long-long))
92 (+ a b)))
94 (defcallback sum-float :float ((a :float) (b :float))
95 ;(format t "~%}}} a: ~A, b: ~A {{{~%" a b)
96 (+ a b))
98 (defcallback sum-double :double ((a :double) (b :double))
99 ;(format t "~%}}} a: ~A, b: ~A {{{~%" a b)
100 (+ a b))
102 #+(and scl long-float)
103 (defcallback sum-long-double :long-double ((a :long-double) (b :long-double))
104 ;(format t "~%}}} a: ~A, b: ~A {{{~%" a b)
105 (+ a b))
107 (defcallback sum-pointer :pointer ((ptr :pointer) (offset :int))
108 (inc-pointer ptr offset))
110 (defcallback lisp-strcat :string ((a :string) (b :string))
111 (concatenate 'string a b))
113 (deftest callbacks.char
114 (expect-char-sum (get-callback 'sum-char))
117 (deftest callbacks.unsigned-char
118 (expect-unsigned-char-sum (get-callback 'sum-unsigned-char))
121 (deftest callbacks.short
122 (expect-short-sum (callback sum-short))
125 (deftest callbacks.unsigned-short
126 (expect-unsigned-short-sum (callback sum-unsigned-short))
129 (deftest callbacks.int
130 (expect-int-sum (callback sum-int))
133 (deftest callbacks.unsigned-int
134 (expect-unsigned-int-sum (callback sum-unsigned-int))
137 (deftest callbacks.long
138 (expect-long-sum (callback sum-long))
141 (deftest callbacks.unsigned-long
142 (expect-unsigned-long-sum (callback sum-unsigned-long))
145 #-cffi-features:no-long-long
146 (progn
147 #+openmcl (push 'callbacks.long-long rt::*expected-failures*)
149 (deftest callbacks.long-long
150 (expect-long-long-sum (callback sum-long-long))
153 (deftest callbacks.unsigned-long-long
154 (expect-unsigned-long-long-sum (callback sum-unsigned-long-long))
157 (deftest callbacks.float
158 (expect-float-sum (callback sum-float))
161 (deftest callbacks.double
162 (expect-double-sum (callback sum-double))
165 #+(and scl long-float)
166 (deftest callbacks.long-double
167 (expect-long-double-sum (callback sum-long-double))
170 (deftest callbacks.pointer
171 (expect-pointer-sum (callback sum-pointer))
174 (deftest callbacks.string
175 (expect-strcat (callback lisp-strcat))
178 #-cffi-features:no-foreign-funcall
179 (defcallback return-a-string-not-nil :string ()
180 "abc")
182 #-cffi-features:no-foreign-funcall
183 (deftest callbacks.string-not-docstring
184 (foreign-funcall-pointer (callback return-a-string-not-nil) () :string)
185 "abc")
187 ;;; This one tests mem-aref too.
188 (defcfun "qsort" :void
189 (base :pointer)
190 (nmemb :int)
191 (size :int)
192 (fun-compar :pointer))
194 (defcallback < :int ((a :pointer) (b :pointer))
195 (let ((x (mem-ref a :int))
196 (y (mem-ref b :int)))
197 (cond ((> x y) 1)
198 ((< x y) -1)
199 (t 0))))
201 (deftest callbacks.qsort
202 (with-foreign-object (array :int 10)
203 ;; Initialize array.
204 (loop for i from 0 and n in '(7 2 10 4 3 5 1 6 9 8)
205 do (setf (mem-aref array :int i) n))
206 ;; Sort it.
207 (qsort array 10 (foreign-type-size :int) (callback <))
208 ;; Return it as a list.
209 (loop for i from 0 below 10
210 collect (mem-aref array :int i)))
211 (1 2 3 4 5 6 7 8 9 10))
213 ;;; void callback
214 (defparameter *int* -1)
216 (defcfun "pass_int_ref" :void (f :pointer))
218 ;;; CMUCL chokes on this one for some reason.
219 #-(and cffi-features:darwin cmu)
220 (defcallback read-int-from-pointer :void ((a :pointer))
221 (setq *int* (mem-ref a :int)))
223 #+(and cffi-features:darwin cmu)
224 (pushnew 'callbacks.void rt::*expected-failures*)
226 (deftest callbacks.void
227 (progn
228 (pass-int-ref (callback read-int-from-pointer))
229 *int*)
230 1984)
232 ;;; test funcalling of a callback and also declarations inside
233 ;;; callbacks.
235 #-cffi-features:no-foreign-funcall
236 (progn
237 (defcallback sum-2 :int ((a :int) (b :int) (c :int))
238 (declare (ignore c))
239 (+ a b))
241 (deftest callbacks.funcall.1
242 (foreign-funcall-pointer (callback sum-2) () :int 2 :int 3 :int 1 :int)
245 (defctype foo-float :float)
247 (defcallback sum-2f foo-float
248 ((a foo-float) (b foo-float) (c foo-float) (d foo-float) (e foo-float))
249 "This one ignores the middle 3 arguments."
250 (declare (ignore b c))
251 (declare (ignore d))
252 (+ a e))
254 (deftest callbacks.funcall.2
255 (foreign-funcall-pointer (callback sum-2f) () foo-float 1.0 foo-float 2.0
256 foo-float 3.0 foo-float 4.0 foo-float 5.0
257 foo-float)
258 6.0))
260 ;;; (cb-test :no-long-long t)
262 (defcfun "call_sum_127_no_ll" :long (cb :pointer))
264 ;;; CMUCL and ECL choke on this one.
265 #-(:or :ecl :cmu #.(cl:if (cl:>= cl:lambda-parameters-limit 127) '(:or) '(:and)))
266 (defcallback sum-127-no-ll :long
267 ((a1 :unsigned-long) (a2 :pointer) (a3 :long) (a4 :double)
268 (a5 :unsigned-long) (a6 :float) (a7 :float) (a8 :int) (a9 :unsigned-int)
269 (a10 :double) (a11 :double) (a12 :double) (a13 :pointer)
270 (a14 :unsigned-short) (a15 :unsigned-short) (a16 :pointer) (a17 :long)
271 (a18 :long) (a19 :int) (a20 :short) (a21 :unsigned-short)
272 (a22 :unsigned-short) (a23 :char) (a24 :long) (a25 :pointer) (a26 :pointer)
273 (a27 :char) (a28 :unsigned-char) (a29 :unsigned-long) (a30 :short)
274 (a31 :int) (a32 :int) (a33 :unsigned-char) (a34 :short) (a35 :long)
275 (a36 :long) (a37 :pointer) (a38 :unsigned-short) (a39 :char) (a40 :double)
276 (a41 :unsigned-short) (a42 :pointer) (a43 :short) (a44 :unsigned-long)
277 (a45 :unsigned-short) (a46 :float) (a47 :unsigned-char) (a48 :short)
278 (a49 :float) (a50 :short) (a51 :char) (a52 :unsigned-long)
279 (a53 :unsigned-long) (a54 :char) (a55 :float) (a56 :long) (a57 :pointer)
280 (a58 :short) (a59 :float) (a60 :unsigned-int) (a61 :float)
281 (a62 :unsigned-int) (a63 :double) (a64 :unsigned-int) (a65 :unsigned-char)
282 (a66 :int) (a67 :long) (a68 :char) (a69 :short) (a70 :double) (a71 :int)
283 (a72 :pointer) (a73 :char) (a74 :unsigned-short) (a75 :pointer)
284 (a76 :unsigned-short) (a77 :pointer) (a78 :unsigned-long) (a79 :double)
285 (a80 :pointer) (a81 :long) (a82 :float) (a83 :unsigned-short)
286 (a84 :unsigned-short) (a85 :pointer) (a86 :float) (a87 :int)
287 (a88 :unsigned-int) (a89 :double) (a90 :float) (a91 :long) (a92 :pointer)
288 (a93 :unsigned-short) (a94 :float) (a95 :unsigned-char) (a96 :unsigned-char)
289 (a97 :float) (a98 :unsigned-int) (a99 :float) (a100 :unsigned-short)
290 (a101 :double) (a102 :unsigned-short) (a103 :unsigned-long)
291 (a104 :unsigned-int) (a105 :unsigned-long) (a106 :pointer)
292 (a107 :unsigned-char) (a108 :char) (a109 :char) (a110 :unsigned-short)
293 (a111 :unsigned-long) (a112 :float) (a113 :short) (a114 :pointer)
294 (a115 :long) (a116 :unsigned-short) (a117 :short) (a118 :double)
295 (a119 :short) (a120 :int) (a121 :char) (a122 :unsigned-long) (a123 :long)
296 (a124 :int) (a125 :pointer) (a126 :double) (a127 :unsigned-char))
297 (let ((args (list a1 (pointer-address a2) a3 (floor a4) a5 (floor a6)
298 (floor a7) a8 a9 (floor a10) (floor a11) (floor a12)
299 (pointer-address a13) a14 a15 (pointer-address a16) a17 a18
300 a19 a20 a21 a22 a23 a24 (pointer-address a25)
301 (pointer-address a26) a27 a28 a29 a30 a31 a32 a33 a34 a35
302 a36 (pointer-address a37) a38 a39 (floor a40) a41
303 (pointer-address a42) a43 a44 a45 (floor a46) a47 a48
304 (floor a49) a50 a51 a52 a53 a54 (floor a55) a56
305 (pointer-address a57) a58 (floor a59) a60 (floor a61) a62
306 (floor a63) a64 a65 a66 a67 a68 a69 (floor a70) a71
307 (pointer-address a72) a73 a74 (pointer-address a75) a76
308 (pointer-address a77) a78 (floor a79) (pointer-address a80)
309 a81 (floor a82) a83 a84 (pointer-address a85) (floor a86)
310 a87 a88 (floor a89) (floor a90) a91 (pointer-address a92)
311 a93 (floor a94) a95 a96 (floor a97) a98 (floor a99) a100
312 (floor a101) a102 a103 a104 a105 (pointer-address a106) a107
313 a108 a109 a110 a111 (floor a112) a113 (pointer-address a114)
314 a115 a116 a117 (floor a118) a119 a120 a121 a122 a123 a124
315 (pointer-address a125) (floor a126) a127)))
316 #-(and)
317 (loop for i from 1 and arg in args do
318 (format t "a~A: ~A~%" i arg))
319 (reduce #'+ args)))
321 #+(or openmcl cmu ecl (and cffi-features:darwin (or allegro lispworks)))
322 (push 'callbacks.bff.1 regression-test::*expected-failures*)
324 #+#.(cl:if (cl:>= cl:lambda-parameters-limit 127) '(:and) '(:or))
325 (deftest callbacks.bff.1
326 (call-sum-127-no-ll (callback sum-127-no-ll))
327 2008547941)
329 ;;; (cb-test)
331 #-(:or cffi-features:no-long-long
332 #.(cl:if (cl:>= cl:lambda-parameters-limit 127) '(:or) '(:and)))
333 (progn
334 (defcfun "call_sum_127" :long-long (cb :pointer))
336 ;;; CMUCL and ECL choke on this one.
337 #-(or cmu ecl)
338 (defcallback sum-127 :long-long
339 ((a1 :short) (a2 :char) (a3 :pointer) (a4 :float) (a5 :long) (a6 :double)
340 (a7 :unsigned-long-long) (a8 :unsigned-short) (a9 :unsigned-char)
341 (a10 :char) (a11 :char) (a12 :unsigned-short) (a13 :unsigned-long-long)
342 (a14 :unsigned-short) (a15 :long-long) (a16 :unsigned-short)
343 (a17 :unsigned-long-long) (a18 :unsigned-char) (a19 :unsigned-char)
344 (a20 :unsigned-long-long) (a21 :long-long) (a22 :char) (a23 :float)
345 (a24 :unsigned-int) (a25 :float) (a26 :float) (a27 :unsigned-int)
346 (a28 :float) (a29 :char) (a30 :unsigned-char) (a31 :long) (a32 :long-long)
347 (a33 :unsigned-char) (a34 :double) (a35 :long) (a36 :double)
348 (a37 :unsigned-int) (a38 :unsigned-short) (a39 :long-long)
349 (a40 :unsigned-int) (a41 :int) (a42 :unsigned-long-long) (a43 :long)
350 (a44 :short) (a45 :unsigned-int) (a46 :unsigned-int)
351 (a47 :unsigned-long-long) (a48 :unsigned-int) (a49 :long) (a50 :pointer)
352 (a51 :unsigned-char) (a52 :char) (a53 :long-long) (a54 :unsigned-short)
353 (a55 :unsigned-int) (a56 :float) (a57 :unsigned-char) (a58 :unsigned-long)
354 (a59 :long-long) (a60 :float) (a61 :long) (a62 :float) (a63 :int)
355 (a64 :float) (a65 :unsigned-short) (a66 :unsigned-long-long) (a67 :short)
356 (a68 :unsigned-long) (a69 :long) (a70 :char) (a71 :unsigned-short)
357 (a72 :long-long) (a73 :short) (a74 :double) (a75 :pointer)
358 (a76 :unsigned-int) (a77 :char) (a78 :unsigned-int) (a79 :pointer)
359 (a80 :pointer) (a81 :unsigned-char) (a82 :pointer) (a83 :unsigned-short)
360 (a84 :unsigned-char) (a85 :long) (a86 :pointer) (a87 :char) (a88 :long)
361 (a89 :unsigned-short) (a90 :unsigned-char) (a91 :double)
362 (a92 :unsigned-long-long) (a93 :unsigned-short) (a94 :unsigned-short)
363 (a95 :unsigned-int) (a96 :long) (a97 :char) (a98 :long) (a99 :char)
364 (a100 :short) (a101 :unsigned-short) (a102 :unsigned-long)
365 (a103 :unsigned-long) (a104 :short) (a105 :long-long) (a106 :long-long)
366 (a107 :long-long) (a108 :double) (a109 :unsigned-short)
367 (a110 :unsigned-char) (a111 :short) (a112 :unsigned-char) (a113 :long)
368 (a114 :long-long) (a115 :unsigned-long-long) (a116 :unsigned-int)
369 (a117 :unsigned-long) (a118 :unsigned-char) (a119 :long-long)
370 (a120 :unsigned-char) (a121 :unsigned-long-long) (a122 :double)
371 (a123 :unsigned-char) (a124 :long-long) (a125 :unsigned-char)
372 (a126 :char) (a127 :long-long))
373 (+ a1 a2 (pointer-address a3) (values (floor a4)) a5 (values (floor a6))
374 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22
375 (values (floor a23)) a24 (values (floor a25)) (values (floor a26))
376 a27 (values (floor a28)) a29 a30 a31 a32 a33 (values (floor a34))
377 a35 (values (floor a36)) a37 a38 a39 a40 a41 a42 a43 a44 a45 a46 a47
378 a48 a49 (pointer-address a50) a51 a52 a53 a54 a55 (values (floor a56))
379 a57 a58 a59 (values (floor a60)) a61 (values (floor a62)) a63
380 (values (floor a64)) a65 a66 a67 a68 a69 a70 a71 a72 a73
381 (values (floor a74)) (pointer-address a75) a76 a77 a78
382 (pointer-address a79) (pointer-address a80) a81 (pointer-address a82)
383 a83 a84 a85 (pointer-address a86) a87 a88 a89 a90 (values (floor a91))
384 a92 a93 a94 a95 a96 a97 a98 a99 a100 a101 a102 a103 a104 a105 a106 a107
385 (values (floor a108)) a109 a110 a111 a112 a113 a114 a115 a116 a117 a118
386 a119 a120 a121 (values (floor a122)) a123 a124 a125 a126 a127))
388 #+(or openmcl cmu ecl)
389 (push 'callbacks.bff.2 rt::*expected-failures*)
391 (deftest callbacks.bff.2
392 (call-sum-127 (callback sum-127))
393 8166570665645582011))
395 ;;; regression test: (callback non-existant-callback) should throw an error
396 (deftest callbacks.non-existant
397 (not (null (nth-value 1 (ignore-errors (callback doesnt-exist)))))
400 ;;; Handling many arguments of type double. Many lisps (used to) fail
401 ;;; this one on darwin/ppc. This test might be bogus due to floating
402 ;;; point arithmetic rounding errors.
404 ;;; CMUCL chokes on this one.
405 #-(and cffi-features:darwin cmu)
406 (defcallback double26 :double
407 ((a1 :double) (a2 :double) (a3 :double) (a4 :double) (a5 :double)
408 (a6 :double) (a7 :double) (a8 :double) (a9 :double) (a10 :double)
409 (a11 :double) (a12 :double) (a13 :double) (a14 :double) (a15 :double)
410 (a16 :double) (a17 :double) (a18 :double) (a19 :double) (a20 :double)
411 (a21 :double) (a22 :double) (a23 :double) (a24 :double) (a25 :double)
412 (a26 :double))
413 (let ((args (list a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15
414 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26)))
415 #-(and)
416 (loop for i from 1 and arg in args do
417 (format t "a~A: ~A~%" i arg))
418 (reduce #'+ args)))
420 (defcfun "call_double26" :double (f :pointer))
422 #+(and cffi-features:darwin (or allegro cmu))
423 (pushnew 'callbacks.double26 rt::*expected-failures*)
425 (deftest callbacks.double26
426 (call-double26 (callback double26))
427 81.64d0)
429 #+(and cffi-features:darwin cmu)
430 (pushnew 'callbacks.double26.funcall rt::*expected-failures*)
432 #-cffi-features:no-foreign-funcall
433 (deftest callbacks.double26.funcall
434 (foreign-funcall-pointer
435 (callback double26) () :double 3.14d0 :double 3.14d0
436 :double 3.14d0 :double 3.14d0 :double 3.14d0 :double 3.14d0
437 :double 3.14d0 :double 3.14d0 :double 3.14d0 :double 3.14d0
438 :double 3.14d0 :double 3.14d0 :double 3.14d0 :double 3.14d0
439 :double 3.14d0 :double 3.14d0 :double 3.14d0 :double 3.14d0
440 :double 3.14d0 :double 3.14d0 :double 3.14d0 :double 3.14d0
441 :double 3.14d0 :double 3.14d0 :double 3.14d0 :double 3.14d0
442 :double)
443 81.64d0)
445 ;;; Same as above, for floats.
446 #-(and cffi-features:darwin cmu)
447 (defcallback float26 :float
448 ((a1 :float) (a2 :float) (a3 :float) (a4 :float) (a5 :float)
449 (a6 :float) (a7 :float) (a8 :float) (a9 :float) (a10 :float)
450 (a11 :float) (a12 :float) (a13 :float) (a14 :float) (a15 :float)
451 (a16 :float) (a17 :float) (a18 :float) (a19 :float) (a20 :float)
452 (a21 :float) (a22 :float) (a23 :float) (a24 :float) (a25 :float)
453 (a26 :float))
454 (let ((args (list a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15
455 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26)))
456 #-(and)
457 (loop for i from 1 and arg in args do
458 (format t "a~A: ~A~%" i arg))
459 (reduce #'+ args)))
461 (defcfun "call_float26" :float (f :pointer))
463 #+(and cffi-features:darwin (or lispworks openmcl cmu))
464 (pushnew 'callbacks.float26 regression-test::*expected-failures*)
466 (deftest callbacks.float26
467 (call-float26 (callback float26))
468 130.0)
470 #+(and cffi-features:darwin (or lispworks openmcl cmu))
471 (pushnew 'callbacks.float26.funcall regression-test::*expected-failures*)
473 #-cffi-features:no-foreign-funcall
474 (deftest callbacks.float26.funcall
475 (foreign-funcall-pointer
476 (callback float26) () :float 5.0 :float 5.0
477 :float 5.0 :float 5.0 :float 5.0 :float 5.0
478 :float 5.0 :float 5.0 :float 5.0 :float 5.0
479 :float 5.0 :float 5.0 :float 5.0 :float 5.0
480 :float 5.0 :float 5.0 :float 5.0 :float 5.0
481 :float 5.0 :float 5.0 :float 5.0 :float 5.0
482 :float 5.0 :float 5.0 :float 5.0 :float 5.0
483 :float)
484 130.0)
486 ;;; Defining a callback as a non-toplevel form. Not portable. Doesn't
487 ;;; work for CMUCL or Allegro.
488 #-(and)
489 (let ((n 42))
490 (defcallback non-toplevel-cb :int ()
493 #-(and)
494 (deftest callbacks.non-toplevel
495 (foreign-funcall (callback non-toplevel-cb) :int)
498 ;;;# Stdcall
500 #+(and cffi-features:x86 (not cffi-features:no-stdcall))
501 (progn
502 (defcallback (stdcall-cb :cconv :stdcall) :int
503 ((a :int) (b :int) (c :int))
504 (+ a b c))
506 (defcfun "call_stdcall_fun" :int
507 (f :pointer))
509 (deftest callbacks.stdcall.1
510 (call-stdcall-fun (callback stdcall-cb))
511 42))