Skip to content

Commit 2bddba4

Browse files
authored
streams: use C enums instead of define for error_{store_}mode (#22901)
Also make private as these are not used outside of the file.
1 parent c852fce commit 2bddba4

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

main/streams/php_stream_errors.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@
2121

2222
BEGIN_EXTERN_C()
2323

24-
/* Error mode context options (internal C constants) */
25-
#define PHP_STREAM_ERROR_MODE_ERROR 0
26-
#define PHP_STREAM_ERROR_MODE_EXCEPTION 1
27-
#define PHP_STREAM_ERROR_MODE_SILENT 2
28-
29-
/* Error store context options (internal C constants) */
30-
#define PHP_STREAM_ERROR_STORE_AUTO 0
31-
#define PHP_STREAM_ERROR_STORE_NONE 1
32-
#define PHP_STREAM_ERROR_STORE_NON_TERM 2
33-
#define PHP_STREAM_ERROR_STORE_TERMINAL 3
34-
#define PHP_STREAM_ERROR_STORE_ALL 4
35-
3624
/* Maximum operation nesting depth */
3725
#define PHP_STREAM_ERROR_MAX_DEPTH 1000
3826
/* Operations pool size to prevent extra allocations */

main/streams/stream_errors.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,23 @@ static void php_stream_error_create_array(zval *zv, php_stream_error_entry *firs
8383
}
8484

8585
/* Context option helpers */
86-
87-
static int php_stream_auto_decide_error_store_mode(int error_mode)
86+
/* Error mode context options (internal C constants) */
87+
C23_ENUM(php_stream_error_mode, uint8_t) {
88+
PHP_STREAM_ERROR_MODE_ERROR = 0,
89+
PHP_STREAM_ERROR_MODE_EXCEPTION = 1,
90+
PHP_STREAM_ERROR_MODE_SILENT = 2
91+
};
92+
93+
/* Error store context options (internal C constants) */
94+
C23_ENUM(php_stream_error_store, uint8_t) {
95+
PHP_STREAM_ERROR_STORE_AUTO = 0,
96+
PHP_STREAM_ERROR_STORE_NONE = 1,
97+
PHP_STREAM_ERROR_STORE_NON_TERM = 2,
98+
PHP_STREAM_ERROR_STORE_TERMINAL = 3,
99+
PHP_STREAM_ERROR_STORE_ALL = 4
100+
};
101+
102+
static php_stream_error_store php_stream_auto_decide_error_store_mode(php_stream_error_mode error_mode)
88103
{
89104
switch (error_mode) {
90105
case PHP_STREAM_ERROR_MODE_ERROR:
@@ -98,7 +113,7 @@ static int php_stream_auto_decide_error_store_mode(int error_mode)
98113
}
99114
}
100115

101-
static int php_stream_get_error_mode(php_stream_context *context)
116+
static php_stream_error_mode php_stream_get_error_mode(php_stream_context *context)
102117
{
103118
if (!context) {
104119
return PHP_STREAM_ERROR_MODE_ERROR;
@@ -127,7 +142,8 @@ static int php_stream_get_error_mode(php_stream_context *context)
127142
return PHP_STREAM_ERROR_MODE_ERROR;
128143
}
129144

130-
static int php_stream_get_error_store_mode(php_stream_context *context, int error_mode)
145+
static php_stream_error_store php_stream_get_error_store_mode(
146+
php_stream_context *context, php_stream_error_mode error_mode)
131147
{
132148
if (!context) {
133149
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
386402
}
387403

388404
static void php_stream_report_errors(php_stream_context *context, php_stream_error_operation *op,
389-
int error_mode, bool is_terminating)
405+
php_stream_error_mode error_mode, bool is_terminating)
390406
{
391407
switch (error_mode) {
392408
case PHP_STREAM_ERROR_MODE_ERROR: {
@@ -439,8 +455,8 @@ PHPAPI void php_stream_error_operation_end(php_stream_context *context)
439455
context = FG(default_context);
440456
}
441457

442-
int error_mode = php_stream_get_error_mode(context);
443-
int store_mode = php_stream_get_error_store_mode(context, error_mode);
458+
php_stream_error_mode error_mode = php_stream_get_error_mode(context);
459+
php_stream_error_store store_mode = php_stream_get_error_store_mode(context, error_mode);
444460

445461
bool is_terminating = php_stream_has_terminating_error(op);
446462

0 commit comments

Comments
 (0)