From 3f25c996531774c82cdf5d342bca53dd3ea6e5de Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 13 Apr 2007 17:12:25 +0000 Subject: [PATCH] fixed a corruption bug when toggling debug mode --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40698 --- core/vm/sp_vm_basecontext.cpp | 66 ++++++++++++++++++++++++++--------- core/vm/sp_vm_basecontext.h | 5 ++- 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/core/vm/sp_vm_basecontext.cpp b/core/vm/sp_vm_basecontext.cpp index d855a624..9b2eab0d 100644 --- a/core/vm/sp_vm_basecontext.cpp +++ b/core/vm/sp_vm_basecontext.cpp @@ -42,9 +42,12 @@ BaseContext::BaseContext(sp_context_t *_ctx) m_InExec = false; m_CustomMsg = false; m_funcsnum = ctx->vmbase->FunctionCount(ctx); +#if 0 m_priv_funcs = NULL; +#endif m_pub_funcs = NULL; +#if 0 /** * Note: Since the m_plugin member will never change, * it is safe to assume the function count will never change @@ -56,6 +59,7 @@ BaseContext::BaseContext(sp_context_t *_ctx) } else { m_priv_funcs = NULL; } +#endif if (ctx->plugin->info.publics_num && m_pub_funcs == NULL) { @@ -66,44 +70,72 @@ BaseContext::BaseContext(sp_context_t *_ctx) } } -void BaseContext::FlushFunctionCache(bool remove) +void BaseContext::FlushFunctionCache() { if (m_pub_funcs) { for (uint32_t i=0; iplugin->info.publics_num; i++) { - if (remove) - { - delete m_pub_funcs[i]; - m_pub_funcs[i] = NULL; - } else if (m_pub_funcs[i]) { - m_pub_funcs[i]->Invalidate(); - } + delete m_pub_funcs[i]; + m_pub_funcs[i] = NULL; } } +#if 0 if (m_priv_funcs) { for (unsigned int i=0; iInvalidate(); - } + delete m_priv_funcs[i]; + m_priv_funcs[i] = NULL; } } +#endif +} + +void BaseContext::RefreshFunctionCache() +{ + if (m_pub_funcs) + { + sp_public_t *pub; + for (uint32_t i=0; iplugin->info.publics_num; i++) + { + if (!m_pub_funcs[i]) + { + continue; + } + if (GetPublicByIndex(i, &pub) != SP_ERROR_NONE) + { + continue; + } + m_pub_funcs[i]->Set(pub->code_offs, this); + } + } + +#if 0 + if (m_priv_funcs) + { + for (unsigned int i=0; i + } + } +#endif } BaseContext::~BaseContext() { - FlushFunctionCache(true); + FlushFunctionCache(); delete [] m_pub_funcs; m_pub_funcs = NULL; +#if 0 delete [] m_priv_funcs; m_priv_funcs = NULL; +#endif } void BaseContext::SetContext(sp_context_t *_ctx) @@ -115,7 +147,7 @@ void BaseContext::SetContext(sp_context_t *_ctx) ctx = _ctx; ctx->context = this; ctx->dbreak = GlobalDebugBreak; - FlushFunctionCache(false); + RefreshFunctionCache(); } IVirtualMachine *BaseContext::GetVirtualMachine() diff --git a/core/vm/sp_vm_basecontext.h b/core/vm/sp_vm_basecontext.h index e84ca66c..15977543 100644 --- a/core/vm/sp_vm_basecontext.h +++ b/core/vm/sp_vm_basecontext.h @@ -78,7 +78,8 @@ namespace SourcePawn void SetContext(sp_context_t *_ctx); private: void SetErrorMessage(const char *msg, va_list ap); - void FlushFunctionCache(bool remove); + void FlushFunctionCache(); + void RefreshFunctionCache(); private: sp_context_t *ctx; #if defined SOURCEMOD_BUILD @@ -88,7 +89,9 @@ namespace SourcePawn bool m_CustomMsg; bool m_InExec; unsigned int m_funcsnum; +#if 0 CFunction **m_priv_funcs; +#endif CFunction **m_pub_funcs; }; };