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
|
From 6c1a72c93812bf53515ff9293e3ab4849c09b282 Mon Sep 17 00:00:00 2001
From: Arnaud Le Blanc <arnaud.lb@gmail.com>
Date: Fri, 25 Oct 2024 13:59:21 +0200
Subject: [PATCH] Fix build on php 7.0 (#563)
Co-authored-by: Remi Collet <remi@remirepo.net>
---
kafka_error_exception.c | 6 +++---
php_rdkafka_priv.h | 16 +++++++++++++++-
rdkafka.c | 4 +---
tests/oauthbearer_integration.phpt | 2 +-
4 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/kafka_error_exception.c b/kafka_error_exception.c
index 8c19ca0c..f28730fd 100644
--- a/kafka_error_exception.c
+++ b/kafka_error_exception.c
@@ -39,9 +39,9 @@ void create_kafka_error(zval *return_value, const rd_kafka_error_t *error) /* {{
{
object_init_ex(return_value, ce_kafka_error);
- zend_string *message = zend_strpprintf(0, "%s (RD_KAFKA_RESP_ERR_%s)", rd_kafka_error_string(error), rd_kafka_error_name(error));
- zend_update_property_str(ce_kafka_error, Z_RDKAFKA_PROP_OBJ(return_value), ZEND_STRL("message"), message);
- zend_string_release(message);
+ char message[1024];
+ snprintf(message, sizeof(message), "%s (RD_KAFKA_RESP_ERR_%s)", rd_kafka_error_string(error), rd_kafka_error_name(error));
+ zend_update_property_string(ce_kafka_error, Z_RDKAFKA_PROP_OBJ(return_value), ZEND_STRL("message"), message);
zend_update_property_long(ce_kafka_error, Z_RDKAFKA_PROP_OBJ(return_value), ZEND_STRL("code"), rd_kafka_error_code(error));
zend_update_property_string(ce_kafka_error, Z_RDKAFKA_PROP_OBJ(return_value), ZEND_STRL("error_string"), rd_kafka_error_string(error));
diff --git a/php_rdkafka_priv.h b/php_rdkafka_priv.h
index 695a2739..ee6b440e 100644
--- a/php_rdkafka_priv.h
+++ b/php_rdkafka_priv.h
@@ -79,7 +79,21 @@ static zend_always_inline void *zend_object_alloc(size_t obj_size, zend_class_en
memset(obj, 0, obj_size - sizeof(zval));
return obj;
}
-#endif
+
+static zend_always_inline zend_string *zval_get_tmp_string(zval *op, zend_string **tmp) {
+ if (EXPECTED(Z_TYPE_P(op) == IS_STRING)) {
+ *tmp = NULL;
+ return Z_STR_P(op);
+ } else {
+ return *tmp = _zval_get_string_func(op);
+ }
+}
+static zend_always_inline void zend_tmp_string_release(zend_string *tmp) {
+ if (UNEXPECTED(tmp)) {
+ zend_string_release(tmp);
+ }
+}
+#endif // PHP_MINOR_VERSION < 3
#endif // PHP 7
diff --git a/rdkafka.c b/rdkafka.c
index 4029409a..727fc8c6 100644
--- a/rdkafka.c
+++ b/rdkafka.c
@@ -491,9 +491,7 @@ PHP_METHOD(RdKafka, oauthbearerSetToken)
zend_string *tmp_extension_val_str;
zend_string *extension_val_str = zval_get_tmp_string(extension_zval, &tmp_extension_val_str);
extensions[pos++] = estrdup(ZSTR_VAL(extension_val_str));
- if (tmp_extension_val_str) {
- zend_string_release(tmp_extension_val_str);
- }
+ zend_tmp_string_release(tmp_extension_val_str);
} ZEND_HASH_FOREACH_END();
}
diff --git a/tests/oauthbearer_integration.phpt b/tests/oauthbearer_integration.phpt
index b95de0f6..1b9399cb 100644
--- a/tests/oauthbearer_integration.phpt
+++ b/tests/oauthbearer_integration.phpt
@@ -20,7 +20,7 @@ function generateJws($scope = 'required-scope', $expiresInSeconds = 60)
$principal,
$expirySeconds,
$nowSeconds - 10,
- $scope,
+ $scope
);
$headerJwsSegment = 'eyJhbGciOiJub25lIn0';
$claimsJwsSegment = base64_encode($claimsJson);
|