From 2c546c5c620f36d92ac7b9628caf54f1bc4d5dba Mon Sep 17 00:00:00 2001 From: Rui Peng Li Date: Wed, 27 Mar 2024 21:47:09 -0700 Subject: [PATCH] bug fix --- bbb/exmain.c | 117 +++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/bbb/exmain.c b/bbb/exmain.c index 6828f483..df2f88a5 100755 --- a/bbb/exmain.c +++ b/bbb/exmain.c @@ -27,7 +27,7 @@ static struct sigaction act,oact; static sigjmp_buf ev; -/* +/* Handler for SIGINT signal */ void int_handler() { @@ -36,59 +36,58 @@ void int_handler() { printf("\nType \"cont\" to continue exmain(), \"abort\" (not compatible with openmp) or \"stop\" (with openmp) to return to Python prompt \n"); printf("or a single line to be evaluated by Python.\n"); #pragma omp master - { -int condition; -condition=1; - while(1){ + { + int condition; + condition=1; + while(1){ #ifdef HAS_READLINE - ret = readline("Debug>>> "); - if(ret == (char *)NULL)return; - add_history(ret); - strncpy(mymyline,ret,sizeof(mymyline)-1); - free(ret); + ret = readline("Debug>>> "); + if(ret == (char *)NULL) break; + add_history(ret); + strncpy(mymyline,ret,sizeof(mymyline)-1); + free(ret); #else - printf("Debug>>> "); - ret = fgets(mymyline,150,stdin); - if(ret == (char *)NULL)return; + printf("Debug>>> "); + ret = fgets(mymyline,150,stdin); + if(ret == (char *)NULL)break; #endif - if(strncmp(mymyline,"cont",4) == 0){ - return; - } else if (strncmp(mymyline,"abort",5) == 0) { - PyRun_SimpleString("bbb.exmain_aborted = True"); - siglongjmp(ev,1); - } else if (strncmp(mymyline,"stop",4) == 0) { - PyRun_SimpleString("print(\"Stopping exmain ... Please wait...\")"); - PyRun_SimpleString("bbb.exmain_aborted = True"); - return; - } else if (strncmp(mymyline,"exit",4) == 0) { - PyRun_SimpleString("bbb.exmain_aborted = True"); - siglongjmp(ev,1); - } else { - PyRun_SimpleString(mymyline); - /* matplotlib seems to unset the hander - so it is set again just in case */ - sigfillset(&block_mask); - act.sa_handler = int_handler; - act.sa_mask = block_mask; - act.sa_flags = 0; - sigaction(SIGINT,&act,NULL); - } + if(strncmp(mymyline,"cont",4) == 0){ + break; + } else if (strncmp(mymyline,"abort",5) == 0) { + PyRun_SimpleString("bbb.exmain_aborted = True"); + siglongjmp(ev,1); + } else if (strncmp(mymyline,"stop",4) == 0) { + PyRun_SimpleString("print(\"Stopping exmain ... Please wait...\")"); + PyRun_SimpleString("bbb.exmain_aborted = True"); + break; + } else if (strncmp(mymyline,"exit",4) == 0) { + PyRun_SimpleString("bbb.exmain_aborted = True"); + siglongjmp(ev,1); + } else { + PyRun_SimpleString(mymyline); + /* matplotlib seems to unset the hander + so it is set again just in case */ + sigfillset(&block_mask); + act.sa_handler = int_handler; + act.sa_mask = block_mask; + act.sa_flags = 0; + sigaction(SIGINT,&act,NULL); + } + } } - -} } #endif -/* FORTHON is defined by the Python build. This exmain does nothing when +/* FORTHON is defined by the Python build. This exmain does nothing when compiled for the basis version of the code, it just drops through to the Fortran routine. */ #if defined(FC_FUNC) -void FC_FUNC(exmain_f, EXMAIN_F)(void); +void FC_FUNC(exmain_f, EXMAIN_F)(void); #else -void exmain_f_(void); +void exmain_f_(void); #endif #if defined(FC_FUNC) @@ -99,40 +98,40 @@ void exmain_() { #ifdef FORTHON sigset_t block_mask; int ival; + int err = 0; #pragma omp master -{ - ival = sigsetjmp(ev,1); - if(ival != 0){ - sigaction(SIGINT,&oact,NULL); - return; - } + { + ival = sigsetjmp(ev,1); + if(ival != 0) { + sigaction(SIGINT,&oact,NULL); + err = 1; + } } - + + if (err) { return; } /* setup to catch SIGINT and save the previous handler to be restored on return */ #pragma omp master -{ - sigfillset(&block_mask); - act.sa_handler = int_handler; - act.sa_mask = block_mask; - act.sa_flags = 0; - sigaction(SIGINT,&act,&oact); - - PyRun_SimpleString("from uedge import bbb"); - PyRun_SimpleString("bbb.exmain_aborted = False"); + { + sigfillset(&block_mask); + act.sa_handler = int_handler; + act.sa_mask = block_mask; + act.sa_flags = 0; + sigaction(SIGINT,&act,&oact); + + PyRun_SimpleString("from uedge import bbb"); + PyRun_SimpleString("bbb.exmain_aborted = False"); } - #endif - /* now call the Fortran version of exmain */ #if defined(FC_FUNC) FC_FUNC(exmain_f, EXMAIN_F)(); #else - exmain_f_(); + exmain_f_(); #endif #ifdef FORTHON sigaction(SIGINT,&oact,NULL);