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"
30 #include "ion_private.h"
32 static ZEND_METHOD(ion_Symbol_ImportLocation
, __construct
)
34 php_ion_symbol_iloc
*obj
= php_ion_obj(symbol_iloc
, Z_OBJ_P(ZEND_THIS
));
38 ZEND_PARSE_PARAMETERS_START(2, 2)
39 Z_PARAM_STR(obj
->name
)
40 Z_PARAM_LONG(location
)
41 ZEND_PARSE_PARAMETERS_END();
43 obj
->loc
.location
= (SID
) location
;
44 php_ion_symbol_iloc_ctor(obj
);
46 static ZEND_METHOD(ion_Symbol
, __construct
)
48 php_ion_symbol
*obj
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
52 ZEND_PARSE_PARAMETERS_START(0, 3)
54 Z_PARAM_STR_OR_NULL(obj
->value
)
56 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->iloc
, ce_Symbol_ImportLocation
)
57 ZEND_PARSE_PARAMETERS_END();
59 obj
->sym
.sid
= (SID
) sid
;
60 php_ion_symbol_ctor(obj
);
62 static ZEND_METHOD(ion_Symbol
, equals
)
64 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
67 zend_object
*other_obj
;
68 ZEND_PARSE_PARAMETERS_START(1, 1)
69 Z_PARAM_OBJ_OF_CLASS(other_obj
, ce_Symbol
)
70 ZEND_PARSE_PARAMETERS_END();
73 iERR err
= ion_symbol_is_equal(
75 &php_ion_obj(symbol
, other_obj
)->sym
, &eq
);
79 static ZEND_METHOD(ion_Symbol
, __toString
)
81 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
84 ZEND_PARSE_PARAMETERS_NONE();
87 RETURN_EMPTY_STRING();
89 RETURN_STR_COPY(sym
->value
);
91 static ZEND_METHOD(ion_Symbol_Enum
, toSymbol
)
93 ZEND_PARSE_PARAMETERS_NONE();
95 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
98 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
100 RETVAL_ZVAL(zsym
, 1, 0);
102 static ZEND_METHOD(ion_Symbol_Enum
, toSID
)
104 ZEND_PARSE_PARAMETERS_NONE();
106 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
109 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
113 RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym
), Z_OBJ_P(zsym
), ZEND_STRL("sid"), 0, &tmp
), 1, 0);
115 static ZEND_METHOD(ion_Symbol_Enum
, toString
)
117 ZEND_PARSE_PARAMETERS_NONE();
119 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
122 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
126 RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym
), Z_OBJ_P(zsym
), ZEND_STRL("value"), 0, &tmp
), 1, 0);
128 static ZEND_METHOD(ion_Symbol_System
, asTable
)
130 ZEND_PARSE_PARAMETERS_NONE();
132 object_init_ex(return_value
, ce_Symbol_Table_Shared
);
133 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(return_value
));
134 ION_CHECK(ion_symbol_table_get_system_table(&obj
->tab
, 1));
135 php_ion_symbol_table_ctor(obj
);
136 ion_symbol_table_lock(obj
->tab
);
138 static ZEND_METHOD(ion_Symbol_PHP
, asTable
)
140 ZEND_PARSE_PARAMETERS_NONE();
142 object_init_ex(return_value
, ce_Symbol_Table_Shared
);
143 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(return_value
));
144 obj
->tab
= g_sym_tab_php
;
145 php_ion_symbol_table_ctor(obj
);
146 ion_symbol_table_lock(obj
->tab
);
148 static ZEND_METHOD(ion_Symbol_Table_Local
, __construct
)
150 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
153 ZEND_PARSE_PARAMETERS_NONE();
155 ION_CHECK(ion_symbol_table_open_with_type(&obj
->tab
, NULL
, ist_LOCAL
));
156 obj
->dtor
= ion_symbol_table_close
;
159 static ZEND_METHOD(ion_Symbol_Table_Local
, import
)
161 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
164 zend_object
*zo_import
;
165 ZEND_PARSE_PARAMETERS_START(1, 1)
166 Z_PARAM_OBJ_OF_CLASS(zo_import
, ce_Symbol_Table
);
167 ZEND_PARSE_PARAMETERS_END();
169 php_ion_symbol_table_import(obj
, php_ion_obj(symbol_table
, zo_import
));
171 static ZEND_METHOD(ion_Symbol_Table_Shared
, __construct
)
173 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
177 zend_long version
= 1;
178 HashTable
*ht_sym
= NULL
;
179 ZEND_PARSE_PARAMETERS_START(1, 3)
182 Z_PARAM_LONG(version
)
183 Z_PARAM_ARRAY_HT_OR_NULL(ht_sym
)
184 ZEND_PARSE_PARAMETERS_END();
186 ION_CHECK(ion_symbol_table_open_with_type(&obj
->tab
, NULL
, ist_SHARED
));
187 obj
->dtor
= ion_symbol_table_close
;
190 ION_CHECK(ion_symbol_table_set_name(obj
->tab
, ion_string_from_zend(&is
, zname
)));
191 ION_CHECK(ion_symbol_table_set_version(obj
->tab
, version
));
193 php_ion_symbol_table_ctor(obj
);
196 if (ht_sym
) ZEND_HASH_FOREACH_VAL(ht_sym
, zsym
)
198 zend_string
*str
= zval_get_string(zsym
);
204 ION_CHECK(ion_symbol_table_add_symbol(obj
->tab
, ion_string_from_zend(&istr
, str
), NULL
), zend_string_release(str
));
205 zend_string_release(str
);
207 ZEND_HASH_FOREACH_END();
209 static ZEND_METHOD(ion_Symbol_Table
, getMaxId
)
211 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
214 ZEND_PARSE_PARAMETERS_NONE();
217 ION_CHECK(ion_symbol_table_get_max_sid(obj
->tab
, &max_sid
));
218 RETURN_LONG(max_sid
);
220 static ZEND_METHOD(ion_Symbol_Table
, add
)
222 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
225 zend_object
*zo_sym
= NULL
;
226 zend_string
*zs_sym
= NULL
;
227 ZEND_PARSE_PARAMETERS_START(1, 1)
228 Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_sym
, ce_Symbol
, zs_sym
)
229 ZEND_PARSE_PARAMETERS_END();
233 ZVAL_OBJ(&z_sym
, zo_sym
);
234 zs_sym
= zval_get_string(&z_sym
);
239 ION_CHECK(ion_symbol_table_add_symbol(obj
->tab
, ion_string_from_zend(&is
, zs_sym
), &sid
),
241 zend_string_release(zs_sym
);
244 zend_string_release(zs_sym
);
248 static ZEND_METHOD(ion_Symbol_Table
, find
)
250 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
254 zend_string
*zstring
= NULL
;
255 ZEND_PARSE_PARAMETERS_START(1, 1)
256 Z_PARAM_STR_OR_LONG(zstring
, zsid
)
257 ZEND_PARSE_PARAMETERS_END();
262 ION_CHECK(ion_symbol_table_find_by_name(obj
->tab
, ion_string_from_zend(&is
, zstring
), &sid
));
266 ION_CHECK(ion_symbol_table_get_symbol(obj
->tab
, zsid
, &sym
));
268 php_ion_symbol_table_symbol_zval(obj
, sym
, return_value
);
271 static ZEND_METHOD(ion_Symbol_Table
, findLocal
)
273 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
277 zend_string
*zstring
;
278 ZEND_PARSE_PARAMETERS_START(1, 1)
279 Z_PARAM_STR_OR_LONG(zstring
, zsid
)
280 ZEND_PARSE_PARAMETERS_END();
285 ION_CHECK(ion_symbol_table_find_by_name(obj
->tab
, ion_string_from_zend(&is
, zstring
), &sid
));
289 ION_CHECK(ion_symbol_table_get_local_symbol(obj
->tab
, zsid
, &sym
));
291 php_ion_symbol_table_symbol_zval(obj
, sym
, return_value
);
294 static ZEND_METHOD(ion_Catalog
, __construct
)
296 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
299 ZEND_PARSE_PARAMETERS_NONE();
301 php_ion_catalog_ctor(obj
);
303 static ZEND_METHOD(ion_Catalog
, count
)
305 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
308 ZEND_PARSE_PARAMETERS_NONE();
311 ION_CHECK(ion_catalog_get_symbol_table_count(obj
->cat
, &c
));
314 static ZEND_METHOD(ion_Catalog
, add
)
316 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
319 zend_object
*zo_symtab
;
320 ZEND_PARSE_PARAMETERS_START(1, 1)
321 Z_PARAM_OBJ_OF_CLASS(zo_symtab
, ce_Symbol_Table
)
322 ZEND_PARSE_PARAMETERS_END();
324 php_ion_symbol_table
*o_symtab
= php_ion_obj(symbol_table
, zo_symtab
);
325 php_ion_catalog_add_symbol_table(obj
, o_symtab
);
328 static ZEND_METHOD(ion_Catalog
, remove
)
330 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
333 zend_object
*zo_symtab
= NULL
;
334 zend_string
*zs_symtab
= NULL
;
335 ZEND_PARSE_PARAMETERS_START(1, 1)
336 Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_symtab
, ce_Symbol_Table
, zs_symtab
)
337 ZEND_PARSE_PARAMETERS_END();
342 zval
*ztabs
= zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("symbolTables"), 0, &tmp
);
346 zend_ulong idx
= (uintptr_t) &zo_symtab
->gc
;
347 RETVAL_BOOL(SUCCESS
== zend_hash_index_del(Z_ARRVAL_P(ztabs
), idx
));
348 ION_CHECK(ion_catalog_release_symbol_table(obj
->cat
, php_ion_obj(symbol_table
, zo_symtab
)->tab
));
350 bool deleted
= false;
351 ION_SYMBOL_TABLE
*tab
;
353 ion_string_from_zend(&is
, zs_symtab
);
356 ION_CHECK(ion_catalog_find_best_match(obj
->cat
, &is
, 0, &tab
));
358 ION_CHECK(ion_catalog_release_symbol_table(obj
->cat
, tab
));
362 RETVAL_BOOL(deleted
);
366 static ZEND_METHOD(ion_Catalog
, find
)
368 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
371 zend_long zversion
= 0;
373 ZEND_PARSE_PARAMETERS_START(1, 2)
376 Z_PARAM_LONG(zversion
)
377 ZEND_PARSE_PARAMETERS_END();
380 ION_SYMBOL_TABLE
*tab_ptr
= NULL
;
381 ION_CHECK(ion_catalog_find_symbol_table(obj
->cat
, ion_string_from_zend(&is
, zname
), zversion
, &tab_ptr
));
383 php_ion_catalog_symbol_table_zval(obj
, tab_ptr
, return_value
);
386 static ZEND_METHOD(ion_Catalog
, findBest
)
388 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
391 zend_long zversion
= 0;
393 ZEND_PARSE_PARAMETERS_START(1, 2)
396 Z_PARAM_LONG(zversion
)
397 ZEND_PARSE_PARAMETERS_END();
400 ION_SYMBOL_TABLE
*tab_ptr
= NULL
;
401 ION_CHECK(ion_catalog_find_best_match(obj
->cat
, ion_string_from_zend(&is
, zname
), zversion
, &tab_ptr
));
403 php_ion_catalog_symbol_table_zval(obj
, tab_ptr
, return_value
);
406 static ZEND_METHOD(ion_Timestamp
, __construct
)
408 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
412 zend_object
*precision_obj
= NULL
, *format_obj
= NULL
;
413 zend_string
*fmt
= NULL
, *dt
= NULL
, *tz
= NULL
;
414 zend_object
*tz_obj
= NULL
;
415 zval z_tz_tmp
, *z_tz_ptr
= NULL
;
416 ZEND_PARSE_PARAMETERS_START(1, 4)
417 Z_PARAM_OBJ_OF_CLASS_OR_LONG(precision_obj
, ce_Timestamp_Precision
, precision
)
419 Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL(format_obj
, ce_Timestamp_Format
, fmt
)
420 Z_PARAM_STR_OR_NULL(dt
)
421 Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL(tz_obj
, php_date_get_timezone_ce(), tz
)
422 ZEND_PARSE_PARAMETERS_END();
425 precision
= Z_LVAL_P(zend_enum_fetch_case_value(precision_obj
));
428 fmt
= Z_STR_P(zend_enum_fetch_case_value(format_obj
));
431 ZVAL_OBJ(z_tz_ptr
= &z_tz_tmp
, tz_obj
);
433 // there's no public API, so call timezone_open
434 zend_function
*tz_open
= zend_fetch_function_str(ZEND_STRL("timezone_open"));
437 ZVAL_STR(&z_arg
, tz
);
438 zend_call_known_function(tz_open
, NULL
, NULL
, z_tz_ptr
= &z_tz_tmp
, 1, &z_arg
, NULL
);
441 php_ion_timestamp_ctor(obj
, precision
, fmt
, dt
, z_tz_ptr
);
442 if (tz
&& z_tz_ptr
) {
443 zval_ptr_dtor(z_tz_ptr
);
446 static ZEND_METHOD(ion_Timestamp
, __toString
)
448 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
451 ZEND_PARSE_PARAMETERS_NONE();
455 zend_call_method_with_1_params(&obj
->std
, obj
->std
.ce
, NULL
, "format", return_value
,
456 zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("format"), 0, &fmt
));
458 static ZEND_METHOD(ion_Decimal_Context
, __construct
)
460 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(ZEND_THIS
));
464 zend_object
*o_round
= NULL
;
465 zend_long digits
, emax
, emin
, round
;
466 ZEND_PARSE_PARAMETERS_START(5, 5)
470 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
472 ZEND_PARSE_PARAMETERS_END();
475 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
477 php_ion_decimal_ctx_init(&obj
->ctx
, digits
, emax
, emin
, round
, clamp
); // NOLINT(cppcoreguidelines-narrowing-conversions)
478 php_ion_decimal_ctx_ctor(obj
, o_round
);
480 static inline void make_decimal_ctx(INTERNAL_FUNCTION_PARAMETERS
, int kind
)
482 ZEND_PARSE_PARAMETERS_NONE();
484 object_init_ex(return_value
, ce_Decimal_Context
);
485 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
486 decContextDefault(&obj
->ctx
, kind
);
487 php_ion_decimal_ctx_ctor(obj
, NULL
);
489 static ZEND_METHOD(ion_Decimal_Context
, Dec32
)
491 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL32
);
493 static ZEND_METHOD(ion_Decimal_Context
, Dec64
)
495 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL64
);
497 static ZEND_METHOD(ion_Decimal_Context
, Dec128
)
499 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL128
);
501 static ZEND_METHOD(ion_Decimal_Context
, DecMax
)
503 zend_object
*o_round
= NULL
;
504 zend_long round
= DEC_ROUND_HALF_EVEN
;
505 ZEND_PARSE_PARAMETERS_START(0, 1)
507 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
508 ZEND_PARSE_PARAMETERS_END();
511 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
513 object_init_ex(return_value
, ce_Decimal_Context
);
514 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
515 php_ion_decimal_ctx_init_max(&obj
->ctx
, round
);
516 php_ion_decimal_ctx_ctor(obj
, o_round
);
518 static ZEND_METHOD(ion_Decimal
, __construct
)
520 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
525 ZEND_PARSE_PARAMETERS_START(1, 2)
526 Z_PARAM_STR_OR_LONG(zstr
, num
)
528 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->ctx
, ce_Decimal_Context
)
529 ZEND_PARSE_PARAMETERS_END();
535 object_init_ex(&zdc
, ce_Decimal_Context
);
536 obj
->ctx
= Z_OBJ(zdc
);
537 php_ion_decimal_ctx_ctor(php_ion_obj(decimal_ctx
, obj
->ctx
), NULL
);
540 decContext
*ctx
= &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
;
543 ION_CHECK(ion_decimal_from_string(&obj
->dec
, zstr
->val
, ctx
), OBJ_RELEASE(obj
->ctx
));
545 php_ion_decimal_from_zend_long(&obj
->dec
, ctx
, num
);
548 php_ion_decimal_ctor(obj
);
549 OBJ_RELEASE(obj
->ctx
);
551 static ZEND_METHOD(ion_Decimal
, equals
)
553 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
556 zend_object
*dec_obj
;
557 ZEND_PARSE_PARAMETERS_START(1, 1)
558 Z_PARAM_OBJ_OF_CLASS(dec_obj
, ce_Decimal
)
559 ZEND_PARSE_PARAMETERS_END();
562 ION_CHECK(ion_decimal_equals(&obj
->dec
, &php_ion_obj(decimal
, dec_obj
)->dec
,
563 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &is
));
566 static ZEND_METHOD(ion_Decimal
, __toString
)
568 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
571 ZEND_PARSE_PARAMETERS_NONE();
573 RETURN_STR(php_ion_decimal_to_string(&obj
->dec
));
575 static ZEND_METHOD(ion_Decimal
, toInt
)
577 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
580 ZEND_PARSE_PARAMETERS_NONE();
583 php_ion_decimal_to_zend_long(&obj
->dec
, &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
, &l
);
586 static ZEND_METHOD(ion_Decimal
, isInt
)
588 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
591 ZEND_PARSE_PARAMETERS_NONE();
593 RETURN_BOOL(ion_decimal_is_integer(&obj
->dec
));
595 static ZEND_METHOD(ion_LOB
, __construct
)
598 zend_object
*type
= NULL
;
599 ZEND_PARSE_PARAMETERS_START(1, 2)
602 Z_PARAM_OBJ_OF_CLASS(type
, ce_Type
)
603 ZEND_PARSE_PARAMETERS_END();
606 type
= zend_enum_get_case_cstr(ce_Type
, "CLob");
608 update_property_obj(Z_OBJ_P(ZEND_THIS
), ZEND_STRL("type"), type
);
609 zend_update_property_str(Z_OBJCE_P(ZEND_THIS
), Z_OBJ_P(ZEND_THIS
), ZEND_STRL("value"), value
);
611 static ZEND_METHOD(ion_Reader_Options
, __construct
)
613 php_ion_reader_options
*opt
= php_ion_obj(reader_options
, Z_OBJ_P(ZEND_THIS
));
614 zend_bool ret_sys_val
= false, skip_validation
= false;
615 zend_long max_depth
= 10, max_ann
= 10, ann_buf_siz
= 0x4000, tmp_buf_siz
= 0x4000;
619 ZEND_PARSE_PARAMETERS_START(0, 9)
621 // public readonly ?\ion\Catalog $catalog = null,
622 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cat
, ce_Catalog
)
623 // public readonly ?\ion\Decimal\Context $decimalContext = null,
624 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->dec_ctx
, ce_Decimal_Context
)
625 // public readonly ?\Closure $onContextChange = null,
626 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cb
, zend_ce_closure
);
627 // public readonly bool $returnSystemValues = false,
628 Z_PARAM_BOOL(ret_sys_val
)
629 // public readonly int $maxContainerDepth = 10,
630 Z_PARAM_LONG(max_depth
)
631 // public readonly int $maxAnnotations = 10,
632 Z_PARAM_LONG(max_ann
)
633 // public readonly int $annotationBufferSize = 0x4000,
634 Z_PARAM_LONG(ann_buf_siz
)
635 // public readonly int $tempBufferSize = 0x4000,
636 Z_PARAM_LONG(tmp_buf_siz
)
637 // public readonly bool $skipCharacterValidation = false,
638 Z_PARAM_BOOL(skip_validation
)
639 ZEND_PARSE_PARAMETERS_END();
643 ZVAL_OBJ(&zcb
, opt
->cb
);
644 zend_fcall_info_init(&zcb
, 0, &opt
->ccn
.fci
, &opt
->ccn
.fcc
, NULL
, NULL
);
645 opt
->opt
.context_change_notifier
.context
= &opt
->ccn
;
646 update_property_obj(&opt
->std
, ZEND_STRL("onContextChange"), opt
->cb
);
648 zend_update_property_null(NULL
, &opt
->std
, ZEND_STRL("onContextChange"));
651 update_property_obj(&opt
->std
, ZEND_STRL("catalog"), opt
->cat
);
652 opt
->opt
.pcatalog
= php_ion_obj(catalog
, opt
->cat
)->cat
;
654 zend_update_property_null(NULL
, &opt
->std
, ZEND_STRL("catalog"));
657 update_property_obj(&opt
->std
, ZEND_STRL("decimalContext"), opt
->dec_ctx
);
658 opt
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, opt
->dec_ctx
)->ctx
;
660 zend_update_property_null(NULL
, &opt
->std
, ZEND_STRL("decimalContext"));
662 zend_update_property_bool(opt
->std
.ce
, &opt
->std
, ZEND_STRL("returnSystemValues"),
663 opt
->opt
.return_system_values
= ret_sys_val
);
664 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxContainerDepth"),
665 opt
->opt
.max_container_depth
= (SIZE
) max_depth
);
666 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotations"),
667 opt
->opt
.max_annotation_count
= (SIZE
) max_ann
);
668 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("annotationBufferSize"),
669 opt
->opt
.max_annotation_buffered
= (SIZE
) ann_buf_siz
);
670 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("tempBufferSize"),
671 opt
->opt
.chunk_threshold
= opt
->opt
.user_value_threshold
= opt
->opt
.symbol_threshold
= (SIZE
) tmp_buf_siz
);
672 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("skipCharacterValidation"),
673 opt
->opt
.skip_character_validation
= (SIZE
) 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();
867 max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
871 ION_SYMBOL
*ptr
= ecalloc(sizeof(*ptr
), max
);
872 iERR err
= ion_reader_get_annotation_symbols(obj
->reader
, ptr
, max
, &count
);
874 array_init_size(return_value
, count
);
875 for (int32_t i
= 0; i
< count
; ++i
) {
877 php_ion_symbol_zval(&ptr
[i
], &zsym
);
878 add_next_index_zval(return_value
, &zsym
);
884 static ZEND_METHOD(ion_Reader_Reader
, countAnnotations
)
886 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
889 ZEND_PARSE_PARAMETERS_NONE();
892 ION_CHECK(ion_reader_get_annotation_count(obj
->reader
, &sz
));
895 static ZEND_METHOD(ion_Reader_Reader
, getAnnotation
)
897 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
901 ZEND_PARSE_PARAMETERS_START(1, 1)
903 ZEND_PARSE_PARAMETERS_END();
906 ION_CHECK(ion_reader_get_an_annotation(obj
->reader
, idx
, &ann
));
907 RETURN_STRINGL((char *) ann
.value
, ann
.length
);
909 static ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbol
)
911 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
915 ZEND_PARSE_PARAMETERS_START(1, 1)
917 ZEND_PARSE_PARAMETERS_END();
920 ION_CHECK(ion_reader_get_an_annotation_symbol(obj
->reader
, idx
, &sym
));
921 php_ion_symbol_zval(&sym
, return_value
);
923 static ZEND_METHOD(ion_Reader_Reader
, readNull
)
925 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
928 ZEND_PARSE_PARAMETERS_NONE();
931 ION_CHECK(ion_reader_read_null(obj
->reader
, &typ
));
934 static ZEND_METHOD(ion_Reader_Reader
, readBool
)
936 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
939 ZEND_PARSE_PARAMETERS_NONE();
942 ION_CHECK(ion_reader_read_bool(obj
->reader
, &b
));
945 static ZEND_METHOD(ion_Reader_Reader
, readInt
)
947 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
950 ZEND_PARSE_PARAMETERS_NONE();
952 php_ion_reader_read_int(obj
->reader
, return_value
);
954 static ZEND_METHOD(ion_Reader_Reader
, readFloat
)
956 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
959 ZEND_PARSE_PARAMETERS_NONE();
962 ION_CHECK(ion_reader_read_double(obj
->reader
, &dval
));
965 static ZEND_METHOD(ion_Reader_Reader
, readDecimal
)
967 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
970 ZEND_PARSE_PARAMETERS_NONE();
972 object_init_ex(return_value
, ce_Decimal
);
973 php_ion_decimal
*dec
= php_ion_obj(decimal
, Z_OBJ_P(return_value
));
974 ION_CHECK(ion_reader_read_ion_decimal(obj
->reader
, &dec
->dec
));
975 php_ion_decimal_ctor(dec
);
977 static ZEND_METHOD(ion_Reader_Reader
, readTimestamp
)
979 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
982 ZEND_PARSE_PARAMETERS_NONE();
984 php_ion_reader_read_timestamp(obj
->reader
, obj
->opt
? &php_ion_obj(reader_options
, obj
->opt
)->opt
: NULL
, return_value
);
986 static ZEND_METHOD(ion_Reader_Reader
, readSymbol
)
988 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
991 ZEND_PARSE_PARAMETERS_NONE();
994 ION_CHECK(ion_reader_read_ion_symbol(obj
->reader
, &sym
));
995 php_ion_symbol_zval(&sym
, return_value
);
997 static ZEND_METHOD(ion_Reader_Reader
, readString
)
999 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1002 ZEND_PARSE_PARAMETERS_NONE();
1005 ION_CHECK(ion_reader_read_string(obj
->reader
, &str
));
1006 RETURN_STRINGL((char *) str
.value
, str
.length
);
1009 typedef iERR (*read_part_fn
)(ION_READER
*, BYTE
*, SIZE
, SIZE
*);
1010 static void read_part(INTERNAL_FUNCTION_PARAMETERS
, read_part_fn fn
)
1012 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1017 zend_long len
= 0x1000;
1018 ZEND_PARSE_PARAMETERS_START(1, 1)
1022 ZEND_PARSE_PARAMETERS_END();
1026 if (Z_TYPE_P(ref
) == IS_STRING
&& Z_STRLEN_P(ref
) == len
) {
1028 zstr
= Z_STR_P(ref
);
1031 zstr
= zend_string_alloc(len
, 0);
1035 ION_CHECK(fn(obj
->reader
, (BYTE
*) zstr
->val
, zstr
->len
, &read
), goto fail
);
1037 if (read
< zstr
->len
) {
1038 zstr
= zend_string_truncate(zstr
, read
, 0);
1040 ZVAL_STR(ref
, zstr
);
1044 zend_string_release(zstr
);
1045 ZVAL_EMPTY_STRING(ref
);
1048 static ZEND_METHOD(ion_Reader_Reader
, readStringPart
)
1050 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_partial_string
);
1052 static ZEND_METHOD(ion_Reader_Reader
, readLob
)
1054 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1057 ZEND_PARSE_PARAMETERS_NONE();
1059 php_ion_reader_read_lob(obj
->reader
, return_value
);
1061 static ZEND_METHOD(ion_Reader_Reader
, readLobPart
)
1063 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_lob_partial_bytes
);
1065 static ZEND_METHOD(ion_Reader_Reader
, getPosition
)
1067 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1070 ZEND_PARSE_PARAMETERS_NONE();
1074 ION_CHECK(ion_reader_get_position(obj
->reader
, &bytes
, &dummy
, &dummy
));
1077 static ZEND_METHOD(ion_Reader_Reader
, getDepth
)
1079 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1082 ZEND_PARSE_PARAMETERS_NONE();
1085 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
1088 static ZEND_METHOD(ion_Reader_Reader
, seek
)
1090 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1093 zend_long off
, len
= -1;
1094 ZEND_PARSE_PARAMETERS_START(1, 2)
1098 ZEND_PARSE_PARAMETERS_END();
1100 ION_CHECK(ion_reader_seek(obj
->reader
, off
, len
));
1102 static ZEND_METHOD(ion_Reader_Reader
, getValueOffset
)
1104 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1107 ZEND_PARSE_PARAMETERS_NONE();
1110 ION_CHECK(ion_reader_get_value_offset(obj
->reader
, &off
));
1113 static ZEND_METHOD(ion_Reader_Reader
, getValueLength
)
1115 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1118 ZEND_PARSE_PARAMETERS_NONE();
1121 ION_CHECK(ion_reader_get_value_length(obj
->reader
, &len
));
1124 static ZEND_METHOD(ion_Reader_Buffer_Reader
, __construct
)
1126 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1130 ZEND_PARSE_PARAMETERS_START(1, 2)
1133 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1134 ZEND_PARSE_PARAMETERS_END();
1136 obj
->type
= BUFFER_READER
;
1137 obj
->buffer
= zend_string_copy(zstr
);
1139 php_ion_reader_ctor(obj
);
1141 static ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
1143 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1146 ZEND_PARSE_PARAMETERS_NONE();
1147 RETURN_STR_COPY(obj
->buffer
);
1150 static ZEND_METHOD(ion_Reader_Stream_Reader
, __construct
)
1152 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1156 ZEND_PARSE_PARAMETERS_START(1, 2)
1157 Z_PARAM_RESOURCE(zstream
)
1159 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1160 ZEND_PARSE_PARAMETERS_END();
1162 obj
->type
= STREAM_READER
;
1163 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1165 php_ion_reader_ctor(obj
);
1167 static ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
1169 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1172 ZEND_PARSE_PARAMETERS_NONE();
1173 PTR_CHECK(obj
->stream
.ptr
);
1175 GC_ADDREF(obj
->stream
.ptr
->res
);
1176 RETURN_RES(obj
->stream
.ptr
->res
);
1178 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
1180 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1184 ZEND_PARSE_PARAMETERS_START(1, 1);
1185 Z_PARAM_RESOURCE(zstream
);
1186 ZEND_PARSE_PARAMETERS_END();
1188 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
1190 if (obj
->stream
.ptr
) {
1191 zend_list_delete(obj
->stream
.ptr
->res
);
1193 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1194 PTR_CHECK(obj
->stream
.ptr
);
1195 Z_ADDREF_P(zstream
);
1197 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
1199 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1204 ZEND_PARSE_PARAMETERS_START(2, 2);
1205 Z_PARAM_RESOURCE(zstream
);
1206 Z_PARAM_LONG(length
)
1207 ZEND_PARSE_PARAMETERS_END();
1209 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
1211 if (obj
->stream
.ptr
) {
1212 zend_list_delete(obj
->stream
.ptr
->res
);
1214 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1215 PTR_CHECK(obj
->stream
.ptr
);
1216 Z_ADDREF_P(zstream
);
1218 static ZEND_METHOD(ion_Writer_Options
, __construct
)
1220 php_ion_writer_options
*obj
= php_ion_obj(writer_options
, Z_OBJ_P(ZEND_THIS
));
1223 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
1224 tabs
= true, flush
= false;
1225 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x4000;
1226 ZEND_PARSE_PARAMETERS_START(0, 12)
1228 //public readonly ?\ion\Catalog $catalog = null,
1229 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
1230 //public readonly ?\ion\Decimal\Context $decimalContext = null,
1231 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
1232 //public readonly bool $outputBinary = false,
1233 Z_PARAM_BOOL(binary
)
1234 //public readonly bool $compactFloats = false,
1235 Z_PARAM_BOOL(compact_floats
)
1236 //public readonly bool $escapeNonAscii = false,
1237 Z_PARAM_BOOL(escape
)
1238 //public readonly bool $prettyPrint = false,
1239 Z_PARAM_BOOL(pretty
)
1240 //public readonly bool $indentTabs = true,
1242 //public readonly int $indentSize = 2,
1243 Z_PARAM_LONG(indent
)
1244 //public readonly bool $flushEveryValue = false,
1246 //public readonly int $maxContainerDepth = 10,
1247 Z_PARAM_LONG(max_depth
)
1248 //public readonly int $maxAnnotations = 10,
1249 Z_PARAM_LONG(max_ann
)
1250 //public readonly int $tempBufferSize = 0x4000,
1252 ZEND_PARSE_PARAMETERS_END();
1255 update_property_obj(&obj
->std
, ZEND_STRL("catalog"), obj
->cat
);
1256 obj
->opt
.pcatalog
= php_ion_obj(catalog
, obj
->cat
)->cat
;
1258 zend_update_property_null(NULL
, &obj
->std
, ZEND_STRL("catalog"));
1261 update_property_obj(&obj
->std
, ZEND_STRL("decimalContext"), obj
->dec_ctx
);
1262 obj
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, obj
->dec_ctx
)->ctx
;
1264 zend_update_property_null(NULL
, &obj
->std
, ZEND_STRL("decimalContext"));
1266 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("outputBinary"),
1267 obj
->opt
.output_as_binary
= binary
);
1268 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("compactFloats"),
1269 obj
->opt
.compact_floats
= compact_floats
);
1270 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("escapeNonAscii"),
1271 obj
->opt
.escape_all_non_ascii
= escape
);
1272 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("prettyPrint"),
1273 obj
->opt
.pretty_print
= pretty
);
1274 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentTabs"),
1275 obj
->opt
.indent_with_tabs
= tabs
);
1276 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentSize"),
1277 obj
->opt
.indent_size
= (SIZE
) indent
);
1278 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("flushEveryValue"),
1279 obj
->opt
.flush_every_value
= flush
);
1280 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxContainerDepth"),
1281 obj
->opt
.max_container_depth
= (SIZE
) max_depth
);
1282 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxAnnotations"),
1283 obj
->opt
.max_annotation_count
= (SIZE
) max_ann
);
1284 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("tempBufferSize"),
1285 obj
->opt
.temp_buffer_size
= (SIZE
) temp
);
1287 static ZEND_METHOD(ion_Writer_Writer
, writeNull
)
1289 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1292 ZEND_PARSE_PARAMETERS_NONE();
1294 ION_CHECK(ion_writer_write_null(obj
->writer
));
1296 static ZEND_METHOD(ion_Writer_Writer
, writeTypedNull
)
1298 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1301 zend_object
*typ_obj
;
1302 ZEND_PARSE_PARAMETERS_START(1, 1)
1303 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1304 ZEND_PARSE_PARAMETERS_END();
1306 ION_CHECK(ion_writer_write_typed_null(obj
->writer
, ion_type_from_enum(typ_obj
)));
1308 static ZEND_METHOD(ion_Writer_Writer
, writeBool
)
1310 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1314 ZEND_PARSE_PARAMETERS_START(1, 1)
1316 ZEND_PARSE_PARAMETERS_END();
1318 ION_CHECK(ion_writer_write_bool(obj
->writer
, b
));
1320 static ZEND_METHOD(ion_Writer_Writer
, writeInt
)
1322 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1327 ZEND_PARSE_PARAMETERS_START(1, 1)
1328 Z_PARAM_STR_OR_LONG(s
, l
)
1329 ZEND_PARSE_PARAMETERS_END();
1333 ION_CHECK(ion_int_alloc(obj
->writer
, &i
));
1334 ION_CHECK(ion_int_from_chars(i
, s
->val
, s
->len
));
1335 ION_CHECK(ion_writer_write_ion_int(obj
->writer
, i
));
1338 ION_CHECK(ion_writer_write_int64(obj
->writer
, l
));
1341 static ZEND_METHOD(ion_Writer_Writer
, writeFloat
)
1343 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1347 ZEND_PARSE_PARAMETERS_START(1, 1)
1349 ZEND_PARSE_PARAMETERS_END();
1351 ION_CHECK(ion_writer_write_double(obj
->writer
, d
));
1353 static ZEND_METHOD(ion_Writer_Writer
, writeDecimal
)
1355 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1358 zend_object
*dec_obj
;
1359 zend_string
*dec_str
;
1360 ZEND_PARSE_PARAMETERS_START(1, 1)
1361 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj
, ce_Decimal
, dec_str
)
1362 ZEND_PARSE_PARAMETERS_END();
1365 decContext
*ctx
= &php_ion_globals
.decimal
.ctx
;
1366 ION_DECIMAL dec
= {0};
1369 php_ion_writer_options
*opt_obj
= php_ion_obj(writer_options
, obj
->opt
);
1370 if (opt_obj
->opt
.decimal_context
) {
1371 ctx
= opt_obj
->opt
.decimal_context
;
1374 ION_CHECK(ion_decimal_from_string(&dec
, dec_str
->val
, ctx
));
1375 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
));
1377 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
1378 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
1381 static ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
1383 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1386 zend_object
*ts_obj
;
1387 zend_string
*ts_str
;
1388 ZEND_PARSE_PARAMETERS_START(1, 1)
1389 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
1390 ZEND_PARSE_PARAMETERS_END();
1392 decContext
*ctx
= NULL
;
1394 ctx
= php_ion_obj(reader_options
, obj
->opt
)->opt
.decimal_context
;
1397 ION_TIMESTAMP tmp
= {0};
1400 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1402 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1404 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1406 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1408 static ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1410 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1413 zend_object
*sym_obj
;
1414 zend_string
*sym_str
;
1415 ZEND_PARSE_PARAMETERS_START(1, 1)
1416 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1417 ZEND_PARSE_PARAMETERS_END();
1421 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1423 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1425 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1428 static ZEND_METHOD(ion_Writer_Writer
, writeString
)
1430 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1434 ZEND_PARSE_PARAMETERS_START(1, 1)
1436 ZEND_PARSE_PARAMETERS_END();
1439 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1441 static ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1443 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1447 ZEND_PARSE_PARAMETERS_START(1, 1)
1449 ZEND_PARSE_PARAMETERS_END();
1451 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1453 static ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1455 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1459 ZEND_PARSE_PARAMETERS_START(1, 1)
1461 ZEND_PARSE_PARAMETERS_END();
1463 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1465 static ZEND_METHOD(ion_Writer_Writer
, startLob
)
1467 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1470 zend_object
*typ_obj
;
1471 ZEND_PARSE_PARAMETERS_START(1, 1)
1472 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1473 ZEND_PARSE_PARAMETERS_END();
1475 ION_CHECK(ion_writer_start_lob(obj
->writer
, ion_type_from_enum(typ_obj
)));
1477 static ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1479 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1483 ZEND_PARSE_PARAMETERS_START(1, 1)
1485 ZEND_PARSE_PARAMETERS_END();
1487 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1489 static ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1491 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1494 ZEND_PARSE_PARAMETERS_NONE();
1496 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1498 static ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1500 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1503 zend_object
*typ_obj
;
1504 ZEND_PARSE_PARAMETERS_START(1, 1)
1505 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1506 ZEND_PARSE_PARAMETERS_END();
1508 ION_CHECK(ion_writer_start_container(obj
->writer
, ion_type_from_enum(typ_obj
)));
1510 static ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1512 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1515 ZEND_PARSE_PARAMETERS_NONE();
1517 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1519 static ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1521 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1524 zend_object
*sym_obj
;
1525 zend_string
*sym_str
;
1526 ZEND_PARSE_PARAMETERS_START(1, 1)
1527 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1528 ZEND_PARSE_PARAMETERS_END();
1532 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1534 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1536 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1539 static ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1541 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1546 ZEND_PARSE_PARAMETERS_START(1, -1)
1547 Z_PARAM_VARIADIC('+', args
, argc
);
1548 ZEND_PARSE_PARAMETERS_END();
1550 for (unsigned i
= 0; i
< argc
; ++i
) {
1551 switch (Z_TYPE(args
[i
])) {
1554 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1558 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1563 static ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1565 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1568 ZEND_PARSE_PARAMETERS_NONE();
1571 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1574 static ZEND_METHOD(ion_Writer_Writer
, flush
)
1576 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1579 ZEND_PARSE_PARAMETERS_NONE();
1582 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1583 RETURN_LONG(flushed
);
1585 static ZEND_METHOD(ion_Writer_Writer
, finish
)
1587 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1590 ZEND_PARSE_PARAMETERS_NONE();
1593 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1594 RETURN_LONG(flushed
);
1596 static ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1598 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1601 ZEND_PARSE_PARAMETERS_START(0, 1)
1603 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1604 ZEND_PARSE_PARAMETERS_END();
1606 obj
->type
= BUFFER_WRITER
;
1607 php_ion_writer_ctor(obj
);
1609 static ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1611 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1614 ZEND_PARSE_PARAMETERS_NONE();
1616 RETVAL_STR(php_ion_writer_buffer_copy(obj
));
1618 static ZEND_METHOD(ion_Writer_Buffer_Writer
, resetBuffer
)
1620 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1623 ZEND_PARSE_PARAMETERS_NONE();
1625 php_ion_writer_buffer_reset(obj
);
1627 static ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1629 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1633 ZEND_PARSE_PARAMETERS_START(1, 2)
1634 Z_PARAM_RESOURCE(zstream
)
1636 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1637 ZEND_PARSE_PARAMETERS_END();
1639 obj
->type
= STREAM_WRITER
;
1640 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1642 php_ion_writer_ctor(obj
);
1644 static ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1646 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1649 ZEND_PARSE_PARAMETERS_NONE();
1650 PTR_CHECK(obj
->stream
.ptr
);
1652 GC_ADDREF(obj
->stream
.ptr
->res
);
1653 RETURN_RES(obj
->stream
.ptr
->res
);
1656 #define Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj_dest, iface_ce, impl_ce, arr_dest) \
1657 Z_PARAM_PROLOGUE(0,0) \
1658 if (!zend_parse_arg_obj(_arg, &(obj_dest), iface_ce, true)) { \
1659 if (UNEXPECTED(!zend_parse_arg_array(_arg, &(arr_dest), true, 0))) { \
1660 _error = (iface_ce)->name->val; \
1661 _error_code = ZPP_ERROR_WRONG_CLASS_OR_NULL; \
1665 object_init_ex(&tmp, impl_ce); \
1666 *(&(obj_dest)) = Z_OBJ(tmp); \
1667 zend_call_known_function((impl_ce)->constructor, obj_dest, impl_ce, \
1668 NULL, 0, NULL, Z_ARRVAL_P(arr_dest)); \
1669 if (EG(exception)) { \
1670 OBJ_RELEASE(obj_dest); \
1675 static ZEND_METHOD(ion_Serializer_PHP
, __construct
)
1677 php_ion_serializer_php
*obj
= php_ion_obj(serializer_php
, Z_OBJ_P(ZEND_THIS
));
1680 obj
->serializer
.call_magic
= true;
1682 zval
*za_opt
= NULL
;
1683 ZEND_PARSE_PARAMETERS_START(0, 4)
1685 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj
->opt
, ce_Writer_Options
, ce_Writer_Options
, za_opt
)
1686 Z_PARAM_BOOL(obj
->serializer
.multi_seq
)
1687 Z_PARAM_BOOL(obj
->serializer
.call_magic
)
1688 Z_PARAM_STR_OR_NULL(obj
->serializer
.call_custom
)
1689 ZEND_PARSE_PARAMETERS_END();
1691 php_ion_serializer_php_ctor(obj
);
1693 OBJ_RELEASE(obj
->opt
);
1696 static ZEND_METHOD(ion_Serializer_PHP
, serialize
)
1698 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1701 ZEND_PARSE_PARAMETERS_START(1, 1)
1703 ZEND_PARSE_PARAMETERS_END();
1705 php_ion_serialize(&php_ion_obj(serializer_php
, obj
)->serializer
, data
, return_value
);
1707 static ZEND_FUNCTION(ion_serialize
)
1709 zval
*data
, *za_ser
= NULL
;
1710 zend_object
*zo_ser
= NULL
;
1711 ZEND_PARSE_PARAMETERS_START(1, 2)
1714 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_ser
, ce_Serializer
, ce_Serializer_PHP
, za_ser
)
1715 ZEND_PARSE_PARAMETERS_END();
1717 if (!zo_ser
|| zo_ser
->ce
== ce_Serializer_PHP
) {
1718 // default, fast path
1719 php_ion_serializer
*ser
= zo_ser
? &php_ion_obj(serializer_php
, zo_ser
)->serializer
: NULL
;
1720 php_ion_serialize(ser
, data
, return_value
);
1722 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "serialize", return_value
, data
);
1726 OBJ_RELEASE(zo_ser
);
1730 static ZEND_METHOD(ion_Unserializer_PHP
, __construct
)
1732 php_ion_unserializer_php
*obj
= php_ion_obj(unserializer_php
, Z_OBJ_P(ZEND_THIS
));
1735 obj
->unserializer
.call_magic
= true;
1737 zval
*za_opt
= NULL
;
1738 ZEND_PARSE_PARAMETERS_START(0, 4)
1740 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj
->opt
, ce_Reader_Options
, ce_Reader_Options
, za_opt
)
1741 Z_PARAM_BOOL(obj
->unserializer
.multi_seq
)
1742 Z_PARAM_BOOL(obj
->unserializer
.call_magic
)
1743 Z_PARAM_STR_OR_NULL(obj
->unserializer
.call_custom
)
1744 ZEND_PARSE_PARAMETERS_END();
1746 php_ion_unserializer_php_ctor(obj
);
1748 OBJ_RELEASE(obj
->opt
);
1751 static ZEND_METHOD(ion_Unserializer_PHP
, unserialize
)
1753 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1756 ZEND_PARSE_PARAMETERS_START(1, 1)
1758 ZEND_PARSE_PARAMETERS_END();
1760 php_ion_unserialize(&php_ion_obj(unserializer_php
, obj
)->unserializer
, data
, return_value
);
1762 static ZEND_FUNCTION(ion_unserialize
)
1764 zval
*data
, *za_ser
= NULL
;
1765 zend_object
*zo_ser
= NULL
;
1766 ZEND_PARSE_PARAMETERS_START(1, 2)
1769 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_ser
, ce_Unserializer
, ce_Unserializer_PHP
, za_ser
)
1770 ZEND_PARSE_PARAMETERS_END();
1772 if (!zo_ser
|| zo_ser
->ce
== ce_Unserializer_PHP
) {
1773 // default, fast path
1774 php_ion_unserializer
*ser
= zo_ser
? &php_ion_obj(unserializer_php
, zo_ser
)->unserializer
: NULL
;
1775 php_ion_unserialize(ser
, data
, return_value
);
1777 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "unserialize", return_value
, data
);
1781 OBJ_RELEASE(zo_ser
);
1785 PHP_RINIT_FUNCTION(ion
)
1787 #if defined(ZTS) && defined(COMPILE_DL_ION)
1788 ZEND_TSRMLS_CACHE_UPDATE();
1791 php_ion_globals_symbols_init();
1792 php_ion_globals_serializer_init();
1793 php_ion_globals_unserializer_init();
1797 PHP_RSHUTDOWN_FUNCTION(ion
)
1799 php_ion_globals_unserializer_dtor();
1800 php_ion_globals_serializer_dtor();
1801 php_ion_globals_symbols_dtor();
1805 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
1806 { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, ((type_mask) | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0))), default_value },
1807 #include "ion_arginfo.h"
1809 // spl_iterators.h includes ext/pcre/php_pcre.h which might not find pcre2.h
1810 extern PHPAPI zend_class_entry
*spl_ce_RecursiveIterator
;
1812 PHP_MINIT_FUNCTION(ion
)
1815 if (SUCCESS
!= g_sym_init()) {
1818 g_intern_str_init();
1821 php_ion_register(catalog
, Catalog
, zend_ce_countable
);
1824 php_ion_register(decimal
, Decimal
);
1825 php_ion_register(decimal_ctx
, Decimal_Context
);
1826 ce_Decimal_Context_Rounding
= register_class_ion_Decimal_Context_Rounding();
1829 ce_Exception
= register_class_ion_Exception(zend_ce_exception
);
1832 ce_LOB
= register_class_ion_LOB();
1835 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1836 php_ion_register(reader_options
, Reader_Options
);
1837 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1838 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1839 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1840 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1841 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1844 ce_Serializer
= register_class_ion_Serializer();
1845 php_ion_register(serializer_php
, Serializer_PHP
, ce_Serializer
);
1848 php_ion_register(symbol
, Symbol
);
1849 oh_Symbol
.compare
= php_ion_symbol_zval_compare
;
1850 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1851 php_ion_register(symbol_table
, Symbol_Table
);
1852 ce_Symbol_Table
->create_object
= NULL
;
1853 ce_Symbol_Table_Local
= register_class_ion_Symbol_Table_Local(ce_Symbol_Table
);
1854 ce_Symbol_Table_Local
->create_object
= create_ion_Symbol_Table
;
1855 ce_Symbol_Table_Shared
= register_class_ion_Symbol_Table_Shared(ce_Symbol_Table
);
1856 ce_Symbol_Table_Shared
->create_object
= create_ion_Symbol_Table
;
1857 ce_Symbol_Enum
= register_class_ion_Symbol_Enum();
1858 ce_Symbol_Table_System
= register_class_ion_Symbol_System(ce_Symbol_Enum
);
1859 ce_Symbol_Table_PHP
= register_class_ion_Symbol_PHP(ce_Symbol_Enum
);
1862 ce_Timestamp
= register_class_ion_Timestamp(php_date_get_date_ce());
1863 ce_Timestamp_Format
= register_class_ion_Timestamp_Format();
1864 ce_Timestamp_Precision
= register_class_ion_Timestamp_Precision();
1867 ce_Type
= register_class_ion_Type();
1870 ce_Writer
= register_class_ion_Writer();
1871 php_ion_register(writer_options
, Writer_Options
);
1872 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1873 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1874 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1875 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1876 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1879 ce_Unserializer
= register_class_ion_Unserializer();
1880 php_ion_register(unserializer_php
, Unserializer_PHP
, ce_Unserializer
);
1885 PHP_MSHUTDOWN_FUNCTION(ion
)
1887 if (g_sym_tab_php
) {
1888 ion_symbol_table_close(g_sym_tab_php
);
1890 zend_hash_destroy(&g_sym_hash
);
1894 PHP_MINFO_FUNCTION(ion
)
1896 php_info_print_table_start();
1897 php_info_print_table_header(2, "ion support", "enabled");
1898 php_info_print_table_end();
1901 PHP_GINIT_FUNCTION(ion
)
1903 memset(ion_globals
, 0, sizeof(*ion_globals
));
1905 php_ion_decimal_ctx_init_max(&ion_globals
->decimal
.ctx
, DEC_ROUND_HALF_EVEN
);
1906 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_max
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MAX
);
1907 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_min
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MIN
);
1910 PHP_GSHUTDOWN_FUNCTION(ion
)
1914 static zend_module_dep ion_module_deps
[] = {
1915 ZEND_MOD_REQUIRED("date")
1916 ZEND_MOD_REQUIRED("spl")
1920 zend_module_entry ion_module_entry
= {
1921 STANDARD_MODULE_HEADER_EX
,
1924 "ion", /* Extension name */
1925 ext_functions
, /* zend_function_entry */
1926 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1927 PHP_MSHUTDOWN(ion
), /* PHP_MSHUTDOWN - Module shutdown */
1928 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1929 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1930 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1931 PHP_ION_VERSION
, /* Version */
1932 ZEND_MODULE_GLOBALS(ion
),
1933 PHP_GINIT(ion
), /* PHP_GINIT */
1934 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1936 STANDARD_MODULE_PROPERTIES_EX
1939 #ifdef COMPILE_DL_ION
1941 ZEND_TSRMLS_CACHE_DEFINE()
1943 ZEND_GET_MODULE(ion
)