serf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject svn commit: r1761053 - /serf/trunk/buckets/deflate_buckets.c
Date Fri, 16 Sep 2016 16:04:09 GMT
Author: ivan
Date: Fri Sep 16 16:04:09 2016
New Revision: 1761053

URL: http://svn.apache.org/viewvc?rev=1761053&view=rev
Log:
Configure ZLib to use bucket allocator in deflate buckets.

* buckets/deflate_buckets.c
  (zalloc_func, zalloc_free): New.
  (serf_bucket_deflate_create,
   serf_bucket_deflate_compress_create): Configure zlib's alloc/free callbacks
   to allocate memory from bucket allocator.

Modified:
    serf/trunk/buckets/deflate_buckets.c

Modified: serf/trunk/buckets/deflate_buckets.c
URL: http://svn.apache.org/viewvc/serf/trunk/buckets/deflate_buckets.c?rev=1761053&r1=1761052&r2=1761053&view=diff
==============================================================================
--- serf/trunk/buckets/deflate_buckets.c (original)
+++ serf/trunk/buckets/deflate_buckets.c Fri Sep 16 16:04:09 2016
@@ -93,6 +93,23 @@ static unsigned long getLong(unsigned ch
           | (((unsigned long)string[3]) << 24);
 }
 
+/* zlib alloc function. opaque is the bucket allocator. */
+static voidpf zalloc_func(voidpf opaque, uInt items, uInt size)
+{
+    serf_bucket_alloc_t *allocator = opaque;
+    apr_size_t alloc_size = items * size;
+    return serf_bucket_mem_alloc(allocator, alloc_size);
+}
+
+/* zlib free function */
+static void zfree_func(voidpf opaque, voidpf address)
+{
+    if (address) {
+        serf_bucket_alloc_t *allocator = opaque;
+        serf_bucket_mem_free(allocator, address);
+    }
+}
+
 serf_bucket_t *serf_bucket_deflate_create(
     serf_bucket_t *stream,
     serf_bucket_alloc_t *allocator,
@@ -110,6 +127,12 @@ serf_bucket_t *serf_bucket_deflate_creat
     /* zstream must be NULL'd out. */
     memset(&ctx->zstream, 0, sizeof(ctx->zstream));
 
+    /* Configure alloc/free callbacks to allocate memory from bucket
+     * allocator. */
+    ctx->zstream.zalloc = zalloc_func;
+    ctx->zstream.zfree = zfree_func;
+    ctx->zstream.opaque = allocator;
+
     switch (ctx->format) {
         case SERF_DEFLATE_GZIP:
             ctx->state = STATE_READING_HEADER;
@@ -151,6 +174,12 @@ serf_bucket_t *serf_bucket_deflate_compr
     /* zstream must be NULL'd out. */
     memset(&ctx->zstream, 0, sizeof(ctx->zstream));
 
+    /* Configure alloc/free callbacks to allocate memory from bucket
+     * allocator. */
+    ctx->zstream.zalloc = zalloc_func;
+    ctx->zstream.zfree = zfree_func;
+    ctx->zstream.opaque = allocator;
+
     switch (ctx->format) {
         case SERF_DEFLATE_GZIP:
             ctx->state = STATE_WRITING_HEADER;



Mime
View raw message