Don't expose mutable sp_native_t.
This commit is contained in:
@@ -111,8 +111,8 @@ CContextTrace::GetLastNative(uint32_t *index)
|
||||
if (lastNative < 0)
|
||||
return NULL;
|
||||
|
||||
sp_native_t *native;
|
||||
if (m_pRuntime->GetNativeByIndex(lastNative, &native) != SP_ERROR_NONE)
|
||||
const sp_native_t *native = m_pRuntime->GetNative(lastNative);
|
||||
if (!native)
|
||||
return NULL;
|
||||
|
||||
if (index)
|
||||
|
||||
@@ -173,12 +173,7 @@ static void BindNative(IPluginRuntime *rt, const char *name, SPVM_NATIVE_FUNC fn
|
||||
if ((err = rt->FindNativeByName(name, &index)) != SP_ERROR_NONE)
|
||||
return;
|
||||
|
||||
sp_native_t *native;
|
||||
if (rt->GetNativeByIndex(index, &native) != SP_ERROR_NONE)
|
||||
return;
|
||||
|
||||
native->pfn = fn;
|
||||
native->status = SP_NATIVE_BOUND;
|
||||
rt->UpdateNativeBinding(index, fn, 0, nullptr);
|
||||
}
|
||||
|
||||
static cell_t PrintFloat(IPluginContext *cx, const cell_t *params)
|
||||
|
||||
@@ -351,20 +351,32 @@ PluginRuntime::FindNativeByName(const char *name, uint32_t *index)
|
||||
|
||||
int
|
||||
PluginRuntime::GetNativeByIndex(uint32_t index, sp_native_t **native)
|
||||
{
|
||||
return SP_ERROR_PARAM;
|
||||
}
|
||||
|
||||
int
|
||||
PluginRuntime::UpdateNativeBinding(uint32_t index, SPVM_NATIVE_FUNC pfn, uint32_t flags, void *data)
|
||||
{
|
||||
if (index >= m_plugin.num_natives)
|
||||
return SP_ERROR_INDEX;
|
||||
|
||||
if (native)
|
||||
*native = &(m_plugin.natives[index]);
|
||||
sp_native_t *native = &m_plugin.natives[index];
|
||||
|
||||
native->pfn = pfn;
|
||||
native->status = pfn
|
||||
? SP_NATIVE_BOUND
|
||||
: SP_NATIVE_UNBOUND;
|
||||
native->flags = flags;
|
||||
native->user = data;
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
sp_native_t *
|
||||
PluginRuntime::GetNativeByIndex(uint32_t index)
|
||||
const sp_native_t *
|
||||
PluginRuntime::GetNative(uint32_t index)
|
||||
{
|
||||
assert(index < m_plugin.num_natives);
|
||||
if (index >= m_plugin.num_natives)
|
||||
return nullptr;
|
||||
return &m_plugin.natives[index];
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ class PluginRuntime
|
||||
virtual IPluginDebugInfo *GetDebugInfo();
|
||||
virtual int FindNativeByName(const char *name, uint32_t *index);
|
||||
virtual int GetNativeByIndex(uint32_t index, sp_native_t **native);
|
||||
virtual sp_native_t *GetNativeByIndex(uint32_t index);
|
||||
virtual uint32_t GetNativesNum();
|
||||
virtual int FindPublicByName(const char *name, uint32_t *index);
|
||||
virtual int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
|
||||
@@ -83,6 +82,8 @@ class PluginRuntime
|
||||
void SetName(const char *name);
|
||||
unsigned GetNativeReplacement(size_t index);
|
||||
ScriptedInvoker *GetPublicFunction(size_t index);
|
||||
int UpdateNativeBinding(uint32_t index, SPVM_NATIVE_FUNC pfn, uint32_t flags, void *data) KE_OVERRIDE;
|
||||
const sp_native_t *GetNative(uint32_t index) KE_OVERRIDE;
|
||||
|
||||
PluginContext *GetBaseContext();
|
||||
const sp_plugin_t *plugin() const {
|
||||
|
||||
@@ -1497,7 +1497,7 @@ Compiler::emitNativeCall(OPCODE op)
|
||||
__ subl(stk, dat);
|
||||
__ movl(Operand(eax, PluginContext::offsetOfSp()), stk);
|
||||
|
||||
sp_native_t *native = rt_->GetNativeByIndex(native_index);
|
||||
const sp_native_t *native = rt_->GetNative(native_index);
|
||||
if ((native->status != SP_NATIVE_BOUND) ||
|
||||
(native->flags & (SP_NTVFLAG_OPTIONAL | SP_NTVFLAG_EPHEMERAL)))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user