mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
make the builtins an array of pointers so the hash table doesn't get royally
screwed up
This commit is contained in:
parent
6ab3329b94
commit
6af9a5d8e6
4 changed files with 19 additions and 20 deletions
|
@ -143,6 +143,7 @@ typedef void (*builtin_proc) (progs_t *pr);
|
|||
typedef struct {
|
||||
const char *name;
|
||||
builtin_proc proc;
|
||||
int first_statement;
|
||||
} builtin_t;
|
||||
|
||||
ddef_t *PR_FindGlobal (progs_t *pr, const char *name);
|
||||
|
@ -277,7 +278,7 @@ struct progs_s {
|
|||
int (*prune_edict)(progs_t *pr, edict_t *ent);
|
||||
void (*free_edict)(progs_t *pr, edict_t *ent);
|
||||
|
||||
builtin_t *builtins;
|
||||
builtin_t **builtins;
|
||||
int numbuiltins;
|
||||
|
||||
// debug info
|
||||
|
|
|
@ -1287,35 +1287,39 @@ PR_AddBuiltin (progs_t *pr, const char *name, builtin_proc builtin, int num)
|
|||
{
|
||||
int i;
|
||||
|
||||
if (!pr->builtin_hash)
|
||||
pr->builtin_hash = Hash_NewTable (1021, builtin_get_key, 0, pr);
|
||||
|
||||
if (pr->numbuiltins == 0) {
|
||||
pr->builtins = calloc (PR_AUTOBUILTIN, sizeof (builtin_t));
|
||||
pr->builtins = calloc (PR_AUTOBUILTIN, sizeof (builtin_t*));
|
||||
pr->numbuiltins = PR_AUTOBUILTIN;
|
||||
if (!pr->builtins)
|
||||
PR_Error (pr, "PR_AddBuiltin: memory allocation error!\n");
|
||||
pr->builtin_hash = Hash_NewTable (1021, builtin_get_key, 0, pr);
|
||||
}
|
||||
|
||||
if (num < 0) {
|
||||
for (i = PR_AUTOBUILTIN;
|
||||
i < pr->numbuiltins && pr->builtins[i].proc; i++)
|
||||
i < pr->numbuiltins && pr->builtins[i]; i++)
|
||||
;
|
||||
if (i >= pr->numbuiltins) {
|
||||
pr->numbuiltins++;
|
||||
pr->builtins = realloc (pr->builtins,
|
||||
pr->numbuiltins * sizeof (builtin_t));
|
||||
pr->numbuiltins * sizeof (builtin_t*));
|
||||
if (!pr->builtins)
|
||||
PR_Error (pr, "PR_AddBuiltin: memory allocation error!\n");
|
||||
}
|
||||
} else {
|
||||
if (num >= PR_AUTOBUILTIN || num == 0)
|
||||
PR_Error (pr, "PR_AddBuiltin: invalid builtin number.\n");
|
||||
if (pr->builtins[num].proc)
|
||||
if (pr->builtins[num])
|
||||
PR_Error (pr, "PR_AddBuiltin: builtin number already exists.\n");
|
||||
i = num;
|
||||
}
|
||||
pr->builtins[i].proc = builtin;
|
||||
pr->builtins[i].name = name;
|
||||
Hash_Add (pr->builtin_hash, &pr->builtins[i]);
|
||||
pr->builtins[i] = malloc (sizeof (builtin_t));
|
||||
pr->builtins[i]->proc = builtin;
|
||||
pr->builtins[i]->name = name;
|
||||
pr->builtins[i]->first_statement = i;
|
||||
Hash_Add (pr->builtin_hash, pr->builtins[i]);
|
||||
}
|
||||
|
||||
builtin_t *
|
||||
|
@ -1405,7 +1409,7 @@ PR_RelocateBuiltins (progs_t *pr)
|
|||
pr->progs_name, bi_name);
|
||||
return 0;
|
||||
}
|
||||
func->first_statement = -(bi - pr->builtins);
|
||||
func->first_statement = -bi->first_statement;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -710,21 +710,15 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum)
|
|||
pr->pr_argc = st->op - OP_CALL0;
|
||||
if (!OPA.func_var)
|
||||
PR_RunError (pr, "NULL function");
|
||||
if (OPA.func_var < 0) { // dynamic builtin
|
||||
int i = -OPA.func_var;
|
||||
if (i >= pr->numbuiltins || !pr->builtins[i].proc)
|
||||
PR_RunError (pr, "Bad builtin call number");
|
||||
pr->builtins[i].proc (pr);
|
||||
break;
|
||||
}
|
||||
newf = &pr->pr_functions[OPA.func_var];
|
||||
if (newf->first_statement < 0) {
|
||||
// negative statements are built in functions
|
||||
int i = -newf->first_statement;
|
||||
|
||||
if (i >= pr->numbuiltins || !pr->builtins[i].proc)
|
||||
if (i >= pr->numbuiltins || !pr->builtins[i]
|
||||
|| !pr->builtins[i]->proc)
|
||||
PR_RunError (pr, "Bad builtin call number");
|
||||
pr->builtins[i].proc (pr);
|
||||
pr->builtins[i]->proc (pr);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1599,7 +1599,7 @@ SV_PR_Cmds_Init ()
|
|||
{
|
||||
PR_Cmds_Init (&sv_pr_state);
|
||||
|
||||
sv_pr_state.builtins[45].proc = 0; // (override standard builtin)
|
||||
sv_pr_state.builtins[45] = 0; // (override standard builtin)
|
||||
PR_AddBuiltin (&sv_pr_state, "cvar", PF_sv_cvar, 45);
|
||||
// float (string s) cvar
|
||||
|
||||
|
|
Loading…
Reference in a new issue