- Timestamp:
- 03/03/2007 11:28:42 (21 months ago)
- Files:
-
- 1 modified
-
trunk/ext/php/phpext.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ext/php/phpext.c
r111 r242 15 15 16 16 #include "php.h" 17 #include "zend_exceptions.h" 17 18 #include "php_ini.h" 18 19 #include "ext/standard/info.h" 19 20 #include "php_syck.h" 20 21 21 static double zero() { return 0.0; }22 static double zero() { return 0.0; } 22 23 static double one() { return 1.0; } 23 24 static double inf() { return one() / zero(); } 24 static double nan () { return zero() / zero(); }25 static double nanphp() { return zero() / zero(); } 25 26 26 27 /* {{{ syck_functions[] … … 42 43 "syck", 43 44 syck_functions, 44 NULL, /* module init function */45 NULL, /* module shutdown function */46 NULL, /* request init function */47 NULL, /* request shutdown function */45 NULL, /* module init function */ 46 NULL, /* module shutdown function */ 47 NULL, /* request init function */ 48 NULL, /* request shutdown function */ 48 49 PHP_MINFO(syck), /* module info function */ 49 50 #if ZEND_MODULE_API_NO >= 20010901 … … 62 63 /* Remove comments and fill if you need to have entries in php.ini 63 64 PHP_INI_BEGIN() 64 STD_PHP_INI_ENTRY("syck.global_value","42", PHP_INI_ALL, OnUpdateInt, global_value, zend_syck_globals, syck_globals)65 STD_PHP_INI_ENTRY("syck.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_syck_globals, syck_globals)65 STD_PHP_INI_ENTRY("syck.global_value", "42", PHP_INI_ALL, OnUpdateInt, global_value, zend_syck_globals, syck_globals) 66 STD_PHP_INI_ENTRY("syck.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_syck_globals, syck_globals) 66 67 PHP_INI_END() 67 68 */ … … 86 87 87 88 static zend_function_entry mergekey_functions[] = { 88 PHP_FALIAS(mergekey, mergekey_init,NULL)89 PHP_FALIAS(mergekey, mergekey_init, NULL) 89 90 { NULL, NULL, NULL } 90 91 }; … … 96 97 object_init_ex(getThis(), &merge_key_entry); 97 98 } 98 99 99 100 100 101 static void destroy_MergeKey_resource(zend_rsrc_list_entry *resource TSRMLS_DC) … … 110 111 PHP_MINIT_FUNCTION(syck) 111 112 { 112 le_mergekeyp = zend_register_list_destructors_ex(destroy_MergeKey_resource, NULL, "MergeKey", module_number);113 le_mergekeyp = zend_register_list_destructors_ex(destroy_MergeKey_resource, NULL, "MergeKey", module_number); 113 114 114 115 INIT_CLASS_ENTRY(merge_key_entry, "mergekey", mergekey_functions); … … 168 169 169 170 170 SYMID 171 php_syck_handler(p, n) 172 SyckParser *p; 173 SyckNode *n; 174 { 175 SYMID oid; 176 zval *o, *o2, *o3; 177 unsigned int i; 171 SYMID php_syck_handler(SyckParser *p, SyckNode *n) 172 { 173 SYMID oid; 174 zval *o, *o2, *o3; 175 unsigned int i; 178 176 179 177 MAKE_STD_ZVAL(o); 180 switch (n->kind)181 {182 case syck_str_kind:183 if ( n->type_id == NULL || strcmp( n->type_id, "str" ) == 0 )184 {178 switch (n->kind) 179 { 180 case syck_str_kind: 181 if ( n->type_id == NULL || strcmp( n->type_id, "str" ) == 0 ) 182 { 185 183 ZVAL_STRINGL( o, n->data.str->ptr, n->data.str->len, 1); 186 }187 else if ( strcmp( n->type_id, "null" ) == 0 )188 {189 ZVAL_NULL( o );190 }191 else if ( strcmp( n->type_id, "bool#yes" ) == 0 )192 {184 } 185 else if ( strcmp( n->type_id, "null" ) == 0 ) 186 { 187 ZVAL_NULL( o ); 188 } 189 else if ( strcmp( n->type_id, "bool#yes" ) == 0 ) 190 { 193 191 ZVAL_BOOL( o, 1 ); 194 }195 else if ( strcmp( n->type_id, "bool#no" ) == 0 )196 {192 } 193 else if ( strcmp( n->type_id, "bool#no" ) == 0 ) 194 { 197 195 ZVAL_BOOL( o, 0 ); 198 }199 else if ( strcmp( n->type_id, "int#hex" ) == 0 )200 {196 } 197 else if ( strcmp( n->type_id, "int#hex" ) == 0 ) 198 { 201 199 long intVal = strtol( n->data.str->ptr, NULL, 16 ); 202 200 ZVAL_LONG( o, intVal ); 203 }204 else if ( strcmp( n->type_id, "int#oct" ) == 0 )205 {201 } 202 else if ( strcmp( n->type_id, "int#oct" ) == 0 ) 203 { 206 204 long intVal = strtol( n->data.str->ptr, NULL, 8 ); 207 205 ZVAL_LONG( o, intVal ); 208 }209 else if ( strcmp( n->type_id, "int" ) == 0 )210 {206 } 207 else if ( strcmp( n->type_id, "int" ) == 0 ) 208 { 211 209 long intVal = strtol( n->data.str->ptr, NULL, 10 ); 212 210 ZVAL_LONG( o, intVal ); 213 }214 else if ( strcmp( n->type_id, "float" ) == 0 )215 {216 double f;217 syck_str_blow_away_commas( n );218 f = strtod( n->data.str->ptr, NULL );211 } 212 else if ( strcmp( n->type_id, "float" ) == 0 ) 213 { 214 double f; 215 syck_str_blow_away_commas( n ); 216 f = strtod( n->data.str->ptr, NULL ); 219 217 ZVAL_DOUBLE( o, f ); 220 } 221 else if ( strcmp( n->type_id, "float#nan" ) == 0 ) 222 { 223 ZVAL_DOUBLE( o, nan() ); 224 } 225 else if ( strcmp( n->type_id, "float#inf" ) == 0 ) 226 { 227 ZVAL_DOUBLE( o, inf() ); 228 } 229 else if ( strcmp( n->type_id, "float#neginf" ) == 0 ) 230 { 231 ZVAL_DOUBLE( o, -inf() ); 232 } 233 else if ( strcmp( n->type_id, "merge" ) == 0 ) 234 { 218 } 219 else if ( strcmp( n->type_id, "float#nan" ) == 0 ) 220 { 221 ZVAL_DOUBLE( o, nanphp() ); 222 } 223 else if ( strcmp( n->type_id, "float#inf" ) == 0 ) 224 { 225 ZVAL_DOUBLE( o, inf() ); 226 } 227 else if ( strcmp( n->type_id, "float#neginf" ) == 0 ) 228 { 229 ZVAL_DOUBLE( o, -inf() ); 230 } 231 else if ( strcmp( n->type_id, "merge" ) == 0 ) 232 { 233 TSRMLS_FETCH(); 235 234 MAKE_STD_ZVAL( o ); 236 235 object_init_ex( o, &merge_key_entry ); 237 }238 else239 {236 } 237 else 238 { 240 239 ZVAL_STRINGL(o, n->data.str->ptr, n->data.str->len, 1); 241 }242 break;243 244 case syck_seq_kind:240 } 241 break; 242 243 case syck_seq_kind: 245 244 array_init(o); 246 for ( i = 0; i < n->data.list->idx; i++ )247 {248 oid = syck_seq_read( n, i );249 syck_lookup_sym( p, oid, &o2 );245 for ( i = 0; i < n->data.list->idx; i++ ) 246 { 247 oid = syck_seq_read( n, i ); 248 syck_lookup_sym( p, oid, &o2 ); 250 249 add_index_zval( o, i, o2 ); 251 }252 break;253 254 case syck_map_kind:250 } 251 break; 252 253 case syck_map_kind: 255 254 array_init(o); 256 for ( i = 0; i < n->data.pairs->idx; i++ )257 {258 oid = syck_map_read( n, map_key, i );259 syck_lookup_sym( p, oid, &o2 );260 oid = syck_map_read( n, map_value, i );261 syck_lookup_sym( p, oid, &o3 );255 for ( i = 0; i < n->data.pairs->idx; i++ ) 256 { 257 oid = syck_map_read( n, map_key, i ); 258 syck_lookup_sym( p, oid, &o2 ); 259 oid = syck_map_read( n, map_value, i ); 260 syck_lookup_sym( p, oid, &o3 ); 262 261 if ( o2->type == IS_STRING ) 263 262 { 264 263 add_assoc_zval( o, o2->value.str.val, o3 ); 265 264 } 266 } 267 break; 268 } 269 oid = syck_add_sym( p, o ); 270 return oid; 265 } 266 break; 267 } 268 oid = syck_add_sym( p, o ); 269 return oid; 270 } 271 272 void php_syck_ehandler(SyckParser *p, char *str) 273 { 274 TSRMLS_FETCH(); 275 zend_class_entry *exc = zend_get_error_exception(); 276 zend_throw_error_exception(exc, str, 1, 1 TSRMLS_CC); 271 277 } 272 278 … … 287 293 288 294 parser = syck_new_parser(); 289 syck_parser_str( parser, arg, arg_len, NULL ); 290 syck_parser_handler( parser, php_syck_handler ); 291 syck_parser_implicit_typing( parser, 1 ); 292 syck_parser_taguri_expansion( parser, 0 ); 293 v = syck_parse( parser ); 294 syck_lookup_sym( parser, v, &obj ); 295 syck_free_parser( parser ); 296 297 *return_value = *obj; 298 zval_copy_ctor(return_value); 295 296 syck_parser_handler( parser, php_syck_handler ); 297 syck_parser_error_handler( parser, php_syck_ehandler ); 298 299 syck_parser_implicit_typing( parser, 1 ); 300 syck_parser_taguri_expansion( parser, 0 ); 301 302 syck_parser_str( parser, arg, arg_len, NULL ); 303 304 v = syck_parse( parser ); 305 306 if (1 == syck_lookup_sym( parser, v, &obj )) { 307 *return_value = *obj; 308 zval_copy_ctor(return_value); 309 } 310 311 syck_free_parser( parser ); 299 312 } 300 313 /* }}} */