Skip to content

Commit 4ad1b33

Browse files
authored
updates for php7.4 and php8.0 (#212)
* 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.
1 parent 97a073c commit 4ad1b33

11 files changed

+56
-32
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ dist: trusty
22

33
language: php
44
php:
5-
#- nightly requires more changes
6-
#- 7.4 requires more changes
5+
- nightly
6+
- 7.4
77
- 7.3
88
- 7.2
99
- 7.1
@@ -33,4 +33,4 @@ sudo: false
3333

3434
cache:
3535
directories:
36-
- $HOME/zeromq-cache
36+
- $HOME/zeromq-cache

options/sockopts_set.gsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ PHP_METHOD(zmqsocket, setsockopt)
1313
zend_long key;
1414
zval *zv;
1515

16-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz/", &key, &zv) == FAILURE) {
16+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz/", &key, &zv) == FAILURE) {
1717
return;
1818
}
1919

php_zmq_private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ typedef struct _php_zmq_device_object {
156156

157157
#define PHP_ZMQ_ERROR_HANDLING_INIT() zend_error_handling error_handling;
158158

159-
#define PHP_ZMQ_ERROR_HANDLING_THROW() zend_replace_error_handling(EH_THROW, php_zmq_socket_exception_sc_entry, &error_handling TSRMLS_CC);
159+
#define PHP_ZMQ_ERROR_HANDLING_THROW() zend_replace_error_handling(EH_THROW, php_zmq_socket_exception_sc_entry, &error_handling);
160160

161-
#define PHP_ZMQ_ERROR_HANDLING_RESTORE() zend_restore_error_handling(&error_handling TSRMLS_CC);
161+
#define PHP_ZMQ_ERROR_HANDLING_RESTORE() zend_restore_error_handling(&error_handling);
162162

163163
/* Compatibility macros between zeromq 2.x and 3.x */
164164
#ifndef ZMQ_DONTWAIT

tests/016-callbackinvalidargs.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ try {
1010
echo "Fail\n";
1111
} catch (ZMQSocketException $e) {
1212
echo "OK\n";
13+
} catch (TypeError $e) {
14+
echo "OK\n"; // on PHP8
1315
}
1416

1517
try {
@@ -18,6 +20,8 @@ try {
1820
echo "Fail\n";
1921
} catch (ZMQSocketException $e) {
2022
echo "OK\n";
23+
} catch (TypeError $e) {
24+
echo "OK\n"; // on PHP8
2125
}
2226

2327
--EXPECT--

tests/021-callbackwarning.phpt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,25 @@ Test warning in callback
55
--FILE--
66
<?php
77

8+
error_reporting(0);
9+
810
function generate_warning($a, $b)
911
{
1012
in_array(1, 1);
1113
}
1214

13-
$socket = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REQ, 'persistent_socket', 'generate_warning');
14-
15-
--EXPECTF--
16-
Warning: in_array() expects parameter 2 to be array, %s given in %s on line %d
17-
15+
try {
16+
$socket = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REQ, 'persistent_socket', 'generate_warning');
17+
// on PHP7 and lower
18+
$lastError = error_get_last();
19+
if(strpos($lastError['message'], 'in_array() expects parameter 2 to be array') !== false)
20+
echo "OK\n";
21+
else{
22+
echo "FAIL\n";
23+
print_r($lastError);
24+
}
25+
}catch(TypeError $e){
26+
echo "OK\n"; // on PHP8
27+
}
28+
--EXPECT--
29+
OK

tests/022-highwatermark.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
--TEST--
22
Test that high-watermark works
33
--SKIPIF--
4-
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5-
4+
<?php
5+
require_once(dirname(__FILE__) . '/skipif.inc');
66
if (!defined('ZMQ::SOCKOPT_LINGER'))
77
die ("Skip Not compiled against new enough version");
8-
8+
?>
99
--FILE--
1010
<?php
1111

tests/055-socks-proxy.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Test socks proxy
33
--SKIPIF--
44
<?php
55
require_once(dirname(__FILE__) . '/skipif.inc');
6-
if(!fsockopen('127.0.0.1', 5557, $errCode, $errStr, 0.1))
6+
if(!@fsockopen('127.0.0.1', 5557, $errCode, $errStr, 0.1))
77
die ('skip test requires local SOCKS5 proxy on port 5557');
88
?>
99
--FILE--

tests/bug_gh_43.phpt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@ Test for Github issue #43
77
--FILE--
88
<?php
99

10+
error_reporting(0);
11+
1012
$context = new ZMQContext (1, false);
1113

1214
$sock1 = new ZMQSocket ($context, ZMQ::SOCKET_PUB);
1315
$sock2 = new ZMQSocket ($context, ZMQ::SOCKET_SUB);
1416

15-
$device = new ZMQDevice ($sock1, $sock1, $sock1, $sock1);
16-
17-
echo "OK";
18-
?>
19-
20-
--EXPECTF--
21-
Warning: ZMQDevice::__construct() expects at most 3 parameters, 4 given in %s/bug_gh_43.php on line %d
22-
OK
17+
try {
18+
$device = new ZMQDevice ($sock1, $sock1, $sock1, $sock1);
19+
// on PHP7 and lower
20+
$lastError = error_get_last();
21+
if(strpos($lastError['message'], 'ZMQDevice::__construct() expects at most 3 parameters, 4 given') !== false)
22+
echo "OK\n";
23+
else{
24+
echo "FAIL\n";
25+
print_r($lastError);
26+
}
27+
}catch(TypeError $e){
28+
echo "OK\n"; // on PHP8
29+
}
30+
--EXPECT--
31+
OK

zmq.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,6 @@ PHP_METHOD(zmqcontext, getsocket)
687687
if (!php_zmq_connect_callback(return_value, &fci, &fci_cache, persistent_id)) {
688688
php_zmq_socket_destroy(socket);
689689
interns->socket = NULL;
690-
zval_dtor(return_value);
691690
return;
692691
}
693692
}

zmq_device.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
ZEND_EXTERN_MODULE_GLOBALS(php_zmq)
4242

4343
static
44-
zend_bool s_invoke_device_cb (php_zmq_device_cb_t *cb, uint64_t current_ts TSRMLS_DC)
44+
zend_bool s_invoke_device_cb (php_zmq_device_cb_t *cb, uint64_t current_ts)
4545
{
4646
zend_bool retval = 0;
4747
zval params[1];
@@ -59,7 +59,7 @@ zend_bool s_invoke_device_cb (php_zmq_device_cb_t *cb, uint64_t current_ts TSRML
5959
if (zend_call_function(&(cb->fci), &(cb->fci_cache)) == FAILURE) {
6060
if (!EG(exception)) {
6161
char *func_name = php_zmq_printable_func(&cb->fci, &cb->fci_cache);
62-
zend_throw_exception_ex(php_zmq_device_exception_sc_entry_get (), 0 TSRMLS_CC, "Failed to invoke device callback %s()", func_name);
62+
zend_throw_exception_ex(php_zmq_device_exception_sc_entry_get (), 0, "Failed to invoke device callback %s()", func_name);
6363
zval_ptr_dtor(&params[0]);
6464
efree(func_name);
6565
}
@@ -94,7 +94,7 @@ int s_capture_message (void *socket, zmq_msg_t *msg, int more)
9494
}
9595

9696
static
97-
int s_calculate_timeout (php_zmq_device_object *intern TSRMLS_DC)
97+
int s_calculate_timeout (php_zmq_device_object *intern)
9898
{
9999
int timeout = -1;
100100
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)
131131
}
132132

133133

134-
zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC)
134+
zend_bool php_zmq_device (php_zmq_device_object *intern)
135135
{
136136
int errno_;
137137
uint64_t last_message_received;
@@ -186,7 +186,7 @@ zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC)
186186
uint64_t current_ts = 0;
187187

188188
/* Calculate poll_timeout based on idle / timer cb */
189-
int timeout = s_calculate_timeout (intern TSRMLS_CC);
189+
int timeout = s_calculate_timeout (intern);
190190

191191
rc = zmq_poll(&items [0], 2, timeout);
192192
if (rc < 0) {
@@ -205,7 +205,7 @@ zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC)
205205
if (intern->timer_cb.initialized && intern->timer_cb.timeout > 0) {
206206
/* Is it timer to call the timer ? */
207207
if (intern->timer_cb.scheduled_at <= current_ts) {
208-
if (!s_invoke_device_cb (&intern->timer_cb, current_ts TSRMLS_CC)) {
208+
if (!s_invoke_device_cb (&intern->timer_cb, current_ts)) {
209209
zmq_msg_close (&msg);
210210
return 1;
211211
}
@@ -217,7 +217,7 @@ zend_bool php_zmq_device (php_zmq_device_object *intern TSRMLS_DC)
217217
/* Is it timer to call the idle callback ? */
218218
if ((current_ts - last_message_received) >= intern->idle_cb.timeout &&
219219
intern->idle_cb.scheduled_at <= current_ts) {
220-
if (!s_invoke_device_cb (&intern->idle_cb, current_ts TSRMLS_CC)) {
220+
if (!s_invoke_device_cb (&intern->idle_cb, current_ts)) {
221221
zmq_msg_close (&msg);
222222
return 1;
223223
}

zmq_sockopt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ PHP_METHOD(zmqsocket, setsockopt)
14761476
zend_long key;
14771477
zval *zv;
14781478

1479-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz/", &key, &zv) == FAILURE) {
1479+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz/", &key, &zv) == FAILURE) {
14801480
return;
14811481
}
14821482

0 commit comments

Comments
 (0)