mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-21 02:40:56 +00:00
executor: prog_delete: deleting builtins properly - unless statically allocated; added a qc_builtins array for the standalone executor containing 'print'
This commit is contained in:
parent
5f0a6bcc53
commit
10d70328c8
1 changed files with 24 additions and 0 deletions
24
exec.c
24
exec.c
|
@ -22,6 +22,8 @@ MEM_VEC_FUNCTIONS(qc_program, qc_exec_stack, stack)
|
|||
MEM_VEC_FUNCTIONS(qc_program, size_t, profile)
|
||||
MEM_VEC_FUN_RESIZE(qc_program, size_t, profile)
|
||||
|
||||
MEM_VEC_FUNCTIONS(qc_program, prog_builtin, builtins)
|
||||
|
||||
static void loaderror(const char *fmt, ...)
|
||||
{
|
||||
int err = errno;
|
||||
|
@ -134,6 +136,11 @@ void prog_delete(qc_program *prog)
|
|||
MEM_VECTOR_CLEAR(prog, localstack);
|
||||
MEM_VECTOR_CLEAR(prog, stack);
|
||||
MEM_VECTOR_CLEAR(prog, profile);
|
||||
|
||||
if (prog->builtins_alloc) {
|
||||
MEM_VECTOR_CLEAR(prog, builtins);
|
||||
}
|
||||
/* otherwise the builtins were statically allocated */
|
||||
mem_d(prog);
|
||||
}
|
||||
|
||||
|
@ -451,6 +458,19 @@ cleanup:
|
|||
*/
|
||||
|
||||
#if defined(QCVM_EXECUTOR)
|
||||
static int qc_print(qc_program *prog)
|
||||
{
|
||||
qcany *str = (qcany*)(prog->globals + OFS_PARM0);
|
||||
printf("%s", prog_getstring(prog, str->string));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static prog_builtin qc_builtins[] = {
|
||||
NULL,
|
||||
&qc_print
|
||||
};
|
||||
static size_t qc_builtins_count = sizeof(qc_builtins) / sizeof(qc_builtins[0]);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
size_t i;
|
||||
|
@ -468,6 +488,10 @@ int main(int argc, char **argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
prog->builtins = qc_builtins;
|
||||
prog->builtins_count = qc_builtins_count;
|
||||
prog->builtins_alloc = 0;
|
||||
|
||||
for (i = 1; i < prog->functions_count; ++i) {
|
||||
const char *name = prog_getstring(prog, prog->functions[i].name);
|
||||
printf("Found function: %s\n", name);
|
||||
|
|
Loading…
Reference in a new issue