Skip to content

Commit 68665d3

Browse files
committed
ext/standard/dir.c: Use new PHP_Z_PARAM_STREAM_OR_NULL() ZPP specifier
1 parent 4101a8c commit 68665d3

5 files changed

+18
-25
lines changed

Diff for: ext/standard/dir.c

+14-21
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,18 @@ PHP_FUNCTION(dir)
157157
/* }}} */
158158

159159

160-
static php_stream* php_dir_get_directory_stream_from_user_arg(zval *arg)
160+
static php_stream* php_dir_get_directory_stream_from_user_arg(php_stream *dir_stream)
161161
{
162-
zend_resource *res;
163-
if (arg == NULL) {
162+
if (dir_stream == NULL) {
164163
if (UNEXPECTED(DIRG(default_dir) == NULL)) {
165164
zend_type_error("No resource supplied");
166165
return NULL;
167166
}
168-
res = DIRG(default_dir);
169-
} else {
170-
ZEND_ASSERT(Z_TYPE_P(arg) == IS_RESOURCE);
171-
res = Z_RES_P(arg);
167+
zend_resource *res = DIRG(default_dir);
168+
ZEND_ASSERT(res->type == php_file_le_stream());
169+
dir_stream = (php_stream*) res->ptr;
172170
}
173171

174-
if (UNEXPECTED(res->type != php_file_le_stream())) {
175-
zend_argument_type_error(1, "must be a valid Directory resource");
176-
return NULL;
177-
}
178-
php_stream *dir_stream = (php_stream*) res->ptr;
179172
if (UNEXPECTED((dir_stream->flags & PHP_STREAM_FLAG_IS_DIR)) == 0) {
180173
zend_argument_type_error(1, "must be a valid Directory resource");
181174
return NULL;
@@ -209,14 +202,14 @@ static php_stream* php_dir_get_directory_stream_from_this(zval *this_z)
209202
/* {{{ Close directory connection identified by the dir_handle */
210203
PHP_FUNCTION(closedir)
211204
{
212-
zval *id = NULL;
205+
php_stream *dirp = NULL;
213206

214207
ZEND_PARSE_PARAMETERS_START(0, 1)
215208
Z_PARAM_OPTIONAL
216-
Z_PARAM_RESOURCE_OR_NULL(id)
209+
PHP_Z_PARAM_STREAM_OR_NULL(dirp)
217210
ZEND_PARSE_PARAMETERS_END();
218211

219-
php_stream *dirp = php_dir_get_directory_stream_from_user_arg(id);
212+
dirp = php_dir_get_directory_stream_from_user_arg(dirp);
220213
if (UNEXPECTED(dirp == NULL)) {
221214
RETURN_THROWS();
222215
}
@@ -249,14 +242,14 @@ PHP_METHOD(Directory, close)
249242
/* {{{ Rewind dir_handle back to the start */
250243
PHP_FUNCTION(rewinddir)
251244
{
252-
zval *id = NULL;
245+
php_stream *dirp = NULL;
253246

254247
ZEND_PARSE_PARAMETERS_START(0, 1)
255248
Z_PARAM_OPTIONAL
256-
Z_PARAM_RESOURCE_OR_NULL(id)
249+
PHP_Z_PARAM_STREAM_OR_NULL(dirp)
257250
ZEND_PARSE_PARAMETERS_END();
258251

259-
php_stream *dirp = php_dir_get_directory_stream_from_user_arg(id);
252+
dirp = php_dir_get_directory_stream_from_user_arg(dirp);
260253
if (UNEXPECTED(dirp == NULL)) {
261254
RETURN_THROWS();
262255
}
@@ -280,14 +273,14 @@ PHP_METHOD(Directory, rewind)
280273
/* {{{ Read directory entry from dir_handle */
281274
PHP_FUNCTION(readdir)
282275
{
283-
zval *id = NULL;
276+
php_stream *dirp = NULL;
284277

285278
ZEND_PARSE_PARAMETERS_START(0, 1)
286279
Z_PARAM_OPTIONAL
287-
Z_PARAM_RESOURCE_OR_NULL(id)
280+
PHP_Z_PARAM_STREAM_OR_NULL(dirp)
288281
ZEND_PARSE_PARAMETERS_END();
289282

290-
php_stream *dirp = php_dir_get_directory_stream_from_user_arg(id);
283+
dirp = php_dir_get_directory_stream_from_user_arg(dirp);
291284
if (UNEXPECTED(dirp == NULL)) {
292285
RETURN_THROWS();
293286
}

Diff for: ext/standard/tests/dir/closedir_variation2-win32-mb.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ NULL
4747
Directory Handle: resource(%d) of type (Unknown)
4848

4949
-- Close directory handle second time: --
50-
closedir(): Argument #1 ($dir_handle) must be a valid Directory resource
50+
closedir(): Argument #1 ($dir_handle) must be an open stream resource
5151
Directory Handle: resource(%d) of type (Unknown)

Diff for: ext/standard/tests/dir/closedir_variation2.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ NULL
4141
Directory Handle: resource(%d) of type (Unknown)
4242

4343
-- Close directory handle second time: --
44-
closedir(): Argument #1 ($dir_handle) must be a valid Directory resource
44+
closedir(): Argument #1 ($dir_handle) must be an open stream resource
4545
Directory Handle: resource(%d) of type (Unknown)

Diff for: ext/standard/tests/dir/rewinddir_variation2-win32-mb.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ resource(%d) of type (stream)
4242
string(%d) "%s"
4343

4444
-- Call to rewinddir() --
45-
rewinddir(): Argument #1 ($dir_handle) must be a valid Directory resource
45+
rewinddir(): Argument #1 ($dir_handle) must be an open stream resource

Diff for: ext/standard/tests/dir/rewinddir_variation2.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ resource(%d) of type (stream)
3636
string(%d) "%s"
3737

3838
-- Call to rewinddir() --
39-
rewinddir(): Argument #1 ($dir_handle) must be a valid Directory resource
39+
rewinddir(): Argument #1 ($dir_handle) must be an open stream resource

0 commit comments

Comments
 (0)