Changeset 246 for trunk/ext

Show
Ignore:
Timestamp:
03/03/2007 18:07:45 (21 months ago)
Author:
indeyets
Message:

* Conformance to PECL-style of coding
* Support for PHP 5.2
* Report versions for phpinfo()
* Added casts, to block warnings

Location:
trunk/ext/php
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/php/config.m4

    r24 r246  
    77if test "$PHP_SYCK" != "no"; then 
    88  # --with-syck -> check with-path 
    9   SEARCH_PATH="/usr/local /usr" 
     9  SEARCH_PATH="/sw/local /sw /usr/local /usr" 
    1010  SEARCH_FOR="/include/syck.h" 
    1111  if test -r $PHP_SYCK/; then # path given as parameter 
     
    4343  ]) 
    4444   
    45   # For PHP 4.3.0: 
    46   # PHP_NEW_EXTENSION(syck, phpext.c, $ext_shared) 
    47  
    48   # For PHP pre-4.3.0: 
    49   PHP_EXTENSION(syck, $ext_shared) 
     45  PHP_NEW_EXTENSION(syck, phpext.c, $ext_shared) 
    5046 
    5147  PHP_SUBST(SYCK_SHARED_LIBADD) 
  • trunk/ext/php/phpext.c

    r245 r246  
    1 // 
    2 // phpext.c 
    3 // 
    4 // $Author$ 
    5 // $Date$ 
    6 // 
    7 // Copyright (C) 2003 why the lucky stiff 
    8 // Copyright © 2007 Alexey Zakhlestin <indeyets@gmail.com> 
    9 // 
    10  
     1/** 
     2 * phpext.c 
     3 *  
     4 * $Author$ 
     5 * $Date$ 
     6 *  
     7 * Copyright (C) 2003 why the lucky stiff 
     8 * Copyright © 2007 Alexey Zakhlestin <indeyets@gmail.com> 
     9 *  
     10**/ 
    1111#ifdef HAVE_CONFIG_H 
    12 #include "config.h" 
     12# include "config.h" 
    1313#endif 
    1414 
     
    2020#include "ext/standard/info.h" 
    2121#include "php_syck.h" 
     22 
     23#define PHP_SYCK_VERSION "0.2" 
    2224 
    2325#define PHP_SYCK_EXCEPTION_PARENT "UnexpectedValueException" 
     
    5052 
    5153static double zero()    { return 0.0; } 
    52 static double one() { return 1.0; } 
    53 static double inf() { return one() / zero(); } 
    54 static double nanphp() { return zero() / zero(); } 
    55  
    56 /* {{{ syck_functions[] 
    57  * 
    58  * Every user visible function must have an entry in syck_functions[]. 
    59  */ 
     54static double one()             { return 1.0; } 
     55static double inf()             { return one() / zero(); } 
     56static double nanphp()  { return zero() / zero(); } 
     57 
     58 
    6059function_entry syck_functions[] = { 
    61         PHP_FE(syck_load,                               NULL) 
     60        PHP_FE(syck_load, NULL) 
    6261        {NULL, NULL, NULL}      /* Must be the last line in syck_functions[] */ 
    6362}; 
    64 /* }}} */ 
    65  
    66 /* {{{ syck_module_entry 
    67  */ 
     63 
     64#if ZEND_MODULE_API_NO >= 20050922 
     65static zend_module_dep syck_deps[] = { 
     66# ifdef HAVE_SPL 
     67        ZEND_MOD_REQUIRED("spl") 
     68# endif 
     69        {NULL, NULL, NULL} 
     70}; 
     71#endif 
     72 
    6873zend_module_entry syck_module_entry = { 
    69 #if ZEND_MODULE_API_NO >= 20010901 
     74#if ZEND_MODULE_API_NO >= 20050922 
     75        STANDARD_MODULE_HEADER_EX, NULL, 
     76        syck_deps, 
     77#else 
    7078        STANDARD_MODULE_HEADER, 
    7179#endif 
     
    7381        syck_functions, 
    7482        PHP_MINIT(syck),        /* module init function */ 
    75         NULL,                   /* module shutdown function */ 
    76         NULL,                   /* request init function */ 
    77         NULL,                   /* request shutdown function */ 
     83        NULL,                           /* module shutdown function */ 
     84        NULL,                           /* request init function */ 
     85        NULL,                           /* request shutdown function */ 
    7886        PHP_MINFO(syck),        /* module info function */ 
    79 #if ZEND_MODULE_API_NO >= 20010901 
    80         "0.2",                  /* Replace with version number for your extension */ 
    81 #endif 
     87        PHP_SYCK_VERSION,       /* Replace with version number for your extension */ 
    8288        STANDARD_MODULE_PROPERTIES 
    8389}; 
    84 /* }}} */ 
     90 
    8591 
    8692#ifdef COMPILE_DL_SYCK 
    8793ZEND_GET_MODULE(syck) 
    8894#endif 
     95 
     96 
    8997 
    9098/** 
     
    114122 
    115123zend_class_entry *syck_exception_entry; 
    116 /* }}} */ 
    117  
    118 /* {{{ PHP_MINIT_FUNCTION 
    119  */ 
     124 
    120125PHP_MINIT_FUNCTION(syck) 
    121126{ 
     
    131136        return SUCCESS; 
    132137} 
    133 /* }}} */ 
    134  
    135 /* {{{ PHP_MSHUTDOWN_FUNCTION 
    136  */ 
     138 
    137139PHP_MSHUTDOWN_FUNCTION(syck) 
    138140{ 
     
    142144        return SUCCESS; 
    143145} 
    144 /* }}} */ 
    145  
    146 /* Remove if there's nothing to do at request start */ 
    147 /* {{{ PHP_RINIT_FUNCTION 
    148  */ 
    149 PHP_RINIT_FUNCTION(syck) 
    150 { 
    151         return SUCCESS; 
    152 } 
    153 /* }}} */ 
    154  
    155 /* Remove if there's nothing to do at request end */ 
    156 /* {{{ PHP_RSHUTDOWN_FUNCTION 
    157  */ 
    158 PHP_RSHUTDOWN_FUNCTION(syck) 
    159 { 
    160         return SUCCESS; 
    161 } 
    162 /* }}} */ 
    163  
    164 /* {{{ PHP_MINFO_FUNCTION 
    165  */ 
     146 
     147 
    166148PHP_MINFO_FUNCTION(syck) 
    167149{ 
    168150        php_info_print_table_start(); 
    169         php_info_print_table_header(2, "syck support", "enabled"); 
     151        php_info_print_table_header(2, "Extension version", PHP_SYCK_VERSION); 
     152        php_info_print_table_header(2, "Syck library version", SYCK_VERSION); 
    170153        php_info_print_table_end(); 
    171  
    172         /* Remove comments if you have entries in php.ini 
    173         DISPLAY_INI_ENTRIES(); 
    174         */ 
    175 } 
    176 /* }}} */ 
     154} 
    177155 
    178156 
     
    185163 
    186164        MAKE_STD_ZVAL(o); 
    187         switch (n->kind) 
    188         { 
     165        switch (n->kind) { 
    189166                case syck_str_kind: 
    190                         if ( n->type_id == NULL || strcmp( n->type_id, "str" ) == 0 ) 
    191                         { 
    192                                 ZVAL_STRINGL( o, n->data.str->ptr, n->data.str->len, 1); 
    193                         } 
    194                         else if ( strcmp( n->type_id, "null" ) == 0 ) 
    195                         { 
    196                                 ZVAL_NULL( o ); 
    197                         } 
    198                         else if ( strcmp( n->type_id, "bool#yes" ) == 0 ) 
    199                         { 
    200                                 ZVAL_BOOL( o, 1 ); 
    201                         } 
    202                         else if ( strcmp( n->type_id, "bool#no" ) == 0 ) 
    203                         { 
    204                                 ZVAL_BOOL( o, 0 ); 
    205                         } 
    206                         else if ( strcmp( n->type_id, "int#hex" ) == 0 ) 
    207                         { 
    208                                 long intVal = strtol( n->data.str->ptr, NULL, 16 ); 
    209                                 ZVAL_LONG( o, intVal ); 
    210                         } 
    211                         else if ( strcmp( n->type_id, "int#oct" ) == 0 ) 
    212                         { 
    213                                 long intVal = strtol( n->data.str->ptr, NULL, 8 ); 
    214                                 ZVAL_LONG( o, intVal ); 
    215                         } 
    216                         else if ( strcmp( n->type_id, "int" ) == 0 ) 
    217                         { 
    218                                 long intVal = strtol( n->data.str->ptr, NULL, 10 ); 
    219                                 ZVAL_LONG( o, intVal ); 
    220                         } 
    221                         else if ( strcmp( n->type_id, "float" ) == 0 ) 
    222                         { 
     167                        if (n->type_id == NULL || strcmp(n->type_id, "str") == 0) { 
     168                                ZVAL_STRINGL(o, n->data.str->ptr, n->data.str->len, 1); 
     169                        } else if (strcmp(n->type_id, "null") == 0) { 
     170                                ZVAL_NULL(o); 
     171                        } else if (strcmp(n->type_id, "bool#yes") == 0) { 
     172                                ZVAL_BOOL(o, 1); 
     173                        } else if (strcmp(n->type_id, "bool#no") == 0) { 
     174                                ZVAL_BOOL(o, 0); 
     175                        } else if (strcmp(n->type_id, "int#hex") == 0) { 
     176                                long intVal = strtol(n->data.str->ptr, NULL, 16); 
     177                                ZVAL_LONG(o, intVal); 
     178                        } else if (strcmp(n->type_id, "int#oct") == 0) { 
     179                                long intVal = strtol(n->data.str->ptr, NULL, 8); 
     180                                ZVAL_LONG(o, intVal); 
     181                        } else if (strcmp(n->type_id, "int") == 0) { 
     182                                long intVal = strtol(n->data.str->ptr, NULL, 10); 
     183                                ZVAL_LONG(o, intVal); 
     184                        } else if (strcmp(n->type_id, "float") == 0) { 
    223185                                double f; 
    224                                 syck_str_blow_away_commas( n ); 
    225                                 f = strtod( n->data.str->ptr, NULL ); 
    226                                 ZVAL_DOUBLE( o, f ); 
    227                         } 
    228                         else if ( strcmp( n->type_id, "float#nan" ) == 0 ) 
    229                         { 
    230                                 ZVAL_DOUBLE( o, nanphp() ); 
    231                         } 
    232                         else if ( strcmp( n->type_id, "float#inf" ) == 0 ) 
    233                         { 
    234                                 ZVAL_DOUBLE( o, inf() ); 
    235                         } 
    236                         else if ( strcmp( n->type_id, "float#neginf" ) == 0 ) 
    237                         { 
    238                                 ZVAL_DOUBLE( o, -inf() ); 
    239                         } 
    240                         else if ( strcmp( n->type_id, "merge" ) == 0 ) 
    241                         { 
     186                                syck_str_blow_away_commas(n); 
     187                                f = strtod(n->data.str->ptr, NULL); 
     188                                ZVAL_DOUBLE(o, f); 
     189                        } else if (strcmp(n->type_id, "float#nan") == 0) { 
     190                                ZVAL_DOUBLE(o, nanphp()); 
     191                        } else if (strcmp(n->type_id, "float#inf") == 0) { 
     192                                ZVAL_DOUBLE(o, inf()); 
     193                        } else if (strcmp(n->type_id, "float#neginf") == 0) { 
     194                                ZVAL_DOUBLE(o, -inf()); 
     195                        } else if (strcmp(n->type_id, "merge") == 0) { 
    242196                                TSRMLS_FETCH(); 
    243                                 MAKE_STD_ZVAL( o ); 
    244                                 object_init_ex( o, merge_key_entry ); 
    245                         } 
    246                         else 
    247                         { 
     197                                MAKE_STD_ZVAL(o); 
     198                                object_init_ex(o, merge_key_entry); 
     199                        } else { 
    248200                                ZVAL_STRINGL(o, n->data.str->ptr, n->data.str->len, 1); 
    249201                        } 
     
    252204                case syck_seq_kind: 
    253205                        array_init(o); 
    254                         for ( i = 0; i < n->data.list->idx; i++ ) 
    255                         { 
    256                                 oid = syck_seq_read( n, i ); 
    257                                 syck_lookup_sym( p, oid, &o2 ); 
    258                                 add_index_zval( o, i, o2 ); 
     206                        for (i = 0; i < n->data.list->idx; i++) { 
     207                                oid = syck_seq_read(n, i); 
     208                                syck_lookup_sym(p, oid, (char **) &o2); 
     209                                add_index_zval(o, i, o2); 
    259210                        } 
    260211                break; 
     
    262213                case syck_map_kind: 
    263214                        array_init(o); 
    264                         for ( i = 0; i < n->data.pairs->idx; i++ ) 
    265                         { 
    266                                 oid = syck_map_read( n, map_key, i ); 
    267                                 syck_lookup_sym( p, oid, &o2 ); 
    268                                 oid = syck_map_read( n, map_value, i ); 
    269                                 syck_lookup_sym( p, oid, &o3 ); 
    270                                 if ( o2->type == IS_STRING ) 
    271                                 { 
    272                                         add_assoc_zval( o, o2->value.str.val, o3 ); 
     215                        for (i = 0; i < n->data.pairs->idx; i++) { 
     216                                oid = syck_map_read(n, map_key, i); 
     217                                syck_lookup_sym(p, oid, (char **) &o2); 
     218                                oid = syck_map_read(n, map_value, i); 
     219                                syck_lookup_sym(p, oid, (char **) &o3); 
     220                                if (o2->type == IS_STRING) { 
     221                                        add_assoc_zval(o, o2->value.str.val, o3); 
    273222                                } 
    274223                        } 
    275224                break; 
    276225        } 
    277         oid = syck_add_sym( p, o ); 
     226 
     227        oid = syck_add_sym(p, (char *)o); 
    278228        return oid; 
    279229} 
     
    295245        SyckParser *parser; 
    296246 
    297         if (ZEND_NUM_ARGS() != 1) WRONG_PARAM_COUNT; 
     247        if (ZEND_NUM_ARGS() != 1) { 
     248                WRONG_PARAM_COUNT; 
     249        } 
     250 
    298251        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { 
    299252                return; 
     
    302255        parser = syck_new_parser(); 
    303256 
    304         syck_parser_handler( parser, php_syck_handler ); 
    305         syck_parser_error_handler( parser, php_syck_ehandler ); 
    306  
    307         syck_parser_implicit_typing( parser, 1 ); 
    308         syck_parser_taguri_expansion( parser, 0 ); 
    309  
    310         syck_parser_str( parser, arg, arg_len, NULL ); 
    311  
    312         v = syck_parse( parser ); 
    313  
    314         if (1 == syck_lookup_sym( parser, v, &obj )) { 
     257        syck_parser_handler(parser, php_syck_handler); 
     258        syck_parser_error_handler(parser, php_syck_ehandler); 
     259 
     260        syck_parser_implicit_typing(parser, 1); 
     261        syck_parser_taguri_expansion(parser, 0); 
     262 
     263        syck_parser_str(parser, arg, arg_len, NULL); 
     264 
     265        v = syck_parse(parser); 
     266 
     267        if (1 == syck_lookup_sym(parser, v, (char **) &obj)) { 
    315268                *return_value = *obj; 
    316269                zval_copy_ctor(return_value); 
    317270        } 
    318271 
    319         syck_free_parser( parser ); 
     272        syck_free_parser(parser); 
    320273} 
    321274/* }}} */ 
  • trunk/ext/php/syck.php

    r111 r246  
    1 <? 
     1<?php 
    22if(!extension_loaded('syck')) { 
    33        dl('syck.so');