News for hackers. Stuff that matters.
Re:In the C++ bag of tricks: scoped locks by dllthomas on Friday February 07, 2014 @12:33PM (#7197485)
You can do some of this with the cleanup attribute in GCC, although it doesn't trigger in the case of a longjmp.
Re:In the C++ bag of tricks: scoped locks by khc on Friday February 07, 2014 @12:47PM (#7197575)
if you can rely on gcc, cleanup attribute is probably the best you can do. The solution in original post doesn't cope with "break", "continue", "return" (and of course, "goto", but I don't remember if cleanup attribute handles that either).

Looks like their project already uses C++ though, so why don't they just use C++ for this is beyond me.

Re:In the C++ bag of tricks: scoped locks by dllthomas on Friday February 07, 2014 @12:49PM (#7197583)
Agreed.
Re:In the C++ bag of tricks: scoped locks by dllthomas on Friday February 07, 2014 @03:24PM (#7198497)
Actually, it looks like C++ destructors don't run on longjmp either, though that's less of an issue since C++ actually has real exceptions.
Re:In the C++ bag of tricks: scoped locks by mpyne on Friday February 07, 2014 @05:20PM (#7199153)
longjmp is what the library and standards writers refer to as a "non-local goto" so it's kind of to be expected that it would manage to bypass destructors (I'm not sure how you'd unwind the stack enough to ensure that you've destructed everything created since the corresponding setjmp).
Re:In the C++ bag of tricks: scoped locks by dllthomas on Friday February 07, 2014 @05:41PM (#7199256)
It's not terribly surprising, but it is worth noting since one use of setjmp/longjmp is to implement exceptions, and one would expect (and desire) destructors to run when unwinding on exceptions.