From bb4163ea456fab54385f7310b4e20949cda0aaa6 Mon Sep 17 00:00:00 2001 From: Zeex Date: Thu, 2 Jan 2014 16:44:48 +0700 Subject: [PATCH] Fix #emit SYSREQ.C generating wrong native index for unused natives This commit fixes a bug where the compiler generated incorrect native index in assembly code for natives invoked via #emit sysreq.c and not called elsewhere with the normal syntax. See 4) here: http://forum.sa-mp.com/showthread.php?t=355877 --------- test code -------- native print(const s[]); native printf(const format[], ...); main() { new string[] = "hi there!"; printf(string); #emit push.adr string #emit push.c 4 #emit sysreq.c print #emit sysreq.c printf #emit stack 8 } ----- end of test code ----- --- source/compiler/sc2.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 02a256f..5887a86 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1224,6 +1224,13 @@ static int command(void) assert((sym->ident & iFUNCTN)!=0 || (sym->ident & iREFFUNC)!=0); stgwrite(sym->name); } else { + if (strcmp(name, "sysreq.c")==0) { + assert((sym->ident & iFUNCTN)!=0 && (sym->usage & uNATIVE)!=0); + if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->addr>=0) { + /* reserve a SYSREQ id if called for the first time */ + sym->addr=ntv_funcid++; + } /* if */ + } outval(sym->addr,FALSE); } /* if */ /* mark symbol as "used", unknown whether for read or write */