2
1

0001-updates-for-php7.4-and-php8.0.patch 7.7 KB

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