Skip to content

Commit 2d9231d

Browse files
committed
stream: refactor php_stream_from_persistent_id() to return enum
1 parent ad92eca commit 2d9231d

5 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎main/php_streams.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,14 @@ static zend_always_inline bool php_stream_zend_parse_arg_into_stream(
339339
PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclosed);
340340
PHPAPI int php_stream_free_enclosed(php_stream *stream_enclosed, int close_options);
341341

342-
PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream);
343-
#define PHP_STREAM_PERSISTENT_SUCCESS 0 /* id exists */
344-
#define PHP_STREAM_PERSISTENT_FAILURE 1 /* id exists but is not a stream! */
345-
#define PHP_STREAM_PERSISTENT_NOT_EXIST 2 /* id does not exist */
342+
343+
C23_ENUM(php_stream_persistent_status, uint8_t) {
344+
PHP_STREAM_PERSISTENT_SUCCESS = 0, /* id exists */
345+
PHP_STREAM_PERSISTENT_FAILURE = 1, /* id exists but is not a stream! */
346+
PHP_STREAM_PERSISTENT_NOT_EXIST = 2, /* id does not exist */
347+
};
348+
349+
PHPAPI php_stream_persistent_status php_stream_from_persistent_id(const char *persistent_id, php_stream **stream);
346350

347351
#define PHP_STREAM_FREE_CALL_DTOR 1 /* call ops->close */
348352
#define PHP_STREAM_FREE_RELEASE_STREAM 2 /* pefree(stream) */

‎main/streams/php_stream_plain_wrapper.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ PHPAPI FILE * _php_stream_open_wrapper_as_file(char * path, char * mode, int opt
4646
#define php_stream_open_wrapper_as_file(path, mode, options, opened_path) _php_stream_open_wrapper_as_file((path), (mode), (options), (opened_path) STREAMS_CC)
4747

4848
/* parse standard "fopen" modes into open() flags */
49-
PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags);
49+
PHPAPI zend_result php_stream_parse_fopen_modes(const char *mode, int *open_flags);
5050

5151
END_EXTERN_C()

‎main/streams/plain_wrapper.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,8 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen
12201220
case PHP_STREAM_PERSISTENT_FAILURE:
12211221
efree(persistent_id);
12221222
return ret;
1223+
case PHP_STREAM_PERSISTENT_NOT_EXIST:
1224+
ZEND_UNREACHABLE();
12231225
}
12241226
}
12251227
#ifdef PHP_WIN32

‎main/streams/streams.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclos
107107
return orig;
108108
}
109109

110-
PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream)
110+
PHPAPI php_stream_persistent_status php_stream_from_persistent_id(const char *persistent_id, php_stream **stream)
111111
{
112112
zend_resource *le;
113113

‎main/streams/transports.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
8585
/* fall through */
8686

8787
case PHP_STREAM_PERSISTENT_FAILURE:
88-
default:
88+
case PHP_STREAM_PERSISTENT_NOT_EXIST:
8989
/* failed; get a new one */
9090
;
9191
}

0 commit comments

Comments
 (0)