Skip to content

Commit

Permalink
Fix #emit SYSREQ.C generating wrong native index for unused natives
Browse files Browse the repository at this point in the history
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.s string
	#emit push.c 4
	#emit sysreq.c print
	#emit sysreq.c printf
}

----- end of test code -----
  • Loading branch information
Zeex committed Jan 2, 2014
1 parent 8d238c4 commit 569f811
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source/compiler/sc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 569f811

Please sign in to comment.