Changeset 246
- Timestamp:
- 03/03/2007 18:07:45 (21 months ago)
- Location:
- trunk/ext/php
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/ext/php/config.m4
r24 r246 7 7 if test "$PHP_SYCK" != "no"; then 8 8 # --with-syck -> check with-path 9 SEARCH_PATH="/ usr/local /usr"9 SEARCH_PATH="/sw/local /sw /usr/local /usr" 10 10 SEARCH_FOR="/include/syck.h" 11 11 if test -r $PHP_SYCK/; then # path given as parameter … … 43 43 ]) 44 44 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) 50 46 51 47 PHP_SUBST(SYCK_SHARED_LIBADD) -
trunk/ext/php/phpext.c
r245 r246 1 / /2 //phpext.c3 // 4 //$Author$5 //$Date$6 // 7 //Copyright (C) 2003 why the lucky stiff8 //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 **/ 11 11 #ifdef HAVE_CONFIG_H 12 # include "config.h"12 # include "config.h" 13 13 #endif 14 14 … … 20 20 #include "ext/standard/info.h" 21 21 #include "php_syck.h" 22 23 #define PHP_SYCK_VERSION "0.2" 22 24 23 25 #define PHP_SYCK_EXCEPTION_PARENT "UnexpectedValueException" … … 50 52 51 53 static 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 */ 54 static double one() { return 1.0; } 55 static double inf() { return one() / zero(); } 56 static double nanphp() { return zero() / zero(); } 57 58 60 59 function_entry syck_functions[] = { 61 PHP_FE(syck_load, NULL)60 PHP_FE(syck_load, NULL) 62 61 {NULL, NULL, NULL} /* Must be the last line in syck_functions[] */ 63 62 }; 64 /* }}} */ 65 66 /* {{{ syck_module_entry 67 */ 63 64 #if ZEND_MODULE_API_NO >= 20050922 65 static zend_module_dep syck_deps[] = { 66 # ifdef HAVE_SPL 67 ZEND_MOD_REQUIRED("spl") 68 # endif 69 {NULL, NULL, NULL} 70 }; 71 #endif 72 68 73 zend_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 70 78 STANDARD_MODULE_HEADER, 71 79 #endif … … 73 81 syck_functions, 74 82 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 */ 78 86 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 */ 82 88 STANDARD_MODULE_PROPERTIES 83 89 }; 84 /* }}} */ 90 85 91 86 92 #ifdef COMPILE_DL_SYCK 87 93 ZEND_GET_MODULE(syck) 88 94 #endif 95 96 89 97 90 98 /** … … 114 122 115 123 zend_class_entry *syck_exception_entry; 116 /* }}} */ 117 118 /* {{{ PHP_MINIT_FUNCTION 119 */ 124 120 125 PHP_MINIT_FUNCTION(syck) 121 126 { … … 131 136 return SUCCESS; 132 137 } 133 /* }}} */ 134 135 /* {{{ PHP_MSHUTDOWN_FUNCTION 136 */ 138 137 139 PHP_MSHUTDOWN_FUNCTION(syck) 138 140 { … … 142 144 return SUCCESS; 143 145 } 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 166 148 PHP_MINFO_FUNCTION(syck) 167 149 { 168 150 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); 170 153 php_info_print_table_end(); 171 172 /* Remove comments if you have entries in php.ini 173 DISPLAY_INI_ENTRIES(); 174 */ 175 } 176 /* }}} */ 154 } 177 155 178 156 … … 185 163 186 164 MAKE_STD_ZVAL(o); 187 switch (n->kind) 188 { 165 switch (n->kind) { 189 166 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) { 223 185 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) { 242 196 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 { 248 200 ZVAL_STRINGL(o, n->data.str->ptr, n->data.str->len, 1); 249 201 } … … 252 204 case syck_seq_kind: 253 205 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); 259 210 } 260 211 break; … … 262 213 case syck_map_kind: 263 214 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); 273 222 } 274 223 } 275 224 break; 276 225 } 277 oid = syck_add_sym( p, o ); 226 227 oid = syck_add_sym(p, (char *)o); 278 228 return oid; 279 229 } … … 295 245 SyckParser *parser; 296 246 297 if (ZEND_NUM_ARGS() != 1) WRONG_PARAM_COUNT; 247 if (ZEND_NUM_ARGS() != 1) { 248 WRONG_PARAM_COUNT; 249 } 250 298 251 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { 299 252 return; … … 302 255 parser = syck_new_parser(); 303 256 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)) { 315 268 *return_value = *obj; 316 269 zval_copy_ctor(return_value); 317 270 } 318 271 319 syck_free_parser( parser);272 syck_free_parser(parser); 320 273 } 321 274 /* }}} */ -
trunk/ext/php/syck.php
r111 r246 1 <? 1 <?php 2 2 if(!extension_loaded('syck')) { 3 3 dl('syck.so');