aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-07-18 07:17:10 +0000
committerMike Buland <eichlan@xagasoft.com>2007-07-18 07:17:10 +0000
commit162525457320b5dba9a4e736759f840757635231 (patch)
treeb00464b34a924f41622bebef4fa3b72750744bd6
parentd7ea32daa44c9e0cc4ac00a69168b4e1d182082b (diff)
downloadlibbu++-162525457320b5dba9a4e736759f840757635231.tar.gz
libbu++-162525457320b5dba9a4e736759f840757635231.tar.bz2
libbu++-162525457320b5dba9a4e736759f840757635231.tar.xz
libbu++-162525457320b5dba9a4e736759f840757635231.zip
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.
-rw-r--r--build.conf5
-rw-r--r--patches/libbu++-osx-compatability.patch85
-rw-r--r--src/fstring.h41
-rw-r--r--src/ito.cpp1
-rw-r--r--src/server.cpp1
-rw-r--r--src/serversocket.cpp11
-rw-r--r--src/socket.cpp1
-rw-r--r--src/tests/fstring.cpp4
-rw-r--r--src/unit/fstring.cpp9
9 files changed, 142 insertions, 16 deletions
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"
5"all" action: check group "lnhdrs", check targets() 5"all" action: check group "lnhdrs", check targets()
6 6
7set "CXXFLAGS" += "-ggdb -Wall" 7set "CXXFLAGS" += "-ggdb -Wall"
8#set "CXXFLAGS" += "-O2 -Wall"
8 9
9#set "CXXFLAGS" += "-pg" 10set "CXXFLAGS" += "-pg"
10#set "LDFLAGS" += "-pg" 11set "LDFLAGS" += "-pg"
11 12
12filesIn("src") filter regexp("^src/(.*)\\.h$", "src/bu/{re:1}.h"): 13filesIn("src") filter regexp("^src/(.*)\\.h$", "src/bu/{re:1}.h"):
13 rule "hln", 14 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 @@
1Index: src/server.cpp
2===================================================================
3--- src/server.cpp (revision 345)
4+++ src/server.cpp (working copy)
5@@ -3,6 +3,7 @@
6 #include "bu/serversocket.h"
7 #include "bu/client.h"
8 #include "bu/socket.h"
9+#include "osx_compatibility.h"
10
11 Bu::Server::Server() :
12 nTimeoutSec( 0 ),
13Index: src/socket.cpp
14===================================================================
15--- src/socket.cpp (revision 345)
16+++ src/socket.cpp (working copy)
17@@ -13,6 +13,7 @@
18 #include <fcntl.h>
19 #include "socket.h"
20 #include "exceptions.h"
21+#include "osx_compatibility.h"
22
23 #define RBS (1024*2)
24
25Index: src/osx_compatibility.h
26===================================================================
27--- src/osx_compatibility.h (revision 0)
28+++ src/osx_compatibility.h (revision 0)
29@@ -0,0 +1,19 @@
30+#ifndef OSX_COMPATIBILITY__H
31+#define OSX_COMPATIBILITY__H
32+
33+#ifdef __APPLE__
34+
35+#ifndef TEMP_FAILURE_RETRY
36+#define TEMP_FAILURE_RETRY(expression) \
37+ (__extension__ \
38+ ({ long int __result; \
39+ do __result = (long int) (expression); \
40+ while (__result == -1L && errno == EINTR); \
41+ __result; }))
42+#endif
43+
44+#include <sched.h>
45+
46+#define pthread_yield() sched_yield()
47+#endif /* __APPLE__ */
48+#endif
49\ No newline at end of file
50Index: src/serversocket.cpp
51===================================================================
52--- src/serversocket.cpp (revision 345)
53+++ src/serversocket.cpp (working copy)
54@@ -13,6 +13,7 @@
55 #include <fcntl.h>
56 #include "serversocket.h"
57 #include "exceptions.h"
58+#include "osx_compatibility.h"
59
60 Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) :
61 nPort( nPort )
62@@ -118,8 +119,12 @@
63 (int *)&size
64 );
65 #else
66- nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size );
67+#ifdef __APPLE__
68+ nClient = ::accept( nServer, (struct sockaddr *)&clientname, (socklen_t*)&size );
69+#else
70+ nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size );
71 #endif
72+#endif
73 if( nClient < 0 )
74 {
75 throw SocketException(
76Index: src/ito.cpp
77===================================================================
78--- src/ito.cpp (revision 345)
79+++ src/ito.cpp (working copy)
80@@ -1,4 +1,5 @@
81 #include "ito.h"
82+#include "osx_compatibility.h"
83
84 Bu::Ito::Ito()
85 {
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
25 * generation in mind. Like the standard string class you can specify what 25 * generation in mind. Like the standard string class you can specify what
26 * datatype to use for each character. Unlike the standard string class, 26 * datatype to use for each character. Unlike the standard string class,
27 * collection of appended and prepended terms is done lazily, making long 27 * collection of appended and prepended terms is done lazily, making long
28 * operations that involve many appends very inexpensive. In addition internal 28 * operations that involve many appends very inexpensive. In addition
29 * ref-counting means that if you pass strings around between functions there's 29 * internal ref-counting means that if you pass strings around between
30 * almost no overhead in time or memory since a reference is created and no 30 * functions there's almost no overhead in time or memory since a reference
31 * data is actually copied. This also means that you never need to put any 31 * is created and no data is actually copied. This also means that you
32 * FBasicString into a ref-counting container class. 32 * never need to put any FBasicString into a ref-counting container class.
33 * 33 *
34 *@param chr (typename) Type of character (i.e. char) 34 *@param chr (typename) Type of character (i.e. char)
35 *@param nMinSize (int) Chunk size (default: 256) 35 *@param nMinSize (int) Chunk size (default: 256)
@@ -126,7 +126,7 @@ namespace Bu
126 for( nLen = 0; pData[nLen] != (chr)0; nLen++ ); 126 for( nLen = 0; pData[nLen] != (chr)0; nLen++ );
127 if( nLen == 0 ) 127 if( nLen == 0 )
128 return; 128 return;
129 129
130 Chunk *pNew = newChunk( nLen ); 130 Chunk *pNew = newChunk( nLen );
131 cpy( pNew->pData, pData, nLen ); 131 cpy( pNew->pData, pData, nLen );
132 132
@@ -156,7 +156,16 @@ namespace Bu
156 */ 156 */
157 void append( const chr &cData ) 157 void append( const chr &cData )
158 { 158 {
159 append( &cData, 1 ); 159 if( pLast && pLast->nLength < nMinSize )
160 {
161 pLast->pData[pLast->nLength] = cData;
162 ++pLast->nLength; ++nLength;
163 // pLast->pData[pLast->nLength] = (chr)0;
164 }
165 else
166 {
167 append( &cData, 1 );
168 }
160 } 169 }
161 170
162 /** 171 /**
@@ -323,11 +332,21 @@ namespace Bu
323 * Plus equals operator for FString. 332 * Plus equals operator for FString.
324 *@param pData (const chr) The character to append to your FString. 333 *@param pData (const chr) The character to append to your FString.
325 */ 334 */
326 MyType &operator +=( const chr pData ) 335 MyType &operator +=( const chr cData )
327 { 336 {
328 append( &pData, 1 ); 337 if( pLast && pLast->nLength < nMinSize )
338 {
339 pLast->pData[pLast->nLength] = cData;
340 ++pLast->nLength; ++nLength;
341 // pLast->pData[pLast->nLength] = (chr)0;
342 }
343 else
344 {
345 append( &cData, 1 );
346 }
347 //append( pData );
329 348
330 return (*this); 349 //return (*this);
331 } 350 }
332 351
333 /** 352 /**
@@ -714,7 +733,7 @@ namespace Bu
714 Chunk *pNew = aChunk.allocate( 1 ); 733 Chunk *pNew = aChunk.allocate( 1 );
715 pNew->pNext = NULL; 734 pNew->pNext = NULL;
716 pNew->nLength = nLen; 735 pNew->nLength = nLen;
717 pNew->pData = aChr.allocate( nLen+1 ); 736 pNew->pData = aChr.allocate( (nLen<nMinSize)?(nMinSize):(nLen)+1 );
718 pNew->pData[nLen] = (chr)0; 737 pNew->pData[nLen] = (chr)0;
719 return pNew; 738 return pNew;
720 } 739 }
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 @@
1#include "ito.h" 1#include "ito.h"
2#include "osx_compatibility.h"
2 3
3Bu::Ito::Ito() 4Bu::Ito::Ito()
4{ 5{
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 @@
3#include "bu/serversocket.h" 3#include "bu/serversocket.h"
4#include "bu/client.h" 4#include "bu/client.h"
5#include "bu/socket.h" 5#include "bu/socket.h"
6#include "osx_compatibility.h"
6 7
7Bu::Server::Server() : 8Bu::Server::Server() :
8 nTimeoutSec( 0 ), 9 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 @@
13#include <fcntl.h> 13#include <fcntl.h>
14#include "serversocket.h" 14#include "serversocket.h"
15#include "exceptions.h" 15#include "exceptions.h"
16#include "osx_compatibility.h"
16 17
17Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) : 18Bu::ServerSocket::ServerSocket( int nPort, int nPoolSize ) :
18 nPort( nPort ) 19 nPort( nPort )
@@ -117,9 +118,13 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec )
117 nClient = ::accept( nServer, (struct sockaddr *)&clientname, 118 nClient = ::accept( nServer, (struct sockaddr *)&clientname,
118 (int *)&size 119 (int *)&size
119 ); 120 );
120#else 121#else /* not-cygwin */
121 nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size ); 122#ifdef __APPLE__
122#endif 123 nClient = ::accept( nServer, (struct sockaddr *)&clientname, (socklen_t*)&size );
124#else /* linux */
125 nClient = ::accept( nServer, (struct sockaddr *)&clientname, &size );
126#endif /* __APPLE__ */
127#endif /* __CYGWIN__ */
123 if( nClient < 0 ) 128 if( nClient < 0 )
124 { 129 {
125 throw SocketException( 130 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 @@
13#include <fcntl.h> 13#include <fcntl.h>
14#include "socket.h" 14#include "socket.h"
15#include "exceptions.h" 15#include "exceptions.h"
16#include "osx_compatibility.h"
16 17
17#define RBS (1024*2) 18#define RBS (1024*2)
18 19
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()
110#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() ); 110#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() );
111int main( int argc, char *argv ) 111int main( int argc, char *argv )
112{ 112{
113 Bu::FString fs1;
114 for( int j = 0; j < 500000; j++ ) fs1 += (char)('a'+(j%26));
115 return 0;
116
113 Bu::FString str("th"); 117 Bu::FString str("th");
114 118
115 str.prepend("Hello "); 119 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:
9 setName("FString"); 9 setName("FString");
10 addTest( Unit::compare1 ); 10 addTest( Unit::compare1 );
11 addTest( Unit::compare2 ); 11 addTest( Unit::compare2 );
12 addTest( Unit::appendSingle );
12 } 13 }
13 14
14 virtual ~Unit() 15 virtual ~Unit()
@@ -28,6 +29,14 @@ public:
28 unitTest( !(b == "Bob") ); 29 unitTest( !(b == "Bob") );
29 unitTest( b == "Bobo" ); 30 unitTest( b == "Bobo" );
30 } 31 }
32
33 void appendSingle()
34 {
35 Bu::FString b;
36 for( char l = 'a'; l < 'g'; l++ )
37 b += l;
38 unitTest( b == "abcdef" );
39 }
31}; 40};
32 41
33int main( int argc, char *argv[] ) 42int main( int argc, char *argv[] )