kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #19017
Re: APP_SINGLE_TOP in 5834
Okay, I had a look at this. I don't see the potential for a problem,
though I think I see the initial cause for concern.
Placing OnPgmExit() in OnRun instead of OnInit ensures that it won't be
called twice if OnInit fails.
However, here is a pseudocode simplification of the wx entry point -
this calls OnInit, OnRun, and OnExit:
try {
if( !OnInit() ) return 1;
ON_OUT_OF_SCOPE {
OnExit();
}
return OnRun();
}
catch(all) {
OnUnhandledException();
return -1;
}
If OnInit throws an exception, OnExit has not been registered yet, so it
will not run. This solves the problem nicely - an unexpected bit of
"works correctly in every case" elegance from wx...
To test this theory, I inserted a "throw 1;" into OnInit, outside its
built-in exception handling, and traced through the function calls. Here
are the interesting bits of the trace:
- wxEntryReal: main TRY block (wx source: common/init.cpp line 473)
-- APP_SINGLE_TOP::OnInit
--- throw 1;
- wxEntryReal: main CATCH block (wx source: common/init.cpp line 497)
-- wxAppConsoleBase::OnUnhandledException (wx source: common/appbase.cpp line 629)
--- Detect exception type, print to console:
*** Caught unhandled unknown exception; terminating
Neither OnExit nor OnRun is ever called, so the code in these methods
has absolutely no effect.
The alternate case is when the exception occurs _in_ the kicad-supplied
exception handling inside OnInit(). The behavior in this case is the
same, with the single difference that OnUnhandledException is never
called, because "return 1" in wxEntryReal skips registering the OnExit
handler the same way that an exception does.
--
Chris
On Mon, Jun 29, 2015 at 07:23:24AM -0400, Wayne Stambaugh wrote:
> I didn't see why either but I also did not test it to confirm. If you
> have the time to confirm, I would appreciate it.
>
> On 6/28/2015 11:48 PM, Chris Pavlina wrote:
> > Interesting. I don't see why - perhaps I'll have a look at that tomorrow.
> >
> > On Sun, Jun 28, 2015 at 07:27:40PM -0400, Wayne Stambaugh wrote:
> >> The author of this code informed me that there may be some issues if an
> >> exception occurs during APP_SINGLE_TOP initialization. I did not
> >> confirm this but I suspect that he may be correct. That is why I
> >> conditionally compiled them for the time being until it can be confirmed.
> >>
> >> On 6/28/2015 4:22 PM, Chris Pavlina wrote:
> >>> Hi,
> >>>
> >>> Just curious here - what was the reason behind the change made in
> >>> single_top.cpp in revision 5834?
> >>>
> >>> http://bazaar.launchpad.net/~kicad-product-committers/kicad/product/revision/5834
> >>>
> >>> I had moved Pgm().OnPgmExit() into OnExit() to correct a segfault on
> >>> quit - why move it back to OnRun() for non-Python builds? Surely OnExit
> >>> is the right place for exit code in all cases?
> >>>
> >>> --
> >>> Chris
> >>>
> >>> _______________________________________________
> >>> Mailing list: https://launchpad.net/~kicad-developers
> >>> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> >>> Unsubscribe : https://launchpad.net/~kicad-developers
> >>> More help : https://help.launchpad.net/ListHelp
> >>>
> >>
> >>
> >> _______________________________________________
> >> Mailing list: https://launchpad.net/~kicad-developers
> >> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> >> Unsubscribe : https://launchpad.net/~kicad-developers
> >> More help : https://help.launchpad.net/ListHelp
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~kicad-developers
> > Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~kicad-developers
> > More help : https://help.launchpad.net/ListHelp
> >
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help : https://help.launchpad.net/ListHelp
References