Windows "compatibility"
* Makefile changes allowing for cross-compilation * SRDData: had to rename an enum member from ERROR to ERR because apparently creating a macro called ERROR is a thing in the windows headers * DynLib: ported * Strings: fixes in toOSString, untested for now * Fixes in some tests * TODO list update
This commit is contained in:
parent
ae2ad1f8b4
commit
30d8d3057e
9 changed files with 157 additions and 34 deletions
|
@ -7,9 +7,79 @@
|
|||
using namespace ebcl;
|
||||
|
||||
#ifdef _WIN32
|
||||
# error "Not implemented"
|
||||
#endif
|
||||
|
||||
/*= T_DynLibWindows ==========================================================*/
|
||||
|
||||
namespace {
|
||||
struct T_DynLibWindows_
|
||||
{
|
||||
T_Buffer< char > path;
|
||||
T_String error;
|
||||
HMODULE lib;
|
||||
|
||||
explicit T_DynLibWindows_( T_String const& path ) noexcept;
|
||||
explicit T_DynLibWindows_( char const* const path ) noexcept;
|
||||
~T_DynLibWindows_( ) noexcept;
|
||||
|
||||
bool load( ) noexcept;
|
||||
void unload( ) noexcept;
|
||||
|
||||
bool isLoaded( ) const noexcept;
|
||||
|
||||
void* getSymbol( char const* const symbol ) noexcept;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
inline T_DynLibWindows_::T_DynLibWindows_(
|
||||
T_String const& path ) noexcept
|
||||
: path( path.toOSString( ) ) , lib( nullptr )
|
||||
{ }
|
||||
|
||||
inline T_DynLibWindows_::T_DynLibWindows_(
|
||||
char const* const path ) noexcept
|
||||
: path( path , strlen( path ) ) , lib( nullptr )
|
||||
{ }
|
||||
|
||||
inline T_DynLibWindows_::~T_DynLibWindows_( ) noexcept
|
||||
{
|
||||
unload( );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
inline bool T_DynLibWindows_::load( ) noexcept
|
||||
{
|
||||
lib = LoadLibraryW( (wchar_t const*) path.data( ) );
|
||||
return lib != nullptr;
|
||||
}
|
||||
|
||||
inline void T_DynLibWindows_::unload( ) noexcept
|
||||
{
|
||||
if ( lib != nullptr ) {
|
||||
FreeLibrary( lib );
|
||||
lib = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool T_DynLibWindows_::isLoaded( ) const noexcept
|
||||
{
|
||||
return lib != nullptr;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
inline void* T_DynLibWindows_::getSymbol(
|
||||
char const* const symbol ) noexcept
|
||||
{
|
||||
return (void*) GetProcAddress( lib , symbol );
|
||||
}
|
||||
|
||||
using T_DynLibImpl_ = T_DynLibWindows_;
|
||||
|
||||
|
||||
#else // ifdef _WIN32
|
||||
|
||||
/*= T_DynLibLinux_ ===========================================================*/
|
||||
|
||||
|
@ -89,11 +159,12 @@ inline void* T_DynLibLinux_::getSymbol(
|
|||
return ptr;
|
||||
}
|
||||
|
||||
using T_DynLibImpl_ = T_DynLibLinux_;
|
||||
|
||||
#endif // ifdef _WIN32
|
||||
|
||||
/*= T_DynLib =================================================================*/
|
||||
|
||||
using T_DynLibImpl_ = T_DynLibLinux_; // FIXME
|
||||
|
||||
T_DynLib::T_DynLib(
|
||||
T_String const& name )
|
||||
: A_PrivateImplementation( new T_DynLibImpl_( name ) )
|
||||
|
|
|
@ -104,7 +104,7 @@ T_StringBuilder& ebcl::operator<< (
|
|||
void T_SRDErrors::checkAdded(
|
||||
T_SRDError const& last )
|
||||
{
|
||||
if ( last.type( ) != E_SRDErrorType::ERROR
|
||||
if ( last.type( ) != E_SRDErrorType::ERR
|
||||
|| errCount_ >= MAX_ERRORS ) {
|
||||
return;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ void T_SRDErrors::addAll(
|
|||
RPC_SRDLocation lastLocation = nullptr;
|
||||
for ( uint32_t i = 0 ; i < nErrors ; i ++ ) {
|
||||
errors_.add( source[ i ] );
|
||||
if ( source[ i ].type( ) == E_SRDErrorType::ERROR ) {
|
||||
if ( source[ i ].type( ) == E_SRDErrorType::ERR ) {
|
||||
lastLocation = &source[ i ].location( );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1677,14 +1677,16 @@ T_Buffer< char > T_String::toOSString( ) const
|
|||
#ifdef _WIN32
|
||||
|
||||
const auto n( data_->length( ) );
|
||||
T_Buffer< char > output( ( n + 1 ) * 2 );
|
||||
const auto rsz( MultiByteToWideChar( CP_UTF8 , 0 ,
|
||||
data( ) , data_->size( ) ,
|
||||
nullptr , 0 ) );
|
||||
T_Buffer< char > output( rsz * 2 );
|
||||
if ( !MultiByteToWideChar( CP_UTF8 , 0 ,
|
||||
data( ) , data_->size( ) ,
|
||||
( wchar_t* ) output.data( ) , n ) )
|
||||
( wchar_t* ) output.data( ) , rsz * 2 ) )
|
||||
{
|
||||
return T_Buffer< char >( );
|
||||
}
|
||||
output[ n * 2 ] = output[ n * 2 + 1 ] = 0;
|
||||
return output;
|
||||
|
||||
#else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue