Remove native override API (bug 5852 part 1, r=ds).
authorDavid Anderson <dvander@alliedmods.net>
Fri Aug 30 10:10:57 2013 -0700 (2013-08-30)
changeset 4106a39557bde4ac
parent 4105 c523a3bcfa57
child 4107 5a723cf42aee
Remove native override API (bug 5852 part 1, r=ds).
core/logic/NativeInvoker.cpp
core/logic/NativeInvoker.h
core/logic/NativeOwner.cpp
core/logic/NativeOwner.h
core/logic/ShareSys.cpp
core/logic/ShareSys.h
public/IShareSys.h
     1.1 --- a/core/logic/NativeInvoker.cpp	Fri Aug 30 12:50:47 2013 -0700
     1.2 +++ b/core/logic/NativeInvoker.cpp	Fri Aug 30 10:10:57 2013 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /**
     1.5 - * vim: set ts=4 :
     1.6 + * vim: set ts=4 sw=4 tw=99 noet :
     1.7   * =============================================================================
     1.8   * SourcePawn
     1.9   * Copyright (C) 2004-2009 AlliedModders LLC.  All rights reserved.
    1.10 @@ -69,30 +69,15 @@
    1.11  
    1.12  bool NativeInvoker::Start(IPluginContext *pContext, const char *name)
    1.13  {
    1.14 -	NativeEntry *entry;
    1.15 -	
    1.16 -	entry = g_ShareSys.FindNative(name);
    1.17 -	if (entry == NULL)
    1.18 -	{
    1.19 +	NativeEntry *entry = g_ShareSys.FindNative(name);
    1.20 +	if (!entry)
    1.21  		return false;
    1.22 -	}
    1.23  
    1.24 -	native = NULL;
    1.25 -	if (entry->replacement.owner != NULL)
    1.26 -	{
    1.27 -		native = entry->replacement.func;
    1.28 -	}
    1.29 -	else if (entry->owner != NULL)
    1.30 -	{
    1.31 -		native = entry->func;
    1.32 -	}
    1.33 +	if (!entry->owner || !entry->func)
    1.34 +		return false;
    1.35  
    1.36 -	if (native == NULL)
    1.37 -	{
    1.38 -		return false;
    1.39 -	}
    1.40 -
    1.41 -	this->pContext = pContext;
    1.42 +	native_ = entry->func;
    1.43 +	context_ = pContext;
    1.44  
    1.45  	m_curparam = 0;
    1.46  	m_errorstate = SP_ERROR_NONE;
    1.47 @@ -184,15 +169,13 @@
    1.48  
    1.49  void NativeInvoker::Cancel()
    1.50  {
    1.51 -	if (pContext == NULL)
    1.52 -	{
    1.53 +	if (context_ == NULL)
    1.54  		return;
    1.55 -	}
    1.56  
    1.57  	m_errorstate = SP_ERROR_NONE;
    1.58  	m_curparam = 0;
    1.59 -	pContext = NULL;
    1.60 -	native = NULL;
    1.61 +	context_ = NULL;
    1.62 +	native_ = NULL;
    1.63  }
    1.64  
    1.65  int NativeInvoker::SetError(int err)
    1.66 @@ -205,10 +188,8 @@
    1.67  {
    1.68  	int err = SP_ERROR_NONE;
    1.69  
    1.70 -	if (pContext == NULL)
    1.71 -	{
    1.72 +	if (context_ == NULL)
    1.73  		return SP_ERROR_INVALID_NATIVE;
    1.74 -	}
    1.75  
    1.76  	if (m_errorstate != SP_ERROR_NONE)
    1.77  	{
    1.78 @@ -225,7 +206,7 @@
    1.79  	}
    1.80  
    1.81  	//This is for re-entrancy!
    1.82 -	IPluginContext *ctx = pContext;
    1.83 +	IPluginContext *ctx = context_;
    1.84  	cell_t _temp_params[SP_MAX_EXEC_PARAMS + 1];
    1.85  	cell_t *temp_params = &_temp_params[1];
    1.86  	ParamInfo temp_info[SP_MAX_EXEC_PARAMS];
    1.87 @@ -239,7 +220,7 @@
    1.88  		memcpy(temp_info, m_info, numparams * sizeof(ParamInfo));
    1.89  	}
    1.90  	m_curparam = 0;
    1.91 -	pContext = NULL;
    1.92 +	context_ = NULL;
    1.93  
    1.94  	/* Initialize 0th parameter */
    1.95  	_temp_params[0] = numparams;
    1.96 @@ -324,7 +305,7 @@
    1.97  	/* Make the call if we can */
    1.98  	if (err == SP_ERROR_NONE)
    1.99  	{
   1.100 -		*result = native(ctx, _temp_params);
   1.101 +		*result = native_(ctx, _temp_params);
   1.102  		if (ctx->GetLastNativeError() != SP_ERROR_NONE)
   1.103  		{
   1.104  			docopies = false;
     2.1 --- a/core/logic/NativeInvoker.h	Fri Aug 30 12:50:47 2013 -0700
     2.2 +++ b/core/logic/NativeInvoker.h	Fri Aug 30 10:10:57 2013 -0700
     2.3 @@ -75,8 +75,8 @@
     2.4  	int _PushString(const char *string, int sz_flags, int cp_flags, size_t len);
     2.5  	int SetError(int err);
     2.6  private:
     2.7 -	IPluginContext *pContext;
     2.8 -	SPVM_NATIVE_FUNC native;
     2.9 +	IPluginContext *context_;
    2.10 +	SPVM_NATIVE_FUNC native_;
    2.11  	cell_t m_params[SP_MAX_EXEC_PARAMS];
    2.12  	ParamInfo m_info[SP_MAX_EXEC_PARAMS];
    2.13  	unsigned int m_curparam;
     3.1 --- a/core/logic/NativeOwner.cpp	Fri Aug 30 12:50:47 2013 -0700
     3.2 +++ b/core/logic/NativeOwner.cpp	Fri Aug 30 10:10:57 2013 -0700
     3.3 @@ -123,16 +123,6 @@
     3.4  		iter = m_WeakRefs.erase(iter);
     3.5  	}
     3.6  
     3.7 -	/* Unmark our replacement natives */
     3.8 -	ntv_iter = m_ReplacedNatives.begin();
     3.9 -	while (ntv_iter != m_ReplacedNatives.end())
    3.10 -	{
    3.11 -		pEntry = (*ntv_iter);
    3.12 -		pEntry->replacement.func = NULL;
    3.13 -		pEntry->replacement.owner = NULL;
    3.14 -		ntv_iter = m_ReplacedNatives.erase(ntv_iter);
    3.15 -	}
    3.16 -
    3.17  	/* Strip all of our natives from the cache */
    3.18  	ntv_iter = m_Natives.begin();
    3.19  	while (ntv_iter != m_Natives.end())
    3.20 @@ -167,8 +157,3 @@
    3.21  	m_Dependents.remove(pPlugin);
    3.22  	DropWeakRefsTo(pPlugin);
    3.23  }
    3.24 -
    3.25 -void CNativeOwner::AddReplacedNative(NativeEntry *pEntry)
    3.26 -{
    3.27 -	m_ReplacedNatives.push_back(pEntry);
    3.28 -}
     4.1 --- a/core/logic/NativeOwner.h	Fri Aug 30 12:50:47 2013 -0700
     4.2 +++ b/core/logic/NativeOwner.h	Fri Aug 30 10:10:57 2013 -0700
     4.3 @@ -47,7 +47,6 @@
     4.4  	void AddDependent(CPlugin *pPlugin);
     4.5  	void AddWeakRef(const WeakNative & ref);
     4.6  	void DropRefsTo(CPlugin *pPlugin);
     4.7 -	void AddReplacedNative(NativeEntry *pEntry);
     4.8  private:
     4.9  	void DropWeakRefsTo(CPlugin *pPlugin);
    4.10  	void UnbindWeakRef(const WeakNative & ref);
    4.11 @@ -56,7 +55,6 @@
    4.12  	unsigned int m_nMarkSerial;
    4.13  	List<WeakNative> m_WeakRefs;
    4.14  	List<NativeEntry *> m_Natives;
    4.15 -	List<NativeEntry *> m_ReplacedNatives;
    4.16  };
    4.17  
    4.18  extern CNativeOwner g_CoreNatives;
     5.1 --- a/core/logic/ShareSys.cpp	Fri Aug 30 12:50:47 2013 -0700
     5.2 +++ b/core/logic/ShareSys.cpp	Fri Aug 30 10:10:57 2013 -0700
     5.3 @@ -35,6 +35,7 @@
     5.4  #include "common_logic.h"
     5.5  #include "PluginSys.h"
     5.6  #include "HandleSys.h"
     5.7 +#include <assert.h>
     5.8  
     5.9  ShareSystem g_ShareSys;
    5.10  static unsigned int g_mark_serial = 0;
    5.11 @@ -255,34 +256,7 @@
    5.12  
    5.13  void ShareSystem::OverrideNatives(IExtension *myself, const sp_nativeinfo_t *natives)
    5.14  {
    5.15 -	unsigned int i;
    5.16 -	NativeEntry *pEntry;
    5.17 -	CNativeOwner *pOwner;
    5.18 -
    5.19 -	pOwner = g_Extensions.GetNativeOwner(myself);
    5.20 -
    5.21 -	for (i = 0; natives[i].func != NULL && natives[i].name != NULL; i++)
    5.22 -	{
    5.23 -		if ((pEntry = FindNative(natives[i].name)) == NULL)
    5.24 -		{
    5.25 -			continue;
    5.26 -		}
    5.27 -
    5.28 -		if (pEntry->owner != &g_CoreNatives)
    5.29 -		{
    5.30 -			continue;
    5.31 -		}
    5.32 -
    5.33 -		if (pEntry->replacement.owner != NULL)
    5.34 -		{
    5.35 -			continue;
    5.36 -		}
    5.37 -
    5.38 -		/* Now it's safe to add the override */
    5.39 -		pEntry->replacement.func = natives[i].func;
    5.40 -		pEntry->replacement.owner = pOwner;
    5.41 -		pOwner->AddReplacedNative(pEntry);
    5.42 -	}
    5.43 +	assert(false);
    5.44  }
    5.45  
    5.46  NativeEntry *ShareSystem::FindNative(const char *name)
    5.47 @@ -295,7 +269,6 @@
    5.48  
    5.49  void ShareSystem::BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly)
    5.50  {
    5.51 -	NativeEntry *pEntry;
    5.52  	sp_native_t *native;
    5.53  	uint32_t i, native_count;
    5.54  	IPluginContext *pContext;
    5.55 @@ -310,34 +283,19 @@
    5.56  	for (i = 0; i < native_count; i++)
    5.57  	{
    5.58  		if (pContext->GetNativeByIndex(i, &native) != SP_ERROR_NONE)
    5.59 -		{
    5.60  			continue;
    5.61 -		}
    5.62  
    5.63 -		/* If we're bound, check if there is a replacement available.  
    5.64 -		 * If not, this native is totally finalized.
    5.65 -		 */
    5.66 +		// If we're already bound, no need to do anything else.
    5.67  		if (native->status == SP_NATIVE_BOUND)
    5.68 -		{
    5.69 -			pEntry = (NativeEntry *)native->user;
    5.70 -			assert(pEntry != NULL);
    5.71 -			if (pEntry->replacement.owner == NULL
    5.72 -				|| (pEntry->replacement.owner != NULL 
    5.73 -				&&  pEntry->replacement.func == native->pfn))
    5.74 -			{
    5.75 -				continue;
    5.76 -			}
    5.77 -		}
    5.78 +			continue;
    5.79 +
    5.80  		/* Otherwise, the native must be in our cache. */
    5.81 -		else if ((pEntry = FindNative(native->name)) == NULL)
    5.82 -		{
    5.83 +		NativeEntry *pEntry = FindNative(native->name);
    5.84 +		if (!pEntry)
    5.85  			continue;
    5.86 -		}
    5.87  
    5.88  		if (bCoreOnly && pEntry->owner != &g_CoreNatives)
    5.89 -		{
    5.90  			continue;
    5.91 -		}
    5.92  
    5.93  		BindNativeToPlugin(pPlugin, native, i, pEntry);
    5.94  	}
    5.95 @@ -377,49 +335,39 @@
    5.96  	native->status = SP_NATIVE_BOUND;
    5.97  	native->user = pEntry;
    5.98  
    5.99 -	/* See if a replacement is available. */
   5.100 -	if (pEntry->replacement.owner != NULL)
   5.101 +	/* Perform a bind. */
   5.102 +	native->pfn = pEntry->func;
   5.103 +
   5.104 +	/* We don't bother with dependency crap if the owner is Core. */
   5.105 +	if (pEntry->owner != &g_CoreNatives)
   5.106  	{
   5.107 -		/* Perform a replacement bind. */
   5.108 -		native->pfn = pEntry->replacement.func;
   5.109 -		pEntry->replacement.owner->AddWeakRef(WeakNative(pPlugin, index, pEntry));
   5.110 -	}
   5.111 -	else
   5.112 -	{
   5.113 -		/* Perform a normal bind. */
   5.114 -		native->pfn = pEntry->func;
   5.115 -
   5.116 -		/* We don't bother with dependency crap if the owner is Core. */
   5.117 -		if (pEntry->owner != &g_CoreNatives)
   5.118 +		/* The native is optional, this is a special case */
   5.119 +		if ((native->flags & SP_NTVFLAG_OPTIONAL) == SP_NTVFLAG_OPTIONAL)
   5.120  		{
   5.121 -			/* The native is optional, this is a special case */
   5.122 -			if ((native->flags & SP_NTVFLAG_OPTIONAL) == SP_NTVFLAG_OPTIONAL)
   5.123 +			/* Only add if there is a valid owner. */
   5.124 +			if (pEntry->owner != NULL)
   5.125  			{
   5.126 -				/* Only add if there is a valid owner. */
   5.127 -				if (pEntry->owner != NULL)
   5.128 -				{
   5.129 -					pEntry->owner->AddWeakRef(WeakNative(pPlugin, index));
   5.130 -				}
   5.131 -				else
   5.132 -				{
   5.133 -					native->status = SP_NATIVE_UNBOUND;
   5.134 -				}
   5.135 +				pEntry->owner->AddWeakRef(WeakNative(pPlugin, index));
   5.136  			}
   5.137 -			/* Otherwise, we're a strong dependent and not a weak one */
   5.138  			else
   5.139  			{
   5.140 -				/* See if this has already been marked as a dependent.
   5.141 -				 * If it has, it means this relationship has already occurred, 
   5.142 -				 * and there is no reason to do it again.
   5.143 -				 */
   5.144 -				if (pEntry->owner != pPlugin->ToNativeOwner() 
   5.145 -					&& pEntry->owner->GetMarkSerial() != g_mark_serial)
   5.146 -				{
   5.147 -					/* This has not been marked as a dependency yet */
   5.148 -					//pPlugin->AddDependency(pEntry->owner);
   5.149 -					pEntry->owner->AddDependent(pPlugin);
   5.150 -					pEntry->owner->SetMarkSerial(g_mark_serial);
   5.151 -				}
   5.152 +				native->status = SP_NATIVE_UNBOUND;
   5.153 +			}
   5.154 +		}
   5.155 +		/* Otherwise, we're a strong dependent and not a weak one */
   5.156 +		else
   5.157 +		{
   5.158 +			/* See if this has already been marked as a dependent.
   5.159 +			 * If it has, it means this relationship has already occurred, 
   5.160 +			 * and there is no reason to do it again.
   5.161 +			 */
   5.162 +			if (pEntry->owner != pPlugin->ToNativeOwner() 
   5.163 +				&& pEntry->owner->GetMarkSerial() != g_mark_serial)
   5.164 +			{
   5.165 +				/* This has not been marked as a dependency yet */
   5.166 +				//pPlugin->AddDependency(pEntry->owner);
   5.167 +				pEntry->owner->AddDependent(pPlugin);
   5.168 +				pEntry->owner->SetMarkSerial(g_mark_serial);
   5.169  			}
   5.170  		}
   5.171  	}
   5.172 @@ -436,8 +384,6 @@
   5.173  		pEntry->owner = pOwner;
   5.174  		pEntry->name = ntv->name;
   5.175  		pEntry->func = ntv->func;
   5.176 -		pEntry->replacement.func = NULL;
   5.177 -		pEntry->replacement.owner = NULL;
   5.178  		pEntry->fake = NULL;
   5.179  
   5.180  		m_NtvCache.insert(ntv->name, pEntry);
   5.181 @@ -481,8 +427,6 @@
   5.182  	pEntry->func = NULL;
   5.183  	pEntry->name = NULL;
   5.184  	pEntry->owner = NULL;
   5.185 -	pEntry->replacement.func = NULL;
   5.186 -	pEntry->replacement.owner = NULL;
   5.187  }
   5.188  
   5.189  NativeEntry *ShareSystem::AddFakeNative(IPluginFunction *pFunc, const char *name, SPVM_FAKENATIVE_FUNC func)
   5.190 @@ -518,8 +462,6 @@
   5.191  	pEntry->func = gate;
   5.192  	pEntry->name = pFake->name;
   5.193  	pEntry->owner = g_PluginSys.GetPluginByCtx(pFake->ctx->GetContext());
   5.194 -	pEntry->replacement.func = NULL;
   5.195 -	pEntry->replacement.owner = NULL;
   5.196  
   5.197  	return pEntry;
   5.198  }
   5.199 @@ -582,18 +524,13 @@
   5.200  	}
   5.201  
   5.202  	NativeEntry *entry = FindNative(name);
   5.203 -	if (entry == NULL)
   5.204 +	if (!entry)
   5.205  		return FeatureStatus_Unknown;
   5.206  
   5.207 -	if ((entry->replacement.owner != NULL || entry->owner != NULL) &&
   5.208 -		(entry->replacement.func != NULL || entry->func != NULL))
   5.209 -	{
   5.210 +	if (entry->owner && entry->func)
   5.211  		return FeatureStatus_Available;
   5.212 -	}
   5.213 -	else
   5.214 -	{
   5.215 -		return FeatureStatus_Unavailable;
   5.216 -	}
   5.217 +
   5.218 +	return FeatureStatus_Unavailable;
   5.219  }
   5.220  
   5.221  FeatureStatus ShareSystem::TestCap(const char *name)
     6.1 --- a/core/logic/ShareSys.h	Fri Aug 30 12:50:47 2013 -0700
     6.2 +++ b/core/logic/ShareSys.h	Fri Aug 30 10:10:57 2013 -0700
     6.3 @@ -65,12 +65,6 @@
     6.4  struct NativeEntry;
     6.5  class CPlugin;
     6.6  
     6.7 -struct ReplaceNative
     6.8 -{
     6.9 -	CNativeOwner *owner;
    6.10 -	SPVM_NATIVE_FUNC func;
    6.11 -};
    6.12 -
    6.13  struct FakeNative
    6.14  {
    6.15  	char name[64];
    6.16 @@ -83,7 +77,6 @@
    6.17  	CNativeOwner *owner;
    6.18  	SPVM_NATIVE_FUNC func;
    6.19  	const char *name;
    6.20 -	ReplaceNative replacement;
    6.21  	FakeNative *fake;
    6.22  
    6.23  	static inline bool matches(const char *name, const NativeEntry *entry)
     7.1 --- a/public/IShareSys.h	Fri Aug 30 12:50:47 2013 -0700
     7.2 +++ b/public/IShareSys.h	Fri Aug 30 10:10:57 2013 -0700
     7.3 @@ -1,5 +1,5 @@
     7.4  /**
     7.5 - * vim: set ts=4 :
     7.6 + * vim: set ts=4 sw=4 tw=99 noet :
     7.7   * =============================================================================
     7.8   * SourceMod
     7.9   * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
    7.10 @@ -234,23 +234,10 @@
    7.11  		virtual void RegisterLibrary(IExtension *myself, const char *name) =0;
    7.12  
    7.13  		/**
    7.14 -		 * @brief Adds natives that will override Core natives when called.
    7.15 -		 *
    7.16 -		 * A Core version of each native must exist.  If one does not, then 
    7.17 -		 * Core will simply ignore that entry.  No more than one override 
    7.18 -		 * can exist on a given native.
    7.19 +		 * @brief Deprecated. Does nothing.
    7.20  		 *
    7.21 -		 * Override natives represent a weak coupling.  If the extension is 
    7.22 -		 * unloaded, the native will be re-bound to the Core version.  If 
    7.23 -		 * the extension is loaded after plugins are loaded, the override 
    7.24 -		 * will not take effect until those plugins are reloaded.
    7.25 -		 * 
    7.26 -		 * @param myself		Identity token of parent object.
    7.27 -		 * @param natives		Array of natives to add.  The last entry in 
    7.28 -		 *						the array must be filled with NULLs to 
    7.29 -		 *						terminate the array.  The array must be static 
    7.30 -		 *						as Core will cache the pointer for the 
    7.31 -		 *						lifetime of the extension.
    7.32 +		 * @param myself        Ignored.
    7.33 +		 * @param natives       Ignored.
    7.34  		 */
    7.35  		virtual void OverrideNatives(IExtension *myself, const sp_nativeinfo_t *natives) =0;
    7.36