From c9bc46e770f3dec4e88087be159fbc4e7d9634c9 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 15 May 2007 04:59:24 +0000 Subject: [PATCH] core will now ignore missing natives starting with '@' the compiler will now resolve aliased natives to single references and export '@' natives for each redundant entry --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40804 --- core/systems/PluginSys.cpp | 3 ++- sourcepawn/compiler/sc4.c | 9 +++++++++ sourcepawn/compiler/sc6.c | 27 ++++++++++++++------------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/core/systems/PluginSys.cpp b/core/systems/PluginSys.cpp index c501f7fb..2404df7c 100644 --- a/core/systems/PluginSys.cpp +++ b/core/systems/PluginSys.cpp @@ -1037,7 +1037,8 @@ bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxleng { break; } - if (native->status == SP_NATIVE_UNBOUND) + if (native->status == SP_NATIVE_UNBOUND + && native->name[0] != '@') { if (error) { diff --git a/sourcepawn/compiler/sc4.c b/sourcepawn/compiler/sc4.c index b3e7fb86..a18267e3 100644 --- a/sourcepawn/compiler/sc4.c +++ b/sourcepawn/compiler/sc4.c @@ -738,6 +738,7 @@ SC_FUNC void ffcase(cell value,char *labelname,int newtable) SC_FUNC void ffcall(symbol *sym,const char *label,int numargs) { char symname[2*sNAMEMAX+16]; + char aliasname[sNAMEMAX+1]; assert(sym!=NULL); assert(sym->ident==iFUNCTN); @@ -749,6 +750,14 @@ SC_FUNC void ffcall(symbol *sym,const char *label,int numargs) if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->addr>=0) sym->addr=ntv_funcid++; stgwrite("\tsysreq.c "); + /* Look for an alias */ + if (lookup_alias(aliasname, sym->name)) { + symbol *asym = findglb(aliasname, sGLOBAL); + if (asym && asym->ident==iFUNCTN && ((sym->usage & uNATIVE) != 0)) { + sym = asym; + } + } + assert(sym->addr != 0x1d); outval(sym->addr,FALSE); if (sc_asmfile) { stgwrite("\t; "); diff --git a/sourcepawn/compiler/sc6.c b/sourcepawn/compiler/sc6.c index ea090bb2..a19b62cd 100644 --- a/sourcepawn/compiler/sc6.c +++ b/sourcepawn/compiler/sc6.c @@ -676,6 +676,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) constvalue *constptr; cell mainaddr; char nullchar; + char testalias[sNAMEMAX+1]; /* if compression failed, restart the assembly with compaction switched off */ if (setjmp(compact_err)!=0) { @@ -706,8 +707,9 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) for (sym=glbtab.next; sym!=NULL; sym=sym->next) { int match=0; if (sym->ident==iFUNCTN) { - if ((sym->usage & uNATIVE)!=0 && (sym->usage & uREAD)!=0 && sym->addr>=0) + if ((sym->usage & uNATIVE)!=0 && (sym->usage & uREAD)!=0 && sym->addr>=0) { match=++numnatives; + } if ((sym->usage & uPUBLIC)!=0 && (sym->usage & uDEFINE)!=0) match=++numpublics; if (strcmp(sym->name,uMAINFUNC)==0) { @@ -719,13 +721,12 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) match=++numpubvars; } /* if */ if (match) { - char alias[sNAMEMAX+1]; + const char *aliasptr = sym->name; assert(sym!=NULL); - if ((sym->usage & uNATIVE)==0 || !lookup_alias(alias,sym->name)) { - assert(strlen(sym->name)<=sNAMEMAX); - strcpy(alias,sym->name); + if (((sym->usage & uNATIVE)!=0) && lookup_alias(testalias,sym->name)) { + aliasptr = "@"; } /* if */ - nametablesize+=strlen(alias)+1; + nametablesize+=strlen(aliasptr)+1; } /* if */ } /* for */ assert(numnatives==ntv_funcid); @@ -843,13 +844,13 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) } /* for */ count=0; for (i=0; iname)) { - assert(strlen(sym->name)<=sNAMEMAX); - strcpy(alias,sym->name); - } /* if */ + aliasptr = sym->name; + if (lookup_alias(testalias,sym->name)) { + aliasptr = "@"; + } assert(sym->vclass==sGLOBAL); func.address=0; func.nameofs=nameofs; @@ -860,8 +861,8 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) pc_resetbin(fout,hdr.natives+count*sizeof(AMX_FUNCSTUBNT)); pc_writebin(fout,&func,sizeof func); pc_resetbin(fout,nameofs); - pc_writebin(fout,alias,strlen(alias)+1); - nameofs+=strlen(alias)+1; + pc_writebin(fout,(void *)aliasptr,strlen(aliasptr)+1); + nameofs+=strlen(aliasptr)+1; count++; } /* for */ free(nativelist);