Skip to content

Commit

Permalink
Fixed PHP 5.2 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
whatthejeff committed Aug 4, 2014
1 parent 8fda629 commit b4f46f0
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,6 +1,7 @@
language: php

php:
- 5.2
- 5.3
- 5.4
- 5.5
Expand Down
10 changes: 9 additions & 1 deletion test_helpers.c
Expand Up @@ -63,6 +63,14 @@
#if PHP_VERSION_ID < 50300
typedef opcode_handler_t user_opcode_handler_t;

#if (defined (__GNUC__) && __GNUC__ > 2 ) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX)
# define EXPECTED(condition) __builtin_expect(condition, 1)
# define UNEXPECTED(condition) __builtin_expect(condition, 0)
#else
# define EXPECTED(condition) (condition)
# define UNEXPECTED(condition) (condition)
#endif

#define Z_ADDREF_P(z) ((z)->refcount++)

#define zend_parse_parameters_none() zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")
Expand Down Expand Up @@ -424,7 +432,7 @@ static PHP_FUNCTION(set_new_overload)
/* {{{ proto bool set_exit_overload(callback cb)
Register a callback, called on exit()/die() */
static PHP_FUNCTION(set_exit_overload)
{
{
overload_helper(pth_exit_handler, ZEND_EXIT, &THG(exit_handler), INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
Expand Down
1 change: 1 addition & 0 deletions tests/set_exit_overload.phpt
Expand Up @@ -2,6 +2,7 @@
set_exit_overload()
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3', '<')) die("skip this test is for PHP 5.3+.");
if (!extension_loaded('test_helpers')) die('skip test_helpers extension not loaded');
?>
--FILE--
Expand Down
1 change: 1 addition & 0 deletions tests/set_exit_overload_exception.phpt
Expand Up @@ -2,6 +2,7 @@
set_exit_overload() with an uncaught exception
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3', '<')) die("skip this test is for PHP 5.3+.");
if (!extension_loaded('test_helpers')) die('skip test_helpers extension not loaded');
?>
--FILE--
Expand Down
18 changes: 18 additions & 0 deletions tests/set_exit_overload_exception_named.phpt
@@ -0,0 +1,18 @@
--TEST--
set_exit_overload() with an uncaught exception with a named function
--SKIPIF--
<?php
if (!extension_loaded('test_helpers')) die('skip test_helpers extension not loaded');
?>
--FILE--
<?php
function _exit($arg = NULL) { throw new Exception("Please don't segfault"); }
set_exit_overload('_exit');
try {
exit("hi");
} catch(Exception $exception) {
echo $exception->getMessage();
}
?>
--EXPECT--
Please don't segfault
28 changes: 28 additions & 0 deletions tests/set_exit_overload_named.phpt
@@ -0,0 +1,28 @@
--TEST--
set_exit_overload() with a named function
--SKIPIF--
<?php
if (!extension_loaded('test_helpers')) die('skip test_helpers extension not loaded');
?>
--FILE--
<?php
function _exit1($arg = NULL) { var_dump($arg); echo "FALSE\n"; return false; }
set_exit_overload('_exit1');
die("DIE 1");
die;
exit;
function _exit2($arg = NULL) { var_dump($arg); echo "TRUE\n"; return true; }
set_exit_overload('_exit2');
die("DIE 4");
echo "HAHA";
?>
--EXPECT--
string(5) "DIE 1"
FALSE
NULL
FALSE
NULL
FALSE
string(5) "DIE 4"
TRUE
DIE 4
2 changes: 1 addition & 1 deletion tests/set_new_overload_error_undefined_callback.phpt
Expand Up @@ -12,6 +12,6 @@ var_dump(set_new_overload('callback'));

var_dump(get_class(new Bar));
--EXPECTF--
Warning: set_new_overload() expects parameter 1 to be a valid callback, function 'callback' not found or invalid function name in %s on line %d
Warning: set_new_overload() expects parameter 1 to be %s
NULL
string(3) "Bar"
2 changes: 1 addition & 1 deletion tests/set_new_overload_private_method.phpt
Expand Up @@ -31,7 +31,7 @@ var_dump(get_class(new Bar));
var_dump($cb->set_overload());
var_dump(get_class(new Bar));
--EXPECTF--
Warning: set_new_overload() expects parameter 1 to be a valid callback, cannot access private method CB::callback() in %s on line %d
Warning: set_new_overload() expects parameter 1 to be %s
NULL
string(3) "Bar"
bool(true)
Expand Down
1 change: 1 addition & 0 deletions tests/unset_exit_overload.phpt
Expand Up @@ -2,6 +2,7 @@
set_exit_overload()
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3', '<')) die("skip this test is for PHP 5.3+.");
if (!extension_loaded('test_helpers')) die('skip test_helpers extension not loaded');
?>
--FILE--
Expand Down
16 changes: 16 additions & 0 deletions tests/unset_exit_overload_named.phpt
@@ -0,0 +1,16 @@
--TEST--
set_exit_overload() with a named function
--SKIPIF--
<?php
if (!extension_loaded('test_helpers')) die('skip test_helpers extension not loaded');
?>
--FILE--
<?php
function _exit() { echo "FALSE\n"; return false; }
set_exit_overload('_exit');
unset_exit_overload();
die("DIE");
echo "HAHA";
?>
--EXPECT--
DIE

0 comments on commit b4f46f0

Please sign in to comment.