summaryrefslogtreecommitdiffstats
path: root/php-ext-lz4-pr18.patch
blob: c2f60586faca3982863b6924a1d6b21935b5a3db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
From 408423281fa767b98bb66269fe098ad166c6fa16 Mon Sep 17 00:00:00 2001
From: Remi Collet <fedora@famillecollet.com>
Date: Thu, 5 Jan 2017 10:46:14 +0100
Subject: [PATCH] improve use of system liblz4

---
 lz4.c          | 50 ++++++++++++++++++++++++++++++++++++++++++--------
 tests/011.phpt |  4 ++--
 2 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/lz4.c b/lz4.c
index 27e3f66..175516e 100644
--- a/lz4.c
+++ b/lz4.c
@@ -35,6 +35,19 @@
 #include "lz4.h"
 #include "lz4hc.h"
 
+#if defined(LZ4HC_CLEVEL_MAX)
+/* version >= 1.7.5 */
+#define PHP_LZ4_CLEVEL_MAX LZ4HC_CLEVEL_MAX
+
+#elif defined (LZ4HC_MAX_CLEVEL)
+/* version >= 1.7.3 */
+#define PHP_LZ4_CLEVEL_MAX LZ4HC_MAX_CLEVEL
+
+#else
+/* older versions */
+#define PHP_LZ4_CLEVEL_MAX 16
+#endif
+
 static ZEND_FUNCTION(lz4_compress);
 static ZEND_FUNCTION(lz4_uncompress);
 
@@ -56,19 +69,40 @@ static zend_function_entry lz4_functions[] = {
     ZEND_FE_END
 };
 
+
+static PHP_MINIT_FUNCTION(lz4)
+{
+    REGISTER_LONG_CONSTANT("LZ4_CLEVEL_MAX", PHP_LZ4_CLEVEL_MAX, CONST_CS | CONST_PERSISTENT);
+
+    return SUCCESS;
+}
+
 ZEND_MINFO_FUNCTION(lz4)
 {
-    char buffer[128];
     php_info_print_table_start();
     php_info_print_table_row(2, "LZ4 support", "enabled");
     php_info_print_table_row(2, "Extension Version", LZ4_EXT_VERSION);
-#ifdef HAVE_LIBLZ4
-    snprintf(buffer, sizeof(buffer), "%s", "system library");
-#else
+#if !defined(HAVE_LIBLZ4)
+    /* Bundled library */
+    php_info_print_table_row(2, "LZ4 Version", LZ4_versionString());
+#elif defined(LZ4_VERSION_MAJOR)
+    /* Recent system library */
+    {
+    char buffer[128];
+
     snprintf(buffer, sizeof(buffer), "%d.%d.%d",
              LZ4_VERSION_MAJOR, LZ4_VERSION_MINOR, LZ4_VERSION_RELEASE);
+    php_info_print_table_row(2, "LZ4 headers Version", buffer);
+
+    /* LZ4_versionString is not usable, see https://github.com/lz4/lz4/issues/301 */
+    snprintf(buffer, sizeof(buffer), "%d.%d.%d",
+             LZ4_versionNumber()/10000, (LZ4_versionNumber()/100)%100, LZ4_versionNumber()%100);
+    php_info_print_table_row(2, "LZ4 library Version", buffer);
+    }
+#else
+    /* Old system library */
+    php_info_print_table_row(2, "LZ4 Version", "system library");
 #endif
-    php_info_print_table_row(2, "LZ4 Version", buffer);
     php_info_print_table_end();
 }
 
@@ -78,7 +112,7 @@ zend_module_entry lz4_module_entry = {
 #endif
     "lz4",
     lz4_functions,
-    NULL,
+    PHP_MINIT(lz4),
     NULL,
     NULL,
     NULL,
@@ -99,7 +133,7 @@ static ZEND_FUNCTION(lz4_compress)
     char *output;
     int output_len, data_len, dst_len;
     long level = 0;
-    long maxLevel = (long)LZ4HC_CLEVEL_MAX;
+    long maxLevel = (long)PHP_LZ4_CLEVEL_MAX;
     char *extra = NULL;
 #if ZEND_MODULE_API_NO >= 20141001
     size_t extra_len = -1;
@@ -147,7 +181,7 @@ static ZEND_FUNCTION(lz4_compress)
     } else {
         if (level > maxLevel || level < 0) {
             zend_error(E_WARNING, "lz4_compress: compression level (%ld)"
-                       " must be within 1..%d", level, maxLevel);
+                       " must be within 1..%ld", level, maxLevel);
             efree(output);
             RETURN_FALSE;
         }
diff --git a/tests/011.phpt b/tests/011.phpt
index 8e5fe3c..6b521ae 100644
--- a/tests/011.phpt
+++ b/tests/011.phpt
@@ -45,8 +45,8 @@ check_compress($data, -1);
 8 -- 2686 -- true
 9 -- 2686 -- true
 10 -- 2686 -- true
-11 -- 2683 -- true
-12 -- 2683 -- true
+11 -- 26%d -- true
+12 -- 26%d -- true
 *** Invalid Compression Level ***
 100 -- 0 -- false
 -1 -- 0 -- false