From 70ad3d81288bca44196e61fd8619a2147b2c6125 Mon Sep 17 00:00:00 2001 From: Rick L Bird Date: Fri, 13 May 2011 21:41:48 -0400 Subject: [PATCH] More fixes to SC Core Hooks --- src/cque.c | 1 - src/modules.c | 65 ++++++++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/cque.c b/src/cque.c index 9047de5..1cb4665 100644 --- a/src/cque.c +++ b/src/cque.c @@ -1971,7 +1971,6 @@ void free_namedregs(HASHTAB * regs) { clear_namedregs(regs); - hashfree(regs); } void diff --git a/src/modules.c b/src/modules.c index 1429304..acc84cd 100644 --- a/src/modules.c +++ b/src/modules.c @@ -276,6 +276,13 @@ int CHook_Run(struct core_entry_t *entry, const char *format, ...) { va_list argp; + /* Environment Saving */ + char *preserve_wnxt[10], *preserve_rnxt[NUMQ]; + char *val_wnxt[10], *val_rnxt[NUMQ]; + char *preserves[10], *preserveq[NUMQ]; + HASHTAB preserve_namedregs; + char save_ccom[BUFFER_LEN]; + /* */ int rval; int (*module_func) (struct core_entry_t * entry, va_list argp); @@ -285,8 +292,31 @@ CHook_Run(struct core_entry_t *entry, const char *format, ...) module_func = NULL; /* Just for initialization purposes */ va_start(argp, format); if (entry->flags & MODHOOK_SOFTCODE) { + /* Step 1: Save Environment */ + save_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, val_wnxt, + val_rnxt); + save_global_regs("chook_sc_save", preserveq); + save_global_env("chook_sc_save", preserves); + init_namedregs(&preserve_namedregs); + copy_namedregs(&preserve_namedregs, &global_eval_context.namedregs); + clear_namedregs(&global_eval_context.namedregs); + init_namedregs(&global_eval_context.namedregs); + strncpy(save_ccom, global_eval_context.ccom, BUFFER_LEN); + /* Step 2: Call the Softcode Hook */ rval = CHook_SC(entry, format, argp); va_end(argp); + /* Step 3: Restore the Environment */ + memset(global_eval_context.ccom, '\0', BUFFER_LEN); + strcpy(global_eval_context.ccom, save_ccom); + clear_namedregs(&global_eval_context.namedregs); + init_namedregs(&global_eval_context.namedregs); + copy_namedregs(&global_eval_context.namedregs, &preserve_namedregs); + clear_namedregs(&preserve_namedregs); + restore_global_regs("chook_sc_save", preserveq); + restore_global_env("chook_sc_save", preserves); + restore_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, + val_wnxt, val_rnxt); + } else if (entry->flags & MODHOOK_MODULE) { /* We'll do this code later */ va_end(argp); @@ -306,13 +336,7 @@ CHook_Run(struct core_entry_t *entry, const char *format, ...) int CHook_SC(struct core_entry_t *entry, const char *format, va_list arguments) { - /* Register Saving */ - char *preserve_wnxt[10], *preserve_rnxt[NUMQ]; - char *val_wnxt[10], *val_rnxt[NUMQ]; - char *preserves[10], *preserveq[NUMQ]; - HASHTAB preserve_namedregs; - /* */ - struct softcode_hook *sc_hook; + struct softcode_hook *sc_hook; const char *s, *fptr; char cmd_buf[BUFFER_LEN], tbuf[BUFFER_LEN]; char *r; @@ -323,7 +347,6 @@ CHook_SC(struct core_entry_t *entry, const char *format, va_list arguments) int break_count, spot = 0; sc_hook = (struct softcode_hook *) entry->data; - strcpy(global_eval_context.ccom, ""); /* Before we bother with va_list .. Make sure A) Its a good object, B) Its a good attribute */ if (!GoodObject(sc_hook->obj)) @@ -331,15 +354,7 @@ CHook_SC(struct core_entry_t *entry, const char *format, va_list arguments) atr = atr_get(sc_hook->obj, sc_hook->attribute); if (!atr) return -1; - /* Save Environment */ - save_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, val_wnxt, - val_rnxt); - save_global_regs("chook_sc_save", preserveq); - save_global_env("chook_sc_save", preserves); - init_namedregs(&preserve_namedregs); - copy_namedregs(&preserve_namedregs, &global_eval_context.namedregs); - clear_namedregs(&global_eval_context.namedregs); - enactor = executor = cause = sc_hook->obj; + enactor = executor = cause = sc_hook->obj; /* Ok.. Now that we haev all the info we need we need to build a parse_que with 0-10 being the args passed */ for (fptr = format; fptr && *fptr; fptr++) { @@ -378,13 +393,6 @@ CHook_SC(struct core_entry_t *entry, const char *format, va_list arguments) "%s:%d -> Unexpected format character '%c' in format \"%s\"", __FILE__, __LINE__, *fptr, format); /* Restore Environment */ - copy_namedregs(&global_eval_context.namedregs, &preserve_namedregs); - free_namedregs(&preserve_namedregs); - restore_global_regs("chook_sc_save", preserveq); - restore_global_env("chook_sc_save", preserves); - restore_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, - val_wnxt, val_rnxt); - return -2; } } @@ -423,14 +431,7 @@ CHook_SC(struct core_entry_t *entry, const char *format, va_list arguments) ooref = local_ooref; } reset_cpu_timer(); - /* Restore Environment */ - copy_namedregs(&global_eval_context.namedregs, &preserve_namedregs); - free_namedregs(&preserve_namedregs); - restore_global_regs("chook_sc_save", preserveq); - restore_global_env("chook_sc_save", preserves); - restore_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, - val_wnxt, val_rnxt); - return 1; + return 1; } -- 2.30.2