Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue 15721 - std.experimental.allocator dispose on interface #4022

Merged
merged 1 commit into from Mar 3, 2016
Merged

fixed issue 15721 - std.experimental.allocator dispose on interface #4022

merged 1 commit into from Mar 3, 2016

Conversation

ghost
Copy link

@ghost ghost commented Feb 26, 2016

No description provided.

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
15721 free error when calling Mallocator.dispose on interfaces

@@ -1099,7 +1099,11 @@ 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))
auto ob = cast(Object) p;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this cast returns null? I believe you can't cast C++ COM interfaces to Object (https://dlang.org/spec/interface.html#com-interfaces).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so used to CORBA interfaces that I forgot this crap exists.

Short answer IDK. I never use COM interface. Someone has to propose an alternative.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MetaLang.

Actually I think it's not a problem. COM interfaces are reference counted, so trying to free one with dispose is a programming error. So there is no problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that works then. Might be worth putting in an assert that is(T: IUknown) is false.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd even like to put a static assertion for this case but we need the expertise from someone who actually uses COM interfaces.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to https://dlang.org/spec/interface.html#com-interfaces

It cannot be the argument of a DeleteExpression.

so the static assertion to reject this case is conform.

@ghost
Copy link
Author

ghost commented Feb 26, 2016

#4022 updated

@schveiguy
Copy link
Member

You should be able to check whether an interface is COM or not by determining if it is a derivative of core.stdc.windows.com.IUnknown:

if(is(T : IUnknown))

I would say you shouldn't even compile if it's one of those (even if it's a concrete class). Only Windows should be allocating/deallocating COM classes I think. Even in the docs it says "It cannot be the argument of a DeleteExpression."

Edit: Oh, right, you already did that. In my defense, I read about 3 comments in and stopped :)

@schveiguy
Copy link
Member

LGTM, just update changelog.dd

@schveiguy
Copy link
Member

As noted on #4023, changelog.dd update is not necessary, sorry for that request. Still LGTM.

@ghost
Copy link
Author

ghost commented Mar 3, 2016

green again.

@MetaLang
Copy link
Member

MetaLang commented Mar 3, 2016

LGTM

@schveiguy
Copy link
Member

Auto-merge toggled on

schveiguy added a commit that referenced this pull request Mar 3, 2016
fixed issue 15721 - std.experimental.allocator dispose on interface
@schveiguy schveiguy merged commit e55e196 into dlang:master Mar 3, 2016
@ghost ghost deleted the issue-15721 branch March 3, 2016 14:14
@schveiguy
Copy link
Member

@bbasile mind fixing that request? I'll merge it immediately.

@schveiguy
Copy link
Member

Nevermind, I got it.

schveiguy added a commit that referenced this pull request Mar 3, 2016
gchatelet pushed a commit to gchatelet/phobos that referenced this pull request Mar 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants