/usr/lib/gcc/x86_64-linux-gnu/5/include/d/rt/arraycast.d is in libphobos-5-dev 5.5.0-12ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | /**
* Implementation of array cast support routines.
*
* Copyright: Copyright Digital Mars 2004 - 2010.
* License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
* Authors: Walter Bright, Sean Kelly
*/
/* Copyright Digital Mars 2004 - 2010.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module rt.arraycast;
/******************************************
* Runtime helper to convert dynamic array of one
* type to dynamic array of another.
* Adjusts the length of the array.
* Throws an error if new length is not aligned.
*/
extern (C)
@trusted nothrow
void[] _d_arraycast(size_t tsize, size_t fsize, void[] a)
{
auto length = a.length;
auto nbytes = length * fsize;
if (nbytes % tsize != 0)
{
throw new Error("array cast misalignment");
}
length = nbytes / tsize;
*cast(size_t *)&a = length; // jam new length
return a;
}
unittest
{
byte[int.sizeof * 3] b;
int[] i;
short[] s;
i = cast(int[])b;
assert(i.length == 3);
s = cast(short[])b;
assert(s.length == 6);
s = cast(short[])i;
assert(s.length == 6);
}
/******************************************
* Runtime helper to convert dynamic array of bits
* dynamic array of another.
* Adjusts the length of the array.
* Throws an error if new length is not aligned.
*/
version (none)
{
extern (C)
@trusted nothrow
void[] _d_arraycast_frombit(uint tsize, void[] a)
{
uint length = a.length;
if (length & 7)
{
throw new Error("bit[] array cast misalignment");
}
length /= 8 * tsize;
*cast(size_t *)&a = length; // jam new length
return a;
}
unittest
{
version (D_Bits)
{
bit[int.sizeof * 3 * 8] b;
int[] i;
short[] s;
i = cast(int[])b;
assert(i.length == 3);
s = cast(short[])b;
assert(s.length == 6);
}
}
}
|