digitalmars.D - Any libunwind experts n da house?
- Andrei Alexandrescu (4/4) Sep 23 2014 We need a libunwind expert to figure out a good approach for handling
- David Nadlinger (9/12) Sep 23 2014 More or less.
- David Nadlinger (6/15) Sep 23 2014 Let me also note that if you do, it's no longer a question of
- Andrei Alexandrescu (2/14) Sep 23 2014 Yes. -- Andrei
- Andrei Alexandrescu (4/14) Sep 23 2014 I think we should explore that rabbit hole. In the interim, a simpler
- deadalnix (9/32) Sep 23 2014 Here is the other side of the rabbit hole you want to be
- Walter Bright (6/16) Sep 23 2014 One goal is to have dmd use the g++ exception handling mechanism. But go...
- Jason King via Digitalmars-d (6/32) Sep 23 2014 I believe pretty much anything *ix on 64-bit(at least) x86 (32-bit gets ...
- Walter Bright (2/6) Sep 23 2014 Thanks, this contains part of the info.
- Jacob Carlborg (18/25) Sep 23 2014 From the LLVM docs [1]:
- Walter Bright (2/3) Sep 23 2014 Thank you. This is helpful.
- David Nadlinger (9/12) Sep 23 2014 Yes, that's quite a nice list already.
- Andrei Alexandrescu (4/16) Sep 23 2014 Speaking of which, what's the current story with gdc and ldc with regard...
- David Nadlinger (5/8) Sep 23 2014 Currently, the LDC runtime just aborts, but that wouldn't be too
- Iain Buclaw via Digitalmars-d (41/65) Sep 23 2014 GDC lets foreign exceptions pass through just fine. The only time
- Andrei Alexandrescu (2/3) Sep 23 2014 Proper unwinding of the D stack and all? -- Andrei
- Iain Buclaw via Digitalmars-d (7/11) Sep 24 2014 If you mean in the sense that libunwind will happily work it's way up,
- Andrei Alexandrescu (2/13) Sep 24 2014 Yah, that's what I meant. Thanks! -- Andrei
- deadalnix (3/7) Sep 23 2014 https://github.com/deadalnix/libsdrt/blob/master/src/d/rt/eh.d
- Iain Buclaw via Digitalmars-d (4/15) Sep 23 2014 https://github.com/D-Programming-GDC/GDC/blob/master/libphobos/libdrunti...
- Andrei Alexandrescu (4/21) Sep 23 2014 Noice. How difficult would be to port this to dmd/Linux? This is big -
- Walter Bright (3/27) Sep 23 2014 There is a problem, that code is gpl licensed. It may not actually matte...
- Iain Buclaw via Digitalmars-d (11/50) Sep 24 2014 As well as the license, there's also two technical details that need
- IgorStepanov (16/20) Sep 24 2014 Is there plans to catching C++ exceptions in D?
- Iain Buclaw via Digitalmars-d (6/27) Sep 24 2014 I'd say no to such an idea.
- Andrei Alexandrescu (14/42) Sep 24 2014 I understand the difficulty of it. However, we should look into it
- Sean Kelly (7/17) Sep 24 2014 If C++ code can execute D delegates, perhaps an intermediate step
- Andrei Alexandrescu (2/18) Sep 24 2014 That's a good idea, thanks. -- Andrei
- Iain Buclaw via Digitalmars-d (22/58) Sep 24 2014 Thinking about it:
- Andrei Alexandrescu (8/37) Sep 24 2014 Yah. I'm thinking of simplifying assumptions, e.g. all C++ exceptions
- deadalnix (5/22) Sep 24 2014 Considered it for SDC. it is not that simple as if it is a C++
- Iain Buclaw via Digitalmars-d (5/28) Sep 24 2014 Hmm... I forgot about the C++ compiler emitting function calls for the
- IgorStepanov (18/72) Sep 24 2014 I have one freaky example for you. This example can be
- IgorStepanov (11/11) Sep 24 2014 Now DMD doesn't support thorowing C++ exceptions through D
- Andrei Alexandrescu (2/18) Sep 24 2014 Awesome! How do we make it standard and safe? -- Andrei
- IgorStepanov (25/47) Sep 24 2014 C++ hasn't standart abi(
- Kagamin (4/6) Sep 25 2014 Why not catch std::exception directly? Then you could generate
- Andrei Alexandrescu (4/9) Sep 25 2014 That would be a language change - right now D can only catch Exception
- Kagamin (3/5) Sep 25 2014 Isn't the idea to let D do more things with C++ things?
- Kagamin (3/3) Sep 25 2014 I mean, D's inability to interoperate with C++ is not a feature,
- IgorStepanov (55/68) Sep 26 2014 I've implemented an experemental "framework" to catching C++
- deadalnix (2/2) Sep 26 2014 Congrat, that is some awesome work. I will certainly dig into
- Jacob Carlborg (17/19) Sep 27 2014 BTW, are you only interested in handling C++ exception, or are you
- IgorStepanov (10/19) Sep 27 2014 C++ exception mechanism uses C++ type_info objects. We can
- Jacob Carlborg (6/15) Sep 27 2014 Objective-C can do it somehow. If they can do it I'm sure we can
- IgorStepanov (5/20) Sep 27 2014 If someone from D commanders bless me, I can start to exploring
- Andrei Alexandrescu (3/22) Sep 27 2014 Would that be for throwing exceptions from D into C++? I think we can
- IgorStepanov (11/45) Sep 27 2014 No, that for throwing from C++ into D: for catch an exception, we
- Andrei Alexandrescu (3/11) Sep 27 2014 If that's what's needed, definitely please do explore it! But I defer
- IgorStepanov (88/105) Sep 28 2014 Ok. Anyway, I can't work on this to the full extent, because I
- Jacob Carlborg (5/8) Sep 28 2014 Objective-C seems to use a struct made of a vtable, the class name and
- Andrei Alexandrescu (4/9) Sep 27 2014 The more the merrier, but there's a large difference in importance. For
- IgorStepanov (7/20) Sep 27 2014 Can someone implement an C++ exception transparency? (when
- Iain Buclaw via Digitalmars-d (5/23) Sep 27 2014 Well, ObjC++ shares the same EH personality routines as C++, which
- IgorStepanov (3/44) Sep 27 2014 Is this way acceptable for D, or not. Why?
- Iain Buclaw via Digitalmars-d (12/49) Sep 27 2014 Digitalmars-d wrote:
We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind? Andrei
Sep 23 2014
On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind?More or less. What exactly are your goals? I thought the options we have are fairly clear, as discussed a few days ago. At least, Amaury and I seemed to agree (both of us worked on EH recently). The main question to decide is whether you want to go down the catch-C++-exceptions-in-D rabbit hole. David
Sep 23 2014
On Tuesday, 23 September 2014 at 18:03:18 UTC, David Nadlinger wrote:On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:Let me also note that if you do, it's no longer a question of just libunwind, but also of C++ runtime internals. I assume your primary target is g++ on Linux x86/x86_64? DavidWe need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind?[…] The main question to decide is whether you want to go down the catch-C++-exceptions-in-D rabbit hole.
Sep 23 2014
On 9/23/14, 11:06 AM, David Nadlinger wrote:On Tuesday, 23 September 2014 at 18:03:18 UTC, David Nadlinger wrote:Yes. -- AndreiOn Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:Let me also note that if you do, it's no longer a question of just libunwind, but also of C++ runtime internals. I assume your primary target is g++ on Linux x86/x86_64?We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind?[…] The main question to decide is whether you want to go down the catch-C++-exceptions-in-D rabbit hole.
Sep 23 2014
On 9/23/14, 11:03 AM, David Nadlinger wrote:On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:I think we should explore that rabbit hole. In the interim, a simpler solution may work: a C++ exception can only be caught from within C++ code. If no handler, the program terminates reliably. -- AndreiWe need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind?More or less. What exactly are your goals? I thought the options we have are fairly clear, as discussed a few days ago. At least, Amaury and I seemed to agree (both of us worked on EH recently). The main question to decide is whether you want to go down the catch-C++-exceptions-in-D rabbit hole.
Sep 23 2014
On Tuesday, 23 September 2014 at 18:14:35 UTC, Andrei Alexandrescu wrote:On 9/23/14, 11:03 AM, David Nadlinger wrote:Here is the other side of the rabbit hole you want to be compatible with: libstdc++-v3//libsupc++/eh_personality.cc (from GCC source tree, svn checkout svn://gcc.gnu.org/svn/gcc/trunk SomeLocalDir ). I think catching C++ exception may be realistic on the long run, but having them unwind properly should probably be the goal on the short run.On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:I think we should explore that rabbit hole. In the interim, a simpler solution may work: a C++ exception can only be caught from within C++ code. If no handler, the program terminates reliably. -- AndreiWe need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind?More or less. What exactly are your goals? I thought the options we have are fairly clear, as discussed a few days ago. At least, Amaury and I seemed to agree (both of us worked on EH recently). The main question to decide is whether you want to go down the catch-C++-exceptions-in-D rabbit hole.
Sep 23 2014
On 9/23/2014 11:03 AM, David Nadlinger wrote:On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:One goal is to have dmd use the g++ exception handling mechanism. But googling how that works, I find dead links, specs that are 15 years old accompanied by vague comments about it being "extended" and "look at the g++ source code", etc. Are there any actual docs about how it works for x86? Or is it the usual "take apart the output of g++ and figure it out" that I usually wind up doing :-( ?We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind?More or less. What exactly are your goals? I thought the options we have are fairly clear, as discussed a few days ago. At least, Amaury and I seemed to agree (both of us worked on EH recently). The main question to decide is whether you want to go down the catch-C++-exceptions-in-D rabbit hole.
Sep 23 2014
I believe pretty much anything *ix on 64-bit(at least) x86 (32-bit gets a bit murkier due to historical issues) is using the same exception handling ABI (which itself was based off the Itanic ABI): http://www.x86-64.org/documentation/abi.pdf On Tue, Sep 23, 2014 at 1:31 PM, Walter Bright via Digitalmars-d < digitalmars-d puremagic.com> wrote:On 9/23/2014 11:03 AM, David Nadlinger wrote:On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:One goal is to have dmd use the g++ exception handling mechanism. But googling how that works, I find dead links, specs that are 15 years old accompanied by vague comments about it being "extended" and "look at the g++ source code", etc. Are there any actual docs about how it works for x86? Or is it the usual "take apart the output of g++ and figure it out" that I usually wind up doing :-( ?We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind?More or less. What exactly are your goals? I thought the options we have are fairly clear, as discussed a few days ago. At least, Amaury and I seemed to agree (both of us worked on EH recently). The main question to decide is whether you want to go down the catch-C++-exceptions-in-D rabbit hole.
Sep 23 2014
On 9/23/2014 11:58 AM, Jason King via Digitalmars-d wrote:I believe pretty much anything *ix on 64-bit(at least) x86 (32-bit gets a bit murkier due to historical issues) is using the same exception handling ABI (which itself was based off the Itanic ABI): http://www.x86-64.org/documentation/abi.pdfThanks, this contains part of the info.
Sep 23 2014
On 2014-09-23 20:31, Walter Bright wrote:One goal is to have dmd use the g++ exception handling mechanism.That would be cool. It's useful for Objective-C on x86-64 as well.But googling how that works, I find dead links, specs that are 15 years old accompanied by vague comments about it being "extended" and "look at the g++ source code", etc. Are there any actual docs about how it works for x86? Or is it the usual "take apart the output of g++ and figure it out" that I usually wind up doing :-( ?From the LLVM docs [1]: A more complete description of the Itanium ABI exception handling runtime support of can be found at Itanium C++ ABI: Exception Handling [2]. A description of the exception frame format can be found at Exception Frames [3], with details of the DWARF 4 specification at DWARF 4 Standard [4]. A description for the C++ exception table formats can be found at Exception Handling Tables [5]. [1] http://llvm.org/docs/ExceptionHandling.html#itanium-abi-zero-cost-exception-handling [2] http://mentorembedded.github.com/cxx-abi/abi-eh.html [3] http://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html [4] http://dwarfstd.org/Dwarf4Std.php [5] http://mentorembedded.github.com/cxx-abi/exceptions.pdf -- /Jacob Carlborg
Sep 23 2014
On 9/23/2014 12:57 PM, Jacob Carlborg wrote:From the LLVM docs [1]:Thank you. This is helpful.
Sep 23 2014
On Tuesday, 23 September 2014 at 20:29:22 UTC, Walter Bright wrote:On 9/23/2014 12:57 PM, Jacob Carlborg wrote:Yes, that's quite a nice list already. As far as the C++ implementation details go, I posted the most interesting source files in the earlier discussion: http://forum.dlang.org/thread/lutf3c$2usj$1 digitalmars.com (the GCC ones can be found in the GCC release tarballs, the OS X Clang ones at http://llvm.org/svn/llvm-project/libcxxabi/trunk/src/). DavidFrom the LLVM docs [1]:Thank you. This is helpful.
Sep 23 2014
On 9/23/14, 2:07 PM, David Nadlinger wrote:On Tuesday, 23 September 2014 at 20:29:22 UTC, Walter Bright wrote:Speaking of which, what's the current story with gdc and ldc with regard to unwinding? Can they unwind properly when a C++ exception gets thrown? -- AndreiOn 9/23/2014 12:57 PM, Jacob Carlborg wrote:Yes, that's quite a nice list already. As far as the C++ implementation details go, I posted the most interesting source files in the earlier discussion: http://forum.dlang.org/thread/lutf3c$2usj$1 digitalmars.com (the GCC ones can be found in the GCC release tarballs, the OS X Clang ones at http://llvm.org/svn/llvm-project/libcxxabi/trunk/src/). DavidFrom the LLVM docs [1]:Thank you. This is helpful.
Sep 23 2014
On Tuesday, 23 September 2014 at 21:20:37 UTC, Andrei Alexandrescu wrote:Speaking of which, what's the current story with gdc and ldc with regard to unwinding? Can they unwind properly when a C++ exception gets thrown? -- AndreiCurrently, the LDC runtime just aborts, but that wouldn't be too hard to fix. David
Sep 23 2014
On 23 September 2014 22:20, Andrei Alexandrescu via Digitalmars-d <digitalmars-d puremagic.com> wrote:On 9/23/14, 2:07 PM, David Nadlinger wrote:GDC lets foreign exceptions pass through just fine. The only time when runtime terminates is when GDC has no choice *but* to handle a foreign exception it doesn't know about. By all means, you can have this kind of code: --- D: extern(C++) int Dfunction() { try { return CXXfunction(2); } catch { return 8; } } --- C++: int main() { try { return Dfunction(); } catch (int error) { return error; } } int CXXfunction(int i) { throw int(16); return i * 2; } And the runtime flow is: Phase 1. => __gdc_personality_v0 // Found nothing, continue unwinding. => __gxx_personality_v0 // Found something, cache details and continue unwind Phase 2. => __gdc_personality_v0 // Found nothing, continue unwinding. => __gxx_personality_v0 // Found something, finish unwinding. And we land back in C++ main, return 16. Iain.On Tuesday, 23 September 2014 at 20:29:22 UTC, Walter Bright wrote:Speaking of which, what's the current story with gdc and ldc with regard to unwinding? Can they unwind properly when a C++ exception gets thrown? -- AndreiOn 9/23/2014 12:57 PM, Jacob Carlborg wrote:Yes, that's quite a nice list already. As far as the C++ implementation details go, I posted the most interesting source files in the earlier discussion: http://forum.dlang.org/thread/lutf3c$2usj$1 digitalmars.com (the GCC ones can be found in the GCC release tarballs, the OS X Clang ones at http://llvm.org/svn/llvm-project/libcxxabi/trunk/src/). DavidFrom the LLVM docs [1]:Thank you. This is helpful.
Sep 23 2014
On 9/23/14, 3:14 PM, Iain Buclaw via Digitalmars-d wrote:GDC lets foreign exceptions pass through just fine.Proper unwinding of the D stack and all? -- Andrei
Sep 23 2014
On 23 September 2014 23:44, Andrei Alexandrescu via Digitalmars-d <digitalmars-d puremagic.com> wrote:On 9/23/14, 3:14 PM, Iain Buclaw via Digitalmars-d wrote:If you mean in the sense that libunwind will happily work it's way up, bouncing between D / C++ stacks until it finds a catch handler, then yes. Otherwise, please give an example. IainGDC lets foreign exceptions pass through just fine.Proper unwinding of the D stack and all? -- Andrei
Sep 24 2014
On 9/24/14, 5:06 AM, Iain Buclaw via Digitalmars-d wrote:On 23 September 2014 23:44, Andrei Alexandrescu via Digitalmars-d <digitalmars-d puremagic.com> wrote:Yah, that's what I meant. Thanks! -- AndreiOn 9/23/14, 3:14 PM, Iain Buclaw via Digitalmars-d wrote:If you mean in the sense that libunwind will happily work it's way up, bouncing between D / C++ stacks until it finds a catch handler, then yes.GDC lets foreign exceptions pass through just fine.Proper unwinding of the D stack and all? -- Andrei
Sep 24 2014
On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind? Andreihttps://github.com/deadalnix/libsdrt/blob/master/src/d/rt/eh.d
Sep 23 2014
On 23 September 2014 22:29, deadalnix via Digitalmars-d <digitalmars-d puremagic.com> wrote:On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:https://github.com/D-Programming-GDC/GDC/blob/master/libphobos/libdruntime/gcc/deh.d :o)We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind? Andreihttps://github.com/deadalnix/libsdrt/blob/master/src/d/rt/eh.d
Sep 23 2014
On 9/23/14, 3:15 PM, Iain Buclaw via Digitalmars-d wrote:On 23 September 2014 22:29, deadalnix via Digitalmars-d <digitalmars-d puremagic.com> wrote:Noice. How difficult would be to port this to dmd/Linux? This is big - we need to get it done, and soon. AndreiOn Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:https://github.com/D-Programming-GDC/GDC/blob/master/libphobos/libdruntime/gcc/deh.d :o)We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind? Andreihttps://github.com/deadalnix/libsdrt/blob/master/src/d/rt/eh.d
Sep 23 2014
On 9/23/2014 3:45 PM, Andrei Alexandrescu wrote:On 9/23/14, 3:15 PM, Iain Buclaw via Digitalmars-d wrote:There is a problem, that code is gpl licensed. It may not actually matter, since this code is only to interface with gpl libraries, but we should be careful.On 23 September 2014 22:29, deadalnix via Digitalmars-d <digitalmars-d puremagic.com> wrote:Noice. How difficult would be to port this to dmd/Linux? This is big - we need to get it done, and soon. AndreiOn Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:https://github.com/D-Programming-GDC/GDC/blob/master/libphobos/libdruntime/gcc/deh.d :o)We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind? Andreihttps://github.com/deadalnix/libsdrt/blob/master/src/d/rt/eh.d
Sep 23 2014
On 23 September 2014 23:56, Walter Bright via Digitalmars-d <digitalmars-d puremagic.com> wrote:On 9/23/2014 3:45 PM, Andrei Alexandrescu wrote:As well as the license, there's also two technical details that need to be addressed to fit with the features of dmd EH. 1) Exception chaining - still on my todo 2) OOM exceptions could be handled better. By all means, I'm happy with you to use it as a point of reference. What you'll find is that pretty much all GCC frontend personality routines are essentially identical, barring the of handling it's own exception object / data. Iain.On 9/23/14, 3:15 PM, Iain Buclaw via Digitalmars-d wrote:There is a problem, that code is gpl licensed. It may not actually matter, since this code is only to interface with gpl libraries, but we should be careful.On 23 September 2014 22:29, deadalnix via Digitalmars-d <digitalmars-d puremagic.com> wrote:Noice. How difficult would be to port this to dmd/Linux? This is big - we need to get it done, and soon. AndreiOn Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:https://github.com/D-Programming-GDC/GDC/blob/master/libphobos/libdruntime/gcc/deh.d :o)We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind? Andreihttps://github.com/deadalnix/libsdrt/blob/master/src/d/rt/eh.d
Sep 24 2014
On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind? AndreiIs there plans to catching C++ exceptions in D? What kind of C++ exceptions planned to catch in D? For example C++ can throw primitive types exceptions, for example int. Of cource, them can be wrapped into special D CPPException : Throwable, class, which contains string representation of C++ exception. What about C++ polymorthic exceptions? AFAIK, C++ exception are throwing by-value, and catching by ref (to allow polimorthic catch). Where C++ calls destructor for exception? In catch block? In D GC handles an exception lifetime. Is there any ideas about it? P.S. I tell about user-side of catching C++ exceptions, not about implementation.
Sep 24 2014
On 24 September 2014 12:27, IgorStepanov via Digitalmars-d <digitalmars-d puremagic.com> wrote:On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:I'd say no to such an idea.We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind? AndreiIs there plans to catching C++ exceptions in D?What kind of C++ exceptions planned to catch in D?NoneFor example C++ can throw primitive types exceptions, for example int. Of cource, them can be wrapped into special D CPPException : Throwable, class, which contains string representation of C++ exception. What about C++ polymorthic exceptions? AFAIK, C++ exception are throwing by-value, and catching by ref (to allow polimorthic catch). Where C++ calls destructor for exception? In catch block? In D GC handles an exception lifetime. Is there any ideas about it? P.S. I tell about user-side of catching C++ exceptions, not about implementation.Let C++ land catch the exception and deal with it. Iain.
Sep 24 2014
On 9/24/14, 5:12 AM, Iain Buclaw via Digitalmars-d wrote:On 24 September 2014 12:27, IgorStepanov via Digitalmars-d <digitalmars-d puremagic.com> wrote:I understand the difficulty of it. However, we should look into it closely. Preventing D code from catching C++ exceptions forces one to implement the driver/event loop/etc in C++, which is quite unpleasant. It essentially takes C++ compatibility a few good notches down.On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:I'd say no to such an idea.We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind? AndreiIs there plans to catching C++ exceptions in D?I wonder how difficult would be to create a wrapper class CppException for everything derived from C++ std::exception. It would not save the exact exception, but it would save its what() string and perhaps the typeid().name(). A translator would create CppException objects from std::exception objects and their derivatives. How hard would that be? Please advise.What kind of C++ exceptions planned to catch in D?NoneBelieve me, I hear you :o). I'm afraid we need to do something better about it. AndreiFor example C++ can throw primitive types exceptions, for example int. Of cource, them can be wrapped into special D CPPException : Throwable, class, which contains string representation of C++ exception. What about C++ polymorthic exceptions? AFAIK, C++ exception are throwing by-value, and catching by ref (to allow polimorthic catch). Where C++ calls destructor for exception? In catch block? In D GC handles an exception lifetime. Is there any ideas about it? P.S. I tell about user-side of catching C++ exceptions, not about implementation.Let C++ land catch the exception and deal with it.
Sep 24 2014
On Wednesday, 24 September 2014 at 15:07:05 UTC, Andrei Alexandrescu wrote:On 9/24/14, 5:12 AM, Iain Buclaw via Digitalmars-d wrote:If C++ code can execute D delegates, perhaps an intermediate step would be to create a wrapper in C++ that calls the delegate wrapped in an appropriate try/catch block. Syntax would be a bit weird as you'd have to specify a callback for each exception type you wanted to catch, but it seems doable.I understand the difficulty of it. However, we should look into it closely. Preventing D code from catching C++ exceptions forces one to implement the driver/event loop/etc in C++, which is quite unpleasant. It essentially takes C++ compatibility a few good notches down.Is there plans to catching C++ exceptions in D?I'd say no to such an idea.
Sep 24 2014
On 9/24/14, 9:05 AM, Sean Kelly wrote:On Wednesday, 24 September 2014 at 15:07:05 UTC, Andrei Alexandrescu wrote:That's a good idea, thanks. -- AndreiOn 9/24/14, 5:12 AM, Iain Buclaw via Digitalmars-d wrote:If C++ code can execute D delegates, perhaps an intermediate step would be to create a wrapper in C++ that calls the delegate wrapped in an appropriate try/catch block. Syntax would be a bit weird as you'd have to specify a callback for each exception type you wanted to catch, but it seems doable.I understand the difficulty of it. However, we should look into it closely. Preventing D code from catching C++ exceptions forces one to implement the driver/event loop/etc in C++, which is quite unpleasant. It essentially takes C++ compatibility a few good notches down.Is there plans to catching C++ exceptions in D?I'd say no to such an idea.
Sep 24 2014
On 24 September 2014 16:07, Andrei Alexandrescu via Digitalmars-d <digitalmars-d puremagic.com> wrote:On 9/24/14, 5:12 AM, Iain Buclaw via Digitalmars-d wrote:Thinking about it: - Identifying a C++ exception, simple. - Identifying whether a D catch handler for a C++ exception object matches, tricky - maybe. ABI of structs being a potential maintenance burden - though you'd hope that they only change ABI once every two years or so. Second, determining that the C++ object being thrown and catch handler we are examining match might be awkward from D. That is something that needs investigation. However, for sure, the easiest thing that could be done *now* that only needs a slight EH library tweak is using catch-all handlers to recover from any language exception. try { SomeCxxFuncThatMayThrow(); } catch { // Recover, but without knowing what happened. } But I'd imagine you'd actually want information to come with your caught exception, though. :) IainOn 24 September 2014 12:27, IgorStepanov via Digitalmars-d <digitalmars-d puremagic.com> wrote:I understand the difficulty of it. However, we should look into it closely. Preventing D code from catching C++ exceptions forces one to implement the driver/event loop/etc in C++, which is quite unpleasant. It essentially takes C++ compatibility a few good notches down.On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:I'd say no to such an idea.We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D. Is anyone fluent with libunwind? AndreiIs there plans to catching C++ exceptions in D?I wonder how difficult would be to create a wrapper class CppException for everything derived from C++ std::exception. It would not save the exact exception, but it would save its what() string and perhaps the typeid().name(). A translator would create CppException objects from std::exception objects and their derivatives. How hard would that be? Please advise.What kind of C++ exceptions planned to catch in D?None
Sep 24 2014
On 9/24/14, 9:54 AM, Iain Buclaw via Digitalmars-d wrote:On 24 September 2014 16:07, Andrei Alexandrescu via Digitalmars-d <digitalmars-d puremagic.com> wrote:Noice.I wonder how difficult would be to create a wrapper class CppException for everything derived from C++ std::exception. It would not save the exact exception, but it would save its what() string and perhaps the typeid().name(). A translator would create CppException objects from std::exception objects and their derivatives. How hard would that be? Please advise.Thinking about it: - Identifying a C++ exception, simple.- Identifying whether a D catch handler for a C++ exception object matches, tricky - maybe. ABI of structs being a potential maintenance burden - though you'd hope that they only change ABI once every two years or so. Second, determining that the C++ object being thrown and catch handler we are examining match might be awkward from D. That is something that needs investigation.Yah. I'm thinking of simplifying assumptions, e.g. all C++ exceptions map to one single D type called CppException, and we can assume there's always a D handler on top of the stack. All the CppException saves is a copy of the what() message from the C++ exception.However, for sure, the easiest thing that could be done *now* that only needs a slight EH library tweak is using catch-all handlers to recover from any language exception. try { SomeCxxFuncThatMayThrow(); } catch { // Recover, but without knowing what happened. } But I'd imagine you'd actually want information to come with your caught exception, though. :)Well even a catch like that would definitely be an improvement. Andrei
Sep 24 2014
On Wednesday, 24 September 2014 at 19:28:50 UTC, Andrei Alexandrescu wrote:Considered it for SDC. it is not that simple as if it is a C++ exception, you need to do the same cleanup of the exception that the C++ runtime would do, which is not that simple.However, for sure, the easiest thing that could be done *now* that only needs a slight EH library tweak is using catch-all handlers to recover from any language exception. try { SomeCxxFuncThatMayThrow(); } catch { // Recover, but without knowing what happened. } But I'd imagine you'd actually want information to come with your caught exception, though. :)Well even a catch like that would definitely be an improvement.
Sep 24 2014
On 24 September 2014 21:11, deadalnix via Digitalmars-d <digitalmars-d puremagic.com> wrote:On Wednesday, 24 September 2014 at 19:28:50 UTC, Andrei Alexandrescu wrote:Hmm... I forgot about the C++ compiler emitting function calls for the begin/end of catches. Yeah, that would indeed need to be supported on the compiler side!Considered it for SDC. it is not that simple as if it is a C++ exception, you need to do the same cleanup of the exception that the C++ runtime would do, which is not that simple.However, for sure, the easiest thing that could be done *now* that only needs a slight EH library tweak is using catch-all handlers to recover from any language exception. try { SomeCxxFuncThatMayThrow(); } catch { // Recover, but without knowing what happened. } But I'd imagine you'd actually want information to come with your caught exception, though. :)Well even a catch like that would definitely be an improvement.
Sep 24 2014
On Wednesday, 24 September 2014 at 19:28:50 UTC, Andrei Alexandrescu wrote:On 9/24/14, 9:54 AM, Iain Buclaw via Digitalmars-d wrote:I have one freaky example for you. This example can be non-standart and danger but it works: C++ side: http://pastebin.ru/PceYCOEq special function catch exception, pass it to specified handler and re-throw, if handler not found D side: http://pastebin.ru/7FNBzXHw D defines a special handler and pass it to catchException result: D code call C++ function void throwEx(void *) { throw 4; } and prints: dside.CPPException!int.CPPException (0): 4 Doesn't fire to me, please :)On 24 September 2014 16:07, Andrei Alexandrescu via Digitalmars-d <digitalmars-d puremagic.com> wrote:Noice.I wonder how difficult would be to create a wrapper class CppException for everything derived from C++ std::exception. It would not save the exact exception, but it would save its what() string and perhaps the typeid().name(). A translator would create CppException objects from std::exception objects and their derivatives. How hard would that be? Please advise.Thinking about it: - Identifying a C++ exception, simple.- Identifying whether a D catch handler for a C++ exception object matches, tricky - maybe. ABI of structs being a potential maintenance burden - though you'd hope that they only change ABI once every two years or so. Second, determining that the C++ object being thrown and catch handler we are examining match might be awkward from D. That is something that needs investigation.Yah. I'm thinking of simplifying assumptions, e.g. all C++ exceptions map to one single D type called CppException, and we can assume there's always a D handler on top of the stack. All the CppException saves is a copy of the what() message from the C++ exception.However, for sure, the easiest thing that could be done *now* that only needs a slight EH library tweak is using catch-all handlers to recover from any language exception. try { SomeCxxFuncThatMayThrow(); } catch { // Recover, but without knowing what happened. } But I'd imagine you'd actually want information to come with your caught exception, though. :)Well even a catch like that would definitely be an improvement. Andrei
Sep 24 2014
Now DMD doesn't support thorowing C++ exceptions through D function: extern(C++) void throwEx(); //compiled by G++ and throws exception extern(C++) void dFunc(void*) { throwEx(); } catchException(&dFunc, ...); //terminate programm instead of catch it. Should be works in gdc
Sep 24 2014
On 9/24/14, 2:53 PM, IgorStepanov wrote:I have one freaky example for you. This example can be non-standart and danger but it works: C++ side: http://pastebin.ru/PceYCOEq special function catch exception, pass it to specified handler and re-throw, if handler not found D side: http://pastebin.ru/7FNBzXHw D defines a special handler and pass it to catchException result: D code call C++ function void throwEx(void *) { throw 4; } and prints: dside.CPPException!int.CPPException (0): 4 Doesn't fire to me, please :)Awesome! How do we make it standard and safe? -- Andrei
Sep 24 2014
On Wednesday, 24 September 2014 at 22:14:5 UTC, Andrei Alexandrescu wrote:On 9/24/14, 2:53 PM, IgorStepanov wrote:C++ hasn't standart abi( If we talk about g++, this code has a one conspicuous trouble: I don't know, how to correctly get a pointer to exception. Class exception_ptr has getter for it, but it is private. I'll think about another variants. And I don't know about <cxxabi.h> standartness. The second trouble: if we want to do something more exception printing, we should get an exception pointer to user. However, user shouldn't copy this pointer, because exception object will be destroyed in cpp side. Good news: this code (D side) can be generated by D compiler: try { // C++ exceptions danger } catch(CPPException!int e) { } catch(CPPException!myException e) { } Of course, only exact match of exception will be works. No polymorphism.I have one freaky example for you. This example can be non-standart and danger but it works: C++ side: http://pastebin.ru/PceYCOEq special function catch exception, pass it to specified handler and re-throw, if handler not found D side: http://pastebin.ru/7FNBzXHw D defines a special handler and pass it to catchException result: D code call C++ function void throwEx(void *) { throw 4; } and prints: dside.CPPException!int.CPPException (0): 4 Doesn't fire to me, please :)Awesome! How do we make it standard and safe? -- Andrei
Sep 24 2014
On Wednesday, 24 September 2014 at 15:07:05 UTC, Andrei Alexandrescu wrote:I wonder how difficult would be to create a wrapper class CppException for everything derived from C++ std::exception.Why not catch std::exception directly? Then you could generate code, just like C++ compiler does it.
Sep 25 2014
On 9/25/14, 4:55 AM, Kagamin wrote:On Wednesday, 24 September 2014 at 15:07:05 UTC, Andrei Alexandrescu wrote:That would be a language change - right now D can only catch Exception objects. AndreiI wonder how difficult would be to create a wrapper class CppException for everything derived from C++ std::exception.Why not catch std::exception directly? Then you could generate code, just like C++ compiler does it.
Sep 25 2014
On Thursday, 25 September 2014 at 13:58:23 UTC, Andrei Alexandrescu wrote:That would be a language change - right now D can only catch Exception objects.Isn't the idea to let D do more things with C++ things?
Sep 25 2014
I mean, D's inability to interoperate with C++ is not a feature, but a problem meant to be solved as long as it doesn't take too much effort.
Sep 25 2014
On Thursday, 25 September 2014 at 13:58:23 UTC, Andrei Alexandrescu wrote:On 9/25/14, 4:55 AM, Kagamin wrote:I've implemented an experemental "framework" to catching C++ exceptions from D. https://github.com/IgorStepanov/D-CPP-Exception-Handle It works with G++, and depends on "unwind-cxx.h" header, which has been stealed from "libstdc++/libsupc++/". libsupc++ is a part of libstdc++ and this file can be found in libstdc++ sources. However, libstdc++ developers doesn't publish this header and it cannot be found in /usr/include/ This "framework" allows to call external C++ function and call exception, if good handler is passed. Also it can process polymorphic exceptions: in attached example I throws std::logic_exception and catches std::exception: //C++ #include <stdexcept> //test function void throwEx(void *) { throw std::logic_error("Catch me, if you can"); } //D extern(C++) void throwEx(void *); void main() { /* code like ... try { throwEx(null); } catch(std.exception val) { printf("exception: '%s'\n", val.what()); } may be rewritten as */ Try!(throwEx)( (CPPException!int ex) { printf("exception: '%d'\n", *ex.data); return 0; }, (CPPException!(stdexceptions.std.exception) ex) { printf("exception: '%s'\n", ex.data.what()); return 0; } ); } //prints: exception: 'Catch me, if you can' However, DMD can't pass С++ exceptions through D function (including extern(C++)). Thus, we cant pass delegate to Try function instead of throwEx, but this trouble can be resolved, I think.On Wednesday, 24 September 2014 at 15:07:05 UTC, Andrei Alexandrescu wrote:That would be a language change - right now D can only catch Exception objects. AndreiI wonder how difficult would be to create a wrapper class CppException for everything derived from C++ std::exception.Why not catch std::exception directly? Then you could generate code, just like C++ compiler does it.
Sep 26 2014
Congrat, that is some awesome work. I will certainly dig into this.
Sep 26 2014
On 2014-09-23 19:37, Andrei Alexandrescu wrote:We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D.BTW, are you only interested in handling C++ exception, or are you interested in handling D exceptions in C++ as well? One ugly hack is to register a terminate handler. Then in the handler extract the necessary information from the exception, create a D exception with this information and throw it as a regular D exception. Throwing a D exception that should be catchable in C++ is a bit more tricky. It's possible to wrap the a call to a D function in a try-catch block. Convert the D exception to a C++ exception, then throw it using a function part of the C++ exception runtime. The problem here is that C++ won't be able to catch this exception because there's no personality function (or similar) setup by the D compiler. Ideally D should just use the same exception mechanism as C++. I don't think a language change is necessary for this. Changes in the compiler, yes, but hopefully not in the language. -- /Jacob Carlborg
Sep 27 2014
On Saturday, 27 September 2014 at 09:53:37 UTC, Jacob Carlborg wrote:On 2014-09-23 19:37, Andrei Alexandrescu wrote:We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D.BTW, are you only interested in handling C++ exception, or are you interested in handling D exceptions in C++ as well?Ideally D should just use the same exception mechanism as C++. I don't think a language change is necessary for this. Changes in the compiler, yes, but hopefully not in the language.C++ exception mechanism uses C++ type_info objects. We can inherit object.Throwable from std::exception (through extern(C++) interface), override the what() method, but there are no way to generate C++ type_info for D class now. If we want to do a compiler support of C++ exceptions, we should implement and support another one non-standartized feature: type_info. BTW it allows to do dynamic_cast over C++ classes in D, but I think, nobody approve this suggestion, because it can be hard).
Sep 27 2014
On Saturday, 27 September 2014 at 11:34:32 UTC, IgorStepanov wrote:C++ exception mechanism uses C++ type_info objects. We can inherit object.Throwable from std::exception (through extern(C++) interface), override the what() method, but there are no way to generate C++ type_info for D class now. If we want to do a compiler support of C++ exceptions, we should implement and support another one non-standartized feature: type_info. BTW it allows to do dynamic_cast over C++ classes in D, but I think, nobody approve this suggestion, because it can be hard).Objective-C can do it somehow. If they can do it I'm sure we can as well. -- /Jacob Carlborg
Sep 27 2014
On Saturday, 27 September 2014 at 18:33:24 UTC, Jacob Carlborg wrote:On Saturday, 27 September 2014 at 11:34:32 UTC, IgorStepanov wrote:If someone from D commanders bless me, I can start to exploring and implementing std::type_info for D classes. If we made it, we will implement 50% of C++ exception handling.C++ exception mechanism uses C++ type_info objects. We can inherit object.Throwable from std::exception (through extern(C++) interface), override the what() method, but there are no way to generate C++ type_info for D class now. If we want to do a compiler support of C++ exceptions, we should implement and support another one non-standartized feature: type_info. BTW it allows to do dynamic_cast over C++ classes in D, but I think, nobody approve this suggestion, because it can be hard).Objective-C can do it somehow. If they can do it I'm sure we can as well. -- /Jacob Carlborg
Sep 27 2014
On 9/27/14, 12:53 PM, IgorStepanov wrote:On Saturday, 27 September 2014 at 18:33:24 UTC, Jacob Carlborg wrote:Would that be for throwing exceptions from D into C++? I think we can postpone that for now. -- AndreiOn Saturday, 27 September 2014 at 11:34:32 UTC, IgorStepanov wrote:If someone from D commanders bless me, I can start to exploring and implementing std::type_info for D classes. If we made it, we will implement 50% of C++ exception handling.C++ exception mechanism uses C++ type_info objects. We can inherit object.Throwable from std::exception (through extern(C++) interface), override the what() method, but there are no way to generate C++ type_info for D class now. If we want to do a compiler support of C++ exceptions, we should implement and support another one non-standartized feature: type_info. BTW it allows to do dynamic_cast over C++ classes in D, but I think, nobody approve this suggestion, because it can be hard).Objective-C can do it somehow. If they can do it I'm sure we can as well. -- /Jacob Carlborg
Sep 27 2014
On Saturday, 27 September 2014 at 20:18:42 UTC, Andrei Alexandrescu wrote:On 9/27/14, 12:53 PM, IgorStepanov wrote:No, that for throwing from C++ into D: for catch an exception, we should pass type_info object to special C++ runtime function. C++ runtime determines, can throwed object type can be casted to asked type, and if yes - allow catch it and do catcher code. If you will see the my example, you will see that I do this manually: get throwed type_info and compare its mangle with requested mangle. If we will make it as possible, it will be work better, faster and reliable. As bonus: possibility to implement dynamic_cast over C++ classes.On Saturday, 27 September 2014 at 18:33:24 UTC, Jacob Carlborg wrote:Would that be for throwing exceptions from D into C++? I think we can postpone that for now. -- AndreiOn Saturday, 27 September 2014 at 11:34:32 UTC, IgorStepanov wrote:If someone from D commanders bless me, I can start to exploring and implementing std::type_info for D classes. If we made it, we will implement 50% of C++ exception handling.C++ exception mechanism uses C++ type_info objects. We can inherit object.Throwable from std::exception (through extern(C++) interface), override the what() method, but there are no way to generate C++ type_info for D class now. If we want to do a compiler support of C++ exceptions, we should implement and support another one non-standartized feature: type_info. BTW it allows to do dynamic_cast over C++ classes in D, but I think, nobody approve this suggestion, because it can be hard).Objective-C can do it somehow. If they can do it I'm sure we can as well. -- /Jacob Carlborg
Sep 27 2014
On 9/27/14, 1:31 PM, IgorStepanov wrote:No, that for throwing from C++ into D: for catch an exception, we should pass type_info object to special C++ runtime function. C++ runtime determines, can throwed object type can be casted to asked type, and if yes - allow catch it and do catcher code. If you will see the my example, you will see that I do this manually: get throwed type_info and compare its mangle with requested mangle. If we will make it as possible, it will be work better, faster and reliable. As bonus: possibility to implement dynamic_cast over C++ classes.If that's what's needed, definitely please do explore it! But I defer expertise to Walter. -- Andrei
Sep 27 2014
On Saturday, 27 September 2014 at 23:31:17 UTC, Andrei Alexandrescu wrote:On 9/27/14, 1:31 PM, IgorStepanov wrote:Ok. Anyway, I can't work on this to the full extent, because I have a three D works (six pull requests), which are waiting for action from the D collaborators (UDA for modules PR reviewed and is waiting for approval, multiple alias this and new AA implementation are waiting for review). However, I've seen this direction and I want to report a few points: 1. C++ type_info/TypeHandle for classes is located on -1 index of vtbl; 2. type_info layout aren't standartized (as expected) and differs in G++, VS and (probably) DMC and SunC. 3. type_info in C++ uses in many different cases, like dynamic_cast and excetion handling. 4. D doensn't generate type_info and it can cause danger situation. e.g. ************************************ //C++ code class CppBase { public: virtual void test() = 0; }; class CppDerived : public CppBase { public: void test(); }; void CppDerived::test() { std::cout << "CppDerived::test()" << std::endl; } void doTest(CppBase *obj) { obj->test(); CppDerived *dobj = dynamic_cast<CppDerived *>(obj); //Attention! if (dobj) { std::cout << "casted" << std::endl; } else { std::cout << "fail" << std::endl; } } //D code extern(C++) interface CppBase { void test(); } class DDerived : CppBase { extern(C++) override void test() { writeln("DDerived.test()"); } } extern(C++) void doTest(CppBase); void main() { writeln("start test"); doTest(new DDerived()); //BOOM! segfault while processing dynamic_cast, because DDerived type_info is wrong. writeln("finish test"); } ************************************ //Now my suggestions: 1. We can implement type_info generation as library template like GenTypeInfo(T). It will return valid type_info object for supproted platforms and null for platforms, which isn't supported yet. 2. Compiler will use this template to get type_info and push it into vtbl (at -1 position) 3. In situation, when compile need to use type_info (may be try-catch with C++ exceptions or dynamic_cast, it will be raise error if type_info isn't implemented) This approach allows to move complex, platform-depended code from compiler to library. Also it allows to don't implement some platforms without user restrictions. In conclusion: this is a g++ type_info definitions: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/cxxabi.h#L535 This has a flag "__diamond_shaped_mask" in __vmi_class_type_info, and "__virtual_mask" in __base_class_type_info. D allows multiply inheritance for interfaces. In mapping to C++: Is this inheritance virtual? Should we set __diamond_shaped_mask is A: B, C; B : D; C : D (B, C, D is interfaces)?No, that for throwing from C++ into D: for catch an exception, we should pass type_info object to special C++ runtime function. C++ runtime determines, can throwed object type can be casted to asked type, and if yes - allow catch it and do catcher code. If you will see the my example, you will see that I do this manually: get throwed type_info and compare its mangle with requested mangle. If we will make it as possible, it will be work better, faster and reliable. As bonus: possibility to implement dynamic_cast over C++ classes.If that's what's needed, definitely please do explore it! But I defer expertise to Walter. -- Andrei
Sep 28 2014
On 2014-09-27 21:53, IgorStepanov wrote:If someone from D commanders bless me, I can start to exploring and implementing std::type_info for D classes. If we made it, we will implement 50% of C++ exception handling.Objective-C seems to use a struct made of a vtable, the class name and the Objective-C class as the type_info. -- /Jacob Carlborg
Sep 28 2014
On 9/27/14, 2:53 AM, Jacob Carlborg wrote:On 2014-09-23 19:37, Andrei Alexandrescu wrote:The more the merrier, but there's a large difference in importance. For the most part D code (new) will call into C++ code (old) so it's the C++ exceptions we're most worried about. -- AndreiWe need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D.BTW, are you only interested in handling C++ exception, or are you interested in handling D exceptions in C++ as well?
Sep 27 2014
On Saturday, 27 September 2014 at 19:16:24 UTC, Andrei Alexandrescu wrote:On 9/27/14, 2:53 AM, Jacob Carlborg wrote:Can someone implement an C++ exception transparency? (when exception, throwed from C++ can be passed through D function and landed down in C++ code). Then, if type_info is implemented, I will able to try to implement C++ exception catching.On 2014-09-23 19:37, Andrei Alexandrescu wrote:The more the merrier, but there's a large difference in importance. For the most part D code (new) will call into C++ code (old) so it's the C++ exceptions we're most worried about. -- AndreiWe need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D.BTW, are you only interested in handling C++ exception, or are you interested in handling D exceptions in C++ as well?
Sep 27 2014
On 27 September 2014 10:53, Jacob Carlborg via Digitalmars-d <digitalmars-d puremagic.com> wrote:On 2014-09-23 19:37, Andrei Alexandrescu wrote:Well, ObjC++ shares the same EH personality routines as C++, which probably accounts for the compatibility. :) Iain.We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D.BTW, are you only interested in handling C++ exception, or are you interested in handling D exceptions in C++ as well? One ugly hack is to register a terminate handler. Then in the handler extract the necessary information from the exception, create a D exception with this information and throw it as a regular D exception. Throwing a D exception that should be catchable in C++ is a bit more tricky. It's possible to wrap the a call to a D function in a try-catch block. Convert the D exception to a C++ exception, then throw it using a function part of the C++ exception runtime. The problem here is that C++ won't be able to catch this exception because there's no personality function (or similar) setup by the D compiler. Ideally D should just use the same exception mechanism as C++. I don't think a language change is necessary for this. Changes in the compiler, yes, but hopefully not in the language.
Sep 27 2014
On Saturday, 27 September 2014 at 20:11:34 UTC, Iain Buclaw via Digitalmars-d wrote:On 27 September 2014 10:53, Jacob Carlborg via Digitalmars-d <digitalmars-d puremagic.com> wrote:Is this way acceptable for D, or not. Why?On 2014-09-23 19:37, Andrei Alexandrescu wrote:Well, ObjC++ shares the same EH personality routines as C++, which probably accounts for the compatibility. :) Iain.We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D.BTW, are you only interested in handling C++ exception, or are you interested in handling D exceptions in C++ as well? One ugly hack is to register a terminate handler. Then in the handler extract the necessary information from the exception, create a D exception with this information and throw it as a regular D exception. Throwing a D exception that should be catchable in C++ is a bit more tricky. It's possible to wrap the a call to a D function in a try-catch block. Convert the D exception to a C++ exception, then throw it using a function part of the C++ exception runtime. The problem here is that C++ won't be able to catch this exception because there's no personality function (or similar) setup by the D compiler. Ideally D should just use the same exception mechanism as C++. I don't think a language change is necessary for this. Changes in the compiler, yes, but hopefully not in the language.
Sep 27 2014
On 27 Sep 2014 21:35, "IgorStepanov via Digitalmars-d" < digitalmars-d puremagic.com> wrote:On Saturday, 27 September 2014 at 20:11:34 UTC, Iain Buclaw viaDigitalmars-d wrote:exceptionOn 27 September 2014 10:53, Jacob Carlborg via Digitalmars-d <digitalmars-d puremagic.com> wrote:On 2014-09-23 19:37, Andrei Alexandrescu wrote:We need a libunwind expert to figure out a good approach for handling exceptions thrown by C++ code into D.BTW, are you only interested in handling C++ exception, or are you interested in handling D exceptions in C++ as well? One ugly hack is to register a terminate handler. Then in the handler extract the necessary information from the exception, create a Dtricky.with this information and throw it as a regular D exception. Throwing a D exception that should be catchable in C++ is a bit morefunctionIt's possible to wrap the a call to a D function in a try-catch block. Convert the D exception to a C++ exception, then throw it using athinkpart of the C++ exception runtime. The problem here is that C++ won't be able to catch this exception because there's no personality function (or similar) setup by the D compiler. Ideally D should just use the same exception mechanism as C++. I don'tbuta language change is necessary for this. Changes in the compiler, yes,In the EH routines, we should be able to make do with a generic CppException and pass it back to a D catch. What won't work too well is catching a specific C++ exception. Iain.Is this way acceptable for D, or not. Why?hopefully not in the language.Well, ObjC++ shares the same EH personality routines as C++, which probably accounts for the compatibility. :) Iain.
Sep 27 2014