Common (Library): adds fast path for loading only one lib

This commit is contained in:
李通洲
2026-06-30 18:46:03 +08:00
parent 4cf060eb27
commit 9f446bdad7
2 changed files with 11 additions and 9 deletions
+4 -4
View File
@@ -27,7 +27,7 @@
#endif
#endif
static void* libraryLoad(const char* path, int maxVersion) {
void* ffLibraryLoadSingle(const char* path, int maxVersion) {
void* result = dlopen(path, FF_DLOPEN_FLAGS);
#if _WIN32
@@ -81,8 +81,8 @@ static void* libraryLoad(const char* path, int maxVersion) {
return result;
}
void* ffLibraryLoad(const char* path, int maxVersion, ...) {
void* result = libraryLoad(path, maxVersion);
void* ffLibraryLoadMulti(const char* path, int maxVersion, ...) {
void* result = ffLibraryLoadSingle(path, maxVersion);
if (!result) {
va_list defaultNames;
@@ -95,7 +95,7 @@ void* ffLibraryLoad(const char* path, int maxVersion, ...) {
}
int maxVersionRest = va_arg(defaultNames, int);
result = libraryLoad(pathRest, maxVersionRest);
result = ffLibraryLoadSingle(pathRest, maxVersionRest);
} while (!result);
va_end(defaultNames);
+7 -5
View File
@@ -35,9 +35,10 @@ static inline void ffLibraryUnload(void** handle) {
#define FF_LIBRARY_SYMBOL(symbolName) \
__typeof__(&symbolName) ff##symbolName;
#define FF_LIBRARY_LOAD(libraryObjectName, returnValue, ...) \
void* FF_A_CLEANUP(ffLibraryUnload) libraryObjectName = ffLibraryLoad(__VA_ARGS__, NULL); \
if (libraryObjectName == NULL) \
#define FF_LIBRARY_LOAD(libraryObjectName, returnValue, libraryFileName, maxVersion, ...) \
void* FF_A_CLEANUP(ffLibraryUnload) libraryObjectName = ffLibraryLoadSingle(libraryFileName, maxVersion); \
__VA_OPT__(if (__builtin_expect(libraryObjectName == NULL, false)) libraryObjectName = ffLibraryLoadMulti(__VA_ARGS__, NULL);) \
if (__builtin_expect(libraryObjectName == NULL, false)) \
return returnValue;
#define FF_LIBRARY_LOAD_MESSAGE(libraryObjectName, libraryFileName, maxVersion, ...) \
@@ -45,7 +46,7 @@ static inline void ffLibraryUnload(void** handle) {
#define FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, symbolMapping, symbolName, returnValue) \
symbolMapping = (__typeof__(&symbolName)) dlsym(library, #symbolName); \
if (symbolMapping == NULL) \
if (__builtin_expect(symbolMapping == NULL, false)) \
return returnValue;
#define FF_LIBRARY_LOAD_SYMBOL(library, symbolName, returnValue) \
@@ -66,7 +67,8 @@ static inline void ffLibraryUnload(void** handle) {
#define FF_LIBRARY_LOAD_SYMBOL_PTR(library, varName, symbolName, returnValue) \
FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName)->ff##symbolName, symbolName, returnValue);
void* ffLibraryLoad(const char* path, int maxVersion, ...);
void* ffLibraryLoadSingle(const char* path, int maxVersion);
void* ffLibraryLoadMulti(const char* path, int maxVersion, ...);
#else