Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support exit() function in PHP 8.4 #185

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

@zonuexe zonuexe marked this pull request as draft November 23, 2024 05:49
@zonuexe
Copy link
Author

zonuexe commented Nov 23, 2024

This change seems to allow me to hook an exit function instead of ZEND_EXIT, but the tests don't pass so far.

Can someone help me out?

=====================================================================
PHP         : /Users/megurine/local/php84/bin/php
PHP_SAPI    : cli
PHP_VERSION : 8.4.1-dev
ZEND_VERSION: 4.4.1-dev
PHP_OS      : Darwin - Darwin tadsan14.local 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000 arm64
INI actual  : /Users/megurine/repo/zend/uopz/tmp-php.ini
More .INIs  :
CWD         : /Users/megurine/repo/zend/uopz
Extra dirs  :
VALGRIND    : Not used
=====================================================================
TIME START 2024-11-23 05:42:15
=====================================================================
PASS uopz_set_return [tests/001.phpt]
PASS uopz_get_return [tests/002.phpt]
PASS uopz_unset_return [tests/003.phpt]
PASS uopz_set_mock [tests/004.phpt]
PASS uopz_get_mock [tests/005.phpt]
PASS uopz_unset_mock [tests/006.phpt]
BORK Termsig=6 [tests/007.phpt] reason: invalid output from SKIPIF
PASS uopz_get_static [tests/007_1.phpt]
PASS uopz_set_static [tests/008.phpt]
PASS uopz_set_hook [tests/009.phpt]
PASS uopz_get_hook [tests/010.phpt]
PASS uopz_unset_hook [tests/011.phpt]
PASS uopz_add_function [tests/012.phpt]
PASS uopz_del_function [tests/013.phpt]
PASS uopz_flags [tests/016.phpt]
PASS uopz_redefine [tests/017.phpt]
PASS uopz_undefine [tests/018.phpt]
PASS uopz_set_property/uopz_get_property [tests/019.phpt]
FAIL uopz_get_exit_status [tests/020.phpt]
PASS uopz.disabled [tests/021.phpt]
PASS init method call non string method [tests/027.phpt]
PASS init method call non object object [tests/028.phpt]
PASS init method call object ref [tests/029.phpt]
PASS init ns fcall [tests/032.phpt]
PASS new IS_UNUSED op1 with mock [tests/033.phpt]
PASS fetch class constant non existent class [tests/035.phpt]
PASS init static method call constructor with no constructor [tests/036.phpt]
PASS fetch class string no mock [tests/038.phpt]
PASS fetch class string ref no mock [tests/039.phpt]
PASS fetch class undef class no mock [tests/040.phpt]
PASS uopz_set_static with array [tests/bugs/0001-uopz_set_static.phpt]
PASS uopz_set_static with empty array [tests/bugs/0002-uopz_set_static_clear.phpt]
PASS call uopz_get_property in a class scope [tests/bugs/0003-uopz_get_property.phpt]
PASS call uopz_set_property in a class scope [tests/bugs/0004-uopz_set_property.phpt]
PASS prototype mixup setting return [tests/bugs/0005-uopz_set_return_prototype.phpt]
BORK Termsig=6 [tests/bugs/0006-uopz-opcache-const-subst.phpt] reason: invalid output from SKIPIF
PASS get hook not case insensitive [tests/bugs/gh100.phpt]
PASS uopz_undefine with namespaced constants does not delete constant [tests/bugs/gh102.phpt]
FAIL uopz.exit enabled [tests/bugs/gh106.phpt]
PASS uopz.exit disabled [tests/bugs/gh106a.phpt]
PASS hook closure call inconsistency [tests/bugs/gh109.phpt]
PASS uopz_set_return() overload confusion [tests/bugs/gh167.phpt]
PASS uopz_set_static() does not check that $static is an array [tests/bugs/gh179.phpt]
PASS github #43 [tests/bugs/gh43.phpt]
PASS github #53 [tests/bugs/gh53.phpt]
PASS Segfault after uopz_set_static [tests/bugs/gh64.phpt]
PASS github #68: uopz_set_mock should not hang when mock with no-arg constructor is called with args [tests/bugs/gh68.phpt]
PASS bugs in cuf(a) [tests/bugs/gh73.phpt]
PASS cuf/cufa wierdness [tests/bugs/gh85.phpt]
PASS set return on interface method [tests/bugs/gh86.phpt]
PASS get hook not case insensitive [tests/bugs/gh99.phpt]
=====================================================================
TIME END 2024-11-23 05:42:17

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :     0
Exts tested     :    27
---------------------------------------------------------------------

Number of tests :    51                49
Tests borked    :     2 (  3.9%) --------
Tests skipped   :     0 (  0.0%) --------
Tests warned    :     0 (  0.0%) (  0.0%)
Tests failed    :     2 (  3.9%) (  4.1%)
Tests passed    :    47 ( 92.2%) ( 95.9%)
---------------------------------------------------------------------
Time taken      : 2.263 seconds
=====================================================================

=====================================================================
BORKED TEST SUMMARY
---------------------------------------------------------------------
Termsig=6 [/Users/megurine/repo/zend/uopz/tests/007.phpt]
Termsig=6 [/Users/megurine/repo/zend/uopz/tests/bugs/0006-uopz-opcache-const-subst.phpt]
=====================================================================

@cmb69 cmb69 force-pushed the support/php84-exit branch from c2ba746 to f39ef57 Compare November 23, 2024 11:39
@cmb69
Copy link
Collaborator

cmb69 commented Nov 23, 2024

Note that I've pushed a commit regarding the proper calling convention (otherwise won't build on Windows, and might have issues on other platforms).

And I have force-pushed to get the latest CI improvements (faster/more reliable builds on Windows; fail-fast:false, so the tests will run).

@cmb69
Copy link
Collaborator

cmb69 commented Nov 23, 2024

Oh, and thank you for the PR! This might be getting somewhere. :)

@zonuexe zonuexe marked this pull request as ready for review November 23, 2024 12:19
@zonuexe
Copy link
Author

zonuexe commented Nov 23, 2024

@cmb69 Thank you for your support!

Instead of fiddling with the exit function handler, what is brittle at
best, we employ the return mechanism to install our own exit handler
function.
This are certainly no longer valid since we create an additional
closure, but relying on these numbers rarely makes sense anyway.
@cmb69
Copy link
Collaborator

cmb69 commented Nov 23, 2024

This still needs some work:

  • failing tests should let CI fail (unrelated to this PR, but needs to be fixed that was actually related to this PR; forgot to set the the exit_status if exit is disabled)
  • check segfaults under OPcache (are these related to this PR?no, these are actually XFAILS)
  • make sure that users can't override our exit/die handlers
  • cleanup code mess
  • fix handlers (no need to built-in an EXIT handler for PHP >= 8.4)

We override exit/die on request startup, so we should clean that up on
request shutdown.
uopz already implements its own `call_user_func(_array)`, so we do the
same with `exit`.  While the former has different reasons (compiler
might optimize these calls away), the use case is similar enough to not
use a different mechanism.  This is also a bit cleaner, and may avoid
crashes[1], at the cost of needing to maintain a copy of the exit
function implementation.

[1] <krakjoe@e902fb2>
@cmb69
Copy link
Collaborator

cmb69 commented Nov 24, 2024

While the clean-up turned out rather different to what I had in mind (I completely changed the return mechanism approach, back to swapping the exit handler), this looks good to me now. User who want to, can now use uopz_set_return() and friends to mock exit() calls in PHP 8.4, but otherwise this should be backward compatible with older PHP versions.

Thank you @zonuexe for getting this into motion! If you find some time, please check that everything works as desired now.

@zonuexe
Copy link
Author

zonuexe commented Nov 24, 2024

@cmb69 I really appreciate your work. I don't have any code that depends on exit so at least I shouldn't be affected by this change.

@cmb69
Copy link
Collaborator

cmb69 commented Nov 24, 2024

Maybe @remicollet is still interested in uopz, and will have a look at this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build fails with PHP 8.4
2 participants