From 4c1b6ce76ce62c287f3dde86b721c8e23ad2f587 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 26 Feb 2020 01:55:56 +0900 Subject: [PATCH] Make pr_parse thread safe Or at least, conversion to property list is thread safe. --- libs/gamecode/pr_parse.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/gamecode/pr_parse.c b/libs/gamecode/pr_parse.c index f17b69bf1..c63bb71b5 100644 --- a/libs/gamecode/pr_parse.c +++ b/libs/gamecode/pr_parse.c @@ -68,15 +68,11 @@ Easier to parse than PR_ValueString */ static const char * -PR_UglyValueString (progs_t *pr, etype_t type, pr_type_t *val) +PR_UglyValueString (progs_t *pr, etype_t type, pr_type_t *val, dstring_t *line) { - static dstring_t *line = 0; pr_def_t *def; dfunction_t *f; - if (!line) - line = dstring_new (); - type &= ~DEF_SAVEGLOBAL; switch (type) { @@ -121,6 +117,7 @@ PR_UglyValueString (progs_t *pr, etype_t type, pr_type_t *val) VISIBLE plitem_t * ED_EntityDict (progs_t *pr, edict_t *ed) { + dstring_t *dstr = dstring_newstr (); plitem_t *entity = PL_NewDictionary (); pr_uint_t i; int j; @@ -149,10 +146,11 @@ ED_EntityDict (progs_t *pr, edict_t *ed) if (j == pr_type_size[type]) continue; - value = PR_UglyValueString (pr, type, v); + value = PR_UglyValueString (pr, type, v, dstr); PL_D_AddObject (entity, name, PL_NewString (value)); } } + dstring_delete (dstr); return entity; } @@ -165,6 +163,7 @@ ED_EntityDict (progs_t *pr, edict_t *ed) VISIBLE plitem_t * ED_GlobalsDict (progs_t *pr) { + dstring_t *dstr = dstring_newstr (); plitem_t *globals = PL_NewDictionary (); pr_uint_t i; const char *name; @@ -183,9 +182,10 @@ ED_GlobalsDict (progs_t *pr) continue; name = PR_GetString (pr, def->name); - value = PR_UglyValueString (pr, type, &pr->pr_globals[def->ofs]); + value = PR_UglyValueString (pr, type, &pr->pr_globals[def->ofs], dstr); PL_D_AddObject (globals, name, PL_NewString (value)); } + dstring_delete (dstr); return globals; }