Skip to content

Commit

Permalink
Merge pull request #4009 from quickfur/issue14137
Browse files Browse the repository at this point in the history
Fix issue 14137: std.socket.getAddressInfo breaks @safe
  • Loading branch information
DmitryOlshansky committed Apr 18, 2016
2 parents 1f37557 + c35d4aa commit 8a34531
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions std/socket.d
Expand Up @@ -955,7 +955,7 @@ private string formatGaiError(int err) @trusted
* AddressFamily.INET6);
* ---
*/
AddressInfo[] getAddressInfo(T...)(in char[] node, T options) @trusted
AddressInfo[] getAddressInfo(T...)(in char[] node, T options)
{
const(char)[] service = null;
addrinfo hints;
Expand All @@ -981,7 +981,23 @@ AddressInfo[] getAddressInfo(T...)(in char[] node, T options) @trusted
static assert(0, "Unknown getAddressInfo option type: " ~ typeof(option).stringof);
}

return getAddressInfoImpl(node, service, &hints);
return () @trusted { return getAddressInfoImpl(node, service, &hints); }();
}

@system unittest
{
struct Oops
{
const(char[]) breakSafety()
{
*cast(int*) 0xcafebabe = 0xdeadbeef;
return null;
}
alias breakSafety this;
}
assert(!__traits(compiles, () {
getAddressInfo("", Oops.init);
}), "getAddressInfo breaks @safe");
}

private AddressInfo[] getAddressInfoImpl(in char[] node, in char[] service, addrinfo* hints) @system
Expand Down Expand Up @@ -1019,7 +1035,7 @@ private AddressInfo[] getAddressInfoImpl(in char[] node, in char[] service, addr
}


unittest
@safe unittest
{
softUnittest({
if (getaddrinfoPointer)
Expand Down

0 comments on commit 8a34531

Please sign in to comment.