Merge pull request #228 from vibe-d/interfaceproxy_null
Fix InterfaceProxy to work with null values.
This commit is contained in:
commit
483725f5eb
|
@ -97,16 +97,26 @@ struct InterfaceProxy(I) if (is(I == interface)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this(O)(O object) @trusted
|
this(O)(O object) @trusted
|
||||||
|
if (is(O == struct) || is(O == class) || is(O == interface))
|
||||||
{
|
{
|
||||||
static assert(O.sizeof % m_value[0].sizeof == 0, "Sizeof object ("~O.stringof~") must be a multiple of a pointer size.");
|
static assert(O.sizeof % m_value[0].sizeof == 0, "Sizeof object ("~O.stringof~") must be a multiple of a pointer size.");
|
||||||
static assert(O.sizeof <= maxSize, "Object ("~O.stringof~") is too big to be stored in an InterfaceProxy.");
|
static assert(O.sizeof <= maxSize, "Object ("~O.stringof~") is too big to be stored in an InterfaceProxy.");
|
||||||
import std.conv : emplace;
|
import std.conv : emplace;
|
||||||
|
|
||||||
|
static if (is(O == class) || is(O == interface)) {
|
||||||
|
if (!object) return;
|
||||||
|
}
|
||||||
|
|
||||||
m_intf = ProxyImpl!O.get();
|
m_intf = ProxyImpl!O.get();
|
||||||
static if (is(O == struct))
|
static if (is(O == struct))
|
||||||
emplace!O(m_value[0 .. O.sizeof/m_value[0].sizeof]);
|
emplace!O(m_value[0 .. O.sizeof/m_value[0].sizeof]);
|
||||||
swap((cast(O[])m_value[0 .. O.sizeof/m_value[0].sizeof])[0], object);
|
swap((cast(O[])m_value[0 .. O.sizeof/m_value[0].sizeof])[0], object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this(typeof(null))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
~this() @safe
|
~this() @safe
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
@ -304,6 +314,12 @@ struct InterfaceProxy(I) if (is(I == interface)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest {
|
||||||
|
static interface I {}
|
||||||
|
assert(!InterfaceProxy!I(null));
|
||||||
|
assert(!InterfaceProxy!I(cast(I)null));
|
||||||
|
}
|
||||||
|
|
||||||
private string parameterDecls(alias F, size_t idx)()
|
private string parameterDecls(alias F, size_t idx)()
|
||||||
{
|
{
|
||||||
import std.format : format;
|
import std.format : format;
|
||||||
|
|
Loading…
Reference in a new issue