From 41049477d27e45c451807c3d68348920d5e3c3f9 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 27 Jul 2026 18:07:46 +0100 Subject: [PATCH 1/2] streams: use C enums instead of define for error_{store_}mode Also make private as these are not used outside of the file --- main/streams/php_stream_errors.h | 12 ------------ main/streams/stream_errors.c | 30 +++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/main/streams/php_stream_errors.h b/main/streams/php_stream_errors.h index 67112c8932b7..878350f972ac 100644 --- a/main/streams/php_stream_errors.h +++ b/main/streams/php_stream_errors.h @@ -21,18 +21,6 @@ BEGIN_EXTERN_C() -/* Error mode context options (internal C constants) */ -#define PHP_STREAM_ERROR_MODE_ERROR 0 -#define PHP_STREAM_ERROR_MODE_EXCEPTION 1 -#define PHP_STREAM_ERROR_MODE_SILENT 2 - -/* Error store context options (internal C constants) */ -#define PHP_STREAM_ERROR_STORE_AUTO 0 -#define PHP_STREAM_ERROR_STORE_NONE 1 -#define PHP_STREAM_ERROR_STORE_NON_TERM 2 -#define PHP_STREAM_ERROR_STORE_TERMINAL 3 -#define PHP_STREAM_ERROR_STORE_ALL 4 - /* Maximum operation nesting depth */ #define PHP_STREAM_ERROR_MAX_DEPTH 1000 /* Operations pool size to prevent extra allocations */ diff --git a/main/streams/stream_errors.c b/main/streams/stream_errors.c index 9ee6127df777..3d555f3912a2 100644 --- a/main/streams/stream_errors.c +++ b/main/streams/stream_errors.c @@ -83,8 +83,23 @@ static void php_stream_error_create_array(zval *zv, php_stream_error_entry *firs } /* Context option helpers */ - -static int php_stream_auto_decide_error_store_mode(int error_mode) +/* Error mode context options (internal C constants) */ +C23_ENUM(php_stream_error_mode, uint8_t) { + PHP_STREAM_ERROR_MODE_ERROR = 0, + PHP_STREAM_ERROR_MODE_EXCEPTION = 1, + PHP_STREAM_ERROR_MODE_SILENT = 2 +}; + +/* Error store context options (internal C constants) */ +C23_ENUM(php_stream_error_store_mode, uint8_t) { + PHP_STREAM_ERROR_STORE_AUTO = 0, + PHP_STREAM_ERROR_STORE_NONE = 1, + PHP_STREAM_ERROR_STORE_NON_TERM = 2, + PHP_STREAM_ERROR_STORE_TERMINAL = 3, + PHP_STREAM_ERROR_STORE_ALL = 4 +}; + +static php_stream_error_store_mode php_stream_auto_decide_error_store_mode(php_stream_error_mode error_mode) { switch (error_mode) { case PHP_STREAM_ERROR_MODE_ERROR: @@ -98,7 +113,7 @@ static int php_stream_auto_decide_error_store_mode(int error_mode) } } -static int php_stream_get_error_mode(php_stream_context *context) +static php_stream_error_mode php_stream_get_error_mode(php_stream_context *context) { if (!context) { return PHP_STREAM_ERROR_MODE_ERROR; @@ -127,7 +142,8 @@ static int php_stream_get_error_mode(php_stream_context *context) return PHP_STREAM_ERROR_MODE_ERROR; } -static int php_stream_get_error_store_mode(php_stream_context *context, int error_mode) +static php_stream_error_store_mode php_stream_get_error_store_mode( + php_stream_context *context, php_stream_error_mode error_mode) { if (!context) { return php_stream_auto_decide_error_store_mode(error_mode); @@ -386,7 +402,7 @@ static void php_stream_throw_exception_with_errors(php_stream_error_operation *o } static void php_stream_report_errors(php_stream_context *context, php_stream_error_operation *op, - int error_mode, bool is_terminating) + php_stream_error_mode error_mode, bool is_terminating) { switch (error_mode) { case PHP_STREAM_ERROR_MODE_ERROR: { @@ -439,8 +455,8 @@ PHPAPI void php_stream_error_operation_end(php_stream_context *context) context = FG(default_context); } - int error_mode = php_stream_get_error_mode(context); - int store_mode = php_stream_get_error_store_mode(context, error_mode); + php_stream_error_mode error_mode = php_stream_get_error_mode(context); + php_stream_error_store_mode store_mode = php_stream_get_error_store_mode(context, error_mode); bool is_terminating = php_stream_has_terminating_error(op); From 91e336a9dca5cf9c284d9e343259331366b31dc7 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 27 Jul 2026 19:24:46 +0100 Subject: [PATCH 2/2] Review comment --- main/streams/stream_errors.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main/streams/stream_errors.c b/main/streams/stream_errors.c index 3d555f3912a2..8db5e797f1c7 100644 --- a/main/streams/stream_errors.c +++ b/main/streams/stream_errors.c @@ -91,7 +91,7 @@ C23_ENUM(php_stream_error_mode, uint8_t) { }; /* Error store context options (internal C constants) */ -C23_ENUM(php_stream_error_store_mode, uint8_t) { +C23_ENUM(php_stream_error_store, uint8_t) { PHP_STREAM_ERROR_STORE_AUTO = 0, PHP_STREAM_ERROR_STORE_NONE = 1, PHP_STREAM_ERROR_STORE_NON_TERM = 2, @@ -99,7 +99,7 @@ C23_ENUM(php_stream_error_store_mode, uint8_t) { PHP_STREAM_ERROR_STORE_ALL = 4 }; -static php_stream_error_store_mode php_stream_auto_decide_error_store_mode(php_stream_error_mode error_mode) +static php_stream_error_store php_stream_auto_decide_error_store_mode(php_stream_error_mode error_mode) { switch (error_mode) { case PHP_STREAM_ERROR_MODE_ERROR: @@ -142,7 +142,7 @@ static php_stream_error_mode php_stream_get_error_mode(php_stream_context *conte return PHP_STREAM_ERROR_MODE_ERROR; } -static php_stream_error_store_mode php_stream_get_error_store_mode( +static php_stream_error_store php_stream_get_error_store_mode( php_stream_context *context, php_stream_error_mode error_mode) { if (!context) { @@ -456,7 +456,7 @@ PHPAPI void php_stream_error_operation_end(php_stream_context *context) } php_stream_error_mode error_mode = php_stream_get_error_mode(context); - php_stream_error_store_mode store_mode = php_stream_get_error_store_mode(context, error_mode); + php_stream_error_store store_mode = php_stream_get_error_store_mode(context, error_mode); bool is_terminating = php_stream_has_terminating_error(op);