Ignore:
Timestamp:
06/13/15 21:51:27 (10 years ago)
Author:
epyon
Message:
  • cleanups of clang warnings (gotta love them all)
  • only nv-core for now (this will take a while for the whole source)
  • mainly C++ casts instead of C-style casts, but also a few bugs fixed!
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/library.cc

    r399 r402  
    1111#   include <windows.h>
    1212#   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 )
    1716#elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
    1817#   include <dlfcn.h>
    1918#   define NV_LIB_EXT ".so"
    20 #   define NV_LIB_HANDLE void*
    2119#   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 )
    2422#elif NV_PLATFORM == NV_APPLE
    2523#   include "macUtils.h"
    2624#   include <dlfcn.h>
    2725#   define NV_LIB_EXT ".dylib"
    28 #   define NV_LIB_HANDLE CFBundleRef
    2926#   define NV_LIB_OPEN( name ) mac_loadExeBundle( name )
    3027#   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 )
    3229#endif
    3330
     
    8380    }
    8481
    85     m_handle = (void*)NV_LIB_OPEN( name.c_str() );
     82    m_handle = NV_LIB_OPEN( name.c_str() );
    8683
    8784    if ( m_handle == NULL )
     
    9693void* library::get( string_view symbol )
    9794{
    98         void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.data() );
     95        void* result = NV_LIB_GET( m_handle, symbol.data() );
    9996    if ( !result )
    10097    {
     
    106103void* nv::library::try_get( string_view symbol )
    107104{
    108         return (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.data() );
     105        return NV_LIB_GET( m_handle, symbol.data() );
    109106}
    110107
     
    116113void library::close()
    117114{
    118     if ( NV_LIB_CLOSE( (NV_LIB_HANDLE)m_handle ) )
     115    if ( ! NV_LIB_CLOSE( m_handle ) )
    119116    {
    120117        NV_LOG_ERROR( "library : can't close library '", m_name, "'!" );
    121118    }
    122     m_handle = NULL;
     119    m_handle = nullptr;
    123120}
    124121
    125122library::~library()
    126123{
    127     if ( m_handle != NULL )
     124    if ( m_handle != nullptr )
    128125    {
    129126        close();
     
    135132#if NV_PLATFORM == NV_WINDOWS
    136133    // We do hate WinAPI for code like this, don't we?
    137     LPTSTR buffer = NULL;
     134    LPTSTR buffer = nullptr;
    138135    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 ) );
    141138    LocalFree( buffer );
    142139    return msg;
    143140#elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
    144     return string(dlerror());
     141    return std::string( dlerror() );
    145142#else
    146     return string("");
     143    return std::string("");
    147144#endif
    148145}
Note: See TracChangeset for help on using the changeset viewer.