felipe          Fri Sep 12 01:14:14 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/standard/tests/file    fputcsv_002.phpt 

  Modified files:              
    /php-src/ext/standard       file.c 
  Log:
  - MFH: Fixed unexpected zval changes
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.409.2.6.2.28.2.21&r2=1.409.2.6.2.28.2.22&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.409.2.6.2.28.2.21 
php-src/ext/standard/file.c:1.409.2.6.2.28.2.22
--- php-src/ext/standard/file.c:1.409.2.6.2.28.2.21     Tue Aug 12 19:38:54 2008
+++ php-src/ext/standard/file.c Fri Sep 12 01:14:14 2008
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: file.c,v 1.409.2.6.2.28.2.21 2008/08/12 19:38:54 felipe Exp $ */
+/* $Id: file.c,v 1.409.2.6.2.28.2.22 2008/09/12 01:14:14 felipe Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1866,7 +1866,7 @@
 }
 /* }}} */
 
-#define FPUTCSV_FLD_CHK(c) memchr(Z_STRVAL_PP(field), c, Z_STRLEN_PP(field))
+#define FPUTCSV_FLD_CHK(c) memchr(Z_STRVAL(field), c, Z_STRLEN(field))
 
 /* {{{ proto int fputcsv(resource fp, array fields [, string delimiter [, 
string enclosure]])
    Format line as CSV and write to file pointer */
@@ -1877,7 +1877,7 @@
        const char escape_char = '\\';
        php_stream *stream;
        int ret;
-       zval *fp = NULL, *fields = NULL, **field = NULL;
+       zval *fp = NULL, *fields = NULL, **field_tmp = NULL, field;
        char *delimiter_str = NULL, *enclosure_str = NULL;
        int delimiter_str_len, enclosure_str_len;
        HashPosition pos;
@@ -1918,11 +1918,14 @@
 
        count = zend_hash_num_elements(Z_ARRVAL_P(fields));
        zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(fields), &pos);
-       while (zend_hash_get_current_data_ex(Z_ARRVAL_P(fields), (void **) 
&field, &pos) == SUCCESS) {
-               if (Z_TYPE_PP(field) != IS_STRING) {
-                       SEPARATE_ZVAL(field);
-                       convert_to_string(*field);
+       while (zend_hash_get_current_data_ex(Z_ARRVAL_P(fields), (void **) 
&field_tmp, &pos) == SUCCESS) {
+               field = **field_tmp;
+
+               if (Z_TYPE_PP(field_tmp) != IS_STRING) {
+                       zval_copy_ctor(&field);
+                       convert_to_string(&field);
                }
+
                /* enclose a field that contains a delimiter, an enclosure 
character, or a newline */
                if (FPUTCSV_FLD_CHK(delimiter) ||
                        FPUTCSV_FLD_CHK(enclosure) ||
@@ -1932,8 +1935,8 @@
                        FPUTCSV_FLD_CHK('\t') ||
                        FPUTCSV_FLD_CHK(' ')
                ) {
-                       char *ch = Z_STRVAL_PP(field);
-                       char *end = ch + Z_STRLEN_PP(field);
+                       char *ch = Z_STRVAL(field);
+                       char *end = ch + Z_STRLEN(field);
                        int escaped = 0;
 
                        smart_str_appendc(&csvline, enclosure);
@@ -1950,13 +1953,17 @@
                        }
                        smart_str_appendc(&csvline, enclosure);
                } else {
-                       smart_str_appendl(&csvline, Z_STRVAL_PP(field), 
Z_STRLEN_PP(field));
+                       smart_str_appendl(&csvline, Z_STRVAL(field), 
Z_STRLEN(field));
                }
 
                if (++i != count) {
                        smart_str_appendl(&csvline, &delimiter, 1);
                }
                zend_hash_move_forward_ex(Z_ARRVAL_P(fields), &pos);
+               
+               if (Z_TYPE_PP(field_tmp) != IS_STRING) {
+                       zval_dtor(&field);
+               }
        }
 
        smart_str_appendc(&csvline, '\n');

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/fputcsv_002.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/file/fputcsv_002.phpt
+++ php-src/ext/standard/tests/file/fputcsv_002.phpt
--TEST--
fputcsv(): Checking data after calling the function
--FILE--
<?php

$file = dirname(__FILE__) .'/fgetcsv-test.csv';

$data = array(1, 2, 'foo', 'haha', array(4, 5, 6), 1.3, null);

$fp = fopen($file, 'w');

fputcsv($fp, $data);

var_dump($data);

@unlink($file);

?>
--EXPECTF--
Notice: Array to string conversion in %s on line %d
array(7) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  unicode(3) "foo"
  [3]=>
  unicode(4) "haha"
  [4]=>
  array(3) {
    [0]=>
    int(4)
    [1]=>
    int(5)
    [2]=>
    int(6)
  }
  [5]=>
  float(1.3)
  [6]=>
  NULL
}



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to