Skip to content

Commit d9667d1

Browse files
committed
main/streams: Add Fast ZPP specifier to retrieve stream context
1 parent a73dddc commit d9667d1

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

main/streams/php_stream_context.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,44 @@ END_EXTERN_C()
8585
#define PHP_STREAM_NOTIFY_SEVERITY_ERR 2
8686

8787
BEGIN_EXTERN_C()
88+
static zend_always_inline bool php_stream_zend_parse_arg_into_stream_context(
89+
zval *arg,
90+
php_stream_context **destination_context_ptr,
91+
bool check_null,
92+
php_stream_context *default_context
93+
) {
94+
if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) {
95+
*destination_context_ptr = (php_stream_context*)zend_fetch_resource_ex(arg, "Stream-Context", php_le_stream_context());
96+
if (UNEXPECTED(*destination_context_ptr == NULL)) {
97+
return false;
98+
}
99+
} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
100+
if (default_context) {
101+
*destination_context_ptr = default_context;
102+
} else {
103+
*destination_context_ptr = NULL;
104+
}
105+
} else {
106+
return false;
107+
}
108+
return true;
109+
}
110+
111+
#define PHP_Z_PARAM_STREAM_CONTEXT_EX(destination_context_ptr, check_null, null_as_default_context) \
112+
Z_PARAM_PROLOGUE(0, 0); \
113+
php_stream_context *php_param_default_context = php_stream_context_get_default(null_as_default_context); \
114+
if (UNEXPECTED(!php_stream_zend_parse_arg_into_stream_context(_arg, &destination_context_ptr, check_null, php_param_default_context))) { \
115+
_error_code = ZPP_ERROR_FAILURE; \
116+
if (!EG(exception)) { \
117+
_expected_type = check_null ? Z_EXPECTED_RESOURCE_OR_NULL : Z_EXPECTED_RESOURCE; \
118+
_error_code = ZPP_ERROR_WRONG_ARG; \
119+
} \
120+
break; \
121+
}
122+
#define PHP_Z_PARAM_STREAM_CONTEXT(dest) PHP_Z_PARAM_STREAM_CONTEXT_EX(dest, false, false)
123+
#define PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL(dest) PHP_Z_PARAM_STREAM_CONTEXT_EX(dest, true, false)
124+
#define PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT(dest) PHP_Z_PARAM_STREAM_CONTEXT_EX(dest, true, true)
125+
88126
PHPAPI void php_stream_notification_notify(php_stream_context *context, int notifycode, int severity,
89127
char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr);
90128
PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context);

0 commit comments

Comments
 (0)