From 555ba77568b6faf18ebaed06cd08615deab2d8e3 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 7 Jun 2008 05:30:58 +0000 Subject: This is a testing version. Nothing should be broken, but I won't gurantee it. I wouldn't update to this just yet, if you have problems, back off a rev. I'm trying to update the code to work on both 32bit, and 64bit systems, and hopefully anything else that comes along. Currently some of the archive code is broken, testing must be done on both archetectures. --- src/archive.cpp | 16 ++++---- src/archive.h | 5 ++- src/exceptionbase.cpp | 5 ++- src/minimacro.cpp | 8 ++-- src/plugger.h | 7 ++-- src/serversocket.cpp | 2 +- src/tests/fstring.cpp | 4 +- src/trace.cpp | 8 ++-- src/trace.h | 21 +++++----- src/unit/archive.cpp | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/util.h | 1 - 11 files changed, 152 insertions(+), 36 deletions(-) create mode 100644 src/unit/archive.cpp (limited to 'src') 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) { write( &p, sizeof(p) ); return *this; -} +}/* Bu::Archive &Bu::Archive::operator<<(long p) { write( &p, sizeof(p) ); return *this; -} +}*/ Bu::Archive &Bu::Archive::operator<<(float p) { write( &p, sizeof(p) ); @@ -155,12 +155,12 @@ Bu::Archive &Bu::Archive::operator>>(uint64_t &p) { read( &p, sizeof(p) ); return *this; -} +}/* Bu::Archive &Bu::Archive::operator>>(long &p) { read( &p, sizeof(p) ); return *this; -} +}*/ Bu::Archive &Bu::Archive::operator>>(float &p) { read( &p, sizeof(p) ); @@ -371,9 +371,9 @@ Bu::Archive &Bu::operator>>( Bu::Archive &ar, std::string &s ) uint32_t Bu::Archive::getID( const void *ptr ) { - if( hPtrID.has( (int)ptr ) ) - return hPtrID.get( (int)ptr ); - hPtrID.insert( (int)ptr, nNextID ); + if( hPtrID.has( (ptrdiff_t)ptr ) ) + return hPtrID.get( (ptrdiff_t)ptr ); + hPtrID.insert( (ptrdiff_t)ptr, nNextID ); return nNextID++; } @@ -393,7 +393,7 @@ void Bu::Archive::assocPtrID( void **ptr, uint32_t id ) void Bu::Archive::readID( const void *ptr, uint32_t id ) { - hPtrID.insert( id, (int)ptr ); + hPtrID.insert( id, (ptrdiff_t)ptr ); if( hPtrDest.has( id ) ) { 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 @@ #include "bu/hash.h" #include "bu/list.h" #include "bu/set.h" +#include "bu/util.h" namespace Bu { @@ -96,7 +97,7 @@ namespace Bu virtual Archive &operator<<(uint16_t); virtual Archive &operator<<(uint32_t); virtual Archive &operator<<(uint64_t); - virtual Archive &operator<<(long); +// virtual Archive &operator<<(long); virtual Archive &operator<<(float); virtual Archive &operator<<(double); virtual Archive &operator<<(long double); @@ -110,7 +111,7 @@ namespace Bu virtual Archive &operator>>(uint16_t &); virtual Archive &operator>>(uint32_t &); virtual Archive &operator>>(uint64_t &); - virtual Archive &operator>>(long &); +// virtual Archive &operator>>(long &); virtual Archive &operator>>(float &); virtual Archive &operator>>(double &); 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 ) if( sWhat ) delete[] sWhat; int nSize; - nSize = vsnprintf( NULL, 0, lpFormat, vargs ); + va_list vargs2; + va_copy( vargs2, vargs ); + nSize = vsnprintf( NULL, 0, lpFormat, vargs2 ); + va_end( vargs2 ); sWhat = new char[nSize+1]; vsnprintf( sWhat, nSize+1, lpFormat, vargs ); } 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 ) } } - iLastPos = (int)sCur - (int)sIn.getStr(); + iLastPos = (ptrdiff_t)sCur - (ptrdiff_t)sIn.getStr(); return sOut; } @@ -76,7 +76,7 @@ Bu::FString Bu::MiniMacro::parseRepl() for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ ); if( *sNext == '\0' ) break; - Bu::FString sName( sCur, (int)sNext-(int)sCur ); + Bu::FString sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur ); if( bIsFirst ) { sOut = hVars[sName]; @@ -116,7 +116,7 @@ Bu::FString Bu::MiniMacro::parseCmd() for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ ); if( *sNext != '\0' ) { - Bu::FString sName( sCur, (int)sNext-(int)sCur ); + Bu::FString sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur ); if( sName == "end" ) { sCur = sNext; @@ -152,7 +152,7 @@ Bu::FString Bu::MiniMacro::callFunc( for(; *s == ' ' || *s == '\t' || *s == '\r' || *s == '\n'; s++ ); const char *sNext; for( sNext = s; *sNext && *sNext != ')' && *sNext != ','; sNext++ ); - Bu::FString p( s, (int)sNext-(int)s ); + Bu::FString p( s, (ptrdiff_t)sNext-(ptrdiff_t)s ); lsParams.append( p ); sNext++; 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 @@ #include #include "bu/exceptions.h" #include "bu/fstring.h" +#include namespace Bu { @@ -86,7 +87,7 @@ namespace Bu { public: typedef Bu::Hash PluginHash; - typedef Bu::Hash InstHash; + typedef Bu::Hash InstHash; public: Plugger() @@ -161,7 +162,7 @@ namespace Bu return NULL; T *p = (T *)pReg->pInfo->createPlugin(); - hObj.insert( (int )p, pReg ); + hObj.insert( (ptrdiff_t)p, pReg ); //printf("pReg: %08X, pPlug: %08X\n", pReg, p ); return p; @@ -181,7 +182,7 @@ namespace Bu pReg->pInfo->destroyPlugin( pPlug ); - hObj.erase( (int)pPlug ); + hObj.erase( (ptrdiff_t)pPlug ); } 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 ) if( FD_ISSET( nServer, &fdRead ) ) { struct sockaddr_in clientname; - size_t size; + socklen_t size; int nClient; 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() bob += "cd "; bob += "efg"; - printf("---bob------\n%08X: %s\n", (unsigned int)bob.getStr(), + printf("---bob------\n%08tX: %s\n", (ptrdiff_t)bob.getStr(), bob.getStr() ); return bob; } @@ -115,7 +115,7 @@ void doTimings() delete[] buf; } -#define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.getStr(), str.getStr(), (unsigned int)str2.getStr(), str2.getStr() ); +#define pem printf("---------\n%08tX: %s\n%08tX: %s\n", (ptrdiff_t)str.getStr(), str.getStr(), (ptrdiff_t)str2.getStr(), str2.getStr() ); int main( int argc, char *argv[] ) { 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( const char &v ) { printf("%hhd", v ); } - +/* template<> void Bu::__tracer_format( const long &v ) { printf("%ld", v ); @@ -67,7 +67,7 @@ template<> void Bu::__tracer_format( const long &v ) template<> void Bu::__tracer_format( const unsigned long &v ) { printf("%lu", v ); -} +}*/ template<> void Bu::__tracer_format( const float &v ) { @@ -81,7 +81,7 @@ template<> void Bu::__tracer_format( const double &v ) template<> void Bu::__tracer_format( void * const &v ) { - printf("0x%08X", (unsigned int)v ); + printf("0x%08X", (ptrdiff_t)v ); } template<> void Bu::__tracer_format( char * const &v ) @@ -99,7 +99,7 @@ template<> void Bu::__tracer_format( char ** const &v ) template<> void Bu::__tracer_format( void const * const &v ) { - printf("0x%08X", (unsigned int)v ); + printf("0x%08X", (ptrdiff_t)v ); } template<> void Bu::__tracer_format( 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 @@ #include #include +#include namespace Bu { @@ -27,7 +28,7 @@ namespace Bu { \ if( *n == ',' || *n == ')' ) \ { \ - fwrite( s, (int)n-(int)s, 1, stdout ); \ + fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); \ fwrite("=", 1, 1, stdout); \ __tracer_format( vv ); \ s = n; \ @@ -42,7 +43,7 @@ namespace Bu const char *s = pf; const char *n = pf; looper( v1 ); - fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); fwrite( "\n", 1, 1, stdout ); } @@ -54,7 +55,7 @@ namespace Bu const char *n = pf; looper( v1 ); looper( v2 ); - fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); fwrite( "\n", 1, 1, stdout ); } @@ -67,7 +68,7 @@ namespace Bu looper( v1 ); looper( v2 ); looper( v3 ); - fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); fwrite( "\n", 1, 1, stdout ); } @@ -81,7 +82,7 @@ namespace Bu looper( v2 ); looper( v3 ); looper( v4 ); - fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); fwrite( "\n", 1, 1, stdout ); } @@ -96,7 +97,7 @@ namespace Bu looper( v3 ); looper( v4 ); looper( v5 ); - fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); fwrite( "\n", 1, 1, stdout ); } @@ -114,7 +115,7 @@ namespace Bu looper( v4 ); looper( v5 ); looper( v6 ); - fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); fwrite( "\n", 1, 1, stdout ); } @@ -133,7 +134,7 @@ namespace Bu looper( v5 ); looper( v6 ); looper( v7 ); - fwrite( s, (int)n-(int)s, 1, stdout ); + fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); fwrite( "\n", 1, 1, stdout ); } #undef looper @@ -148,8 +149,8 @@ namespace Bu template<> void __tracer_format( const uint64_t &v ); template<> void __tracer_format( const bool &v ); template<> void __tracer_format( const char &v ); - template<> void __tracer_format( const long &v ); - template<> void __tracer_format( const unsigned long &v ); + //template<> void __tracer_format( const long &v ); + //template<> void __tracer_format( const unsigned long &v ); template<> void __tracer_format( const float &v ); template<> void __tracer_format( const double &v ); template<> void __tracer_format( 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 @@ +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/unitsuite.h" +#include "bu/membuf.h" + +class Unit : public Bu::UnitSuite +{ +public: + Unit() + { + setName("Archive"); + addTest( Unit::testPrimitives ); + } + + virtual ~Unit() + { + } + + void testPrimitives() + { + Bu::MemBuf mb; + { + Bu::Archive ar( mb, Bu::Archive::save ); + ar << (int8_t)1; + ar << (uint8_t)2; + ar << (int16_t)3; + ar << (uint16_t)4; + ar << (int32_t)5; + ar << (uint32_t)6; + ar << (int64_t)7; + ar << (uint64_t)8; + ar << (char)9; + ar << (unsigned char)10; + ar << (short)11; + ar << (unsigned short)12; + ar << (int)13; + ar << (unsigned int)14; + ar << (long)15; + ar << (unsigned long)16; + //ar << (long long)17; + //ar << (unsigned long long)18; + ar.close(); + } + mb.setPos( 0 ); + { + Bu::Archive ar( mb, Bu::Archive::load ); + int8_t p1; + uint8_t p2; + int16_t p3; + uint16_t p4; + int32_t p5; + uint32_t p6; + int64_t p7; + uint64_t p8; + signed char p9; + unsigned char p10; + short p11; + unsigned short p12; + int p13; + unsigned int p14; + long p15; + unsigned long p16; + //long long p17; + //unsigned long long p18; + ar >> p1; + ar >> p2; + ar >> p3; + ar >> p4; + ar >> p5; + ar >> p6; + ar >> p7; + ar >> p8; + ar >> p9; + ar >> p10; + ar >> p11; + ar >> p12; + ar >> p13; + ar >> p14; + ar >> p15; + ar >> p16; + //ar >> p17; + //ar >> p18; + unitTest( p1 == 1 ); + unitTest( p2 == 2 ); + unitTest( p3 == 3 ); + unitTest( p4 == 4 ); + unitTest( p5 == 5 ); + unitTest( p6 == 6 ); + unitTest( p7 == 7 ); + unitTest( p8 == 8 ); + unitTest( p9 == 9 ); + unitTest( p10 == 10 ); + unitTest( p11 == 11 ); + unitTest( p12 == 12 ); + unitTest( p13 == 13 ); + unitTest( p14 == 14 ); + unitTest( p15 == 15 ); + unitTest( p16 == 16 ); + //unitTest( p17 == 17 ); + //unitTest( p18 == 18 ); + ar.close(); + } + } +}; + +int 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 return *a > *b; } }; - }; #endif -- cgit v1.2.3