From 13775b11b622e8bb927b7401a6e91bf717fadf50 Mon Sep 17 00:00:00 2001 From: Borja Ferrer Date: Sun, 5 Nov 2006 13:24:29 +0000 Subject: [PATCH] added a library table for module autoloading updated VM plugin loader to read in this new section --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40149 --- sourcepawn/compiler/pawncc.c | 33 +++++++++++++++++- sourcepawn/compiler/sc2.c | 51 +++++++++++++++++++++++++--- sourcepawn/include/sp_file_headers.h | 6 ++++ sourcepawn/include/sp_vm_types.h | 2 ++ sourcepawn/vm/sp_vm_engine.cpp | 5 +++ 5 files changed, 92 insertions(+), 5 deletions(-) diff --git a/sourcepawn/compiler/pawncc.c b/sourcepawn/compiler/pawncc.c index dc919128..a31f1e4a 100644 --- a/sourcepawn/compiler/pawncc.c +++ b/sourcepawn/compiler/pawncc.c @@ -16,6 +16,7 @@ enum FileSections FS_Publics, FS_Pubvars, FS_Natives, + FS_Libraries, FS_Nametable, /* required */ FS_DbgFile, FS_DbgSymbol, @@ -47,7 +48,7 @@ int main(int argc, char *argv[]) sp_file_t *spf; memfile_t *dbgtab = NULL; //dbgcrab unsigned char *dbgptr = NULL; - uint32_t sections[FS_Number] = {1,1,0,0,0,1,0,0,0,0,0,0}; + uint32_t sections[FS_Number] = {1,1,0,0,0,0,1,0,0,0,0,0,0}; FILE *fp; if (bin_file == NULL) @@ -87,6 +88,11 @@ int main(int argc, char *argv[]) { spfw_add_section(spf, ".natives"); } + sections[FS_Libraries] = (hdr->pubvars - hdr->libraries) / hdr->defsize; + if (sections[FS_Libraries]) + { + spfw_add_section(spf, ".libraries"); + } spfw_add_section(spf, ".names"); @@ -251,6 +257,31 @@ int main(int argc, char *argv[]) spfw_next_section(spf); } + if (sections[FS_Libraries]) + { + sp_file_libraries_t *libtbl; + AMX_FUNCSTUBNT *stub; + unsigned char *stubptr; + uint32_t libraries = sections[FS_Libraries]; + + libtbl = (sp_file_libraries_t *)malloc(sizeof(sp_file_libraries_t) * libraries); + stubptr = (unsigned char *)hdr + hdr->libraries; + + for (i=0; inameofs - (hdr->nametable + sizeof(uint16_t)); + + stubptr += hdr->defsize; + } + if (libraries) + { + sfwrite(libtbl, sizeof(sp_file_libraries_t), libraries, spf); + } + free(libtbl); + spfw_next_section(spf); + } + if (sections[FS_Nametable]) { unsigned char *base; diff --git a/sourcepawn/compiler/sc2.c b/sourcepawn/compiler/sc2.c index 6a1c627d..93576701 100644 --- a/sourcepawn/compiler/sc2.c +++ b/sourcepawn/compiler/sc2.c @@ -1071,8 +1071,28 @@ static int command(void) lptr=(unsigned char*)strchr((char*)lptr,'\0'); /* skip to end (ignore "extra characters on line") */ } else if (strcmp(str,"dynamic")==0) { preproc_expr(&pc_stksize,NULL); - } else if (strcmp(str,"library")==0) { - char name[sNAMEMAX+1]; + } else if (!strcmp(str,"library") + ||!strcmp(str,"reqclass") + ||!strcmp(str,"loadlib") + ||!strcmp(str,"explib") + ||!strcmp(str,"expclass") + ||!strcmp(str,"defclasslib")) { + char name[sNAMEMAX+1],sname[sNAMEMAX+1]; + const char *prefix=""; + sname[0]='\0'; + sname[1]='\0'; + if (!strcmp(str,"library")) + prefix="??li_"; + else if (!strcmp(str,"reqclass")) + prefix="??rc_"; + else if (!strcmp(str,"loadlib")) + prefix="??f_"; + else if (!strcmp(str,"explib")) + prefix="??el_"; + else if (!strcmp(str,"expclass")) + prefix="??ec_"; + else if (!strcmp(str,"defclasslib")) + prefix="??d_"; while (*lptr<=' ' && *lptr!='\0') lptr++; if (*lptr=='"') { @@ -1082,6 +1102,18 @@ static int command(void) for (i=0; iinfo.natives_num = secptr->size / sizeof(sp_file_natives_t); plugin->info.natives = (sp_file_natives_t *)(base + secptr->dataoffs); } + else if (!(plugin->info.lib) && !strcmp(nameptr, ".libraries")) + { + plugin->info.libraries_num = secptr->size / sizeof(sp_file_libraries_t); + plugin->info.lib = (sp_file_libraries_t *)(base + secptr->dataoffs); + } else if (!(plugin->info.stringbase) && !strcmp(nameptr, ".names")) { plugin->info.stringbase = (const char *)(base + secptr->dataoffs);