From 9072b0c98ba4f9412885a1a32002ee7214fd3dc0 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 30 Jan 2014 03:36:23 +0000 Subject: Attempting to fix OSX compatibility, it's not 100%, but it builds and most things seem to work. We've also tested against LLVM. --- Makefile | 2 +- src/compat/osx.h | 23 +++++++++++++++++++++++ src/stable/minicron.cpp | 2 +- src/stable/random.h | 2 +- src/stable/sharedcore.h | 2 +- src/stable/string.cpp | 16 ++++++++++++++++ src/stable/string.h | 4 ++++ src/unstable/cachebase.h | 2 +- src/unstable/uuid.cpp | 18 +++++++++++++----- 9 files changed, 61 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 7997c4b..160e6c4 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ $(foreach fn,$(wildcard src/experimental/*.h),bu/$(notdir ${fn})): bu/%: src/exp ln -s ../$< $@ $(patsubst src/%,bu/%,$(wildcard src/compat/*.h)): bu/%: src/% - ln -s ../../$< $@ + mkdir -p bu/compat; ln -s ../../$< $@ autoconfig: autoconfig.cpp ${CXX} -o autoconfig autoconfig.cpp diff --git a/src/compat/osx.h b/src/compat/osx.h index 26dad4d..ae55507 100644 --- a/src/compat/osx.h +++ b/src/compat/osx.h @@ -21,6 +21,29 @@ #include +#define bu_inet_ntoa inet_ntoa +#define bu_inet_addr inet_addr +#define bu_select select +#define bu_socket socket +#define bu_shutdown shutdown +#define bu_htons htons +#define bu_htonl htonl +#define bu_gethostbyname gethostbyname +#define bu_freeaddrinfo freeaddrinfo +#define bu_getaddrinfo getaddrinfo +#define bu_connect connect +#define bu_getpeername getpeername +#define bu_setsockopt setsockopt +#define bu_bind bind +#define bu_listen listen +#define bu_accept accept +#define bu_send send +#define bu_recv recv +#define open64 open +#define lseek64 lseek + +#define bu_gai_strerror gai_strerror + #define pthread_yield() sched_yield() #endif /* __APPLE__ */ #endif diff --git a/src/stable/minicron.cpp b/src/stable/minicron.cpp index 2f7e868..9d98682 100644 --- a/src/stable/minicron.cpp +++ b/src/stable/minicron.cpp @@ -317,7 +317,7 @@ time_t Bu::MiniCron::TimerBasic::nextTime() if( tLast == -1 ) tLast = time( NULL ); - Bu::String::const_iterator i = sSpec.begin(); + Bu::String::const_iterator i = const_cast(sSpec).begin(); switch( lex( i ) ) { case tokDaily: diff --git a/src/stable/random.h b/src/stable/random.h index b02c9e5..6dc3b45 100644 --- a/src/stable/random.h +++ b/src/stable/random.h @@ -8,11 +8,11 @@ #define BU_RANDOM_H #include "bu/singleton.h" +#include "bu/randombase.h" #include namespace Bu { - class RandomBase; class Random : public Bu::Singleton { friend class Bu::Singleton; diff --git a/src/stable/sharedcore.h b/src/stable/sharedcore.h index be60588..e79c3d6 100644 --- a/src/stable/sharedcore.h +++ b/src/stable/sharedcore.h @@ -104,7 +104,7 @@ namespace Bu Shell clone() const { Shell s( dynamic_cast(*this) ); - s._hardCopy(); + dynamic_cast<_SharedType &>(s)._hardCopy(); return s; } diff --git a/src/stable/string.cpp b/src/stable/string.cpp index bf3aac0..1ceaec1 100644 --- a/src/stable/string.cpp +++ b/src/stable/string.cpp @@ -173,6 +173,17 @@ Bu::String::String( const Bu::String::const_iterator &s, append( s, e ); } +Bu::String::String( const Bu::String::iterator &s ) +{ + append( s ); +} + +Bu::String::String( const Bu::String::iterator &s, + const Bu::String::iterator &e ) +{ + append( s, e ); +} + Bu::String::~String() { } @@ -317,6 +328,11 @@ void Bu::String::append( const const_iterator &s, const const_iterator &e ) } } +void Bu::String::append( const iterator &s, const iterator &e ) +{ + append( const_iterator( s ), const_iterator( e ) ); +} + void Bu::String::prepend( const String & sData ) { prepend( sData.getStr(), sData.getSize() ); diff --git a/src/stable/string.h b/src/stable/string.h index 3f8452d..bd1fe6c 100644 --- a/src/stable/string.h +++ b/src/stable/string.h @@ -569,6 +569,8 @@ namespace Bu String( long nSize ); String( const const_iterator &s ); String( const const_iterator &s, const const_iterator &e ); + String( const iterator &s ); + String( const iterator &s, const iterator &e ); virtual ~String(); /** @@ -646,6 +648,8 @@ namespace Bu */ void append( const const_iterator &s, const const_iterator &e ); + void append( const iterator &s, const iterator &e ); + /** * Prepend another String to this one. *@param sData (String &) The String to prepend. diff --git a/src/unstable/cachebase.h b/src/unstable/cachebase.h index bb543dd..f3152d9 100644 --- a/src/unstable/cachebase.h +++ b/src/unstable/cachebase.h @@ -238,7 +238,7 @@ namespace Bu template CachePtr cast() { - return pCache->cast( *this ); + return pCache->template cast( *this ); } bool operator==( const MyType &rhs ) const diff --git a/src/unstable/uuid.cpp b/src/unstable/uuid.cpp index 304ea4a..bd6662a 100644 --- a/src/unstable/uuid.cpp +++ b/src/unstable/uuid.cpp @@ -9,6 +9,7 @@ #include "bu/file.h" #include "bu/formatter.h" #include "bu/membuf.h" +#include "bu/random.h" #include #ifdef WIN32 @@ -83,6 +84,7 @@ void Bu::Uuid::clear() Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType ) { + Uuid id; switch( eType ) { case Version1: @@ -90,19 +92,24 @@ Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType ) case Version3: case Version4: case Version5: + // Yeah... all of these are just random for now, a lot more + // platform specific code is required for a lot of these. + for( int j = 0; j < 16; j++ ) + { + id.data[j] = Bu::Random::rand(256); + } + break; + default: case System: #if defined(linux) Bu::File fIn( "/proc/sys/kernel/random/uuid", Bu::File::Read ); char dat[36]; fIn.read( dat, 36 ); - Uuid id; id.set( dat ); - return id; #elif defined(WIN32) UUID uuid; UuidCreate( &uuid ); - Uuid id; id.data[0] = ((unsigned char *)&uuid.Data1)[3]; id.data[1] = ((unsigned char *)&uuid.Data1)[2]; id.data[2] = ((unsigned char *)&uuid.Data1)[1]; @@ -113,11 +120,12 @@ Bu::Uuid Bu::Uuid::generate( Bu::Uuid::Type eType ) id.data[7] = ((unsigned char *)&uuid.Data3)[0]; memcpy( id.data+8, uuid.Data4, 8 ); - return id; #else -# error We should be using one of the other fallbacks, but your platform is not supported yet. Sorry. +#warning No platform specific UUID, falling back to random for now + return generate( Version4 ); #endif } + return id; } void Bu::Uuid::set( const Bu::String &sSrc ) -- cgit v1.2.3