2 * Copyright (C) 2004-2007 by Digital Mars, www.digitalmars.com
3 * Written by Walter Bright
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, in both source and binary form, subject to the following
14 * o The origin of this software must not be misrepresented; you must not
15 * claim that you wrote the original software. If you use this software
16 * in a product, an acknowledgment in the product documentation would be
17 * appreciated but is not required.
18 * o Altered source versions must be plainly marked as such, and must not
19 * be misrepresented as being the original software.
20 * o This notice may not be removed or altered from any source
25 * Modified by Sean Kelly for use with the D Runtime Project
30 /******************************************
31 * Runtime helper to convert dynamic array of one
32 * type to dynamic array of another.
33 * Adjusts the length of the array.
34 * Throws exception if new length is not aligned.
39 void[] _d_arraycast(size_t tsize, size_t fsize, void[] a)
41 auto length = a.length;
43 auto nbytes = length * fsize;
44 if (nbytes % tsize != 0)
46 throw new Exception("array cast misalignment");
48 length = nbytes / tsize;
49 *cast(size_t *)&a = length; // jam new length
55 byte[int.sizeof * 3] b;
60 assert(i.length == 3);
63 assert(s.length == 6);
66 assert(s.length == 6);
69 /******************************************
70 * Runtime helper to convert dynamic array of bits
71 * dynamic array of another.
72 * Adjusts the length of the array.
73 * Throws exception if new length is not aligned.
80 void[] _d_arraycast_frombit(uint tsize, void[] a)
82 uint length = a.length;
86 throw new Exception("bit[] array cast misalignment");
89 *cast(size_t *)&a = length; // jam new length
97 bit[int.sizeof * 3 * 8] b;
102 assert(i.length == 3);
105 assert(s.length == 6);