digitalmars.D.learn - setjmp / longjmp
- Cassio Butrico (6/6) Apr 25 2015 Hello everyone , first congratulations for the wonderful forum ,
- ketmar (12/19) Apr 25 2015 you shouldn't use setjmp/longjmp in D. use exceptions instead. something...
- Cassio Butrico (3/26) Apr 26 2015 Thank you for answering me ketmar
-
Stewart Gordon
(16/18)
Apr 26 2015
- Cassio Butrico (3/3) Apr 26 2015 I'm just building a small interpreter with a script and wanted to
- ketmar (3/12) Apr 27 2015 i believe this has something to do with exception frames. but it needs=2...
- Stewart Gordon (9/11) Jun 09 2015 What is an exception frame, exactly?
- ketmar (16/24) Jun 09 2015 to correctly do unwinding and other interesting things exception handler...
Hello everyone , first congratulations for the wonderful forum , I wish someone could help me , I am writing a small basic interpreter in D and I am with some difficulties. estoutentando manupular the setjmp / longjmp buffers , but the error , I use windows 7 and the dmd 2067 , will be whose manipulate the buffers save and return ? Excuse my english sucks.
Apr 25 2015
On Sat, 25 Apr 2015 23:25:13 +0000, Cassio Butrico wrote:Hello everyone , first congratulations for the wonderful forum , I wish someone could help me , I am writing a small basic interpreter in D and I am with some difficulties. =20 estoutentando manupular the setjmp / longjmp buffers , but the error , I use windows 7 and the dmd 2067 , will be whose manipulate the buffers save and return ? Excuse my english sucks.you shouldn't use setjmp/longjmp in D. use exceptions instead. something=20 like this: instead of setjmp: try { doit } catch (MyException e) { process e } and instead of longjmp: throw new MyException(); =
Apr 25 2015
On Sunday, 26 April 2015 at 05:56:46 UTC, ketmar wrote:On Sat, 25 Apr 2015 23:25:13 +0000, Cassio Butrico wrote:Thank you for answering me ketmar I will try thisHello everyone , first congratulations for the wonderful forum , I wish someone could help me , I am writing a small basic interpreter in D and I am with some difficulties. estoutentando manupular the setjmp / longjmp buffers , but the error , I use windows 7 and the dmd 2067 , will be whose manipulate the buffers save and return ? Excuse my english sucks.you shouldn't use setjmp/longjmp in D. use exceptions instead. something like this: instead of setjmp: try { doit } catch (MyException e) { process e } and instead of longjmp: throw new MyException();
Apr 26 2015
On 26/04/2015 06:56, ketmar wrote: <snip>you shouldn't use setjmp/longjmp in D. use exceptions instead. something like this:<snip> True in the general case. Still, there must be some reason that trying it in D causes an AV (even if I disable the GC). I remain curious about what that reason is. Some time ago, just for fun, I wrote an Unlambda to D compiler. Except that I couldn't get the c builtin to work properly. Exceptions cover typical uses cases, but a subtlety of it is that (roughly speaking) the continuation it emits can escape from the function it is passed into, and then when the continuation is later invoked it should return the program to the point at which c was invoked. Essentially, it can wind the stack as well as unwinding it. I envisaged that, maybe with the aid of setjmp and some trick to get GC to work with it, it could be made to work. Stewart. -- My email address is valid but not my primary mailbox and not checked regularly. Please keep replies on the 'group where everybody may benefit.
Apr 26 2015
I'm just building a small interpreter with a script and wanted to handle errors diverting the flow and returning . I am grateful for having responded my question , thank you.
Apr 26 2015
On Sun, 26 Apr 2015 21:45:41 +0100, Stewart Gordon wrote:On 26/04/2015 06:56, ketmar wrote: <snip>i believe this has something to do with exception frames. but it needs=20 further investigation.=you shouldn't use setjmp/longjmp in D. use exceptions instead. something like this:<snip> =20 True in the general case. Still, there must be some reason that trying it in D causes an AV (even if I disable the GC). I remain curious about what that reason is.
Apr 27 2015
On 27/04/2015 10:41, ketmar wrote: <snip>i believe this has something to do with exception frames. but it needs further investigation.What is an exception frame, exactly? Moreover, are these frames applicable even in sections of code where no throwing or catching of exceptions takes place? Stewart. -- My email address is valid but not my primary mailbox and not checked regularly. Please keep replies on the 'group where everybody may benefit.
Jun 09 2015
On Tue, 09 Jun 2015 11:57:03 +0100, Stewart Gordon wrote:On 27/04/2015 10:41, ketmar wrote: <snip>to correctly do unwinding and other interesting things exception handler=20 should do, compiler must establish special hidden structures in the form=20 of single-linked list, so runtime can traverse it backwards if it needs=20 to unwind the stack (i.e. calling destructors for structs, for example).i believe this has something to do with exception frames. but it needs further investigation.=20 What is an exception frame, exactly?Moreover, are these frames applicable even in sections of code where no throwing or catching of exceptions takes place?exception can be thrown by function that is called from your code.=20 compiler needs to setup structures to correctly "unwind" the stack in=20 this case. if nothing will throw, that setup cost as almost zero and can=20 be ignored. but playing games with stack can lead to corruption of such=20 structures (runtime doesn't know that stack was changed, and it can't=20 update it's internal data structures accordingly). this may be harmless,=20 or may lead to crash, or may lead to memory corruption without immediate=20 crashing, or... effects are unpredictable. tldr; don't use setjmp/longjmp in the language with exceptions, unless=20 you can describe it's runtime internals and exception handling down to=20 assembler code when you're awaken at night completely drunk. ;-)=
Jun 09 2015