Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Unified Diff: src/core/SkFlate.cpp

Issue 963853002: Flate: skia_alloc_func works on both miniz and zlib (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-02-27 (Friday) 14:47:34 EST Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkFlate.cpp
diff --git a/src/core/SkFlate.cpp b/src/core/SkFlate.cpp
index baf1c777a557b48fd0bb4b1e821af38542947f17..09975c08f72ca134639c908f714e1fb7def85be0 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);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698