aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/archive.cpp16
-rw-r--r--src/archive.h5
-rw-r--r--src/exceptionbase.cpp5
-rw-r--r--src/minimacro.cpp8
-rw-r--r--src/plugger.h7
-rw-r--r--src/serversocket.cpp2
-rw-r--r--src/tests/fstring.cpp4
-rw-r--r--src/trace.cpp8
-rw-r--r--src/trace.h21
-rw-r--r--src/unit/archive.cpp111
-rw-r--r--src/util.h1
11 files changed, 152 insertions, 36 deletions
diff --git a/src/archive.cpp b/src/archive.cpp
index 610dc7b..d6ad18d 100644
--- a/src/archive.cpp
+++ b/src/archive.cpp
@@ -89,12 +89,12 @@ Bu::Archive &Bu::Archive::operator<<(uint64_t p)
89{ 89{
90 write( &p, sizeof(p) ); 90 write( &p, sizeof(p) );
91 return *this; 91 return *this;
92} 92}/*
93Bu::Archive &Bu::Archive::operator<<(long p) 93Bu::Archive &Bu::Archive::operator<<(long p)
94{ 94{
95 write( &p, sizeof(p) ); 95 write( &p, sizeof(p) );
96 return *this; 96 return *this;
97} 97}*/
98Bu::Archive &Bu::Archive::operator<<(float p) 98Bu::Archive &Bu::Archive::operator<<(float p)
99{ 99{
100 write( &p, sizeof(p) ); 100 write( &p, sizeof(p) );
@@ -155,12 +155,12 @@ Bu::Archive &Bu::Archive::operator>>(uint64_t &p)
155{ 155{
156 read( &p, sizeof(p) ); 156 read( &p, sizeof(p) );
157 return *this; 157 return *this;
158} 158}/*
159Bu::Archive &Bu::Archive::operator>>(long &p) 159Bu::Archive &Bu::Archive::operator>>(long &p)
160{ 160{
161 read( &p, sizeof(p) ); 161 read( &p, sizeof(p) );
162 return *this; 162 return *this;
163} 163}*/
164Bu::Archive &Bu::Archive::operator>>(float &p) 164Bu::Archive &Bu::Archive::operator>>(float &p)
165{ 165{
166 read( &p, sizeof(p) ); 166 read( &p, sizeof(p) );
@@ -371,9 +371,9 @@ Bu::Archive &Bu::operator>>( Bu::Archive &ar, std::string &s )
371 371
372uint32_t Bu::Archive::getID( const void *ptr ) 372uint32_t Bu::Archive::getID( const void *ptr )
373{ 373{
374 if( hPtrID.has( (int)ptr ) ) 374 if( hPtrID.has( (ptrdiff_t)ptr ) )
375 return hPtrID.get( (int)ptr ); 375 return hPtrID.get( (ptrdiff_t)ptr );
376 hPtrID.insert( (int)ptr, nNextID ); 376 hPtrID.insert( (ptrdiff_t)ptr, nNextID );
377 return nNextID++; 377 return nNextID++;
378} 378}
379 379
@@ -393,7 +393,7 @@ void Bu::Archive::assocPtrID( void **ptr, uint32_t id )
393 393
394void Bu::Archive::readID( const void *ptr, uint32_t id ) 394void Bu::Archive::readID( const void *ptr, uint32_t id )
395{ 395{
396 hPtrID.insert( id, (int)ptr ); 396 hPtrID.insert( id, (ptrdiff_t)ptr );
397 397
398 if( hPtrDest.has( id ) ) 398 if( hPtrDest.has( id ) )
399 { 399 {
diff --git a/src/archive.h b/src/archive.h
index 464f85f..31683bb 100644
--- a/src/archive.h
+++ b/src/archive.h
@@ -14,6 +14,7 @@
14#include "bu/hash.h" 14#include "bu/hash.h"
15#include "bu/list.h" 15#include "bu/list.h"
16#include "bu/set.h" 16#include "bu/set.h"
17#include "bu/util.h"
17 18
18namespace Bu 19namespace Bu
19{ 20{
@@ -96,7 +97,7 @@ namespace Bu
96 virtual Archive &operator<<(uint16_t); 97 virtual Archive &operator<<(uint16_t);
97 virtual Archive &operator<<(uint32_t); 98 virtual Archive &operator<<(uint32_t);
98 virtual Archive &operator<<(uint64_t); 99 virtual Archive &operator<<(uint64_t);
99 virtual Archive &operator<<(long); 100// virtual Archive &operator<<(long);
100 virtual Archive &operator<<(float); 101 virtual Archive &operator<<(float);
101 virtual Archive &operator<<(double); 102 virtual Archive &operator<<(double);
102 virtual Archive &operator<<(long double); 103 virtual Archive &operator<<(long double);
@@ -110,7 +111,7 @@ namespace Bu
110 virtual Archive &operator>>(uint16_t &); 111 virtual Archive &operator>>(uint16_t &);
111 virtual Archive &operator>>(uint32_t &); 112 virtual Archive &operator>>(uint32_t &);
112 virtual Archive &operator>>(uint64_t &); 113 virtual Archive &operator>>(uint64_t &);
113 virtual Archive &operator>>(long &); 114// virtual Archive &operator>>(long &);
114 virtual Archive &operator>>(float &); 115 virtual Archive &operator>>(float &);
115 virtual Archive &operator>>(double &); 116 virtual Archive &operator>>(double &);
116 virtual Archive &operator>>(long double &); 117 virtual Archive &operator>>(long double &);
diff --git a/src/exceptionbase.cpp b/src/exceptionbase.cpp
index cea779d..9515e2d 100644
--- a/src/exceptionbase.cpp
+++ b/src/exceptionbase.cpp
@@ -55,7 +55,10 @@ void Bu::ExceptionBase::setWhat( const char *lpFormat, va_list &vargs )
55 if( sWhat ) delete[] sWhat; 55 if( sWhat ) delete[] sWhat;
56 int nSize; 56 int nSize;
57 57
58 nSize = vsnprintf( NULL, 0, lpFormat, vargs ); 58 va_list vargs2;
59 va_copy( vargs2, vargs );
60 nSize = vsnprintf( NULL, 0, lpFormat, vargs2 );
61 va_end( vargs2 );
59 sWhat = new char[nSize+1]; 62 sWhat = new char[nSize+1];
60 vsnprintf( sWhat, nSize+1, lpFormat, vargs ); 63 vsnprintf( sWhat, nSize+1, lpFormat, vargs );
61} 64}
diff --git a/src/minimacro.cpp b/src/minimacro.cpp
index c6a868f..5fd7333 100644
--- a/src/minimacro.cpp
+++ b/src/minimacro.cpp
@@ -62,7 +62,7 @@ Bu::FString Bu::MiniMacro::parse( const Bu::FString &sIn )
62 } 62 }
63 } 63 }
64 64
65 iLastPos = (int)sCur - (int)sIn.getStr(); 65 iLastPos = (ptrdiff_t)sCur - (ptrdiff_t)sIn.getStr();
66 66
67 return sOut; 67 return sOut;
68} 68}
@@ -76,7 +76,7 @@ Bu::FString Bu::MiniMacro::parseRepl()
76 for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ ); 76 for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ );
77 if( *sNext == '\0' ) 77 if( *sNext == '\0' )
78 break; 78 break;
79 Bu::FString sName( sCur, (int)sNext-(int)sCur ); 79 Bu::FString sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur );
80 if( bIsFirst ) 80 if( bIsFirst )
81 { 81 {
82 sOut = hVars[sName]; 82 sOut = hVars[sName];
@@ -116,7 +116,7 @@ Bu::FString Bu::MiniMacro::parseCmd()
116 for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ ); 116 for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ );
117 if( *sNext != '\0' ) 117 if( *sNext != '\0' )
118 { 118 {
119 Bu::FString sName( sCur, (int)sNext-(int)sCur ); 119 Bu::FString sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur );
120 if( sName == "end" ) 120 if( sName == "end" )
121 { 121 {
122 sCur = sNext; 122 sCur = sNext;
@@ -152,7 +152,7 @@ Bu::FString Bu::MiniMacro::callFunc(
152 for(; *s == ' ' || *s == '\t' || *s == '\r' || *s == '\n'; s++ ); 152 for(; *s == ' ' || *s == '\t' || *s == '\r' || *s == '\n'; s++ );
153 const char *sNext; 153 const char *sNext;
154 for( sNext = s; *sNext && *sNext != ')' && *sNext != ','; sNext++ ); 154 for( sNext = s; *sNext && *sNext != ')' && *sNext != ','; sNext++ );
155 Bu::FString p( s, (int)sNext-(int)s ); 155 Bu::FString p( s, (ptrdiff_t)sNext-(ptrdiff_t)s );
156 lsParams.append( p ); 156 lsParams.append( p );
157 sNext++; 157 sNext++;
158 s = sNext; 158 s = sNext;
diff --git a/src/plugger.h b/src/plugger.h
index 992b541..6ae0296 100644
--- a/src/plugger.h
+++ b/src/plugger.h
@@ -14,6 +14,7 @@
14#include <dlfcn.h> 14#include <dlfcn.h>
15#include "bu/exceptions.h" 15#include "bu/exceptions.h"
16#include "bu/fstring.h" 16#include "bu/fstring.h"
17#include <stddef.h>
17 18
18namespace Bu 19namespace Bu
19{ 20{
@@ -86,7 +87,7 @@ namespace Bu
86 { 87 {
87 public: 88 public:
88 typedef Bu::Hash<Bu::FString, PluginReg *> PluginHash; 89 typedef Bu::Hash<Bu::FString, PluginReg *> PluginHash;
89 typedef Bu::Hash<int, void *> InstHash; 90 typedef Bu::Hash<ptrdiff_t, void *> InstHash;
90 91
91 public: 92 public:
92 Plugger() 93 Plugger()
@@ -161,7 +162,7 @@ namespace Bu
161 return NULL; 162 return NULL;
162 163
163 T *p = (T *)pReg->pInfo->createPlugin(); 164 T *p = (T *)pReg->pInfo->createPlugin();
164 hObj.insert( (int )p, pReg ); 165 hObj.insert( (ptrdiff_t)p, pReg );
165 //printf("pReg: %08X, pPlug: %08X\n", pReg, p ); 166 //printf("pReg: %08X, pPlug: %08X\n", pReg, p );
166 167
167 return p; 168 return p;
@@ -181,7 +182,7 @@ namespace Bu
181 182
182 pReg->pInfo->destroyPlugin( pPlug ); 183 pReg->pInfo->destroyPlugin( pPlug );
183 184
184 hObj.erase( (int)pPlug ); 185 hObj.erase( (ptrdiff_t)pPlug );
185 } 186 }
186 187
187 void unloadAll() 188 void unloadAll()
diff --git a/src/serversocket.cpp b/src/serversocket.cpp
index b528b6f..30f584d 100644
--- a/src/serversocket.cpp
+++ b/src/serversocket.cpp
@@ -117,7 +117,7 @@ int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec )
117 if( FD_ISSET( nServer, &fdRead ) ) 117 if( FD_ISSET( nServer, &fdRead ) )
118 { 118 {
119 struct sockaddr_in clientname; 119 struct sockaddr_in clientname;
120 size_t size; 120 socklen_t size;
121 int nClient; 121 int nClient;
122 122
123 size = sizeof( clientname ); 123 size = sizeof( clientname );
diff --git a/src/tests/fstring.cpp b/src/tests/fstring.cpp
index 43de18f..6288ccb 100644
--- a/src/tests/fstring.cpp
+++ b/src/tests/fstring.cpp
@@ -34,7 +34,7 @@ Bu::FString genThing()
34 bob += "cd "; 34 bob += "cd ";
35 bob += "efg"; 35 bob += "efg";
36 36
37 printf("---bob------\n%08X: %s\n", (unsigned int)bob.getStr(), 37 printf("---bob------\n%08tX: %s\n", (ptrdiff_t)bob.getStr(),
38 bob.getStr() ); 38 bob.getStr() );
39 return bob; 39 return bob;
40} 40}
@@ -115,7 +115,7 @@ void doTimings()
115 delete[] buf; 115 delete[] buf;
116} 116}
117 117
118#define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.getStr(), str.getStr(), (unsigned int)str2.getStr(), str2.getStr() ); 118#define pem printf("---------\n%08tX: %s\n%08tX: %s\n", (ptrdiff_t)str.getStr(), str.getStr(), (ptrdiff_t)str2.getStr(), str2.getStr() );
119int main( int argc, char *argv[] ) 119int main( int argc, char *argv[] )
120{ 120{
121 Bu::FString fs1; 121 Bu::FString fs1;
diff --git a/src/trace.cpp b/src/trace.cpp
index b328565..dab53d6 100644
--- a/src/trace.cpp
+++ b/src/trace.cpp
@@ -58,7 +58,7 @@ template<> void Bu::__tracer_format<char>( const char &v )
58{ 58{
59 printf("%hhd", v ); 59 printf("%hhd", v );
60} 60}
61 61/*
62template<> void Bu::__tracer_format<long>( const long &v ) 62template<> void Bu::__tracer_format<long>( const long &v )
63{ 63{
64 printf("%ld", v ); 64 printf("%ld", v );
@@ -67,7 +67,7 @@ template<> void Bu::__tracer_format<long>( const long &v )
67template<> void Bu::__tracer_format<unsigned long>( const unsigned long &v ) 67template<> void Bu::__tracer_format<unsigned long>( const unsigned long &v )
68{ 68{
69 printf("%lu", v ); 69 printf("%lu", v );
70} 70}*/
71 71
72template<> void Bu::__tracer_format<float>( const float &v ) 72template<> void Bu::__tracer_format<float>( const float &v )
73{ 73{
@@ -81,7 +81,7 @@ template<> void Bu::__tracer_format<double>( const double &v )
81 81
82template<> void Bu::__tracer_format<void *>( void * const &v ) 82template<> void Bu::__tracer_format<void *>( void * const &v )
83{ 83{
84 printf("0x%08X", (unsigned int)v ); 84 printf("0x%08X", (ptrdiff_t)v );
85} 85}
86 86
87template<> void Bu::__tracer_format<char *>( char * const &v ) 87template<> void Bu::__tracer_format<char *>( char * const &v )
@@ -99,7 +99,7 @@ template<> void Bu::__tracer_format<char **>( char ** const &v )
99 99
100template<> void Bu::__tracer_format<void const *>( void const * const &v ) 100template<> void Bu::__tracer_format<void const *>( void const * const &v )
101{ 101{
102 printf("0x%08X", (unsigned int)v ); 102 printf("0x%08X", (ptrdiff_t)v );
103} 103}
104 104
105template<> void Bu::__tracer_format<char const *>( char const * const &v ) 105template<> void Bu::__tracer_format<char const *>( char const * const &v )
diff --git a/src/trace.h b/src/trace.h
index e115d66..7a1f368 100644
--- a/src/trace.h
+++ b/src/trace.h
@@ -10,6 +10,7 @@
10 10
11#include <stdio.h> 11#include <stdio.h>
12#include <stdint.h> 12#include <stdint.h>
13#include <stddef.h>
13 14
14namespace Bu 15namespace Bu
15{ 16{
@@ -27,7 +28,7 @@ namespace Bu
27 { \ 28 { \
28 if( *n == ',' || *n == ')' ) \ 29 if( *n == ',' || *n == ')' ) \
29 { \ 30 { \
30 fwrite( s, (int)n-(int)s, 1, stdout ); \ 31 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); \
31 fwrite("=", 1, 1, stdout); \ 32 fwrite("=", 1, 1, stdout); \
32 __tracer_format( vv ); \ 33 __tracer_format( vv ); \
33 s = n; \ 34 s = n; \
@@ -42,7 +43,7 @@ namespace Bu
42 const char *s = pf; 43 const char *s = pf;
43 const char *n = pf; 44 const char *n = pf;
44 looper( v1 ); 45 looper( v1 );
45 fwrite( s, (int)n-(int)s, 1, stdout ); 46 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
46 fwrite( "\n", 1, 1, stdout ); 47 fwrite( "\n", 1, 1, stdout );
47 } 48 }
48 49
@@ -54,7 +55,7 @@ namespace Bu
54 const char *n = pf; 55 const char *n = pf;
55 looper( v1 ); 56 looper( v1 );
56 looper( v2 ); 57 looper( v2 );
57 fwrite( s, (int)n-(int)s, 1, stdout ); 58 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
58 fwrite( "\n", 1, 1, stdout ); 59 fwrite( "\n", 1, 1, stdout );
59 } 60 }
60 61
@@ -67,7 +68,7 @@ namespace Bu
67 looper( v1 ); 68 looper( v1 );
68 looper( v2 ); 69 looper( v2 );
69 looper( v3 ); 70 looper( v3 );
70 fwrite( s, (int)n-(int)s, 1, stdout ); 71 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
71 fwrite( "\n", 1, 1, stdout ); 72 fwrite( "\n", 1, 1, stdout );
72 } 73 }
73 74
@@ -81,7 +82,7 @@ namespace Bu
81 looper( v2 ); 82 looper( v2 );
82 looper( v3 ); 83 looper( v3 );
83 looper( v4 ); 84 looper( v4 );
84 fwrite( s, (int)n-(int)s, 1, stdout ); 85 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
85 fwrite( "\n", 1, 1, stdout ); 86 fwrite( "\n", 1, 1, stdout );
86 } 87 }
87 88
@@ -96,7 +97,7 @@ namespace Bu
96 looper( v3 ); 97 looper( v3 );
97 looper( v4 ); 98 looper( v4 );
98 looper( v5 ); 99 looper( v5 );
99 fwrite( s, (int)n-(int)s, 1, stdout ); 100 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
100 fwrite( "\n", 1, 1, stdout ); 101 fwrite( "\n", 1, 1, stdout );
101 } 102 }
102 103
@@ -114,7 +115,7 @@ namespace Bu
114 looper( v4 ); 115 looper( v4 );
115 looper( v5 ); 116 looper( v5 );
116 looper( v6 ); 117 looper( v6 );
117 fwrite( s, (int)n-(int)s, 1, stdout ); 118 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
118 fwrite( "\n", 1, 1, stdout ); 119 fwrite( "\n", 1, 1, stdout );
119 } 120 }
120 121
@@ -133,7 +134,7 @@ namespace Bu
133 looper( v5 ); 134 looper( v5 );
134 looper( v6 ); 135 looper( v6 );
135 looper( v7 ); 136 looper( v7 );
136 fwrite( s, (int)n-(int)s, 1, stdout ); 137 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
137 fwrite( "\n", 1, 1, stdout ); 138 fwrite( "\n", 1, 1, stdout );
138 } 139 }
139#undef looper 140#undef looper
@@ -148,8 +149,8 @@ namespace Bu
148 template<> void __tracer_format<uint64_t>( const uint64_t &v ); 149 template<> void __tracer_format<uint64_t>( const uint64_t &v );
149 template<> void __tracer_format<bool>( const bool &v ); 150 template<> void __tracer_format<bool>( const bool &v );
150 template<> void __tracer_format<char>( const char &v ); 151 template<> void __tracer_format<char>( const char &v );
151 template<> void __tracer_format<long>( const long &v ); 152 //template<> void __tracer_format<long>( const long &v );
152 template<> void __tracer_format<unsigned long>( const unsigned long &v ); 153 //template<> void __tracer_format<unsigned long>( const unsigned long &v );
153 template<> void __tracer_format<float>( const float &v ); 154 template<> void __tracer_format<float>( const float &v );
154 template<> void __tracer_format<double>( const double &v ); 155 template<> void __tracer_format<double>( const double &v );
155 template<> void __tracer_format<void *>( void * const &v ); 156 template<> void __tracer_format<void *>( void * const &v );
diff --git a/src/unit/archive.cpp b/src/unit/archive.cpp
new file mode 100644
index 0000000..61e3567
--- /dev/null
+++ b/src/unit/archive.cpp
@@ -0,0 +1,111 @@
1/*
2 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "bu/unitsuite.h"
9#include "bu/membuf.h"
10
11class Unit : public Bu::UnitSuite
12{
13public:
14 Unit()
15 {
16 setName("Archive");
17 addTest( Unit::testPrimitives );
18 }
19
20 virtual ~Unit()
21 {
22 }
23
24 void testPrimitives()
25 {
26 Bu::MemBuf mb;
27 {
28 Bu::Archive ar( mb, Bu::Archive::save );
29 ar << (int8_t)1;
30 ar << (uint8_t)2;
31 ar << (int16_t)3;
32 ar << (uint16_t)4;
33 ar << (int32_t)5;
34 ar << (uint32_t)6;
35 ar << (int64_t)7;
36 ar << (uint64_t)8;
37 ar << (char)9;
38 ar << (unsigned char)10;
39 ar << (short)11;
40 ar << (unsigned short)12;
41 ar << (int)13;
42 ar << (unsigned int)14;
43 ar << (long)15;
44 ar << (unsigned long)16;
45 //ar << (long long)17;
46 //ar << (unsigned long long)18;
47 ar.close();
48 }
49 mb.setPos( 0 );
50 {
51 Bu::Archive ar( mb, Bu::Archive::load );
52 int8_t p1;
53 uint8_t p2;
54 int16_t p3;
55 uint16_t p4;
56 int32_t p5;
57 uint32_t p6;
58 int64_t p7;
59 uint64_t p8;
60 signed char p9;
61 unsigned char p10;
62 short p11;
63 unsigned short p12;
64 int p13;
65 unsigned int p14;
66 long p15;
67 unsigned long p16;
68 //long long p17;
69 //unsigned long long p18;
70 ar >> p1;
71 ar >> p2;
72 ar >> p3;
73 ar >> p4;
74 ar >> p5;
75 ar >> p6;
76 ar >> p7;
77 ar >> p8;
78 ar >> p9;
79 ar >> p10;
80 ar >> p11;
81 ar >> p12;
82 ar >> p13;
83 ar >> p14;
84 ar >> p15;
85 ar >> p16;
86 //ar >> p17;
87 //ar >> p18;
88 unitTest( p1 == 1 );
89 unitTest( p2 == 2 );
90 unitTest( p3 == 3 );
91 unitTest( p4 == 4 );
92 unitTest( p5 == 5 );
93 unitTest( p6 == 6 );
94 unitTest( p7 == 7 );
95 unitTest( p8 == 8 );
96 unitTest( p9 == 9 );
97 unitTest( p10 == 10 );
98 unitTest( p11 == 11 );
99 unitTest( p12 == 12 );
100 unitTest( p13 == 13 );
101 unitTest( p14 == 14 );
102 unitTest( p15 == 15 );
103 unitTest( p16 == 16 );
104 //unitTest( p17 == 17 );
105 //unitTest( p18 == 18 );
106 ar.close();
107 }
108 }
109};
110
111int main( int argc, char *argv[] ){ return Unit().run( argc, argv ); }
diff --git a/src/util.h b/src/util.h
index 25eb795..6205c04 100644
--- a/src/util.h
+++ b/src/util.h
@@ -74,7 +74,6 @@ namespace Bu
74 return *a > *b; 74 return *a > *b;
75 } 75 }
76 }; 76 };
77
78}; 77};
79 78
80#endif 79#endif