Skip to content

Commit

Permalink
Merge branch 'krakjoe:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kornrunner authored Aug 8, 2024
2 parents 02de1dc + 77dd7c1 commit 4e9074a
Show file tree
Hide file tree
Showing 19 changed files with 253 additions and 53 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github: krakjoe
custom: https://gofund.me/c34f3dde
22 changes: 9 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
name: Build and Test
on:
push:
pull_request:
schedule:
- cron: '18 3 * * *'
on: [push, pull_request, workflow_dispatch]
jobs:
ubuntu:
strategy:
matrix:
version: ["PHP-8.0", "master"]
version: ["PHP-8.0", "PHP-8.1", "PHP-8.2", "PHP-8.3", "master"]
opcache: ["opcache.enable_cli=0", "opcache.enable_cli=1"]
debug: ["enable-debug", "disable-debug"]
runs-on: ubuntu-latest
Expand All @@ -33,7 +29,7 @@ jobs:
make -j$(nproc)
sudo make install
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Generate Build Files
run: /opt/bin/phpize
- name: Configure Build
Expand All @@ -53,7 +49,7 @@ jobs:
- name: Generate Test Coverage
run: lcov -c --directory ./src/.libs --exclude *Zend* --exclude */usr/include* --output-file coverage.info
- name: Coveralls
uses: coverallsapp/github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage.info
Expand All @@ -63,16 +59,16 @@ jobs:
shell: cmd
strategy:
matrix:
version: ["8.0", "8.1"]
version: ["8.0", "8.1", "8.2", "8.3", "8.4"]
arch: [x64, x86]
ts: [nts, ts]
runs-on: windows-latest
runs-on: windows-2022
steps:
- name: Checkout uopz
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup PHP
id: setup-php
uses: cmb69/setup-php-sdk@v0.7
uses: php/setup-php-sdk@v0.9
with:
version: ${{matrix.version}}
arch: ${{matrix.arch}}
Expand All @@ -89,4 +85,4 @@ jobs:
- name: Build
run: nmake
- name: Run Tests
run: nmake test TESTS=tests
run: nmake test TESTS="--show-diff tests"
59 changes: 37 additions & 22 deletions config.m4
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
PHP_ARG_ENABLE(uopz, whether to enable uopz support,
[ --enable-uopz Enable uopz support])
PHP_ARG_ENABLE([uopz],
[whether to enable uopz support],
[AS_HELP_STRING([--enable-uopz],
[Enable uopz support])])

PHP_ARG_ENABLE(uopz-coverage, whether to enable uopz coverage support,
[ --enable-uopz-coverage Enable uopz coverage support], no, no)
PHP_ARG_ENABLE([uopz-coverage],
[whether to enable uopz coverage support],
[AS_HELP_STRING([--enable-uopz-coverage],
[Enable uopz coverage support])],
[no],
[no])

PHP_ARG_WITH(uopz-sanitize, whether to enable AddressSanitizer for uopz,
[ --with-uopz-sanitize Build uopz with AddressSanitizer support], no, no)
PHP_ARG_WITH([uopz-sanitize],
[whether to enable AddressSanitizer for uopz],
[AS_HELP_STRING([--with-uopz-sanitize],
[Build uopz with AddressSanitizer support])],
[no],
[no])

if test "$PHP_UOPZ" != "no"; then
if test "$PHP_UOPZ_SANITIZE" != "no"; then
AS_VAR_IF([PHP_UOPZ_SANITIZE], [no],, [
EXTRA_LDFLAGS="-lasan"
EXTRA_CFLAGS="-fsanitize=address -fno-omit-frame-pointer"
PHP_SUBST(EXTRA_LDFLAGS)
PHP_SUBST(EXTRA_CFLAGS)
fi
EXTRA_CFLAGS="-fsanitize=address -fno-omit-frame-pointer"
PHP_SUBST([EXTRA_LDFLAGS])
PHP_SUBST([EXTRA_CFLAGS])
])

PHP_NEW_EXTENSION(uopz, uopz.c src/util.c src/return.c src/hook.c src/constant.c src/function.c src/class.c src/handlers.c src/executors.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
PHP_ADD_BUILD_DIR($ext_builddir/src, 1)
PHP_ADD_INCLUDE($ext_builddir)
PHP_NEW_EXTENSION([uopz], m4_normalize([
src/class.c
src/constant.c
src/executors.c
src/function.c
src/handlers.c
src/hook.c
src/return.c
src/util.c
uopz.c
]),
[$ext_shared],,
[-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
PHP_ADD_BUILD_DIR([$ext_builddir/src])
PHP_ADD_INCLUDE([$ext_builddir])

AC_MSG_CHECKING([uopz coverage])
if test "$PHP_UOPZ_COVERAGE" != "no"; then
AC_MSG_RESULT([enabled])

PHP_ADD_MAKEFILE_FRAGMENT
else
AC_MSG_RESULT([disabled])
fi
AS_VAR_IF([PHP_UOPZ_COVERAGE], [no],, [PHP_ADD_MAKEFILE_FRAGMENT])
fi
8 changes: 4 additions & 4 deletions config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
ARG_ENABLE("uopz", "for uopz support", "no");

if (PHP_UOPZ != "no") {
EXTENSION("uopz", "uopz.c");
EXTENSION("uopz", "uopz.c", null, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
ADD_SOURCES(
configure_module_dirname + "/src",
"util.c return.c hook.c constant.c function.c class.c handlers.c executors.c",
configure_module_dirname + "/src",
"util.c return.c hook.c constant.c function.c class.c handlers.c executors.c",
"uopz"
);
);
ADD_FLAG("CFLAGS_UOPZ", "/I" + configure_module_dirname + "");
}

1 change: 1 addition & 0 deletions src/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ zend_bool uopz_set_static(zend_class_entry *clazz, zend_string *function, zval *
zval_ptr_dtor(v);
}

ZEND_ASSERT(Z_TYPE_P(statics) == IS_ARRAY);
if (!(y = zend_hash_find(Z_ARRVAL_P(statics), k))) {
ZVAL_NULL(v);

Expand Down
6 changes: 3 additions & 3 deletions tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ var_dump(uopz_set_return(Foo::class, "bazQuux", function(){}));

var_dump(uopz_get_return(Foo::class, "bazQuux"));
?>
--EXPECT--
--EXPECTF--
bool(true)
bool(true)
bool(true)
object(Closure)#1 (0) {
object(Closure)#1 (%d) {%A
}
NULL
bool(true)
bool(true)
bool(true)
object(Closure)#2 (0) {
object(Closure)#2 (%d) {%A
}
6 changes: 3 additions & 3 deletions tests/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ var_dump(uopz_unset_return("bar"));

var_dump(uopz_get_return(DateTime::class, "__construct"));
?>
--EXPECT--
--EXPECTF--
bool(true)
bool(true)
bool(true)
bool(false)
bool(false)
bool(true)
object(Closure)#2 (0) {
}
object(Closure)#2 (%d) {
%A}
bool(true)
bool(true)
NULL
5 changes: 5 additions & 0 deletions tests/007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
uopz_get_static
--EXTENSIONS--
uopz
--SKIPIF--
<?php
uopz_allow_exit(true);
if (version_compare(PHP_VERSION, "8.3.0") >= 0) die("skip only for PHP < 8.3.0");
?>
--INI--
uopz.disable=0
--FILE--
Expand Down
114 changes: 114 additions & 0 deletions tests/007_1.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
--TEST--
uopz_get_static
--EXTENSIONS--
uopz
--SKIPIF--
<?php
uopz_allow_exit(true);
if (version_compare(PHP_VERSION, "8.3.0") < 0) die("skip only for PHP >= 8.3.0");
?>
--INI--
uopz.disable=0
--FILE--
<?php
class Foo {
public function method() {
static $vars = [1,2,3,4,5];
static $bar = FOO;

$vars[] = 6;
}

public function nostatics() {}
}
const FOO = "bar";

function nostatics() {}

$foo = new Foo();

var_dump(uopz_get_static(Foo::class, "method"));

$foo->method();

var_dump(uopz_get_static(Foo::class, "method"));

try {
uopz_get_static(Foo::class, "none");
} catch (RuntimeException $ex) {
var_dump($ex->getMessage());
}

try {
uopz_get_static("none");
} catch (RuntimeException $ex) {
var_dump($ex->getMessage());
}

try {
uopz_get_static(DateTime::class, "__construct");
} catch(RuntimeException $ex) {
var_dump($ex->getMessage());
}

try {
uopz_get_static("phpversion");
} catch(RuntimeException $ex) {
var_dump($ex->getMessage());
}

try {
uopz_get_static(Foo::class, "nostatics");
} catch(RuntimeException $ex) {
var_dump($ex->getMessage());
}

try {
uopz_get_static("nostatics");
} catch(RuntimeException $ex) {
var_dump($ex->getMessage());
}
?>
--EXPECTF--
array(2) {
["vars"]=>
array(5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
}
["bar"]=>
NULL
}
array(2) {
["vars"]=>
array(6) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
[5]=>
int(6)
}
["bar"]=>
string(3) "bar"
}
string(%d) "failed to get statics from method %s::%s, it does not exist"
string(%d) "failed to get statics from function %s, it does not exist"
string(%d) "failed to get statics from internal method %s::%s"
string(%d) "failed to get statics from internal function %s"
string(%d) "failed to set statics in method %s::%s, no statics declared"
string(%d) "failed to set statics in function %s, no statics declared"
6 changes: 3 additions & 3 deletions tests/010.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ var_dump(uopz_get_hook("none"));

var_dump(uopz_get_hook(DateTime::class, "__construct"));
?>
--EXPECT--
--EXPECTF--
bool(true)
object(Closure)#1 (1) {
object(Closure)#1 (%d) {%A
["parameter"]=>
array(1) {
["$arg"]=>
string(10) "<required>"
}
}
object(Closure)#2 (0) {
object(Closure)#2 (%d) {%A
}
NULL
NULL
2 changes: 1 addition & 1 deletion tests/012.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Foo {
public function exists() {}
}

uopz_add_function(Foo::class, "METHOD", /** doc **/ function(Type $type = null, $with = null, $args = null, ... $vars) : bool {
uopz_add_function(Foo::class, "METHOD", /** doc **/ function(Type|null $type = null, $with = null, $args = null, ... $vars) : bool {
return $this->priv(true);
});

Expand Down
9 changes: 9 additions & 0 deletions tests/017.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
--TEST--
uopz_redefine
--SKIPIF--
<?php
uopz_allow_exit(true);
$protect = extension_loaded("Zend OPcache")
&& ($conf = opcache_get_configuration()["directives"])
&& array_key_exists("opcache.protect_memory", $conf)
&& $conf["opcache.protect_memory"];
if ($protect) die("xfail known issues with constant redefinition; see #151");
?>
--EXTENSIONS--
uopz
--INI--
Expand Down
9 changes: 9 additions & 0 deletions tests/018.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
--TEST--
uopz_undefine
--SKIPIF--
<?php
uopz_allow_exit(true);
$protect = extension_loaded("Zend OPcache")
&& ($conf = opcache_get_configuration()["directives"])
&& array_key_exists("opcache.protect_memory", $conf)
&& $conf["opcache.protect_memory"];
if ($protect) die("xfail known issues with constant redefinition; see #151");
?>
--EXTENSIONS--
uopz
--INI--
Expand Down
6 changes: 6 additions & 0 deletions tests/bugs/0006-uopz-opcache-const-subst.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ uopz
uopz_allow_exit(true);
$opcache = ini_get("opcache.enable_cli");
if ($opcache === false || $opcache === "0") die("skip opcache required");

$protect = extension_loaded("Zend OPcache")
&& ($conf = opcache_get_configuration()["directives"])
&& array_key_exists("opcache.protect_memory", $conf)
&& $conf["opcache.protect_memory"];
if ($protect) die("xfail known issues with constant redefinition; see #151");
?>
--INI--
uopz.disable=0
Expand Down
Loading

0 comments on commit 4e9074a

Please sign in to comment.