Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liruipeng committed Mar 28, 2024
1 parent a773a42 commit 2c546c5
Showing 1 changed file with 58 additions and 59 deletions.
117 changes: 58 additions & 59 deletions bbb/exmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static struct sigaction act,oact;
static sigjmp_buf ev;


/*
/*
Handler for SIGINT signal
*/
void int_handler() {
Expand All @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 2c546c5

Please sign in to comment.