Skip to content

Commit 90b8db4

Browse files
committed
ext/spl: Refactor SplFileInfo::getPathInfo() implementation
1 parent bed11e4 commit 90b8db4

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

ext/spl/spl_directory.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,19 +472,14 @@ static void spl_filesystem_info_set_filename(spl_filesystem_object *intern, zend
472472
intern->path = zend_string_init(ZSTR_VAL(path), path_len, 0);
473473
} /* }}} */
474474

475-
static spl_filesystem_object *spl_filesystem_object_create_info(spl_filesystem_object *source, zend_string *file_path, zend_class_entry *ce, zval *return_value) /* {{{ */
475+
// TODO Do not pass return_value pointer but actually use value returned by function at call site?
476+
static spl_filesystem_object *spl_filesystem_object_create_info(zend_string *file_path, zend_class_entry *ce, zval *return_value) /* {{{ */
476477
{
477478
spl_filesystem_object *intern;
478479
zval arg1;
479480

480-
if (!file_path || !ZSTR_LEN(file_path)) {
481-
#ifdef PHP_WIN32
482-
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot create SplFileInfo for empty path");
483-
#endif
484-
return NULL;
485-
}
486-
487-
ce = ce ? ce : source->info_class;
481+
ZEND_ASSERT(file_path && ZSTR_LEN(file_path) > 0);
482+
ZEND_ASSERT(ce != NULL);
488483

489484
intern = spl_filesystem_from_obj(spl_filesystem_object_new_ex(ce));
490485
RETVAL_OBJ(&intern->std);
@@ -1383,18 +1378,22 @@ PHP_METHOD(SplFileInfo, getFileInfo)
13831378
PHP_METHOD(SplFileInfo, getPathInfo)
13841379
{
13851380
spl_filesystem_object *intern = spl_filesystem_from_obj(Z_OBJ_P(ZEND_THIS));
1386-
zend_class_entry *ce = intern->info_class;
1381+
zend_class_entry *ce = NULL;
13871382
zend_string *path;
13881383

13891384
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|C!", &ce) == FAILURE) {
13901385
RETURN_THROWS();
13911386
}
13921387

1388+
if (ce == NULL) {
1389+
ce = intern->info_class;
1390+
}
1391+
13931392
path = spl_filesystem_object_get_pathname(intern);
13941393
if (path && ZSTR_LEN(path)) {
13951394
zend_string *dpath = zend_string_init(ZSTR_VAL(path), ZSTR_LEN(path), 0);
13961395
ZSTR_LEN(dpath) = php_dirname(ZSTR_VAL(dpath), ZSTR_LEN(path));
1397-
spl_filesystem_object_create_info(intern, dpath, ce, return_value);
1396+
spl_filesystem_object_create_info(dpath, ce, return_value);
13981397
zend_string_release(dpath);
13991398
}
14001399
}

0 commit comments

Comments
 (0)