From 051db368f144029dece826b1449f86c8bda6dd95 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 30 Jun 2005 21:18:38 +0000 Subject: [PATCH] fixed crash from breaking mred too early svn: r285 --- src/mred/mred.cxx | 51 +++++++++++++++++----------------------- src/mred/mrmain.cxx | 9 ++++++- src/mzscheme/cmdline.inc | 23 +++++++++++++++--- 3 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/mred/mred.cxx b/src/mred/mred.cxx index 870d6505b9..151d6276d4 100644 --- a/src/mred/mred.cxx +++ b/src/mred/mred.cxx @@ -3766,35 +3766,16 @@ static unsigned long get_deeper_base() /****************************************************************************/ #if defined(wx_mac) || defined(wx_msw) -void wxDrop_Runtime(char **argv, int argc) -{ - int i; - mz_jmp_buf *save, newbuf; - - save = scheme_current_thread->error_buf; - scheme_current_thread->error_buf = &newbuf; - - if (scheme_setjmp(newbuf)) { - /* give up on rest */ - scheme_clear_escape(); - } else { - for (i = 0; i < argc; i++) { - Scheme_Object *p[1]; - p[0] = scheme_make_path(argv[i]); - scheme_apply(wxs_app_file_proc, 1, p); - } - } - - scheme_current_thread->error_buf = save; -} -#endif - -#if defined(wx_mac) || defined(wx_msw) -static void wxDo(Scheme_Object *proc) +static void wxDo(Scheme_Object *proc, int argc, Scheme_Object **argv) { mz_jmp_buf * volatile save, newbuf; volatile int block_descriptor; + if (!proc) { + /* Oops --- too early. */ + return; + } + /* wxDo might be called when MrEd is sleeping (i.e., blocked on WNE in OS X). Since we're hijacking the thread, save an restore block information. */ @@ -3809,7 +3790,7 @@ static void wxDo(Scheme_Object *proc) if (scheme_setjmp(newbuf)) { scheme_clear_escape(); } else { - scheme_apply(proc, 0, NULL); + scheme_apply(proc, argc, argv); } scheme_current_thread->error_buf = save; @@ -3818,6 +3799,18 @@ static void wxDo(Scheme_Object *proc) scheme_end_atomic_no_swap(); } +#if defined(wx_mac) || defined(wx_msw) +void wxDrop_Runtime(char **argv, int argc) +{ + int i; + + for (i = 0; i < argc; i++) { + Scheme_Object *p[1]; + wxDo(wxs_app_file_proc, 1, p); + } +} +#endif + void wxDrop_Quit() { if (ioFrame) { @@ -3825,20 +3818,20 @@ void wxDrop_Quit() ioFrame->Show(FALSE); } - wxDo(wxs_app_quit_proc); + wxDo(wxs_app_quit_proc, 0, NULL); } #endif #ifdef wx_mac void wxDo_About() { - wxDo(wxs_app_about_proc); + wxDo(wxs_app_about_proc, 0, NULL); } void wxDo_Pref() { if (!SCHEME_FALSEP(wxs_app_pref_proc)) - wxDo(wxs_app_pref_proc); + wxDo(wxs_app_pref_proc, 0, NULL); } int wxCan_Do_Pref() diff --git a/src/mred/mrmain.cxx b/src/mred/mrmain.cxx index ea0b45d25f..b4727b3b12 100644 --- a/src/mred/mrmain.cxx +++ b/src/mred/mrmain.cxx @@ -226,7 +226,14 @@ static int do_main_loop(FinishArgs *fa) } #endif - wxDoMainLoop(); + { + mz_jmp_buf * volatile save, newbuf; + save = scheme_current_thread->error_buf; + scheme_current_thread->error_buf = &newbuf; + if (!scheme_setjmp(newbuf)) + wxDoMainLoop(); + scheme_current_thread->error_buf = save; + } return 0; } diff --git a/src/mzscheme/cmdline.inc b/src/mzscheme/cmdline.inc index 7bfef43970..9186b8d9d7 100644 --- a/src/mzscheme/cmdline.inc +++ b/src/mzscheme/cmdline.inc @@ -303,14 +303,31 @@ static int finish_cmd_line_run(FinishArgs *fa, Repl_Proc repl) #ifndef DONT_RUN_REP if (!fa->no_rep && !fa->script_mode) { /* enter read-eval-print loop */ - repl(fa->global_env); - exit_val = 0; + mz_jmp_buf * volatile save, newbuf; + save = scheme_current_thread->error_buf; + scheme_current_thread->error_buf = &newbuf; + if (!scheme_setjmp(newbuf)) { + repl(fa->global_env); + exit_val = 0; + } else { + exit_val = 1; +#ifdef VERSION_YIELD_FLAG + fa->add_yield = 0; +#endif + } + scheme_current_thread->error_buf = save; } #endif /* DONT_RUN_REP */ #ifdef VERSION_YIELD_FLAG if (fa->add_yield) { - yield_indefinitely(); + mz_jmp_buf * volatile save, newbuf; + save = scheme_current_thread->error_buf; + scheme_current_thread->error_buf = &newbuf; + if (!scheme_setjmp(newbuf)) { + yield_indefinitely(); + } + scheme_current_thread->error_buf = save; } #endif