From f41b3a2b062d0cdc781d387aab615564a13432a7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 23 Jul 2014 23:21:03 -0700 Subject: [PATCH 1/3] Enable binreloc for OS X. --- sourcepawn/compiler/AMBuilder | 2 +- sourcepawn/compiler/sc1.c | 26 +++++++++++--------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/sourcepawn/compiler/AMBuilder b/sourcepawn/compiler/AMBuilder index 1d8e0721..c8ddd554 100644 --- a/sourcepawn/compiler/AMBuilder +++ b/sourcepawn/compiler/AMBuilder @@ -70,7 +70,7 @@ binary.sources += [ 'zlib/zutil.c', 'sp_symhash.c' ] -if builder.target_platform == 'linux': +if builder.target_platform != 'windows': binary.sources.append('binreloc.c') SM.spcomp = builder.Add(binary) diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index 3528f736..fc67fcbf 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -1192,35 +1192,31 @@ static void setopt(int argc,char **argv,char *oname,char *ename,char *pname, } #if defined __BORLANDC__ || defined __WATCOMC__ - #pragma argsused +# pragma argsused #endif static void setconfig(char *root) { - #if defined macintosh - insert_path(":include:"); - #else char path[_MAX_PATH]; char *ptr,*base; int len; /* add the default "include" directory */ - #if defined __WIN32__ || defined _WIN32 +#if defined __WIN32__ || defined _WIN32 GetModuleFileNameA(NULL,path,_MAX_PATH); - #elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ +#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined DARWIN /* see www.autopackage.org for the BinReloc module */ br_init_lib(NULL); ptr=br_find_exe("spcomp"); strlcpy(path,ptr,sizeof path); free(ptr); - #else +#else if (root!=NULL) strlcpy(path,root,sizeof path); /* path + filename (hopefully) */ - #endif - #if defined __MSDOS__ +# if defined __MSDOS__ /* strip the options (appended to the path + filename) */ if ((ptr=strpbrk(path," \t/"))!=NULL) *ptr='\0'; - #endif +# endif /* terminate just behind last \ or : */ if ((ptr=strrchr(path,DIRSEP_CHAR))!=NULL || (ptr=strchr(path,':'))!=NULL) { /* If there is no "\" or ":", the string probably does not contain the @@ -1251,18 +1247,18 @@ static void setconfig(char *root) } /* if */ insert_path(path); /* same for the codepage root */ - #if !defined NO_CODEPAGE +# if !defined NO_CODEPAGE *ptr='\0'; if (!cp_path(path,"codepage")) error(169,path); /* codepage path */ - #endif +# endif /* also copy the root path (for the XML documentation) */ - #if !defined SC_LIGHT +# if !defined SC_LIGHT *ptr='\0'; strcpy(sc_rootpath,path); - #endif +# endif } /* if */ - #endif /* macintosh */ +#endif /* macintosh */ } static void setcaption(void) From 3fc05056b088f70df50075e91bede071a80226c0 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 23 Jul 2014 23:25:12 -0700 Subject: [PATCH 2/3] Rename to __unknown__ to quell sc7 asserts. --- sourcepawn/compiler/sc1.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index fc67fcbf..941319a7 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -654,7 +654,7 @@ const char *pc_tagname(int tag) if ((int)(ptr->value & TAGMASK) == (tag & TAGMASK)) return ptr->name; } - return ""; + return "__unknown__"; } constvalue *pc_tagptr(const char *name) @@ -2878,7 +2878,7 @@ static void decl_const(int vclass) if (expecttoken(tSYMBOL, &tok)) strcpy(constname, tok.str); else - strcpy(constname, ""); + strcpy(constname, "__unknown__"); symbolline=fline; /* save line where symbol was found */ needtoken('='); @@ -3262,7 +3262,7 @@ static int parse_old_decl(declinfo_t *decl, int flags) if ((flags & DECLFLAG_MAYBE_FUNCTION) && matchtoken(tOPERATOR)) { decl->opertok = operatorname(decl->name); if (decl->opertok == 0) - strcpy(decl->name, ""); + strcpy(decl->name, "__unknown__"); } else { if (!lexpeek(tSYMBOL)) { switch (lextok(&tok)) { @@ -3280,7 +3280,7 @@ static int parse_old_decl(declinfo_t *decl, int flags) if (expecttoken(tSYMBOL, &tok)) strcpy(decl->name, tok.str); else - strcpy(decl->name, ""); + strcpy(decl->name, "__unknown__"); } } @@ -3318,10 +3318,10 @@ static int parse_new_decl(declinfo_t *decl, const token_t *first, int flags) if ((flags & DECLFLAG_MAYBE_FUNCTION) && matchtoken(tOPERATOR)) { decl->opertok = operatorname(decl->name); if (decl->opertok == 0) - strcpy(decl->name, ""); + strcpy(decl->name, "__unknown__"); } else { if (!expecttoken(tSYMBOL, &tok)) { - strcpy(decl->name, ""); + strcpy(decl->name, "__unknown__"); return FALSE; } strcpy(decl->name, tok.str); @@ -3473,7 +3473,7 @@ static void define_constructor(methodmap_t *map, methodmap_method_t *method) symbol *sym = findglb(map->name, sGLOBAL); if (sym) { - const char *type = ""; + const char *type = "__unknown__"; switch (sym->ident) { case iVARIABLE: case iARRAY: @@ -3779,11 +3779,11 @@ methodmap_method_t *parse_method(methodmap_t *map) // This stores the name of the method (for destructors, we add a ~). token_ident_t ident; - strcpy(ident.name, ""); + strcpy(ident.name, "__unknown__"); // For binding syntax, like X() = Y, this stores the right-hand name. token_ident_t bindsource; - strcpy(bindsource.name, ""); + strcpy(bindsource.name, "__unknown__"); typeinfo_t type; memset(&type, 0, sizeof(type)); From 2a46f8f881c18800952f93a1e2792bbce982e7d2 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 23 Jul 2014 23:36:11 -0700 Subject: [PATCH 3/3] Add GetNativeFunction (bug 6200). --- core/logic/smn_fakenatives.cpp | 1 + plugins/include/functions.inc | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/core/logic/smn_fakenatives.cpp b/core/logic/smn_fakenatives.cpp index 3c084bff..f5f9d66a 100644 --- a/core/logic/smn_fakenatives.cpp +++ b/core/logic/smn_fakenatives.cpp @@ -441,6 +441,7 @@ REGISTER_NATIVES(nativeNatives) {"GetNativeArray", GetNativeArray}, {"GetNativeCell", GetNativeCell}, {"GetNativeCellRef", GetNativeCellRef}, + {"GetNativeFunction", GetNativeCell}, {"GetNativeString", GetNativeString}, {"GetNativeStringLength", GetNativeStringLength}, {"FormatNativeString", FormatNativeString}, diff --git a/plugins/include/functions.inc b/plugins/include/functions.inc index dc6f31d1..e928213b 100644 --- a/plugins/include/functions.inc +++ b/plugins/include/functions.inc @@ -428,6 +428,15 @@ native SetNativeString(param, const String:source[], maxlength, bool:utf8=true, */ native any:GetNativeCell(param); +/** + * Gets a function pointer from a native parameter. + * + * @param param Parameter number, starting from 1. + * @return Function pointer at the given parameter number. + * @error Invalid parameter number, or calling from a non-native function. + */ +native Function GetNativeFunction(param); + /** * Gets a cell from a native parameter, by reference. *