Skip to content

Commit

Permalink
fix: unique_ptr on g++-8 needs to know sizeof() z_stream up front, so…
Browse files Browse the repository at this point in the history
… we must use a raw ptr :(
  • Loading branch information
braindigitalis committed Dec 13, 2024
1 parent adb25d1 commit 686344a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/dpp/zlibcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class zlibcontext {
* @brief Zlib stream struct. The actual type is defined in zlib.h
* so is only defined in the implementation file.
*/
std::unique_ptr<z_stream> d_stream{};
z_stream* d_stream{};

/**
* @brief ZLib decompression buffer.
Expand Down
12 changes: 7 additions & 5 deletions src/dpp/zlibcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@
namespace dpp {

zlibcontext::zlibcontext() {
d_stream = std::make_unique<z_stream>();
std::memset(d_stream.get(), 0, sizeof(z_stream));
int error = inflateInit(d_stream.get());
d_stream = new z_stream();
std::memset(d_stream, 0, sizeof(z_stream));
int error = inflateInit(d_stream);
if (error != Z_OK) {
delete d_stream;
throw dpp::connection_exception((exception_error_code)error, "Can't initialise stream compression!");
}
decomp_buffer.resize(DECOMP_BUFFER_SIZE);
}

zlibcontext::~zlibcontext() {
inflateEnd(d_stream.get());
inflateEnd(d_stream);
delete d_stream;
}

exception_error_code zlibcontext::decompress(const std::string& buffer, std::string& decompressed) {
Expand All @@ -47,7 +49,7 @@ exception_error_code zlibcontext::decompress(const std::string& buffer, std::str
do {
d_stream->next_out = static_cast<Bytef*>(decomp_buffer.data());
d_stream->avail_out = DECOMP_BUFFER_SIZE;
int ret = inflate(d_stream.get(), Z_NO_FLUSH);
int ret = inflate(d_stream, Z_NO_FLUSH);
size_t have = DECOMP_BUFFER_SIZE - d_stream->avail_out;
switch (ret)
{
Expand Down

0 comments on commit 686344a

Please sign in to comment.