2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2021, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
18 #include "ext/standard/info.h"
20 #include "Zend/zend_enum.h"
21 #include "Zend/zend_exceptions.h"
22 #include "Zend/zend_closures.h"
23 #include "Zend/zend_interfaces.h"
24 #include "Zend/zend_smart_str.h"
26 #include "ext/date/php_date.h"
27 #include "ext/spl/spl_exceptions.h"
28 #include "ext/spl/spl_iterators.h"
31 #include "ion_private.h"
33 static ZEND_METHOD(ion_Symbol_ImportLocation
, __construct
)
35 php_ion_symbol_iloc
*obj
= php_ion_obj(symbol_iloc
, Z_OBJ_P(ZEND_THIS
));
39 ZEND_PARSE_PARAMETERS_START(2, 2)
40 Z_PARAM_STR(obj
->name
)
41 Z_PARAM_LONG(location
)
42 ZEND_PARSE_PARAMETERS_END();
44 obj
->loc
.location
= location
;
45 php_ion_symbol_iloc_ctor(obj
);
47 static ZEND_METHOD(ion_Symbol
, __construct
)
49 php_ion_symbol
*obj
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
53 ZEND_PARSE_PARAMETERS_START(0, 3)
55 Z_PARAM_STR_OR_NULL(obj
->value
)
57 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->iloc
, ce_Symbol_ImportLocation
)
58 ZEND_PARSE_PARAMETERS_END();
61 php_ion_symbol_ctor(obj
);
63 static ZEND_METHOD(ion_Symbol
, equals
)
65 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
68 zend_object
*other_obj
;
69 ZEND_PARSE_PARAMETERS_START(1, 1)
70 Z_PARAM_OBJ_OF_CLASS(other_obj
, ce_Symbol
)
71 ZEND_PARSE_PARAMETERS_END();
74 iERR err
= ion_symbol_is_equal(
76 &php_ion_obj(symbol
, other_obj
)->sym
, &eq
);
80 static ZEND_METHOD(ion_Symbol
, __toString
)
82 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
85 ZEND_PARSE_PARAMETERS_NONE();
88 RETURN_EMPTY_STRING();
90 RETURN_STR_COPY(sym
->value
);
92 static ZEND_METHOD(ion_Symbol_Enum
, toSymbol
)
94 ZEND_PARSE_PARAMETERS_NONE();
96 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
99 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
101 RETVAL_ZVAL(zsym
, 1, 0);
103 static ZEND_METHOD(ion_Symbol_Enum
, toSID
)
105 ZEND_PARSE_PARAMETERS_NONE();
107 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
110 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
114 RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym
), Z_OBJ_P(zsym
), ZEND_STRL("sid"), 0, &tmp
), 1, 0);
116 static ZEND_METHOD(ion_Symbol_Enum
, toString
)
118 ZEND_PARSE_PARAMETERS_NONE();
120 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
123 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
127 RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym
), Z_OBJ_P(zsym
), ZEND_STRL("value"), 0, &tmp
), 1, 0);
129 static ZEND_FUNCTION(ion_Symbol_Table_System
)
131 ZEND_PARSE_PARAMETERS_NONE();
133 object_init_ex(return_value
, ce_Symbol_Table_Shared
);
134 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(return_value
));
135 ION_CHECK(ion_symbol_table_get_system_table(&obj
->tab
, 1));
136 php_ion_symbol_table_ctor(obj
);
137 ion_symbol_table_lock(obj
->tab
);
139 static ZEND_FUNCTION(ion_Symbol_Table_PHP
)
141 ZEND_PARSE_PARAMETERS_NONE();
143 object_init_ex(return_value
, ce_Symbol_Table_Shared
);
144 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(return_value
));
145 obj
->tab
= g_sym_tab_php
;
146 php_ion_symbol_table_ctor(obj
);
147 ion_symbol_table_lock(obj
->tab
);
149 static ZEND_METHOD(ion_Symbol_Table_Local
, __construct
)
151 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
154 ZEND_PARSE_PARAMETERS_NONE();
156 ION_CHECK(ion_symbol_table_open_with_type(&obj
->tab
, NULL
, ist_LOCAL
));
157 obj
->dtor
= ion_symbol_table_close
;
160 static ZEND_METHOD(ion_Symbol_Table_Local
, import
)
162 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
165 zend_object
*zo_import
;
166 ZEND_PARSE_PARAMETERS_START(1, 1)
167 Z_PARAM_OBJ_OF_CLASS(zo_import
, ce_Symbol_Table
);
168 ZEND_PARSE_PARAMETERS_END();
170 php_ion_symbol_table_import(obj
, php_ion_obj(symbol_table
, zo_import
));
172 static ZEND_METHOD(ion_Symbol_Table_Shared
, __construct
)
174 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
178 zend_long version
= 1;
179 HashTable
*ht_sym
= NULL
;
180 ZEND_PARSE_PARAMETERS_START(1, 3)
183 Z_PARAM_LONG(version
)
184 Z_PARAM_ARRAY_HT_OR_NULL(ht_sym
)
185 ZEND_PARSE_PARAMETERS_END();
187 ION_CHECK(ion_symbol_table_open_with_type(&obj
->tab
, NULL
, ist_SHARED
));
188 obj
->dtor
= ion_symbol_table_close
;
191 ION_CHECK(ion_symbol_table_set_name(obj
->tab
, ion_string_from_zend(&is
, zname
)));
192 ION_CHECK(ion_symbol_table_set_version(obj
->tab
, version
));
194 php_ion_symbol_table_ctor(obj
);
197 if (ht_sym
) ZEND_HASH_FOREACH_VAL(ht_sym
, zsym
)
199 zend_string
*str
= zval_get_string(zsym
);
205 ION_CHECK(ion_symbol_table_add_symbol(obj
->tab
, ion_string_from_zend(&is
, str
), NULL
), zend_string_release(str
));
206 zend_string_release(str
);
208 ZEND_HASH_FOREACH_END();
210 static ZEND_METHOD(ion_Symbol_Table
, getMaxId
)
212 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
215 ZEND_PARSE_PARAMETERS_NONE();
218 ION_CHECK(ion_symbol_table_get_max_sid(obj
->tab
, &max_sid
));
219 RETURN_LONG(max_sid
);
221 static ZEND_METHOD(ion_Symbol_Table
, add
)
223 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
226 zend_object
*zo_sym
= NULL
;
227 zend_string
*zs_sym
= NULL
;
228 ZEND_PARSE_PARAMETERS_START(1, 1)
229 Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_sym
, ce_Symbol
, zs_sym
)
230 ZEND_PARSE_PARAMETERS_END();
234 ZVAL_OBJ(&z_sym
, zo_sym
);
235 zs_sym
= zval_get_string(&z_sym
);
240 ION_CHECK(ion_symbol_table_add_symbol(obj
->tab
, ion_string_from_zend(&is
, zs_sym
), &sid
),
242 zend_string_release(zs_sym
);
245 zend_string_release(zs_sym
);
249 static ZEND_METHOD(ion_Symbol_Table
, find
)
251 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
255 zend_string
*zstring
= NULL
;
256 ZEND_PARSE_PARAMETERS_START(1, 1)
257 Z_PARAM_STR_OR_LONG(zstring
, zsid
)
258 ZEND_PARSE_PARAMETERS_END();
263 ION_CHECK(ion_symbol_table_find_by_name(obj
->tab
, ion_string_from_zend(&is
, zstring
), &sid
));
267 ION_CHECK(ion_symbol_table_get_symbol(obj
->tab
, zsid
, &sym
));
269 php_ion_symbol_table_symbol_zval(obj
, sym
, return_value
);
272 static ZEND_METHOD(ion_Symbol_Table
, findLocal
)
274 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
278 zend_string
*zstring
;
279 ZEND_PARSE_PARAMETERS_START(1, 1)
280 Z_PARAM_STR_OR_LONG(zstring
, zsid
)
281 ZEND_PARSE_PARAMETERS_END();
286 ION_CHECK(ion_symbol_table_find_by_name(obj
->tab
, ion_string_from_zend(&is
, zstring
), &sid
));
290 ION_CHECK(ion_symbol_table_get_local_symbol(obj
->tab
, zsid
, &sym
));
292 php_ion_symbol_table_symbol_zval(obj
, sym
, return_value
);
295 static ZEND_METHOD(ion_Catalog
, __construct
)
297 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
300 ZEND_PARSE_PARAMETERS_NONE();
302 php_ion_catalog_ctor(obj
);
304 static ZEND_METHOD(ion_Catalog
, count
)
306 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
309 ZEND_PARSE_PARAMETERS_NONE();
312 ION_CHECK(ion_catalog_get_symbol_table_count(obj
->cat
, &c
));
315 static ZEND_METHOD(ion_Catalog
, add
)
317 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
320 zend_object
*zo_symtab
;
321 ZEND_PARSE_PARAMETERS_START(1, 1)
322 Z_PARAM_OBJ_OF_CLASS(zo_symtab
, ce_Symbol_Table
)
323 ZEND_PARSE_PARAMETERS_END();
325 php_ion_symbol_table
*o_symtab
= php_ion_obj(symbol_table
, zo_symtab
);
326 php_ion_catalog_add_symbol_table(obj
, o_symtab
);
328 struct remove_symtab_ctx
{
332 static int remove_symtab(zval
*ztab
, void *ctx
)
334 struct remove_symtab_ctx
*rsc
= ctx
;
335 php_ion_symbol_table
*tab
= php_ion_obj(symbol_table
, Z_OBJ_P(ztab
));
336 if (tab
&& tab
->tab
) {
338 if (IERR_OK
== ion_symbol_table_get_name(tab
->tab
, &is
)) {
339 if (strcmp((const char *) is
.value
, rsc
->name
)) {
340 return ZEND_HASH_APPLY_KEEP
;
345 return ZEND_HASH_APPLY_REMOVE
;
348 static ZEND_METHOD(ion_Catalog
, remove
)
350 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
353 zend_object
*zo_symtab
= NULL
;
354 zend_string
*zs_symtab
= NULL
;
355 ZEND_PARSE_PARAMETERS_START(1, 1)
356 Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_symtab
, ce_Symbol_Table
, zs_symtab
)
357 ZEND_PARSE_PARAMETERS_END();
362 zval
*ztabs
= zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("symbolTables"), 0, &tmp
);
366 zend_ulong idx
= (uintptr_t) &zo_symtab
->gc
;
367 RETURN_BOOL(SUCCESS
== zend_hash_index_del(Z_ARRVAL_P(ztabs
), idx
));
369 // iterate over all symbol tables and delete any with matching name
370 struct remove_symtab_ctx ctx
= {zs_symtab
->val
, false};
371 zend_hash_apply_with_argument(Z_ARRVAL_P(ztabs
), remove_symtab
, &ctx
);
372 RETURN_BOOL(ctx
.deleted
);
376 static ZEND_METHOD(ion_Catalog
, find
)
378 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
381 zend_long zversion
= 0;
383 ZEND_PARSE_PARAMETERS_START(1, 2)
386 Z_PARAM_LONG(zversion
)
387 ZEND_PARSE_PARAMETERS_END();
390 ION_SYMBOL_TABLE
*tab_ptr
= NULL
;
391 ION_CHECK(ion_catalog_find_symbol_table(obj
->cat
, ion_string_from_zend(&is
, zname
), zversion
, &tab_ptr
));
393 php_ion_catalog_symbol_table_zval(obj
, tab_ptr
, return_value
);
396 static ZEND_METHOD(ion_Catalog
, findBest
)
398 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
401 zend_long zversion
= 0;
403 ZEND_PARSE_PARAMETERS_START(1, 2)
406 Z_PARAM_LONG(zversion
)
407 ZEND_PARSE_PARAMETERS_END();
410 ION_SYMBOL_TABLE
*tab_ptr
= NULL
;
411 ION_CHECK(ion_catalog_find_best_match(obj
->cat
, ion_string_from_zend(&is
, zname
), zversion
, &tab_ptr
));
413 php_ion_catalog_symbol_table_zval(obj
, tab_ptr
, return_value
);
416 static ZEND_METHOD(ion_Timestamp
, __construct
)
418 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
422 zend_object
*precision_obj
;
423 zend_string
*fmt
= NULL
, *dt
= NULL
;
425 ZEND_PARSE_PARAMETERS_START(1, 4)
426 Z_PARAM_OBJ_OF_CLASS_OR_LONG(precision_obj
, ce_Timestamp_Precision
, precision
)
428 Z_PARAM_STR_OR_NULL(fmt
)
429 Z_PARAM_STR_OR_NULL(dt
)
431 ZEND_PARSE_PARAMETERS_END();
434 precision
= Z_LVAL_P(zend_enum_fetch_case_value(precision_obj
));
436 php_ion_timestamp_ctor(obj
, precision
, fmt
, dt
, tz
);
438 static ZEND_METHOD(ion_Timestamp
, __toString
)
440 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
443 ZEND_PARSE_PARAMETERS_NONE();
447 zend_call_method_with_1_params(&obj
->std
, obj
->std
.ce
, NULL
, "format", return_value
,
448 zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("format"), 0, &fmt
));
450 static ZEND_METHOD(ion_Decimal_Context
, __construct
)
452 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(ZEND_THIS
));
456 zend_object
*o_round
= NULL
;
457 zend_long digits
, emax
, emin
, round
;
458 ZEND_PARSE_PARAMETERS_START(5, 5)
462 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
464 ZEND_PARSE_PARAMETERS_END();
467 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
469 php_ion_decimal_ctx_init(&obj
->ctx
, digits
, emax
, emin
, round
, clamp
);
470 php_ion_decimal_ctx_ctor(obj
, o_round
);
472 static inline void make_decimal_ctx(INTERNAL_FUNCTION_PARAMETERS
, int kind
)
474 ZEND_PARSE_PARAMETERS_NONE();
476 object_init_ex(return_value
, ce_Decimal_Context
);
477 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
478 decContextDefault(&obj
->ctx
, kind
);
479 php_ion_decimal_ctx_ctor(obj
, NULL
);
481 static ZEND_METHOD(ion_Decimal_Context
, Dec32
)
483 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL32
);
485 static ZEND_METHOD(ion_Decimal_Context
, Dec64
)
487 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL64
);
489 static ZEND_METHOD(ion_Decimal_Context
, Dec128
)
491 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL128
);
493 static ZEND_METHOD(ion_Decimal_Context
, DecMax
)
495 zend_object
*o_round
= NULL
;
496 zend_long round
= DEC_ROUND_HALF_EVEN
;
497 ZEND_PARSE_PARAMETERS_START(0, 1)
499 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
500 ZEND_PARSE_PARAMETERS_END();
503 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
505 object_init_ex(return_value
, ce_Decimal_Context
);
506 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
507 php_ion_decimal_ctx_init_max(&obj
->ctx
, round
);
508 php_ion_decimal_ctx_ctor(obj
, o_round
);
510 static ZEND_METHOD(ion_Decimal
, __construct
)
512 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
517 ZEND_PARSE_PARAMETERS_START(1, 2)
518 Z_PARAM_STR_OR_LONG(zstr
, num
)
520 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->ctx
, ce_Decimal_Context
)
521 ZEND_PARSE_PARAMETERS_END();
527 object_init_ex(&zdc
, ce_Decimal_Context
);
528 obj
->ctx
= Z_OBJ(zdc
);
529 php_ion_decimal_ctx_ctor(php_ion_obj(decimal_ctx
, obj
->ctx
), NULL
);
532 decContext
*ctx
= &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
;
535 ION_CHECK(ion_decimal_from_string(&obj
->dec
, zstr
->val
, ctx
), OBJ_RELEASE(obj
->ctx
));
537 php_ion_decimal_from_zend_long(&obj
->dec
, ctx
, num
);
540 php_ion_decimal_ctor(obj
);
541 OBJ_RELEASE(obj
->ctx
);
543 static ZEND_METHOD(ion_Decimal
, equals
)
545 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
548 zend_object
*dec_obj
;
549 ZEND_PARSE_PARAMETERS_START(1, 1)
550 Z_PARAM_OBJ_OF_CLASS(dec_obj
, ce_Decimal
)
551 ZEND_PARSE_PARAMETERS_END();
554 ION_CHECK(ion_decimal_equals(&obj
->dec
, &php_ion_obj(decimal
, dec_obj
)->dec
,
555 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &is
));
558 static ZEND_METHOD(ion_Decimal
, __toString
)
560 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
563 ZEND_PARSE_PARAMETERS_NONE();
565 RETURN_STR(php_ion_decimal_to_string(&obj
->dec
));
567 static ZEND_METHOD(ion_Decimal
, toInt
)
569 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
572 ZEND_PARSE_PARAMETERS_NONE();
575 php_ion_decimal_to_zend_long(&obj
->dec
, &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
, &l
);
578 static ZEND_METHOD(ion_Decimal
, isInt
)
580 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
583 ZEND_PARSE_PARAMETERS_NONE();
585 RETURN_BOOL(ion_decimal_is_integer(&obj
->dec
));
587 static ZEND_METHOD(ion_LOB
, __construct
)
590 zend_object
*type
= NULL
;
591 ZEND_PARSE_PARAMETERS_START(1, 2)
594 Z_PARAM_OBJ_OF_CLASS(type
, ce_Type
)
595 ZEND_PARSE_PARAMETERS_END();
598 type
= zend_enum_get_case_cstr(ce_Type
, "CLob");
600 update_property_obj(Z_OBJ_P(ZEND_THIS
), ZEND_STRL("type"), type
);
601 zend_update_property_str(Z_OBJCE_P(ZEND_THIS
), Z_OBJ_P(ZEND_THIS
), ZEND_STRL("value"), value
);
603 static ZEND_METHOD(ion_Reader_Options
, __construct
)
605 php_ion_reader_options
*opt
= php_ion_obj(reader_options
, Z_OBJ_P(ZEND_THIS
));
606 zend_bool ret_sys_val
= false, skip_validation
= false;
607 zend_long ch_nl
= 0xa, max_depth
= 10, max_ann
= 10, max_ann_buf
= 512,
608 sym_thr
= 0x4000, uval_thr
= 0x4000, chunk_thr
= 0x4000, alloc_pgsz
= 0x10000;
612 ZEND_PARSE_PARAMETERS_START(0, 13)
614 // public readonly ?\ion\Catalog $catalog = null,
615 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cat
, ce_Catalog
)
616 // public readonly ?\ion\Decimal\Context $decimalContext = null,
617 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->dec_ctx
, ce_Decimal_Context
)
618 // public readonly ?\Closure $onContextChange = null,
619 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cb
, zend_ce_closure
);
620 // public readonly bool $returnSystemValues = false,
621 Z_PARAM_BOOL(ret_sys_val
)
622 // public readonly int $newLine = 0xa,
624 // public readonly int $maxContainerDepth = 10,
625 Z_PARAM_LONG(max_depth
)
626 // public readonly int $maxAnnotations = 10,
627 Z_PARAM_LONG(max_ann
)
628 // public readonly int $maxAnnotationBuffered = 512,
629 Z_PARAM_LONG(max_ann_buf
)
630 // public readonly int $symbolThreshold = 0x4000,
631 Z_PARAM_LONG(sym_thr
)
632 // public readonly int $userValueThreshold = 0x4000,
633 Z_PARAM_LONG(uval_thr
)
634 // public readonly int $chunkThreshold = 0x4000,
635 Z_PARAM_LONG(chunk_thr
)
636 // public readonly int $allocationPageSize = 0x10000,
637 Z_PARAM_LONG(alloc_pgsz
)
638 // public readonly bool $skipCharacterValidation = false,
639 Z_PARAM_BOOL(skip_validation
)
640 ZEND_PARSE_PARAMETERS_END();
642 opt
->opt
.context_change_notifier
= EMPTY_READER_CHANGE_NOTIFIER
;
644 update_property_obj(&opt
->std
, ZEND_STRL("onContextChange"), opt
->cb
);
647 update_property_obj(&opt
->std
, ZEND_STRL("catalog"), opt
->cat
);
648 opt
->opt
.pcatalog
= php_ion_obj(catalog
, opt
->cat
)->cat
;
651 update_property_obj(&opt
->std
, ZEND_STRL("decimalContext"), opt
->dec_ctx
);
652 opt
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, opt
->dec_ctx
)->ctx
;
654 zend_update_property_bool(opt
->std
.ce
, &opt
->std
, ZEND_STRL("returnSystemValues"),
655 opt
->opt
.return_system_values
= ret_sys_val
);
656 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("newLine"),
657 opt
->opt
.new_line_char
= ch_nl
);
658 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxContainerDepth"),
659 opt
->opt
.max_container_depth
= max_depth
);
660 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationCount"),
661 opt
->opt
.max_annotation_count
= max_ann
);
662 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationBuffered"),
663 opt
->opt
.max_annotation_buffered
= max_ann_buf
);
664 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("symbolThreshold"),
665 opt
->opt
.symbol_threshold
= sym_thr
);
666 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("userValueThreshold"),
667 opt
->opt
.user_value_threshold
= uval_thr
);
668 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("chunkThreshold"),
669 opt
->opt
.chunk_threshold
= chunk_thr
);
670 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("allocationPageSize"),
671 opt
->opt
.allocation_page_size
= alloc_pgsz
);
672 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("skipCharacterValidation"),
673 opt
->opt
.skip_character_validation
= skip_validation
);
675 static ZEND_METHOD(ion_Reader_Reader
, hasChildren
)
677 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
680 ZEND_PARSE_PARAMETERS_NONE();
683 ION_CHECK(ion_reader_get_type(obj
->reader
, &t
));
684 switch (ION_TYPE_INT(t
)) {
695 static ZEND_METHOD(ion_Reader_Reader
, getChildren
)
697 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
700 ZEND_PARSE_PARAMETERS_NONE();
702 ION_CHECK(ion_reader_step_in(obj
->reader
));
704 RETURN_ZVAL(ZEND_THIS
, 1, 0);
706 static ZEND_METHOD(ion_Reader_Reader
, rewind
)
708 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
711 ZEND_PARSE_PARAMETERS_NONE();
713 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
715 static ZEND_METHOD(ion_Reader_Reader
, next
)
717 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
720 ZEND_PARSE_PARAMETERS_NONE();
722 if (obj
->state
== tid_EOF
) {
724 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
726 ION_CHECK(ion_reader_step_out(obj
->reader
));
729 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
731 static ZEND_METHOD(ion_Reader_Reader
, valid
)
733 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
736 ZEND_PARSE_PARAMETERS_NONE();
737 RETURN_BOOL(obj
->state
!= tid_none
&& obj
->state
!= tid_EOF
);
739 static ZEND_METHOD(ion_Reader_Reader
, key
)
741 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
744 ZEND_PARSE_PARAMETERS_NONE();
745 RETURN_IONTYPE(obj
->state
);
747 static ZEND_METHOD(ion_Reader_Reader
, current
)
749 ZEND_PARSE_PARAMETERS_NONE();
750 RETURN_ZVAL(ZEND_THIS
, 1, 0);
752 static ZEND_METHOD(ion_Reader_Reader
, getType
)
754 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
757 ZEND_PARSE_PARAMETERS_NONE();
760 ION_CHECK(ion_reader_get_type(obj
->reader
, &typ
));
763 static ZEND_METHOD(ion_Reader_Reader
, hasAnnotations
)
765 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
768 ZEND_PARSE_PARAMETERS_NONE();
771 ION_CHECK(ion_reader_has_any_annotations(obj
->reader
, &has
));
774 static ZEND_METHOD(ion_Reader_Reader
, hasAnnotation
)
776 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
779 zend_string
*ann_zstr
;
780 ZEND_PARSE_PARAMETERS_START(1, 1);
781 Z_PARAM_STR(ann_zstr
);
782 ZEND_PARSE_PARAMETERS_END();
786 ION_CHECK(ion_reader_has_annotation(obj
->reader
, ion_string_from_zend(&ann_istr
, ann_zstr
), &has
));
789 static ZEND_METHOD(ion_Reader_Reader
, isNull
)
791 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
794 ZEND_PARSE_PARAMETERS_NONE();
797 ION_CHECK(ion_reader_is_null(obj
->reader
, &is
));
800 static ZEND_METHOD(ion_Reader_Reader
, isInStruct
)
802 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
805 ZEND_PARSE_PARAMETERS_NONE();
808 ION_CHECK(ion_reader_is_in_struct(obj
->reader
, &is
));
811 static ZEND_METHOD(ion_Reader_Reader
, getFieldName
)
813 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
816 ZEND_PARSE_PARAMETERS_NONE();
819 ION_CHECK(ion_reader_get_field_name(obj
->reader
, &name
));
820 RETURN_STRINGL((char *) name
.value
, name
.length
);
822 static ZEND_METHOD(ion_Reader_Reader
, getFieldNameSymbol
)
824 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
827 ZEND_PARSE_PARAMETERS_NONE();
830 ION_CHECK(ion_reader_get_field_name_symbol(obj
->reader
, &sym_ptr
));
832 php_ion_symbol_zval(sym_ptr
, return_value
);
834 static ZEND_METHOD(ion_Reader_Reader
, getAnnotations
)
836 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
839 ZEND_PARSE_PARAMETERS_NONE();
843 max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
847 ION_STRING
*ptr
= ecalloc(sizeof(*ptr
), max
);
848 iERR err
= ion_reader_get_annotations(obj
->reader
, ptr
, max
, &count
);
850 array_init_size(return_value
, count
);
851 for (int32_t i
= 0; i
< count
; ++i
) {
852 add_next_index_str(return_value
, zend_string_from_ion(&ptr
[i
]));
858 static ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbols
)
860 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
863 ZEND_PARSE_PARAMETERS_NONE();
865 int32_t count
, max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
866 ION_SYMBOL
*ptr
= ecalloc(sizeof(*ptr
), max
);
867 iERR err
= ion_reader_get_annotation_symbols(obj
->reader
, ptr
, max
, &count
);
869 array_init_size(return_value
, count
);
870 for (int32_t i
= 0; i
< count
; ++i
) {
872 php_ion_symbol_zval(&ptr
[i
], &zsym
);
873 add_next_index_zval(return_value
, &zsym
);
879 static ZEND_METHOD(ion_Reader_Reader
, countAnnotations
)
881 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
884 ZEND_PARSE_PARAMETERS_NONE();
887 ION_CHECK(ion_reader_get_annotation_count(obj
->reader
, &sz
));
890 static ZEND_METHOD(ion_Reader_Reader
, getAnnotation
)
892 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
896 ZEND_PARSE_PARAMETERS_START(1, 1)
898 ZEND_PARSE_PARAMETERS_END();
901 ION_CHECK(ion_reader_get_an_annotation(obj
->reader
, idx
, &ann
));
902 RETURN_STRINGL((char *) ann
.value
, ann
.length
);
904 static ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbol
)
906 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
910 ZEND_PARSE_PARAMETERS_START(1, 1)
912 ZEND_PARSE_PARAMETERS_END();
915 ION_CHECK(ion_reader_get_an_annotation_symbol(obj
->reader
, idx
, &sym
));
916 php_ion_symbol_zval(&sym
, return_value
);
918 static ZEND_METHOD(ion_Reader_Reader
, readNull
)
920 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
923 ZEND_PARSE_PARAMETERS_NONE();
926 ION_CHECK(ion_reader_read_null(obj
->reader
, &typ
));
927 RETURN_OBJ_COPY(php_ion_type_fetch(typ
));
929 static ZEND_METHOD(ion_Reader_Reader
, readBool
)
931 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
934 ZEND_PARSE_PARAMETERS_NONE();
937 ION_CHECK(ion_reader_read_bool(obj
->reader
, &b
));
940 static ZEND_METHOD(ion_Reader_Reader
, readInt
)
942 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
945 ZEND_PARSE_PARAMETERS_NONE();
947 php_ion_reader_read_int(obj
->reader
, return_value
);
949 static ZEND_METHOD(ion_Reader_Reader
, readFloat
)
951 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
954 ZEND_PARSE_PARAMETERS_NONE();
956 ION_CHECK(ion_reader_read_double(obj
->reader
, &Z_DVAL_P(return_value
)));
958 static ZEND_METHOD(ion_Reader_Reader
, readDecimal
)
960 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
963 ZEND_PARSE_PARAMETERS_NONE();
965 object_init_ex(return_value
, ce_Decimal
);
966 php_ion_decimal
*dec
= php_ion_obj(decimal
, Z_OBJ_P(return_value
));
967 ION_CHECK(ion_reader_read_ion_decimal(obj
->reader
, &dec
->dec
));
968 php_ion_decimal_ctor(dec
);
970 static ZEND_METHOD(ion_Reader_Reader
, readTimestamp
)
972 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
975 ZEND_PARSE_PARAMETERS_NONE();
977 php_ion_reader_read_timestamp(obj
->reader
, obj
->opt
? &php_ion_obj(reader_options
, obj
->opt
)->opt
: NULL
, return_value
);
979 static ZEND_METHOD(ion_Reader_Reader
, readSymbol
)
981 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
984 ZEND_PARSE_PARAMETERS_NONE();
987 ION_CHECK(ion_reader_read_ion_symbol(obj
->reader
, &sym
));
988 php_ion_symbol_zval(&sym
, return_value
);
990 static ZEND_METHOD(ion_Reader_Reader
, readString
)
992 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
995 ZEND_PARSE_PARAMETERS_NONE();
998 ION_CHECK(ion_reader_read_string(obj
->reader
, &str
));
999 RETURN_STRINGL((char *) str
.value
, str
.length
);
1002 typedef iERR (*read_part_fn
)(ION_READER
*, BYTE
*, SIZE
, SIZE
*);
1003 static void read_part(INTERNAL_FUNCTION_PARAMETERS
, read_part_fn fn
)
1005 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1010 zend_long len
= 0x1000;
1011 ZEND_PARSE_PARAMETERS_START(1, 1)
1015 ZEND_PARSE_PARAMETERS_END();
1019 if (Z_TYPE_P(ref
) == IS_STRING
&& Z_STRLEN_P(ref
) == len
) {
1021 zstr
= Z_STR_P(ref
);
1024 zstr
= zend_string_alloc(len
, 0);
1028 ION_CHECK(fn(obj
->reader
, (BYTE
*) zstr
->val
, zstr
->len
, &read
), goto fail
);
1030 if (read
< zstr
->len
) {
1031 zstr
= zend_string_truncate(zstr
, read
, 0);
1033 ZVAL_STR(ref
, zstr
);
1037 if (zstr
!= Z_STR_P(ref
)) {
1038 zend_string_release(zstr
);
1040 ZVAL_EMPTY_STRING(ref
);
1043 static ZEND_METHOD(ion_Reader_Reader
, readStringPart
)
1045 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_partial_string
);
1047 static ZEND_METHOD(ion_Reader_Reader
, readLob
)
1049 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1052 ZEND_PARSE_PARAMETERS_NONE();
1054 php_ion_reader_read_lob(obj
->reader
, return_value
);
1056 static ZEND_METHOD(ion_Reader_Reader
, readLobPart
)
1058 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_lob_partial_bytes
);
1060 static ZEND_METHOD(ion_Reader_Reader
, getPosition
)
1062 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1065 ZEND_PARSE_PARAMETERS_NONE();
1069 ION_CHECK(ion_reader_get_position(obj
->reader
, &bytes
, &dummy
, &dummy
));
1072 static ZEND_METHOD(ion_Reader_Reader
, getDepth
)
1074 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1077 ZEND_PARSE_PARAMETERS_NONE();
1080 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
1083 static ZEND_METHOD(ion_Reader_Reader
, seek
)
1085 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1088 zend_long off
, len
= -1;
1089 ZEND_PARSE_PARAMETERS_START(1, 2)
1093 ZEND_PARSE_PARAMETERS_END();
1095 ION_CHECK(ion_reader_seek(obj
->reader
, off
, len
));
1097 static ZEND_METHOD(ion_Reader_Reader
, getValueOffset
)
1099 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1102 ZEND_PARSE_PARAMETERS_NONE();
1105 ION_CHECK(ion_reader_get_value_offset(obj
->reader
, &off
));
1108 static ZEND_METHOD(ion_Reader_Reader
, getValueLength
)
1110 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1113 ZEND_PARSE_PARAMETERS_NONE();
1116 ION_CHECK(ion_reader_get_value_length(obj
->reader
, &len
));
1119 static ZEND_METHOD(ion_Reader_Buffer_Reader
, __construct
)
1121 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1125 ZEND_PARSE_PARAMETERS_START(1, 2)
1128 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1129 ZEND_PARSE_PARAMETERS_END();
1131 obj
->type
= BUFFER_READER
;
1132 obj
->buffer
= zend_string_copy(zstr
);
1134 php_ion_reader_ctor(obj
);
1136 static ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
1138 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1141 ZEND_PARSE_PARAMETERS_NONE();
1142 RETURN_STR_COPY(obj
->buffer
);
1145 static ZEND_METHOD(ion_Reader_Stream_Reader
, __construct
)
1147 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1151 ZEND_PARSE_PARAMETERS_START(1, 2)
1152 Z_PARAM_RESOURCE(zstream
)
1154 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1155 ZEND_PARSE_PARAMETERS_END();
1157 obj
->type
= STREAM_READER
;
1158 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1160 php_ion_reader_ctor(obj
);
1162 static ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
1164 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1167 ZEND_PARSE_PARAMETERS_NONE();
1168 PTR_CHECK(obj
->stream
.ptr
);
1170 GC_ADDREF(obj
->stream
.ptr
->res
);
1171 RETURN_RES(obj
->stream
.ptr
->res
);
1173 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
1175 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1179 ZEND_PARSE_PARAMETERS_START(1, 1);
1180 Z_PARAM_RESOURCE(zstream
);
1181 ZEND_PARSE_PARAMETERS_END();
1183 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
1185 if (obj
->stream
.ptr
) {
1186 zend_list_delete(obj
->stream
.ptr
->res
);
1188 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1189 PTR_CHECK(obj
->stream
.ptr
);
1190 Z_ADDREF_P(zstream
);
1192 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
1194 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1199 ZEND_PARSE_PARAMETERS_START(1, 2);
1200 Z_PARAM_RESOURCE(zstream
);
1201 Z_PARAM_LONG(length
)
1202 ZEND_PARSE_PARAMETERS_END();
1204 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
1206 if (obj
->stream
.ptr
) {
1207 zend_list_delete(obj
->stream
.ptr
->res
);
1209 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1210 PTR_CHECK(obj
->stream
.ptr
);
1211 Z_ADDREF_P(zstream
);
1213 static ZEND_METHOD(ion_Writer_Options
, __construct
)
1215 php_ion_writer_options
*obj
= php_ion_obj(writer_options
, Z_OBJ_P(ZEND_THIS
));
1218 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
1219 tabs
= true, small_cntr_inl
= true, suppress_sys
= false, flush
= false;
1220 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x4000, alloc
= 0x10000;
1221 ZEND_PARSE_PARAMETERS_START(0, 16)
1223 //public readonly ?\ion\Catalog $catalog = null,
1224 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
1225 //public readonly ?\ion\Collection $encodingSymbolTable = null,
1226 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->col
, ce_Collection
)
1227 //public readonly ?\ion\Decimal\Context $decimalContext = null,
1228 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
1229 //public readonly bool $outputBinary = false,
1230 Z_PARAM_BOOL(binary
)
1231 //public readonly bool $compactFloats = false,
1232 Z_PARAM_BOOL(compact_floats
)
1233 //public readonly bool $escapeNonAscii = false,
1234 Z_PARAM_BOOL(escape
)
1235 //public readonly bool $prettyPrint = false,
1236 Z_PARAM_BOOL(pretty
)
1237 //public readonly bool $indentTabs = true,
1239 //public readonly int $indentSize = 2,
1240 Z_PARAM_LONG(indent
)
1241 //public readonly bool $smallContainersInline = true,
1242 Z_PARAM_BOOL(small_cntr_inl
)
1243 //public readonly bool $suppressSystemValues = false,
1244 Z_PARAM_BOOL(suppress_sys
)
1245 //public readonly bool $flushEveryValue = false,
1247 //public readonly int $maxContainerDepth = 10,
1248 Z_PARAM_LONG(max_depth
)
1249 //public readonly int $maxAnnotations = 10,
1250 Z_PARAM_LONG(max_ann
)
1251 //public readonly int $tempBufferSize = 0x4000,
1253 //public readonly int $allocationPageSize = 0x10000,
1255 ZEND_PARSE_PARAMETERS_END();
1258 update_property_obj(&obj
->std
, ZEND_STRL("catalog"), obj
->cat
);
1259 obj
->opt
.pcatalog
= php_ion_obj(catalog
, obj
->cat
)->cat
;
1265 update_property_obj(&obj
->std
, ZEND_STRL("decimalContext"), obj
->dec_ctx
);
1266 obj
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, obj
->dec_ctx
)->ctx
;
1268 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("outputBinary"),
1269 obj
->opt
.output_as_binary
= binary
);
1270 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("comactFloats"),
1271 obj
->opt
.compact_floats
= compact_floats
);
1272 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("excapeNonAscii"),
1273 obj
->opt
.escape_all_non_ascii
= escape
);
1274 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("prettyPrint"),
1275 obj
->opt
.pretty_print
= pretty
);
1276 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentTabs"),
1277 obj
->opt
.indent_with_tabs
= tabs
);
1278 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentSize"),
1279 obj
->opt
.indent_size
= indent
);
1280 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("smallContainersInline"),
1281 obj
->opt
.small_containers_in_line
= small_cntr_inl
);
1282 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("suppressSystemValues"),
1283 obj
->opt
.supress_system_values
= suppress_sys
);
1284 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("flushEveryValue"),
1285 obj
->opt
.flush_every_value
= flush
);
1286 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxContainerDepth"),
1287 obj
->opt
.max_container_depth
= max_depth
);
1288 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxAnnotations"),
1289 obj
->opt
.max_annotation_count
= max_ann
);
1290 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("tempBufferSize"),
1291 obj
->opt
.temp_buffer_size
= temp
);
1292 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("allocationPageSize"),
1293 obj
->opt
.allocation_page_size
= alloc
);
1295 static ZEND_METHOD(ion_Writer_Writer
, writeNull
)
1297 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1300 ZEND_PARSE_PARAMETERS_NONE();
1302 ION_CHECK(ion_writer_write_null(obj
->writer
));
1304 static ZEND_METHOD(ion_Writer_Writer
, writeTypedNull
)
1306 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1309 zend_object
*typ_obj
;
1310 ZEND_PARSE_PARAMETERS_START(1, 1)
1311 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1312 ZEND_PARSE_PARAMETERS_END();
1314 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1316 ION_CHECK(ion_writer_write_typed_null(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1318 static ZEND_METHOD(ion_Writer_Writer
, writeBool
)
1320 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1324 ZEND_PARSE_PARAMETERS_START(1, 1)
1326 ZEND_PARSE_PARAMETERS_END();
1328 ION_CHECK(ion_writer_write_bool(obj
->writer
, b
));
1330 static ZEND_METHOD(ion_Writer_Writer
, writeInt
)
1332 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1337 ZEND_PARSE_PARAMETERS_START(1, 1)
1338 Z_PARAM_STR_OR_LONG(s
, l
)
1339 ZEND_PARSE_PARAMETERS_END();
1343 ION_CHECK(ion_int_alloc(obj
->writer
, &i
));
1344 ION_CHECK(ion_int_from_chars(i
, s
->val
, s
->len
));
1345 ION_CHECK(ion_writer_write_ion_int(obj
->writer
, i
));
1348 ION_CHECK(ion_writer_write_int64(obj
->writer
, l
));
1351 static ZEND_METHOD(ion_Writer_Writer
, writeFloat
)
1353 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1357 ZEND_PARSE_PARAMETERS_START(1, 1)
1359 ZEND_PARSE_PARAMETERS_END();
1361 ION_CHECK(ion_writer_write_double(obj
->writer
, d
));
1363 static ZEND_METHOD(ion_Writer_Writer
, writeDecimal
)
1365 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1368 zend_object
*dec_obj
;
1369 zend_string
*dec_str
;
1370 ZEND_PARSE_PARAMETERS_START(1, 1)
1371 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj
, ce_Decimal
, dec_str
)
1372 ZEND_PARSE_PARAMETERS_END();
1376 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&s
, dec_str
)));
1378 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
1379 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
1382 static ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
1384 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1387 zend_object
*ts_obj
;
1388 zend_string
*ts_str
;
1389 ZEND_PARSE_PARAMETERS_START(1, 1)
1390 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
1391 ZEND_PARSE_PARAMETERS_END();
1393 decContext
*ctx
= NULL
;
1395 ctx
= php_ion_obj(reader_options
, obj
->opt
)->opt
.decimal_context
;
1398 ION_TIMESTAMP tmp
= {0};
1401 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1403 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1405 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1407 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1409 static ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1411 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1414 zend_object
*sym_obj
;
1415 zend_string
*sym_str
;
1416 ZEND_PARSE_PARAMETERS_START(1, 1)
1417 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1418 ZEND_PARSE_PARAMETERS_END();
1422 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1424 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1426 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1429 static ZEND_METHOD(ion_Writer_Writer
, writeString
)
1431 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1435 ZEND_PARSE_PARAMETERS_START(1, 1)
1437 ZEND_PARSE_PARAMETERS_END();
1440 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1442 static ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1444 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1448 ZEND_PARSE_PARAMETERS_START(1, 1)
1450 ZEND_PARSE_PARAMETERS_END();
1452 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1454 static ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1456 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1460 ZEND_PARSE_PARAMETERS_START(1, 1)
1462 ZEND_PARSE_PARAMETERS_END();
1464 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1466 static ZEND_METHOD(ion_Writer_Writer
, startLob
)
1468 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1471 zend_object
*typ_obj
;
1472 ZEND_PARSE_PARAMETERS_START(1, 1)
1473 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1474 ZEND_PARSE_PARAMETERS_END();
1476 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1478 ION_CHECK(ion_writer_start_lob(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1480 static ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1482 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1486 ZEND_PARSE_PARAMETERS_START(1, 1)
1488 ZEND_PARSE_PARAMETERS_END();
1490 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1492 static ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1494 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1497 ZEND_PARSE_PARAMETERS_NONE();
1499 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1501 static ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1503 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1506 zend_object
*typ_obj
;
1507 ZEND_PARSE_PARAMETERS_START(1, 1)
1508 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1509 ZEND_PARSE_PARAMETERS_END();
1511 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1513 ION_CHECK(ion_writer_start_container(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1515 static ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1517 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1520 ZEND_PARSE_PARAMETERS_NONE();
1522 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1524 static ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1526 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1529 zend_object
*sym_obj
;
1530 zend_string
*sym_str
;
1531 ZEND_PARSE_PARAMETERS_START(1, 1)
1532 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1533 ZEND_PARSE_PARAMETERS_END();
1537 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1539 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1541 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1544 static ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1546 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1551 ZEND_PARSE_PARAMETERS_START(1, -1)
1552 Z_PARAM_VARIADIC('+', args
, argc
);
1553 ZEND_PARSE_PARAMETERS_END();
1555 for (unsigned i
= 0; i
< argc
; ++i
) {
1556 switch (Z_TYPE(args
[i
])) {
1559 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1563 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1568 static ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1570 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1573 ZEND_PARSE_PARAMETERS_NONE();
1576 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1579 static ZEND_METHOD(ion_Writer_Writer
, flush
)
1581 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1584 ZEND_PARSE_PARAMETERS_NONE();
1587 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1588 if (obj
->type
== BUFFER_WRITER
) {
1589 smart_str_0(&obj
->buffer
.str
);
1591 RETURN_LONG(flushed
);
1593 static ZEND_METHOD(ion_Writer_Writer
, finish
)
1595 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1598 ZEND_PARSE_PARAMETERS_NONE();
1601 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1602 if (obj
->type
== BUFFER_WRITER
) {
1603 smart_str_0(&obj
->buffer
.str
);
1605 RETURN_LONG(flushed
);
1607 static ZEND_METHOD(ion_Writer_Writer
, writeOne
)
1610 static ZEND_METHOD(ion_Writer_Writer
, writeAll
)
1613 static ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1615 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1619 ZEND_PARSE_PARAMETERS_START(1, 2)
1622 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1623 ZEND_PARSE_PARAMETERS_END();
1625 obj
->type
= BUFFER_WRITER
;
1626 ZVAL_COPY(&obj
->buffer
.val
, ref
);
1627 zval_dtor(Z_REFVAL_P(ref
));
1629 php_ion_writer_ctor(obj
);
1631 static ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1633 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1636 ZEND_PARSE_PARAMETERS_NONE();
1638 RETVAL_STR(zend_string_dup(obj
->buffer
.str
.s
, 0));
1640 static ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1642 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1646 ZEND_PARSE_PARAMETERS_START(1, 2)
1647 Z_PARAM_RESOURCE(zstream
)
1649 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1650 ZEND_PARSE_PARAMETERS_END();
1652 obj
->type
= STREAM_WRITER
;
1653 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1655 php_ion_writer_ctor(obj
);
1657 static ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1659 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1662 ZEND_PARSE_PARAMETERS_NONE();
1663 PTR_CHECK(obj
->stream
.ptr
);
1665 GC_ADDREF(obj
->stream
.ptr
->res
);
1666 RETURN_RES(obj
->stream
.ptr
->res
);
1669 static ZEND_METHOD(ion_Serializer_PHP
, __construct
)
1671 php_ion_serializer_php
*obj
= php_ion_obj(serializer_php
, Z_OBJ_P(ZEND_THIS
));
1674 obj
->serializer
.call_magic
= true;
1676 ZEND_PARSE_PARAMETERS_START(0, 3)
1678 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1679 Z_PARAM_BOOL(obj
->serializer
.multi_seq
)
1680 Z_PARAM_BOOL(obj
->serializer
.call_magic
)
1681 Z_PARAM_STR_OR_NULL(obj
->serializer
.call_custom
)
1682 ZEND_PARSE_PARAMETERS_END();
1684 php_ion_serializer_php_ctor(obj
);
1686 static ZEND_METHOD(ion_Serializer_PHP
, __invoke
)
1688 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1691 ZEND_PARSE_PARAMETERS_START(1, 1)
1693 ZEND_PARSE_PARAMETERS_END();
1695 if (obj
->ce
== ce_Serializer_PHP
) {
1696 // default, fast path
1697 php_ion_serialize(&php_ion_obj(serializer_php
, obj
)->serializer
, data
, return_value
);
1699 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "serialize", return_value
, data
);
1702 static ZEND_FUNCTION(ion_serialize
)
1705 zend_object
*zo_ser
= NULL
;
1706 ZEND_PARSE_PARAMETERS_START(1, 2)
1709 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Serializer
)
1710 ZEND_PARSE_PARAMETERS_END();
1712 if (!zo_ser
|| zo_ser
->ce
== ce_Serializer_PHP
) {
1713 // default, fast path
1714 php_ion_serializer
*ser
= zo_ser
? &php_ion_obj(serializer_php
, zo_ser
)->serializer
: NULL
;
1715 php_ion_serialize(ser
, data
, return_value
);
1717 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1720 static ZEND_METHOD(ion_Serializer_PHP
, serialize
)
1722 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1725 ZEND_PARSE_PARAMETERS_START(1, 1)
1727 ZEND_PARSE_PARAMETERS_END();
1730 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1733 static ZEND_METHOD(ion_Unserializer_PHP
, __construct
)
1735 php_ion_unserializer_php
*obj
= php_ion_obj(unserializer_php
, Z_OBJ_P(ZEND_THIS
));
1738 obj
->unserializer
.call_magic
= true;
1740 ZEND_PARSE_PARAMETERS_START(0, 3)
1742 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1743 Z_PARAM_BOOL(obj
->unserializer
.multi_seq
)
1744 Z_PARAM_BOOL(obj
->unserializer
.call_magic
)
1745 Z_PARAM_STR_OR_NULL(obj
->unserializer
.call_custom
)
1746 ZEND_PARSE_PARAMETERS_END();
1748 php_ion_unserializer_php_ctor(obj
);
1750 static ZEND_METHOD(ion_Unserializer_PHP
, __invoke
)
1752 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1755 ZEND_PARSE_PARAMETERS_START(1, 1)
1757 ZEND_PARSE_PARAMETERS_END();
1759 if (obj
->ce
== ce_Unserializer_PHP
) {
1760 php_ion_unserialize(&php_ion_obj(unserializer_php
, obj
)->unserializer
, data
, return_value
);
1762 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "unserialize", return_value
, data
);
1765 static ZEND_FUNCTION(ion_unserialize
)
1768 zend_object
*zo_ser
= NULL
;
1769 ZEND_PARSE_PARAMETERS_START(1, 2)
1772 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Unserializer
)
1773 ZEND_PARSE_PARAMETERS_END();
1775 if (!zo_ser
|| zo_ser
->ce
== ce_Unserializer_PHP
) {
1776 // default, fast path
1777 php_ion_unserializer
*ser
= zo_ser
? &php_ion_obj(unserializer_php
, zo_ser
)->unserializer
: NULL
;
1778 php_ion_unserialize(ser
, data
, return_value
);
1780 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1783 static ZEND_METHOD(ion_Unserializer_PHP
, unserialize
)
1785 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1788 ZEND_PARSE_PARAMETERS_START(1, 1)
1790 ZEND_PARSE_PARAMETERS_END();
1793 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1796 PHP_RINIT_FUNCTION(ion
)
1798 #if defined(ZTS) && defined(COMPILE_DL_ION)
1799 ZEND_TSRMLS_CACHE_UPDATE();
1802 php_ion_globals_symbols_init();
1803 php_ion_globals_serializer_init();
1804 php_ion_globals_unserializer_init();
1808 PHP_RSHUTDOWN_FUNCTION(ion
)
1810 php_ion_globals_unserializer_dtor();
1811 php_ion_globals_serializer_dtor();
1812 php_ion_globals_symbols_dtor();
1816 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
1817 { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), default_value },
1818 #include "ion_arginfo.h"
1820 PHP_MINIT_FUNCTION(ion
)
1823 if (SUCCESS
!= g_sym_init()) {
1828 php_ion_register(catalog
, Catalog
, zend_ce_countable
);
1831 php_ion_register(decimal
, Decimal
);
1832 php_ion_register(decimal_ctx
, Decimal_Context
);
1833 ce_Decimal_Context_Rounding
= register_class_ion_Decimal_Context_Rounding();
1836 ce_LOB
= register_class_ion_LOB();
1839 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1840 php_ion_register(reader_options
, Reader_Options
);
1841 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1842 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1843 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1844 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1845 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1848 ce_Serializer
= register_class_ion_Serializer();
1849 php_ion_register(serializer_php
, Serializer_PHP
, ce_Serializer
);
1852 php_ion_register(symbol
, Symbol
);
1853 oh_Symbol
.compare
= php_ion_symbol_zval_compare
;
1854 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1855 php_ion_register(symbol_table
, Symbol_Table
);
1856 ce_Symbol_Table
->create_object
= NULL
;
1857 ce_Symbol_Table_Local
= register_class_ion_Symbol_Table_Local(ce_Symbol_Table
);
1858 ce_Symbol_Table_Local
->create_object
= create_ion_Symbol_Table
;
1859 ce_Symbol_Table_Shared
= register_class_ion_Symbol_Table_Shared(ce_Symbol_Table
);
1860 ce_Symbol_Table_Shared
->create_object
= create_ion_Symbol_Table
;
1861 ce_Symbol_Enum
= register_class_ion_Symbol_Enum();
1862 ce_Symbol_Table_System
= register_class_ion_Symbol_Table_System(ce_Symbol_Enum
);
1863 ce_Symbol_Table_PHP
= register_class_ion_Symbol_Table_PHP(ce_Symbol_Enum
);
1866 ce_Timestamp
= register_class_ion_Timestamp(php_date_get_date_ce());
1867 ce_Timestamp_Precision
= register_class_ion_Timestamp_Precision();
1870 php_ion_register(type
, Type
);
1873 ce_Writer
= register_class_ion_Writer();
1874 php_ion_register(writer_options
, Writer_Options
);
1875 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1876 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1877 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1878 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1879 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1882 ce_Unserializer
= register_class_ion_Unserializer();
1883 php_ion_register(unserializer_php
, Unserializer_PHP
, ce_Unserializer
);
1888 PHP_MSHUTDOWN_FUNCTION(ion
)
1890 if (g_sym_tab_php
) {
1891 ion_symbol_table_close(g_sym_tab_php
);
1893 zend_hash_destroy(&g_sym_hash
);
1897 PHP_MINFO_FUNCTION(ion
)
1899 php_info_print_table_start();
1900 php_info_print_table_header(2, "ion support", "enabled");
1901 php_info_print_table_end();
1904 PHP_GINIT_FUNCTION(ion
)
1906 memset(ion_globals
, 0, sizeof(*ion_globals
));
1908 php_ion_decimal_ctx_init_max(&ion_globals
->decimal
.ctx
, DEC_ROUND_HALF_EVEN
);
1909 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_max
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MAX
);
1910 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_min
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MIN
);
1913 PHP_GSHUTDOWN_FUNCTION(ion
)
1917 static zend_module_dep ion_module_deps
[] = {
1918 ZEND_MOD_REQUIRED("date")
1919 ZEND_MOD_REQUIRED("spl")
1923 zend_module_entry ion_module_entry
= {
1924 STANDARD_MODULE_HEADER_EX
,
1927 "ion", /* Extension name */
1928 ext_functions
, /* zend_function_entry */
1929 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1930 PHP_MSHUTDOWN(ion
), /* PHP_MSHUTDOWN - Module shutdown */
1931 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1932 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1933 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1934 PHP_ION_VERSION
, /* Version */
1935 ZEND_MODULE_GLOBALS(ion
),
1936 PHP_GINIT(ion
), /* PHP_GINIT */
1937 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1939 STANDARD_MODULE_PROPERTIES_EX
1942 #ifdef COMPILE_DL_ION
1944 ZEND_TSRMLS_CACHE_DEFINE()
1946 ZEND_GET_MODULE(ion
)