|
27 | 27 | #include "zend_exceptions.h" |
28 | 28 | #include "zend_interfaces.h" |
29 | 29 |
|
30 | | -#include "spl_functions.h" /* For spl_gen_private_prop_name() */ |
31 | 30 | #include "spl_iterators.h" |
32 | 31 | #include "spl_directory.h" |
33 | 32 | #include "spl_directory_arginfo.h" |
34 | 33 | #include "spl_exceptions.h" |
| 34 | +#include "spl_functions.h" /* For spl_set_private_debug_info_property() */ |
35 | 35 |
|
36 | 36 | #define SPL_HAS_FLAG(flags, test_flag) ((flags & test_flag) ? 1 : 0) |
37 | 37 |
|
@@ -600,84 +600,69 @@ static inline HashTable *spl_filesystem_object_get_debug_info(zend_object *objec |
600 | 600 | { |
601 | 601 | spl_filesystem_object *intern = spl_filesystem_from_obj(object); |
602 | 602 | zval tmp; |
603 | | - HashTable *rv; |
604 | | - zend_string *pnstr; |
605 | | - zend_string *path; |
606 | | - char stmp[2]; |
| 603 | + HashTable *debug_info; |
| 604 | + zend_string *path_name; |
607 | 605 |
|
608 | 606 | if (!intern->std.properties) { |
609 | 607 | rebuild_object_properties(&intern->std); |
610 | 608 | } |
611 | 609 |
|
612 | | - rv = zend_array_dup(intern->std.properties); |
| 610 | + // TODO Do zend_new_array() + zend_hash_copy() trick? |
| 611 | + debug_info = zend_array_dup(intern->std.properties); |
613 | 612 |
|
614 | | - pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "pathName", sizeof("pathName")-1); |
615 | | - path = spl_filesystem_object_get_pathname(intern); |
616 | | - if (path) { |
617 | | - ZVAL_STR_COPY(&tmp, path); |
| 613 | + path_name = spl_filesystem_object_get_pathname(intern); |
| 614 | + if (path_name) { |
| 615 | + ZVAL_STR_COPY(&tmp, path_name); |
618 | 616 | } else { |
619 | 617 | ZVAL_EMPTY_STRING(&tmp); |
620 | 618 | } |
621 | | - zend_symtable_update(rv, pnstr, &tmp); |
622 | | - zend_string_release_ex(pnstr, 0); |
| 619 | + /* IMPORTANT: Do not free path_name as spl_filesystem_object_get_pathname() |
| 620 | + * updates/sets the intern->file_name and returns the pointer to |
| 621 | + * intern->file_name which must remain allocated. */ |
| 622 | + spl_set_private_debug_info_property(spl_ce_SplFileInfo, "pathName", strlen("pathName"), debug_info, &tmp); |
623 | 623 |
|
624 | 624 | if (intern->file_name) { |
625 | | - zend_string *path; |
626 | | - |
627 | | - pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "fileName", sizeof("fileName")-1); |
628 | | - path = spl_filesystem_object_get_path(intern); |
629 | | - |
| 625 | + zend_string *path = spl_filesystem_object_get_path(intern); |
630 | 626 | if (path && ZSTR_LEN(path) && ZSTR_LEN(path) < ZSTR_LEN(intern->file_name)) { |
631 | 627 | /* +1 to skip the trailing / of the path in the file name */ |
632 | 628 | ZVAL_STRINGL(&tmp, ZSTR_VAL(intern->file_name) + ZSTR_LEN(path) + 1, ZSTR_LEN(intern->file_name) - (ZSTR_LEN(path) + 1)); |
633 | 629 | } else { |
634 | 630 | ZVAL_STR_COPY(&tmp, intern->file_name); |
635 | 631 | } |
636 | | - zend_symtable_update(rv, pnstr, &tmp); |
637 | | - zend_string_release_ex(pnstr, /* persistent */ false); |
638 | 632 | if (path) { |
639 | 633 | zend_string_release_ex(path, /* persistent */ false); |
640 | 634 | } |
| 635 | + |
| 636 | + spl_set_private_debug_info_property(spl_ce_SplFileInfo, "fileName", strlen("fileName"), debug_info, &tmp); |
641 | 637 | } |
642 | 638 | if (intern->type == SPL_FS_DIR) { |
643 | 639 | #ifdef HAVE_GLOB |
644 | | - pnstr = spl_gen_private_prop_name(spl_ce_DirectoryIterator, "glob", sizeof("glob")-1); |
645 | | - if (php_stream_is(intern->u.dir.dirp ,&php_glob_stream_ops)) { |
| 640 | + if (php_stream_is(intern->u.dir.dirp, &php_glob_stream_ops)) { |
646 | 641 | ZVAL_STR_COPY(&tmp, intern->path); |
647 | 642 | } else { |
648 | 643 | ZVAL_FALSE(&tmp); |
649 | 644 | } |
650 | | - zend_symtable_update(rv, pnstr, &tmp); |
651 | | - zend_string_release_ex(pnstr, 0); |
| 645 | + spl_set_private_debug_info_property(spl_ce_DirectoryIterator, "glob", strlen("glob"), debug_info, &tmp); |
652 | 646 | #endif |
653 | | - pnstr = spl_gen_private_prop_name(spl_ce_RecursiveDirectoryIterator, "subPathName", sizeof("subPathName")-1); |
654 | 647 | if (intern->u.dir.sub_path) { |
655 | 648 | ZVAL_STR_COPY(&tmp, intern->u.dir.sub_path); |
656 | 649 | } else { |
657 | 650 | ZVAL_EMPTY_STRING(&tmp); |
658 | 651 | } |
659 | | - zend_symtable_update(rv, pnstr, &tmp); |
660 | | - zend_string_release_ex(pnstr, 0); |
| 652 | + spl_set_private_debug_info_property(spl_ce_RecursiveDirectoryIterator, "subPathName", strlen("subPathName"), debug_info, &tmp); |
661 | 653 | } |
662 | 654 | if (intern->type == SPL_FS_FILE) { |
663 | | - pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "openMode", sizeof("openMode")-1); |
664 | 655 | ZVAL_STR_COPY(&tmp, intern->u.file.open_mode); |
665 | | - zend_symtable_update(rv, pnstr, &tmp); |
666 | | - zend_string_release_ex(pnstr, 0); |
667 | | - stmp[1] = '\0'; |
668 | | - stmp[0] = intern->u.file.delimiter; |
669 | | - pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "delimiter", sizeof("delimiter")-1); |
670 | | - ZVAL_STRINGL(&tmp, stmp, 1); |
671 | | - zend_symtable_update(rv, pnstr, &tmp); |
672 | | - zend_string_release_ex(pnstr, 0); |
673 | | - stmp[0] = intern->u.file.enclosure; |
674 | | - pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "enclosure", sizeof("enclosure")-1); |
675 | | - ZVAL_STRINGL(&tmp, stmp, 1); |
676 | | - zend_symtable_update(rv, pnstr, &tmp); |
677 | | - zend_string_release_ex(pnstr, 0); |
678 | | - } |
679 | | - |
680 | | - return rv; |
| 656 | + spl_set_private_debug_info_property(spl_ce_SplFileObject, "openMode", strlen("openMode"), debug_info, &tmp); |
| 657 | + |
| 658 | + ZVAL_STR(&tmp, ZSTR_CHAR((zend_uchar)intern->u.file.delimiter)); |
| 659 | + spl_set_private_debug_info_property(spl_ce_SplFileObject, "delimiter", strlen("delimiter"), debug_info, &tmp); |
| 660 | + |
| 661 | + ZVAL_STR(&tmp, ZSTR_CHAR((zend_uchar)intern->u.file.enclosure)); |
| 662 | + spl_set_private_debug_info_property(spl_ce_SplFileObject, "enclosure", strlen("enclosure"), debug_info, &tmp); |
| 663 | + } |
| 664 | + |
| 665 | + return debug_info; |
681 | 666 | } |
682 | 667 | /* }}} */ |
683 | 668 |
|
|
0 commit comments