=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/stackmachine.c,v retrieving revision 1.27 retrieving revision 1.30 diff -u -p -r1.27 -r1.30 --- OpenXM/src/kan96xx/Kan/stackmachine.c 2004/09/16 23:53:44 1.27 +++ OpenXM/src/kan96xx/Kan/stackmachine.c 2005/06/09 04:47:16 1.30 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kan96xx/Kan/stackmachine.c,v 1.26 2004/09/16 02:22:03 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/Kan/stackmachine.c,v 1.29 2004/09/19 00:47:47 takayama Exp $ */ /* stackmachin.c */ #include @@ -74,6 +74,7 @@ static strToInteger(char *); static power(int s,int i); static void pstack(void); static struct object executableStringToExecutableArray(char *str); +static int isThereExecutableArrayOnStack(int n); extern int SerialCurrent; extern int QuoteMode; @@ -94,6 +95,7 @@ struct object * newObject() r->tag = 0; (r->lc).ival = 0; (r->rc).ival = 0; + r->attr = NULL; return(r); } @@ -464,6 +466,32 @@ struct object peek(k) } } +static int isThereExecutableArray(struct object ob) { + int n,i; + struct object otmp; + if (ob.tag == SexecutableArray) return(1); + if (ob.tag == Sarray) { + n = getoaSize(ob); + for (i=0; i "); } if (!Calling_ctrlC_hook) { /* to avoid recursive call of ctrlC-hook. */ - Calling_ctrlC_hook = 1; + Calling_ctrlC_hook = 1; RestrictedMode = 0; KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ + RestrictedMode = RestrictedMode_saved; } Calling_ctrlC_hook = 0; KSexecuteString(" (Computation is interrupted.) "); /* move to ctrlC-hook? */ @@ -868,9 +898,11 @@ void ctrlC(sig) extern int SGClock; extern int UserCtrlC; extern int OXlock; + extern int RestrictedMode, RestrictedMode_saved; signal(sig,SIG_IGN); /* see 133p */ + RestrictedMode = RestrictedMode_saved; cancelAlarm(); if (sig == SIGALRM) { fprintf(stderr,"ctrlC by SIGALRM\n"); @@ -933,7 +965,10 @@ int executeToken(token) extern int WarningMessageMode; extern int Strict; extern int InSendmsg2; + extern int RestrictedMode, RestrictedMode_saved; + int localRestrictedMode_saved; + localRestrictedMode_saved = 0; if (GotoP) { /* for goto */ if (token.kind == ID && isLiteral(token.token)) { if (strcmp(&((token.token)[1]),GotoLabel) == 0) { @@ -987,7 +1022,23 @@ int executeToken(token) if (ob.tag >= 0) { /* there is a definition in the user dictionary */ if (ob.tag == SexecutableArray) { + if (RestrictedMode) { + if (UD_attr & ATTR_EXPORT) { + localRestrictedMode_saved = RestrictedMode; RestrictedMode = 0; + if (isThereExecutableArrayOnStack(5)) { + int i; + for (i=0; i<5; i++) { (void) Kpop(); } + errorStackmachine("Executable array is on the argument stack (restricted mode). They are automatically removed.\n"); + } + }else{ + tracePushName(token.token); + errorStackmachine("You cannot execute this function in restricted mode.\n"); + } + } + status = executeExecutableArray(ob,token.token,0); + + if (localRestrictedMode_saved) RestrictedMode = localRestrictedMode_saved; if ((status & STATUS_BREAK) || (status < 0)) return status; }else { Kpush(ob); @@ -1055,6 +1106,8 @@ errorStackmachine(str) char message0[1024]; char *message; extern int ErrorMessageMode; + extern int RestrictedMode, RestrictedMode_saved; + RestrictedMode = RestrictedMode_saved; cancelAlarm(); if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { pushErrorStack(KnewErrorPacket(SerialCurrent,-1,str)); @@ -1137,6 +1190,7 @@ KSexecuteString(s) jmp_buf saved_EnvOfStackMachine; void (*sigfunc)(); int localCatchCtrlC ; + extern int RestrictedMode, RestrictedMode_saved; localCatchCtrlC = CatchCtrlC; /* If CatchCtrlC is rewrited in this program, @@ -1163,8 +1217,9 @@ KSexecuteString(s) recursive--; if (localCatchCtrlC) { signal(SIGINT, sigfunc); } if (!Calling_ctrlC_hook) { - Calling_ctrlC_hook = 1; + Calling_ctrlC_hook = 1; RestrictedMode = 0; KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ + RestrictedMode_saved; } Calling_ctrlC_hook = 0; KSexecuteString(" (Computation is interrupted.) "); /* move to ctrlC-hook?*/ @@ -1185,8 +1240,9 @@ KSexecuteString(s) recursive = 0; if (localCatchCtrlC) { signal(SIGINT, sigfunc); } if (!Calling_ctrlC_hook) { - Calling_ctrlC_hook = 1; + Calling_ctrlC_hook = 1; RestrictedMode = 0; KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ + RestrictedMode = RestrictedMode_saved; } Calling_ctrlC_hook = 0; Calling_ctrlC_hook = 0;