Skip to content

Commit 11876f9

Browse files
committed
main: Add a custom Fast ZPP specifier for php_streams
1 parent fca1379 commit 11876f9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

main/php_streams.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,35 @@ END_EXTERN_C()
286286
#define php_stream_from_zval_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource2_ex((pzval), "stream", php_file_le_stream(), php_file_le_pstream())
287287

288288
BEGIN_EXTERN_C()
289+
290+
static zend_always_inline bool php_stream_zend_parse_arg_into_stream(zval *arg, php_stream **destination_stream_ptr, bool check_null)
291+
{
292+
if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) {
293+
*destination_stream_ptr = (php_stream*)zend_fetch_resource2(Z_RES_P(arg), "stream", php_file_le_stream(), php_file_le_pstream());
294+
if (UNEXPECTED(*destination_stream_ptr == NULL)) {
295+
return false;
296+
}
297+
} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
298+
*destination_stream_ptr = NULL;
299+
} else {
300+
return false;
301+
}
302+
return true;
303+
}
304+
305+
#define PHP_Z_PARAM_STREAM_EX(destination_stream_ptr, check_null) \
306+
Z_PARAM_PROLOGUE(0, 0); \
307+
if (UNEXPECTED(!php_stream_zend_parse_arg_into_stream(_arg, &destination_stream_ptr, check_null))) { \
308+
_error_code = ZPP_ERROR_FAILURE; \
309+
if (!EG(exception)) { \
310+
_expected_type = check_null ? Z_EXPECTED_RESOURCE_OR_NULL : Z_EXPECTED_RESOURCE; \
311+
_error_code = ZPP_ERROR_WRONG_ARG; \
312+
} \
313+
break; \
314+
}
315+
#define PHP_Z_PARAM_STREAM(dest) PHP_Z_PARAM_STREAM_EX(dest, false)
316+
#define PHP_Z_PARAM_STREAM_OR_NULL(dest) PHP_Z_PARAM_STREAM_EX(dest, true)
317+
289318
PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclosed);
290319
#define php_stream_free_enclosed(stream_enclosed, close_options) _php_stream_free_enclosed((stream_enclosed), (close_options))
291320
PHPAPI int _php_stream_free_enclosed(php_stream *stream_enclosed, int close_options);

0 commit comments

Comments
 (0)