aharvey Fri, 04 Feb 2011 10:49:49 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=308013
Log: Fix bug #53914 (SPL assumes HAVE_GLOB is defined). Original patch by Chris Jones; test updates by myself. Bug: http://bugs.php.net/53914 (Assigned) SPL assumes HAVE_GLOB is defined Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/spl/spl_directory.c U php/php-src/branches/PHP_5_3/ext/spl/tests/dit_001.phpt A php/php-src/branches/PHP_5_3/ext/spl/tests/dit_001_noglob.phpt U php/php-src/branches/PHP_5_3/ext/spl/tests/dit_002.phpt U php/php-src/trunk/ext/spl/spl_directory.c U php/php-src/trunk/ext/spl/tests/dit_001.phpt A php/php-src/trunk/ext/spl/tests/dit_001_noglob.phpt U php/php-src/trunk/ext/spl/tests/dit_002.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2011-02-04 10:49:33 UTC (rev 308012) +++ php/php-src/branches/PHP_5_3/NEWS 2011-02-04 10:49:49 UTC (rev 308013) @@ -130,6 +130,7 @@ (Mateusz Kocielski, Pierre) - SPL extension: + . Fixed bug #53914 (SPL assumes HAVE_GLOB is defined). (Chris Jones) . Fixed bug #53515 (property_exists incorrect on ArrayObject null and 0 values). (Felipe) Modified: php/php-src/branches/PHP_5_3/ext/spl/spl_directory.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/spl/spl_directory.c 2011-02-04 10:49:33 UTC (rev 308012) +++ php/php-src/branches/PHP_5_3/ext/spl/spl_directory.c 2011-02-04 10:49:49 UTC (rev 308013) @@ -164,11 +164,13 @@ PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, int *len TSRMLS_DC) /* {{{ */ { +#ifdef HAVE_GLOB if (intern->type == SPL_FS_DIR) { if (php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) { return php_glob_stream_get_path(intern->u.dir.dirp, 0, len); } } +#endif if (len) { *len = intern->_path_len; } @@ -575,6 +577,7 @@ efree(pnstr); } if (intern->type == SPL_FS_DIR) { +#ifdef HAVE_GLOB pnstr = spl_gen_private_prop_name(spl_ce_DirectoryIterator, "glob", sizeof("glob")-1, &pnlen TSRMLS_CC); if (php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) { add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->_path, intern->_path_len, 1); @@ -582,6 +585,7 @@ add_assoc_bool_ex(&zrv, pnstr, pnlen+1, 0); } efree(pnstr); +#endif pnstr = spl_gen_private_prop_name(spl_ce_RecursiveDirectoryIterator, "subPathName", sizeof("subPathName")-1, &pnlen TSRMLS_CC); if (intern->u.dir.sub_path) { add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->u.dir.sub_path, intern->u.dir.sub_path_len, 1); @@ -647,12 +651,16 @@ intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); intern->flags = flags; +#ifdef HAVE_GLOB if (SPL_HAS_FLAG(ctor_flags, DIT_CTOR_GLOB) && strstr(path, "glob://") != path) { spprintf(&path, 0, "glob://%s", path); spl_filesystem_dir_open(intern, path TSRMLS_CC); efree(path); - } else { + } else +#endif + { spl_filesystem_dir_open(intern, path TSRMLS_CC); + } intern->u.dir.is_recursive = instanceof_function(intern->std.ce, spl_ce_RecursiveDirectoryIterator TSRMLS_CC) ? 1 : 0; @@ -1439,6 +1447,7 @@ } /* }}} */ +#ifdef HAVE_GLOB /* {{{ proto int GlobIterator::__construct(string path [, int flags]) Cronstructs a new dir iterator from a glob expression (no glob:// needed). */ SPL_METHOD(GlobIterator, __construct) @@ -1465,6 +1474,7 @@ } } /* }}} */ +#endif /* HAVE_GLOB */ /* {{{ forward declarations to the iterator handlers */ static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC); @@ -1864,11 +1874,13 @@ {NULL, NULL, NULL} }; +#ifdef HAVE_GLOB static const zend_function_entry spl_GlobIterator_functions[] = { SPL_ME(GlobIterator, __construct, arginfo_r_dir___construct, ZEND_ACC_PUBLIC) SPL_ME(GlobIterator, count, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; +#endif /* }}} */ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */ @@ -2824,8 +2836,10 @@ REGISTER_SPL_SUB_CLASS_EX(RecursiveDirectoryIterator, FilesystemIterator, spl_filesystem_object_new, spl_RecursiveDirectoryIterator_functions); REGISTER_SPL_IMPLEMENTS(RecursiveDirectoryIterator, RecursiveIterator); +#ifdef HAVE_GLOB REGISTER_SPL_SUB_CLASS_EX(GlobIterator, FilesystemIterator, spl_filesystem_object_new, spl_GlobIterator_functions); REGISTER_SPL_IMPLEMENTS(GlobIterator, Countable); +#endif REGISTER_SPL_SUB_CLASS_EX(SplFileObject, SplFileInfo, spl_filesystem_object_new, spl_SplFileObject_functions); REGISTER_SPL_IMPLEMENTS(SplFileObject, RecursiveIterator); Modified: php/php-src/branches/PHP_5_3/ext/spl/tests/dit_001.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/spl/tests/dit_001.phpt 2011-02-04 10:49:33 UTC (rev 308012) +++ php/php-src/branches/PHP_5_3/ext/spl/tests/dit_001.phpt 2011-02-04 10:49:49 UTC (rev 308013) @@ -1,5 +1,8 @@ --TEST-- SPL: Problem with casting to string +--SKIPIF-- +<?php +if (!defined('GLOB_ERR')) print "skip"; --FILE-- <?php $d = new DirectoryIterator('.'); Added: php/php-src/branches/PHP_5_3/ext/spl/tests/dit_001_noglob.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/spl/tests/dit_001_noglob.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/spl/tests/dit_001_noglob.phpt 2011-02-04 10:49:49 UTC (rev 308013) @@ -0,0 +1,27 @@ +--TEST-- +SPL: Problem with casting to string (no glob version) +--SKIPIF-- +<?php +if (defined('GLOB_ERR')) print "skip"; +--FILE-- +<?php +$d = new DirectoryIterator('.'); +var_dump($d); +var_dump(is_string($d)); +preg_match('/x/', $d); +var_dump(is_string($d)); +?> +===DONE=== +--EXPECTF-- +object(DirectoryIterator)#%d (3) { + %s"pathName"%s"SplFileInfo":private]=> + %s(%d) ".%c%s" + %s"fileName"%s"SplFileInfo":private]=> + %s(%d) "%s" + %s"subPathName"%s"RecursiveDirectoryIterator":private]=> + %s(0) "" +} +bool(false) +bool(false) +===DONE=== + Modified: php/php-src/branches/PHP_5_3/ext/spl/tests/dit_002.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/spl/tests/dit_002.phpt 2011-02-04 10:49:33 UTC (rev 308012) +++ php/php-src/branches/PHP_5_3/ext/spl/tests/dit_002.phpt 2011-02-04 10:49:49 UTC (rev 308013) @@ -1,7 +1,7 @@ --TEST-- SPL: DirectoryIterator defaults --SKIPIF-- -<?php if (!extension_loaded("spl") || !extension_loaded('reflection')) print "skip"; ?> +<?php if (!extension_loaded("spl") || !extension_loaded('reflection') || !defined('GLOB_ERR')) print "skip"; ?> --FILE-- <?php Modified: php/php-src/trunk/ext/spl/spl_directory.c =================================================================== --- php/php-src/trunk/ext/spl/spl_directory.c 2011-02-04 10:49:33 UTC (rev 308012) +++ php/php-src/trunk/ext/spl/spl_directory.c 2011-02-04 10:49:49 UTC (rev 308013) @@ -163,11 +163,13 @@ PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, int *len TSRMLS_DC) /* {{{ */ { +#ifdef HAVE_GLOB if (intern->type == SPL_FS_DIR) { if (php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) { return php_glob_stream_get_path(intern->u.dir.dirp, 0, len); } } +#endif if (len) { *len = intern->_path_len; } @@ -578,6 +580,7 @@ efree(pnstr); } if (intern->type == SPL_FS_DIR) { +#ifdef HAVE_GLOB pnstr = spl_gen_private_prop_name(spl_ce_DirectoryIterator, "glob", sizeof("glob")-1, &pnlen TSRMLS_CC); if (php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) { add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->_path, intern->_path_len, 1); @@ -585,6 +588,7 @@ add_assoc_bool_ex(&zrv, pnstr, pnlen+1, 0); } efree(pnstr); +#endif pnstr = spl_gen_private_prop_name(spl_ce_RecursiveDirectoryIterator, "subPathName", sizeof("subPathName")-1, &pnlen TSRMLS_CC); if (intern->u.dir.sub_path) { add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->u.dir.sub_path, intern->u.dir.sub_path_len, 1); @@ -650,12 +654,16 @@ intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); intern->flags = flags; +#ifdef HAVE_GLOB if (SPL_HAS_FLAG(ctor_flags, DIT_CTOR_GLOB) && strstr(path, "glob://") != path) { spprintf(&path, 0, "glob://%s", path); spl_filesystem_dir_open(intern, path TSRMLS_CC); efree(path); - } else { + } else +#endif + { spl_filesystem_dir_open(intern, path TSRMLS_CC); + } intern->u.dir.is_recursive = instanceof_function(intern->std.ce, spl_ce_RecursiveDirectoryIterator TSRMLS_CC) ? 1 : 0; @@ -1501,6 +1509,7 @@ } /* }}} */ +#ifdef HAVE_GLOB /* {{{ proto int GlobIterator::__construct(string path [, int flags]) Cronstructs a new dir iterator from a glob expression (no glob:// needed). */ SPL_METHOD(GlobIterator, __construct) @@ -1527,6 +1536,7 @@ } } /* }}} */ +#endif /* HAVE_GLOB */ /* {{{ forward declarations to the iterator handlers */ static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC); @@ -1928,11 +1938,13 @@ {NULL, NULL, NULL} }; +#ifdef HAVE_GLOB static const zend_function_entry spl_GlobIterator_functions[] = { SPL_ME(GlobIterator, __construct, arginfo_r_dir___construct, ZEND_ACC_PUBLIC) SPL_ME(GlobIterator, count, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; +#endif /* }}} */ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */ @@ -2932,8 +2944,10 @@ REGISTER_SPL_SUB_CLASS_EX(RecursiveDirectoryIterator, FilesystemIterator, spl_filesystem_object_new, spl_RecursiveDirectoryIterator_functions); REGISTER_SPL_IMPLEMENTS(RecursiveDirectoryIterator, RecursiveIterator); +#ifdef HAVE_GLOB REGISTER_SPL_SUB_CLASS_EX(GlobIterator, FilesystemIterator, spl_filesystem_object_new, spl_GlobIterator_functions); REGISTER_SPL_IMPLEMENTS(GlobIterator, Countable); +#endif REGISTER_SPL_SUB_CLASS_EX(SplFileObject, SplFileInfo, spl_filesystem_object_new, spl_SplFileObject_functions); REGISTER_SPL_IMPLEMENTS(SplFileObject, RecursiveIterator); Modified: php/php-src/trunk/ext/spl/tests/dit_001.phpt =================================================================== --- php/php-src/trunk/ext/spl/tests/dit_001.phpt 2011-02-04 10:49:33 UTC (rev 308012) +++ php/php-src/trunk/ext/spl/tests/dit_001.phpt 2011-02-04 10:49:49 UTC (rev 308013) @@ -1,5 +1,8 @@ --TEST-- SPL: Problem with casting to string +--SKIPIF-- +<?php +if (!defined('GLOB_ERR')) print "skip"; --FILE-- <?php $d = new DirectoryIterator('.'); Added: php/php-src/trunk/ext/spl/tests/dit_001_noglob.phpt =================================================================== --- php/php-src/trunk/ext/spl/tests/dit_001_noglob.phpt (rev 0) +++ php/php-src/trunk/ext/spl/tests/dit_001_noglob.phpt 2011-02-04 10:49:49 UTC (rev 308013) @@ -0,0 +1,27 @@ +--TEST-- +SPL: Problem with casting to string (no glob version) +--SKIPIF-- +<?php +if (defined('GLOB_ERR')) print "skip"; +--FILE-- +<?php +$d = new DirectoryIterator('.'); +var_dump($d); +var_dump(is_string($d)); +preg_match('/x/', $d); +var_dump(is_string($d)); +?> +===DONE=== +--EXPECTF-- +object(DirectoryIterator)#%d (3) { + %s"pathName"%s"SplFileInfo":private]=> + %s(%d) ".%c%s" + %s"fileName"%s"SplFileInfo":private]=> + %s(%d) "%s" + %s"subPathName"%s"RecursiveDirectoryIterator":private]=> + %s(0) "" +} +bool(false) +bool(false) +===DONE=== + Modified: php/php-src/trunk/ext/spl/tests/dit_002.phpt =================================================================== --- php/php-src/trunk/ext/spl/tests/dit_002.phpt 2011-02-04 10:49:33 UTC (rev 308012) +++ php/php-src/trunk/ext/spl/tests/dit_002.phpt 2011-02-04 10:49:49 UTC (rev 308013) @@ -1,7 +1,7 @@ --TEST-- SPL: DirectoryIterator defaults --SKIPIF-- -<?php if (!extension_loaded("spl") || !extension_loaded('reflection')) print "skip"; ?> +<?php if (!extension_loaded("spl") || !extension_loaded('reflection') || !defined('GLOB_ERR')) print "skip"; ?> --FILE-- <?php
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php