Thread overview | |||||
---|---|---|---|---|---|
|
March 08, 2007 try block portability? | ||||
---|---|---|---|---|
| ||||
i've seen reactos hacker suffer from PSEH thingie. and they use a macro to implement PSEH try block. the PSEH try block would looks like _PSEH_TRY { .... } _PSEH_EXCEPT { ... } _PSEH_END this is a good idea since all try block code implemented in C. and it's more portable than try { } except { } but it's very difficult to ensure it's correct. and also the binary generated is dummy and low efficient, cause the idea of it is implemented roughly as following for(;;) { if not firsttimevisit { ... try code break; } else { if (setjmp(label1)) label1: { ... finally code } else { continue; } } } any idea of meta-programming of implementing this try block stuff? or need some compiler support? and binding try block binary with compiler is really ain't a good idea, compiler needs to support linux version, windows version. |
March 08, 2007 Re: try block portability? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Davidl | On Thu, 08 Mar 2007 15:17:45 +0800, Davidl@126.com wrote: > i've seen reactos hacker suffer from PSEH thingie. > and they use a macro to implement PSEH try block. > the PSEH try block would looks like Huh? Can somebody translate that into English for me? > _PSEH_TRY > { > .... > } > _PSEH_EXCEPT > { > ... > } > _PSEH_END > > this is a good idea since all try block code implemented > in C. and it's more portable than > try > { > } > except > { > } What is wrong with ... try { ... some code ... } catch { ... oops! something went wrong, so handle it. ... } finally { ... All is well, so deal with that ... } How does this not suit your needs? Or is the 'scope' syntax better for you? { ... some code ... scope(failure) {... oops! something went wrong, so handle it. ...} scope(success) {... All is well, so deal with that ...} } -- Derek (skype: derek.j.parnell) Melbourne, Australia "Justice for David Hicks!" 8/03/2007 6:22:15 PM |
March 08, 2007 Re: try block portability? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Davidl | Davidl@126.com wrote:
>
> i've seen reactos hacker suffer from PSEH thingie.
> and they use a macro to implement PSEH try block.
> the PSEH try block would looks like
> _PSEH_TRY
> {
> .....
> }
> _PSEH_EXCEPT
> {
> ....
> }
> _PSEH_END
>
> this is a good idea since all try block code implemented
> in C. and it's more portable than
> try
> {
> }
> except
> {
> }
>
> but it's very difficult to ensure it's correct. and also the
> binary generated is dummy and low efficient, cause the idea
> of it is implemented roughly as following
>
> for(;;)
> {
> if not firsttimevisit
> {
> ... try code
> break;
> }
> else
> {
> if (setjmp(label1))
> label1:
> {
> ... finally code
> }
> else
> {
> continue;
> }
> }
> }
>
> any idea of meta-programming of implementing this try block
> stuff? or need some compiler support?
This could probably be sorted out with some clever programming, but I'm not sure it's a good idea. Depending on the platform, longjmp may or may not execute dtors and such as it moves its way up the stack. If it doesn't, the app could leak resources. If it does, you're doing the same thing as normal exception handling and gain nothing. If performance is really a concern, it might be worth investigating the exception handing mechanism itself and see if that can be optimized. Win32 uses SEH, and I think Win64 uses some new method. And exception handling in Unix is largely hand-coded into phobos (see internal/deh.d).
Sean
|
Copyright © 1999-2021 by the D Language Foundation