Don't expose mutable sp_native_t.
This commit is contained in:
@@ -84,11 +84,11 @@ void CNativeOwner::UnbindWeakRef(const WeakNative &ref)
|
||||
IPluginContext *pContext;
|
||||
|
||||
pContext = ref.pl->GetBaseContext();
|
||||
if ((pContext->GetNativeByIndex(ref.idx, &native)) == SP_ERROR_NONE)
|
||||
{
|
||||
native->status = SP_NATIVE_UNBOUND;
|
||||
native->pfn = NULL;
|
||||
}
|
||||
pContext->GetRuntime()->UpdateNativeBinding(
|
||||
ref.idx,
|
||||
nullptr,
|
||||
0,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void CNativeOwner::DropEverything()
|
||||
|
||||
+11
-19
@@ -646,11 +646,7 @@ void CPlugin::DependencyDropped(CPlugin *pOwner)
|
||||
if (m_pRuntime->FindNativeByName(entry->name(), &idx) != SP_ERROR_NONE)
|
||||
continue;
|
||||
|
||||
sp_native_t *native;
|
||||
m_pRuntime->GetNativeByIndex(idx, &native);
|
||||
|
||||
native->pfn = NULL;
|
||||
native->status = SP_NATIVE_UNBOUND;
|
||||
m_pRuntime->UpdateNativeBinding(idx, nullptr, 0, nullptr);
|
||||
unbound++;
|
||||
}
|
||||
|
||||
@@ -1357,16 +1353,14 @@ bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxleng
|
||||
/* Find any unbound natives. Right now, these are not allowed. */
|
||||
IPluginContext *pContext = pPlugin->GetBaseContext();
|
||||
uint32_t num = pContext->GetNativesNum();
|
||||
sp_native_t *native;
|
||||
for (unsigned int i=0; i<num; i++)
|
||||
{
|
||||
if (pContext->GetNativeByIndex(i, &native) != SP_ERROR_NONE)
|
||||
{
|
||||
const sp_native_t *native = pContext->GetRuntime()->GetNative(i);
|
||||
if (!native)
|
||||
break;
|
||||
}
|
||||
if (native->status == SP_NATIVE_UNBOUND
|
||||
&& native->name[0] != '@'
|
||||
&& !(native->flags & SP_NTVFLAG_OPTIONAL))
|
||||
if (native->status == SP_NATIVE_UNBOUND &&
|
||||
native->name[0] != '@' &&
|
||||
!(native->flags & SP_NTVFLAG_OPTIONAL))
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
@@ -1478,16 +1472,14 @@ void CPluginManager::TryRefreshDependencies(CPlugin *pPlugin)
|
||||
*/
|
||||
IPluginContext *pContext = pPlugin->GetBaseContext();
|
||||
uint32_t num = pContext->GetNativesNum();
|
||||
sp_native_t *native;
|
||||
for (unsigned int i=0; i<num; i++)
|
||||
{
|
||||
if (pContext->GetNativeByIndex(i, &native) != SP_ERROR_NONE)
|
||||
{
|
||||
const sp_native_t *native = pContext->GetRuntime()->GetNative(i);
|
||||
if (!native)
|
||||
break;
|
||||
}
|
||||
if (native->status == SP_NATIVE_UNBOUND
|
||||
&& native->name[0] != '@'
|
||||
&& !(native->flags & SP_NTVFLAG_OPTIONAL))
|
||||
if (native->status == SP_NATIVE_UNBOUND &&
|
||||
native->name[0] != '@' &&
|
||||
!(native->flags & SP_NTVFLAG_OPTIONAL))
|
||||
{
|
||||
pPlugin->SetErrorState(Plugin_Error, "Native not found: %s", native->name);
|
||||
return;
|
||||
|
||||
+17
-17
@@ -271,7 +271,6 @@ PassRef<Native> ShareSystem::FindNative(const char *name)
|
||||
|
||||
void ShareSystem::BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly)
|
||||
{
|
||||
sp_native_t *native;
|
||||
uint32_t i, native_count;
|
||||
IPluginContext *pContext;
|
||||
|
||||
@@ -284,7 +283,8 @@ void ShareSystem::BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly)
|
||||
native_count = pContext->GetNativesNum();
|
||||
for (i = 0; i < native_count; i++)
|
||||
{
|
||||
if (pContext->GetNativeByIndex(i, &native) != SP_ERROR_NONE)
|
||||
const sp_native_t *native = pContext->GetRuntime()->GetNative(i);
|
||||
if (!native)
|
||||
continue;
|
||||
|
||||
// If we're already bound, no need to do anything else.
|
||||
@@ -314,8 +314,8 @@ void ShareSystem::BindNativeToPlugin(CPlugin *pPlugin, const Ref<Native> &entry)
|
||||
if (pContext->FindNativeByName(entry->name(), &i) != SP_ERROR_NONE)
|
||||
return;
|
||||
|
||||
sp_native_t *native;
|
||||
if (pContext->GetNativeByIndex(i, &native) != SP_ERROR_NONE)
|
||||
const sp_native_t *native = pContext->GetRuntime()->GetNative(i);
|
||||
if (!native)
|
||||
return;
|
||||
|
||||
if (native->status == SP_NATIVE_BOUND)
|
||||
@@ -324,18 +324,15 @@ void ShareSystem::BindNativeToPlugin(CPlugin *pPlugin, const Ref<Native> &entry)
|
||||
BindNativeToPlugin(pPlugin, native, i, entry);
|
||||
}
|
||||
|
||||
void ShareSystem::BindNativeToPlugin(CPlugin *pPlugin, sp_native_t *native, uint32_t index,
|
||||
void ShareSystem::BindNativeToPlugin(CPlugin *pPlugin, const sp_native_t *native, uint32_t index,
|
||||
const Ref<Native> &pEntry)
|
||||
{
|
||||
/* Mark as bound... we do the rest next. */
|
||||
native->status = SP_NATIVE_BOUND;
|
||||
native->pfn = pEntry->func();
|
||||
|
||||
uint32_t flags = 0;
|
||||
if (pEntry->fake)
|
||||
{
|
||||
/* This native is not necessarily optional, but we don't guarantee
|
||||
* that its address is long-lived. */
|
||||
native->flags |= SP_NTVFLAG_EPHEMERAL;
|
||||
flags |= SP_NTVFLAG_EPHEMERAL;
|
||||
}
|
||||
|
||||
/* We don't bother with dependency crap if the owner is Core. */
|
||||
@@ -345,10 +342,9 @@ void ShareSystem::BindNativeToPlugin(CPlugin *pPlugin, sp_native_t *native, uint
|
||||
if ((native->flags & SP_NTVFLAG_OPTIONAL) == SP_NTVFLAG_OPTIONAL)
|
||||
{
|
||||
/* Only add if there is a valid owner. */
|
||||
if (pEntry->owner)
|
||||
pEntry->owner->AddWeakRef(WeakNative(pPlugin, index));
|
||||
else
|
||||
native->status = SP_NATIVE_UNBOUND;
|
||||
if (!pEntry->owner)
|
||||
return;
|
||||
pEntry->owner->AddWeakRef(WeakNative(pPlugin, index));
|
||||
}
|
||||
/* Otherwise, we're a strong dependent and not a weak one */
|
||||
else
|
||||
@@ -367,6 +363,12 @@ void ShareSystem::BindNativeToPlugin(CPlugin *pPlugin, sp_native_t *native, uint
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pPlugin->GetRuntime()->UpdateNativeBinding(
|
||||
index,
|
||||
pEntry->func(),
|
||||
flags,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
PassRef<Native> ShareSystem::AddNativeToCache(CNativeOwner *pOwner, const sp_nativeinfo_t *ntv)
|
||||
@@ -468,9 +470,7 @@ FeatureStatus ShareSystem::TestNative(IPluginRuntime *pRuntime, const char *name
|
||||
|
||||
if (pRuntime->FindNativeByName(name, &index) == SP_ERROR_NONE)
|
||||
{
|
||||
sp_native_t *native;
|
||||
if (pRuntime->GetNativeByIndex(index, &native) == SP_ERROR_NONE)
|
||||
{
|
||||
if (const sp_native_t *native = pRuntime->GetNative(index)) {
|
||||
if (native->status == SP_NATIVE_BOUND)
|
||||
return FeatureStatus_Available;
|
||||
else
|
||||
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
private:
|
||||
ke::PassRef<Native> AddNativeToCache(CNativeOwner *pOwner, const sp_nativeinfo_t *ntv);
|
||||
void ClearNativeFromCache(CNativeOwner *pOwner, const char *name);
|
||||
void BindNativeToPlugin(CPlugin *pPlugin, sp_native_t *ntv, uint32_t index, const ke::Ref<Native> &pEntry);
|
||||
void BindNativeToPlugin(CPlugin *pPlugin, const sp_native_t *ntv, uint32_t index, const ke::Ref<Native> &pEntry);
|
||||
private:
|
||||
typedef NameHashSet<ke::Ref<Native>, Native> NativeCache;
|
||||
|
||||
|
||||
@@ -457,7 +457,6 @@ static cell_t MarkNativeAsOptional(IPluginContext *pContext, const cell_t *param
|
||||
{
|
||||
char *name;
|
||||
uint32_t idx;
|
||||
sp_native_t *native;
|
||||
|
||||
pContext->LocalToString(params[1], &name);
|
||||
if (pContext->FindNativeByName(name, &idx) != SP_ERROR_NONE)
|
||||
@@ -466,10 +465,7 @@ static cell_t MarkNativeAsOptional(IPluginContext *pContext, const cell_t *param
|
||||
return 0;
|
||||
}
|
||||
|
||||
pContext->GetNativeByIndex(idx, &native);
|
||||
|
||||
native->flags |= SP_NTVFLAG_OPTIONAL;
|
||||
|
||||
pContext->GetRuntime()->UpdateNativeBinding(idx, nullptr, SP_NTVFLAG_OPTIONAL, nullptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user