[php-src] master: stream: refactor php_stream_from_persistent_id() to return enum
| From: | Gina Peter Banyard | Date: | Sun, 22 Nov 2026 19:54:56 +0000 |
| Subject: | [php-src] master: stream: refactor php_stream_from_persistent_id() to return enum | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-144043@lists.php.net to get a copy of this message | ||
Author: Gina Peter Banyard (Girgias)
Date: 2026-11-22T19:54:50Z
Commit: https://github.com/php/php-src/commit/62da58acbde764c2b3d239f0a7d976c676f23b81
Raw diff: https://github.com/php/php-src/commit/62da58acbde764c2b3d239f0a7d976c676f23b81.diff
stream: refactor php_stream_from_persistent_id() to return enum
Changed paths:
M main/php_streams.h
M main/streams/plain_wrapper.c
M main/streams/streams.c
M main/streams/transports.c
Diff:
diff --git a/main/php_streams.h b/main/php_streams.h
index 37e1f3e01b01..54baead30fe3 100644
--- a/main/php_streams.h
+++ b/main/php_streams.h
@@ -341,10 +341,14 @@ static zend_always_inline bool php_stream_zend_parse_arg_into_stream(
PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclosed);
PHPAPI int php_stream_free_enclosed(php_stream *stream_enclosed, int close_options);
-PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream);
-#define PHP_STREAM_PERSISTENT_SUCCESS 0 /* id exists */
-#define PHP_STREAM_PERSISTENT_FAILURE 1 /* id exists but is not a stream! */
-#define PHP_STREAM_PERSISTENT_NOT_EXIST 2 /* id does not exist */
+
+C23_ENUM(php_stream_persistent_status, uint8_t) {
+ PHP_STREAM_PERSISTENT_SUCCESS = 0, /* id exists */
+ PHP_STREAM_PERSISTENT_FAILURE = 1, /* id exists but is not a stream! */
+ PHP_STREAM_PERSISTENT_NOT_EXIST = 2, /* id does not exist */
+};
+
+PHPAPI php_stream_persistent_status php_stream_from_persistent_id(const char *persistent_id,
php_stream **stream);
#define PHP_STREAM_FREE_CALL_DTOR 1 /* call ops->close */
#define PHP_STREAM_FREE_RELEASE_STREAM 2 /* pefree(stream) */
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index ccf38ca0d543..376936607919 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -1220,6 +1220,9 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode,
zen
case PHP_STREAM_PERSISTENT_FAILURE:
efree(persistent_id);
return ret;
+ case PHP_STREAM_PERSISTENT_NOT_EXIST:
+ /* Fallthrough to open new stream */
+ break;
}
}
#ifdef PHP_WIN32
diff --git a/main/streams/streams.c b/main/streams/streams.c
index d332cc7f9a3c..3e948add11fd 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -105,7 +105,7 @@ PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclos
return orig;
}
-PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream)
+PHPAPI php_stream_persistent_status php_stream_from_persistent_id(const char *persistent_id,
php_stream **stream)
{
zend_resource *le;
diff --git a/main/streams/transports.c b/main/streams/transports.c
index a1410aa4a0e4..f8f74c606144 100644
--- a/main/streams/transports.c
+++ b/main/streams/transports.c
@@ -84,7 +84,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
/* fall through */
case PHP_STREAM_PERSISTENT_FAILURE:
- default:
+ case PHP_STREAM_PERSISTENT_NOT_EXIST:
/* failed; get a new one */
;
}