Skip to content

Commit

Permalink
Fixed|Cleanup: Missing plugin entry points; plugin loading
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 2eeaf20 commit 2a80a52
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 32 deletions.
4 changes: 2 additions & 2 deletions doomsday/apps/api/apis.h
Expand Up @@ -186,7 +186,7 @@ typedef struct de_api_s {
#define DE_USING_API(Name) DE_EXTERN_C DE_DECLARE_API(Name)

#define DE_API_EXCHANGE(APIs) \
DE_EXTERN_C void deng_API(int id, void *api) { \
DE_ENTRYPOINT void deng_API(int id, void *api) { \
switch(id) { APIs \
default: break; } }
#define DE_GET_API(Ident, Name) \
Expand All @@ -197,7 +197,7 @@ typedef struct de_api_s {

#if defined (DE_STATIC_LINK)
#define DE_SYMBOL_PTR(var, symbolName) \
if (!qstrcmp(var, #symbolName)) { \
if (!strcmp(var, #symbolName)) { \
return reinterpret_cast<void *>(symbolName); \
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/plugins/example/src/example.c
Expand Up @@ -55,7 +55,7 @@ static int ExampleHook(int hookType, int parm, void *data)
* Declares the type of the plugin so the engine knows how to treat it. Called
* during plugin loading, before DP_Initialize().
*/
DE_EXTERN_C DE_VISIBLE_SYMBOL char const *deng_LibraryType(void)
DE_ENTRYPOINT char const *deng_LibraryType(void)
{
return "deng-plugin/generic";
}
Expand All @@ -64,7 +64,7 @@ DE_EXTERN_C DE_VISIBLE_SYMBOL char const *deng_LibraryType(void)
* This function is called automatically when the plugin is loaded. We let the
* engine know what we'd like to do.
*/
DE_EXTERN_C DE_VISIBLE_SYMBOL void DP_Initialize(void)
DE_ENTRYPOINT void DP_Initialize(void)
{
Plug_AddHook(HOOK_STARTUP, ExampleHook);
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/plugins/importsave/src/importsave.cpp
Expand Up @@ -87,7 +87,7 @@ int SavegameConvertHook(int /*hook_type*/, int /*parm*/, void *data)
* This function is called automatically when the plugin is loaded. We let the engine know
* what we'd like to do.
*/
void DP_Initialize()
DE_ENTRYPOINT void DP_Initialize()
{
Plug_AddHook(HOOK_SAVEGAME_CONVERT, SavegameConvertHook);
}
Expand All @@ -96,7 +96,7 @@ void DP_Initialize()
* Declares the type of the plugin so the engine knows how to treat it. Called automatically
* when the plugin is loaded.
*/
extern "C" char const *deng_LibraryType()
DE_ENTRYPOINT char const *deng_LibraryType()
{
return "deng-plugin/generic";
}
Expand Down
12 changes: 7 additions & 5 deletions doomsday/libs/doomsday/src/games.cpp
Expand Up @@ -191,15 +191,17 @@ GameProfile const *Games::firstPlayable() const

Game &Games::operator[](String const &id) const
{
if (id.isEmpty()) return *d->nullGame;

if (id.isEmpty())
{
return *d->nullGame;
}
if (auto *game = d->findById(id))
{
return *game;
}

/// @throw NotFoundError The specified @a identityKey string is not associated with a game in the collection.
throw NotFoundError("Games::operator []", "No game exists with ID '" + id + "'");
/// @throw NotFoundError The specified @a identityKey string is not associated with
/// a game in the collection.
throw NotFoundError("Games::operator[]", "No game exists with ID '" + id + "'");
}

bool Games::contains(String const &id) const
Expand Down
29 changes: 15 additions & 14 deletions doomsday/libs/doomsday/src/plugins.cpp
Expand Up @@ -94,21 +94,23 @@ DE_PIMPL_NOREF(Plugins)
return nullptr; // none available.
}

int loadPlugin(LibraryFile &lib)
bool loadPlugin(LibraryFile &lib)
{
typedef void (*PluginInitializer)(void);

#if !defined (DE_STATIC_LINK)
// We are only interested in native files.
if (!is<NativeFile>(lib.source()))
return 0; // Continue iteration.
{
return false;
}
#endif

DE_ASSERT(!lib.path().isEmpty());
if (lib.path().beginsWith("/bin/audio_", CaseInsensitive))
{
// Do not touch audio plugins at this point.
return true;
return false;
}

::Library *plugin = Library_New(lib.path());
Expand All @@ -119,18 +121,18 @@ DE_PIMPL_NOREF(Plugins)
if (fn.contains("libfmod") || fn.contains("libassimp"))
{
// No need to warn about these shared libs.
return 0;
return false;
}
#endif
LOG_RES_WARNING("Failed to load \"%s\": %s") << lib.path() << Library_LastError();
return 0; // Continue iteration.
return false;
}

if (!strcmp(Library_Type(plugin), "deng-plugin/audio"))
if (!iCmpStr(Library_Type(plugin), "deng-plugin/audio"))
{
// Audio plugins will be loaded later, on demand.
Library_Delete(plugin);
return 0;
return false;
}

PluginInitializer initializer = de::function_cast<void (*)()>(Library_Symbol(plugin, "DP_Initialize"));
Expand All @@ -141,7 +143,7 @@ DE_PIMPL_NOREF(Plugins)

// Clearly not a Doomsday plugin.
Library_Delete(plugin);
return 0; // Continue iteration.
return false;
}

// Assign a handle and ID to the plugin.
Expand All @@ -153,7 +155,7 @@ DE_PIMPL_NOREF(Plugins)
<< lib.path();

Library_Delete(plugin);
return 0; // Continue iteration.
return false;
}

// This seems to be a Doomsday plugin.
Expand All @@ -165,8 +167,7 @@ DE_PIMPL_NOREF(Plugins)
setActivePluginId(plugId);
initializer();
setActivePluginId(0);

return 0; // Continue iteration.
return true;
}

bool unloadPlugin(PluginHandle *handle)
Expand Down Expand Up @@ -217,9 +218,9 @@ void Plugins::loadAll()
{
LOG_RES_VERBOSE("Initializing plugins...");

Library_ForAll([this] (LibraryFile &lib)
{
return d->loadPlugin(lib);
Library_ForAll([this](LibraryFile &lib) {
d->loadPlugin(lib);
return LoopContinue;
});
}

Expand Down
8 changes: 1 addition & 7 deletions doomsday/libs/legacy/include/de/liblegacy.h
Expand Up @@ -79,16 +79,10 @@

#endif // !defined (DE_PUBLIC)

#if defined (DE_IOS)
# define DE_VISIBLE_SYMBOL __attribute__((visibility("default")))
#else
# define DE_VISIBLE_SYMBOL
#endif

#if defined (DE_STATIC_LINK)
# define DE_ENTRYPOINT static
#else
# define DE_ENTRYPOINT DE_EXTERN_C
# define DE_ENTRYPOINT DE_EXTERN_C DE_PUBLIC
#endif

#if !defined(_MSC_VER)
Expand Down

0 comments on commit 2a80a52

Please sign in to comment.