GetContext() now returns 'this' as a hack (shouldn't+can't be accessed anyway) refac-jit
authorDavid Anderson <dvander@alliedmods.net>
Fri Jul 11 05:14:32 2008 +0000 (2008-07-11)
branchrefac-jit
changeset 2190880e81f30b5e
parent 2189 9596588fb029
child 2191 426832b7b7bd
GetContext() now returns 'this' as a hack (shouldn't+can't be accessed anyway)
public/sourcepawn/sp_vm_api.h
sourcepawn/jit/BaseRuntime.cpp
sourcepawn/jit/BaseRuntime.h
sourcepawn/jit/sp_vm_basecontext.cpp
sourcepawn/jit/sp_vm_basecontext.h
sourcepawn/jit/sp_vm_engine.cpp
sourcepawn/jit/x86/jit_x86.cpp
     1.1 --- a/public/sourcepawn/sp_vm_api.h	Thu Jul 10 05:42:10 2008 +0000
     1.2 +++ b/public/sourcepawn/sp_vm_api.h	Fri Jul 11 05:14:32 2008 +0000
     1.3 @@ -494,7 +494,9 @@
     1.4  		/**
     1.5  		 * @brief Deprecated, do not use.
     1.6  		 *
     1.7 -		 * @return				Opaque pointer.
     1.8 +		 * Returns the pointer of this object, casted to an opaque structure.
     1.9 +		 *
    1.10 +		 * @return				Returns this.
    1.11  		 */
    1.12  		virtual sp_context_t *GetContext() =0;
    1.13  
     2.1 --- a/sourcepawn/jit/BaseRuntime.cpp	Thu Jul 10 05:42:10 2008 +0000
     2.2 +++ b/sourcepawn/jit/BaseRuntime.cpp	Fri Jul 11 05:14:32 2008 +0000
     2.3 @@ -52,7 +52,7 @@
     2.4  
     2.5  void BaseRuntime::ClearCompile()
     2.6  {
     2.7 -	g_Jit1.FreeContextVars(m_pCtx->GetContext());
     2.8 +	g_Jit1.FreeContextVars(m_pCtx->GetCtx());
     2.9  	g_Jit1.FreePluginVars(m_pPlugin);
    2.10  }
    2.11  
    2.12 @@ -349,3 +349,9 @@
    2.13  
    2.14  	return mem;
    2.15  }
    2.16 +
    2.17 +BaseContext *BaseRuntime::GetBaseContext()
    2.18 +{
    2.19 +	return m_pCtx;
    2.20 +}
    2.21 +
     3.1 --- a/sourcepawn/jit/BaseRuntime.h	Thu Jul 10 05:42:10 2008 +0000
     3.2 +++ b/sourcepawn/jit/BaseRuntime.h	Fri Jul 11 05:14:32 2008 +0000
     3.3 @@ -45,6 +45,8 @@
     3.4  	virtual void SetPauseState(bool paused);
     3.5  	virtual bool IsPaused();
     3.6  	virtual size_t GetMemUsage();
     3.7 +public:
     3.8 +	BaseContext *GetBaseContext();
     3.9  private:
    3.10  	void ClearCompile();
    3.11  	void RefreshFunctionCache();
     4.1 --- a/sourcepawn/jit/sp_vm_basecontext.cpp	Thu Jul 10 05:42:10 2008 +0000
     4.2 +++ b/sourcepawn/jit/sp_vm_basecontext.cpp	Fri Jul 11 05:14:32 2008 +0000
     4.3 @@ -66,6 +66,11 @@
     4.4  
     4.5  sp_context_t *BaseContext::GetContext()
     4.6  {
     4.7 +	return reinterpret_cast<sp_context_t *>((IPluginContext * )this);
     4.8 +}
     4.9 +
    4.10 +sp_context_t *BaseContext::GetCtx()
    4.11 +{
    4.12  	return &m_ctx;
    4.13  }
    4.14  
    4.15 @@ -481,12 +486,14 @@
    4.16  
    4.17  SourceMod::IdentityToken_t *BaseContext::GetIdentity()
    4.18  {
    4.19 -	return m_pToken;
    4.20 -}
    4.21 +	SourceMod::IdentityToken_t *tok;
    4.22  
    4.23 -void BaseContext::SetIdentity(SourceMod::IdentityToken_t *token)
    4.24 -{
    4.25 -	m_pToken = token;
    4.26 +	if (GetKey(1, (void **)&tok))
    4.27 +	{
    4.28 +		return tok;
    4.29 +	}
    4.30 +
    4.31 +	return NULL;
    4.32  }
    4.33  
    4.34  cell_t *BaseContext::GetNullRef(SP_NULL_TYPE type)
    4.35 @@ -536,7 +543,7 @@
    4.36  		return SP_ERROR_NOT_RUNNABLE;
    4.37  	}
    4.38  
    4.39 -	if (m_ctx.hp + 16*sizeof(cell_t) > (cell_t)(m_ctx.sp - (sizeof(cell_t) * (num_params + 1))))
    4.40 +	if ((cell_t)(m_ctx.hp + 16*sizeof(cell_t)) > (cell_t)(m_ctx.sp - (sizeof(cell_t) * (num_params + 1))))
    4.41  	{
    4.42  		return SP_ERROR_STACKLOW;
    4.43  	}
     5.1 --- a/sourcepawn/jit/sp_vm_basecontext.h	Thu Jul 10 05:42:10 2008 +0000
     5.2 +++ b/sourcepawn/jit/sp_vm_basecontext.h	Fri Jul 11 05:14:32 2008 +0000
     5.3 @@ -49,6 +49,7 @@
     5.4  public: //IPluginContext
     5.5  	IVirtualMachine *GetVirtualMachine();
     5.6  	sp_context_t *GetContext();
     5.7 +	sp_context_t *GetCtx();
     5.8  	bool IsDebugging();
     5.9  	int SetDebugBreak(void *newpfn, void *oldpfn);
    5.10  	IPluginDebugInfo *GetDebugInfo();
    5.11 @@ -82,7 +83,6 @@
    5.12  	IPluginFunction *GetFunctionByName(const char *public_name);
    5.13  	IPluginFunction *GetFunctionById(funcid_t func_id);
    5.14  	SourceMod::IdentityToken_t *GetIdentity();
    5.15 -	void SetIdentity(SourceMod::IdentityToken_t *token);
    5.16  	cell_t *GetNullRef(SP_NULL_TYPE type);
    5.17  	int LocalToStringNULL(cell_t local_addr, char **addr);
    5.18  	int BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC native);
    5.19 @@ -100,7 +100,6 @@
    5.20  	void _SetErrorMessage(const char *msg, ...);
    5.21  private:
    5.22  	sp_plugin_t *m_pPlugin;
    5.23 -	SourceMod::IdentityToken_t *m_pToken;
    5.24  	cell_t *m_pNullVec;
    5.25  	cell_t *m_pNullString;
    5.26  	char m_MsgCache[1024];
     6.1 --- a/sourcepawn/jit/sp_vm_engine.cpp	Thu Jul 10 05:42:10 2008 +0000
     6.2 +++ b/sourcepawn/jit/sp_vm_engine.cpp	Fri Jul 11 05:14:32 2008 +0000
     6.3 @@ -329,9 +329,9 @@
     6.4  	{
     6.5  		uint32_t native = INVALID_CIP;
     6.6  
     6.7 -		if (m_CallStack->ctx->GetContext()->n_err)
     6.8 +		if (m_CallStack->ctx->GetCtx()->n_err)
     6.9  		{
    6.10 -			native = m_CallStack->ctx->GetContext()->n_idx;
    6.11 +			native = m_CallStack->ctx->GetCtx()->n_idx;
    6.12  		}
    6.13  
    6.14  		CContextTrace trace(m_CallStack, error, msg, native);
     7.1 --- a/sourcepawn/jit/x86/jit_x86.cpp	Thu Jul 10 05:42:10 2008 +0000
     7.2 +++ b/sourcepawn/jit/x86/jit_x86.cpp	Fri Jul 11 05:14:32 2008 +0000
     7.3 @@ -38,6 +38,8 @@
     7.4  #include "../jit_version.h"
     7.5  #include "../sp_vm_engine.h"
     7.6  #include "../engine2.h"
     7.7 +#include "BaseRuntime.h"
     7.8 +#include "../sp_vm_basecontext.h"
     7.9  
    7.10  #if defined USE_UNGEN_OPCODES
    7.11  #include "ungen_opcodes.h"
    7.12 @@ -2416,10 +2418,7 @@
    7.13  
    7.14  static cell_t InvalidNative(IPluginContext *pCtx, const cell_t *params)
    7.15  {
    7.16 -	sp_context_t *ctx = pCtx->GetContext();
    7.17 -	ctx->n_err = SP_ERROR_INVALID_NATIVE;
    7.18 -
    7.19 -	return 0;
    7.20 +	return pCtx->ThrowNativeErrorEx(SP_ERROR_INVALID_NATIVE, "Invalid native");
    7.21  }
    7.22  
    7.23  jitoffs_t RelocLookup(JitWriter *jit, cell_t pcode_offs, bool relative)
    7.24 @@ -2664,7 +2663,7 @@
    7.25  	 *************/
    7.26  
    7.27  	/* setup  basics */
    7.28 -	sp_context_t *ctx = data->runtime->GetDefaultContext()->GetContext();
    7.29 +	sp_context_t *ctx = data->runtime->GetBaseContext()->GetCtx();
    7.30  
    7.31  	/* Clear out any old cruft */
    7.32  	if (plugin->codebase != NULL)