From be20b6d093e722cb748800b7acb89a74ccf1a2f0 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 28 Sep 2019 07:05:24 +1000 Subject: [PATCH] Move platform-specific dynamic lib default file extension out of Game.c and into Platform.c where it belongs --- src/Game.c | 10 +--------- src/Platform.c | 13 +++++++++++-- src/Platform.h | 2 ++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Game.c b/src/Game.c index 38f3f4e3c..9e50f92a7 100644 --- a/src/Game.c +++ b/src/Game.c @@ -373,14 +373,6 @@ static void Game_LoadOptions(void) { static void Game_LoadPlugins(void) { } #else static void Game_LoadPlugin(const String* path, void* obj) { -#if defined CC_BUILD_WIN - static const String ext = String_FromConst(".dll"); -#elif defined CC_BUILD_OSX - static const String ext = String_FromConst(".dylib"); -#else - static const String ext = String_FromConst(".so"); -#endif - void* lib; void* verSymbol; /* EXPORT int Plugin_ApiVersion = GAME_API_VER; */ void* compSymbol; /* EXPORT struct IGameComponent Plugin_Component = { (whatever) } */ @@ -388,7 +380,7 @@ static void Game_LoadPlugin(const String* path, void* obj) { ReturnCode res; /* ignore accepted.txt, deskop.ini, .pdb files, etc */ - if (!String_CaselessEnds(path, &ext)) return; + if (!String_CaselessEnds(path, &DynamicLib_Ext)) return; res = DynamicLib_Load(path, &lib); if (res) { Logger_DynamicLibWarn2(res, "loading plugin", path); return; } diff --git a/src/Platform.c b/src/Platform.c index 7633862a9..1b47e53d1 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -1339,6 +1339,8 @@ ReturnCode Updater_GetBuildTime(TimeMS* ms) { *-------------------------------------------------------Dynamic lib-------------------------------------------------------* *#########################################################################################################################*/ #if defined CC_BUILD_WIN +const String DynamicLib_Ext = String_FromConst(".dll"); + ReturnCode DynamicLib_Load(const String* path, void** lib) { TCHAR str[NATIVE_STR_LEN]; Platform_ConvertString(str, path); @@ -1355,10 +1357,17 @@ bool DynamicLib_DescribeError(ReturnCode res, String* dst) { return Platform_DescribeError(res, dst); } #elif defined CC_BUILD_WEB -ReturnCode DynamicLib_Load(const String* path, void** lib) { return ERR_NOT_SUPPORTED; } +ReturnCode DynamicLib_Load(const String* path, void** lib) { return ERR_NOT_SUPPORTED; } ReturnCode DynamicLib_Get(void* lib, const char* name, void** symbol) { return ERR_NOT_SUPPORTED; } -bool DynamicLib_DescribeError(ReturnCode res, String* dst) { return false; } +bool DynamicLib_DescribeError(ReturnCode res, String* dst) { return false; } #elif defined CC_BUILD_POSIX +/* TODO: Should we use .bundle instead of .dylib? */ +#ifdef CC_BUILD_OSX +const String DynamicLib_Ext = String_FromConst(".dylib"); +#else +const String DynamicLib_Ext = String_FromConst(".so"); +#endif + ReturnCode DynamicLib_Load(const String* path, void** lib) { char str[NATIVE_STR_LEN]; Platform_ConvertString(str, path); diff --git a/src/Platform.h b/src/Platform.h index 561545c25..42ead942d 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -73,6 +73,8 @@ CC_API ReturnCode Updater_Start(void); /* Returns the last time the application was modified, as number of milliseconds since 1/1/0001 */ CC_API ReturnCode Updater_GetBuildTime(TimeMS* ms); +/* The default file extension used for dynamic libraries on this platform. */ +extern const String DynamicLib_Ext; /* Attempts to load a native dynamic library from the given path. */ CC_API ReturnCode DynamicLib_Load(const String* path, void** lib); /* Attempts to get the address of the symbol in the given dynamic library. */