From 162525457320b5dba9a4e736759f840757635231 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 18 Jul 2007 07:17:10 +0000 Subject: Incorporated a patch contributed by Brandon CS Sanders that allows libbu++ to compile under OSX. So far, no problems with anything else, it looks like build and nango both build without problems, libbu++ is truly becoming a full cross- platform toolkit. --- build.conf | 5 +- patches/libbu++-osx-compatability.patch | 85 +++++++++++++++++++++++++++++++++ src/fstring.h | 41 +++++++++++----- src/ito.cpp | 1 + src/server.cpp | 1 + src/serversocket.cpp | 11 +++-- src/socket.cpp | 1 + src/tests/fstring.cpp | 4 ++ src/unit/fstring.cpp | 9 ++++ 9 files changed, 142 insertions(+), 16 deletions(-) create mode 100644 patches/libbu++-osx-compatability.patch diff --git a/build.conf b/build.conf index e82cc29..36f1f8b 100644 --- a/build.conf +++ b/build.conf @@ -5,9 +5,10 @@ default action: check group "lnhdrs", check "libbu++.a" "all" action: check group "lnhdrs", check targets() set "CXXFLAGS" += "-ggdb -Wall" +#set "CXXFLAGS" += "-O2 -Wall" -#set "CXXFLAGS" += "-pg" -#set "LDFLAGS" += "-pg" +set "CXXFLAGS" += "-pg" +set "LDFLAGS" += "-pg" filesIn("src") filter regexp("^src/(.*)\\.h$", "src/bu/{re:1}.h"): rule "hln", diff --git a/patches/libbu++-osx-compatability.patch b/patches/libbu++-osx-compatability.patch new file mode 100644 index 0000000..73f4d7a --- /dev/null +++ b/patches/libbu++-osx-compatability.patch @@ -0,0 +1,85 @@ +Index: src/server.cpp +=================================================================== +--- src/server.cpp (revision 345) ++++ src/server.cpp (working copy) +@@ -3,6 +3,7 @@ + #include "bu/serversocket.h" + #include "bu/client.h" + #include "bu/socket.h" ++#include "osx_compatibility.h" + + Bu::Server::Server() : + nTimeoutSec( 0 ), +Index: src/socket.cpp +=================================================================== +--- src/socket.cpp (revision 345) ++++ src/socket.cpp (working copy) +@@ -13,6 +13,7 @@ + #include + #include "socket.h" + #include "exceptions.h" ++#include "osx_compatibility.h" + + #define RBS (1024*2) + +Index: src/osx_compatibility.h +=================================================================== +--- src/osx_compatibility.h (revision 0) ++++ src/osx_compatibility.h (revision 0) +@@ -0,0 +1,19 @@ ++#ifndef OSX_COMPATIBILITY__H ++#define OSX_COMPATIBILITY__H ++ ++#ifdef __APPLE__ ++ ++#ifndef TEMP_FAILURE_RETRY ++#define TEMP_FAILURE_RETRY(expression) \ ++ (__extension__ \ ++ ({ long int __result; \ ++ do __result = (long int) (expression); \ ++ while (__result == -1L && errno == EINTR); \ ++ __result; })) ++#endif ++ ++#include ++ ++#define pthread_yield() sched_yield() ++#endif /* __APPLE__ */ ++#endif +\ No newline at end of file +Index: src/serversocket.cpp +=================================================================== +--- src/serversocket.cpp (revision 345) ++++ src/serversocket.cpp (working copy) +@@ -13,6 +13,7 @@ + #include + #include "serversocket.h" + #include "exceptions.h" ++#include "osx_compatibility.h" + + Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) : + nPort( nPort ) +@@ -118,8 +119,12 @@ + (int *)&size + ); + #else +- nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size ); ++#ifdef __APPLE__ ++ nClient = ::accept( nServer, (struct sockaddr *)&clientname, (socklen_t*)&size ); ++#else ++ nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size ); + #endif ++#endif + if( nClient < 0 ) + { + throw SocketException( +Index: src/ito.cpp +=================================================================== +--- src/ito.cpp (revision 345) ++++ src/ito.cpp (working copy) +@@ -1,4 +1,5 @@ + #include "ito.h" ++#include "osx_compatibility.h" + + Bu::Ito::Ito() + { diff --git a/src/fstring.h b/src/fstring.h index 72ac99d..4dee537 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -25,11 +25,11 @@ namespace Bu * generation in mind. Like the standard string class you can specify what * datatype to use for each character. Unlike the standard string class, * collection of appended and prepended terms is done lazily, making long - * operations that involve many appends very inexpensive. In addition internal - * ref-counting means that if you pass strings around between functions there's - * almost no overhead in time or memory since a reference is created and no - * data is actually copied. This also means that you never need to put any - * FBasicString into a ref-counting container class. + * operations that involve many appends very inexpensive. In addition + * internal ref-counting means that if you pass strings around between + * functions there's almost no overhead in time or memory since a reference + * is created and no data is actually copied. This also means that you + * never need to put any FBasicString into a ref-counting container class. * *@param chr (typename) Type of character (i.e. char) *@param nMinSize (int) Chunk size (default: 256) @@ -126,7 +126,7 @@ namespace Bu for( nLen = 0; pData[nLen] != (chr)0; nLen++ ); if( nLen == 0 ) return; - + Chunk *pNew = newChunk( nLen ); cpy( pNew->pData, pData, nLen ); @@ -156,7 +156,16 @@ namespace Bu */ void append( const chr &cData ) { - append( &cData, 1 ); + if( pLast && pLast->nLength < nMinSize ) + { + pLast->pData[pLast->nLength] = cData; + ++pLast->nLength; ++nLength; + // pLast->pData[pLast->nLength] = (chr)0; + } + else + { + append( &cData, 1 ); + } } /** @@ -323,11 +332,21 @@ namespace Bu * Plus equals operator for FString. *@param pData (const chr) The character to append to your FString. */ - MyType &operator +=( const chr pData ) + MyType &operator +=( const chr cData ) { - append( &pData, 1 ); + if( pLast && pLast->nLength < nMinSize ) + { + pLast->pData[pLast->nLength] = cData; + ++pLast->nLength; ++nLength; + // pLast->pData[pLast->nLength] = (chr)0; + } + else + { + append( &cData, 1 ); + } + //append( pData ); - return (*this); + //return (*this); } /** @@ -714,7 +733,7 @@ namespace Bu Chunk *pNew = aChunk.allocate( 1 ); pNew->pNext = NULL; pNew->nLength = nLen; - pNew->pData = aChr.allocate( nLen+1 ); + pNew->pData = aChr.allocate( (nLenpData[nLen] = (chr)0; return pNew; } diff --git a/src/ito.cpp b/src/ito.cpp index 001ca06..231e822 100644 --- a/src/ito.cpp +++ b/src/ito.cpp @@ -1,4 +1,5 @@ #include "ito.h" +#include "osx_compatibility.h" Bu::Ito::Ito() { diff --git a/src/server.cpp b/src/server.cpp index d07a597..53b4301 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3,6 +3,7 @@ #include "bu/serversocket.h" #include "bu/client.h" #include "bu/socket.h" +#include "osx_compatibility.h" Bu::Server::Server() : nTimeoutSec( 0 ), diff --git a/src/serversocket.cpp b/src/serversocket.cpp index 1424630..010c562 100644 --- a/src/serversocket.cpp +++ b/src/serversocket.cpp @@ -13,6 +13,7 @@ #include #include "serversocket.h" #include "exceptions.h" +#include "osx_compatibility.h" Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) : nPort( nPort ) @@ -117,9 +118,13 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) nClient = ::accept( nServer, (struct sockaddr *)&clientname, (int *)&size ); -#else - nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size ); -#endif +#else /* not-cygwin */ +#ifdef __APPLE__ + nClient = ::accept( nServer, (struct sockaddr *)&clientname, (socklen_t*)&size ); +#else /* linux */ + nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size ); +#endif /* __APPLE__ */ +#endif /* __CYGWIN__ */ if( nClient < 0 ) { throw SocketException( diff --git a/src/socket.cpp b/src/socket.cpp index 50ed4e2..ce4ee82 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -13,6 +13,7 @@ #include #include "socket.h" #include "exceptions.h" +#include "osx_compatibility.h" #define RBS (1024*2) diff --git a/src/tests/fstring.cpp b/src/tests/fstring.cpp index 48dfc5f..11f147d 100644 --- a/src/tests/fstring.cpp +++ b/src/tests/fstring.cpp @@ -110,6 +110,10 @@ void doTimings() #define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() ); int main( int argc, char *argv ) { + Bu::FString fs1; + for( int j = 0; j < 500000; j++ ) fs1 += (char)('a'+(j%26)); + return 0; + Bu::FString str("th"); str.prepend("Hello "); diff --git a/src/unit/fstring.cpp b/src/unit/fstring.cpp index 2c6bf7a..462ce5e 100644 --- a/src/unit/fstring.cpp +++ b/src/unit/fstring.cpp @@ -9,6 +9,7 @@ public: setName("FString"); addTest( Unit::compare1 ); addTest( Unit::compare2 ); + addTest( Unit::appendSingle ); } virtual ~Unit() @@ -28,6 +29,14 @@ public: unitTest( !(b == "Bob") ); unitTest( b == "Bobo" ); } + + void appendSingle() + { + Bu::FString b; + for( char l = 'a'; l < 'g'; l++ ) + b += l; + unitTest( b == "abcdef" ); + } }; int main( int argc, char *argv[] ) -- cgit v1.2.3