From a8796543af9e27e9db0f6166184f51607e6cfb2f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 7 Nov 2014 17:41:33 -0800 Subject: [PATCH] Use symbols for fatal errors and bump them by 20 slots. --- sourcepawn/compiler/libpawnc.cpp | 2 +- sourcepawn/compiler/sc.h | 19 +++++++++++ sourcepawn/compiler/sc1.cpp | 54 ++++++++++++++++---------------- sourcepawn/compiler/sc2.cpp | 24 +++++++------- sourcepawn/compiler/sc3.cpp | 4 +-- sourcepawn/compiler/sc5-in.scp | 24 +++++++------- sourcepawn/compiler/sc5.cpp | 10 +++--- sourcepawn/compiler/sc6.cpp | 4 +-- sourcepawn/compiler/sc7.cpp | 4 +-- 9 files changed, 82 insertions(+), 63 deletions(-) diff --git a/sourcepawn/compiler/libpawnc.cpp b/sourcepawn/compiler/libpawnc.cpp index 2ca5acea..8500b6cc 100644 --- a/sourcepawn/compiler/libpawnc.cpp +++ b/sourcepawn/compiler/libpawnc.cpp @@ -74,7 +74,7 @@ static const char *prefix[3]={ "error", "fatal error", "warning" }; if (number!=0) { int idx; - if (number < 160 || (number >= 200 && sc_warnings_are_errors)) + if (number < FIRST_FATAL_ERROR || (number >= 200 && sc_warnings_are_errors)) idx = 0; else if (number < 200) idx = 1; diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index f1f404f3..91ec7556 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -938,4 +938,23 @@ typedef struct array_info_s cell *base; /* &litq[startlit] */ } array_info_t; +enum FatalError { + FIRST_FATAL_ERROR = 180, + + FATAL_ERROR_READ = FIRST_FATAL_ERROR, + FATAL_ERROR_WRITE, + FATAL_ERROR_ALLOC_OVERFLOW, + FATAL_ERROR_OOM, + FATAL_ERROR_INVALID_INSN, + FATAL_ERROR_INT_OVERFLOW, + FATAL_ERROR_SCRIPT_OVERFLOW, + FATAL_ERROR_OVERWHELMED_BY_BAD, + FATAL_ERROR_NO_CODEPAGE, + FATAL_ERROR_INVALID_PATH, + FATAL_ERROR_ASSERTION_FAILED, + FATAL_ERROR_USER_ERROR, + + FATAL_ERRORS_TOTAL +}; + #endif /* SC_H_INCLUDED */ diff --git a/sourcepawn/compiler/sc1.cpp b/sourcepawn/compiler/sc1.cpp index 720fe58b..61cc13e8 100644 --- a/sourcepawn/compiler/sc1.cpp +++ b/sourcepawn/compiler/sc1.cpp @@ -218,17 +218,17 @@ int pc_compile(int argc, char *argv[]) sp_Globals = NewHashTable(); if (!sp_Globals) - error(163); + error(FATAL_ERROR_OOM); /* allocate memory for fixed tables */ inpfname=(char*)malloc(_MAX_PATH); if (inpfname==NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); /* insufficient memory */ litq=(cell*)malloc(litmax*sizeof(cell)); if (litq==NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); /* insufficient memory */ if (!phopt_init()) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); /* insufficient memory */ setopt(argc,argv,outfname,errfname,incfname,reportname,codepage); strcpy(binfname,outfname); @@ -254,7 +254,7 @@ int pc_compile(int argc, char *argv[]) lcl_tabsize=sc_tabsize; #if !defined NO_CODEPAGE if (!cp_set(codepage)) /* set codepage */ - error(168); /* codepage mapping file not found */ + error(FATAL_ERROR_NO_CODEPAGE); #endif /* optionally create a temporary input file that is a collection of all * input files @@ -271,7 +271,7 @@ int pc_compile(int argc, char *argv[]) tname=tempnam(NULL,"pawn"); #elif defined(MACOS) && !defined(__MACH__) /* tempnam is not supported for the Macintosh CFM build. */ - error(164,get_sourcefile(1)); + error(FATAL_ERROR_INVALID_INSN,get_sourcefile(1)); tname=NULL; sname=NULL; #else @@ -287,7 +287,7 @@ int pc_compile(int argc, char *argv[]) pc_closesrc(ftmp); remove(tname); strcpy(inpfname,sname); /* avoid invalid filename */ - error(160,sname); + error(FATAL_ERROR_READ,sname); } /* if */ pc_writesrc(ftmp,(unsigned char*)"#file \""); pc_writesrc(ftmp,(unsigned char*)sname); @@ -306,11 +306,11 @@ int pc_compile(int argc, char *argv[]) } /* if */ inpf_org=pc_opensrc(inpfname); if (inpf_org==NULL) - error(160,inpfname); + error(FATAL_ERROR_READ,inpfname); freading=TRUE; outf=(FILE*)pc_openasm(outfname); /* first write to assembler file (may be temporary) */ if (outf==NULL) - error(161,outfname); + error(FATAL_ERROR_WRITE,outfname); setconstants(); /* set predefined constants and tagnames */ for (i=0; isize = needsub(&type->idxtag[type->numdim], enumrootp); if (type->size > INT_MAX) - error(165); + error(FATAL_ERROR_INT_OVERFLOW); type->dim[type->numdim++] = type->size; } while (matchtoken('[')); @@ -3994,7 +3994,7 @@ static void domethodmap(LayoutSpec spec) methods = (methodmap_method_t **)realloc(map->methods, sizeof(methodmap_method_t *) * (map->nummethods + 1)); if (!methods) { - error(163); + error(FATAL_ERROR_OOM); return; } map->methods = methods; @@ -4521,7 +4521,7 @@ static void decl_enum(int vclass) enumsym->usage |= uENUMROOT; /* start a new list for the element names */ if ((enumroot=(constvalue*)malloc(sizeof(constvalue)))==NULL) - error(163); /* insufficient memory (fatal error) */ + error(FATAL_ERROR_OOM); /* insufficient memory (fatal error) */ memset(enumroot,0,sizeof(constvalue)); } else { enumsym=NULL; @@ -4671,7 +4671,7 @@ static void attachstatelist(symbol *sym, int state_id) constvalue *stateptr; if (sym->states==NULL) { if ((sym->states=(constvalue*)malloc(sizeof(constvalue)))==NULL) - error(163); /* insufficient memory (fatal error) */ + error(FATAL_ERROR_OOM); /* insufficient memory (fatal error) */ memset(sym->states,0,sizeof(constvalue)); } /* if */ /* see whether the id already exists (add new state only if it does not @@ -5483,7 +5483,7 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag) /* redimension the argument list, add the entry iVARARGS */ sym->dim.arglist=(arginfo*)realloc(sym->dim.arglist,(argcnt+2)*sizeof(arginfo)); if (sym->dim.arglist==0) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); /* insufficient memory */ memset(&sym->dim.arglist[argcnt+1],0,sizeof(arginfo)); /* keep the list terminated */ sym->dim.arglist[argcnt].ident=iVARARGS; sym->dim.arglist[argcnt].hasdefault=FALSE; @@ -5492,7 +5492,7 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag) sym->dim.arglist[argcnt].numtags=decl.type.numtags; sym->dim.arglist[argcnt].tags=(int*)malloc(decl.type.numtags*sizeof decl.type.tags[0]); if (sym->dim.arglist[argcnt].tags==NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); /* insufficient memory */ memcpy(sym->dim.arglist[argcnt].tags,decl.type.tags,decl.type.numtags*sizeof decl.type.tags[0]); } else { if (argcnt>oldargcnt || sym->dim.arglist[argcnt].ident!=iVARARGS) @@ -5525,7 +5525,7 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag) /* redimension the argument list, add the entry */ sym->dim.arglist=(arginfo*)realloc(sym->dim.arglist,(argcnt+2)*sizeof(arginfo)); if (sym->dim.arglist==0) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); /* insufficient memory */ memset(&sym->dim.arglist[argcnt+1],0,sizeof(arginfo)); /* keep the list terminated */ sym->dim.arglist[argcnt]=arg; } else { @@ -5684,7 +5684,7 @@ static void doarg(declinfo_t *decl, int offset, int fpublic, int chkshadow, argi cell val; tokeninfo(&val,&name); if ((arg->defvalue.size.symname=duplicatestring(name)) == NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); /* insufficient memory */ arg->defvalue.size.level=0; if (size_tag_token==uSIZEOF || size_tag_token==uCOUNTOF) { while (matchtoken('[')) { @@ -5709,7 +5709,7 @@ static void doarg(declinfo_t *decl, int offset, int fpublic, int chkshadow, argi arg->numtags=type->numtags; arg->tags=(int*)malloc(type->numtags * sizeof(type->tags[0])); if (arg->tags==NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); /* insufficient memory */ memcpy(arg->tags, type->tags, type->numtags * sizeof(type->tags[0])); argsym=findloc(decl->name); if (argsym!=NULL) { @@ -6458,7 +6458,7 @@ static constvalue *insert_constval(constvalue *prev,constvalue *next,const char constvalue *cur; if ((cur=(constvalue*)malloc(sizeof(constvalue)))==NULL) - error(163); /* insufficient memory (fatal error) */ + error(FATAL_ERROR_OOM); /* insufficient memory (fatal error) */ memset(cur,0,sizeof(constvalue)); if (name!=NULL) { assert(strlen(name)<=sNAMEMAX); @@ -7758,7 +7758,7 @@ static void addwhile(int *ptr) ptr[wqLOOP]=getlabel(); ptr[wqEXIT]=getlabel(); if (wqptr>=(wq+wqTABSZ-wqSIZE)) - error(162,"loop table"); /* loop table overflow (too many active loops)*/ + error(FATAL_ERROR_ALLOC_OVERFLOW,"loop table"); /* loop table overflow (too many active loops)*/ k=0; while (kstktop); newstack=(stkitem*)malloc(newsize*sizeof(stkitem)); if (newstack==NULL) - error(162,"parser stack"); /* stack overflow (recursive include?) */ + error(FATAL_ERROR_ALLOC_OVERFLOW,"parser stack"); /* swap the stacks */ memcpy(newstack,stack,stkidx*sizeof(stkitem)); if (stack!=NULL) @@ -172,7 +172,7 @@ int plungequalifiedfile(char *name) PUSHSTK_I(fline); inpfname=duplicatestring(name);/* set name of include file */ if (inpfname==NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); inpf=fp; /* set input file pointer to include file */ fnumber++; fline=0; /* set current line number to 0 */ @@ -276,7 +276,7 @@ static void doinclude(int silent) result=plungefile(name,(c!='>'),TRUE); if (!result && !silent) - error(160,name); /* cannot read from ... (fatal error) */ + error(FATAL_ERROR_READ,name); } /* readline @@ -890,7 +890,7 @@ static int command(void) ret=CMD_IF; assert(iflevel>=0); if (iflevel>=sCOMP_STACK) - error(162,"Conditional compilation stack"); /* table overflow */ + error(FATAL_ERROR_ALLOC_OVERFLOW,"Conditional compilation stack"); iflevel++; if (SKIPPING) break; /* break out of switch */ @@ -979,7 +979,7 @@ static int command(void) free(inpfname); inpfname=duplicatestring(pathname); if (inpfname==NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); fline=0; } /* if */ } /* if */ @@ -1023,7 +1023,7 @@ static int command(void) name[i]='\0'; } /* if */ if (!cp_set(name)) - error(168); /* codepage mapping file not found */ + error(FATAL_ERROR_NO_CODEPAGE); } else if (strcmp(str,"compress")==0) { cell val; preproc_expr(&val,NULL); @@ -1292,7 +1292,7 @@ static int command(void) /* store matched pattern */ pattern=(char*)malloc(count+1); if (pattern==NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); lptr=start; count=0; while (lptr!=end) { @@ -1326,7 +1326,7 @@ static int command(void) /* store matched substitution */ substitution=(char*)malloc(count+1); /* +1 for '\0' */ if (substitution==NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); lptr=start; count=0; while (lptr!=end) { @@ -1542,7 +1542,7 @@ static int substpattern(unsigned char *line,size_t buffersize,char *pattern,char len=(int)(e-s); args[arg]=(unsigned char*)malloc(len+1); if (args[arg]==NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); strlcpy((char*)args[arg],(char*)s,len+1); /* character behind the pattern was matched too */ if (*e==*p) { @@ -2469,7 +2469,7 @@ static void chk_grow_litq(void) litmax+=sDEF_LITMAX; p=(cell *)realloc(litq,litmax*sizeof(cell)); if (p==NULL) - error(162,"literal table"); /* literal table overflow (fatal error) */ + error(FATAL_ERROR_ALLOC_OVERFLOW,"literal table"); litq=p; } /* if */ } @@ -2662,7 +2662,7 @@ static symbol *add_symbol(symbol *root,symbol *entry,int sort) root=root->next; if ((newsym=(symbol *)malloc(sizeof(symbol)))==NULL) { - error(163); + error(FATAL_ERROR_OOM); return NULL; } /* if */ memcpy(newsym,entry,sizeof(symbol)); @@ -3057,7 +3057,7 @@ symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,int usage /* create an empty referrer list */ if ((refer=(symbol**)malloc(sizeof(symbol*)))==NULL) { - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); return NULL; } /* if */ *refer=NULL; diff --git a/sourcepawn/compiler/sc3.cpp b/sourcepawn/compiler/sc3.cpp index 1e1fe9e6..90aa2430 100644 --- a/sourcepawn/compiler/sc3.cpp +++ b/sourcepawn/compiler/sc3.cpp @@ -2212,7 +2212,7 @@ restart: */ sym=fetchfunc(lastsymbol); if (sym==NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); markusage(sym,uREAD); } else { return error(12); /* invalid function call */ @@ -2358,7 +2358,7 @@ static int primary(value *lval) assert(sc_status==statFIRST); sym=fetchfunc(st); if (sym==NULL) - error(163); /* insufficient memory */ + error(FATAL_ERROR_OOM); } /* if */ assert(sym!=NULL); assert(sym->ident==iFUNCTN || sym->ident==iREFFUNC); diff --git a/sourcepawn/compiler/sc5-in.scp b/sourcepawn/compiler/sc5-in.scp index 8d905438..4ad17ca0 100644 --- a/sourcepawn/compiler/sc5-in.scp +++ b/sourcepawn/compiler/sc5-in.scp @@ -365,24 +365,24 @@ static const char *errmsg[] = { static const char *fatalmsg[] = { #ifdef SCPACK -/*160*/ "cannot read from file: \"%s\"\n", -/*161*/ "cannot write to file: \"%s\"\n", -/*162*/ "table overflow: \"%s\"\n", +/*180*/ "cannot read from file: \"%s\"\n", +/*181*/ "cannot write to file: \"%s\"\n", +/*182*/ "table overflow: \"%s\"\n", /* table can be: loop table * literal table * staging buffer * option table (response file) * peephole optimizer table */ -/*163*/ "insufficient memory\n", -/*164*/ "invalid assembler instruction \"%s\"\n", -/*165*/ "numeric overflow, exceeding capacity\n", -/*166*/ "compiled script exceeds the maximum memory size (%ld bytes)\n", -/*167*/ "too many error messages on one line\n", -/*168*/ "codepage mapping file not found\n", -/*169*/ "invalid path: \"%s\"\n", -/*170*/ "assertion failed: %s\n", -/*171*/ "user error: %s\n", +/*183*/ "insufficient memory\n", +/*184*/ "invalid assembler instruction \"%s\"\n", +/*185*/ "numeric overflow, exceeding capacity\n", +/*186*/ "compiled script exceeds the maximum memory size (%ld bytes)\n", +/*187*/ "too many error messages on one line\n", +/*188*/ "codepage mapping file not found\n", +/*189*/ "invalid path: \"%s\"\n", +/*190*/ "assertion failed: %s\n", +/*191*/ "user error: %s\n", #else "\256\214a\204from \344le:\354", "\256writ\200\266 \344le:\354", diff --git a/sourcepawn/compiler/sc5.cpp b/sourcepawn/compiler/sc5.cpp index e161ed1a..17d48618 100644 --- a/sourcepawn/compiler/sc5.cpp +++ b/sourcepawn/compiler/sc5.cpp @@ -89,7 +89,7 @@ static short lastfile; * the error reporting is enabled only in the second pass (and only when * actually producing output). Fatal errors may never be ignored. */ - int not_fatal = (number < 160 || number >= 200); + int not_fatal = (number < FIRST_FATAL_ERROR || number >= 200); if (errflag && not_fatal) return 0; if (sc_status != statWRITE && not_fatal) { @@ -105,13 +105,13 @@ static short lastfile; return 0; } /* if */ - if (number<160){ + if (number=160 && number<200) || errnum>25){ + if ((number>=FIRST_FATAL_ERROR && number<200) || errnum>25){ if (strlen(errfname)==0) { va_start(argptr,number); pc_error(0,"\nCompilation aborted.",NULL,0,0,argptr); @@ -175,7 +175,7 @@ static short lastfile; if (!is_warning) errorcount++; if (errorcount>=3) - error(167); /* too many error/warning messages on one line */ + error(FATAL_ERROR_OVERWHELMED_BY_BAD); return 0; } diff --git a/sourcepawn/compiler/sc6.cpp b/sourcepawn/compiler/sc6.cpp index 1c6be5bb..5e73e7dd 100644 --- a/sourcepawn/compiler/sc6.cpp +++ b/sourcepawn/compiler/sc6.cpp @@ -920,12 +920,12 @@ static void splat_to_binary(const char *binfname, void *bytes, size_t size) // Note: error 161 will setjmp(), which skips destructors :( FILE *fp = fopen(binfname, "wb"); if (!fp) { - error(161, binfname); + error(FATAL_ERROR_WRITE, binfname); return; } if (fwrite(bytes, 1, size, fp) != size) { fclose(fp); - error(161, binfname); + error(FATAL_ERROR_WRITE, binfname); return; } fclose(fp); diff --git a/sourcepawn/compiler/sc7.cpp b/sourcepawn/compiler/sc7.cpp index 754a0ed1..99763956 100644 --- a/sourcepawn/compiler/sc7.cpp +++ b/sourcepawn/compiler/sc7.cpp @@ -95,14 +95,14 @@ static void grow_stgbuffer(char **buffer, int *curmax, int requiredsize) * over a few kBytes, there is probably a run-away expression */ if (requiredsize>sSTG_MAX) - error(163); /* staging buffer overflow (fatal error) */ + error(FATAL_ERROR_OOM); *curmax=requiredsize+sSTG_GROW; if (*buffer!=NULL) p=(char *)realloc(*buffer,*curmax*sizeof(char)); else p=(char *)malloc(*curmax*sizeof(char)); if (p==NULL) - error(163); /* staging buffer overflow (fatal error) */ + error(FATAL_ERROR_OOM); *buffer=p; if (clear) **buffer='\0';