]> iEval git - io-compress-brotli.git/blobdiff - Brotli.xs
Use a local temporary buffer for decompression instead of a global.
[io-compress-brotli.git] / Brotli.xs
index a14b828c089dc170df4e576f32b2d8da4b7b3fbb..4378e97f64e3b9ba6645df99ef7ae73dbd6a05a3 100644 (file)
--- a/Brotli.xs
+++ b/Brotli.xs
@@ -9,7 +9,6 @@
 #include <common/dictionary.h>
 
 #define BUFFER_SIZE 1048576
-static uint8_t buffer[BUFFER_SIZE]; /* It's almost 2016, is anyone still using ithreads? */
 
 MODULE = IO::Compress::Brotli          PACKAGE = IO::Uncompress::Brotli
 PROTOTYPES: ENABLE
@@ -50,22 +49,30 @@ SV* BrotliDecoderDecompressStream(state, in)
     SV* state
     SV* in
   PREINIT:
-    uint8_t *next_in, *next_out;
-    size_t available_in, available_out, total_out;
+    uint8_t *next_in, *next_out, *buffer;
+    size_t available_in, available_out;
     BrotliDecoderResult result;
   CODE:
     next_in = (uint8_t*) SvPV(in, available_in);
+    Newx(buffer, BUFFER_SIZE, uint8_t);
     RETVAL = newSVpv("", 0);
     result = BROTLI_RESULT_NEEDS_MORE_OUTPUT;
     while(result == BROTLI_RESULT_NEEDS_MORE_OUTPUT) {
         next_out = buffer;
         available_out=BUFFER_SIZE;
-        result = BrotliDecoderDecompressStream((BrotliDecoderState*) SvIV(state), &available_in, (const uint8_t**) &next_in, &available_out, &next_out, &total_out);
+        result = BrotliDecoderDecompressStream( (BrotliDecoderState*) SvIV(state),
+                                                &available_in,
+                                                (const uint8_t**) &next_in,
+                                                &available_out,
+                                                &next_out,
+                                                NULL );
         if(!result){
-             croak("Error in BrotliDecoderDecompressStream");
+            Safefree(buffer);
+            croak("Error in BrotliDecoderDecompressStream");
         }
         sv_catpvn(RETVAL, (const char*)buffer, BUFFER_SIZE-available_out);
     }
+    Safefree(buffer);
   OUTPUT:
     RETVAL
 
This page took 0.023936 seconds and 4 git commands to generate.