Skip to content

Commit c9b2f6b

Browse files
committed
add debug output
1 parent f747def commit c9b2f6b

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

Diff for: src/GzipFile.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "Debug.h"
88
#include "FileHandle.h"
9+
#include "GzipReader.h"
910
#include "PathUtils.h"
1011

1112

Diff for: src/GzipFile.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "Block.h"
44
#include "Buffer.h"
55
#include "CompressedFile.h"
6-
#include "GzipReader.h"
76

87

98
class GzipFile : public IndexedCompFile
@@ -39,7 +38,7 @@ class GzipFile : public IndexedCompFile
3938
Block* b ) override; // True unless EOF
4039

4140
void writeBlock( FileHandle& fh,
42-
const Block *b ) const override;
41+
const Block *b ) const override;
4342

4443
public:
4544
static const size_t WindowSize;

Diff for: src/GzipReader.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ GzipBlockReader::GzipBlockReader( const FileHandle& fh,
163163

164164
void SavingGzipReader::save()
165165
{
166-
DEBUG( "%s start", __func__ );
167-
168166
if ( !mSave ) {
169167
mSave = new PositionedGzipReader( mFH );
170168
}
@@ -187,8 +185,6 @@ void SavingGzipReader::save()
187185

188186
mInitOutPos = mSave->opos();
189187
mOutBytes = 0;
190-
191-
DEBUG( "%s end", __func__ );
192188
}
193189

194190
void SavingGzipReader::restore()

Diff for: src/GzipReader.h

+34-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,18 @@ class GzipReaderBase
7272
void throwEx( const std::string& s,
7373
int err );
7474

75-
void resetOutBuf()
75+
inline void resetOutBuf()
7676
{
7777
mStream.next_out = &outBuf()[0];
7878
mStream.avail_out = outBuf().size();
79+
80+
if ( mStream.next_out == nullptr ) {
81+
std::cerr << "Output buffer location is null. Can't work with this!\n";
82+
}
83+
84+
if ( mStream.avail_out == 0 ) {
85+
std::cerr << "Available outbut buffer is empty. Can't work with this!\n";
86+
}
7987
}
8088

8189
/** only used by GzipBlockReader */
@@ -84,7 +92,7 @@ class GzipReaderBase
8492
void prime( uint8_t byte,
8593
size_t bits );
8694

87-
int step( int flush = Z_BLOCK ); // One iteration of inflate
95+
int step( int flush = Z_BLOCK ); // One iteration of inflate
8896

8997
int stepThrow( int flush = Z_BLOCK );
9098

@@ -94,15 +102,35 @@ class GzipReaderBase
94102

95103
virtual size_t chunkSize() const;
96104

97-
virtual Wrapper wrapper() const { return Raw; }
105+
inline virtual Wrapper wrapper() const { return Raw; }
98106

99107
virtual Buffer& outBuf() = 0;
100108

101-
virtual void writeOut()
109+
inline virtual void writeOut()
102110
{
103111
throw std::runtime_error( "out of space in gzip output buffer" );
104112
}
105113

114+
/** debug function */
115+
inline static void
116+
dumpStream( const z_stream& stream )
117+
{
118+
std::cerr
119+
<< "z_stream:\n"
120+
<< " next input from : " << (void*) stream.next_in << "\n"
121+
<< " available input bytes : " << stream.avail_in << "\n"
122+
<< " input bytes already read : " << stream.total_in << "\n"
123+
<< "\n"
124+
<< " next output to : " << (void*) stream.next_out << "\n"
125+
<< " remaining free output space : " << stream.avail_out << "\n"
126+
<< " output bytes already written : " << stream.total_out << "\n"
127+
<< "\n"
128+
<< " last error message : " << ( stream.msg == nullptr ? "(null)" : stream.msg ) << "\n"
129+
<< " data type guess : " << stream.data_type << "\n"
130+
<< " checksum for uncompressed data : " << stream.adler << "\n"
131+
<< "\n";
132+
}
133+
106134
public:
107135
GzipReaderBase();
108136

@@ -123,6 +151,7 @@ class GzipReaderBase
123151
inline virtual void
124152
reset( Wrapper w )
125153
{
154+
dumpStream( mStream );
126155
CHECK_ZLIB( inflateReset2( &mStream, w ) );
127156
};
128157

@@ -304,6 +333,7 @@ class SavingGzipReader : public GzipReaderInternal::PositionedGzipReader
304333
off_t opos = 0 ) :
305334
PositionedGzipReader( fh, opos )
306335
{
336+
std::cerr << "Resize buffer to " << windowSize() << "\n";
307337
mOutBuf.resize( windowSize() );
308338
}
309339

0 commit comments

Comments
 (0)