@@ -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 */
210203PHP_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 */
250243PHP_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 */
281274PHP_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 }
0 commit comments