Merge to XFA: Move FPDFAPI_FlateInit() prototype and friends to .h file
authorTom Sepez <tsepez@chromium.org>
Tue, 14 Jul 2015 23:43:54 +0000 (16:43 -0700)
committerTom Sepez <tsepez@chromium.org>
Tue, 14 Jul 2015 23:43:54 +0000 (16:43 -0700)
(cherry picked from commit dacc22cdfea727a04bce086d9bfec9a4d1a29bd4)
Orignal Review URL: https://codereview.chromium.org/1240713004 .
TBR=thestig@chromium.org

Review URL: https://codereview.chromium.org/1230373003 .

BUILD.gn
core/include/fxcodec/fx_codec_flate.h [new file with mode: 0644]
core/src/fpdfapi/fpdf_parser/fpdf_parser_filters.cpp
core/src/fxcodec/codec/fx_codec_flate.cpp
pdfium.gyp

index b236c7b..2277d5e 100644 (file)
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -323,6 +323,7 @@ static_library("fxcodec") {
   sources = [
     "core/include/fxcodec/fx_codec.h",
     "core/include/fxcodec/fx_codec_def.h",
+    "core/include/fxcodec/fx_codec_flate.h",
     "core/include/fxcodec/fx_codec_provider.h",
     "core/src/fxcodec/codec/codec_int.h",
     "core/src/fxcodec/codec/fx_codec.cpp",
diff --git a/core/include/fxcodec/fx_codec_flate.h b/core/include/fxcodec/fx_codec_flate.h
new file mode 100644 (file)
index 0000000..8495a37
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2015 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../../third_party/zlib_v128/zlib.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Note: Some of these return Z_* status codes from zlib.h.
+void* FPDFAPI_FlateInit(void* (*alloc_func)(void*, unsigned int, unsigned int),
+                        void (*free_func)(void*, void*));
+void FPDFAPI_FlateInput(void* context, const unsigned char* src_buf,
+                        unsigned int src_size);
+int FPDFAPI_FlateOutput(void* context, unsigned char* dest_buf,
+                        unsigned int dest_size);
+int FPDFAPI_FlateGetAvailIn(void* context);
+int FPDFAPI_FlateGetAvailOut(void* context);
+void FPDFAPI_FlateEnd(void* context);
+
+#ifdef __cplusplus
+}  // extern "C"
+#endif
index efe085c..fed4546 100644 (file)
@@ -4,12 +4,25 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "../../../../third_party/zlib_v128/zlib.h"
 #include "../../../include/fpdfapi/fpdf_parser.h"
 #include "../../../include/fxcodec/fx_codec.h"
+#include "../../../include/fxcodec/fx_codec_flate.h"
 #include "../../../include/fpdfapi/fpdf_module.h"
 #include "filters_int.h"
 
+extern "C" {
+
+static void* my_alloc_func(void* opaque, unsigned int items, unsigned int size)
+{
+    return FX_Alloc2D(uint8_t, items, size);
+}
+static void my_free_func(void* opaque, void* address)
+{
+    FX_Free(address);
+}
+
+}  // extern "C"
+
 CFX_DataFilter::CFX_DataFilter()
 {
     m_bEOF = FALSE;
@@ -288,23 +301,6 @@ void CPDF_DecryptFilter::v_FilterFinish(CFX_BinaryBuf& dest_buf)
     m_pCryptoHandler->DecryptFinish(m_pContext, dest_buf);
     m_pContext = NULL;
 }
-extern "C" {
-    static void* my_alloc_func (void* opaque, unsigned int items, unsigned int size)
-    {
-        return FX_Alloc2D(uint8_t, items, size);
-    }
-    static void   my_free_func  (void* opaque, void* address)
-    {
-        FX_Free(address);
-    }
-    void* FPDFAPI_FlateInit(void* (*alloc_func)(void*, unsigned int, unsigned int),
-                            void (*free_func)(void*, void*));
-    void FPDFAPI_FlateInput(void* context, const unsigned char* src_buf, unsigned int src_size);
-    int FPDFAPI_FlateOutput(void* context, unsigned char* dest_buf, unsigned int dest_size);
-    int FPDFAPI_FlateGetAvailIn(void* context);
-    int FPDFAPI_FlateGetAvailOut(void* context);
-    void FPDFAPI_FlateEnd(void* context);
-}
 CPDF_FlateFilter::CPDF_FlateFilter()
 {
     m_pContext = NULL;
index 99643e4..6223b9c 100644 (file)
@@ -7,18 +7,34 @@
 #include "../../../../third_party/base/nonstd_unique_ptr.h"
 #include "../../../../third_party/zlib_v128/zlib.h"
 #include "../../../include/fxcodec/fx_codec.h"
+#include "../../../include/fxcodec/fx_codec_flate.h"
 #include "codec_int.h"
 
 extern "C"
 {
-    static void* my_alloc_func (void* opaque, unsigned int items, unsigned int size)
+    static void* my_alloc_func(void* opaque, unsigned int items, unsigned int size)
     {
         return FX_Alloc2D(uint8_t, items, size);
     }
-    static void   my_free_func  (void* opaque, void* address)
+    static void my_free_func(void* opaque, void* address)
     {
         FX_Free(address);
     }
+    static int FPDFAPI_FlateGetTotalOut(void* context)
+    {
+        return ((z_stream*)context)->total_out;
+    }
+    static int FPDFAPI_FlateGetTotalIn(void* context)
+    {
+        return ((z_stream*)context)->total_in;
+    }
+    static void FPDFAPI_FlateCompress(unsigned char* dest_buf,
+                                      unsigned long* dest_size,
+                                      const unsigned char* src_buf,
+                                      unsigned long src_size)
+    {
+        compress(dest_buf, dest_size, src_buf, src_size);
+    }
     void* FPDFAPI_FlateInit(void* (*alloc_func)(void*, unsigned int, unsigned int),
                             void (*free_func)(void*, void*))
     {
@@ -37,10 +53,6 @@ extern "C"
         ((z_stream*)context)->next_in = (unsigned char*)src_buf;
         ((z_stream*)context)->avail_in = src_size;
     }
-    int FPDFAPI_FlateGetTotalOut(void* context)
-    {
-        return ((z_stream*)context)->total_out;
-    }
     int FPDFAPI_FlateOutput(void* context, unsigned char* dest_buf, unsigned int dest_size)
     {
         ((z_stream*)context)->next_out = dest_buf;
@@ -54,28 +66,21 @@ extern "C"
         }
         return ret;
     }
-    int FPDFAPI_FlateGetTotalIn(void* context)
+    int FPDFAPI_FlateGetAvailIn(void* context)
     {
-        return ((z_stream*)context)->total_in;
+        return ((z_stream*)context)->avail_in;
     }
     int FPDFAPI_FlateGetAvailOut(void* context)
     {
         return ((z_stream*)context)->avail_out;
     }
-    int FPDFAPI_FlateGetAvailIn(void* context)
-    {
-        return ((z_stream*)context)->avail_in;
-    }
     void FPDFAPI_FlateEnd(void* context)
     {
         inflateEnd((z_stream*)context);
         ((z_stream*)context)->zfree(0, context);
     }
-    void FPDFAPI_FlateCompress(unsigned char* dest_buf, unsigned long* dest_size, const unsigned char* src_buf, unsigned long src_size)
-    {
-        compress(dest_buf, dest_size, src_buf, src_size);
-    }
-}
+}  // extern "C"
+
 class CLZWDecoder
 {
 public:
index f95a4a6..7ccc15e 100644 (file)
       'sources': [
         'core/include/fxcodec/fx_codec.h',
         'core/include/fxcodec/fx_codec_def.h',
+        'core/include/fxcodec/fx_codec_flate.h',
         'core/include/fxcodec/fx_codec_provider.h',
         'core/src/fxcodec/codec/codec_int.h',
         'core/src/fxcodec/codec/fx_codec.cpp',