From e7ac6376876591b361151d069a98abb1b258977d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 31 Jan 2022 23:45:29 +0900 Subject: [PATCH] [ruamoko] Wrap hash table callbacks with push/pop frame Builtins that call progs with parameters now must always wrap the call to PR_ExecuteProgram so that the data stack is properly preserved across the call. I need to do an audit of all the calls to PR_ExecuteProgram. --- libs/ruamoko/rua_hash.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libs/ruamoko/rua_hash.c b/libs/ruamoko/rua_hash.c index c2cf1f8f7..c4939e1e7 100644 --- a/libs/ruamoko/rua_hash.c +++ b/libs/ruamoko/rua_hash.c @@ -95,48 +95,59 @@ static const char * bi_get_key (const void *key, void *_ht) { bi_hashtab_t *ht = (bi_hashtab_t *)_ht; + PR_PushFrame (ht->pr); PR_RESET_PARAMS (ht->pr); P_INT (ht->pr, 0) = (intptr_t) (key); P_INT (ht->pr, 1) = ht->ud; ht->pr->pr_argc = 2; PR_ExecuteProgram (ht->pr, ht->gk); - return PR_GetString (ht->pr, R_STRING (ht->pr)); + pr_string_t string = R_STRING (ht->pr); + PR_PopFrame (ht->pr); + return PR_GetString (ht->pr, string); } static uintptr_t bi_get_hash (const void *key, void *_ht) { bi_hashtab_t *ht = (bi_hashtab_t *)_ht; + PR_PushFrame (ht->pr); PR_RESET_PARAMS (ht->pr); P_INT (ht->pr, 0) = (intptr_t) (key); P_INT (ht->pr, 1) = ht->ud; ht->pr->pr_argc = 2; PR_ExecuteProgram (ht->pr, ht->gh); - return R_INT (ht->pr); + int hash = R_INT (ht->pr); + PR_PopFrame (ht->pr); + return hash; } static int bi_compare (const void *key1, const void *key2, void *_ht) { bi_hashtab_t *ht = (bi_hashtab_t *)_ht; + PR_PushFrame (ht->pr); PR_RESET_PARAMS (ht->pr); P_INT (ht->pr, 0) = (intptr_t) (key1); P_INT (ht->pr, 1) = (intptr_t) (key2); P_INT (ht->pr, 2) = ht->ud; ht->pr->pr_argc = 3; PR_ExecuteProgram (ht->pr, ht->cmp); - return R_INT (ht->pr); + int cmp = R_INT (ht->pr); + PR_PopFrame (ht->pr); + return cmp; } static void bi_free (void *key, void *_ht) { bi_hashtab_t *ht = (bi_hashtab_t *)_ht; + PR_PushFrame (ht->pr); PR_RESET_PARAMS (ht->pr); P_INT (ht->pr, 0) = (intptr_t) (key); P_INT (ht->pr, 1) = ht->ud; ht->pr->pr_argc = 2; PR_ExecuteProgram (ht->pr, ht->f); + PR_PopFrame (ht->pr); } static void