diff options
author | halcanary <halcanary@google.com> | 2015-02-27 13:09:07 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-27 13:09:07 -0800 |
commit | 394ce76992e2e8349af64ab99d6e2e702bae735d (patch) | |
tree | 502044b8d7bee85e0abf75c765efe67cf3190ab0 /src | |
parent | d4c7d55594d94a00b6cecf6b2fdbb811836ce2ff (diff) |
Flate: skia_alloc_func works on both miniz and zlib
Also, Revert "Revert of Flate: fix valgrind miniz
Conditional-jump-or-move-depends... error"
This reverts commit 6dc4ef01a656a9f7c3087eec2ff5142c707ceb7f.
The alloc functions really do have different types depending
on zlib implementation.
CQ_INCLUDE_TRYBOTS=client.skia:Linux Builder-Trybot
Review URL: https://codereview.chromium.org/963853002
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkFlate.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/core/SkFlate.cpp b/src/core/SkFlate.cpp index baf1c777a5..09975c08f7 100644 --- a/src/core/SkFlate.cpp +++ b/src/core/SkFlate.cpp @@ -24,12 +24,21 @@ namespace { // static const size_t kBufferSize = 1024; +// Different zlib implementations use different T. +// We've seen size_t and unsigned. +template <typename T> void* skia_alloc_func(void*, T items, T size) { + return sk_calloc_throw(SkToSizeT(items) * SkToSizeT(size)); +} + +static void skia_free_func(void*, void* address) { sk_free(address); } + bool doFlate(bool compress, SkStream* src, SkWStream* dst) { uint8_t inputBuffer[kBufferSize]; uint8_t outputBuffer[kBufferSize]; z_stream flateData; - flateData.zalloc = NULL; - flateData.zfree = NULL; + flateData.zalloc = &skia_alloc_func; + flateData.zfree = &skia_free_func; + flateData.opaque = NULL; flateData.next_in = NULL; flateData.avail_in = 0; flateData.next_out = outputBuffer; @@ -170,9 +179,9 @@ SkDeflateWStream::SkDeflateWStream(SkWStream* out) if (!fImpl->fOut) { return; } - fImpl->fZStream.zalloc = Z_NULL; - fImpl->fZStream.zfree = Z_NULL; - fImpl->fZStream.opaque = Z_NULL; + fImpl->fZStream.zalloc = &skia_alloc_func; + fImpl->fZStream.zfree = &skia_free_func; + fImpl->fZStream.opaque = NULL; SkDEBUGCODE(int r =) deflateInit(&fImpl->fZStream, Z_DEFAULT_COMPRESSION); SkASSERT(Z_OK == r); } |