changed the API - funcid_t is now index only rather than a code address

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40353
This commit is contained in:
David Anderson 2007-01-25 06:21:20 +00:00
parent f9a5920e5b
commit 2129bb6d92
7 changed files with 18 additions and 54 deletions

View File

@ -128,7 +128,7 @@ IPluginDebugInfo *BaseContext::GetDebugInfo()
return this;
}
int BaseContext::Execute(funcid_t funcid, cell_t *result)
int BaseContext::Execute(uint32_t code_addr, cell_t *result)
{
if (!m_Runnable)
{
@ -138,25 +138,8 @@ int BaseContext::Execute(funcid_t funcid, cell_t *result)
IVirtualMachine *vm = (IVirtualMachine *)ctx->vmbase;
uint32_t pushcount = ctx->pushcount;
uint32_t code_addr;
int err;
if (funcid & 1)
{
sp_public_t *pubfunc;
if ((err=GetPublicByIndex((funcid>>1), &pubfunc)) != SP_ERROR_NONE)
{
return err;
}
code_addr = pubfunc->code_offs;
} else {
#if 0
code_addr = funcid >> 1;
#endif
assert(false);
return SP_ERROR_INVALID_ADDRESS;
}
PushCell(pushcount++);
ctx->pushcount = 0;
@ -331,25 +314,6 @@ int BaseContext::FindNativeByName(const char *name, uint32_t *index)
high = ctx->plugin->info.natives_num - 1;
#if 0
while (low <= high)
{
mid = (low + high) / 2;
diff = strcmp(ctx->natives[mid].name, name);
if (diff == 0)
{
if (index)
{
*index = mid;
}
return SP_ERROR_NONE;
} else if (diff < 0) {
low = mid + 1;
} else {
high = mid - 1;
}
}
#else
for (uint32_t i=0; i<ctx->plugin->info.natives_num; i++)
{
if (strcmp(ctx->natives[i].name, name) == 0)
@ -361,7 +325,6 @@ int BaseContext::FindNativeByName(const char *name, uint32_t *index)
return SP_ERROR_NONE;
}
}
#endif
return SP_ERROR_NOT_FOUND;
}
@ -863,7 +826,6 @@ int BaseContext::LookupLine(ucell_t addr, uint32_t *line)
IPluginFunction *BaseContext::GetFunctionById(funcid_t func_id)
{
CFunction *pFunc = NULL;
funcid_t save = func_id;
if (func_id & 1)
{
@ -875,10 +837,11 @@ IPluginFunction *BaseContext::GetFunctionById(funcid_t func_id)
pFunc = m_pub_funcs[func_id];
if (!pFunc)
{
m_pub_funcs[func_id] = new CFunction(save, this);
m_pub_funcs[func_id] = new CFunction(ctx->publics[func_id].code_offs, this);
pFunc = m_pub_funcs[func_id];
}
} else {
/* :TODO: currently not used */
#if 0
func_id >>= 1;
unsigned int index;
@ -892,7 +855,7 @@ IPluginFunction *BaseContext::GetFunctionById(funcid_t func_id)
m_priv_funcs[func_id] = new CFunction(save, this);
pFunc = m_priv_funcs[func_id];
}
#endif
#endif 0
assert(false);
}
@ -915,7 +878,7 @@ IPluginFunction *BaseContext::GetFunctionByName(const char *public_name)
GetPublicByIndex(index, &pub);
if (pub)
{
m_pub_funcs[index] = new CFunction(pub->funcid, this);
m_pub_funcs[index] = new CFunction(pub->code_offs, this);
}
pFunc = m_pub_funcs[index];
}

View File

@ -47,7 +47,7 @@ namespace SourcePawn
virtual int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite);
virtual int BindNative(const sp_nativeinfo_t *native);
virtual int BindNativeToAny(SPVM_NATIVE_FUNC native);
virtual int Execute(funcid_t funcid, cell_t *result);
virtual int Execute(uint32_t code_addr, cell_t *result);
virtual void ThrowNativeErrorEx(int error, const char *msg, ...);
virtual cell_t ThrowNativeError(const char *msg, ...);
virtual IPluginFunction *GetFunctionByName(const char *public_name);

View File

@ -5,9 +5,9 @@
* FUNCTION CALLING *
********************/
void CFunction::Set(funcid_t funcid, IPluginContext *plugin)
void CFunction::Set(uint32_t code_addr, IPluginContext *plugin)
{
m_funcid = funcid;
m_codeaddr = code_addr;
m_pContext = plugin;
m_curparam = 0;
m_errorstate = SP_ERROR_NONE;
@ -20,7 +20,7 @@ int CFunction::CallFunction(const cell_t *params, unsigned int num_params, cell_
m_pContext->PushCell(params[num_params]);
}
return m_pContext->Execute(m_funcid, result);
return m_pContext->Execute(m_codeaddr, result);
}
IPluginContext *CFunction::GetParentContext()
@ -28,8 +28,8 @@ IPluginContext *CFunction::GetParentContext()
return m_pContext;
}
CFunction::CFunction(funcid_t funcid, IPluginContext *plugin) :
m_funcid(funcid), m_pContext(plugin), m_curparam(0),
CFunction::CFunction(uint32_t code_addr, IPluginContext *plugin) :
m_codeaddr(code_addr), m_pContext(plugin), m_curparam(0),
m_errorstate(SP_ERROR_NONE)
{
}

View File

@ -19,7 +19,7 @@ class CFunction : public IPluginFunction
{
friend class SourcePawnEngine;
public:
CFunction(funcid_t funcid, IPluginContext *pContext);
CFunction(uint32_t code_addr, IPluginContext *pContext);
public:
virtual int PushCell(cell_t cell);
virtual int PushCellByRef(cell_t *cell, int flags);
@ -34,7 +34,7 @@ public:
virtual int CallFunction(const cell_t *params, unsigned int num_params, cell_t *result);
virtual IPluginContext *GetParentContext();
public:
void Set(funcid_t funcid, IPluginContext *plugin);
void Set(uint32_t code_addr, IPluginContext *plugin);
private:
int _PushString(const char *string, int sz_flags, int cp_flags, size_t len);
inline int SetError(int err)
@ -43,7 +43,7 @@ private:
return err;
}
private:
funcid_t m_funcid;
uint32_t m_codeaddr;
IPluginContext *m_pContext;
cell_t m_params[SP_MAX_EXEC_PARAMS];
ParamInfo m_info[SP_MAX_EXEC_PARAMS];

View File

@ -19,6 +19,7 @@ enum AdminFlag
Admin_Password, /* Set a server password */
Admin_RCON, /* Use RCON */
Admin_Cheats, /* Change sv_cheats and use its commands */
Admin_Root, /* Root access */
/* --- */
AdminFlags_TOTAL,
};

View File

@ -44,6 +44,7 @@ namespace SourceMod
Admin_Password, /* Set a server password */
Admin_RCON, /* Use RCON */
Admin_Cheats, /* Change sv_cheats and use its commands */
Admin_Root, /* All access by default */
/* --- */
AdminFlags_TOTAL,
};

View File

@ -461,12 +461,11 @@ namespace SourcePawn
/**
* @brief Executes a function ID located in this context.
*
* @param funcid Function id to execute.
* @param code_addr Address to execute at.
* @param result Pointer to store the return value (required).
* @return Error code (if any) from the VM.
*/
virtual int Execute(uint32_t funcid, cell_t *result) =0;
virtual int Execute(uint32_t code_addr, cell_t *result) =0;
/**
* @brief Throws a error and halts any current execution.