Skip to content

Commit

Permalink
Merge pull request #4022 from BBasile/issue-15721
Browse files Browse the repository at this point in the history
fixed issue 15721 - std.experimental.allocator dispose on interface
  • Loading branch information
schveiguy committed Mar 3, 2016
2 parents 35a2a56 + 211c10a commit e55e196
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion std/experimental/allocator/package.d
Expand Up @@ -1099,7 +1099,19 @@ void dispose(A, T)(auto ref A alloc, T p)
if (is(T == class) || is(T == interface))
{
if (!p) return;
auto support = (cast(void*) p)[0 .. typeid(p).initializer.length];
static if (is(T==interface))
{
version(Windows)
{
import core.sys.windows.unknwn;
static assert(!is(T: IUnknown), "COM interfaces can't be destroyed in "
~ __PRETTY_FUNCTION__);
}
auto ob = cast(Object) p;
}
else
alias ob = p;
auto support = (cast(void*) ob)[0 .. typeid(ob).initializer.length];
destroy(p);
alloc.deallocate(support);
}
Expand Down Expand Up @@ -1155,6 +1167,20 @@ unittest
theAllocator.dispose(arr);
}

unittest //bugzilla 15721
{
import std.experimental.allocator.mallocator: Mallocator;

interface Foo {}
class Bar: Foo {}

Bar bar;
Foo foo;
bar = Mallocator.instance.make!Bar;
foo = cast(Foo) bar;
Mallocator.instance.dispose(foo);
}

/**
Returns a dynamically-typed $(D CAllocator) built around a given statically-
Expand Down

0 comments on commit e55e196

Please sign in to comment.