hc
2025-02-14 bbb9540dc49f70f6b703d1c8d1b85fa5f602d86e
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
From 4ad1b33e095924bd4ccf79295999dd54edaaac37 Mon Sep 17 00:00:00 2001
From: Luca Boccassi <luca.boccassi@gmail.com>
Date: Thu, 5 Mar 2020 22:51:22 +0000
Subject: [PATCH] updates for php7.4 and php8.0 (#212)
 
From upstream commit: 4ad1b33e095924bd4ccf79295999dd54edaaac37
 
* travisci: enabled php7.4 and php8.0
 
* updates for php7.4 and php8.0
 
- travisci enabled php7.4 and php8.0
- removed now unused references to TSRMLS_*
  These flags were mostly already removed from the
  php7 codebase but some instances were still present.
  With php8 these produce compile errors.
- fix tests for php8 and php7.4
  New TypeErrors now get handled correctly in the test cases.
- fix memory corruption in zmq.c
  The conflicting line causes memory leaks on other php
  version and causes a segfault on php8 and php7.4
  The error was provocable with test case
  021-callbackwarning.phpt. After removing of the line
  valgrind showed no memory leak, so this line was probably
  redundant. Also if you compare with zmqsocket constructor
  this line is also not present.
 
Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
Signed-off-by: Adam Duskett <aduskett@gmail.com>
---
 php_zmq_private.h                  |  4 ++--
 tests/016-callbackinvalidargs.phpt |  4 ++++
 tests/022-highwatermark.phpt       |  6 +++---
 tests/bug_gh_43.phpt               | 25 +++++++++++++++++--------
 zmq.c                              |  1 -
 zmq_device.c                       | 14 +++++++-------
 zmq_sockopt.c                      |  2 +-
 7 files changed, 34 insertions(+), 22 deletions(-)
 
diff --git a/php_zmq_private.h b/php_zmq_private.h
index 49630e9..2e5cd3b 100644
--- a/php_zmq_private.h
+++ b/php_zmq_private.h
@@ -156,9 +156,9 @@ typedef struct _php_zmq_device_object  {
 
 #define PHP_ZMQ_ERROR_HANDLING_INIT() zend_error_handling error_handling;
 
-#define PHP_ZMQ_ERROR_HANDLING_THROW() zend_replace_error_handling(EH_THROW, php_zmq_socket_exception_sc_entry, &error_handling TSRMLS_CC);
+#define PHP_ZMQ_ERROR_HANDLING_THROW() zend_replace_error_handling(EH_THROW, php_zmq_socket_exception_sc_entry, &error_handling);
 
-#define PHP_ZMQ_ERROR_HANDLING_RESTORE() zend_restore_error_handling(&error_handling TSRMLS_CC);
+#define PHP_ZMQ_ERROR_HANDLING_RESTORE() zend_restore_error_handling(&error_handling);
 
 /* Compatibility macros between zeromq 2.x and 3.x */
 #ifndef ZMQ_DONTWAIT
diff --git a/tests/016-callbackinvalidargs.phpt b/tests/016-callbackinvalidargs.phpt
index a940e41..6bd0e75 100644
--- a/tests/016-callbackinvalidargs.phpt
+++ b/tests/016-callbackinvalidargs.phpt
@@ -10,6 +10,8 @@ try {
     echo "Fail\n";
 } catch (ZMQSocketException $e) {
     echo "OK\n";
+} catch (TypeError $e) {
+     echo "OK\n"; // on PHP8
 }
 
 try {
@@ -18,6 +20,8 @@ try {
     echo "Fail\n";
 } catch (ZMQSocketException $e) {
     echo "OK\n";
+} catch (TypeError $e) {
+     echo "OK\n"; // on PHP8
 }
 
 --EXPECT--
diff --git a/tests/022-highwatermark.phpt b/tests/022-highwatermark.phpt
index 84be509..c1ff703 100644
--- a/tests/022-highwatermark.phpt
+++ b/tests/022-highwatermark.phpt
@@ -1,11 +1,11 @@
 --TEST--
 Test that high-watermark works
 --SKIPIF--
-<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
-
+<?php
+require_once(dirname(__FILE__) . '/skipif.inc');
 if (!defined('ZMQ::SOCKOPT_LINGER'))
     die ("Skip Not compiled against new enough version");
-
+?>
 --FILE--
 <?php
 
diff --git a/tests/bug_gh_43.phpt b/tests/bug_gh_43.phpt
index bdc274a..923d074 100644
--- a/tests/bug_gh_43.phpt
+++ b/tests/bug_gh_43.phpt
@@ -7,16 +7,25 @@ Test for Github issue #43
 --FILE--
 <?php
 
+error_reporting(0);
+
 $context = new ZMQContext (1, false);
 
 $sock1 = new ZMQSocket ($context, ZMQ::SOCKET_PUB);
 $sock2 = new ZMQSocket ($context, ZMQ::SOCKET_SUB);
 
-$device = new ZMQDevice ($sock1, $sock1, $sock1, $sock1);
-
-echo "OK";
-?>
-
---EXPECTF--
-Warning: ZMQDevice::__construct() expects at most 3 parameters, 4 given in %s/bug_gh_43.php on line %d
-OK
\ No newline at end of file
+try {
+    $device = new ZMQDevice ($sock1, $sock1, $sock1, $sock1);
+    // on PHP7 and lower
+    $lastError = error_get_last();
+    if(strpos($lastError['message'], 'ZMQDevice::__construct() expects at most 3 parameters, 4 given') !== false)
+         echo "OK\n";
+    else{
+        echo "FAIL\n";
+        print_r($lastError);
+    }
+}catch(TypeError $e){
+     echo "OK\n"; // on PHP8
+}
+--EXPECT--
+OK
diff --git a/zmq.c b/zmq.c
index 942e69b..66196ea 100644
--- a/zmq.c
+++ b/zmq.c
@@ -687,7 +687,6 @@ PHP_METHOD(zmqcontext, getsocket)
             if (!php_zmq_connect_callback(return_value, &fci, &fci_cache, persistent_id)) {
                 php_zmq_socket_destroy(socket);
                 interns->socket = NULL;
-                zval_dtor(return_value);
                 return;
             }
         }
diff --git a/zmq_device.c b/zmq_device.c
index c7415c1..534f966 100644
--- a/zmq_device.c
+++ b/zmq_device.c
@@ -41,7 +41,7 @@
 ZEND_EXTERN_MODULE_GLOBALS(php_zmq)
 
 static
-zend_bool s_invoke_device_cb (php_zmq_device_cb_t *cb, uint64_t current_ts TSRMLS_DC)
+zend_bool s_invoke_device_cb (php_zmq_device_cb_t *cb, uint64_t current_ts)
 {
     zend_bool retval = 0;
     zval params[1];
@@ -59,7 +59,7 @@ zend_bool s_invoke_device_cb (php_zmq_device_cb_t *cb, uint64_t current_ts TSRML
     if (zend_call_function(&(cb->fci), &(cb->fci_cache)) == FAILURE) {
         if (!EG(exception)) {
             char *func_name = php_zmq_printable_func(&cb->fci, &cb->fci_cache);
-            zend_throw_exception_ex(php_zmq_device_exception_sc_entry_get (), 0 TSRMLS_CC, "Failed to invoke device callback %s()", func_name);
+            zend_throw_exception_ex(php_zmq_device_exception_sc_entry_get (), 0, "Failed to invoke device callback %s()", func_name);
             zval_ptr_dtor(&params[0]);
             efree(func_name);
         }
@@ -94,7 +94,7 @@ int s_capture_message (void *socket, zmq_msg_t *msg, int more)
 }
 
 static
-int s_calculate_timeout (php_zmq_device_object *intern TSRMLS_DC)
+int s_calculate_timeout (php_zmq_device_object *intern)
 {
     int timeout = -1;
     uint64_t current = php_zmq_clock (ZMQ_G (clock_ctx));
@@ -131,7 +131,7 @@ int s_calculate_timeout (php_zmq_device_object *intern TSRMLS_DC)
 }
 
 
-zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC)
+zend_bool php_zmq_device (php_zmq_device_object *intern)
 {
     int errno_;
     uint64_t last_message_received;
@@ -186,7 +186,7 @@ zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC)
         uint64_t current_ts = 0;
 
         /* Calculate poll_timeout based on idle / timer cb */
-        int timeout = s_calculate_timeout (intern TSRMLS_CC);
+        int timeout = s_calculate_timeout (intern);
 
         rc = zmq_poll(&items [0], 2, timeout);
         if (rc < 0) {
@@ -205,7 +205,7 @@ zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC)
         if (intern->timer_cb.initialized && intern->timer_cb.timeout > 0) {
             /* Is it timer to call the timer ? */
             if (intern->timer_cb.scheduled_at <= current_ts) {
-                if (!s_invoke_device_cb (&intern->timer_cb, current_ts TSRMLS_CC)) {
+                if (!s_invoke_device_cb (&intern->timer_cb, current_ts)) {
                     zmq_msg_close (&msg);
                     return 1;
                 }
@@ -217,7 +217,7 @@ zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC)
             /* Is it timer to call the idle callback ? */
             if ((current_ts - last_message_received) >= intern->idle_cb.timeout &&
                 intern->idle_cb.scheduled_at <= current_ts) {
-                if (!s_invoke_device_cb (&intern->idle_cb, current_ts TSRMLS_CC)) {
+                if (!s_invoke_device_cb (&intern->idle_cb, current_ts)) {
                     zmq_msg_close (&msg);
                     return 1;
                 }
diff --git a/zmq_sockopt.c b/zmq_sockopt.c
index 1357032..14b59f0 100644
--- a/zmq_sockopt.c
+++ b/zmq_sockopt.c
@@ -2036,7 +2036,7 @@ PHP_METHOD(zmqsocket, setsockopt)
     long key;
     zval *zv;
 
-    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz/", &key, &zv) == FAILURE) {
+    if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz/", &key, &zv) == FAILURE) {
         return;
     }
 
-- 
2.31.1