From 18cc854f300e125b0c2e8f1575ac18cc006d1dd2 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Tue, 28 Jul 2026 08:48:51 +0100 Subject: [PATCH 1/5] streams: use zend string property update function (#22903) Instead of the char* version --- main/streams/stream_errors.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/streams/stream_errors.c b/main/streams/stream_errors.c index 067a604af787..40056f0856e7 100644 --- a/main/streams/stream_errors.c +++ b/main/streams/stream_errors.c @@ -385,8 +385,8 @@ static void php_stream_throw_exception_with_errors(php_stream_error_operation *o object_init_ex(&ex, php_ce_stream_exception); /* Set message from first error */ - zend_update_property_string(php_ce_stream_exception, Z_OBJ(ex), ZEND_STRL("message"), - ZSTR_VAL(op->first_error->message)); + zend_update_property_str(php_ce_stream_exception, Z_OBJ(ex), ZEND_STRL("message"), + op->first_error->message); /* Set code from first error */ zend_update_property_long(php_ce_stream_exception, Z_OBJ(ex), ZEND_STRL("code"), From ec29a6bd768fc43a60d9f15a145140df059602c8 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 27 Jul 2026 19:42:14 +0100 Subject: [PATCH 2/5] sapi: use bool type for post_read global --- main/SAPI.c | 4 ++-- main/SAPI.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main/SAPI.c b/main/SAPI.c index 523759ea79be..0ed241569db3 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -217,7 +217,7 @@ SAPI_API size_t sapi_read_post_block(char *buffer, size_t buflen) } if (read_bytes < buflen) { /* done */ - SG(post_read) = 1; + SG(post_read) = true; } return read_bytes; @@ -418,7 +418,7 @@ SAPI_API void sapi_activate(void) SG(request_info).post_entry = NULL; SG(request_info).proto_num = 1000; /* Default to HTTP 1.0 */ SG(global_request_time) = 0; - SG(post_read) = 0; + SG(post_read) = false; SG(send_header_fcc) = empty_fcall_info_cache; /* It's possible to override this general case in the activate() callback, if necessary. */ if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) { diff --git a/main/SAPI.h b/main/SAPI.h index d34c12f1bbc8..1e9a81866382 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -132,7 +132,7 @@ typedef struct _sapi_globals_struct { sapi_request_info request_info; sapi_headers_struct sapi_headers; int64_t read_post_bytes; - unsigned char post_read; + bool post_read; unsigned char headers_sent; zend_stat_t global_stat; char *default_mimetype; From c30acf5b78b206e3d594e195949c02ff5b42f8c1 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 27 Jul 2026 19:45:05 +0100 Subject: [PATCH 3/5] sapi: use bool type for headers_sent global --- main/SAPI.c | 8 ++++---- main/SAPI.h | 2 +- sapi/cgi/cgi_main.c | 12 ++++++------ sapi/cli/php_cli_server.c | 2 +- sapi/fpm/fpm/fpm_main.c | 10 +++++----- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/main/SAPI.c b/main/SAPI.c index 0ed241569db3..291b0de75cde 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -409,7 +409,7 @@ SAPI_API void sapi_activate(void) */ SG(sapi_headers).http_status_line = NULL; SG(sapi_headers).mimetype = NULL; - SG(headers_sent) = 0; + SG(headers_sent) = false; SG(read_post_bytes) = 0; SG(request_info).request_body = NULL; SG(request_info).current_user = NULL; @@ -517,7 +517,7 @@ SAPI_API void sapi_deactivate_destroy(void) } sapi_send_headers_free(); SG(sapi_started) = 0; - SG(headers_sent) = 0; + SG(headers_sent) = false; SG(request_info).headers_read = 0; SG(global_request_time) = 0; } @@ -871,7 +871,7 @@ SAPI_API int sapi_send_headers(void) zend_fcc_dtor(&fcc); } - SG(headers_sent) = 1; + SG(headers_sent) = true; if (sapi_module.send_headers) { retval = sapi_module.send_headers(&SG(sapi_headers)); @@ -908,7 +908,7 @@ SAPI_API int sapi_send_headers(void) ret = SUCCESS; break; case SAPI_HEADER_SEND_FAILED: - SG(headers_sent) = 0; + SG(headers_sent) = false; ret = FAILURE; break; } diff --git a/main/SAPI.h b/main/SAPI.h index 1e9a81866382..096774e08f4c 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -133,7 +133,7 @@ typedef struct _sapi_globals_struct { sapi_headers_struct sapi_headers; int64_t read_post_bytes; bool post_read; - unsigned char headers_sent; + bool headers_sent; zend_stat_t global_stat; char *default_mimetype; char *default_charset; diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 7efd8f159d59..841f45b207a8 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -2263,7 +2263,7 @@ consult the installation file that came with this distribution, or visit \n\ } fcgi_shutdown(); no_headers = 1; - SG(headers_sent) = 1; + SG(headers_sent) = true; php_cgi_usage(argv[0]); php_output_end_all(); exit_status = 0; @@ -2325,7 +2325,7 @@ consult the installation file that came with this distribution, or visit \n\ return FAILURE; } if (no_headers) { - SG(headers_sent) = 1; + SG(headers_sent) = true; SG(request_info).no_headers = 1; } php_print_info(0xFFFFFFFF); @@ -2343,7 +2343,7 @@ consult the installation file that came with this distribution, or visit \n\ if (script_file) { efree(script_file); } - SG(headers_sent) = 1; + SG(headers_sent) = true; php_printf("[PHP Modules]\n"); print_modules(); php_printf("\n[Zend Modules]\n"); @@ -2369,7 +2369,7 @@ consult the installation file that came with this distribution, or visit \n\ free(bindpath); return FAILURE; } - SG(headers_sent) = 1; + SG(headers_sent) = true; SG(request_info).no_headers = 1; php_print_version(&cgi_sapi_module); php_request_shutdown((void *) 0); @@ -2406,7 +2406,7 @@ consult the installation file that came with this distribution, or visit \n\ } if (no_headers) { - SG(headers_sent) = 1; + SG(headers_sent) = true; SG(request_info).no_headers = 1; } @@ -2466,7 +2466,7 @@ consult the installation file that came with this distribution, or visit \n\ return FAILURE; } if (no_headers) { - SG(headers_sent) = 1; + SG(headers_sent) = true; SG(request_info).no_headers = 1; } diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 797979b67305..e06f30b9e2d2 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -526,7 +526,7 @@ static void sapi_cli_server_flush(void *server_context) /* {{{ */ if (!SG(headers_sent)) { sapi_send_headers(); - SG(headers_sent) = 1; + SG(headers_sent) = true; } } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index 827225387487..9b7cbcf16f06 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1636,7 +1636,7 @@ int main(int argc, char *argv[]) case 'm': /* list compiled in modules */ cgi_sapi_module.startup(&cgi_sapi_module); php_output_activate(); - SG(headers_sent) = 1; + SG(headers_sent) = true; php_printf("[PHP Modules]\n"); print_modules(); php_printf("\n[Zend Modules]\n"); @@ -1674,7 +1674,7 @@ int main(int argc, char *argv[]) case PHP_GETOPT_INVALID_ARG: cgi_sapi_module.startup(&cgi_sapi_module); php_output_activate(); - SG(headers_sent) = 1; + SG(headers_sent) = true; php_cgi_usage(argv[0]); php_output_end_all(); php_output_deactivate(); @@ -1689,7 +1689,7 @@ int main(int argc, char *argv[]) php_module_shutdown(); return FPM_EXIT_SOFTWARE; } - SG(headers_sent) = 1; + SG(headers_sent) = true; SG(request_info).no_headers = 1; php_print_version(&sapi_module); @@ -1710,7 +1710,7 @@ int main(int argc, char *argv[]) php_module_shutdown(); return FPM_EXIT_SOFTWARE; } - SG(headers_sent) = 1; + SG(headers_sent) = true; SG(request_info).no_headers = 1; php_print_info(0xFFFFFFFF); php_request_shutdown((void *) 0); @@ -1723,7 +1723,7 @@ int main(int argc, char *argv[]) if (argc != php_optind) { cgi_sapi_module.startup(&cgi_sapi_module); php_output_activate(); - SG(headers_sent) = 1; + SG(headers_sent) = true; php_cgi_usage(argv[0]); php_output_end_all(); php_output_deactivate(); From 25159e0619cc6db79e6ffab3830c0d03cb777f36 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 27 Jul 2026 19:46:49 +0100 Subject: [PATCH 4/5] sapi: pack globals struct Size goes from 632 to 624 bytes --- main/SAPI.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/SAPI.h b/main/SAPI.h index 096774e08f4c..9536ced064db 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -134,13 +134,13 @@ typedef struct _sapi_globals_struct { int64_t read_post_bytes; bool post_read; bool headers_sent; + bool sapi_started; + int options; zend_stat_t global_stat; char *default_mimetype; char *default_charset; HashTable *rfc1867_uploaded_files; zend_long post_max_size; - int options; - bool sapi_started; double global_request_time; HashTable known_post_content_types; zend_fcall_info_cache send_header_fcc; From 395d0186c1efa0759e068fad1407f2353caa1af4 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 27 Jul 2026 20:08:48 +0100 Subject: [PATCH 5/5] sapi: use zend_result type for return types when possible --- main/SAPI.c | 21 ++++++++++----------- main/SAPI.h | 16 ++++++++-------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/main/SAPI.c b/main/SAPI.c index 291b0de75cde..31cf5da18a1d 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -646,7 +646,7 @@ static void sapi_header_add_op(sapi_header_op_enum op, sapi_header_struct *sapi_ } } -SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg) +SAPI_API zend_result sapi_header_op(sapi_header_op_enum op, void *arg) { sapi_header_struct sapi_header; char *colon_offset; @@ -830,10 +830,10 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg) } -SAPI_API int sapi_send_headers(void) +SAPI_API zend_result sapi_send_headers(void) { int retval; - int ret = FAILURE; + zend_result ret = FAILURE; if (SG(headers_sent) || SG(request_info).no_headers) { return SUCCESS; @@ -919,7 +919,7 @@ SAPI_API int sapi_send_headers(void) } -SAPI_API int sapi_register_post_entries(const sapi_post_entry *post_entries) +SAPI_API zend_result sapi_register_post_entries(const sapi_post_entry *post_entries) { const sapi_post_entry *p=post_entries; @@ -933,16 +933,15 @@ SAPI_API int sapi_register_post_entries(const sapi_post_entry *post_entries) } -SAPI_API int sapi_register_post_entry(const sapi_post_entry *post_entry) +SAPI_API zend_result sapi_register_post_entry(const sapi_post_entry *post_entry) { - int ret; zend_string *key; if (SG(sapi_started) && EG(current_execute_data)) { return FAILURE; } key = zend_string_init(post_entry->content_type, post_entry->content_type_len, 1); GC_MAKE_PERSISTENT_LOCAL(key); - ret = zend_hash_add_mem(&SG(known_post_content_types), key, + zend_result ret = zend_hash_add_mem(&SG(known_post_content_types), key, (void *) post_entry, sizeof(sapi_post_entry)) ? SUCCESS : FAILURE; zend_string_release_ex(key, 1); return ret; @@ -958,7 +957,7 @@ SAPI_API void sapi_unregister_post_entry(const sapi_post_entry *post_entry) } -SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(void)) +SAPI_API zend_result sapi_register_default_post_reader(void (*default_post_reader)(void)) { if (SG(sapi_started) && EG(current_execute_data)) { return FAILURE; @@ -968,7 +967,7 @@ SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(void) } -SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray)) +SAPI_API zend_result sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray)) { if (SG(sapi_started) && EG(current_execute_data)) { return FAILURE; @@ -977,7 +976,7 @@ SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zva return SUCCESS; } -SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len), unsigned int (*input_filter_init)(void)) +SAPI_API zend_result sapi_register_input_filter(unsigned int (*input_filter)(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len), unsigned int (*input_filter_init)(void)) { if (SG(sapi_started) && EG(current_execute_data)) { return FAILURE; @@ -987,7 +986,7 @@ SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, co return SUCCESS; } -SAPI_API int sapi_flush(void) +SAPI_API zend_result sapi_flush(void) { if (sapi_module.flush) { sapi_module.flush(SG(server_context)); diff --git a/main/SAPI.h b/main/SAPI.h index 9536ced064db..29532a019335 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -198,25 +198,25 @@ typedef enum { /* Parameter: */ } sapi_header_op_enum; BEGIN_EXTERN_C() -SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg); +SAPI_API zend_result sapi_header_op(sapi_header_op_enum op, void *arg); SAPI_API int sapi_add_header_ex(const char *header_line, size_t header_line_len, bool duplicate, bool replace); #define sapi_add_header(a, b, c) sapi_add_header_ex((a),(b),(c),1) -SAPI_API int sapi_send_headers(void); +SAPI_API zend_result sapi_send_headers(void); SAPI_API void sapi_free_header(sapi_header_struct *sapi_header); SAPI_API void sapi_handle_post(void *arg); SAPI_API void sapi_read_post_data(void); SAPI_API size_t sapi_read_post_block(char *buffer, size_t buflen); -SAPI_API int sapi_register_post_entries(const sapi_post_entry *post_entry); -SAPI_API int sapi_register_post_entry(const sapi_post_entry *post_entry); +SAPI_API zend_result sapi_register_post_entries(const sapi_post_entry *post_entry); +SAPI_API zend_result sapi_register_post_entry(const sapi_post_entry *post_entry); SAPI_API void sapi_unregister_post_entry(const sapi_post_entry *post_entry); -SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(void)); -SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray)); -SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len), unsigned int (*input_filter_init)(void)); +SAPI_API zend_result sapi_register_default_post_reader(void (*default_post_reader)(void)); +SAPI_API zend_result sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray)); +SAPI_API zend_result sapi_register_input_filter(unsigned int (*input_filter)(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len), unsigned int (*input_filter_init)(void)); -SAPI_API int sapi_flush(void); +SAPI_API zend_result sapi_flush(void); SAPI_API zend_stat_t *sapi_get_stat(void); SAPI_API char *sapi_getenv(const char *name, size_t name_len);