Introduction
Introduction Statistics Contact Development Disclaimer Help
tarrays.lisp - clic - Clic is an command line interactive client for gopher wri…
git clone git://bitreich.org/clic/ git://hg6vgqziawt5s4dj.onion/clic/
Log
Files
Refs
Tags
LICENSE
---
tarrays.lisp (3464B)
---
1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; arrays.lisp --- Tests for foreign arrays.
4 ;;;
5 ;;; Copyright (C) 2005-2006, James Bielman <[email protected]>
6 ;;; Copyright (C) 2005-2007, Luis Oliveira <[email protected]>
7 ;;;
8 ;;; Permission is hereby granted, free of charge, to any person
9 ;;; obtaining a copy of this software and associated documentation
10 ;;; files (the "Software"), to deal in the Software without
11 ;;; restriction, including without limitation the rights to use, copy,
12 ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
13 ;;; of the Software, and to permit persons to whom the Software is
14 ;;; furnished to do so, subject to the following conditions:
15 ;;;
16 ;;; The above copyright notice and this permission notice shall be
17 ;;; included in all copies or substantial portions of the Software.
18 ;;;
19 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 ;;; DEALINGS IN THE SOFTWARE.
27 ;;;
28
29 ;;;#Foreign Array Conversion Tests
30 ;;;
31
32 (in-package #:cffi-tests)
33
34 (deftest array.foreign-to-lisp.basic
35 (with-foreign-array (ptr #(1 2 3 4 5) '(:array :int32 5))
36 (foreign-array-to-lisp ptr '(:array :int32 5)))
37 #(1 2 3 4 5))
38
39 (deftest array.foreign-to-lisp.adjustable
40 (with-foreign-array (ptr #(1 2 3 4 5) '(:array :int32 5))
41 (let ((array (foreign-array-to-lisp ptr '(:array :int32 5)
42 :adjustable t)))
43 (adjustable-array-p array)))
44 t)
45
46 (deftest array.foreign-to-lisp.displaced
47 (let ((array (make-array 10 :initial-contents '(1 2 3 4 5 6 7 8 9 0)…
48 (with-foreign-array (ptr #(10 20 30 40 50) '(:array :int32 5))
49 (let ((displaced (foreign-array-to-lisp ptr '(:array :int32 5)
50 :displaced-to array
51 :displaced-index-offset …
52 array)))
53 #(1 2 3 4 5 10 20 30 40 50))
54
55 ;;; Implementation detail: 15.1.2.2 of the CL standard states that the o…
56 ;;; truly portable array specializations are for bits (bit-vectors) and
57 ;;; characters (strings). Since char-codes are implementation-dependent,…
58 ;;; would be tricky to write a portable test for them without generating
59 ;;; characters at runtime. So, for a truly portable test, we are only le…
60 ;;; bits, which are luckily numeric, and equal to (UNSIGNED-BYTE 1).
61 ;;; This is why the below test is so terribly wasteful, spending a whole…
62 ;;; for a single bit - CFFI has no capabilities for dealing with single …
63 ;;; and this test is only meant to check correctness of the :ELEMENT-TYPE
64 ;;; argument to MAKE-ARRAY. In actual use cases of specialized
65 ;;; FOREIGN-ARRAY-TO-LISP, capable implementations will be able to make
66 ;;; specialized arrays of types that are commonly optimized for and/or
67 ;;; representable in hardware, such as (UNSIGNED-BYTE 8) on x86 architec…
68 (deftest array.foreign-to-lisp.specialized
69 (with-foreign-array (ptr #(1 0 1 0 1 1 1 0) '(:array :int8 8))
70 (foreign-array-to-lisp ptr '(:array :int8 8) :element-type 'bit))
71 #*10101110)
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.