-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
Fix bugzilla issue 24882 - COM class is allocated using GC not malloc #17095
Conversation
Thanks for your pull request and interest in making D better, @rikkimax! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "stable + dmd#17095" |
changelog/dmd.isCOMClass.dd
Outdated
|
||
A COM class inherits from a possibly user defined interface called ``IUnknown``. | ||
To detect this during compilation use the trait ``__traits(isCOMClass, Type)``. | ||
Or using the ``TypeInfo_Class`` flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you check that flag? If this works as an alternative, why is __traits(isCOMClass)
introduced?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the original code from the hook:
extern (C) Object _d_newclass(const ClassInfo ci) @weak
{
import core.stdc.stdlib;
import core.exception : onOutOfMemoryError;
void* p;
auto init = ci.initializer;
debug(PRINTF) printf("_d_newclass(ci = %p, %s)\n", ci, cast(char *)ci.name);
if (ci.m_flags & TypeInfo_Class.ClassFlags.isCOMclass)
The templated hook that has been fixed to use the new trait:
T _d_newclassT(T)() @trusted
if (is(T == class))
{
import core.internal.traits : hasIndirections;
import core.exception : onOutOfMemoryError;
import core.memory : pureMalloc;
import core.memory : GC;
alias BlkAttr = GC.BlkAttr;
auto init = __traits(initSymbol, T);
void* p;
static if (__traits(isCOMClass, T))
While both do the same thing new a class, one uses purely CT available information, the other RT only information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either we revert back to TypeInfo for this hook, or we go in the direction of some sort of CT available information.
Of course we could derive it by looking for a IUnknown
interface, but that isn't an easy thing to do, let alone perform on every single class new instantiation when there is a flag in the compiler easily readable with the information we need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new trait is good, I just think the last line of the changelog should be removed or clarified. The current wording implies TypeInfo_Class
can be used during compilation to check the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like "The trait is equivalent to the runtime check ClassInfo.m_flags & TypeInfo_Class.ClassFlags.isCOMclass
".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to encourage people to use anything TypeInfo-related, it's stated so that people know what existing code they can replace with the trait.
What's the problem with |
A COM class is any class derived from an interface called That would only work with a specific |
Has spec PR: dlang/dlang.org#3928
Fixes it by introducing the trait isCOMClass