Changeset 273 for trunk/ext/php

Show
Ignore:
Timestamp:
10/04/2007 15:22:32 (14 months ago)
Author:
indeyets
Message:

- fixed dumping of mixed arrays and numeric-arrays starting from non-zero digit
- added some Dump-tests

Location:
trunk/ext/php
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/php/CHANGELOG

    r272 r273  
    11--- %YAML:1.0 
    22- version: 0.9.2 
    3   date: 2007-08-?? 
     3  date: 2007-09-?? 
    44  status: beta 
    55  changes: 
    66    - short-and-flat arrays are dumped using inline-mode now (for readability) 
    77    - gcc-2.95 compatibility (patch by Brian J. France) 
     8    - fixed dumping of mixed arrays and numeric-arrays starting from non-zero digit 
    89 
    910- version: 0.9.1 
  • trunk/ext/php/phpext.c

    r272 r273  
    3232#include "php_syck.h" 
    3333 
    34 #define PHP_SYCK_VERSION "@PACKAGE_VERSION@" 
     34#define PHP_SYCK_VERSION "0.9.2-dev" 
    3535 
    3636/** 
     
    134134        return ptr->stack[(ptr->level)--]; 
    135135} 
     136 
     137 
     138 
     139 
     140/** 
     141 * returns 
     142 *   0 for sequential numeric arrays 
     143 *   1 for insequential or associative arrays 
     144 */ 
     145static int psex_determine_array_type(HashTable *myht TSRMLS_DC) /* {{{ */ 
     146{ 
     147        int i = myht ? zend_hash_num_elements(myht) : 0; 
     148 
     149        if (i > 0) { 
     150                char *key; 
     151                uint key_len; 
     152                HashPosition pos; 
     153                ulong index, idx = 0; 
     154 
     155                zend_hash_internal_pointer_reset_ex(myht, &pos); 
     156 
     157                for (;; zend_hash_move_forward_ex(myht, &pos)) { 
     158                        i = zend_hash_get_current_key_ex(myht, &key, &key_len, &index, 0, &pos); 
     159 
     160                        if (i == HASH_KEY_NON_EXISTANT) 
     161                                break; 
     162 
     163                        if (i == HASH_KEY_IS_STRING) { 
     164                                return 1; 
     165                        } else { 
     166                                if (index != idx) { 
     167                                        return 1; 
     168                                } 
     169                        } 
     170 
     171                        idx++; 
     172                } 
     173        } 
     174 
     175        return 0; 
     176} 
     177 
     178 
     179 
    136180 
    137181function_entry syck_functions[] = { 
     
    416460        php_syck_emitter_xtra *bonus = (php_syck_emitter_xtra *) e->bonus; 
    417461        zval *data = bonus->stack[id]; 
     462        TSRMLS_FETCH(); 
    418463 
    419464        switch (Z_TYPE_P(data)) { 
     
    481526                        } 
    482527 
    483                         if (zend_hash_index_exists(tbl, 0)) { 
     528                        if (0 == psex_determine_array_type(tbl TSRMLS_CC)) { 
    484529                                /* indexed array */ 
    485530                                if (flat_and_short) 
     
    509554                                        zval **ppzval, kzval; 
    510555                                        char *key; 
    511                                         size_t key_len, idx; 
     556                                        size_t key_len, idx, key_type; 
    512557 
    513558                                        zend_hash_get_current_key_ex(tbl, (char **)&key, (uint *)&key_len, &idx, 0, NULL); 
    514559                                        zend_hash_get_current_data(tbl, (void **)&ppzval); 
     560                                        key_type = zend_hash_get_current_key_type_ex(tbl, NULL); 
     561 
     562                                        if (key_type == HASH_KEY_IS_LONG) { 
     563                                                key_len = 1 + snprintf(key, 0, "%ld", idx); /* getting size ("0" doesn't let output) */ 
     564                                                key = emalloc(key_len); 
     565                                                snprintf(key, key_len, "%ld", idx); 
     566                                        } 
    515567 
    516568                                        ZVAL_STRINGL(&kzval, key, key_len - 1, 1); 
     
    527579 
    528580                                        zval_dtor(&kzval); 
     581 
     582                                        if (key_type == HASH_KEY_IS_LONG) { 
     583                                                efree(key); 
     584                                        } 
    529585                                } 
    530586