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