Changeset 402 for trunk/src/core/library.cc
- Timestamp:
- 06/13/15 21:51:27 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/library.cc
r399 r402 11 11 # include <windows.h> 12 12 # define NV_LIB_EXT ".dll" 13 # define NV_LIB_HANDLE HMODULE 14 # define NV_LIB_OPEN( name ) LoadLibraryEx( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) 15 # define NV_LIB_GET( handle, name ) GetProcAddress( handle, name ) 16 # define NV_LIB_CLOSE( name ) !FreeLibrary( name ) 13 # define NV_LIB_OPEN( name ) static_cast<void*>( LoadLibraryEx( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) ) 14 # define NV_LIB_GET( handle, name ) reinterpret_cast<void*>( GetProcAddress( static_cast<HMODULE>( handle ), name ) ) 15 # define NV_LIB_CLOSE( handle ) ( FreeLibrary( static_cast<HMODULE>( handle ) ) != 0 ) 17 16 #elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE 18 17 # include <dlfcn.h> 19 18 # define NV_LIB_EXT ".so" 20 # define NV_LIB_HANDLE void*21 19 # define NV_LIB_OPEN( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL) 22 # define NV_LIB_GET( handle, name ) dlsym( handle, name )23 # define NV_LIB_CLOSE( name ) dlclose( name)20 # define NV_LIB_GET( handle, name ) dlsym( static_cast<void*>( handle ), name ) 21 # define NV_LIB_CLOSE( handle ) ( dlclose( static_cast<void*>( handle ) ) == 0 ) 24 22 #elif NV_PLATFORM == NV_APPLE 25 23 # include "macUtils.h" 26 24 # include <dlfcn.h> 27 25 # define NV_LIB_EXT ".dylib" 28 # define NV_LIB_HANDLE CFBundleRef29 26 # define NV_LIB_OPEN( name ) mac_loadExeBundle( name ) 30 27 # define NV_LIB_GET( handle, name ) mac_getBundleSym( handle, name ) 31 # define NV_LIB_CLOSE( name ) mac_unloadExeBundle( name)28 # define NV_LIB_CLOSE( handle ) ( mac_unloadExeBundle( handle ) == 0 ) 32 29 #endif 33 30 … … 83 80 } 84 81 85 m_handle = (void*)NV_LIB_OPEN( name.c_str() );82 m_handle = NV_LIB_OPEN( name.c_str() ); 86 83 87 84 if ( m_handle == NULL ) … … 96 93 void* library::get( string_view symbol ) 97 94 { 98 void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE)m_handle, symbol.data() );95 void* result = NV_LIB_GET( m_handle, symbol.data() ); 99 96 if ( !result ) 100 97 { … … 106 103 void* nv::library::try_get( string_view symbol ) 107 104 { 108 return (void*) NV_LIB_GET( (NV_LIB_HANDLE)m_handle, symbol.data() );105 return NV_LIB_GET( m_handle, symbol.data() ); 109 106 } 110 107 … … 116 113 void library::close() 117 114 { 118 if ( NV_LIB_CLOSE( (NV_LIB_HANDLE)m_handle ) )115 if ( ! NV_LIB_CLOSE( m_handle ) ) 119 116 { 120 117 NV_LOG_ERROR( "library : can't close library '", m_name, "'!" ); 121 118 } 122 m_handle = NULL;119 m_handle = nullptr; 123 120 } 124 121 125 122 library::~library() 126 123 { 127 if ( m_handle != NULL)124 if ( m_handle != nullptr ) 128 125 { 129 126 close(); … … 135 132 #if NV_PLATFORM == NV_WINDOWS 136 133 // We do hate WinAPI for code like this, don't we? 137 LPTSTR buffer = NULL;134 LPTSTR buffer = nullptr; 138 135 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 139 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buffer, 0, NULL );140 std::string msg( (char*)buffer);136 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>( &buffer ), 0, NULL ); 137 std::string msg( reinterpret_cast<char*>( buffer ) ); 141 138 LocalFree( buffer ); 142 139 return msg; 143 140 #elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE 144 return st ring(dlerror());141 return std::string( dlerror() ); 145 142 #else 146 return st ring("");143 return std::string(""); 147 144 #endif 148 145 }
Note: See TracChangeset
for help on using the changeset viewer.