Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Add catching C++ exception support to dwarfeh.d #1470

Merged
merged 1 commit into from Jan 17, 2016

Conversation

WalterBright
Copy link
Member

Requires:
dlang/dmd#5342

p = *cast(void**)p;

// Pointer adjustment may be necessary due to multiple inheritance
return (sti.__do_catch(tt, &p, 1)) ? p : null;
Copy link
Member

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.

Copy link
Contributor

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);
}

Copy link
Member

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==.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member Author

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.

@IgorStepanov
Copy link
Contributor

BTW, will be this exception handling work with some another c++ compilers? clang++? intel c++ compiler?

@WalterBright
Copy link
Member Author

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.

@IgorStepanov
Copy link
Contributor

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.

@WalterBright
Copy link
Member Author

You can be binary compatible and yet have a different implementation. Again, my understanding is they are binary compatible.

@IgorStepanov
Copy link
Contributor

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);
Copy link
Member

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

@andralex
Copy link
Member

thx!

andralex added a commit that referenced this pull request Jan 17, 2016
Add catching C++ exception support to dwarfeh.d
@andralex andralex merged commit 244349f into dlang:master Jan 17, 2016
@WalterBright WalterBright deleted the dwarfeh2 branch January 19, 2016 05:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants