summaryrefslogtreecommitdiffstats
path: root/hdr_histogram-lib0114.patch
blob: c53ba3a59926673b80c920666ec9972ef57c263d (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
From b62e02bf30b5967f6b5514dfba025c8c8ce1a431 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Tue, 1 Mar 2022 10:31:21 +0100
Subject: [PATCH 1/3] Fix for libhdr_histogram version 0.11.4

---
 config.m4      | 76 ++++++++++++++++++++++++++++++--------------------
 hdrhistogram.c | 34 ++++++++++++++--------
 2 files changed, 68 insertions(+), 42 deletions(-)

diff --git a/config.m4 b/config.m4
index aa4fec8..729a038 100644
--- a/config.m4
+++ b/config.m4
@@ -3,41 +3,57 @@ PHP_ARG_WITH(hdrhistogram,
     [  --with-hdrhistogram[=DIR]    Enable "hdrhistogram" extension support])
 
 if test "$PHP_HDRHISTOGRAM" != "no"; then
-    SEARCH_PATH="/usr/local /usr"
-    SEARCH_FOR="/include/hdr/hdr_histogram.h"  # you most likely want to change this
+    AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
 
-    if test -r $PHP_HDRHISTOGRAM/$SEARCH_FOR; then
-        HDRHISTOGRAM_PATH=$PHP_HDRHISTOGRAM
+    if test "$PHP_HDRHISTOGRAM" = "yes" -a -x "$PKG_CONFIG" && $PKG_CONFIG --exists hdr_histogram; then
+
+        AC_MSG_CHECKING([for hdrhistogram from pkg-config])
+        LIBHDR_CFLAGS=`$PKG_CONFIG hdr_histogram --cflags`
+        LIBHDR_LIBDIR=`$PKG_CONFIG hdr_histogram --libs`
+        LIBHDR_VERSON=`$PKG_CONFIG hdr_histogram --modversion`
+        AC_MSG_RESULT(found $LIBHDR_VERSON)
+        if $PKG_CONFIG hdr_histogram --atleast-version 0.11.4; then
+            AC_DEFINE(HAVE_HDRHISTOGRAM_0_11_4,1,[ ])
+        fi
+        PHP_EVAL_LIBLINE($LIBHDR_LIBDIR, HDRHISTOGRAM_SHARED_LIBADD)
+        PHP_EVAL_INCLINE($LIBHDR_CFLAGS)
     else
-        AC_MSG_CHECKING([for hdrhistogram files in default path])
-        for i in $SEARCH_PATH ; do
-            if test -r $i/$SEARCH_FOR; then
-            HDRHISTOGRAM_PATH=$i
-            AC_MSG_RESULT(found in $i)
+        SEARCH_PATH="/usr/local /usr"
+        SEARCH_FOR="/include/hdr/hdr_histogram.h"  # you most likely want to change this
+
+        if test -r $PHP_HDRHISTOGRAM/$SEARCH_FOR; then
+            HDRHISTOGRAM_PATH=$PHP_HDRHISTOGRAM
+        else
+            AC_MSG_CHECKING([for hdrhistogram files in default path])
+            for i in $SEARCH_PATH ; do
+                if test -r $i/$SEARCH_FOR; then
+                HDRHISTOGRAM_PATH=$i
+                AC_MSG_RESULT(found in $i)
+            fi
+            done
         fi
-        done
-    fi
 
-    if test -z "$HDRHISTOGRAM_PATH"; then
-      AC_MSG_RESULT([not found])
-      AC_MSG_ERROR([Please reinstall the hdrhistogram library])
-    fi
+        if test -z "$HDRHISTOGRAM_PATH"; then
+          AC_MSG_RESULT([not found])
+          AC_MSG_ERROR([Please reinstall the hdrhistogram library])
+        fi
 
-    PHP_ADD_INCLUDE($HDRHISTOGRAM_PATH/include)
-
-    LIBNAME=hdr_histogram
-    LIBSYMBOL=hdr_init
-
-    PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
-        [
-            PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $HDRHISTOGRAM_PATH/$PHP_LIBDIR, HDRHISTOGRAM_SHARED_LIBADD)
-            AC_DEFINE(HAVE_HDRHISTOGRAM,1,[ ])
-        ],[
-            AC_MSG_ERROR([wrong hdrhistogram lib version or lib not found])
-        ],[
-            -L$HDRHISTOGRAM_PATH/$PHP_LIBDIR
-        ]
-    )
+        PHP_ADD_INCLUDE($HDRHISTOGRAM_PATH/include)
+
+        LIBNAME=hdr_histogram
+        LIBSYMBOL=hdr_init
+
+        PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
+            [
+                PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $HDRHISTOGRAM_PATH/$PHP_LIBDIR, HDRHISTOGRAM_SHARED_LIBADD)
+                AC_DEFINE(HAVE_HDRHISTOGRAM,1,[ ])
+            ],[
+                AC_MSG_ERROR([wrong hdrhistogram lib version or lib not found])
+            ],[
+                -L$HDRHISTOGRAM_PATH/$PHP_LIBDIR
+            ]
+        )
+    fi
 
     PHP_SUBST(HDRHISTOGRAM_SHARED_LIBADD)
 
diff --git a/hdrhistogram.c b/hdrhistogram.c
index d3099a1..5a60a53 100644
--- a/hdrhistogram.c
+++ b/hdrhistogram.c
@@ -117,17 +117,17 @@ PHP_MINFO_FUNCTION(hdrhistogram)
 PHP_FUNCTION(hdr_init)
 {
     struct hdr_histogram *hdr;
-    long lowest_trackable_value, highest_trackable_value, significant_figures;
+    long lowest_discernible_value, highest_trackable_value, significant_figures;
     int res;
 
     if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll",
-                &lowest_trackable_value, &highest_trackable_value, &significant_figures) == FAILURE) {
+                &lowest_discernible_value, &highest_trackable_value, &significant_figures) == FAILURE) {
         php_error_docref(NULL, E_WARNING, "Invalid arguments passed.");
 
         RETURN_FALSE;
     }
 
-    res = hdr_init(lowest_trackable_value, highest_trackable_value, significant_figures, &hdr);
+    res = hdr_init(lowest_discernible_value, highest_trackable_value, significant_figures, &hdr);
 
     if (res == 0) {
         hdr_register_hdr_resource(return_value, hdr);
@@ -342,8 +342,11 @@ PHP_FUNCTION(hdr_add)
     hdra = hdr_fetch_resource(a, return_value);
     hdrb = hdr_fetch_resource(b, return_value);
 
+#ifdef HAVE_HDRHISTOGRAM_0_11_4
+    res = hdr_init(hdra->lowest_discernible_value, hdra->highest_trackable_value, hdra->significant_figures, &hdr_new);
+#else
     res = hdr_init(hdra->lowest_trackable_value, hdra->highest_trackable_value, hdra->significant_figures, &hdr_new);
-
+#endif
     hdr_add(hdr_new, hdra);
     hdr_add(hdr_new, hdrb);
 
@@ -477,9 +480,16 @@ PHP_FUNCTION(hdr_export)
 
     array_init(return_value);
 
+
+#ifdef HAVE_HDRHISTOGRAM_0_11_4
+    if (hdr->lowest_discernible_value > 1) {
+        add_assoc_long(return_value, "ltv", hdr->lowest_discernible_value);
+    }
+#else
     if (hdr->lowest_trackable_value > 1) {
         add_assoc_long(return_value, "ltv", hdr->lowest_trackable_value);
     }
+#endif
     if (hdr->highest_trackable_value != 60000) {
         add_assoc_long(return_value, "htv", hdr->highest_trackable_value);
     }
@@ -513,7 +523,7 @@ PHP_FUNCTION(hdr_import)
 {
     struct hdr_histogram *hdr;
     zval *import, *value, *item;
-    long lowest_trackable_value, highest_trackable_value, significant_figures;
+    long lowest_discernible_value, highest_trackable_value, significant_figures;
     int res, count;
     zend_ulong i, bucket, skipped;
 
@@ -522,12 +532,12 @@ PHP_FUNCTION(hdr_import)
     }
 
     if (value = hdr_hash_find(Z_ARRVAL_P(import), "ltv", 4)) {
-        lowest_trackable_value = Z_LVAL_P(value);
+        lowest_discernible_value = Z_LVAL_P(value);
     } else {
-        lowest_trackable_value = 1;
+        lowest_discernible_value = 1;
     }
 
-    if (lowest_trackable_value <= 0) {
+    if (lowest_discernible_value <= 0) {
         php_error_docref(NULL, E_WARNING, "lowest_trackable_value (ltv) must be >= 1.");
         RETURN_FALSE;
     }
@@ -560,7 +570,7 @@ PHP_FUNCTION(hdr_import)
         skipped = 0;
     }
 
-    if (skipped < 0 || lowest_trackable_value < 1 || highest_trackable_value < lowest_trackable_value || significant_figures < 1) {
+    if (skipped < 0 || lowest_discernible_value < 1 || highest_trackable_value < lowest_discernible_value || significant_figures < 1) {
         php_error_docref(NULL, E_WARNING, "Invalid values for ltv, htv, sf or sk keys given.");
         RETURN_FALSE;
     }
@@ -570,7 +580,7 @@ PHP_FUNCTION(hdr_import)
     // version 3 format
     if (value != NULL && Z_TYPE_P(value) == IS_ARRAY) {
         count = zend_hash_num_elements(Z_ARRVAL_P(value));
-        res = hdr_init(lowest_trackable_value, highest_trackable_value, significant_figures, &hdr);
+        res = hdr_init(lowest_discernible_value, highest_trackable_value, significant_figures, &hdr);
 
         if (res == 0) {
             hdr_register_hdr_resource(return_value, hdr);
@@ -612,7 +622,7 @@ PHP_FUNCTION(hdr_import)
     if (value != NULL && Z_TYPE_P(value) == IS_ARRAY) {
         count = zend_hash_num_elements(Z_ARRVAL_P(value));
 
-        res = hdr_init(lowest_trackable_value, highest_trackable_value, significant_figures, &hdr);
+        res = hdr_init(lowest_discernible_value, highest_trackable_value, significant_figures, &hdr);
 
         if (res == 0) {
             hdr_register_hdr_resource(return_value, hdr);
@@ -655,7 +665,7 @@ PHP_FUNCTION(hdr_import)
 
     // version 2 format
     if (value != NULL && Z_TYPE_P(value) == IS_ARRAY) {
-        res = hdr_init(lowest_trackable_value, highest_trackable_value, significant_figures, &hdr);
+        res = hdr_init(lowest_discernible_value, highest_trackable_value, significant_figures, &hdr);
 
         if (res == 0) {
             hdr_register_hdr_resource(return_value, hdr);

From 82a52859195755097cf3437f957ded89834533c0 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Thu, 27 Apr 2023 09:01:20 +0200
Subject: [PATCH 2/3] improve phpinfo with extension and library version (from
 0.11.7)

---
 config.m4      |  3 +++
 hdrhistogram.c | 11 +++++++++++
 2 files changed, 14 insertions(+)

diff --git a/config.m4 b/config.m4
index 729a038..955d15c 100644
--- a/config.m4
+++ b/config.m4
@@ -12,6 +12,9 @@ if test "$PHP_HDRHISTOGRAM" != "no"; then
         LIBHDR_LIBDIR=`$PKG_CONFIG hdr_histogram --libs`
         LIBHDR_VERSON=`$PKG_CONFIG hdr_histogram --modversion`
         AC_MSG_RESULT(found $LIBHDR_VERSON)
+        if $PKG_CONFIG hdr_histogram --atleast-version 0.11.7; then
+            AC_DEFINE(HAVE_HDRHISTOGRAM_0_11_7,1,[ ])
+        fi
         if $PKG_CONFIG hdr_histogram --atleast-version 0.11.4; then
             AC_DEFINE(HAVE_HDRHISTOGRAM_0_11_4,1,[ ])
         fi
diff --git a/hdrhistogram.c b/hdrhistogram.c
index 5a60a53..fff37db 100644
--- a/hdrhistogram.c
+++ b/hdrhistogram.c
@@ -3,8 +3,12 @@
 #endif
 
 #include "php.h"
+#include "ext/standard/info.h"
 #include "hdr/hdr_histogram.h"
 #include "hdr/hdr_histogram_log.h"
+#ifdef HAVE_HDRHISTOGRAM_0_11_7
+#include "hdr/hdr_histogram_version.h"
+#endif
 #include "php_hdrhistogram.h"
 
 #if PHP_VERSION_ID < 80000
@@ -112,6 +116,13 @@ PHP_RSHUTDOWN_FUNCTION(hdrhistogram)
 
 PHP_MINFO_FUNCTION(hdrhistogram)
 {
+	php_info_print_table_start();
+
+	php_info_print_table_row(2, "hdrhistogram", "enabled");
+	php_info_print_table_row(2, "Extension version", HDR_VERSION);
+#ifdef HDR_HISTOGRAM_VERSION
+	php_info_print_table_row(2, "Library version", HDR_HISTOGRAM_VERSION);
+#endif
 }
 
 PHP_FUNCTION(hdr_init)

From 21e89822c9c98ede68c0a16ece78c3323788888a Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Thu, 27 Apr 2023 09:03:59 +0200
Subject: [PATCH 3/3] use normalized macro name

---
 hdrhistogram.c     | 6 +++---
 php_hdrhistogram.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hdrhistogram.c b/hdrhistogram.c
index fff37db..0a241be 100644
--- a/hdrhistogram.c
+++ b/hdrhistogram.c
@@ -67,7 +67,7 @@ zend_module_entry hdrhistogram_module_entry = {
     PHP_RINIT(hdrhistogram),               /* Request init callback */
     PHP_RSHUTDOWN(hdrhistogram),           /* Request shutdown callback */
     PHP_MINFO(hdrhistogram),               /* Module info callback */
-    HDR_VERSION,
+    PHP_HDR_HISTOGRAM_VERSION,
     STANDARD_MODULE_PROPERTIES
 };
 
@@ -118,8 +118,8 @@ PHP_MINFO_FUNCTION(hdrhistogram)
 {
 	php_info_print_table_start();
 
-	php_info_print_table_row(2, "hdrhistogram", "enabled");
-	php_info_print_table_row(2, "Extension version", HDR_VERSION);
+	php_info_print_table_row(2, "hdrhistogram support", "enabled");
+	php_info_print_table_row(2, "Extension version", PHP_HDR_HISTOGRAM_VERSION);
 #ifdef HDR_HISTOGRAM_VERSION
 	php_info_print_table_row(2, "Library version", HDR_HISTOGRAM_VERSION);
 #endif
diff --git a/php_hdrhistogram.h b/php_hdrhistogram.h
index 68fd9ae..894b224 100644
--- a/php_hdrhistogram.h
+++ b/php_hdrhistogram.h
@@ -5,7 +5,7 @@
 
 extern zend_module_entry hdrhistogram_module_entry;
 #define phpext_hdrhistogram_ptr &hdrhistogram_module_entry
-#define HDR_VERSION "0.4.2"
+#define PHP_HDR_HISTOGRAM_VERSION "0.4.2"
 
 PHP_MINIT_FUNCTION(hdrhistogram);
 PHP_MSHUTDOWN_FUNCTION(hdrhistogram);