com php-src: Merge branch 'PHP-5.3' into PHP-5.4: ext/spl/spl _directory.c

From: Date: Thu, 22 Mar 2012 11:13:52 +0000
Subject: com php-src: Merge branch 'PHP-5.3' into PHP-5.4: ext/spl/spl _directory.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-68138@lists.php.net to get a copy of this message
Commit: b60f9fe146eea4edbcc1c17172d8ee3c0c719c82 Author: David Soria Parra <dsp@php.net> Thu, 22 Mar 2012 12:13:52 +0100 Parents: 0b646e8027131a1fb127e1e6cc845319b65e46a4 14af1fe6923c65a91cd77eab5a8d4326f854391d Branches: PHP-5.4 5bf1efbf209b7d14edc8d01098465ed0bdda1516 ef678028bf8b9b3fde0d609328c2722040fba269 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b60f9fe146eea4edbcc1c17172d8ee3c0c719c82 Log: Merge branch 'PHP-5.3' into PHP-5.4 * PHP-5.3: Fixed reference counting Changed paths: MM ext/spl/spl_directory.c

b60f9fe146eea4edbcc1c17172d8ee3c0c719c82 diff --combined ext/spl/spl_directory.c index c6eec94,9d454c9..7bd340b --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@@ -148,6 -148,7 +148,6 @@@ static zend_object_value spl_filesystem { zend_object_value retval; spl_filesystem_object *intern; - zval *tmp; intern = emalloc(sizeof(spl_filesystem_object)); memset(intern, 0, sizeof(spl_filesystem_object)); @@@ -157,7 -158,7 +157,7 @@@ if (obj) *obj = intern; zend_object_std_init(&intern->std, class_type TSRMLS_CC); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + object_properties_init(&intern->std, class_type); 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; @@@ -244,7 -245,7 +244,7 @@@ static void spl_filesystem_dir_open(spl intern->type = SPL_FS_DIR; intern->_path_len = strlen(path); - intern->u.dir.dirp = php_stream_opendir(path, ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL); + 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)) { intern->_path = estrndup(path, --intern->_path_len); @@@ -270,20 -271,9 +270,20 @@@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_include_path, int silent TSRMLS_DC) /* {{{ */ { + 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)) { + 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"); + return FAILURE; + } + intern->u.file.context = php_stream_context_from_zval(intern->u.file.zcontext, 0); - intern->u.file.stream = php_stream_open_wrapper_ex(intern->file_name, intern->u.file.open_mode, (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, intern->u.file.context); + intern->u.file.stream = php_stream_open_wrapper_ex(intern->file_name, intern->u.file.open_mode, (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, NULL, intern->u.file.context); if (!intern->file_name_len || !intern->u.file.stream) { if (!EG(exception)) { @@@ -595,10 -585,6 +595,10 @@@ static HashTable* spl_filesystem_object *is_temp = 1; + if (!intern->std.properties) { + rebuild_object_properties(&intern->std); + } + ALLOC_HASHTABLE(rv); ZEND_INIT_SYMTABLE_EX(rv, zend_hash_num_elements(intern->std.properties) + 3, 0); @@@ -660,17 -646,16 +660,17 @@@ } /* }}} */ -zend_function *spl_filesystem_object_get_method_check(zval **object_ptr, char *method, int method_len TSRMLS_DC) /* {{{ */ +zend_function *spl_filesystem_object_get_method_check(zval **object_ptr, char *method, int method_len, const struct _zend_literal *key TSRMLS_DC) /* {{{ */ { spl_filesystem_object *fsobj = zend_object_store_get_object(*object_ptr TSRMLS_CC); 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; } - return zend_get_std_object_handlers()->get_method(object_ptr, method, method_len TSRMLS_CC); + return zend_get_std_object_handlers()->get_method(object_ptr, method, method_len, key TSRMLS_CC); } /* }}} */ @@@ -1252,7 -1237,11 +1252,7 @@@ SPL_METHOD(SplFileInfo, getLinkTarget RETURN_FALSE; } else if (!IS_ABSOLUTE_PATH(intern->file_name, intern->file_name_len)) { char expanded_path[MAXPATHLEN]; - - /* TODO: Fix expand_filepath to do not resolve links but only expand the path - avoiding double two resolution attempts - (Pierre) */ - if (!expand_filepath(intern->file_name, expanded_path TSRMLS_CC)) { + 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"); RETURN_FALSE; } @@@ -1655,8 -1644,8 +1655,8 @@@ zend_object_iterator *spl_filesystem_di /* ->current must be initialized; rewind doesn't set it and valid * doesn't check whether it's set */ iterator->current = object; + Z_SET_REFCOUNT_P(object, Z_REFCOUNT_P(object) + 2); } - zval_add_ref(&object); return (zend_object_iterator*)iterator; } @@@ -1858,8 -1847,8 +1858,8 @@@ zend_object_iterator *spl_filesystem_tr if (iterator->intern.data == NULL) { iterator->intern.data = object; iterator->intern.funcs = &spl_filesystem_tree_it_funcs; + zval_add_ref(&object); } - zval_add_ref(&object); return (zend_object_iterator*)iterator; } @@@ -2040,6 -2029,7 +2040,6 @@@ static int spl_filesystem_file_read(spl { char *buf; size_t line_len = 0; - int len; long line_add = (intern->u.file.current_line || intern->u.file.current_zval) ? 1 : 0; spl_filesystem_file_free_line(intern TSRMLS_CC); @@@ -2072,6 -2062,11 +2072,6 @@@ buf[line_len] = '\0'; } - if (PG(magic_quotes_runtime)) { - buf = php_addslashes(buf, line_len, &len, 1 TSRMLS_CC); - line_len = len; - } - intern->u.file.current_line = buf; intern->u.file.current_line_len = line_len; } @@@ -2279,7 -2274,7 +2279,7 @@@ SPL_METHOD(SplFileObject, __construct intern->u.file.open_mode = NULL; intern->u.file.open_mode_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sbr", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "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) { @@@ -2293,7 -2288,7 +2293,7 @@@ 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) { tmp_path_len = strlen(intern->u.file.stream->orig_path); @@@ -2481,9 -2476,7 +2481,9 @@@ SPL_METHOD(SplFileObject, setFlags { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &intern->flags); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &intern->flags) == FAILURE) { + return; + } } /* }}} */ /* {{{ proto int SplFileObject::getFlags() @@@ -2603,43 -2596,6 +2603,43 @@@ SPL_METHOD(SplFileObject, fgetcsv } /* }}} */ +/* {{{ proto int SplFileObject::fputcsv(array fields, [string delimiter [, string enclosure]]) + 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); + char delimiter = intern->u.file.delimiter, enclosure = intern->u.file.enclosure, escape = intern->u.file.escape; + char *delim = NULL, *enclo = NULL; + int d_len = 0, e_len = 0, ret; + zval *fields = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ss", &fields, &delim, &d_len, &enclo, &e_len) == SUCCESS) { + switch(ZEND_NUM_ARGS()) + { + case 3: + if (e_len != 1) { + php_error_docref(NULL TSRMLS_CC, 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"); + RETURN_FALSE; + } + delimiter = delim[0]; + /* no break */ + case 1: + case 0: + break; + } + ret = php_fputcsv(intern->u.file.stream, fields, delimiter, enclosure, escape TSRMLS_CC); + RETURN_LONG(ret); + } +} +/* }}} */ + /* {{{ proto void SplFileObject::setCsvControl([string delimiter = ',' [, string enclosure = '"' [, string escape = '\\']]]) Set the delimiter and enclosure character used in fgetcsv */ SPL_METHOD(SplFileObject, setCsvControl) @@@ -2821,6 -2777,7 +2821,6 @@@ SPL_METHOD(SplFileObject, fwrite spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); char *str; int str_len; - int ret; long length = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &length) == FAILURE) { @@@ -2834,6 -2791,14 +2834,6 @@@ RETURN_LONG(0); } - if (PG(magic_quotes_runtime)) { - str = estrndup(str, str_len); - php_stripslashes(str, &str_len TSRMLS_CC); - ret = php_stream_write(intern->u.file.stream, str, str_len); - efree(str); - RETURN_LONG(ret); - } - RETURN_LONG(php_stream_write(intern->u.file.stream, str, str_len)); } /* }}} */ @@@ -2904,13 -2869,6 +2904,13 @@@ ZEND_END_ARG_INFO( ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetcsv, 0, 0, 0) ZEND_ARG_INFO(0, delimiter) ZEND_ARG_INFO(0, enclosure) + ZEND_ARG_INFO(0, escape) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fputcsv, 0, 0, 1) + ZEND_ARG_INFO(0, fields) + ZEND_ARG_INFO(0, delimiter) + ZEND_ARG_INFO(0, enclosure) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_flock, 0, 0, 1) @@@ -2927,7 -2885,7 +2927,7 @@@ ZEND_BEGIN_ARG_INFO_EX(arginfo_file_obj ZEND_ARG_INFO(0, allowable_tags) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fscanf, 1, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fscanf, 1, 0, 1) ZEND_ARG_INFO(0, format) ZEND_END_ARG_INFO() @@@ -2951,7 -2909,6 +2951,7 @@@ static const zend_function_entry spl_Sp SPL_ME(SplFileObject, valid, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC) SPL_ME(SplFileObject, fgets, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC) SPL_ME(SplFileObject, fgetcsv, arginfo_file_object_fgetcsv, ZEND_ACC_PUBLIC) + SPL_ME(SplFileObject, fputcsv, arginfo_file_object_fputcsv, ZEND_ACC_PUBLIC) SPL_ME(SplFileObject, setCsvControl, arginfo_file_object_fgetcsv, ZEND_ACC_PUBLIC) SPL_ME(SplFileObject, getCsvControl, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC) SPL_ME(SplFileObject, flock, arginfo_file_object_flock, ZEND_ACC_PUBLIC) @@@ -3020,7 -2977,6 +3020,7 @@@ PHP_MINIT_FUNCTION(spl_directory REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "FOLLOW_SYMLINKS", SPL_FILE_DIR_FOLLOW_SYMLINKS); REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "KEY_AS_FILENAME", SPL_FILE_DIR_KEY_AS_FILENAME); REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "NEW_CURRENT_AND_KEY", SPL_FILE_DIR_KEY_AS_FILENAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO); + REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "OTHER_MODE_MASK", SPL_FILE_DIR_OTHERS_MASK); REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "SKIP_DOTS", SPL_FILE_DIR_SKIPDOTS); REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "UNIX_PATHS", SPL_FILE_DIR_UNIXPATHS);
« previous php.cvs (#68138) next »