Skip to content

Refactor php_module_startup() #8303

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

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 7 additions & 22 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1960,24 +1960,6 @@ int php_register_extensions(zend_module_entry * const * ptr, int count)
return SUCCESS;
}

/* A very long time ago php_module_startup() was refactored in a way
* which broke calling it with more than one additional module.
* This alternative to php_register_extensions() works around that
* by walking the shallower structure.
*
* See algo: https://bugs.php.net/bug.php?id=63159
*/
static int php_register_extensions_bc(zend_module_entry *ptr, int count)
{
while (count--) {
if (zend_register_internal_module(ptr++) == NULL) {
return FAILURE;
}
}
return SUCCESS;
}
/* }}} */

#ifdef PHP_WIN32
static _invalid_parameter_handler old_invalid_parameter_handler;

Expand Down Expand Up @@ -2012,11 +1994,12 @@ void dummy_invalid_parameter_handler(
#endif

/* {{{ php_module_startup */
int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint32_t num_additional_modules)
zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_module)
{
zend_utility_functions zuf;
zend_utility_values zuv;
int retval = SUCCESS, module_number=0; /* for REGISTER_INI_ENTRIES() */
zend_result retval = SUCCESS;
int module_number = 0; /* for REGISTER_INI_ENTRIES() */
char *php_os;
zend_module_entry *module;

Expand Down Expand Up @@ -2243,7 +2226,9 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
}

/* start additional PHP extensions */
php_register_extensions_bc(additional_modules, num_additional_modules);
if (additional_module && (zend_register_internal_module(additional_module) == NULL)) {
return FAILURE;
}

/* load and startup extensions compiled as shared objects (aka DLLs)
as requested by php.ini entries
Expand Down Expand Up @@ -2278,7 +2263,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
module->version = PHP_VERSION;
module->info_func = PHP_MINFO(php_core);
}

/* freeze the list of observer fcall_init handlers */
zend_observer_post_startup();

Expand Down
2 changes: 1 addition & 1 deletion main/php_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
BEGIN_EXTERN_C()
PHPAPI int php_request_startup(void);
PHPAPI void php_request_shutdown(void *dummy);
PHPAPI int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint32_t num_additional_modules);
PHPAPI zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_module);
PHPAPI void php_module_shutdown(void);
PHPAPI int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals);

Expand Down
5 changes: 1 addition & 4 deletions sapi/apache2handler/sapi_apache2.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,7 @@ extern zend_module_entry php_apache_module;

static int php_apache2_startup(sapi_module_struct *sapi_module)
{
if (php_module_startup(sapi_module, &php_apache_module, 1)==FAILURE) {
return FAILURE;
}
return SUCCESS;
return php_module_startup(sapi_module, &php_apache_module);
}

static sapi_module_struct apache2_sapi_module = {
Expand Down
5 changes: 1 addition & 4 deletions sapi/cgi/cgi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,10 +966,7 @@ static int sapi_cgi_deactivate(void)

static int php_cgi_startup(sapi_module_struct *sapi_module)
{
if (php_module_startup(sapi_module, &cgi_module_entry, 1) == FAILURE) {
return FAILURE;
}
return SUCCESS;
return php_module_startup(sapi_module, &cgi_module_entry);
}

/* {{{ sapi_module_struct cgi_sapi_module */
Expand Down
5 changes: 1 addition & 4 deletions sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,7 @@ static void sapi_cli_send_header(sapi_header_struct *sapi_header, void *server_c

static int php_cli_startup(sapi_module_struct *sapi_module) /* {{{ */
{
if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
return FAILURE;
}
return SUCCESS;
return php_module_startup(sapi_module, NULL);
}
/* }}} */

Expand Down
2 changes: 1 addition & 1 deletion sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ const zend_function_entry server_additional_functions[] = {

static int sapi_cli_server_startup(sapi_module_struct *sapi_module) /* {{{ */
{
return php_module_startup(sapi_module, &cli_server_module_entry, 1);
return php_module_startup(sapi_module, &cli_server_module_entry);
} /* }}} */

static size_t sapi_cli_server_ub_write(const char *str, size_t str_length) /* {{{ */
Expand Down
5 changes: 1 addition & 4 deletions sapi/embed/php_embed.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ static void php_embed_register_variables(zval *track_vars_array)
/* Module initialization (MINIT) */
static int php_embed_startup(sapi_module_struct *sapi_module)
{
if (php_module_startup(sapi_module, NULL, 0) == FAILURE) {
return FAILURE;
}
return SUCCESS;
return php_module_startup(sapi_module, NULL);
}

EMBED_SAPI_API sapi_module_struct php_embed_module = {
Expand Down
5 changes: 1 addition & 4 deletions sapi/fpm/fpm/fpm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,7 @@ static int sapi_cgi_deactivate(void) /* {{{ */

static int php_cgi_startup(sapi_module_struct *sapi_module) /* {{{ */
{
if (php_module_startup(sapi_module, &cgi_module_entry, 1) == FAILURE) {
return FAILURE;
}
return SUCCESS;
return php_module_startup(sapi_module, &cgi_module_entry);
}
/* }}} */

Expand Down
5 changes: 1 addition & 4 deletions sapi/fuzzer/fuzzer-sapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ const char HARDCODED_INI[] =

static int startup(sapi_module_struct *sapi_module)
{
if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
return FAILURE;
}
return SUCCESS;
return php_module_startup(sapi_module, NULL);
}

static size_t ub_write(const char *str, size_t str_length)
Expand Down
4 changes: 2 additions & 2 deletions sapi/litespeed/lsapi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void init_sapi_from_env(sapi_module_struct *sapi_module)
/* {{{ php_lsapi_startup */
static int php_lsapi_startup(sapi_module_struct *sapi_module)
{
if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
if (php_module_startup(sapi_module, NULL)==FAILURE) {
return FAILURE;
}
argv0 = sapi_module->executable_location;
Expand Down Expand Up @@ -1518,7 +1518,7 @@ int main( int argc, char * argv[] )

lsapi_sapi_module.ini_defaults = sapi_lsapi_ini_defaults;

if (php_module_startup(&lsapi_sapi_module, &litespeed_module_entry, 1) == FAILURE) {
if (php_module_startup(&lsapi_sapi_module, &litespeed_module_entry) == FAILURE) {
#ifdef ZTS
tsrm_shutdown();
#endif
Expand Down
2 changes: 1 addition & 1 deletion sapi/phpdbg/phpdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ static zend_module_entry sapi_phpdbg_module_entry = {

static inline int php_sapi_phpdbg_module_startup(sapi_module_struct *module) /* {{{ */
{
if (php_module_startup(module, &sapi_phpdbg_module_entry, 1) == FAILURE) {
if (php_module_startup(module, &sapi_phpdbg_module_entry) == FAILURE) {
return FAILURE;
}

Expand Down