1From 4ad1b33e095924bd4ccf79295999dd54edaaac37 Mon Sep 17 00:00:00 2001 2From: Luca Boccassi <luca.boccassi@gmail.com> 3Date: Thu, 5 Mar 2020 22:51:22 +0000 4Subject: [PATCH] updates for php7.4 and php8.0 (#212) 5 6From upstream commit: 4ad1b33e095924bd4ccf79295999dd54edaaac37 7 8* travisci: enabled php7.4 and php8.0 9 10* updates for php7.4 and php8.0 11 12- travisci enabled php7.4 and php8.0 13- removed now unused references to TSRMLS_* 14 These flags were mostly already removed from the 15 php7 codebase but some instances were still present. 16 With php8 these produce compile errors. 17- fix tests for php8 and php7.4 18 New TypeErrors now get handled correctly in the test cases. 19- fix memory corruption in zmq.c 20 The conflicting line causes memory leaks on other php 21 version and causes a segfault on php8 and php7.4 22 The error was provocable with test case 23 021-callbackwarning.phpt. After removing of the line 24 valgrind showed no memory leak, so this line was probably 25 redundant. Also if you compare with zmqsocket constructor 26 this line is also not present. 27 28Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com> 29Signed-off-by: Adam Duskett <aduskett@gmail.com> 30--- 31 php_zmq_private.h | 4 ++-- 32 tests/016-callbackinvalidargs.phpt | 4 ++++ 33 tests/022-highwatermark.phpt | 6 +++--- 34 tests/bug_gh_43.phpt | 25 +++++++++++++++++-------- 35 zmq.c | 1 - 36 zmq_device.c | 14 +++++++------- 37 zmq_sockopt.c | 2 +- 38 7 files changed, 34 insertions(+), 22 deletions(-) 39 40diff --git a/php_zmq_private.h b/php_zmq_private.h 41index 49630e9..2e5cd3b 100644 42--- a/php_zmq_private.h 43+++ b/php_zmq_private.h 44@@ -156,9 +156,9 @@ typedef struct _php_zmq_device_object { 45 46 #define PHP_ZMQ_ERROR_HANDLING_INIT() zend_error_handling error_handling; 47 48-#define PHP_ZMQ_ERROR_HANDLING_THROW() zend_replace_error_handling(EH_THROW, php_zmq_socket_exception_sc_entry, &error_handling TSRMLS_CC); 49+#define PHP_ZMQ_ERROR_HANDLING_THROW() zend_replace_error_handling(EH_THROW, php_zmq_socket_exception_sc_entry, &error_handling); 50 51-#define PHP_ZMQ_ERROR_HANDLING_RESTORE() zend_restore_error_handling(&error_handling TSRMLS_CC); 52+#define PHP_ZMQ_ERROR_HANDLING_RESTORE() zend_restore_error_handling(&error_handling); 53 54 /* Compatibility macros between zeromq 2.x and 3.x */ 55 #ifndef ZMQ_DONTWAIT 56diff --git a/tests/016-callbackinvalidargs.phpt b/tests/016-callbackinvalidargs.phpt 57index a940e41..6bd0e75 100644 58--- a/tests/016-callbackinvalidargs.phpt 59+++ b/tests/016-callbackinvalidargs.phpt 60@@ -10,6 +10,8 @@ try { 61 echo "Fail\n"; 62 } catch (ZMQSocketException $e) { 63 echo "OK\n"; 64+} catch (TypeError $e) { 65+ echo "OK\n"; // on PHP8 66 } 67 68 try { 69@@ -18,6 +20,8 @@ try { 70 echo "Fail\n"; 71 } catch (ZMQSocketException $e) { 72 echo "OK\n"; 73+} catch (TypeError $e) { 74+ echo "OK\n"; // on PHP8 75 } 76 77 --EXPECT-- 78diff --git a/tests/022-highwatermark.phpt b/tests/022-highwatermark.phpt 79index 84be509..c1ff703 100644 80--- a/tests/022-highwatermark.phpt 81+++ b/tests/022-highwatermark.phpt 82@@ -1,11 +1,11 @@ 83 --TEST-- 84 Test that high-watermark works 85 --SKIPIF-- 86-<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> 87- 88+<?php 89+require_once(dirname(__FILE__) . '/skipif.inc'); 90 if (!defined('ZMQ::SOCKOPT_LINGER')) 91 die ("Skip Not compiled against new enough version"); 92- 93+?> 94 --FILE-- 95 <?php 96 97diff --git a/tests/bug_gh_43.phpt b/tests/bug_gh_43.phpt 98index bdc274a..923d074 100644 99--- a/tests/bug_gh_43.phpt 100+++ b/tests/bug_gh_43.phpt 101@@ -7,16 +7,25 @@ Test for Github issue #43 102 --FILE-- 103 <?php 104 105+error_reporting(0); 106+ 107 $context = new ZMQContext (1, false); 108 109 $sock1 = new ZMQSocket ($context, ZMQ::SOCKET_PUB); 110 $sock2 = new ZMQSocket ($context, ZMQ::SOCKET_SUB); 111 112-$device = new ZMQDevice ($sock1, $sock1, $sock1, $sock1); 113- 114-echo "OK"; 115-?> 116- 117---EXPECTF-- 118-Warning: ZMQDevice::__construct() expects at most 3 parameters, 4 given in %s/bug_gh_43.php on line %d 119-OK 120\ No newline at end of file 121+try { 122+ $device = new ZMQDevice ($sock1, $sock1, $sock1, $sock1); 123+ // on PHP7 and lower 124+ $lastError = error_get_last(); 125+ if(strpos($lastError['message'], 'ZMQDevice::__construct() expects at most 3 parameters, 4 given') !== false) 126+ echo "OK\n"; 127+ else{ 128+ echo "FAIL\n"; 129+ print_r($lastError); 130+ } 131+}catch(TypeError $e){ 132+ echo "OK\n"; // on PHP8 133+} 134+--EXPECT-- 135+OK 136diff --git a/zmq.c b/zmq.c 137index 942e69b..66196ea 100644 138--- a/zmq.c 139+++ b/zmq.c 140@@ -687,7 +687,6 @@ PHP_METHOD(zmqcontext, getsocket) 141 if (!php_zmq_connect_callback(return_value, &fci, &fci_cache, persistent_id)) { 142 php_zmq_socket_destroy(socket); 143 interns->socket = NULL; 144- zval_dtor(return_value); 145 return; 146 } 147 } 148diff --git a/zmq_device.c b/zmq_device.c 149index c7415c1..534f966 100644 150--- a/zmq_device.c 151+++ b/zmq_device.c 152@@ -41,7 +41,7 @@ 153 ZEND_EXTERN_MODULE_GLOBALS(php_zmq) 154 155 static 156-zend_bool s_invoke_device_cb (php_zmq_device_cb_t *cb, uint64_t current_ts TSRMLS_DC) 157+zend_bool s_invoke_device_cb (php_zmq_device_cb_t *cb, uint64_t current_ts) 158 { 159 zend_bool retval = 0; 160 zval params[1]; 161@@ -59,7 +59,7 @@ zend_bool s_invoke_device_cb (php_zmq_device_cb_t *cb, uint64_t current_ts TSRML 162 if (zend_call_function(&(cb->fci), &(cb->fci_cache)) == FAILURE) { 163 if (!EG(exception)) { 164 char *func_name = php_zmq_printable_func(&cb->fci, &cb->fci_cache); 165- zend_throw_exception_ex(php_zmq_device_exception_sc_entry_get (), 0 TSRMLS_CC, "Failed to invoke device callback %s()", func_name); 166+ zend_throw_exception_ex(php_zmq_device_exception_sc_entry_get (), 0, "Failed to invoke device callback %s()", func_name); 167 zval_ptr_dtor(¶ms[0]); 168 efree(func_name); 169 } 170@@ -94,7 +94,7 @@ int s_capture_message (void *socket, zmq_msg_t *msg, int more) 171 } 172 173 static 174-int s_calculate_timeout (php_zmq_device_object *intern TSRMLS_DC) 175+int s_calculate_timeout (php_zmq_device_object *intern) 176 { 177 int timeout = -1; 178 uint64_t current = php_zmq_clock (ZMQ_G (clock_ctx)); 179@@ -131,7 +131,7 @@ int s_calculate_timeout (php_zmq_device_object *intern TSRMLS_DC) 180 } 181 182 183-zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC) 184+zend_bool php_zmq_device (php_zmq_device_object *intern) 185 { 186 int errno_; 187 uint64_t last_message_received; 188@@ -186,7 +186,7 @@ zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC) 189 uint64_t current_ts = 0; 190 191 /* Calculate poll_timeout based on idle / timer cb */ 192- int timeout = s_calculate_timeout (intern TSRMLS_CC); 193+ int timeout = s_calculate_timeout (intern); 194 195 rc = zmq_poll(&items [0], 2, timeout); 196 if (rc < 0) { 197@@ -205,7 +205,7 @@ zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC) 198 if (intern->timer_cb.initialized && intern->timer_cb.timeout > 0) { 199 /* Is it timer to call the timer ? */ 200 if (intern->timer_cb.scheduled_at <= current_ts) { 201- if (!s_invoke_device_cb (&intern->timer_cb, current_ts TSRMLS_CC)) { 202+ if (!s_invoke_device_cb (&intern->timer_cb, current_ts)) { 203 zmq_msg_close (&msg); 204 return 1; 205 } 206@@ -217,7 +217,7 @@ zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC) 207 /* Is it timer to call the idle callback ? */ 208 if ((current_ts - last_message_received) >= intern->idle_cb.timeout && 209 intern->idle_cb.scheduled_at <= current_ts) { 210- if (!s_invoke_device_cb (&intern->idle_cb, current_ts TSRMLS_CC)) { 211+ if (!s_invoke_device_cb (&intern->idle_cb, current_ts)) { 212 zmq_msg_close (&msg); 213 return 1; 214 } 215diff --git a/zmq_sockopt.c b/zmq_sockopt.c 216index 1357032..14b59f0 100644 217--- a/zmq_sockopt.c 218+++ b/zmq_sockopt.c 219@@ -2036,7 +2036,7 @@ PHP_METHOD(zmqsocket, setsockopt) 220 long key; 221 zval *zv; 222 223- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz/", &key, &zv) == FAILURE) { 224+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz/", &key, &zv) == FAILURE) { 225 return; 226 } 227 228-- 2292.31.1 230 231