Clean up a lot of va usage

va is not thread-safe (it's not save even without threads), and I want
to be able to run progs in threads.
This commit is contained in:
Bill Currie 2020-02-26 09:46:59 +09:00
parent 42713cad8b
commit d60291a73e
5 changed files with 13 additions and 43 deletions

View file

@ -34,22 +34,10 @@
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <stdarg.h>
#include <stdio.h>
#include "QF/cbuf.h"
#include "QF/crc.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/hash.h"
#include "QF/idparse.h"
#include "QF/progs.h"
#include "QF/qdefs.h"
#include "QF/qendian.h"
#include "QF/quakefs.h"
#include "QF/sys.h"
#include "QF/zone.h"
#include "QF/va.h"
#include "compat.h"

View file

@ -34,22 +34,17 @@
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <stdarg.h>
#include <stdio.h>
#include "QF/cmd.h"
#include "QF/crc.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/hash.h"
#include "QF/mathlib.h"
#include "QF/progs.h"
#include "QF/qdefs.h"
#include "QF/qendian.h"
#include "QF/quakefs.h"
#include "QF/sys.h"
#include "QF/zone.h"
#include "QF/va.h"
#include "compat.h"

View file

@ -43,21 +43,12 @@
#include <malloc.h>
#endif
#include "QF/cbuf.h"
#include "QF/crc.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/hash.h"
#include "QF/mathlib.h"
#include "QF/progs.h"
#include "QF/qdefs.h"
#include "QF/qfplist.h"
#include "QF/qendian.h"
#include "QF/quakefs.h"
#include "QF/script.h"
#include "QF/sys.h"
#include "QF/zone.h"
#include "QF/va.h"
#include "compat.h"
@ -301,6 +292,7 @@ ED_ParseEpair (progs_t *pr, pr_type_t *base, pr_def_t *key, const char *s)
VISIBLE plitem_t *
ED_ConvertToPlist (script_t *script, int nohack)
{
dstring_t *dstr = dstring_newstr ();
plitem_t *plist = PL_NewArray ();
plitem_t *ent;
plitem_t *key;
@ -341,15 +333,18 @@ ED_ConvertToPlist (script_t *script, int nohack)
token = script->token->str;
if (strequal (token, "}"))
Sys_Error ("ED_ConvertToPlist: closing brace without data");
if (anglehack)
value = PL_NewString (va ("0 %s 0", token));
else
if (anglehack) {
dsprintf (dstr, "0 %s 0", token);
value = PL_NewString (dstr->str);
} else {
value = PL_NewString (token);
}
PL_D_AddObject (ent, PL_String (key), value);
PL_Free (key);
}
PL_A_AddObject (plist, ent);
}
dstring_delete (dstr);
return plist;
}

View file

@ -34,23 +34,14 @@
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <stdarg.h>
#include <stdio.h>
#include "QF/cmd.h"
#include "QF/crc.h"
#include "QF/cvar.h"
#include "QF/hash.h"
#include "QF/progs.h"
#include "QF/qdefs.h"
#include "QF/qendian.h"
#include "QF/quakefs.h"
#include "QF/sys.h"
#include "QF/zone.h"
#include "QF/va.h"
#include "compat.h"
static const char param_str[] = ".param_0";
pr_def_t *
PR_GlobalAtOfs (progs_t * pr, pointer_t ofs)
@ -124,11 +115,14 @@ PR_ResolveGlobals (progs_t *pr)
pr->pr_param_size = OFS_PARM1 - OFS_PARM0;
pr->pr_param_alignment = 0; // log2
} else {
char *param_n = alloca (sizeof (param_str));
strcpy (param_n, param_str);
if (!(def = PR_FindGlobal (pr, sym = ".return")))
goto error;
pr->pr_return = &pr->pr_globals[def->ofs];
for (i = 0; i < MAX_PARMS; i++) {
if (!(def = PR_FindGlobal (pr, sym = va(".param_%d", i))))
param_n[sizeof (param_str) - 2] = i + '0';
if (!(def = PR_FindGlobal (pr, sym = param_n)))
goto error;
pr->pr_params[i] = &pr->pr_globals[def->ofs];
}

View file

@ -38,9 +38,7 @@
#include "QF/dstring.h"
#include "QF/progs.h"
#include "QF/quakefs.h"
#include "QF/va.h"
#include "QF/zone.h"
#include "QF/quakeio.h"
#include "rua_internal.h"