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

From: Date: Fri, 23 Mar 2012 05:30:51 +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-68156@lists.php.net to get a copy of this message
Commit: bcc15b56331f3055c99d8c126a61f48b33229c1c Author: Stanislav Malyshev <stas@php.net> Thu, 22 Mar 2012 22:30:51 -0700 Parents: ee755fafb99ba618fd82bbe05758ace68584ded1 a89c4a34ee55686ab1430a5060e1460335fc5203 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=bcc15b56331f3055c99d8c126a61f48b33229c1c Log: Merge branch 'PHP-5.3' into PHP-5.4 * PHP-5.3: Revert "- Fixed bug #61418 (Segmentation fault when DirectoryIterator's or" - causes bug #61482 Add initialization tests for SQLT_INT binds Fix NEWS Bugs: https://bugs.php.net/61418 https://bugs.php.net/61482 Changed paths: MM ext/spl/spl_directory.c

bcc15b56331f3055c99d8c126a61f48b33229c1c diff --combined ext/spl/spl_directory.c index c6eec94,f0e903f..22d4ffa --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@@ -120,16 -120,6 +120,6 @@@ static void spl_filesystem_object_free_ spl_filesystem_file_free_line(intern TSRMLS_CC); 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); } /* }}} */ @@@ -148,6 -138,7 +138,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 -148,7 +147,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 -235,7 +234,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 -261,9 +260,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 -575,6 +585,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 -636,16 +650,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 -1227,11 +1242,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; } @@@ -1648,15 -1627,10 +1638,10 @@@ zend_object_iterator *spl_filesystem_di dir_object = (spl_filesystem_object*)zend_object_store_get_object(object TSRMLS_CC); iterator = spl_filesystem_object_to_iterator(dir_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); + Z_SET_REFCOUNT_P(object, Z_REFCOUNT_P(object) + 2); + iterator->intern.data = (void*)object; + iterator->intern.funcs = &spl_filesystem_dir_it_funcs; + iterator->current = object; return (zend_object_iterator*)iterator; } @@@ -1735,15 -1709,15 +1720,15 @@@ static void spl_filesystem_dir_it_rewin static void spl_filesystem_tree_it_dtor(zend_object_iterator *iter TSRMLS_DC) { spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter; + zval *zfree = (zval*)iterator->intern.data; - if (iterator->intern.data) { - zval *object = iterator->intern.data; - zval_ptr_dtor(&object); - } else { - if (iterator->current) { - zval_ptr_dtor(&iterator->current); - } + if (iterator->current) { + zval_ptr_dtor(&iterator->current); } + iterator->intern.data = NULL; /* mark as unused */ + /* free twice as we add ref twice */ + zval_ptr_dtor(&zfree); + zval_ptr_dtor(&zfree); } /* }}} */ @@@ -1854,12 -1828,10 +1839,10 @@@ zend_object_iterator *spl_filesystem_tr dir_object = (spl_filesystem_object*)zend_object_store_get_object(object TSRMLS_CC); 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); + Z_SET_REFCOUNT_P(object, Z_REFCOUNT_P(object) + 2); + iterator->intern.data = (void*)object; + iterator->intern.funcs = &spl_filesystem_tree_it_funcs; + iterator->current = NULL; return (zend_object_iterator*)iterator; } @@@ -2040,6 -2012,7 +2023,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 -2045,11 +2055,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 -2257,7 +2262,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 -2271,7 +2276,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 -2459,7 +2464,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 -2579,6 +2586,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 -2760,7 +2804,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 -2774,14 +2817,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 -2852,6 +2887,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 -2868,7 +2910,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 -2892,6 +2934,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 -2960,6 +3003,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 (#68156) next »