mirror of
https://github.com/dlang/phobos.git
synced 2025-05-01 15:40:36 +03:00
Made std.exception.pointsTo "@trusted pure nothrow".
Also made it tolerant of shared objects. It's @trusted to cast shared away because the function just compares the addresses of passed objects.
This commit is contained in:
parent
85b5c42510
commit
0339b6acde
1 changed files with 9 additions and 4 deletions
|
@ -361,11 +361,12 @@ that points to $(D target)'s representation or somewhere inside
|
||||||
it. Note that evaluating $(D pointsTo(x, x)) checks whether $(D x) has
|
it. Note that evaluating $(D pointsTo(x, x)) checks whether $(D x) has
|
||||||
internal pointers.
|
internal pointers.
|
||||||
*/
|
*/
|
||||||
bool pointsTo(S, T)(ref S source, ref T target)
|
bool pointsTo(S, T)(ref const S source, ref const T target) @trusted pure nothrow
|
||||||
{
|
{
|
||||||
static if (is(S P : U*, U))
|
static if (is(S P : U*, U))
|
||||||
{
|
{
|
||||||
const void * m = source, b = &target, e = b + target.sizeof;
|
const m = cast(void*) source,
|
||||||
|
b = cast(void*) &target, e = b + target.sizeof;
|
||||||
return b <= m && m < e;
|
return b <= m && m < e;
|
||||||
}
|
}
|
||||||
else static if (is(S == struct))
|
else static if (is(S == struct))
|
||||||
|
@ -379,8 +380,8 @@ bool pointsTo(S, T)(ref S source, ref T target)
|
||||||
}
|
}
|
||||||
else static if (isDynamicArray!(S))
|
else static if (isDynamicArray!(S))
|
||||||
{
|
{
|
||||||
const void* p1 = source.ptr, p2 = p1 + source.length,
|
const p1 = cast(void*) source.ptr, p2 = p1 + source.length,
|
||||||
b = &target, e = b + target.sizeof;
|
b = cast(void*) &target, e = b + target.sizeof;
|
||||||
return overlap(p1[0 .. p2 - p1], b[0 .. e - b]).length != 0;
|
return overlap(p1[0 .. p2 - p1], b[0 .. e - b]).length != 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -421,6 +422,10 @@ unittest
|
||||||
Holder h;
|
Holder h;
|
||||||
pointsTo(h, h);
|
pointsTo(h, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared S3 sh3;
|
||||||
|
shared sh3sub = sh3.a[];
|
||||||
|
assert(pointsTo(sh3sub, sh3));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue