Skip to content

Commit 55ffc3d

Browse files
committed
ext/phar: Use new php_streams_context fast ZPP specifier
1 parent 79abfff commit 55ffc3d

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

ext/phar/func_interceptors.c

+27-27
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PHP_FUNCTION(phar_opendir) /* {{{ */
2424
{
2525
char *filename;
2626
size_t filename_len;
27-
zval *zcontext = NULL;
27+
php_stream_context *context = NULL;
2828

2929
if (!PHAR_G(intercepted)) {
3030
goto skip_phar;
@@ -35,9 +35,11 @@ PHP_FUNCTION(phar_opendir) /* {{{ */
3535
goto skip_phar;
3636
}
3737

38-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|r!", &filename, &filename_len, &zcontext) == FAILURE) {
39-
RETURN_THROWS();
40-
}
38+
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 2)
39+
Z_PARAM_PATH(filename, filename_len)
40+
Z_PARAM_OPTIONAL
41+
PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT(context)
42+
ZEND_PARSE_PARAMETERS_END_EX(goto skip_phar;);
4143

4244
if (!IS_ABSOLUTE_PATH(filename, filename_len) && !strstr(filename, "://")) {
4345
char *arch, *entry;
@@ -51,7 +53,6 @@ PHP_FUNCTION(phar_opendir) /* {{{ */
5153
}
5254

5355
if (SUCCESS == phar_split_fname(ZSTR_VAL(fname), ZSTR_LEN(fname), &arch, &arch_len, &entry, &entry_len, 2, 0)) {
54-
php_stream_context *context = NULL;
5556
php_stream *stream;
5657
char *name;
5758

@@ -69,9 +70,7 @@ PHP_FUNCTION(phar_opendir) /* {{{ */
6970
}
7071
efree(entry);
7172
efree(arch);
72-
if (zcontext) {
73-
context = php_stream_context_from_zval(zcontext, 0);
74-
}
73+
7574
stream = php_stream_opendir(name, REPORT_ERRORS, context);
7675
efree(name);
7776
if (!stream) {
@@ -163,7 +162,7 @@ PHP_FUNCTION(phar_file_get_contents) /* {{{ */
163162
zend_long offset = -1;
164163
zend_long maxlen;
165164
bool maxlen_is_null = 1;
166-
zval *zcontext = NULL;
165+
php_stream_context *context = NULL;
167166

168167
if (!PHAR_G(intercepted)) {
169168
goto skip_phar;
@@ -175,9 +174,14 @@ PHP_FUNCTION(phar_file_get_contents) /* {{{ */
175174
}
176175

177176
/* Parse arguments */
178-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "P|br!ll!", &filename, &use_include_path, &zcontext, &offset, &maxlen, &maxlen_is_null) == FAILURE) {
179-
goto skip_phar;
180-
}
177+
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 5)
178+
Z_PARAM_PATH_STR(filename)
179+
Z_PARAM_OPTIONAL
180+
Z_PARAM_BOOL(use_include_path)
181+
PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT(context)
182+
Z_PARAM_LONG(offset)
183+
Z_PARAM_LONG_OR_NULL(maxlen, maxlen_is_null)
184+
ZEND_PARSE_PARAMETERS_END_EX(goto skip_phar;);
181185

182186
if (maxlen_is_null) {
183187
maxlen = (ssize_t) PHP_STREAM_COPY_ALL;
@@ -192,13 +196,7 @@ PHP_FUNCTION(phar_file_get_contents) /* {{{ */
192196
goto skip_phar;
193197
}
194198

195-
php_stream_context *context = NULL;
196-
php_stream *stream;
197-
198-
if (zcontext) {
199-
context = php_stream_context_from_zval(zcontext, 0);
200-
}
201-
stream = php_stream_open_wrapper_ex(ZSTR_VAL(name), "rb", 0 | REPORT_ERRORS, NULL, context);
199+
php_stream *stream = php_stream_open_wrapper_ex(ZSTR_VAL(name), "rb", 0 | REPORT_ERRORS, NULL, context);
202200

203201
zend_string_release_ex(name, false);
204202

@@ -236,7 +234,7 @@ PHP_FUNCTION(phar_readfile) /* {{{ */
236234
{
237235
zend_string *filename;
238236
bool use_include_path = 0;
239-
zval *zcontext = NULL;
237+
php_stream_context *context = NULL;
240238

241239
if (!PHAR_G(intercepted)) {
242240
goto skip_phar;
@@ -246,19 +244,21 @@ PHP_FUNCTION(phar_readfile) /* {{{ */
246244
&& !HT_IS_INITIALIZED(&cached_phars)) {
247245
goto skip_phar;
248246
}
249-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "P|br!", &filename, &use_include_path, &zcontext) == FAILURE) {
250-
goto skip_phar;
251-
}
247+
248+
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_QUIET, 1, 3)
249+
Z_PARAM_PATH_STR(filename)
250+
Z_PARAM_OPTIONAL
251+
Z_PARAM_BOOL(use_include_path)
252+
PHP_Z_PARAM_STREAM_CONTEXT_OR_NULL_AS_DEFAULT_CONTEXT(context)
253+
ZEND_PARSE_PARAMETERS_END_EX(goto skip_phar;);
254+
252255
if (use_include_path || (!IS_ABSOLUTE_PATH(ZSTR_VAL(filename), ZSTR_LEN(filename)) && !strstr(ZSTR_VAL(filename), "://"))) {
253256
zend_string *name = phar_get_name_for_relative_paths(filename, use_include_path);
254257
if (!name) {
255258
goto skip_phar;
256259
}
257260

258-
php_stream *stream;
259-
php_stream_context *context = php_stream_context_from_zval(zcontext, 0);
260-
261-
stream = php_stream_open_wrapper_ex(ZSTR_VAL(name), "rb", 0 | REPORT_ERRORS, NULL, context);
261+
php_stream *stream = php_stream_open_wrapper_ex(ZSTR_VAL(name), "rb", 0 | REPORT_ERRORS, NULL, context);
262262

263263
zend_string_release_ex(name, false);
264264
if (stream == NULL) {

0 commit comments

Comments
 (0)