Changeset 318 for trunk/ext/php

Show
Ignore:
Timestamp:
05/26/2008 04:09:53 (4 months ago)
Author:
indeyets
Message:

added handling of sequences and maps of unknown types

Location:
trunk/ext/php
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/php/CHANGELOG

    r308 r318  
    66    - fixed bug#31 (broken yaml caused segfault) 
    77    - multiline strings are exported in folded format (for readability) now 
     8    - maps and sequences of unknown types are treated as php/hash and php/array (with notice) 
    89 
    910- version: 0.9.2 
  • trunk/ext/php/phpext.c

    r308 r318  
    415415                case syck_seq_kind: 
    416416                { 
    417                         if (NULL == n->type_id || strcmp(n->type_id, "php/array") == 0) { 
    418                                 size_t i; 
    419  
    420                                 /* Just an array */ 
    421                                 array_init(o); 
    422  
    423                                 for (i = 0; i < n->data.list->idx; i++) { 
    424                                         SYMID oid = syck_seq_read(n, i); 
    425                                         zval *o2 = NULL; 
    426  
    427                                         syck_lookup_sym(p, oid, (char **) &o2); /* retrieving child-node */ 
    428  
    429                                         add_index_zval(o, i, o2); 
    430                                 } 
    431                         } else if (strncmp(n->type_id, "php/array::", 11) == 0) { 
     417                        if (strncmp(n->type_id, "php/array::", 11) == 0) { 
    432418                                /* some class which implements ArrayAccess */ 
    433419                                size_t i; 
     
    476462                                efree(classname); 
    477463                        } else { 
    478                                 /* something else */ 
    479                                 php_error(E_NOTICE, "syck extension didn't handle %s type", n->type_id); 
     464                                size_t i; 
     465 
     466                                if (NULL != n->type_id && strcmp(n->type_id, "php/array") != 0) { 
     467                                        php_error(E_NOTICE, "syck extension didn't handle sequence of %s type. treating as php/array", n->type_id); 
     468                                } 
     469 
     470                                /* Just an array */ 
     471                                array_init(o); 
     472 
     473                                for (i = 0; i < n->data.list->idx; i++) { 
     474                                        SYMID oid = syck_seq_read(n, i); 
     475                                        zval *o2 = NULL; 
     476 
     477                                        syck_lookup_sym(p, oid, (char **) &o2); /* retrieving child-node */ 
     478 
     479                                        add_index_zval(o, i, o2); 
     480                                } 
    480481                        } 
    481482                } 
     
    484485                case syck_map_kind: 
    485486                { 
    486                         if (NULL == n->type_id || strcmp(n->type_id, "php/hash") == 0) { 
    487                                 SYMID oid; 
    488                                 size_t i; 
    489                                 zval *o2 = NULL, *o3 = NULL; 
    490                                 zval *res = NULL; 
    491  
    492                                 array_init(o); 
    493  
    494                                 for (i = 0; i < n->data.pairs->idx; i++) { 
    495                                         oid = syck_map_read(n, map_key, i); 
    496                                         syck_lookup_sym(p, oid, (char **) &o2); /* retrieving key-node */ 
    497  
    498                                         if (o2->type == IS_STRING || o2->type == IS_LONG) { 
    499                                                 oid = syck_map_read(n, map_value, i); 
    500                                                 syck_lookup_sym(p, oid, (char **) &o3); /* retrieving value-node */ 
    501  
    502                                                 if (o2->type == IS_LONG) { 
    503                                                         add_index_zval(o, Z_LVAL_P(o2), o3); 
    504                                                 } else { 
    505                                                         add_assoc_zval(o, Z_STRVAL_P(o2), o3); 
    506                                                 } 
    507                                         } 
    508  
    509                                         zval_ptr_dtor(&o2); 
    510                                 } 
    511                         } else if (strncmp(n->type_id, "php/hash::", 10) == 0) { 
     487                        if (strncmp(n->type_id, "php/hash::", 10) == 0) { 
    512488                                /* some class which implements ArrayAccess */ 
    513489                                SYMID oid; 
     
    556532                                efree(classname); 
    557533                        } else { 
    558                                 /* something else */ 
    559                                 php_error(E_NOTICE, "syck extension didn't handle %s type", n->type_id); 
     534                                SYMID oid; 
     535                                size_t i; 
     536                                zval *o2 = NULL, *o3 = NULL; 
     537                                zval *res = NULL; 
     538 
     539                                if (NULL != n->type_id && strcmp(n->type_id, "php/hash") != 0) { 
     540                                        php_error(E_NOTICE, "syck extension didn't handle map of %s type. treating as php/hash", n->type_id); 
     541                                } 
     542 
     543                                array_init(o); 
     544 
     545                                for (i = 0; i < n->data.pairs->idx; i++) { 
     546                                        oid = syck_map_read(n, map_key, i); 
     547                                        syck_lookup_sym(p, oid, (char **) &o2); /* retrieving key-node */ 
     548 
     549                                        if (o2->type == IS_STRING || o2->type == IS_LONG) { 
     550                                                oid = syck_map_read(n, map_value, i); 
     551                                                syck_lookup_sym(p, oid, (char **) &o3); /* retrieving value-node */ 
     552 
     553                                                if (o2->type == IS_LONG) { 
     554                                                        add_index_zval(o, Z_LVAL_P(o2), o3); 
     555                                                } else { 
     556                                                        add_assoc_zval(o, Z_STRVAL_P(o2), o3); 
     557                                                } 
     558                                        } 
     559 
     560                                        zval_ptr_dtor(&o2); 
     561                                } 
    560562                        } 
    561563                }