Browse Source

platform: define platform-specific posix-compatible library loaders as macros to reduce macros hell in lib_posix.c

pull/2/head
Alibek Omarov 5 years ago
parent
commit
6e637456ef
  1. 5
      engine/platform/android/lib_android.h
  2. 2
      engine/platform/apple/lib_ios.h
  3. 5
      engine/platform/emscripten/lib_em.h
  4. 18
      engine/platform/posix/lib_posix.c

5
engine/platform/android/lib_android.h

@ -13,10 +13,15 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
*/ */
#pragma once #pragma once
#if XASH_ANDROID
#ifndef ANDROID_LIB_H #ifndef ANDROID_LIB_H
#define ANDROID_LIB_H #define ANDROID_LIB_H
#define Platform_POSIX_LoadLibrary( x ) Android_LoadLibrary(( x ))
#define Platform_POSIX_GetProcAddress( x, y ) Android_GetProcAddress(( x ), ( y ))
void *ANDROID_LoadLibrary( const char *dllname ); void *ANDROID_LoadLibrary( const char *dllname );
void *ANDROID_GetProcAddress( void *hInstance, const char *name ); void *ANDROID_GetProcAddress( void *hInstance, const char *name );
#endif // ANDROID_LIB_H #endif // ANDROID_LIB_H
#endif // XASH_ANDROID

2
engine/platform/apple/lib_ios.h

@ -17,6 +17,8 @@ GNU General Public License for more details.
#ifndef IOS_LIB_H #ifndef IOS_LIB_H
#define IOS_LIB_H #define IOS_LIB_H
#define Platform_POSIX_LoadLibrary( x ) IOS_LoadLibrary(( x ))
void *IOS_LoadLibrary( const char *dllname ); void *IOS_LoadLibrary( const char *dllname );
#endif // IOS_LIB_H #endif // IOS_LIB_H

5
engine/platform/emscripten/lib_em.h

@ -17,6 +17,11 @@ GNU General Public License for more details.
#ifndef EM_LIB_H #ifndef EM_LIB_H
#define EM_LIB_H #define EM_LIB_H
#define Platform_POSIX_LoadLibrary( x ) EMSCRIPTEN_LoadLibrary(( x ))
#ifndef EMSCRIPTEN_LIB_FS
#define Platform_POSIX_FreeLibrary( x ) // nothing
#endif // EMSCRIPTEN_LIB_FS
void *EMSCRIPTEN_LoadLibrary( const char *dllname ); void *EMSCRIPTEN_LoadLibrary( const char *dllname );
#endif // EM_LIB_H #endif // EM_LIB_H

18
engine/platform/posix/lib_posix.c

@ -72,12 +72,8 @@ void *COM_LoadLibrary( const char *dllname, int build_ordinals_table, qboolean d
COM_ResetLibraryError(); COM_ResetLibraryError();
// platforms where gameinfo mechanism is impossible // platforms where gameinfo mechanism is impossible
#if TARGET_OS_IPHONE #ifdef Platform_POSIX_LoadLibrary
return IOS_LoadLibrary( dllname ); return Platform_POSIX_LoadLibrary( dllname );
#elif defined( __EMSCRIPTEN__ )
return EMSCRIPTEN_LoadLibrary( dllname );
#elif defined( __ANDROID__ )
return ANDROID_LoadLibrary( dllname );
#endif #endif
// platforms where gameinfo mechanism is working goes here // platforms where gameinfo mechanism is working goes here
@ -156,9 +152,13 @@ void COM_FreeLibrary( void *hInstance )
return Loader_FreeLibrary( hInstance ); return Loader_FreeLibrary( hInstance );
else else
#endif #endif
#if !defined __EMSCRIPTEN__ || defined EMSCRIPTEN_LIB_FS {
#ifdef Platform_POSIX_FreeLibrary
Platform_POSIX_FreeLibrary( hInstance );
#else
dlclose( hInstance ); dlclose( hInstance );
#endif #endif
}
} }
void *COM_GetProcAddress( void *hInstance, const char *name ) void *COM_GetProcAddress( void *hInstance, const char *name )
@ -169,8 +169,8 @@ void *COM_GetProcAddress( void *hInstance, const char *name )
return Loader_GetProcAddress(hInstance, name); return Loader_GetProcAddress(hInstance, name);
else else
#endif #endif
#if defined(__ANDROID__) #if Platform_POSIX_GetProcAddress
return ANDROID_GetProcAddress( hInstance, name ); return Platform_POSIX_GetProcAddress( hInstance, name );
#else #else
return dlsym( hInstance, name ); return dlsym( hInstance, name );
#endif #endif

Loading…
Cancel
Save