summaryrefslogtreecommitdiff
path: root/ext/spl/spl_directory.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/spl/spl_directory.c')
-rw-r--r--ext/spl/spl_directory.c1620
1 files changed, 795 insertions, 825 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index e60078a539..b0ee3bc7a3 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
@@ -60,28 +60,28 @@ PHPAPI zend_class_entry *spl_ce_GlobIterator;
PHPAPI zend_class_entry *spl_ce_SplFileObject;
PHPAPI zend_class_entry *spl_ce_SplTempFileObject;
-static void spl_filesystem_file_free_line(spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
+static void spl_filesystem_file_free_line(spl_filesystem_object *intern) /* {{{ */
{
if (intern->u.file.current_line) {
efree(intern->u.file.current_line);
intern->u.file.current_line = NULL;
}
- if (intern->u.file.current_zval) {
+ if (!Z_ISUNDEF(intern->u.file.current_zval)) {
zval_ptr_dtor(&intern->u.file.current_zval);
- intern->u.file.current_zval = NULL;
+ ZVAL_UNDEF(&intern->u.file.current_zval);
}
} /* }}} */
-static void spl_filesystem_object_free_storage(void *object TSRMLS_DC) /* {{{ */
+static void spl_filesystem_object_free_storage(zend_object *object) /* {{{ */
{
- spl_filesystem_object *intern = (spl_filesystem_object*)object;
+ spl_filesystem_object *intern = spl_filesystem_from_obj(object);
if (intern->oth_handler && intern->oth_handler->dtor) {
- intern->oth_handler->dtor(intern TSRMLS_CC);
+ intern->oth_handler->dtor(intern);
}
-
- zend_object_std_dtor(&intern->std TSRMLS_CC);
-
+
+ zend_object_std_dtor(&intern->std);
+
if (intern->_path) {
efree(intern->_path);
}
@@ -98,17 +98,19 @@ static void spl_filesystem_object_free_storage(void *object TSRMLS_DC) /* {{{ */
}
if (intern->u.dir.sub_path) {
efree(intern->u.dir.sub_path);
- }
+ }
break;
case SPL_FS_FILE:
if (intern->u.file.stream) {
+ /*
if (intern->u.file.zcontext) {
-/* zend_list_delref(Z_RESVAL_P(intern->zcontext));*/
+ zend_list_delref(Z_RESVAL_P(intern->zcontext));
}
+ */
if (!intern->u.file.stream->is_persistent) {
- php_stream_free(intern->u.file.stream, PHP_STREAM_FREE_CLOSE);
+ php_stream_close(intern->u.file.stream);
} else {
- php_stream_free(intern->u.file.stream, PHP_STREAM_FREE_CLOSE_PERSISTENT);
+ php_stream_pclose(intern->u.file.stream);
}
if (intern->u.file.open_mode) {
efree(intern->u.file.open_mode);
@@ -117,73 +119,57 @@ static void spl_filesystem_object_free_storage(void *object TSRMLS_DC) /* {{{ */
efree(intern->orig_path);
}
}
- spl_filesystem_file_free_line(intern TSRMLS_CC);
+ spl_filesystem_file_free_line(intern);
break;
}
-
- {
- zend_object_iterator *iterator;
- iterator = (zend_object_iterator*)
- spl_filesystem_object_to_iterator(intern);
- if (iterator->data != NULL) {
- iterator->data = NULL;
- iterator->funcs->dtor(iterator TSRMLS_CC);
- }
- }
- efree(object);
} /* }}} */
/* {{{ spl_ce_dir_object_new */
-/* creates the object by
- - allocating memory
+/* creates the object by
+ - allocating memory
- initializing the object members
- storing the object
- setting it's handlers
- called from
+ called from
- clone
- new
*/
-static zend_object_value spl_filesystem_object_new_ex(zend_class_entry *class_type, spl_filesystem_object **obj TSRMLS_DC)
+static zend_object *spl_filesystem_object_new_ex(zend_class_entry *class_type)
{
- zend_object_value retval;
spl_filesystem_object *intern;
- intern = emalloc(sizeof(spl_filesystem_object));
- memset(intern, 0, sizeof(spl_filesystem_object));
+ intern = ecalloc(1, sizeof(spl_filesystem_object) + zend_object_properties_size(class_type));
/* intern->type = SPL_FS_INFO; done by set 0 */
intern->file_class = spl_ce_SplFileObject;
intern->info_class = spl_ce_SplFileInfo;
- if (obj) *obj = intern;
- zend_object_std_init(&intern->std, class_type TSRMLS_CC);
+ zend_object_std_init(&intern->std, class_type);
object_properties_init(&intern->std, class_type);
+ intern->std.handlers = &spl_filesystem_object_handlers;
- retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_filesystem_object_free_storage, NULL TSRMLS_CC);
- retval.handlers = &spl_filesystem_object_handlers;
- return retval;
+ return &intern->std;
}
/* }}} */
/* {{{ spl_filesystem_object_new */
/* See spl_filesystem_object_new_ex */
-static zend_object_value spl_filesystem_object_new(zend_class_entry *class_type TSRMLS_DC)
+static zend_object *spl_filesystem_object_new(zend_class_entry *class_type)
{
- return spl_filesystem_object_new_ex(class_type, NULL TSRMLS_CC);
+ return spl_filesystem_object_new_ex(class_type);
}
/* }}} */
-/* {{{ spl_filesystem_object_new_ex */
-static zend_object_value spl_filesystem_object_new_check(zend_class_entry *class_type TSRMLS_DC)
+/* {{{ spl_filesystem_object_new_check */
+static zend_object *spl_filesystem_object_new_check(zend_class_entry *class_type)
{
- zend_object_value ret = spl_filesystem_object_new_ex(class_type, NULL TSRMLS_CC);
- ret.handlers = &spl_filesystem_object_check_handlers;
- return ret;
+ spl_filesystem_object *ret = spl_filesystem_from_obj(spl_filesystem_object_new_ex(class_type));
+ ret->std.handlers = &spl_filesystem_object_check_handlers;
+ return &ret->std;
}
/* }}} */
-
-PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, int *len TSRMLS_DC) /* {{{ */
+PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, size_t *len) /* {{{ */
{
#ifdef HAVE_GLOB
if (intern->type == SPL_FS_DIR) {
@@ -198,7 +184,7 @@ PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, int *
return intern->_path;
} /* }}} */
-static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
+static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *intern) /* {{{ */
{
char slash = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_UNIXPATHS) ? '/' : DEFAULT_SLASH;
@@ -206,21 +192,21 @@ static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *in
case SPL_FS_INFO:
case SPL_FS_FILE:
if (!intern->file_name) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
+ php_error_docref(NULL, E_ERROR, "Object not initialized");
}
break;
case SPL_FS_DIR:
if (intern->file_name) {
efree(intern->file_name);
}
- intern->file_name_len = spprintf(&intern->file_name, 0, "%s%c%s",
- spl_filesystem_object_get_path(intern, NULL TSRMLS_CC),
+ intern->file_name_len = (int)spprintf(&intern->file_name, 0, "%s%c%s",
+ spl_filesystem_object_get_path(intern, NULL),
slash, intern->u.dir.entry.d_name);
break;
}
} /* }}} */
-static int spl_filesystem_dir_read(spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
+static int spl_filesystem_dir_read(spl_filesystem_object *intern) /* {{{ */
{
if (!intern->u.dir.dirp || !php_stream_readdir(intern->u.dir.dirp, &intern->u.dir.entry)) {
intern->u.dir.entry.d_name[0] = '\0';
@@ -241,12 +227,12 @@ static inline int spl_filesystem_is_dot(const char * d_name) /* {{{ */
/* {{{ spl_filesystem_dir_open */
/* open a directory resource */
-static void spl_filesystem_dir_open(spl_filesystem_object* intern, char *path TSRMLS_DC)
+static void spl_filesystem_dir_open(spl_filesystem_object* intern, char *path)
{
int skip_dots = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_SKIPDOTS);
intern->type = SPL_FS_DIR;
- intern->_path_len = strlen(path);
+ intern->_path_len = (int)strlen(path);
intern->u.dir.dirp = php_stream_opendir(path, REPORT_ERRORS, FG(default_context));
if (intern->_path_len > 1 && IS_SLASH_AT(path, intern->_path_len-1)) {
@@ -260,28 +246,28 @@ static void spl_filesystem_dir_open(spl_filesystem_object* intern, char *path TS
intern->u.dir.entry.d_name[0] = '\0';
if (!EG(exception)) {
/* open failed w/out notice (turned to exception due to EH_THROW) */
- zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0
- TSRMLS_CC, "Failed to open directory \"%s\"", path);
+ zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
+ "Failed to open directory \"%s\"", path);
}
} else {
do {
- spl_filesystem_dir_read(intern TSRMLS_CC);
+ spl_filesystem_dir_read(intern);
} while (skip_dots && spl_filesystem_is_dot(intern->u.dir.entry.d_name));
}
}
/* }}} */
-static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_include_path, int silent TSRMLS_DC) /* {{{ */
+static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_include_path, int silent) /* {{{ */
{
- zval tmp;
+ zval tmp;
intern->type = SPL_FS_FILE;
- php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, &tmp TSRMLS_CC);
- if (Z_LVAL(tmp)) {
+ php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, &tmp);
+ if (Z_TYPE(tmp) == IS_TRUE) {
intern->u.file.open_mode = NULL;
intern->file_name = NULL;
- zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Cannot use SplFileObject with directories");
+ zend_throw_exception_ex(spl_ce_LogicException, 0, "Cannot use SplFileObject with directories");
return FAILURE;
}
@@ -290,16 +276,19 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
if (!intern->file_name_len || !intern->u.file.stream) {
if (!EG(exception)) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot open file '%s'", intern->file_name_len ? intern->file_name : "");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot open file '%s'", intern->file_name_len ? intern->file_name : "");
}
intern->file_name = NULL; /* until here it is not a copy */
intern->u.file.open_mode = NULL;
return FAILURE;
}
+ /*
if (intern->u.file.zcontext) {
- zend_list_addref(Z_RESVAL_P(intern->u.file.zcontext));
+ //zend_list_addref(Z_RES_VAL(intern->u.file.zcontext));
+ Z_ADDREF_P(intern->u.file.zcontext);
}
+ */
if (intern->file_name_len > 1 && IS_SLASH_AT(intern->file_name, intern->file_name_len-1)) {
intern->file_name_len--;
@@ -311,93 +300,92 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
intern->u.file.open_mode = estrndup(intern->u.file.open_mode, intern->u.file.open_mode_len);
/* avoid reference counting in debug mode, thus do it manually */
- ZVAL_RESOURCE(&intern->u.file.zresource, php_stream_get_resource_id(intern->u.file.stream));
+ ZVAL_RES(&intern->u.file.zresource, intern->u.file.stream->res);
+ /*!!! TODO: maybe bug?
Z_SET_REFCOUNT(intern->u.file.zresource, 1);
-
+ */
+
intern->u.file.delimiter = ',';
intern->u.file.enclosure = '"';
intern->u.file.escape = '\\';
- zend_hash_find(&intern->std.ce->function_table, "getcurrentline", sizeof("getcurrentline"), (void **) &intern->u.file.func_getCurr);
+ intern->u.file.func_getCurr = zend_hash_str_find_ptr(&intern->std.ce->function_table, "getcurrentline", sizeof("getcurrentline") - 1);
return SUCCESS;
} /* }}} */
/* {{{ spl_filesystem_object_clone */
-/* Local zend_object_value creation (on stack)
- Load the 'other' object
+/* Local zend_object creation (on stack)
+ Load the 'other' object
Create a new empty object (See spl_filesystem_object_new_ex)
Open the directory
Clone other members (properties)
*/
-static zend_object_value spl_filesystem_object_clone(zval *zobject TSRMLS_DC)
+static zend_object *spl_filesystem_object_clone(zval *zobject)
{
- zend_object_value new_obj_val;
zend_object *old_object;
zend_object *new_object;
- zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
spl_filesystem_object *intern;
spl_filesystem_object *source;
int index, skip_dots;
- old_object = zend_objects_get_address(zobject TSRMLS_CC);
- source = (spl_filesystem_object*)old_object;
-
- new_obj_val = spl_filesystem_object_new_ex(old_object->ce, &intern TSRMLS_CC);
- new_object = &intern->std;
+ old_object = Z_OBJ_P(zobject);
+ source = spl_filesystem_from_obj(old_object);
+ new_object = spl_filesystem_object_new_ex(old_object->ce);
+ intern = spl_filesystem_from_obj(new_object);
intern->flags = source->flags;
switch (source->type) {
- case SPL_FS_INFO:
- intern->_path_len = source->_path_len;
- intern->_path = estrndup(source->_path, source->_path_len);
- intern->file_name_len = source->file_name_len;
- intern->file_name = estrndup(source->file_name, intern->file_name_len);
- break;
- case SPL_FS_DIR:
- spl_filesystem_dir_open(intern, source->_path TSRMLS_CC);
- /* read until we hit the position in which we were before */
- skip_dots = SPL_HAS_FLAG(source->flags, SPL_FILE_DIR_SKIPDOTS);
- for(index = 0; index < source->u.dir.index; ++index) {
- do {
- spl_filesystem_dir_read(intern TSRMLS_CC);
- } while (skip_dots && spl_filesystem_is_dot(intern->u.dir.entry.d_name));
- }
- intern->u.dir.index = index;
- break;
- case SPL_FS_FILE:
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "An object of class %s cannot be cloned", old_object->ce->name);
- break;
+ case SPL_FS_INFO:
+ intern->_path_len = source->_path_len;
+ intern->_path = estrndup(source->_path, source->_path_len);
+ intern->file_name_len = source->file_name_len;
+ intern->file_name = estrndup(source->file_name, intern->file_name_len);
+ break;
+ case SPL_FS_DIR:
+ spl_filesystem_dir_open(intern, source->_path);
+ /* read until we hit the position in which we were before */
+ skip_dots = SPL_HAS_FLAG(source->flags, SPL_FILE_DIR_SKIPDOTS);
+ for(index = 0; index < source->u.dir.index; ++index) {
+ do {
+ spl_filesystem_dir_read(intern);
+ } while (skip_dots && spl_filesystem_is_dot(intern->u.dir.entry.d_name));
+ }
+ intern->u.dir.index = index;
+ break;
+ case SPL_FS_FILE:
+ php_error_docref(NULL, E_ERROR, "An object of class %s cannot be cloned", ZSTR_VAL(old_object->ce->name));
+ break;
}
-
+
intern->file_class = source->file_class;
intern->info_class = source->info_class;
intern->oth = source->oth;
intern->oth_handler = source->oth_handler;
- zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC);
+ zend_objects_clone_members(new_object, old_object);
if (intern->oth_handler && intern->oth_handler->clone) {
- intern->oth_handler->clone(source, intern TSRMLS_CC);
+ intern->oth_handler->clone(source, intern);
}
- return new_obj_val;
+ return new_object;
}
/* }}} */
-void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path, int len, int use_copy TSRMLS_DC) /* {{{ */
+void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path, size_t len, size_t use_copy) /* {{{ */
{
char *p1, *p2;
-
+
if (intern->file_name) {
efree(intern->file_name);
}
intern->file_name = use_copy ? estrndup(path, len) : path;
- intern->file_name_len = len;
+ intern->file_name_len = (int)len;
- while(IS_SLASH_AT(intern->file_name, intern->file_name_len-1) && intern->file_name_len > 1) {
+ while (intern->file_name_len > 1 && IS_SLASH_AT(intern->file_name, intern->file_name_len-1)) {
intern->file_name[intern->file_name_len-1] = 0;
intern->file_name_len--;
}
@@ -409,26 +397,26 @@ void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path,
p2 = 0;
#endif
if (p1 || p2) {
- intern->_path_len = (p1 > p2 ? p1 : p2) - intern->file_name;
+ intern->_path_len = (int)((p1 > p2 ? p1 : p2) - intern->file_name);
} else {
intern->_path_len = 0;
}
-
+
if (intern->_path) {
efree(intern->_path);
}
intern->_path = estrndup(path, intern->_path_len);
} /* }}} */
-static spl_filesystem_object * spl_filesystem_object_create_info(spl_filesystem_object *source, char *file_path, int file_path_len, int use_copy, zend_class_entry *ce, zval *return_value TSRMLS_DC) /* {{{ */
+static spl_filesystem_object *spl_filesystem_object_create_info(spl_filesystem_object *source, char *file_path, int file_path_len, int use_copy, zend_class_entry *ce, zval *return_value) /* {{{ */
{
spl_filesystem_object *intern;
- zval *arg1;
+ zval arg1;
zend_error_handling error_handling;
if (!file_path || !file_path_len) {
#if defined(PHP_WIN32)
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot create SplFileInfo for empty path");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot create SplFileInfo for empty path");
if (file_path && !use_copy) {
efree(file_path);
}
@@ -442,123 +430,124 @@ static spl_filesystem_object * spl_filesystem_object_create_info(spl_filesystem_
return NULL;
}
- zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
ce = ce ? ce : source->info_class;
- zend_update_class_constants(ce TSRMLS_CC);
+ zend_update_class_constants(ce);
- return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC);
- Z_TYPE_P(return_value) = IS_OBJECT;
+ intern = spl_filesystem_from_obj(spl_filesystem_object_new_ex(ce));
+ ZVAL_OBJ(return_value, &intern->std);
if (ce->constructor->common.scope != spl_ce_SplFileInfo) {
- MAKE_STD_ZVAL(arg1);
- ZVAL_STRINGL(arg1, file_path, file_path_len, use_copy);
- zend_call_method_with_1_params(&return_value, ce, &ce->constructor, "__construct", NULL, arg1);
+ ZVAL_STRINGL(&arg1, file_path, file_path_len);
+ zend_call_method_with_1_params(return_value, ce, &ce->constructor, "__construct", NULL, &arg1);
zval_ptr_dtor(&arg1);
} else {
- spl_filesystem_info_set_filename(intern, file_path, file_path_len, use_copy TSRMLS_CC);
+ spl_filesystem_info_set_filename(intern, file_path, file_path_len, use_copy);
}
-
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+
+ zend_restore_error_handling(&error_handling);
return intern;
} /* }}} */
-static spl_filesystem_object * spl_filesystem_object_create_type(int ht, spl_filesystem_object *source, int type, zend_class_entry *ce, zval *return_value TSRMLS_DC) /* {{{ */
+static spl_filesystem_object *spl_filesystem_object_create_type(int ht, spl_filesystem_object *source, int type, zend_class_entry *ce, zval *return_value) /* {{{ */
{
spl_filesystem_object *intern;
zend_bool use_include_path = 0;
- zval *arg1, *arg2;
+ zval arg1, arg2;
zend_error_handling error_handling;
- zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
switch (source->type) {
- case SPL_FS_INFO:
- case SPL_FS_FILE:
- break;
- case SPL_FS_DIR:
- if (!source->u.dir.entry.d_name[0]) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Could not open file");
- zend_restore_error_handling(&error_handling TSRMLS_CC);
- return NULL;
- }
+ case SPL_FS_INFO:
+ case SPL_FS_FILE:
+ break;
+ case SPL_FS_DIR:
+ if (!source->u.dir.entry.d_name[0]) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Could not open file");
+ zend_restore_error_handling(&error_handling);
+ return NULL;
+ }
}
switch (type) {
- case SPL_FS_INFO:
- ce = ce ? ce : source->info_class;
+ case SPL_FS_INFO:
+ ce = ce ? ce : source->info_class;
- zend_update_class_constants(ce TSRMLS_CC);
+ if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
+ break;
+ }
- return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC);
- Z_TYPE_P(return_value) = IS_OBJECT;
+ intern = spl_filesystem_from_obj(spl_filesystem_object_new_ex(ce));
+ ZVAL_OBJ(return_value, &intern->std);
- spl_filesystem_object_get_file_name(source TSRMLS_CC);
- if (ce->constructor->common.scope != spl_ce_SplFileInfo) {
- MAKE_STD_ZVAL(arg1);
- ZVAL_STRINGL(arg1, source->file_name, source->file_name_len, 1);
- zend_call_method_with_1_params(&return_value, ce, &ce->constructor, "__construct", NULL, arg1);
- zval_ptr_dtor(&arg1);
- } else {
- intern->file_name = estrndup(source->file_name, source->file_name_len);
- intern->file_name_len = source->file_name_len;
- intern->_path = spl_filesystem_object_get_path(source, &intern->_path_len TSRMLS_CC);
- intern->_path = estrndup(intern->_path, intern->_path_len);
- }
- break;
- case SPL_FS_FILE:
- ce = ce ? ce : source->file_class;
-
- zend_update_class_constants(ce TSRMLS_CC);
-
- return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC);
- Z_TYPE_P(return_value) = IS_OBJECT;
-
- spl_filesystem_object_get_file_name(source TSRMLS_CC);
-
- if (ce->constructor->common.scope != spl_ce_SplFileObject) {
- MAKE_STD_ZVAL(arg1);
- MAKE_STD_ZVAL(arg2);
- ZVAL_STRINGL(arg1, source->file_name, source->file_name_len, 1);
- ZVAL_STRINGL(arg2, "r", 1, 1);
- zend_call_method_with_2_params(&return_value, ce, &ce->constructor, "__construct", NULL, arg1, arg2);
- zval_ptr_dtor(&arg1);
- zval_ptr_dtor(&arg2);
- } else {
- intern->file_name = source->file_name;
- intern->file_name_len = source->file_name_len;
- intern->_path = spl_filesystem_object_get_path(source, &intern->_path_len TSRMLS_CC);
- intern->_path = estrndup(intern->_path, intern->_path_len);
-
- intern->u.file.open_mode = "r";
- intern->u.file.open_mode_len = 1;
-
- if (ht && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sbr",
- &intern->u.file.open_mode, &intern->u.file.open_mode_len,
- &use_include_path, &intern->u.file.zcontext) == FAILURE) {
- zend_restore_error_handling(&error_handling TSRMLS_CC);
- intern->u.file.open_mode = NULL;
- intern->file_name = NULL;
- zval_dtor(return_value);
- Z_TYPE_P(return_value) = IS_NULL;
- return NULL;
+ spl_filesystem_object_get_file_name(source);
+ if (ce->constructor->common.scope != spl_ce_SplFileInfo) {
+ ZVAL_STRINGL(&arg1, source->file_name, source->file_name_len);
+ zend_call_method_with_1_params(return_value, ce, &ce->constructor, "__construct", NULL, &arg1);
+ zval_ptr_dtor(&arg1);
+ } else {
+ intern->file_name = estrndup(source->file_name, source->file_name_len);
+ intern->file_name_len = source->file_name_len;
+ intern->_path = spl_filesystem_object_get_path(source, &intern->_path_len);
+ intern->_path = estrndup(intern->_path, intern->_path_len);
}
-
- if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == FAILURE) {
- zend_restore_error_handling(&error_handling TSRMLS_CC);
- zval_dtor(return_value);
- Z_TYPE_P(return_value) = IS_NULL;
- return NULL;
+ break;
+ case SPL_FS_FILE:
+ ce = ce ? ce : source->file_class;
+
+ if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
+ break;
}
- }
- break;
- case SPL_FS_DIR:
- zend_restore_error_handling(&error_handling TSRMLS_CC);
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Operation not supported");
- return NULL;
+
+ intern = spl_filesystem_from_obj(spl_filesystem_object_new_ex(ce));
+
+ ZVAL_OBJ(return_value, &intern->std);
+
+ spl_filesystem_object_get_file_name(source);
+
+ if (ce->constructor->common.scope != spl_ce_SplFileObject) {
+ ZVAL_STRINGL(&arg1, source->file_name, source->file_name_len);
+ ZVAL_STRINGL(&arg2, "r", 1);
+ zend_call_method_with_2_params(return_value, ce, &ce->constructor, "__construct", NULL, &arg1, &arg2);
+ zval_ptr_dtor(&arg1);
+ zval_ptr_dtor(&arg2);
+ } else {
+ intern->file_name = source->file_name;
+ intern->file_name_len = source->file_name_len;
+ intern->_path = spl_filesystem_object_get_path(source, &intern->_path_len);
+ intern->_path = estrndup(intern->_path, intern->_path_len);
+
+ intern->u.file.open_mode = "r";
+ intern->u.file.open_mode_len = 1;
+
+ if (ht && zend_parse_parameters(ht, "|sbr",
+ &intern->u.file.open_mode, &intern->u.file.open_mode_len,
+ &use_include_path, &intern->u.file.zcontext) == FAILURE) {
+ zend_restore_error_handling(&error_handling);
+ intern->u.file.open_mode = NULL;
+ intern->file_name = NULL;
+ zval_ptr_dtor(return_value);
+ ZVAL_NULL(return_value);
+ return NULL;
+ }
+
+ if (spl_filesystem_file_open(intern, use_include_path, 0) == FAILURE) {
+ zend_restore_error_handling(&error_handling);
+ zval_ptr_dtor(return_value);
+ ZVAL_NULL(return_value);
+ return NULL;
+ }
+ }
+ break;
+ case SPL_FS_DIR:
+ zend_restore_error_handling(&error_handling);
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Operation not supported");
+ return NULL;
}
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_restore_error_handling(&error_handling);
return NULL;
} /* }}} */
@@ -568,31 +557,32 @@ static int spl_filesystem_is_invalid_or_dot(const char * d_name) /* {{{ */
}
/* }}} */
-static char *spl_filesystem_object_get_pathname(spl_filesystem_object *intern, int *len TSRMLS_DC) { /* {{{ */
+static char *spl_filesystem_object_get_pathname(spl_filesystem_object *intern, size_t *len) { /* {{{ */
switch (intern->type) {
- case SPL_FS_INFO:
- case SPL_FS_FILE:
- *len = intern->file_name_len;
- return intern->file_name;
- case SPL_FS_DIR:
- if (intern->u.dir.entry.d_name[0]) {
- spl_filesystem_object_get_file_name(intern TSRMLS_CC);
+ case SPL_FS_INFO:
+ case SPL_FS_FILE:
*len = intern->file_name_len;
return intern->file_name;
- }
+ case SPL_FS_DIR:
+ if (intern->u.dir.entry.d_name[0]) {
+ spl_filesystem_object_get_file_name(intern);
+ *len = intern->file_name_len;
+ return intern->file_name;
+ }
}
*len = 0;
return NULL;
}
/* }}} */
-static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp TSRMLS_DC) /* {{{ */
+static HashTable *spl_filesystem_object_get_debug_info(zval *object, int *is_temp) /* {{{ */
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(obj TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(object);
+ zval tmp;
HashTable *rv;
- zval *tmp, zrv;
- char *pnstr, *path;
- int pnlen, path_len;
+ zend_string *pnstr;
+ char *path;
+ size_t path_len;
char stmp[2];
*is_temp = 1;
@@ -601,100 +591,103 @@ static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp T
rebuild_object_properties(&intern->std);
}
- ALLOC_HASHTABLE(rv);
- ZEND_INIT_SYMTABLE_EX(rv, zend_hash_num_elements(intern->std.properties) + 3, 0);
-
- INIT_PZVAL(&zrv);
- Z_ARRVAL(zrv) = rv;
-
- zend_hash_copy(rv, intern->std.properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+ rv = zend_array_dup(intern->std.properties);
- pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "pathName", sizeof("pathName")-1, &pnlen TSRMLS_CC);
- path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC);
- add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, path, path_len, 1);
- efree(pnstr);
+ pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "pathName", sizeof("pathName")-1);
+ path = spl_filesystem_object_get_pathname(intern, &path_len);
+ ZVAL_STRINGL(&tmp, path, path_len);
+ zend_symtable_update(rv, pnstr, &tmp);
+ zend_string_release(pnstr);
if (intern->file_name) {
- pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "fileName", sizeof("fileName")-1, &pnlen TSRMLS_CC);
- spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC);
-
+ pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "fileName", sizeof("fileName")-1);
+ spl_filesystem_object_get_path(intern, &path_len);
+
if (path_len && path_len < intern->file_name_len) {
- add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->file_name + path_len + 1, intern->file_name_len - (path_len + 1), 1);
+ ZVAL_STRINGL(&tmp, intern->file_name + path_len + 1, intern->file_name_len - (path_len + 1));
} else {
- add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->file_name, intern->file_name_len, 1);
+ ZVAL_STRINGL(&tmp, intern->file_name, intern->file_name_len);
}
- efree(pnstr);
+ zend_symtable_update(rv, pnstr, &tmp);
+ zend_string_release(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);
+ pnstr = spl_gen_private_prop_name(spl_ce_DirectoryIterator, "glob", sizeof("glob")-1);
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);
+ ZVAL_STRINGL(&tmp, intern->_path, intern->_path_len);
} else {
- add_assoc_bool_ex(&zrv, pnstr, pnlen+1, 0);
+ ZVAL_FALSE(&tmp);
}
- efree(pnstr);
+ zend_symtable_update(rv, pnstr, &tmp);
+ zend_string_release(pnstr);
#endif
- pnstr = spl_gen_private_prop_name(spl_ce_RecursiveDirectoryIterator, "subPathName", sizeof("subPathName")-1, &pnlen TSRMLS_CC);
+ pnstr = spl_gen_private_prop_name(spl_ce_RecursiveDirectoryIterator, "subPathName", sizeof("subPathName")-1);
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);
+ ZVAL_STRINGL(&tmp, intern->u.dir.sub_path, intern->u.dir.sub_path_len);
} else {
- add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, "", 0, 1);
+ ZVAL_EMPTY_STRING(&tmp);
}
- efree(pnstr);
+ zend_symtable_update(rv, pnstr, &tmp);
+ zend_string_release(pnstr);
}
if (intern->type == SPL_FS_FILE) {
- pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "openMode", sizeof("openMode")-1, &pnlen TSRMLS_CC);
- add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->u.file.open_mode, intern->u.file.open_mode_len, 1);
- efree(pnstr);
+ pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "openMode", sizeof("openMode")-1);
+ ZVAL_STRINGL(&tmp, intern->u.file.open_mode, intern->u.file.open_mode_len);
+ zend_symtable_update(rv, pnstr, &tmp);
+ zend_string_release(pnstr);
stmp[1] = '\0';
stmp[0] = intern->u.file.delimiter;
- pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "delimiter", sizeof("delimiter")-1, &pnlen TSRMLS_CC);
- add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, stmp, 1, 1);
- efree(pnstr);
+ pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "delimiter", sizeof("delimiter")-1);
+ ZVAL_STRINGL(&tmp, stmp, 1);
+ zend_symtable_update(rv, pnstr, &tmp);
+ zend_string_release(pnstr);
stmp[0] = intern->u.file.enclosure;
- pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "enclosure", sizeof("enclosure")-1, &pnlen TSRMLS_CC);
- add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, stmp, 1, 1);
- efree(pnstr);
+ pnstr = spl_gen_private_prop_name(spl_ce_SplFileObject, "enclosure", sizeof("enclosure")-1);
+ ZVAL_STRINGL(&tmp, stmp, 1);
+ zend_symtable_update(rv, pnstr, &tmp);
+ zend_string_release(pnstr);
}
return rv;
}
/* }}} */
-zend_function *spl_filesystem_object_get_method_check(zval **object_ptr, char *method, int method_len, const struct _zend_literal *key TSRMLS_DC) /* {{{ */
+zend_function *spl_filesystem_object_get_method_check(zend_object **object, zend_string *method, const zval *key) /* {{{ */
{
- spl_filesystem_object *fsobj = zend_object_store_get_object(*object_ptr TSRMLS_CC);
-
+ spl_filesystem_object *fsobj = spl_filesystem_from_obj(*object);
+
if (fsobj->u.dir.entry.d_name[0] == '\0' && fsobj->orig_path == NULL) {
- method = "_bad_state_ex";
- method_len = sizeof("_bad_state_ex") - 1;
- key = NULL;
+ zend_function *func;
+ zend_string *tmp = zend_string_init("_bad_state_ex", sizeof("_bad_state_ex") - 1, 0);
+ func = zend_get_std_object_handlers()->get_method(object, tmp, NULL);
+ zend_string_release(tmp);
+ return func;
}
-
- return zend_get_std_object_handlers()->get_method(object_ptr, method, method_len, key TSRMLS_CC);
+
+ return zend_get_std_object_handlers()->get_method(object, method, key);
}
/* }}} */
#define DIT_CTOR_FLAGS 0x00000001
#define DIT_CTOR_GLOB 0x00000002
-void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, long ctor_flags) /* {{{ */
+void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, zend_long ctor_flags) /* {{{ */
{
spl_filesystem_object *intern;
char *path;
- int parsed, len;
- long flags;
+ size_t parsed, len;
+ zend_long flags;
zend_error_handling error_handling;
- zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling);
if (SPL_HAS_FLAG(ctor_flags, DIT_CTOR_FLAGS)) {
flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO;
- parsed = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &path, &len, &flags);
+ parsed = zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &path, &len, &flags);
} else {
flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_SELF;
- parsed = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &len);
+ parsed = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &path, &len);
}
if (SPL_HAS_FLAG(ctor_flags, SPL_FILE_DIR_SKIPDOTS)) {
flags |= SPL_FILE_DIR_SKIPDOTS;
@@ -703,38 +696,38 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, long ctor_fla
flags |= SPL_FILE_DIR_UNIXPATHS;
}
if (parsed == FAILURE) {
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_restore_error_handling(&error_handling);
return;
}
if (!len) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Directory name must not be empty.");
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Directory name must not be empty.");
+ zend_restore_error_handling(&error_handling);
return;
}
- intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern = Z_SPLFILESYSTEM_P(getThis());
if (intern->_path) {
/* object is alreay initialized */
- zend_restore_error_handling(&error_handling TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Directory object is already initialized");
+ zend_restore_error_handling(&error_handling);
+ php_error_docref(NULL, E_WARNING, "Directory object is already initialized");
return;
}
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);
+ spl_filesystem_dir_open(intern, path);
efree(path);
} else
#endif
{
- spl_filesystem_dir_open(intern, path TSRMLS_CC);
+ spl_filesystem_dir_open(intern, path);
}
- intern->u.dir.is_recursive = instanceof_function(intern->std.ce, spl_ce_RecursiveDirectoryIterator TSRMLS_CC) ? 1 : 0;
+ intern->u.dir.is_recursive = instanceof_function(intern->std.ce, spl_ce_RecursiveDirectoryIterator) ? 1 : 0;
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
@@ -750,8 +743,8 @@ SPL_METHOD(DirectoryIterator, __construct)
Rewind dir back to the start */
SPL_METHOD(DirectoryIterator, rewind)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
@@ -760,7 +753,7 @@ SPL_METHOD(DirectoryIterator, rewind)
if (intern->u.dir.dirp) {
php_stream_rewinddir(intern->u.dir.dirp);
}
- spl_filesystem_dir_read(intern TSRMLS_CC);
+ spl_filesystem_dir_read(intern);
}
/* }}} */
@@ -768,8 +761,8 @@ SPL_METHOD(DirectoryIterator, rewind)
Return current dir entry */
SPL_METHOD(DirectoryIterator, key)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
@@ -789,7 +782,8 @@ SPL_METHOD(DirectoryIterator, current)
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- RETURN_ZVAL(getThis(), 1, 0);
+ ZVAL_OBJ(return_value, Z_OBJ_P(getThis()));
+ Z_ADDREF_P(return_value);
}
/* }}} */
@@ -797,16 +791,16 @@ SPL_METHOD(DirectoryIterator, current)
Move to next entry */
SPL_METHOD(DirectoryIterator, next)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
int skip_dots = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_SKIPDOTS);
-
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
intern->u.dir.index++;
do {
- spl_filesystem_dir_read(intern TSRMLS_CC);
+ spl_filesystem_dir_read(intern);
} while (skip_dots && spl_filesystem_is_dot(intern->u.dir.entry.d_name));
if (intern->file_name) {
efree(intern->file_name);
@@ -819,39 +813,31 @@ SPL_METHOD(DirectoryIterator, next)
Seek to the given position */
SPL_METHOD(DirectoryIterator, seek)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *retval = NULL;
- long pos;
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+ zval retval;
+ zend_long pos;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &pos) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &pos) == FAILURE) {
return;
}
if (intern->u.dir.index > pos) {
/* we first rewind */
- zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), &intern->u.dir.func_rewind, "rewind", &retval);
- if (retval) {
- zval_ptr_dtor(&retval);
- retval = NULL;
- }
+ zend_call_method_with_0_params(&EX(This), Z_OBJCE(EX(This)), &intern->u.dir.func_rewind, "rewind", NULL);
}
while (intern->u.dir.index < pos) {
int valid = 0;
- zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), &intern->u.dir.func_valid, "valid", &retval);
- if (retval) {
- valid = zend_is_true(retval);
+ zend_call_method_with_0_params(&EX(This), Z_OBJCE(EX(This)), &intern->u.dir.func_valid, "valid", &retval);
+ if (!Z_ISUNDEF(retval)) {
+ valid = zend_is_true(&retval);
zval_ptr_dtor(&retval);
- retval = NULL;
}
if (!valid) {
zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Seek position %ld is out of range", pos);
return;
}
- zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), &intern->u.dir.func_next, "next", &retval);
- if (retval) {
- zval_ptr_dtor(&retval);
- }
+ zend_call_method_with_0_params(&EX(This), Z_OBJCE(EX(This)), &intern->u.dir.func_next, "next", NULL);
}
} /* }}} */
@@ -859,8 +845,8 @@ SPL_METHOD(DirectoryIterator, seek)
Check whether dir contains more entries */
SPL_METHOD(DirectoryIterator, valid)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
@@ -873,16 +859,16 @@ SPL_METHOD(DirectoryIterator, valid)
Return the path */
SPL_METHOD(SplFileInfo, getPath)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char *path;
- int path_len;
-
+ size_t path_len;
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- path = spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC);
- RETURN_STRINGL(path, path_len, 1);
+ path = spl_filesystem_object_get_path(intern, &path_len);
+ RETURN_STRINGL(path, path_len);
}
/* }}} */
@@ -890,19 +876,19 @@ SPL_METHOD(SplFileInfo, getPath)
Return filename only */
SPL_METHOD(SplFileInfo, getFilename)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- int path_len;
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+ size_t path_len;
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC);
-
+ spl_filesystem_object_get_path(intern, &path_len);
+
if (path_len && path_len < intern->file_name_len) {
- RETURN_STRINGL(intern->file_name + path_len + 1, intern->file_name_len - (path_len + 1), 1);
+ RETURN_STRINGL(intern->file_name + path_len + 1, intern->file_name_len - (path_len + 1));
} else {
- RETURN_STRINGL(intern->file_name, intern->file_name_len, 1);
+ RETURN_STRINGL(intern->file_name, intern->file_name_len);
}
}
/* }}} */
@@ -911,13 +897,13 @@ SPL_METHOD(SplFileInfo, getFilename)
Return filename of current dir entry */
SPL_METHOD(DirectoryIterator, getFilename)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- RETURN_STRING(intern->u.dir.entry.d_name, 1);
+ RETURN_STRING(intern->u.dir.entry.d_name);
}
/* }}} */
@@ -925,17 +911,19 @@ SPL_METHOD(DirectoryIterator, getFilename)
Returns file extension component of path */
SPL_METHOD(SplFileInfo, getExtension)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char *fname = NULL;
const char *p;
size_t flen;
- int path_len, idx;
+ size_t path_len;
+ int idx;
+ zend_string *ret;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC);
+ spl_filesystem_object_get_path(intern, &path_len);
if (path_len && path_len < intern->file_name_len) {
fname = intern->file_name + path_len + 1;
@@ -945,18 +933,16 @@ SPL_METHOD(SplFileInfo, getExtension)
flen = intern->file_name_len;
}
- php_basename(fname, flen, NULL, 0, &fname, &flen TSRMLS_CC);
+ ret = php_basename(fname, flen, NULL, 0);
- p = zend_memrchr(fname, '.', flen);
+ p = zend_memrchr(ZSTR_VAL(ret), '.', ZSTR_LEN(ret));
if (p) {
- idx = p - fname;
- RETVAL_STRINGL(fname + idx + 1, flen - idx - 1, 1);
- efree(fname);
+ idx = (int)(p - ZSTR_VAL(ret));
+ RETVAL_STRINGL(ZSTR_VAL(ret) + idx + 1, ZSTR_LEN(ret) - idx - 1);
+ zend_string_release(ret);
return;
} else {
- if (fname) {
- efree(fname);
- }
+ zend_string_release(ret);
RETURN_EMPTY_STRING();
}
}
@@ -966,47 +952,43 @@ SPL_METHOD(SplFileInfo, getExtension)
Returns the file extension component of path */
SPL_METHOD(DirectoryIterator, getExtension)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- char *fname = NULL;
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
const char *p;
- size_t flen;
int idx;
+ zend_string *fname;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- php_basename(intern->u.dir.entry.d_name, strlen(intern->u.dir.entry.d_name), NULL, 0, &fname, &flen TSRMLS_CC);
+ fname = php_basename(intern->u.dir.entry.d_name, strlen(intern->u.dir.entry.d_name), NULL, 0);
- p = zend_memrchr(fname, '.', flen);
+ p = zend_memrchr(ZSTR_VAL(fname), '.', ZSTR_LEN(fname));
if (p) {
- idx = p - fname;
- RETVAL_STRINGL(fname + idx + 1, flen - idx - 1, 1);
- efree(fname);
- return;
+ idx = (int)(p - ZSTR_VAL(fname));
+ RETVAL_STRINGL(ZSTR_VAL(fname) + idx + 1, ZSTR_LEN(fname) - idx - 1);
+ zend_string_release(fname);
} else {
- if (fname) {
- efree(fname);
- }
+ zend_string_release(fname);
RETURN_EMPTY_STRING();
}
}
/* }}} */
-/* {{{ proto string SplFileInfo::getBasename([string $suffix]) U
+/* {{{ proto string SplFileInfo::getBasename([string $suffix])
Returns filename component of path */
SPL_METHOD(SplFileInfo, getBasename)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char *fname, *suffix = 0;
size_t flen;
- int slen = 0, path_len;
+ size_t slen = 0, path_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &suffix, &slen) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &suffix, &slen) == FAILURE) {
return;
}
- spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC);
+ spl_filesystem_object_get_path(intern, &path_len);
if (path_len && path_len < intern->file_name_len) {
fname = intern->file_name + path_len + 1;
@@ -1016,28 +998,26 @@ SPL_METHOD(SplFileInfo, getBasename)
flen = intern->file_name_len;
}
- php_basename(fname, flen, suffix, slen, &fname, &flen TSRMLS_CC);
-
- RETURN_STRINGL(fname, flen, 0);
+ RETURN_STR(php_basename(fname, flen, suffix, slen));
}
-/* }}}*/
+/* }}}*/
-/* {{{ proto string DirectoryIterator::getBasename([string $suffix]) U
+/* {{{ proto string DirectoryIterator::getBasename([string $suffix])
Returns filename component of current dir entry */
SPL_METHOD(DirectoryIterator, getBasename)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- char *suffix = 0, *fname;
- int slen = 0;
- size_t flen;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &suffix, &slen) == FAILURE) {
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+ char *suffix = 0;
+ size_t slen = 0;
+ zend_string *fname;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &suffix, &slen) == FAILURE) {
return;
}
- php_basename(intern->u.dir.entry.d_name, strlen(intern->u.dir.entry.d_name), suffix, slen, &fname, &flen TSRMLS_CC);
+ fname = php_basename(intern->u.dir.entry.d_name, strlen(intern->u.dir.entry.d_name), suffix, slen);
- RETURN_STRINGL(fname, flen, 0);
+ RETVAL_STR(fname);
}
/* }}} */
@@ -1045,16 +1025,16 @@ SPL_METHOD(DirectoryIterator, getBasename)
Return path and filename */
SPL_METHOD(SplFileInfo, getPathname)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char *path;
- int path_len;
+ size_t path_len;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC);
+ path = spl_filesystem_object_get_pathname(intern, &path_len);
if (path != NULL) {
- RETURN_STRINGL(path, path_len, 1);
+ RETURN_STRINGL(path, path_len);
} else {
RETURN_FALSE;
}
@@ -1065,17 +1045,17 @@ SPL_METHOD(SplFileInfo, getPathname)
Return getPathname() or getFilename() depending on flags */
SPL_METHOD(FilesystemIterator, key)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (SPL_FILE_DIR_KEY(intern, SPL_FILE_DIR_KEY_AS_FILENAME)) {
- RETURN_STRING(intern->u.dir.entry.d_name, 1);
+ RETURN_STRING(intern->u.dir.entry.d_name);
} else {
- spl_filesystem_object_get_file_name(intern TSRMLS_CC);
- RETURN_STRINGL(intern->file_name, intern->file_name_len, 1);
+ spl_filesystem_object_get_file_name(intern);
+ RETURN_STRINGL(intern->file_name, intern->file_name_len);
}
}
/* }}} */
@@ -1084,20 +1064,21 @@ SPL_METHOD(FilesystemIterator, key)
Return getFilename(), getFileInfo() or $this depending on flags */
SPL_METHOD(FilesystemIterator, current)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (SPL_FILE_DIR_CURRENT(intern, SPL_FILE_DIR_CURRENT_AS_PATHNAME)) {
- spl_filesystem_object_get_file_name(intern TSRMLS_CC);
- RETURN_STRINGL(intern->file_name, intern->file_name_len, 1);
+ spl_filesystem_object_get_file_name(intern);
+ RETURN_STRINGL(intern->file_name, intern->file_name_len);
} else if (SPL_FILE_DIR_CURRENT(intern, SPL_FILE_DIR_CURRENT_AS_FILEINFO)) {
- spl_filesystem_object_get_file_name(intern TSRMLS_CC);
- spl_filesystem_object_create_type(0, intern, SPL_FS_INFO, NULL, return_value TSRMLS_CC);
+ spl_filesystem_object_get_file_name(intern);
+ spl_filesystem_object_create_type(0, intern, SPL_FS_INFO, NULL, return_value);
} else {
- RETURN_ZVAL(getThis(), 1, 0);
+ ZVAL_OBJ(return_value, Z_OBJ_P(getThis()));
+ Z_ADDREF_P(return_value);
/*RETURN_STRING(intern->u.dir.entry.d_name, 1);*/
}
}
@@ -1107,8 +1088,8 @@ SPL_METHOD(FilesystemIterator, current)
Returns true if current entry is '.' or '..' */
SPL_METHOD(DirectoryIterator, isDot)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
@@ -1119,33 +1100,23 @@ SPL_METHOD(DirectoryIterator, isDot)
/* {{{ proto void SplFileInfo::__construct(string file_name)
Cronstructs a new SplFileInfo from a path. */
-/* zend_replace_error_handling() is used to throw exceptions in case
- the constructor fails. Here we use this to ensure the object
- has a valid directory resource.
-
- When the constructor gets called the object is already created
+/* When the constructor gets called the object is already created
by the engine, so we must only call 'additional' initializations.
*/
SPL_METHOD(SplFileInfo, __construct)
{
spl_filesystem_object *intern;
char *path;
- int len;
- zend_error_handling error_handling;
+ size_t len;
- zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &len) == FAILURE) {
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &path, &len) == FAILURE) {
return;
}
- intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
- spl_filesystem_info_set_filename(intern, path, len, 1 TSRMLS_CC);
+ intern = Z_SPLFILESYSTEM_P(getThis());
+
+ spl_filesystem_info_set_filename(intern, path, len, 1);
- zend_restore_error_handling(&error_handling TSRMLS_CC);
-
/* intern->type = SPL_FS_INFO; already set */
}
/* }}} */
@@ -1154,16 +1125,16 @@ SPL_METHOD(SplFileInfo, __construct)
#define FileInfoFunction(func_name, func_num) \
SPL_METHOD(SplFileInfo, func_name) \
{ \
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); \
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis()); \
zend_error_handling error_handling; \
if (zend_parse_parameters_none() == FAILURE) { \
return; \
} \
\
- zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);\
- spl_filesystem_object_get_file_name(intern TSRMLS_CC); \
- php_stat(intern->file_name, intern->file_name_len, func_num, return_value TSRMLS_CC); \
- zend_restore_error_handling(&error_handling TSRMLS_CC); \
+ zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);\
+ spl_filesystem_object_get_file_name(intern); \
+ php_stat(intern->file_name, intern->file_name_len, func_num, return_value); \
+ zend_restore_error_handling(&error_handling); \
}
/* }}} */
@@ -1242,29 +1213,29 @@ FileInfoFunction(isDir, FS_IS_DIR)
FileInfoFunction(isLink, FS_IS_LINK)
/* }}} */
-/* {{{ proto string SplFileInfo::getLinkTarget() U
+/* {{{ proto string SplFileInfo::getLinkTarget()
Return the target of a symbolic link */
SPL_METHOD(SplFileInfo, getLinkTarget)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
int ret;
char buff[MAXPATHLEN];
zend_error_handling error_handling;
-
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
#if defined(PHP_WIN32) || HAVE_SYMLINK
if (intern->file_name == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty filename");
+ php_error_docref(NULL, E_WARNING, "Empty filename");
RETURN_FALSE;
} else if (!IS_ABSOLUTE_PATH(intern->file_name, intern->file_name_len)) {
char expanded_path[MAXPATHLEN];
- if (!expand_filepath_with_mode(intern->file_name, expanded_path, NULL, 0, CWD_EXPAND TSRMLS_CC)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory");
+ if (!expand_filepath_with_mode(intern->file_name, expanded_path, NULL, 0, CWD_EXPAND )) {
+ php_error_docref(NULL, E_WARNING, "No such file or directory");
RETURN_FALSE;
}
ret = php_sys_readlink(expanded_path, buff, MAXPATHLEN - 1);
@@ -1276,16 +1247,16 @@ SPL_METHOD(SplFileInfo, getLinkTarget)
#endif
if (ret == -1) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Unable to read link %s, error: %s", intern->file_name, strerror(errno));
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Unable to read link %s, error: %s", intern->file_name, strerror(errno));
RETVAL_FALSE;
} else {
/* Append NULL to the end of the string */
buff[ret] = '\0';
- RETVAL_STRINGL(buff, ret, 1);
+ RETVAL_STRINGL(buff, ret);
}
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
@@ -1294,24 +1265,24 @@ SPL_METHOD(SplFileInfo, getLinkTarget)
Return the resolved path */
SPL_METHOD(SplFileInfo, getRealPath)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char buff[MAXPATHLEN];
char *filename;
zend_error_handling error_handling;
-
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
if (intern->type == SPL_FS_DIR && !intern->file_name && intern->u.dir.entry.d_name[0]) {
- spl_filesystem_object_get_file_name(intern TSRMLS_CC);
+ spl_filesystem_object_get_file_name(intern);
}
-
+
if (intern->orig_path) {
filename = intern->orig_path;
- } else {
+ } else {
filename = intern->file_name;
}
@@ -1322,12 +1293,12 @@ SPL_METHOD(SplFileInfo, getRealPath)
RETVAL_FALSE;
} else
#endif
- RETVAL_STRING(buff, 1);
+ RETVAL_STRING(buff);
} else {
RETVAL_FALSE;
}
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
#endif
@@ -1336,9 +1307,9 @@ SPL_METHOD(SplFileInfo, getRealPath)
Open the current file */
SPL_METHOD(SplFileInfo, openFile)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
- spl_filesystem_object_create_type(ht, intern, SPL_FS_FILE, NULL, return_value TSRMLS_CC);
+ spl_filesystem_object_create_type(ZEND_NUM_ARGS(), intern, SPL_FS_FILE, NULL, return_value);
}
/* }}} */
@@ -1346,17 +1317,17 @@ SPL_METHOD(SplFileInfo, openFile)
Class to use in openFile() */
SPL_METHOD(SplFileInfo, setFileClass)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
zend_class_entry *ce = spl_ce_SplFileObject;
zend_error_handling error_handling;
-
- zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) {
+ zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|C", &ce) == SUCCESS) {
intern->file_class = ce;
}
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
@@ -1364,17 +1335,17 @@ SPL_METHOD(SplFileInfo, setFileClass)
Class to use in getFileInfo(), getPathInfo() */
SPL_METHOD(SplFileInfo, setInfoClass)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
zend_class_entry *ce = spl_ce_SplFileInfo;
zend_error_handling error_handling;
-
- zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) {
+ zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling );
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|C", &ce) == SUCCESS) {
intern->info_class = ce;
}
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
@@ -1382,17 +1353,17 @@ SPL_METHOD(SplFileInfo, setInfoClass)
Get/copy file info */
SPL_METHOD(SplFileInfo, getFileInfo)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
zend_class_entry *ce = intern->info_class;
zend_error_handling error_handling;
-
- zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) {
- spl_filesystem_object_create_type(ht, intern, SPL_FS_INFO, ce, return_value TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|C", &ce) == SUCCESS) {
+ spl_filesystem_object_create_type(ZEND_NUM_ARGS(), intern, SPL_FS_INFO, ce, return_value);
}
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
@@ -1400,31 +1371,31 @@ SPL_METHOD(SplFileInfo, getFileInfo)
Get/copy file info */
SPL_METHOD(SplFileInfo, getPathInfo)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
zend_class_entry *ce = intern->info_class;
zend_error_handling error_handling;
-
- zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling TSRMLS_CC);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) {
- int path_len;
- char *path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|C", &ce) == SUCCESS) {
+ size_t path_len;
+ char *path = spl_filesystem_object_get_pathname(intern, &path_len);
if (path) {
char *dpath = estrndup(path, path_len);
path_len = php_dirname(dpath, path_len);
- spl_filesystem_object_create_info(intern, dpath, path_len, 1, ce, return_value TSRMLS_CC);
+ spl_filesystem_object_create_info(intern, dpath, (int)path_len, 1, ce, return_value);
efree(dpath);
}
}
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
-/* {{{ */
+/* {{{ proto SplFileInfo::_bad_state_ex(void) */
SPL_METHOD(SplFileInfo, _bad_state_ex)
{
- zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC,
+ zend_throw_exception_ex(spl_ce_LogicException, 0,
"The parent constructor was not called: the object is in an "
"invalid state ");
}
@@ -1442,7 +1413,7 @@ SPL_METHOD(FilesystemIterator, __construct)
Rewind dir back to the start */
SPL_METHOD(FilesystemIterator, rewind)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
int skip_dots = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_SKIPDOTS);
if (zend_parse_parameters_none() == FAILURE) {
@@ -1454,7 +1425,7 @@ SPL_METHOD(FilesystemIterator, rewind)
php_stream_rewinddir(intern->u.dir.dirp);
}
do {
- spl_filesystem_dir_read(intern TSRMLS_CC);
+ spl_filesystem_dir_read(intern);
} while (skip_dots && spl_filesystem_is_dot(intern->u.dir.entry.d_name));
}
/* }}} */
@@ -1463,8 +1434,8 @@ SPL_METHOD(FilesystemIterator, rewind)
Get handling flags */
SPL_METHOD(FilesystemIterator, getFlags)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
@@ -1476,10 +1447,10 @@ SPL_METHOD(FilesystemIterator, getFlags)
Set handling flags */
SPL_METHOD(FilesystemIterator, setFlags)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- long flags;
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+ zend_long flags;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flags) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &flags) == FAILURE) {
return;
}
@@ -1492,22 +1463,22 @@ SPL_METHOD(FilesystemIterator, setFlags)
SPL_METHOD(RecursiveDirectoryIterator, hasChildren)
{
zend_bool allow_links = 0;
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &allow_links) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &allow_links) == FAILURE) {
return;
}
if (spl_filesystem_is_invalid_or_dot(intern->u.dir.entry.d_name)) {
RETURN_FALSE;
} else {
- spl_filesystem_object_get_file_name(intern TSRMLS_CC);
+ spl_filesystem_object_get_file_name(intern);
if (!allow_links && !(intern->flags & SPL_FILE_DIR_FOLLOW_SYMLINKS)) {
- php_stat(intern->file_name, intern->file_name_len, FS_IS_LINK, return_value TSRMLS_CC);
+ php_stat(intern->file_name, intern->file_name_len, FS_IS_LINK, return_value);
if (zend_is_true(return_value)) {
RETURN_FALSE;
}
}
- php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, return_value TSRMLS_CC);
+ php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, return_value);
}
}
/* }}} */
@@ -1516,31 +1487,29 @@ SPL_METHOD(RecursiveDirectoryIterator, hasChildren)
Returns an iterator for the current entry if it is a directory */
SPL_METHOD(RecursiveDirectoryIterator, getChildren)
{
- zval *zpath, *zflags;
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ zval zpath, zflags;
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
spl_filesystem_object *subdir;
char slash = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_UNIXPATHS) ? '/' : DEFAULT_SLASH;
-
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
-
- spl_filesystem_object_get_file_name(intern TSRMLS_CC);
- MAKE_STD_ZVAL(zflags);
- MAKE_STD_ZVAL(zpath);
- ZVAL_LONG(zflags, intern->flags);
- ZVAL_STRINGL(zpath, intern->file_name, intern->file_name_len, 1);
- spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), &return_value, 0, zpath, zflags TSRMLS_CC);
+ spl_filesystem_object_get_file_name(intern);
+
+ ZVAL_LONG(&zflags, intern->flags);
+ ZVAL_STRINGL(&zpath, intern->file_name, intern->file_name_len);
+ spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), return_value, &zpath, &zflags);
zval_ptr_dtor(&zpath);
zval_ptr_dtor(&zflags);
- subdir = (spl_filesystem_object*)zend_object_store_get_object(return_value TSRMLS_CC);
+ subdir = Z_SPLFILESYSTEM_P(return_value);
if (subdir) {
if (intern->u.dir.sub_path && intern->u.dir.sub_path[0]) {
- subdir->u.dir.sub_path_len = spprintf(&subdir->u.dir.sub_path, 0, "%s%c%s", intern->u.dir.sub_path, slash, intern->u.dir.entry.d_name);
+ subdir->u.dir.sub_path_len = (int)spprintf(&subdir->u.dir.sub_path, 0, "%s%c%s", intern->u.dir.sub_path, slash, intern->u.dir.entry.d_name);
} else {
- subdir->u.dir.sub_path_len = strlen(intern->u.dir.entry.d_name);
+ subdir->u.dir.sub_path_len = (int)strlen(intern->u.dir.entry.d_name);
subdir->u.dir.sub_path = estrndup(intern->u.dir.entry.d_name, subdir->u.dir.sub_path_len);
}
subdir->info_class = intern->info_class;
@@ -1554,16 +1523,16 @@ SPL_METHOD(RecursiveDirectoryIterator, getChildren)
Get sub path */
SPL_METHOD(RecursiveDirectoryIterator, getSubPath)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (intern->u.dir.sub_path) {
- RETURN_STRINGL(intern->u.dir.sub_path, intern->u.dir.sub_path_len, 1);
+ RETURN_STRINGL(intern->u.dir.sub_path, intern->u.dir.sub_path_len);
} else {
- RETURN_STRINGL("", 0, 1);
+ RETURN_EMPTY_STRING();
}
}
/* }}} */
@@ -1572,20 +1541,17 @@ SPL_METHOD(RecursiveDirectoryIterator, getSubPath)
Get sub path and file name */
SPL_METHOD(RecursiveDirectoryIterator, getSubPathname)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- char *sub_name;
- int len;
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char slash = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_UNIXPATHS) ? '/' : DEFAULT_SLASH;
-
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (intern->u.dir.sub_path) {
- len = spprintf(&sub_name, 0, "%s%c%s", intern->u.dir.sub_path, slash, intern->u.dir.entry.d_name);
- RETURN_STRINGL(sub_name, len, 0);
+ RETURN_NEW_STR(strpprintf(0, "%s%c%s", intern->u.dir.sub_path, slash, intern->u.dir.entry.d_name));
} else {
- RETURN_STRING(intern->u.dir.entry.d_name, 1);
+ RETURN_STRING(intern->u.dir.entry.d_name);
}
}
/* }}} */
@@ -1611,8 +1577,8 @@ SPL_METHOD(GlobIterator, __construct)
Return the number of directories and files found by globbing */
SPL_METHOD(GlobIterator, count)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
@@ -1621,19 +1587,19 @@ SPL_METHOD(GlobIterator, count)
RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL));
} else {
/* should not happen */
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "GlobIterator lost glob state");
+ php_error_docref(NULL, E_ERROR, "GlobIterator lost glob state");
}
}
/* }}} */
#endif /* HAVE_GLOB */
/* {{{ forward declarations to the iterator handlers */
-static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC);
-static int spl_filesystem_dir_it_valid(zend_object_iterator *iter TSRMLS_DC);
-static void spl_filesystem_dir_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC);
-static void spl_filesystem_dir_it_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC);
-static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter TSRMLS_DC);
-static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter TSRMLS_DC);
+static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter);
+static int spl_filesystem_dir_it_valid(zend_object_iterator *iter);
+static zval *spl_filesystem_dir_it_current_data(zend_object_iterator *iter);
+static void spl_filesystem_dir_it_current_key(zend_object_iterator *iter, zval *key);
+static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter);
+static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter);
/* iterator handler table */
zend_object_iterator_funcs spl_filesystem_dir_it_funcs = {
@@ -1647,50 +1613,44 @@ zend_object_iterator_funcs spl_filesystem_dir_it_funcs = {
/* }}} */
/* {{{ spl_ce_dir_get_iterator */
-zend_object_iterator *spl_filesystem_dir_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC)
+zend_object_iterator *spl_filesystem_dir_get_iterator(zend_class_entry *ce, zval *object, int by_ref)
{
spl_filesystem_iterator *iterator;
- spl_filesystem_object *dir_object;
+ spl_filesystem_object *dir_object;
if (by_ref) {
zend_error(E_ERROR, "An iterator cannot be used with foreach by reference");
}
- dir_object = (spl_filesystem_object*)zend_object_store_get_object(object TSRMLS_CC);
- iterator = spl_filesystem_object_to_iterator(dir_object);
+ dir_object = Z_SPLFILESYSTEM_P(object);
+ iterator = spl_filesystem_object_to_iterator(dir_object);
+ ZVAL_COPY(&iterator->intern.data, object);
+ iterator->intern.funcs = &spl_filesystem_dir_it_funcs;
+ /* ->current must be initialized; rewind doesn't set it and valid
+ * doesn't check whether it's set */
+ iterator->current = *object;
- /* initialize iterator if it wasn't gotten before */
- if (iterator->intern.data == NULL) {
- iterator->intern.data = object;
- iterator->intern.funcs = &spl_filesystem_dir_it_funcs;
- /* ->current must be initialized; rewind doesn't set it and valid
- * doesn't check whether it's set */
- iterator->current = object;
- }
- zval_add_ref(&object);
-
- return (zend_object_iterator*)iterator;
+ return &iterator->intern;
}
/* }}} */
/* {{{ spl_filesystem_dir_it_dtor */
-static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC)
+static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter)
{
spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
- if (iterator->intern.data) {
- zval *object = iterator->intern.data;
- zval_ptr_dtor(&object);
+ if (!Z_ISUNDEF(iterator->intern.data)) {
+ zval *object = &iterator->intern.data;
+ zval_ptr_dtor(object);
}
/* Otherwise we were called from the owning object free storage handler as
- * it sets
- * iterator->intern.data to NULL.
+ * it sets iterator->intern.data to IS_UNDEF.
* We don't even need to destroy iterator->current as we didn't add a
* reference to it in move_forward or get_iterator */
}
/* }}} */
/* {{{ spl_filesystem_dir_it_valid */
-static int spl_filesystem_dir_it_valid(zend_object_iterator *iter TSRMLS_DC)
+static int spl_filesystem_dir_it_valid(zend_object_iterator *iter)
{
spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);
@@ -1699,16 +1659,16 @@ static int spl_filesystem_dir_it_valid(zend_object_iterator *iter TSRMLS_DC)
/* }}} */
/* {{{ spl_filesystem_dir_it_current_data */
-static void spl_filesystem_dir_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC)
+static zval *spl_filesystem_dir_it_current_data(zend_object_iterator *iter)
{
spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
-
- *data = &iterator->current;
+
+ return &iterator->current;
}
/* }}} */
/* {{{ spl_filesystem_dir_it_current_key */
-static void spl_filesystem_dir_it_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC)
+static void spl_filesystem_dir_it_current_key(zend_object_iterator *iter, zval *key)
{
spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);
@@ -1717,12 +1677,12 @@ static void spl_filesystem_dir_it_current_key(zend_object_iterator *iter, zval *
/* }}} */
/* {{{ spl_filesystem_dir_it_move_forward */
-static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter TSRMLS_DC)
+static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter)
{
spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);
-
+
object->u.dir.index++;
- spl_filesystem_dir_read(object TSRMLS_CC);
+ spl_filesystem_dir_read(object);
if (object->file_name) {
efree(object->file_name);
object->file_name = NULL;
@@ -1731,111 +1691,110 @@ static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter TSRMLS
/* }}} */
/* {{{ spl_filesystem_dir_it_rewind */
-static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter TSRMLS_DC)
+static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter)
{
spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);
-
+
object->u.dir.index = 0;
if (object->u.dir.dirp) {
php_stream_rewinddir(object->u.dir.dirp);
}
- spl_filesystem_dir_read(object TSRMLS_CC);
+ spl_filesystem_dir_read(object);
}
/* }}} */
/* {{{ spl_filesystem_tree_it_dtor */
-static void spl_filesystem_tree_it_dtor(zend_object_iterator *iter TSRMLS_DC)
+static void spl_filesystem_tree_it_dtor(zend_object_iterator *iter)
{
spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
- if (iterator->intern.data) {
- zval *object = iterator->intern.data;
- zval_ptr_dtor(&object);
+ if (!Z_ISUNDEF(iterator->intern.data)) {
+ zval *object = &iterator->intern.data;
+ zval_ptr_dtor(object);
} else {
- if (iterator->current) {
+ if (!Z_ISUNDEF(iterator->current)) {
zval_ptr_dtor(&iterator->current);
+ ZVAL_UNDEF(&iterator->current);
}
}
}
/* }}} */
/* {{{ spl_filesystem_tree_it_current_data */
-static void spl_filesystem_tree_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC)
+static zval *spl_filesystem_tree_it_current_data(zend_object_iterator *iter)
{
spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
spl_filesystem_object *object = spl_filesystem_iterator_to_object(iterator);
if (SPL_FILE_DIR_CURRENT(object, SPL_FILE_DIR_CURRENT_AS_PATHNAME)) {
- if (!iterator->current) {
- ALLOC_INIT_ZVAL(iterator->current);
- spl_filesystem_object_get_file_name(object TSRMLS_CC);
- ZVAL_STRINGL(iterator->current, object->file_name, object->file_name_len, 1);
+ if (Z_ISUNDEF(iterator->current)) {
+ spl_filesystem_object_get_file_name(object);
+ ZVAL_STRINGL(&iterator->current, object->file_name, object->file_name_len);
}
- *data = &iterator->current;
+ return &iterator->current;
} else if (SPL_FILE_DIR_CURRENT(object, SPL_FILE_DIR_CURRENT_AS_FILEINFO)) {
- if (!iterator->current) {
- ALLOC_INIT_ZVAL(iterator->current);
- spl_filesystem_object_get_file_name(object TSRMLS_CC);
- spl_filesystem_object_create_type(0, object, SPL_FS_INFO, NULL, iterator->current TSRMLS_CC);
+ if (Z_ISUNDEF(iterator->current)) {
+ spl_filesystem_object_get_file_name(object);
+ spl_filesystem_object_create_type(0, object, SPL_FS_INFO, NULL, &iterator->current);
}
- *data = &iterator->current;
+ return &iterator->current;
} else {
- *data = (zval**)&iterator->intern.data;
+ return &iterator->intern.data;
}
}
/* }}} */
/* {{{ spl_filesystem_tree_it_current_key */
-static void spl_filesystem_tree_it_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC)
+static void spl_filesystem_tree_it_current_key(zend_object_iterator *iter, zval *key)
{
spl_filesystem_object *object = spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);
if (SPL_FILE_DIR_KEY(object, SPL_FILE_DIR_KEY_AS_FILENAME)) {
- ZVAL_STRING(key, object->u.dir.entry.d_name, 1);
+ ZVAL_STRING(key, object->u.dir.entry.d_name);
} else {
- spl_filesystem_object_get_file_name(object TSRMLS_CC);
- ZVAL_STRINGL(key, object->file_name, object->file_name_len, 1);
+ spl_filesystem_object_get_file_name(object);
+ ZVAL_STRINGL(key, object->file_name, object->file_name_len);
}
}
/* }}} */
/* {{{ spl_filesystem_tree_it_move_forward */
-static void spl_filesystem_tree_it_move_forward(zend_object_iterator *iter TSRMLS_DC)
+static void spl_filesystem_tree_it_move_forward(zend_object_iterator *iter)
{
spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
spl_filesystem_object *object = spl_filesystem_iterator_to_object(iterator);
-
+
object->u.dir.index++;
do {
- spl_filesystem_dir_read(object TSRMLS_CC);
+ spl_filesystem_dir_read(object);
} while (spl_filesystem_is_dot(object->u.dir.entry.d_name));
if (object->file_name) {
efree(object->file_name);
object->file_name = NULL;
}
- if (iterator->current) {
+ if (!Z_ISUNDEF(iterator->current)) {
zval_ptr_dtor(&iterator->current);
- iterator->current = NULL;
+ ZVAL_UNDEF(&iterator->current);
}
}
/* }}} */
/* {{{ spl_filesystem_tree_it_rewind */
-static void spl_filesystem_tree_it_rewind(zend_object_iterator *iter TSRMLS_DC)
+static void spl_filesystem_tree_it_rewind(zend_object_iterator *iter)
{
spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
spl_filesystem_object *object = spl_filesystem_iterator_to_object(iterator);
-
+
object->u.dir.index = 0;
if (object->u.dir.dirp) {
php_stream_rewinddir(object->u.dir.dirp);
}
do {
- spl_filesystem_dir_read(object TSRMLS_CC);
+ spl_filesystem_dir_read(object);
} while (spl_filesystem_is_dot(object->u.dir.entry.d_name));
- if (iterator->current) {
+ if (!Z_ISUNDEF(iterator->current)) {
zval_ptr_dtor(&iterator->current);
- iterator->current = NULL;
+ ZVAL_UNDEF(&iterator->current);
}
}
/* }}} */
@@ -1852,7 +1811,7 @@ zend_object_iterator_funcs spl_filesystem_tree_it_funcs = {
/* }}} */
/* {{{ spl_ce_dir_get_iterator */
-zend_object_iterator *spl_filesystem_tree_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC)
+zend_object_iterator *spl_filesystem_tree_get_iterator(zend_class_entry *ce, zval *object, int by_ref)
{
spl_filesystem_iterator *iterator;
spl_filesystem_object *dir_object;
@@ -1860,28 +1819,24 @@ zend_object_iterator *spl_filesystem_tree_get_iterator(zend_class_entry *ce, zva
if (by_ref) {
zend_error(E_ERROR, "An iterator cannot be used with foreach by reference");
}
- dir_object = (spl_filesystem_object*)zend_object_store_get_object(object TSRMLS_CC);
- iterator = spl_filesystem_object_to_iterator(dir_object);
+ dir_object = Z_SPLFILESYSTEM_P(object);
+ iterator = spl_filesystem_object_to_iterator(dir_object);
- /* initialize iterator if wasn't gotten before */
- if (iterator->intern.data == NULL) {
- iterator->intern.data = object;
- iterator->intern.funcs = &spl_filesystem_tree_it_funcs;
- }
- zval_add_ref(&object);
-
- return (zend_object_iterator*)iterator;
+ ZVAL_COPY(&iterator->intern.data, object);
+ iterator->intern.funcs = &spl_filesystem_tree_it_funcs;
+
+ return &iterator->intern;
}
/* }}} */
/* {{{ spl_filesystem_object_cast */
-static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC)
+static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(readobj TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(readobj);
if (type == IS_STRING) {
if (Z_OBJCE_P(readobj)->__tostring) {
- return std_object_handlers.cast_object(readobj, writeobj, type TSRMLS_CC);
+ return std_object_handlers.cast_object(readobj, writeobj, type);
}
switch (intern->type) {
@@ -1891,11 +1846,11 @@ static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type TS
zval retval;
zval *retval_ptr = &retval;
- ZVAL_STRINGL(retval_ptr, intern->file_name, intern->file_name_len, 1);
- zval_dtor(readobj);
- ZVAL_ZVAL(writeobj, retval_ptr, 0, 0);
+ ZVAL_STRINGL(retval_ptr, intern->file_name, intern->file_name_len);
+ zval_ptr_dtor(readobj);
+ ZVAL_COPY_VALUE(writeobj, retval_ptr);
} else {
- ZVAL_STRINGL(writeobj, intern->file_name, intern->file_name_len, 1);
+ ZVAL_STRINGL(writeobj, intern->file_name, intern->file_name_len);
}
return SUCCESS;
case SPL_FS_DIR:
@@ -1903,20 +1858,20 @@ static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type TS
zval retval;
zval *retval_ptr = &retval;
- ZVAL_STRING(retval_ptr, intern->u.dir.entry.d_name, 1);
- zval_dtor(readobj);
- ZVAL_ZVAL(writeobj, retval_ptr, 0, 0);
+ ZVAL_STRING(retval_ptr, intern->u.dir.entry.d_name);
+ zval_ptr_dtor(readobj);
+ ZVAL_COPY_VALUE(writeobj, retval_ptr);
} else {
- ZVAL_STRING(writeobj, intern->u.dir.entry.d_name, 1);
+ ZVAL_STRING(writeobj, intern->u.dir.entry.d_name);
}
return SUCCESS;
}
- } else if (type == IS_BOOL) {
- ZVAL_BOOL(writeobj, 1);
+ } else if (type == _IS_BOOL) {
+ ZVAL_TRUE(writeobj);
return SUCCESS;
}
if (readobj == writeobj) {
- zval_dtor(readobj);
+ zval_ptr_dtor(readobj);
}
ZVAL_NULL(writeobj);
return FAILURE;
@@ -1925,7 +1880,7 @@ static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type TS
/* {{{ declare method parameters */
/* supply a name and default to call by parameter */
-ZEND_BEGIN_ARG_INFO(arginfo_info___construct, 0)
+ZEND_BEGIN_ARG_INFO(arginfo_info___construct, 0)
ZEND_ARG_INFO(0, file_name)
ZEND_END_ARG_INFO()
@@ -1984,11 +1939,11 @@ static const zend_function_entry spl_SplFileInfo_functions[] = {
PHP_FE_END
};
-ZEND_BEGIN_ARG_INFO(arginfo_dir___construct, 0)
+ZEND_BEGIN_ARG_INFO(arginfo_dir___construct, 0)
ZEND_ARG_INFO(0, path)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO(arginfo_dir_it_seek, 0)
+ZEND_BEGIN_ARG_INFO(arginfo_dir_it_seek, 0)
ZEND_ARG_INFO(0, position)
ZEND_END_ARG_INFO();
@@ -2010,7 +1965,7 @@ static const zend_function_entry spl_DirectoryIterator_functions[] = {
PHP_FE_END
};
-ZEND_BEGIN_ARG_INFO_EX(arginfo_r_dir___construct, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_r_dir___construct, 0, 0, 1)
ZEND_ARG_INFO(0, path)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
@@ -2052,17 +2007,17 @@ static const zend_function_entry spl_GlobIterator_functions[] = {
#endif
/* }}} */
-static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */
+static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent) /* {{{ */
{
char *buf;
size_t line_len = 0;
- long line_add = (intern->u.file.current_line || intern->u.file.current_zval) ? 1 : 0;
+ zend_long line_add = (intern->u.file.current_line || !Z_ISUNDEF(intern->u.file.current_zval)) ? 1 : 0;
+
+ spl_filesystem_file_free_line(intern);
- spl_filesystem_file_free_line(intern TSRMLS_CC);
-
if (php_stream_eof(intern->u.file.stream)) {
if (!silent) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot read from file %s", intern->file_name);
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot read from file %s", intern->file_name);
}
return FAILURE;
}
@@ -2087,7 +2042,7 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TS
line_len = strcspn(buf, "\r\n");
buf[line_len] = '\0';
}
-
+
intern->u.file.current_line = buf;
intern->u.file.current_line_len = line_len;
}
@@ -2096,49 +2051,51 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TS
return SUCCESS;
} /* }}} */
-static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function *func_ptr, int pass_num_args, zval *return_value, zval *arg2 TSRMLS_DC) /* {{{ */
+static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function *func_ptr, int pass_num_args, zval *return_value, zval *arg2) /* {{{ */
{
zend_fcall_info fci;
zend_fcall_info_cache fcic;
- zval z_fname;
- zval * zresource_ptr = &intern->u.file.zresource, *retval = NULL;
+ zval *zresource_ptr = &intern->u.file.zresource, retval;
int result;
int num_args = pass_num_args + (arg2 ? 2 : 1);
- zval ***params = (zval***)safe_emalloc(num_args, sizeof(zval**), 0);
+ zval *params = (zval*)safe_emalloc(num_args, sizeof(zval), 0);
+
+ params[0] = *zresource_ptr;
- params[0] = &zresource_ptr;
-
if (arg2) {
- params[1] = &arg2;
+ params[1] = *arg2;
}
- zend_get_parameters_array_ex(pass_num_args, params+(arg2 ? 2 : 1));
+ if (zend_get_parameters_array_ex(pass_num_args, params + (arg2 ? 2 : 1)) != SUCCESS) {
+ efree(params);
+ WRONG_PARAM_COUNT_WITH_RETVAL(FAILURE);
+ }
- ZVAL_STRING(&z_fname, func_ptr->common.function_name, 0);
+ ZVAL_UNDEF(&retval);
fci.size = sizeof(fci);
fci.function_table = EG(function_table);
- fci.object_ptr = NULL;
- fci.function_name = &z_fname;
- fci.retval_ptr_ptr = &retval;
+ fci.object = NULL;
+ fci.retval = &retval;
fci.param_count = num_args;
fci.params = params;
fci.no_separation = 1;
fci.symbol_table = NULL;
+ ZVAL_STR(&fci.function_name, func_ptr->common.function_name);
fcic.initialized = 1;
fcic.function_handler = func_ptr;
fcic.calling_scope = NULL;
fcic.called_scope = NULL;
- fcic.object_ptr = NULL;
+ fcic.object = NULL;
- result = zend_call_function(&fci, &fcic TSRMLS_CC);
-
- if (result == FAILURE || retval == NULL) {
+ result = zend_call_function(&fci, &fcic);
+
+ if (result == FAILURE || Z_ISUNDEF(retval)) {
RETVAL_FALSE;
} else {
- ZVAL_ZVAL(return_value, retval, 1, 1);
+ ZVAL_ZVAL(return_value, &retval, 0, 0);
}
efree(params);
@@ -2148,73 +2105,75 @@ static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function
#define FileFunctionCall(func_name, pass_num_args, arg2) /* {{{ */ \
{ \
zend_function *func_ptr; \
- int ret; \
- ret = zend_hash_find(EG(function_table), #func_name, sizeof(#func_name), (void **) &func_ptr); \
- if (ret != SUCCESS) { \
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Internal error, function '%s' not found. Please report", #func_name); \
+ func_ptr = (zend_function *)zend_hash_str_find_ptr(EG(function_table), #func_name, sizeof(#func_name) - 1); \
+ if (func_ptr == NULL) { \
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Internal error, function '%s' not found. Please report", #func_name); \
return; \
} \
- spl_filesystem_file_call(intern, func_ptr, pass_num_args, return_value, arg2 TSRMLS_CC); \
+ spl_filesystem_file_call(intern, func_ptr, pass_num_args, return_value, arg2); \
} /* }}} */
-static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char delimiter, char enclosure, char escape, zval *return_value TSRMLS_DC) /* {{{ */
+static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char delimiter, char enclosure, char escape, zval *return_value) /* {{{ */
{
int ret = SUCCESS;
-
+ zval *value;
+
do {
- ret = spl_filesystem_file_read(intern, 1 TSRMLS_CC);
+ ret = spl_filesystem_file_read(intern, 1);
} while (ret == SUCCESS && !intern->u.file.current_line_len && SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_SKIP_EMPTY));
-
+
if (ret == SUCCESS) {
size_t buf_len = intern->u.file.current_line_len;
char *buf = estrndup(intern->u.file.current_line, buf_len);
- if (intern->u.file.current_zval) {
+ if (!Z_ISUNDEF(intern->u.file.current_zval)) {
zval_ptr_dtor(&intern->u.file.current_zval);
+ ZVAL_UNDEF(&intern->u.file.current_zval);
}
- ALLOC_INIT_ZVAL(intern->u.file.current_zval);
- php_fgetcsv(intern->u.file.stream, delimiter, enclosure, escape, buf_len, buf, intern->u.file.current_zval TSRMLS_CC);
+ php_fgetcsv(intern->u.file.stream, delimiter, enclosure, escape, buf_len, buf, &intern->u.file.current_zval);
if (return_value) {
- if (Z_TYPE_P(return_value) != IS_NULL) {
- zval_dtor(return_value);
- ZVAL_NULL(return_value);
- }
- ZVAL_ZVAL(return_value, intern->u.file.current_zval, 1, 0);
+ zval_ptr_dtor(return_value);
+ value = &intern->u.file.current_zval;
+ ZVAL_DEREF(value);
+ ZVAL_COPY(return_value, value);
}
}
return ret;
}
/* }}} */
-static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */
+static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_object *intern, int silent) /* {{{ */
{
- zval *retval = NULL;
+ zval retval;
/* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV) || intern->u.file.func_getCurr->common.scope != spl_ce_SplFileObject) {
if (php_stream_eof(intern->u.file.stream)) {
if (!silent) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot read from file %s", intern->file_name);
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot read from file %s", intern->file_name);
}
return FAILURE;
}
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV)) {
- return spl_filesystem_file_read_csv(intern, intern->u.file.delimiter, intern->u.file.enclosure, intern->u.file.escape, NULL TSRMLS_CC);
+ return spl_filesystem_file_read_csv(intern, intern->u.file.delimiter, intern->u.file.enclosure, intern->u.file.escape, NULL);
} else {
- zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), &intern->u.file.func_getCurr, "getCurrentLine", &retval);
+ zend_execute_data *execute_data = EG(current_execute_data);
+ zend_call_method_with_0_params(this_ptr, Z_OBJCE(EX(This)), &intern->u.file.func_getCurr, "getCurrentLine", &retval);
}
- if (retval) {
- if (intern->u.file.current_line || intern->u.file.current_zval) {
+ if (!Z_ISUNDEF(retval)) {
+ if (intern->u.file.current_line || !Z_ISUNDEF(intern->u.file.current_zval)) {
intern->u.file.current_line_num++;
}
- spl_filesystem_file_free_line(intern TSRMLS_CC);
- if (Z_TYPE_P(retval) == IS_STRING) {
- intern->u.file.current_line = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
- intern->u.file.current_line_len = Z_STRLEN_P(retval);
+ spl_filesystem_file_free_line(intern);
+ if (Z_TYPE(retval) == IS_STRING) {
+ intern->u.file.current_line = estrndup(Z_STRVAL(retval), Z_STRLEN(retval));
+ intern->u.file.current_line_len = Z_STRLEN(retval);
} else {
- MAKE_STD_ZVAL(intern->u.file.current_zval);
- ZVAL_ZVAL(intern->u.file.current_zval, retval, 1, 0);
+ zval *value = &retval;
+
+ ZVAL_DEREF(value);
+ ZVAL_COPY(&intern->u.file.current_zval, value);
}
zval_ptr_dtor(&retval);
return SUCCESS;
@@ -2222,30 +2181,35 @@ static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_obje
return FAILURE;
}
} else {
- return spl_filesystem_file_read(intern, silent TSRMLS_CC);
+ return spl_filesystem_file_read(intern, silent);
}
} /* }}} */
-static int spl_filesystem_file_is_empty_line(spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
+static int spl_filesystem_file_is_empty_line(spl_filesystem_object *intern) /* {{{ */
{
if (intern->u.file.current_line) {
return intern->u.file.current_line_len == 0;
- } else if (intern->u.file.current_zval) {
- switch(Z_TYPE_P(intern->u.file.current_zval)) {
- case IS_STRING:
- return Z_STRLEN_P(intern->u.file.current_zval) == 0;
- case IS_ARRAY:
- if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV)
- && zend_hash_num_elements(Z_ARRVAL_P(intern->u.file.current_zval)) == 1) {
- zval ** first = Z_ARRVAL_P(intern->u.file.current_zval)->pListHead->pData;
-
- return Z_TYPE_PP(first) == IS_STRING && Z_STRLEN_PP(first) == 0;
- }
- return zend_hash_num_elements(Z_ARRVAL_P(intern->u.file.current_zval)) == 0;
- case IS_NULL:
- return 1;
- default:
- return 0;
+ } else if (!Z_ISUNDEF(intern->u.file.current_zval)) {
+ switch(Z_TYPE(intern->u.file.current_zval)) {
+ case IS_STRING:
+ return Z_STRLEN(intern->u.file.current_zval) == 0;
+ case IS_ARRAY:
+ if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV)
+ && zend_hash_num_elements(Z_ARRVAL(intern->u.file.current_zval)) == 1) {
+ uint idx = 0;
+ zval *first;
+
+ while (Z_ISUNDEF(Z_ARRVAL(intern->u.file.current_zval)->arData[idx].val)) {
+ idx++;
+ }
+ first = &Z_ARRVAL(intern->u.file.current_zval)->arData[idx].val;
+ return Z_TYPE_P(first) == IS_STRING && Z_STRLEN_P(first) == 0;
+ }
+ return zend_hash_num_elements(Z_ARRVAL(intern->u.file.current_zval)) == 0;
+ case IS_NULL:
+ return 1;
+ default:
+ return 0;
}
} else {
return 1;
@@ -2253,33 +2217,33 @@ static int spl_filesystem_file_is_empty_line(spl_filesystem_object *intern TSRML
}
/* }}} */
-static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */
+static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object *intern, int silent) /* {{{ */
{
- int ret = spl_filesystem_file_read_line_ex(this_ptr, intern, silent TSRMLS_CC);
+ int ret = spl_filesystem_file_read_line_ex(this_ptr, intern, silent);
- while (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_SKIP_EMPTY) && ret == SUCCESS && spl_filesystem_file_is_empty_line(intern TSRMLS_CC)) {
- spl_filesystem_file_free_line(intern TSRMLS_CC);
- ret = spl_filesystem_file_read_line_ex(this_ptr, intern, silent TSRMLS_CC);
+ while (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_SKIP_EMPTY) && ret == SUCCESS && spl_filesystem_file_is_empty_line(intern)) {
+ spl_filesystem_file_free_line(intern);
+ ret = spl_filesystem_file_read_line_ex(this_ptr, intern, silent);
}
-
+
return ret;
}
/* }}} */
-static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *intern TSRMLS_DC) /* {{{ */
+static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *intern) /* {{{ */
{
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
if (-1 == php_stream_rewind(intern->u.file.stream)) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot rewind file %s", intern->file_name);
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot rewind file %s", intern->file_name);
} else {
- spl_filesystem_file_free_line(intern TSRMLS_CC);
+ spl_filesystem_file_free_line(intern);
intern->u.file.current_line_num = 0;
}
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
- spl_filesystem_file_read_line(this_ptr, intern, 1 TSRMLS_CC);
+ spl_filesystem_file_read_line(this_ptr, intern, 1);
}
} /* }}} */
@@ -2287,34 +2251,33 @@ static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *i
Construct a new file object */
SPL_METHOD(SplFileObject, __construct)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
zend_bool use_include_path = 0;
char *p1, *p2;
char *tmp_path;
- int tmp_path_len;
+ size_t tmp_path_len;
zend_error_handling error_handling;
- zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
-
intern->u.file.open_mode = NULL;
intern->u.file.open_mode_len = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|sbr!",
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p|sbr!",
&intern->file_name, &intern->file_name_len,
- &intern->u.file.open_mode, &intern->u.file.open_mode_len,
- &use_include_path, &intern->u.file.zcontext) == FAILURE) {
+ &intern->u.file.open_mode, &intern->u.file.open_mode_len,
+ &use_include_path, &intern->u.file.zcontext) == FAILURE) {
intern->u.file.open_mode = NULL;
intern->file_name = NULL;
- zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
-
+
if (intern->u.file.open_mode == NULL) {
intern->u.file.open_mode = "r";
intern->u.file.open_mode_len = 1;
}
- if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == SUCCESS) {
+ zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
+
+ if (spl_filesystem_file_open(intern, use_include_path, 0) == SUCCESS) {
tmp_path_len = strlen(intern->u.file.stream->orig_path);
if (tmp_path_len > 1 && IS_SLASH_AT(intern->u.file.stream->orig_path, tmp_path_len-1)) {
@@ -2330,7 +2293,7 @@ SPL_METHOD(SplFileObject, __construct)
p2 = 0;
#endif
if (p1 || p2) {
- intern->_path_len = (p1 > p2 ? p1 : p2) - tmp_path;
+ intern->_path_len = (int)((p1 > p2 ? p1 : p2) - tmp_path);
} else {
intern->_path_len = 0;
}
@@ -2340,7 +2303,7 @@ SPL_METHOD(SplFileObject, __construct)
intern->_path = estrndup(intern->u.file.stream->orig_path, intern->_path_len);
}
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_restore_error_handling(&error_handling);
} /* }}} */
@@ -2348,15 +2311,12 @@ SPL_METHOD(SplFileObject, __construct)
Construct a new temp file object */
SPL_METHOD(SplTempFileObject, __construct)
{
- long max_memory = PHP_STREAM_MAX_MEM;
+ zend_long max_memory = PHP_STREAM_MAX_MEM;
char tmp_fname[48];
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
zend_error_handling error_handling;
- zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &max_memory) == FAILURE) {
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|l", &max_memory) == FAILURE) {
return;
}
@@ -2364,7 +2324,7 @@ SPL_METHOD(SplTempFileObject, __construct)
intern->file_name = "php://memory";
intern->file_name_len = 12;
} else if (ZEND_NUM_ARGS()) {
- intern->file_name_len = slprintf(tmp_fname, sizeof(tmp_fname), "php://temp/maxmemory:%ld", max_memory);
+ intern->file_name_len = slprintf(tmp_fname, sizeof(tmp_fname), "php://temp/maxmemory:%pd", max_memory);
intern->file_name = tmp_fname;
} else {
intern->file_name = "php://temp";
@@ -2372,40 +2332,40 @@ SPL_METHOD(SplTempFileObject, __construct)
}
intern->u.file.open_mode = "wb";
intern->u.file.open_mode_len = 1;
- intern->u.file.zcontext = NULL;
-
- if (spl_filesystem_file_open(intern, 0, 0 TSRMLS_CC) == SUCCESS) {
+
+ zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
+ if (spl_filesystem_file_open(intern, 0, 0) == SUCCESS) {
intern->_path_len = 0;
intern->_path = estrndup("", 0);
}
- zend_restore_error_handling(&error_handling TSRMLS_CC);
+ zend_restore_error_handling(&error_handling);
} /* }}} */
/* {{{ proto void SplFileObject::rewind()
Rewind the file and read the first line */
SPL_METHOD(SplFileObject, rewind)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- spl_filesystem_file_rewind(getThis(), intern TSRMLS_CC);
+ spl_filesystem_file_rewind(getThis(), intern);
} /* }}} */
/* {{{ proto void SplFileObject::eof()
Return whether end of file is reached */
SPL_METHOD(SplFileObject, eof)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
@@ -2416,14 +2376,14 @@ SPL_METHOD(SplFileObject, eof)
Return !eof() */
SPL_METHOD(SplFileObject, valid)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
- RETURN_BOOL(intern->u.file.current_line || intern->u.file.current_zval);
+ RETURN_BOOL(intern->u.file.current_line || !Z_ISUNDEF(intern->u.file.current_zval));
} else {
if(!intern->u.file.stream) {
RETURN_FALSE;
@@ -2436,45 +2396,49 @@ SPL_METHOD(SplFileObject, valid)
Rturn next line from file */
SPL_METHOD(SplFileObject, fgets)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
- if (spl_filesystem_file_read(intern, 0 TSRMLS_CC) == FAILURE) {
+ if (spl_filesystem_file_read(intern, 0) == FAILURE) {
RETURN_FALSE;
}
- RETURN_STRINGL(intern->u.file.current_line, intern->u.file.current_line_len, 1);
+ RETURN_STRINGL(intern->u.file.current_line, intern->u.file.current_line_len);
} /* }}} */
/* {{{ proto string SplFileObject::current()
Return current line from file */
SPL_METHOD(SplFileObject, current)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
- if (!intern->u.file.current_line && !intern->u.file.current_zval) {
- spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC);
+ if (!intern->u.file.current_line && Z_ISUNDEF(intern->u.file.current_zval)) {
+ spl_filesystem_file_read_line(getThis(), intern, 1);
}
- if (intern->u.file.current_line && (!SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV) || !intern->u.file.current_zval)) {
- RETURN_STRINGL(intern->u.file.current_line, intern->u.file.current_line_len, 1);
- } else if (intern->u.file.current_zval) {
- RETURN_ZVAL(intern->u.file.current_zval, 1, 0);
+ if (intern->u.file.current_line && (!SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV) || Z_ISUNDEF(intern->u.file.current_zval))) {
+ RETURN_STRINGL(intern->u.file.current_line, intern->u.file.current_line_len);
+ } else if (!Z_ISUNDEF(intern->u.file.current_zval)) {
+ zval *value = &intern->u.file.current_zval;
+
+ ZVAL_DEREF(value);
+ ZVAL_COPY(return_value, value);
+ return;
}
RETURN_FALSE;
} /* }}} */
@@ -2483,15 +2447,15 @@ SPL_METHOD(SplFileObject, current)
Return line number */
SPL_METHOD(SplFileObject, key)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
/* Do not read the next line to support correct counting with fgetc()
if (!intern->current_line) {
- spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC);
+ spl_filesystem_file_read_line(getThis(), intern, 1);
} */
RETURN_LONG(intern->u.file.current_line_num);
} /* }}} */
@@ -2500,15 +2464,15 @@ SPL_METHOD(SplFileObject, key)
Read next line */
SPL_METHOD(SplFileObject, next)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- spl_filesystem_file_free_line(intern TSRMLS_CC);
+ spl_filesystem_file_free_line(intern);
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
- spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC);
+ spl_filesystem_file_read_line(getThis(), intern, 1);
}
intern->u.file.current_line_num++;
} /* }}} */
@@ -2517,9 +2481,9 @@ SPL_METHOD(SplFileObject, next)
Set file handling flags */
SPL_METHOD(SplFileObject, setFlags)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &intern->flags) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &intern->flags) == FAILURE) {
return;
}
} /* }}} */
@@ -2528,7 +2492,7 @@ SPL_METHOD(SplFileObject, setFlags)
Get file handling flags */
SPL_METHOD(SplFileObject, getFlags)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
@@ -2541,19 +2505,19 @@ SPL_METHOD(SplFileObject, getFlags)
Set maximum line length */
SPL_METHOD(SplFileObject, setMaxLineLen)
{
- long max_len;
+ zend_long max_len;
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &max_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &max_len) == FAILURE) {
return;
}
if (max_len < 0) {
- zend_throw_exception_ex(spl_ce_DomainException, 0 TSRMLS_CC, "Maximum line length must be greater than or equal zero");
+ zend_throw_exception_ex(spl_ce_DomainException, 0, "Maximum line length must be greater than or equal zero");
return;
}
-
+
intern->u.file.max_line_len = max_len;
} /* }}} */
@@ -2561,13 +2525,13 @@ SPL_METHOD(SplFileObject, setMaxLineLen)
Get maximum line length */
SPL_METHOD(SplFileObject, getMaxLineLen)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- RETURN_LONG((long)intern->u.file.max_line_len);
+ RETURN_LONG((zend_long)intern->u.file.max_line_len);
} /* }}} */
/* {{{ proto bool SplFileObject::hasChildren()
@@ -2577,7 +2541,7 @@ SPL_METHOD(SplFileObject, hasChildren)
if (zend_parse_parameters_none() == FAILURE) {
return;
}
-
+
RETURN_FALSE;
} /* }}} */
@@ -2595,7 +2559,7 @@ SPL_METHOD(SplFileObject, getChildren)
#define FileFunction(func_name) \
SPL_METHOD(SplFileObject, func_name) \
{ \
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); \
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis()); \
FileFunctionCall(func_name, ZEND_NUM_ARGS(), NULL); \
}
/* }}} */
@@ -2604,15 +2568,15 @@ SPL_METHOD(SplFileObject, func_name) \
Return current line as csv */
SPL_METHOD(SplFileObject, fgetcsv)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char delimiter = intern->u.file.delimiter, enclosure = intern->u.file.enclosure, escape = intern->u.file.escape;
char *delim = NULL, *enclo = NULL, *esc = NULL;
- int d_len = 0, e_len = 0, esc_len = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
+ size_t d_len = 0, e_len = 0, esc_len = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
@@ -2620,21 +2584,21 @@ SPL_METHOD(SplFileObject, fgetcsv)
{
case 3:
if (esc_len != 1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "escape must be a character");
+ php_error_docref(NULL, E_WARNING, "escape must be a character");
RETURN_FALSE;
}
escape = esc[0];
/* no break */
case 2:
if (e_len != 1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character");
+ php_error_docref(NULL, E_WARNING, "enclosure must be a character");
RETURN_FALSE;
}
enclosure = enclo[0];
/* no break */
case 1:
if (d_len != 1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character");
+ php_error_docref(NULL, E_WARNING, "delimiter must be a character");
RETURN_FALSE;
}
delimiter = delim[0];
@@ -2642,7 +2606,7 @@ SPL_METHOD(SplFileObject, fgetcsv)
case 0:
break;
}
- spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value TSRMLS_CC);
+ spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value);
}
}
/* }}} */
@@ -2651,32 +2615,33 @@ SPL_METHOD(SplFileObject, fgetcsv)
Output a field array as a CSV line */
SPL_METHOD(SplFileObject, fputcsv)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char delimiter = intern->u.file.delimiter, enclosure = intern->u.file.enclosure, escape = intern->u.file.escape;
char *delim = NULL, *enclo = NULL, *esc = NULL;
- int d_len = 0, e_len = 0, esc_len = 0, ret;
+ size_t d_len = 0, e_len = 0, esc_len = 0;
+ zend_long ret;
zval *fields = NULL;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|sss", &fields, &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|sss", &fields, &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
switch(ZEND_NUM_ARGS())
{
case 4:
if (esc_len != 1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "escape must be a character");
+ php_error_docref(NULL, E_WARNING, "escape must be a character");
RETURN_FALSE;
}
escape = esc[0];
/* no break */
case 3:
if (e_len != 1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character");
+ php_error_docref(NULL, E_WARNING, "enclosure must be a character");
RETURN_FALSE;
}
enclosure = enclo[0];
/* no break */
case 2:
if (d_len != 1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character");
+ php_error_docref(NULL, E_WARNING, "delimiter must be a character");
RETURN_FALSE;
}
delimiter = delim[0];
@@ -2685,41 +2650,41 @@ SPL_METHOD(SplFileObject, fputcsv)
case 0:
break;
}
- ret = php_fputcsv(intern->u.file.stream, fields, delimiter, enclosure, escape TSRMLS_CC);
+ ret = php_fputcsv(intern->u.file.stream, fields, delimiter, enclosure, escape);
RETURN_LONG(ret);
}
}
/* }}} */
-/* {{{ proto void SplFileObject::setCsvControl([string delimiter = ',' [, string enclosure = '"' [, string escape = '\\']]])
+/* {{{ proto void SplFileObject::setCsvControl([string delimiter [, string enclosure [, string escape ]]])
Set the delimiter and enclosure character used in fgetcsv */
SPL_METHOD(SplFileObject, setCsvControl)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char delimiter = ',', enclosure = '"', escape='\\';
char *delim = NULL, *enclo = NULL, *esc = NULL;
- int d_len = 0, e_len = 0, esc_len = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
+ size_t d_len = 0, e_len = 0, esc_len = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
switch(ZEND_NUM_ARGS())
{
case 3:
if (esc_len != 1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "escape must be a character");
+ php_error_docref(NULL, E_WARNING, "escape must be a character");
RETURN_FALSE;
}
escape = esc[0];
/* no break */
case 2:
if (e_len != 1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character");
+ php_error_docref(NULL, E_WARNING, "enclosure must be a character");
RETURN_FALSE;
}
enclosure = enclo[0];
/* no break */
case 1:
if (d_len != 1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character");
+ php_error_docref(NULL, E_WARNING, "delimiter must be a character");
RETURN_FALSE;
}
delimiter = delim[0];
@@ -2738,18 +2703,18 @@ SPL_METHOD(SplFileObject, setCsvControl)
Get the delimiter and enclosure character used in fgetcsv */
SPL_METHOD(SplFileObject, getCsvControl)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char delimiter[2], enclosure[2];
array_init(return_value);
-
+
delimiter[0] = intern->u.file.delimiter;
delimiter[1] = '\0';
enclosure[0] = intern->u.file.enclosure;
enclosure[1] = '\0';
- add_next_index_string(return_value, delimiter, 1);
- add_next_index_string(return_value, enclosure, 1);
+ add_next_index_string(return_value, delimiter);
+ add_next_index_string(return_value, enclosure);
}
/* }}} */
@@ -2762,10 +2727,10 @@ FileFunction(flock)
Flush the file */
SPL_METHOD(SplFileObject, fflush)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
@@ -2776,11 +2741,11 @@ SPL_METHOD(SplFileObject, fflush)
Return current file position */
SPL_METHOD(SplFileObject, ftell)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- long ret;
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+ zend_long ret;
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
@@ -2797,36 +2762,36 @@ SPL_METHOD(SplFileObject, ftell)
Return current file position */
SPL_METHOD(SplFileObject, fseek)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- long pos, whence = SEEK_SET;
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+ zend_long pos, whence = SEEK_SET;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &pos, &whence) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &pos, &whence) == FAILURE) {
return;
}
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
- spl_filesystem_file_free_line(intern TSRMLS_CC);
- RETURN_LONG(php_stream_seek(intern->u.file.stream, pos, whence));
+ spl_filesystem_file_free_line(intern);
+ RETURN_LONG(php_stream_seek(intern->u.file.stream, pos, (int)whence));
} /* }}} */
/* {{{ proto int SplFileObject::fgetc()
Get a character form the file */
SPL_METHOD(SplFileObject, fgetc)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char buf[2];
int result;
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
- spl_filesystem_file_free_line(intern TSRMLS_CC);
+ spl_filesystem_file_free_line(intern);
result = php_stream_getc(intern->u.file.stream);
@@ -2839,7 +2804,7 @@ SPL_METHOD(SplFileObject, fgetc)
buf[0] = result;
buf[1] = '\0';
- RETURN_STRINGL(buf, 1, 1);
+ RETURN_STRINGL(buf, 1);
}
} /* }}} */
@@ -2847,37 +2812,34 @@ SPL_METHOD(SplFileObject, fgetc)
Get a line from file pointer and strip HTML tags */
SPL_METHOD(SplFileObject, fgetss)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *arg2 = NULL;
- MAKE_STD_ZVAL(arg2);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+ zval arg2;
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
if (intern->u.file.max_line_len > 0) {
- ZVAL_LONG(arg2, intern->u.file.max_line_len);
+ ZVAL_LONG(&arg2, intern->u.file.max_line_len);
} else {
- ZVAL_LONG(arg2, 1024);
+ ZVAL_LONG(&arg2, 1024);
}
- spl_filesystem_file_free_line(intern TSRMLS_CC);
+ spl_filesystem_file_free_line(intern);
intern->u.file.current_line_num++;
- FileFunctionCall(fgetss, ZEND_NUM_ARGS(), arg2);
-
- zval_ptr_dtor(&arg2);
+ FileFunctionCall(fgetss, ZEND_NUM_ARGS(), &arg2);
} /* }}} */
/* {{{ proto int SplFileObject::fpassthru()
Output all remaining data from a file pointer */
SPL_METHOD(SplFileObject, fpassthru)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
@@ -2888,14 +2850,14 @@ SPL_METHOD(SplFileObject, fpassthru)
Implements a mostly ANSI compatible fscanf() */
SPL_METHOD(SplFileObject, fscanf)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
- spl_filesystem_file_free_line(intern TSRMLS_CC);
+ spl_filesystem_file_free_line(intern);
intern->u.file.current_line_num++;
FileFunctionCall(fscanf, ZEND_NUM_ARGS(), NULL);
@@ -2906,22 +2868,27 @@ SPL_METHOD(SplFileObject, fscanf)
Binary-safe file write */
SPL_METHOD(SplFileObject, fwrite)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
char *str;
- int str_len;
- long length = 0;
+ size_t str_len;
+ zend_long length = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &length) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &str, &str_len, &length) == FAILURE) {
return;
}
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
if (ZEND_NUM_ARGS() > 1) {
- str_len = MAX(0, MIN(length, str_len));
+ if (length >= 0) {
+ str_len = MAX(0, MIN((size_t)length, str_len));
+ } else {
+ /* Negative length given, nothing to write */
+ str_len = 0;
+ }
}
if (!str_len) {
RETURN_LONG(0);
@@ -2932,29 +2899,28 @@ SPL_METHOD(SplFileObject, fwrite)
SPL_METHOD(SplFileObject, fread)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- long length = 0;
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+ zend_long length = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &length) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &length) == FAILURE) {
return;
}
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
if (length <= 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
+ php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
RETURN_FALSE;
}
- Z_STRVAL_P(return_value) = emalloc(length + 1);
+ ZVAL_NEW_STR(return_value, zend_string_alloc(length, 0));
Z_STRLEN_P(return_value) = php_stream_read(intern->u.file.stream, Z_STRVAL_P(return_value), length);
/* needed because recv/read/gzread doesnt put a null at the end*/
Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0;
- Z_TYPE_P(return_value) = IS_STRING;
}
/* {{{ proto bool SplFileObject::fstat()
@@ -2966,23 +2932,23 @@ FileFunction(fstat)
Truncate file to 'size' length */
SPL_METHOD(SplFileObject, ftruncate)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- long size;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &size) == FAILURE) {
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+ zend_long size;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &size) == FAILURE) {
return;
}
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
if (!php_stream_truncate_supported(intern->u.file.stream)) {
- zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't truncate file %s", intern->file_name);
+ zend_throw_exception_ex(spl_ce_LogicException, 0, "Can't truncate file %s", intern->file_name);
RETURN_FALSE;
}
-
+
RETURN_BOOL(0 == php_stream_truncate_set_size(intern->u.file.stream, size));
} /* }}} */
@@ -2990,26 +2956,26 @@ SPL_METHOD(SplFileObject, ftruncate)
Seek to specified line */
SPL_METHOD(SplFileObject, seek)
{
- spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- long line_pos;
+ spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
+ zend_long line_pos;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &line_pos) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &line_pos) == FAILURE) {
return;
}
if(!intern->u.file.stream) {
- zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Object not initialized");
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
return;
}
if (line_pos < 0) {
- zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't seek file %s to negative line %ld", intern->file_name, line_pos);
- RETURN_FALSE;
+ zend_throw_exception_ex(spl_ce_LogicException, 0, "Can't seek file %s to negative line %pd", intern->file_name, line_pos);
+ RETURN_FALSE;
}
- spl_filesystem_file_rewind(getThis(), intern TSRMLS_CC);
-
+ spl_filesystem_file_rewind(getThis(), intern);
+
while(intern->u.file.current_line_num < line_pos) {
- if (spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC) == FAILURE) {
+ if (spl_filesystem_file_read_line(getThis(), intern, 1) == FAILURE) {
break;
}
}
@@ -3044,26 +3010,26 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fputcsv, 0, 0, 1)
ZEND_ARG_INFO(0, escape)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_flock, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_flock, 0, 0, 1)
ZEND_ARG_INFO(0, operation)
ZEND_ARG_INFO(1, wouldblock)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fseek, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fseek, 0, 0, 1)
ZEND_ARG_INFO(0, pos)
ZEND_ARG_INFO(0, whence)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetss, 0, 0, 0)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetss, 0, 0, 0)
ZEND_ARG_INFO(0, allowable_tags)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fscanf, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fscanf, 0, 0, 1)
ZEND_ARG_INFO(0, format)
ZEND_ARG_VARIADIC_INFO(1, vars)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fwrite, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fwrite, 0, 0, 1)
ZEND_ARG_INFO(0, str)
ZEND_ARG_INFO(0, length)
ZEND_END_ARG_INFO()
@@ -3072,11 +3038,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fread, 0, 0, 1)
ZEND_ARG_INFO(0, length)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_ftruncate, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_ftruncate, 0, 0, 1)
ZEND_ARG_INFO(0, size)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_seek, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_seek, 0, 0, 1)
ZEND_ARG_INFO(0, line_pos)
ZEND_END_ARG_INFO()
@@ -3134,14 +3100,18 @@ PHP_MINIT_FUNCTION(spl_directory)
{
REGISTER_SPL_STD_CLASS_EX(SplFileInfo, spl_filesystem_object_new, spl_SplFileInfo_functions);
memcpy(&spl_filesystem_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
- spl_filesystem_object_handlers.clone_obj = spl_filesystem_object_clone;
- spl_filesystem_object_handlers.cast_object = spl_filesystem_object_cast;
+ spl_filesystem_object_handlers.offset = XtOffsetOf(spl_filesystem_object, std);
+ spl_filesystem_object_handlers.clone_obj = spl_filesystem_object_clone;
+ spl_filesystem_object_handlers.cast_object = spl_filesystem_object_cast;
spl_filesystem_object_handlers.get_debug_info = spl_filesystem_object_get_debug_info;
+ spl_filesystem_object_handlers.dtor_obj = zend_objects_destroy_object;
+ spl_filesystem_object_handlers.free_obj = spl_filesystem_object_free_storage;
spl_ce_SplFileInfo->serialize = zend_class_serialize_deny;
spl_ce_SplFileInfo->unserialize = zend_class_unserialize_deny;
+
REGISTER_SPL_SUB_CLASS_EX(DirectoryIterator, SplFileInfo, spl_filesystem_object_new, spl_DirectoryIterator_functions);
- zend_class_implements(spl_ce_DirectoryIterator TSRMLS_CC, 1, zend_ce_iterator);
+ zend_class_implements(spl_ce_DirectoryIterator, 1, zend_ce_iterator);
REGISTER_SPL_IMPLEMENTS(DirectoryIterator, SeekableIterator);
spl_ce_DirectoryIterator->get_iterator = spl_filesystem_dir_get_iterator;
@@ -3165,7 +3135,7 @@ PHP_MINIT_FUNCTION(spl_directory)
REGISTER_SPL_SUB_CLASS_EX(RecursiveDirectoryIterator, FilesystemIterator, spl_filesystem_object_new, spl_RecursiveDirectoryIterator_functions);
REGISTER_SPL_IMPLEMENTS(RecursiveDirectoryIterator, RecursiveIterator);
-
+
memcpy(&spl_filesystem_object_check_handlers, &spl_filesystem_object_handlers, sizeof(zend_object_handlers));
spl_filesystem_object_check_handlers.get_method = spl_filesystem_object_get_method_check;
@@ -3182,7 +3152,7 @@ PHP_MINIT_FUNCTION(spl_directory)
REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "READ_AHEAD", SPL_FILE_OBJECT_READ_AHEAD);
REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "SKIP_EMPTY", SPL_FILE_OBJECT_SKIP_EMPTY);
REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "READ_CSV", SPL_FILE_OBJECT_READ_CSV);
-
+
REGISTER_SPL_SUB_CLASS_EX(SplTempFileObject, SplFileObject, spl_filesystem_object_new_check, spl_SplTempFileObject_functions);
return SUCCESS;
}