Add catching C++ exception support to dwarfeh.d #1470
Conversation
p = *cast(void**)p; | ||
|
||
// Pointer adjustment may be necessary due to multiple inheritance | ||
return (sti.__do_catch(tt, &p, 1)) ? p : null; |
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.
Maybe add a pointer comparison before this to shortcut calling do_catch? If sti == tt
then it's a direct match.
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.
It's done inside __do_catch
:
bool __class_type_info::
__do_catch (const type_info *thr_type,
void **thr_obj,
unsigned outer) const
{
if (*this == *thr_type)
return true;
if (outer >= 4)
// Neither `A' nor `A *'.
return false;
return thr_type->__do_upcast (this, thr_obj);
}
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.
That is not actually true. (*this == *thr_type)
calls operator==
.
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.
operator==
in my libstdc++ looks like
bool std::type_info::
operator== (const std::type_info& arg) const
{
return (&arg == this) || (__builtin_strcmp (name (), arg.name ()) == 0);
}
However in other versions it may differ.
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.
You may find that it's been that way for a very long time. C++ is not something that simply changes.
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.
Maybe add a pointer comparison before this to shortcut calling do_catch? If sti == tt then it's a direct match.
Done, but given all the other code executed for an exception, I doubt the difference would be measurable.
3fa1524
to
cea7bb5
Compare
BTW, will be this exception handling work with some another c++ compilers? clang++? intel c++ compiler? |
My understanding is that they are binary compatible with g++, so they should work. |
Are they use the same libstdc++ implementation? Otherwise there can be another virtual method order in std::type_info for example. |
You can be binary compatible and yet have a different implementation. Again, my understanding is they are binary compatible. |
Sounds good. It remains to deal with dmc and Visual Studio :) |
|
||
if (exceptionClass == dmdExceptionClass) | ||
{ | ||
ExceptionHeader *eh = ExceptionHeader.toExceptionHeader(exceptionObject); |
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.
this line in desperate need of auto
cea7bb5
to
07cf8f3
Compare
thx! |
Add catching C++ exception support to dwarfeh.d
Requires:
dlang/dmd#5342