aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/array.h4
-rw-r--r--src/bzip2.cpp13
-rw-r--r--src/fstring.h5
-rw-r--r--src/trace.h7
-rw-r--r--src/unit/array.cpp13
5 files changed, 34 insertions, 8 deletions
diff --git a/src/array.h b/src/array.h
index 9233875..e8d8b30 100644
--- a/src/array.h
+++ b/src/array.h
@@ -157,6 +157,8 @@ namespace Bu
157 src( src ), 157 src( src ),
158 iPos( iPos ) 158 iPos( iPos )
159 { 159 {
160 if( this->iPos >= src.getSize() )
161 this->iPos = -1;
160 } 162 }
161 163
162 MyType &src; 164 MyType &src;
@@ -218,6 +220,8 @@ namespace Bu
218 src( src ), 220 src( src ),
219 iPos( iPos ) 221 iPos( iPos )
220 { 222 {
223 if( this->iPos >= src.getSize() )
224 this->iPos = -1;
221 } 225 }
222 226
223 const MyType &src; 227 const MyType &src;
diff --git a/src/bzip2.cpp b/src/bzip2.cpp
index 9108bcf..c367cff 100644
--- a/src/bzip2.cpp
+++ b/src/bzip2.cpp
@@ -7,6 +7,8 @@
7 7
8#include "bu/bzip2.h" 8#include "bu/bzip2.h"
9#include "bu/exceptions.h" 9#include "bu/exceptions.h"
10#define BU_TRACE
11#include "bu/trace.h"
10 12
11using namespace Bu; 13using namespace Bu;
12 14
@@ -14,16 +16,19 @@ Bu::BZip2::BZip2( Bu::Stream &rNext, int nCompression ) :
14 Bu::Filter( rNext ), 16 Bu::Filter( rNext ),
15 nCompression( nCompression ) 17 nCompression( nCompression )
16{ 18{
19 TRACE( nCompression );
17 start(); 20 start();
18} 21}
19 22
20Bu::BZip2::~BZip2() 23Bu::BZip2::~BZip2()
21{ 24{
25 TRACE();
22 stop(); 26 stop();
23} 27}
24 28
25void Bu::BZip2::start() 29void Bu::BZip2::start()
26{ 30{
31 TRACE();
27 bzState.state = NULL; 32 bzState.state = NULL;
28 bzState.bzalloc = NULL; 33 bzState.bzalloc = NULL;
29 bzState.bzfree = NULL; 34 bzState.bzfree = NULL;
@@ -35,6 +40,7 @@ void Bu::BZip2::start()
35 40
36size_t Bu::BZip2::stop() 41size_t Bu::BZip2::stop()
37{ 42{
43 TRACE();
38 if( bzState.state ) 44 if( bzState.state )
39 { 45 {
40 if( bReading ) 46 if( bReading )
@@ -72,6 +78,7 @@ size_t Bu::BZip2::stop()
72 78
73void Bu::BZip2::bzError( int code ) 79void Bu::BZip2::bzError( int code )
74{ 80{
81 TRACE( code );
75 switch( code ) 82 switch( code )
76 { 83 {
77 case BZ_OK: 84 case BZ_OK:
@@ -115,10 +122,12 @@ void Bu::BZip2::bzError( int code )
115 122
116size_t Bu::BZip2::read( void *pData, size_t nBytes ) 123size_t Bu::BZip2::read( void *pData, size_t nBytes )
117{ 124{
125 TRACE( pData, nBytes );
126 printf("READ!!!\n");
118 if( !bzState.state ) 127 if( !bzState.state )
119 { 128 {
120 bReading = true; 129 bReading = true;
121 BZ2_bzDecompressInit( &bzState, 0, 0 ); 130 BZ2_bzDecompressInit( &bzState, 7, 0 );
122 bzState.next_in = pBuf; 131 bzState.next_in = pBuf;
123 bzState.avail_in = 0; 132 bzState.avail_in = 0;
124 } 133 }
@@ -167,6 +176,7 @@ size_t Bu::BZip2::read( void *pData, size_t nBytes )
167 176
168size_t Bu::BZip2::write( const void *pData, size_t nBytes ) 177size_t Bu::BZip2::write( const void *pData, size_t nBytes )
169{ 178{
179 TRACE( pData, nBytes );
170 if( !bzState.state ) 180 if( !bzState.state )
171 { 181 {
172 bReading = false; 182 bReading = false;
@@ -198,6 +208,7 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes )
198 208
199bool Bu::BZip2::isOpen() 209bool Bu::BZip2::isOpen()
200{ 210{
211 TRACE();
201 return (bzState.state != NULL); 212 return (bzState.state != NULL);
202} 213}
203 214
diff --git a/src/fstring.h b/src/fstring.h
index bc23e57..167c055 100644
--- a/src/fstring.h
+++ b/src/fstring.h
@@ -21,10 +21,6 @@
21#include "bu/hash.h" 21#include "bu/hash.h"
22#include "bu/util.h" 22#include "bu/util.h"
23 23
24#ifndef min
25#define min( a, b ) ((a<b)?(a):(b))
26#endif
27
28namespace Bu 24namespace Bu
29{ 25{
30 template< typename chr > 26 template< typename chr >
@@ -1070,6 +1066,7 @@ namespace Bu
1070 } 1066 }
1071 1067
1072#ifdef BU_TRACE 1068#ifdef BU_TRACE
1069 template<typename t> void __tracer_format( const t &v );
1073 template<> void __tracer_format<FString>( const FString &v ); 1070 template<> void __tracer_format<FString>( const FString &v );
1074#endif 1071#endif
1075} 1072}
diff --git a/src/trace.h b/src/trace.h
index 7a1f368..82399c2 100644
--- a/src/trace.h
+++ b/src/trace.h
@@ -45,6 +45,7 @@ namespace Bu
45 looper( v1 ); 45 looper( v1 );
46 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); 46 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
47 fwrite( "\n", 1, 1, stdout ); 47 fwrite( "\n", 1, 1, stdout );
48 fflush( stdout );
48 } 49 }
49 50
50 template<typename t1, typename t2> void __tracer( const char *pf, 51 template<typename t1, typename t2> void __tracer( const char *pf,
@@ -57,6 +58,7 @@ namespace Bu
57 looper( v2 ); 58 looper( v2 );
58 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); 59 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
59 fwrite( "\n", 1, 1, stdout ); 60 fwrite( "\n", 1, 1, stdout );
61 fflush( stdout );
60 } 62 }
61 63
62 template<typename t1, typename t2, typename t3> 64 template<typename t1, typename t2, typename t3>
@@ -70,6 +72,7 @@ namespace Bu
70 looper( v3 ); 72 looper( v3 );
71 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); 73 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
72 fwrite( "\n", 1, 1, stdout ); 74 fwrite( "\n", 1, 1, stdout );
75 fflush( stdout );
73 } 76 }
74 77
75 template<typename t1, typename t2, typename t3, typename t4> 78 template<typename t1, typename t2, typename t3, typename t4>
@@ -84,6 +87,7 @@ namespace Bu
84 looper( v4 ); 87 looper( v4 );
85 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); 88 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
86 fwrite( "\n", 1, 1, stdout ); 89 fwrite( "\n", 1, 1, stdout );
90 fflush( stdout );
87 } 91 }
88 92
89 template<typename t1, typename t2, typename t3, typename t4, typename t5> 93 template<typename t1, typename t2, typename t3, typename t4, typename t5>
@@ -99,6 +103,7 @@ namespace Bu
99 looper( v5 ); 103 looper( v5 );
100 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); 104 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
101 fwrite( "\n", 1, 1, stdout ); 105 fwrite( "\n", 1, 1, stdout );
106 fflush( stdout );
102 } 107 }
103 108
104 template<typename t1, typename t2, typename t3, typename t4, typename t5, 109 template<typename t1, typename t2, typename t3, typename t4, typename t5,
@@ -117,6 +122,7 @@ namespace Bu
117 looper( v6 ); 122 looper( v6 );
118 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); 123 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
119 fwrite( "\n", 1, 1, stdout ); 124 fwrite( "\n", 1, 1, stdout );
125 fflush( stdout );
120 } 126 }
121 127
122 template<typename t1, typename t2, typename t3, typename t4, typename t5, 128 template<typename t1, typename t2, typename t3, typename t4, typename t5,
@@ -136,6 +142,7 @@ namespace Bu
136 looper( v7 ); 142 looper( v7 );
137 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); 143 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout );
138 fwrite( "\n", 1, 1, stdout ); 144 fwrite( "\n", 1, 1, stdout );
145 fflush( stdout );
139 } 146 }
140#undef looper 147#undef looper
141 148
diff --git a/src/unit/array.cpp b/src/unit/array.cpp
index db29882..57d6c03 100644
--- a/src/unit/array.cpp
+++ b/src/unit/array.cpp
@@ -15,7 +15,8 @@ public:
15 { 15 {
16 setName("Array"); 16 setName("Array");
17 addTest( Unit::general ); 17 addTest( Unit::general );
18 addTest( Unit::iterate ); 18 addTest( Unit::iterate1 );
19 addTest( Unit::iterate2 );
19 } 20 }
20 21
21 virtual ~Unit() 22 virtual ~Unit()
@@ -34,7 +35,7 @@ public:
34 unitTest( ai[1] == 10 ); 35 unitTest( ai[1] == 10 );
35 } 36 }
36 37
37 void iterate() 38 void iterate1()
38 { 39 {
39 Bu::Array<int> ai; 40 Bu::Array<int> ai;
40 for( int j = 0; j < 10; j++ ) 41 for( int j = 0; j < 10; j++ )
@@ -49,7 +50,13 @@ public:
49 for( Bu::Array<int>::const_iterator i = ci.begin(); i != ci.end(); i++ ) 50 for( Bu::Array<int>::const_iterator i = ci.begin(); i != ci.end(); i++ )
50 unitTest( (*i) == j++ ); 51 unitTest( (*i) == j++ );
51 } 52 }
52 53
54 void iterate2()
55 {
56 Bu::Array<int> ai;
57 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
58 unitFailed("Empty lists shouldn't be iterated through.");
59 }
53}; 60};
54 61
55int main( int argc, char *argv[] ) 62int main( int argc, char *argv[] )