From fbe6c2f6312e079de08f8ab958e69c8b5ff7958a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 6 Jan 2004 03:18:44 +0000 Subject: [PATCH] make the bad builtin number a warning and provide a suitable function in case the function is called: allows progs with bad (but unused) builtins to run anyway --- libs/gamecode/engine/pr_builtins.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libs/gamecode/engine/pr_builtins.c b/libs/gamecode/engine/pr_builtins.c index a4b54ffef..71e0181f3 100644 --- a/libs/gamecode/engine/pr_builtins.c +++ b/libs/gamecode/engine/pr_builtins.c @@ -108,6 +108,19 @@ PR_FindBuiltin (progs_t *pr, const char *name) return (builtin_t *) Hash_Find (pr->builtin_hash, name); } +static void +bi_no_function (progs_t *pr) +{ + // no need for checking: the /only/ way to get here is via a function + // descriptor with a bad builtin number + dstatement_t *st = pr->pr_statements + pr->pr_xstatement; + dfunction_t *func = pr->pr_functions + G_FUNCTION (pr, st->a); + const char *bi_name = PR_GetString (pr, func->s_name); + int ind = -func->first_statement; + + PR_RunError (pr, "Bad builtin called: %s = #%d", bi_name, ind); +} + int PR_RelocateBuiltins (progs_t *pr) { @@ -115,6 +128,7 @@ PR_RelocateBuiltins (progs_t *pr) int bad = 0; dfunction_t *func; builtin_t *bi; + builtin_proc proc; const char *bi_name; for (i = 1; i < pr->progs->numfunctions; i++) { @@ -137,12 +151,13 @@ PR_RelocateBuiltins (progs_t *pr) } ind = -func->first_statement; - if (ind >= pr->numbuiltins || !(bi = pr->builtins[ind]) || !bi->proc) { - Sys_Printf ("Bad builtin call number: %s = #%d\n", bi_name, ind); - bad = 1; - continue; + if (ind >= pr->numbuiltins || !(bi = pr->builtins[ind]) + || !(proc = bi->proc)) { + Sys_DPrintf ("WARNING: Bad builtin call number: %s = #%d\n", + bi_name, ind); + proc = bi_no_function; } - ((bfunction_t *) func)->func = bi->proc; + ((bfunction_t *) func)->func = proc; } return !bad; }