Changeset 437 for trunk/src/core
- Timestamp:
- 07/23/15 08:30:41 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/library.cc
r433 r437 6 6 7 7 #include "nv/core/library.hh" 8 #include <string> 8 9 9 10 #if NV_PLATFORM == NV_WINDOWS … … 40 41 void library::open( string_view name ) 41 42 { 42 m_name .assign( name.data(), name.size() );43 m_name = name; 43 44 if ( !open() ) 44 45 { … … 51 52 bool nv::library::try_open( string_view name ) 52 53 { 53 m_name .assign( name.data(), name.size() );54 m_name = name; 54 55 if ( !open() ) 55 56 { … … 62 63 string_view library::get_name() const 63 64 { 64 return string_view( m_name.c_str(), m_name.size() );65 return m_name; 65 66 } 66 67 … … 71 72 return true; 72 73 } 73 NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : loading..." );74 NV_LOG_NOTICE( "library \"", m_name, "\" : loading..." ); 74 75 75 std::string name = m_name;76 std::string name( m_name.data(), m_name.length() ); 76 77 std::string ext( NV_LIB_EXT ); 77 78 … … 85 86 if ( m_handle == NULL ) 86 87 { 87 NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : failed to open!" );88 NV_LOG_NOTICE( "library \"", m_name, "\" : failed to open!" ); 88 89 return false; 89 90 } 90 NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : loaded." );91 91 return true; 92 92 } … … 97 97 if ( !result ) 98 98 { 99 NV_LOG_CRITICAL( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : can't find symbol \"", symbol, "\"" );99 NV_LOG_CRITICAL( "library \"", m_name, "\" : can't find symbol \"", symbol, "\"" ); 100 100 NV_ABORT( "Library symbol load failed!" ); 101 101 } … … 117 117 if ( ! NV_LIB_CLOSE( m_handle ) ) 118 118 { 119 NV_LOG_ERROR( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : can't close library!" );119 NV_LOG_ERROR( "library \"", m_name, "\" : can't close library!" ); 120 120 } 121 121 m_handle = nullptr; … … 130 130 } 131 131 132 std::stringlibrary::get_error()132 nv::string_view library::get_error() 133 133 { 134 134 #if NV_PLATFORM == NV_WINDOWS 135 135 // We do hate WinAPI for code like this, don't we? 136 LPTSTR buffer = nullptr; 137 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 138 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>( &buffer ), 0, NULL ); 139 std::string msg( reinterpret_cast<char*>( buffer ) ); 140 LocalFree( buffer ); 141 return msg; 136 static TCHAR buffer[256]; 137 FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 138 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>( &buffer ), 256, NULL ); 139 return string_view( reinterpret_cast<char*>( buffer ) ); 142 140 #elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE 143 return std::string( dlerror() );141 return nv::string_view( dlerror() ); 144 142 #else 145 return std::string("");143 return nv::string_view(); 146 144 #endif 147 145 }
Note: See TracChangeset
for help on using the changeset viewer.