Skip to content

ext/pcntl pcntl_signal_get_handler update. #13902

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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ext/pcntl/pcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,17 @@ PHP_FUNCTION(pcntl_signal_get_handler)
Z_PARAM_LONG(signo)
ZEND_PARSE_PARAMETERS_END();

if (signo < 1 || signo > 32) {
zend_argument_value_error(1, "must be between 1 and 32");
// note: max signal on mac is SIGUSR2 (31), no real time signals.
static int sigmax = NSIG - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer a non-static variable here. Otherwise we have it in a data section that's shared with other threads too.
The compiler will constant-fold and take care of the branch at compile-time anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we had constexpr in C :-) but sure will change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we had constexpr in C :-)

That's in C23 ;) But sadly we don't even have C11 yet in PHP

#if defined(SIGRTMAX)
// oddily enough, NSIG on freebsd reports only 32 whereas SIGRTMIN starts at 65.
if (sigmax < SIGRTMAX) {
sigmax = SIGRTMAX;
}
#endif

if (signo < 1 || signo > sigmax) {
zend_argument_value_error(1, "must be between 1 and %d", sigmax);
RETURN_THROWS();
}

Expand Down