@@ -203,10 +203,16 @@ static zend_object *spl_filesystem_object_new(zend_class_entry *class_type)
203
203
}
204
204
/* }}} */
205
205
206
+ static inline bool spl_intern_is_glob (const spl_filesystem_object * intern )
207
+ {
208
+ /* NULL check on `dirp` is necessary as destructors may interfere. */
209
+ return intern -> u .dir .dirp && php_stream_is (intern -> u .dir .dirp , & php_glob_stream_ops );
210
+ }
211
+
206
212
PHPAPI zend_string * spl_filesystem_object_get_path (const spl_filesystem_object * intern ) /* {{{ */
207
213
{
208
214
#ifdef HAVE_GLOB
209
- if (intern -> type == SPL_FS_DIR && php_stream_is (intern -> u . dir . dirp , & php_glob_stream_ops )) {
215
+ if (intern -> type == SPL_FS_DIR && spl_intern_is_glob (intern )) {
210
216
size_t len = 0 ;
211
217
char * tmp = php_glob_stream_get_path (intern -> u .dir .dirp , & len );
212
218
if (len == 0 ) {
@@ -636,7 +642,7 @@ static inline HashTable *spl_filesystem_object_get_debug_info(zend_object *objec
636
642
}
637
643
if (intern -> type == SPL_FS_DIR ) {
638
644
#ifdef HAVE_GLOB
639
- if (intern -> u . dir . dirp && php_stream_is (intern -> u . dir . dirp , & php_glob_stream_ops )) {
645
+ if (spl_intern_is_glob (intern )) {
640
646
ZVAL_STR_COPY (& tmp , intern -> path );
641
647
} else {
642
648
ZVAL_FALSE (& tmp );
@@ -1590,11 +1596,11 @@ PHP_METHOD(GlobIterator, count)
1590
1596
RETURN_THROWS ();
1591
1597
}
1592
1598
1593
- if (intern -> u . dir . dirp && php_stream_is (intern -> u . dir . dirp , & php_glob_stream_ops )) {
1599
+ if (spl_intern_is_glob (intern )) {
1594
1600
RETURN_LONG (php_glob_stream_get_count (intern -> u .dir .dirp , NULL ));
1595
1601
} else {
1596
- /* should not happen */
1597
- // TODO ZEND_ASSERT ?
1602
+ /* This can happen by abusing destructors. */
1603
+ /* TODO: relax this from E_ERROR to an exception */
1598
1604
php_error_docref (NULL , E_ERROR , "GlobIterator lost glob state" );
1599
1605
}
1600
1606
}
0 commit comments