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 #define Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj_dest, iface_ce, impl_ce, arr_dest) \
33 Z_PARAM_PROLOGUE(0,0) \
34 if (!zend_parse_arg_obj(_arg, &(obj_dest), iface_ce, true) && !zend_parse_arg_obj(_arg, &(obj_dest), impl_ce, true)) { \
35 if (UNEXPECTED(!zend_parse_arg_array(_arg, &(arr_dest), true, 0))) { \
36 _error = (iface_ce)->name->val; \
37 _error_code = ZPP_ERROR_WRONG_CLASS_OR_NULL; \
41 object_init_ex(&tmp, impl_ce); \
42 *(&(obj_dest)) = Z_OBJ(tmp); \
43 zend_call_known_function((impl_ce)->constructor, obj_dest, impl_ce, \
44 NULL, 0, NULL, Z_ARRVAL_P(arr_dest)); \
45 if (EG(exception)) { \
46 OBJ_RELEASE(obj_dest); \
51 static ZEND_METHOD(ion_Symbol_ImportLocation
, __construct
)
53 php_ion_symbol_iloc
*obj
= php_ion_obj(symbol_iloc
, Z_OBJ_P(ZEND_THIS
));
57 ZEND_PARSE_PARAMETERS_START(2, 2)
58 Z_PARAM_STR(obj
->name
)
59 Z_PARAM_LONG(location
)
60 ZEND_PARSE_PARAMETERS_END();
62 obj
->loc
.location
= (SID
) location
;
63 php_ion_symbol_iloc_ctor(obj
);
65 static ZEND_METHOD(ion_Symbol
, __construct
)
67 php_ion_symbol
*obj
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
71 ZEND_PARSE_PARAMETERS_START(0, 3)
73 Z_PARAM_STR_OR_NULL(obj
->value
)
75 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->iloc
, ce_Symbol_ImportLocation
)
76 ZEND_PARSE_PARAMETERS_END();
78 obj
->sym
.sid
= (SID
) sid
;
79 php_ion_symbol_ctor(obj
);
81 static ZEND_METHOD(ion_Symbol
, equals
)
83 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
86 zend_object
*other_obj
;
87 ZEND_PARSE_PARAMETERS_START(1, 1)
88 Z_PARAM_OBJ_OF_CLASS(other_obj
, ce_Symbol
)
89 ZEND_PARSE_PARAMETERS_END();
92 iERR err
= ion_symbol_is_equal(
94 &php_ion_obj(symbol
, other_obj
)->sym
, &eq
);
98 static ZEND_METHOD(ion_Symbol
, __toString
)
100 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
103 ZEND_PARSE_PARAMETERS_NONE();
106 RETURN_EMPTY_STRING();
108 RETURN_STR_COPY(sym
->value
);
110 static ZEND_METHOD(ion_Symbol_Enum
, toSymbol
)
112 ZEND_PARSE_PARAMETERS_NONE();
114 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
117 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
119 RETVAL_ZVAL(zsym
, 1, 0);
121 static ZEND_METHOD(ion_Symbol_Enum
, toSID
)
123 ZEND_PARSE_PARAMETERS_NONE();
125 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
128 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
132 RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym
), Z_OBJ_P(zsym
), ZEND_STRL("sid"), 0, &tmp
), 1, 0);
134 static ZEND_METHOD(ion_Symbol_Enum
, toString
)
136 ZEND_PARSE_PARAMETERS_NONE();
138 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
141 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
145 RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym
), Z_OBJ_P(zsym
), ZEND_STRL("value"), 0, &tmp
), 1, 0);
147 static ZEND_METHOD(ion_Symbol_System
, asTable
)
149 ZEND_PARSE_PARAMETERS_NONE();
151 object_init_ex(return_value
, ce_Symbol_Table_Shared
);
152 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(return_value
));
153 ION_CHECK(ion_symbol_table_get_system_table(&obj
->tab
, 1));
154 php_ion_symbol_table_ctor(obj
);
155 ion_symbol_table_lock(obj
->tab
);
157 static ZEND_METHOD(ion_Symbol_PHP
, asTable
)
159 ZEND_PARSE_PARAMETERS_NONE();
161 object_init_ex(return_value
, ce_Symbol_Table_Shared
);
162 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(return_value
));
163 obj
->tab
= g_sym_tab_php
;
164 php_ion_symbol_table_ctor(obj
);
165 ion_symbol_table_lock(obj
->tab
);
167 static ZEND_METHOD(ion_Symbol_Table_Local
, __construct
)
169 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
172 ZEND_PARSE_PARAMETERS_NONE();
174 ION_CHECK(ion_symbol_table_open_with_type(&obj
->tab
, NULL
, ist_LOCAL
));
175 obj
->dtor
= ion_symbol_table_close
;
178 static ZEND_METHOD(ion_Symbol_Table_Local
, import
)
180 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
183 zend_object
*zo_import
;
184 ZEND_PARSE_PARAMETERS_START(1, 1)
185 Z_PARAM_OBJ_OF_CLASS(zo_import
, ce_Symbol_Table
);
186 ZEND_PARSE_PARAMETERS_END();
188 php_ion_symbol_table_import(obj
, php_ion_obj(symbol_table
, zo_import
));
190 static ZEND_METHOD(ion_Symbol_Table_Shared
, __construct
)
192 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
196 zend_long version
= 1;
197 HashTable
*ht_sym
= NULL
;
198 ZEND_PARSE_PARAMETERS_START(1, 3)
201 Z_PARAM_LONG(version
)
202 Z_PARAM_ARRAY_HT_OR_NULL(ht_sym
)
203 ZEND_PARSE_PARAMETERS_END();
205 ION_CHECK(ion_symbol_table_open_with_type(&obj
->tab
, NULL
, ist_SHARED
));
206 obj
->dtor
= ion_symbol_table_close
;
209 ION_CHECK(ion_symbol_table_set_name(obj
->tab
, ion_string_from_zend(&is
, zname
)));
210 ION_CHECK(ion_symbol_table_set_version(obj
->tab
, version
));
212 php_ion_symbol_table_ctor(obj
);
215 if (ht_sym
) ZEND_HASH_FOREACH_VAL(ht_sym
, zsym
)
217 zend_string
*str
= zval_get_string(zsym
);
223 ION_CHECK(ion_symbol_table_add_symbol(obj
->tab
, ion_string_from_zend(&istr
, str
), NULL
), zend_string_release(str
));
224 zend_string_release(str
);
226 ZEND_HASH_FOREACH_END();
228 static ZEND_METHOD(ion_Symbol_Table
, getMaxId
)
230 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
233 ZEND_PARSE_PARAMETERS_NONE();
236 ION_CHECK(ion_symbol_table_get_max_sid(obj
->tab
, &max_sid
));
237 RETURN_LONG(max_sid
);
239 static ZEND_METHOD(ion_Symbol_Table
, add
)
241 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
244 zend_object
*zo_sym
= NULL
;
245 zend_string
*zs_sym
= NULL
;
246 ZEND_PARSE_PARAMETERS_START(1, 1)
247 Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_sym
, ce_Symbol
, zs_sym
)
248 ZEND_PARSE_PARAMETERS_END();
252 ZVAL_OBJ(&z_sym
, zo_sym
);
253 zs_sym
= zval_get_string(&z_sym
);
258 ION_CHECK(ion_symbol_table_add_symbol(obj
->tab
, ion_string_from_zend(&is
, zs_sym
), &sid
),
260 zend_string_release(zs_sym
);
263 zend_string_release(zs_sym
);
267 static ZEND_METHOD(ion_Symbol_Table
, find
)
269 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
273 zend_string
*zstring
= NULL
;
274 ZEND_PARSE_PARAMETERS_START(1, 1)
275 Z_PARAM_STR_OR_LONG(zstring
, zsid
)
276 ZEND_PARSE_PARAMETERS_END();
281 ION_CHECK(ion_symbol_table_find_by_name(obj
->tab
, ion_string_from_zend(&is
, zstring
), &sid
));
285 ION_CHECK(ion_symbol_table_get_symbol(obj
->tab
, zsid
, &sym
));
287 php_ion_symbol_table_symbol_zval(obj
, sym
, return_value
);
290 static ZEND_METHOD(ion_Symbol_Table
, findLocal
)
292 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
296 zend_string
*zstring
;
297 ZEND_PARSE_PARAMETERS_START(1, 1)
298 Z_PARAM_STR_OR_LONG(zstring
, zsid
)
299 ZEND_PARSE_PARAMETERS_END();
304 ION_CHECK(ion_symbol_table_find_by_name(obj
->tab
, ion_string_from_zend(&is
, zstring
), &sid
));
308 ION_CHECK(ion_symbol_table_get_local_symbol(obj
->tab
, zsid
, &sym
));
310 php_ion_symbol_table_symbol_zval(obj
, sym
, return_value
);
313 static ZEND_METHOD(ion_Catalog
, __construct
)
315 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
318 ZEND_PARSE_PARAMETERS_NONE();
320 php_ion_catalog_ctor(obj
);
322 static ZEND_METHOD(ion_Catalog
, count
)
324 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
327 ZEND_PARSE_PARAMETERS_NONE();
330 ION_CHECK(ion_catalog_get_symbol_table_count(obj
->cat
, &c
));
333 static ZEND_METHOD(ion_Catalog
, add
)
335 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
338 zend_object
*zo_symtab
;
339 ZEND_PARSE_PARAMETERS_START(1, 1)
340 Z_PARAM_OBJ_OF_CLASS(zo_symtab
, ce_Symbol_Table
)
341 ZEND_PARSE_PARAMETERS_END();
343 php_ion_symbol_table
*o_symtab
= php_ion_obj(symbol_table
, zo_symtab
);
344 php_ion_catalog_add_symbol_table(obj
, o_symtab
);
347 static ZEND_METHOD(ion_Catalog
, remove
)
349 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
352 zend_object
*zo_symtab
= NULL
;
353 zend_string
*zs_symtab
= NULL
;
354 ZEND_PARSE_PARAMETERS_START(1, 1)
355 Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_symtab
, ce_Symbol_Table
, zs_symtab
)
356 ZEND_PARSE_PARAMETERS_END();
361 zval
*ztabs
= zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("symbolTables"), 0, &tmp
);
365 zend_ulong idx
= (uintptr_t) &zo_symtab
->gc
;
366 RETVAL_BOOL(SUCCESS
== zend_hash_index_del(Z_ARRVAL_P(ztabs
), idx
));
367 ION_CHECK(ion_catalog_release_symbol_table(obj
->cat
, php_ion_obj(symbol_table
, zo_symtab
)->tab
));
369 bool deleted
= false;
370 ION_SYMBOL_TABLE
*tab
;
372 ion_string_from_zend(&is
, zs_symtab
);
375 ION_CHECK(ion_catalog_find_best_match(obj
->cat
, &is
, 0, &tab
));
377 ION_CHECK(ion_catalog_release_symbol_table(obj
->cat
, tab
));
381 RETVAL_BOOL(deleted
);
385 static ZEND_METHOD(ion_Catalog
, find
)
387 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
390 zend_long zversion
= 0;
392 ZEND_PARSE_PARAMETERS_START(1, 2)
395 Z_PARAM_LONG(zversion
)
396 ZEND_PARSE_PARAMETERS_END();
399 ION_SYMBOL_TABLE
*tab_ptr
= NULL
;
400 ION_CHECK(ion_catalog_find_symbol_table(obj
->cat
, ion_string_from_zend(&is
, zname
), zversion
, &tab_ptr
));
402 php_ion_catalog_symbol_table_zval(obj
, tab_ptr
, return_value
);
405 static ZEND_METHOD(ion_Catalog
, findBest
)
407 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
410 zend_long zversion
= 0;
412 ZEND_PARSE_PARAMETERS_START(1, 2)
415 Z_PARAM_LONG(zversion
)
416 ZEND_PARSE_PARAMETERS_END();
419 ION_SYMBOL_TABLE
*tab_ptr
= NULL
;
420 ION_CHECK(ion_catalog_find_best_match(obj
->cat
, ion_string_from_zend(&is
, zname
), zversion
, &tab_ptr
));
422 php_ion_catalog_symbol_table_zval(obj
, tab_ptr
, return_value
);
425 static ZEND_METHOD(ion_Timestamp
, __construct
)
427 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
431 zend_object
*precision_obj
= NULL
, *format_obj
= NULL
;
432 zend_string
*fmt
= NULL
, *dt
= NULL
, *tz
= NULL
;
433 zend_object
*tz_obj
= NULL
;
434 zval z_tz_tmp
, *z_tz_ptr
= NULL
;
435 ZEND_PARSE_PARAMETERS_START(1, 4)
436 Z_PARAM_OBJ_OF_CLASS_OR_LONG(precision_obj
, ce_Timestamp_Precision
, precision
)
438 Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL(format_obj
, ce_Timestamp_Format
, fmt
)
439 Z_PARAM_STR_OR_NULL(dt
)
440 Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL(tz_obj
, php_date_get_timezone_ce(), tz
)
441 ZEND_PARSE_PARAMETERS_END();
444 precision
= Z_LVAL_P(zend_enum_fetch_case_value(precision_obj
));
447 fmt
= Z_STR_P(zend_enum_fetch_case_value(format_obj
));
450 ZVAL_OBJ(z_tz_ptr
= &z_tz_tmp
, tz_obj
);
452 // there's no public API, so call timezone_open
453 zend_function
*tz_open
= zend_fetch_function_str(ZEND_STRL("timezone_open"));
456 ZVAL_STR(&z_arg
, tz
);
457 zend_call_known_function(tz_open
, NULL
, NULL
, z_tz_ptr
= &z_tz_tmp
, 1, &z_arg
, NULL
);
460 php_ion_timestamp_ctor(obj
, precision
, fmt
, dt
, z_tz_ptr
);
461 if (tz
&& z_tz_ptr
) {
462 zval_ptr_dtor(z_tz_ptr
);
465 static ZEND_METHOD(ion_Timestamp
, __toString
)
467 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
470 ZEND_PARSE_PARAMETERS_NONE();
474 zend_call_method_with_1_params(&obj
->std
, obj
->std
.ce
, NULL
, "format", return_value
,
475 zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("format"), 0, &fmt
));
477 static ZEND_METHOD(ion_Decimal_Context
, __construct
)
479 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(ZEND_THIS
));
483 zend_object
*o_round
= NULL
;
484 zend_long digits
, emax
, emin
, round
;
485 ZEND_PARSE_PARAMETERS_START(5, 5)
489 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
491 ZEND_PARSE_PARAMETERS_END();
494 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
496 php_ion_decimal_ctx_init(&obj
->ctx
, digits
, emax
, emin
, round
, clamp
); // NOLINT(cppcoreguidelines-narrowing-conversions)
497 php_ion_decimal_ctx_ctor(obj
, o_round
);
499 static inline void make_decimal_ctx(INTERNAL_FUNCTION_PARAMETERS
, int kind
)
501 ZEND_PARSE_PARAMETERS_NONE();
503 object_init_ex(return_value
, ce_Decimal_Context
);
504 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
505 decContextDefault(&obj
->ctx
, kind
);
506 php_ion_decimal_ctx_ctor(obj
, NULL
);
508 static ZEND_METHOD(ion_Decimal_Context
, Dec32
)
510 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL32
);
512 static ZEND_METHOD(ion_Decimal_Context
, Dec64
)
514 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL64
);
516 static ZEND_METHOD(ion_Decimal_Context
, Dec128
)
518 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL128
);
520 static ZEND_METHOD(ion_Decimal_Context
, DecMax
)
522 zend_object
*o_round
= NULL
;
523 zend_long round
= DEC_ROUND_HALF_EVEN
;
524 ZEND_PARSE_PARAMETERS_START(0, 1)
526 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
527 ZEND_PARSE_PARAMETERS_END();
530 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
532 object_init_ex(return_value
, ce_Decimal_Context
);
533 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
534 php_ion_decimal_ctx_init_max(&obj
->ctx
, round
);
535 php_ion_decimal_ctx_ctor(obj
, o_round
);
537 static ZEND_METHOD(ion_Decimal
, __construct
)
539 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
544 ZEND_PARSE_PARAMETERS_START(1, 2)
545 Z_PARAM_STR_OR_LONG(zstr
, num
)
547 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->ctx
, ce_Decimal_Context
)
548 ZEND_PARSE_PARAMETERS_END();
554 object_init_ex(&zdc
, ce_Decimal_Context
);
555 obj
->ctx
= Z_OBJ(zdc
);
556 php_ion_decimal_ctx_ctor(php_ion_obj(decimal_ctx
, obj
->ctx
), NULL
);
559 decContext
*ctx
= &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
;
562 ION_CHECK(ion_decimal_from_string(&obj
->dec
, zstr
->val
, ctx
), OBJ_RELEASE(obj
->ctx
));
564 php_ion_decimal_from_zend_long(&obj
->dec
, ctx
, num
);
567 php_ion_decimal_ctor(obj
);
568 OBJ_RELEASE(obj
->ctx
);
570 static ZEND_METHOD(ion_Decimal
, equals
)
572 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
575 zend_object
*dec_obj
;
576 ZEND_PARSE_PARAMETERS_START(1, 1)
577 Z_PARAM_OBJ_OF_CLASS(dec_obj
, ce_Decimal
)
578 ZEND_PARSE_PARAMETERS_END();
581 ION_CHECK(ion_decimal_equals(&obj
->dec
, &php_ion_obj(decimal
, dec_obj
)->dec
,
582 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &is
));
585 static ZEND_METHOD(ion_Decimal
, __toString
)
587 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
590 ZEND_PARSE_PARAMETERS_NONE();
592 RETURN_STR(php_ion_decimal_to_string(&obj
->dec
));
594 static ZEND_METHOD(ion_Decimal
, toInt
)
596 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
599 ZEND_PARSE_PARAMETERS_NONE();
602 php_ion_decimal_to_zend_long(&obj
->dec
, &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
, &l
);
605 static ZEND_METHOD(ion_Decimal
, isInt
)
607 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
610 ZEND_PARSE_PARAMETERS_NONE();
612 RETURN_BOOL(ion_decimal_is_integer(&obj
->dec
));
614 static ZEND_METHOD(ion_LOB
, __construct
)
617 zend_object
*type
= NULL
;
618 ZEND_PARSE_PARAMETERS_START(1, 2)
621 Z_PARAM_OBJ_OF_CLASS(type
, ce_Type
)
622 ZEND_PARSE_PARAMETERS_END();
625 type
= zend_enum_get_case_cstr(ce_Type
, "CLob");
627 update_property_obj(Z_OBJ_P(ZEND_THIS
), ZEND_STRL("type"), type
);
628 zend_update_property_str(Z_OBJCE_P(ZEND_THIS
), Z_OBJ_P(ZEND_THIS
), ZEND_STRL("value"), value
);
630 static ZEND_METHOD(ion_Reader_Options
, __construct
)
632 php_ion_reader_options
*opt
= php_ion_obj(reader_options
, Z_OBJ_P(ZEND_THIS
));
633 zend_bool ret_sys_val
= false, skip_validation
= false;
634 zend_long max_depth
= 10, max_ann
= 10, ann_buf_siz
= 0x4000, tmp_buf_siz
= 0x4000;
638 ZEND_PARSE_PARAMETERS_START(0, 9)
640 // public readonly ?\ion\Catalog $catalog = null,
641 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cat
, ce_Catalog
)
642 // public readonly ?\ion\Decimal\Context $decimalContext = null,
643 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->dec_ctx
, ce_Decimal_Context
)
644 // public readonly ?\Closure $onContextChange = null,
645 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cb
, zend_ce_closure
);
646 // public readonly bool $returnSystemValues = false,
647 Z_PARAM_BOOL(ret_sys_val
)
648 // public readonly int $maxContainerDepth = 10,
649 Z_PARAM_LONG(max_depth
)
650 // public readonly int $maxAnnotations = 10,
651 Z_PARAM_LONG(max_ann
)
652 // public readonly int $annotationBufferSize = 0x4000,
653 Z_PARAM_LONG(ann_buf_siz
)
654 // public readonly int $tempBufferSize = 0x4000,
655 Z_PARAM_LONG(tmp_buf_siz
)
656 // public readonly bool $skipCharacterValidation = false,
657 Z_PARAM_BOOL(skip_validation
)
658 ZEND_PARSE_PARAMETERS_END();
662 ZVAL_OBJ(&zcb
, opt
->cb
);
663 zend_fcall_info_init(&zcb
, 0, &opt
->ccn
.fci
, &opt
->ccn
.fcc
, NULL
, NULL
);
664 opt
->opt
.context_change_notifier
.context
= &opt
->ccn
;
665 update_property_obj(&opt
->std
, ZEND_STRL("onContextChange"), opt
->cb
);
667 zend_update_property_null(NULL
, &opt
->std
, ZEND_STRL("onContextChange"));
670 update_property_obj(&opt
->std
, ZEND_STRL("catalog"), opt
->cat
);
671 opt
->opt
.pcatalog
= php_ion_obj(catalog
, opt
->cat
)->cat
;
673 zend_update_property_null(NULL
, &opt
->std
, ZEND_STRL("catalog"));
676 update_property_obj(&opt
->std
, ZEND_STRL("decimalContext"), opt
->dec_ctx
);
677 opt
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, opt
->dec_ctx
)->ctx
;
679 zend_update_property_null(NULL
, &opt
->std
, ZEND_STRL("decimalContext"));
681 zend_update_property_bool(opt
->std
.ce
, &opt
->std
, ZEND_STRL("returnSystemValues"),
682 opt
->opt
.return_system_values
= ret_sys_val
);
683 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxContainerDepth"),
684 opt
->opt
.max_container_depth
= (SIZE
) max_depth
);
685 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotations"),
686 opt
->opt
.max_annotation_count
= (SIZE
) max_ann
);
687 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("annotationBufferSize"),
688 opt
->opt
.max_annotation_buffered
= (SIZE
) ann_buf_siz
);
689 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("tempBufferSize"),
690 opt
->opt
.chunk_threshold
= opt
->opt
.user_value_threshold
= opt
->opt
.symbol_threshold
= (SIZE
) tmp_buf_siz
);
691 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("skipCharacterValidation"),
692 opt
->opt
.skip_character_validation
= (SIZE
) skip_validation
);
694 static ZEND_METHOD(ion_Reader_Reader
, hasChildren
)
696 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
699 ZEND_PARSE_PARAMETERS_NONE();
702 ION_CHECK(ion_reader_get_type(obj
->reader
, &t
));
703 switch (ION_TYPE_INT(t
)) {
714 static ZEND_METHOD(ion_Reader_Reader
, getChildren
)
716 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
719 ZEND_PARSE_PARAMETERS_NONE();
721 ION_CHECK(ion_reader_step_in(obj
->reader
));
723 RETURN_ZVAL(ZEND_THIS
, 1, 0);
725 static ZEND_METHOD(ion_Reader_Reader
, rewind
)
727 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
730 ZEND_PARSE_PARAMETERS_NONE();
732 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
734 static ZEND_METHOD(ion_Reader_Reader
, next
)
736 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
739 ZEND_PARSE_PARAMETERS_NONE();
741 if (obj
->state
== tid_EOF
) {
743 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
745 ION_CHECK(ion_reader_step_out(obj
->reader
));
748 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
750 static ZEND_METHOD(ion_Reader_Reader
, valid
)
752 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
755 ZEND_PARSE_PARAMETERS_NONE();
756 RETURN_BOOL(obj
->state
!= tid_none
&& obj
->state
!= tid_EOF
);
758 static ZEND_METHOD(ion_Reader_Reader
, key
)
760 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
763 ZEND_PARSE_PARAMETERS_NONE();
764 RETURN_IONTYPE(obj
->state
);
766 static ZEND_METHOD(ion_Reader_Reader
, current
)
768 ZEND_PARSE_PARAMETERS_NONE();
769 RETURN_ZVAL(ZEND_THIS
, 1, 0);
771 static ZEND_METHOD(ion_Reader_Reader
, getType
)
773 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
776 ZEND_PARSE_PARAMETERS_NONE();
779 ION_CHECK(ion_reader_get_type(obj
->reader
, &typ
));
782 static ZEND_METHOD(ion_Reader_Reader
, hasAnnotations
)
784 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
787 ZEND_PARSE_PARAMETERS_NONE();
790 ION_CHECK(ion_reader_has_any_annotations(obj
->reader
, &has
));
793 static ZEND_METHOD(ion_Reader_Reader
, hasAnnotation
)
795 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
798 zend_string
*ann_zstr
;
799 ZEND_PARSE_PARAMETERS_START(1, 1);
800 Z_PARAM_STR(ann_zstr
);
801 ZEND_PARSE_PARAMETERS_END();
805 ION_CHECK(ion_reader_has_annotation(obj
->reader
, ion_string_from_zend(&ann_istr
, ann_zstr
), &has
));
808 static ZEND_METHOD(ion_Reader_Reader
, isNull
)
810 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
813 ZEND_PARSE_PARAMETERS_NONE();
816 ION_CHECK(ion_reader_is_null(obj
->reader
, &is
));
819 static ZEND_METHOD(ion_Reader_Reader
, isInStruct
)
821 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
824 ZEND_PARSE_PARAMETERS_NONE();
827 ION_CHECK(ion_reader_is_in_struct(obj
->reader
, &is
));
830 static ZEND_METHOD(ion_Reader_Reader
, getFieldName
)
832 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
835 ZEND_PARSE_PARAMETERS_NONE();
838 ION_CHECK(ion_reader_get_field_name(obj
->reader
, &name
));
839 RETURN_STRINGL((char *) name
.value
, name
.length
);
841 static ZEND_METHOD(ion_Reader_Reader
, getFieldNameSymbol
)
843 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
846 ZEND_PARSE_PARAMETERS_NONE();
849 ION_CHECK(ion_reader_get_field_name_symbol(obj
->reader
, &sym_ptr
));
851 php_ion_symbol_zval(sym_ptr
, return_value
);
853 static ZEND_METHOD(ion_Reader_Reader
, getAnnotations
)
855 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
858 ZEND_PARSE_PARAMETERS_NONE();
862 max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
866 ION_STRING
*ptr
= ecalloc(sizeof(*ptr
), max
);
867 iERR err
= ion_reader_get_annotations(obj
->reader
, ptr
, max
, &count
);
869 array_init_size(return_value
, count
);
870 for (int32_t i
= 0; i
< count
; ++i
) {
871 add_next_index_str(return_value
, zend_string_from_ion(&ptr
[i
]));
877 static ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbols
)
879 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
882 ZEND_PARSE_PARAMETERS_NONE();
886 max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
890 ION_SYMBOL
*ptr
= ecalloc(sizeof(*ptr
), max
);
891 iERR err
= ion_reader_get_annotation_symbols(obj
->reader
, ptr
, max
, &count
);
893 array_init_size(return_value
, count
);
894 for (int32_t i
= 0; i
< count
; ++i
) {
896 php_ion_symbol_zval(&ptr
[i
], &zsym
);
897 add_next_index_zval(return_value
, &zsym
);
903 static ZEND_METHOD(ion_Reader_Reader
, countAnnotations
)
905 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
908 ZEND_PARSE_PARAMETERS_NONE();
911 ION_CHECK(ion_reader_get_annotation_count(obj
->reader
, &sz
));
914 static ZEND_METHOD(ion_Reader_Reader
, getAnnotation
)
916 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
920 ZEND_PARSE_PARAMETERS_START(1, 1)
922 ZEND_PARSE_PARAMETERS_END();
925 ION_CHECK(ion_reader_get_an_annotation(obj
->reader
, idx
, &ann
));
926 RETURN_STRINGL((char *) ann
.value
, ann
.length
);
928 static ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbol
)
930 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
934 ZEND_PARSE_PARAMETERS_START(1, 1)
936 ZEND_PARSE_PARAMETERS_END();
939 ION_CHECK(ion_reader_get_an_annotation_symbol(obj
->reader
, idx
, &sym
));
940 php_ion_symbol_zval(&sym
, return_value
);
942 static ZEND_METHOD(ion_Reader_Reader
, readNull
)
944 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
947 ZEND_PARSE_PARAMETERS_NONE();
950 ION_CHECK(ion_reader_read_null(obj
->reader
, &typ
));
953 static ZEND_METHOD(ion_Reader_Reader
, readBool
)
955 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
958 ZEND_PARSE_PARAMETERS_NONE();
961 ION_CHECK(ion_reader_read_bool(obj
->reader
, &b
));
964 static ZEND_METHOD(ion_Reader_Reader
, readInt
)
966 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
969 ZEND_PARSE_PARAMETERS_NONE();
971 php_ion_reader_read_int(obj
->reader
, return_value
);
973 static ZEND_METHOD(ion_Reader_Reader
, readFloat
)
975 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
978 ZEND_PARSE_PARAMETERS_NONE();
981 ION_CHECK(ion_reader_read_double(obj
->reader
, &dval
));
984 static ZEND_METHOD(ion_Reader_Reader
, readDecimal
)
986 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
989 ZEND_PARSE_PARAMETERS_NONE();
991 object_init_ex(return_value
, ce_Decimal
);
992 php_ion_decimal
*dec
= php_ion_obj(decimal
, Z_OBJ_P(return_value
));
993 ION_CHECK(ion_reader_read_ion_decimal(obj
->reader
, &dec
->dec
));
994 php_ion_decimal_ctor(dec
);
996 static ZEND_METHOD(ion_Reader_Reader
, readTimestamp
)
998 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1001 ZEND_PARSE_PARAMETERS_NONE();
1003 php_ion_reader_read_timestamp(obj
->reader
, obj
->opt
? &php_ion_obj(reader_options
, obj
->opt
)->opt
: NULL
, return_value
);
1005 static ZEND_METHOD(ion_Reader_Reader
, readSymbol
)
1007 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1010 ZEND_PARSE_PARAMETERS_NONE();
1013 ION_CHECK(ion_reader_read_ion_symbol(obj
->reader
, &sym
));
1014 php_ion_symbol_zval(&sym
, return_value
);
1016 static ZEND_METHOD(ion_Reader_Reader
, readString
)
1018 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1021 ZEND_PARSE_PARAMETERS_NONE();
1024 ION_CHECK(ion_reader_read_string(obj
->reader
, &str
));
1025 RETURN_STRINGL((char *) str
.value
, str
.length
);
1028 typedef iERR (*read_part_fn
)(ION_READER
*, BYTE
*, SIZE
, SIZE
*);
1029 static void read_part(INTERNAL_FUNCTION_PARAMETERS
, read_part_fn fn
)
1031 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1036 zend_long len
= 0x1000;
1037 ZEND_PARSE_PARAMETERS_START(1, 1)
1041 ZEND_PARSE_PARAMETERS_END();
1045 if (Z_TYPE_P(ref
) == IS_STRING
&& Z_STRLEN_P(ref
) == len
) {
1047 zstr
= Z_STR_P(ref
);
1050 zstr
= zend_string_alloc(len
, 0);
1054 ION_CHECK(fn(obj
->reader
, (BYTE
*) zstr
->val
, zstr
->len
, &read
), goto fail
);
1056 if (read
< zstr
->len
) {
1057 zstr
= zend_string_truncate(zstr
, read
, 0);
1059 ZVAL_STR(ref
, zstr
);
1063 zend_string_release(zstr
);
1064 ZVAL_EMPTY_STRING(ref
);
1067 static ZEND_METHOD(ion_Reader_Reader
, readStringPart
)
1069 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_partial_string
);
1071 static ZEND_METHOD(ion_Reader_Reader
, readLob
)
1073 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1076 ZEND_PARSE_PARAMETERS_NONE();
1078 php_ion_reader_read_lob(obj
->reader
, return_value
);
1080 static ZEND_METHOD(ion_Reader_Reader
, readLobPart
)
1082 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_lob_partial_bytes
);
1084 static ZEND_METHOD(ion_Reader_Reader
, getPosition
)
1086 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1089 ZEND_PARSE_PARAMETERS_NONE();
1093 ION_CHECK(ion_reader_get_position(obj
->reader
, &bytes
, &dummy
, &dummy
));
1096 static ZEND_METHOD(ion_Reader_Reader
, getDepth
)
1098 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1101 ZEND_PARSE_PARAMETERS_NONE();
1104 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
1107 static ZEND_METHOD(ion_Reader_Reader
, seek
)
1109 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1112 zend_long off
, len
= -1;
1113 ZEND_PARSE_PARAMETERS_START(1, 2)
1117 ZEND_PARSE_PARAMETERS_END();
1119 ION_CHECK(ion_reader_seek(obj
->reader
, off
, len
));
1121 static ZEND_METHOD(ion_Reader_Reader
, getValueOffset
)
1123 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1126 ZEND_PARSE_PARAMETERS_NONE();
1129 ION_CHECK(ion_reader_get_value_offset(obj
->reader
, &off
));
1132 static ZEND_METHOD(ion_Reader_Reader
, getValueLength
)
1134 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1137 ZEND_PARSE_PARAMETERS_NONE();
1140 ION_CHECK(ion_reader_get_value_length(obj
->reader
, &len
));
1143 static ZEND_METHOD(ion_Reader_Buffer_Reader
, __construct
)
1145 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1149 zval
*za_opt
= NULL
;
1150 ZEND_PARSE_PARAMETERS_START(1, 2)
1153 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj
->opt
, ce_Reader_Options
, ce_Reader_Options
, za_opt
)
1154 ZEND_PARSE_PARAMETERS_END();
1156 update_property_obj_ex(ce_Reader_Reader
, &obj
->std
, ZEND_STRL("options"), obj
->opt
);
1157 OBJ_RELEASE(obj
->opt
);
1160 obj
->type
= BUFFER_READER
;
1161 obj
->buffer
= zend_string_copy(zstr
);
1163 php_ion_reader_ctor(obj
);
1165 static ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
1167 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1170 ZEND_PARSE_PARAMETERS_NONE();
1171 RETURN_STR_COPY(obj
->buffer
);
1174 static ZEND_METHOD(ion_Reader_Stream_Reader
, __construct
)
1176 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1179 zval
*zstream
, *za_opt
= NULL
;
1180 ZEND_PARSE_PARAMETERS_START(1, 2)
1181 Z_PARAM_RESOURCE(zstream
)
1183 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj
->opt
, ce_Reader_Options
, ce_Reader_Options
, za_opt
)
1184 ZEND_PARSE_PARAMETERS_END();
1186 update_property_obj_ex(ce_Reader_Reader
, &obj
->std
, ZEND_STRL("options"), obj
->opt
);
1187 OBJ_RELEASE(obj
->opt
);
1190 obj
->type
= STREAM_READER
;
1191 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1193 php_ion_reader_ctor(obj
);
1195 static ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
1197 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1200 ZEND_PARSE_PARAMETERS_NONE();
1201 PTR_CHECK(obj
->stream
.ptr
);
1203 GC_ADDREF(obj
->stream
.ptr
->res
);
1204 RETURN_RES(obj
->stream
.ptr
->res
);
1206 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
1208 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1212 ZEND_PARSE_PARAMETERS_START(1, 1);
1213 Z_PARAM_RESOURCE(zstream
);
1214 ZEND_PARSE_PARAMETERS_END();
1216 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
1218 if (obj
->stream
.ptr
) {
1219 zend_list_delete(obj
->stream
.ptr
->res
);
1221 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1222 PTR_CHECK(obj
->stream
.ptr
);
1223 Z_ADDREF_P(zstream
);
1225 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
1227 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1232 ZEND_PARSE_PARAMETERS_START(2, 2);
1233 Z_PARAM_RESOURCE(zstream
);
1234 Z_PARAM_LONG(length
)
1235 ZEND_PARSE_PARAMETERS_END();
1237 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
1239 if (obj
->stream
.ptr
) {
1240 zend_list_delete(obj
->stream
.ptr
->res
);
1242 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1243 PTR_CHECK(obj
->stream
.ptr
);
1244 Z_ADDREF_P(zstream
);
1246 static ZEND_METHOD(ion_Writer_Options
, __construct
)
1248 php_ion_writer_options
*obj
= php_ion_obj(writer_options
, Z_OBJ_P(ZEND_THIS
));
1251 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
1252 tabs
= true, flush
= false;
1253 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x4000;
1254 ZEND_PARSE_PARAMETERS_START(0, 12)
1256 //public readonly ?\ion\Catalog $catalog = null,
1257 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
1258 //public readonly ?\ion\Decimal\Context $decimalContext = null,
1259 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
1260 //public readonly bool $outputBinary = false,
1261 Z_PARAM_BOOL(binary
)
1262 //public readonly bool $compactFloats = false,
1263 Z_PARAM_BOOL(compact_floats
)
1264 //public readonly bool $escapeNonAscii = false,
1265 Z_PARAM_BOOL(escape
)
1266 //public readonly bool $prettyPrint = false,
1267 Z_PARAM_BOOL(pretty
)
1268 //public readonly bool $indentTabs = true,
1270 //public readonly int $indentSize = 2,
1271 Z_PARAM_LONG(indent
)
1272 //public readonly bool $flushEveryValue = false,
1274 //public readonly int $maxContainerDepth = 10,
1275 Z_PARAM_LONG(max_depth
)
1276 //public readonly int $maxAnnotations = 10,
1277 Z_PARAM_LONG(max_ann
)
1278 //public readonly int $tempBufferSize = 0x4000,
1280 ZEND_PARSE_PARAMETERS_END();
1283 update_property_obj(&obj
->std
, ZEND_STRL("catalog"), obj
->cat
);
1284 obj
->opt
.pcatalog
= php_ion_obj(catalog
, obj
->cat
)->cat
;
1286 zend_update_property_null(NULL
, &obj
->std
, ZEND_STRL("catalog"));
1289 update_property_obj(&obj
->std
, ZEND_STRL("decimalContext"), obj
->dec_ctx
);
1290 obj
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, obj
->dec_ctx
)->ctx
;
1292 zend_update_property_null(NULL
, &obj
->std
, ZEND_STRL("decimalContext"));
1294 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("outputBinary"),
1295 obj
->opt
.output_as_binary
= binary
);
1296 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("compactFloats"),
1297 obj
->opt
.compact_floats
= compact_floats
);
1298 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("escapeNonAscii"),
1299 obj
->opt
.escape_all_non_ascii
= escape
);
1300 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("prettyPrint"),
1301 obj
->opt
.pretty_print
= pretty
);
1302 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentTabs"),
1303 obj
->opt
.indent_with_tabs
= tabs
);
1304 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentSize"),
1305 obj
->opt
.indent_size
= (SIZE
) indent
);
1306 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("flushEveryValue"),
1307 obj
->opt
.flush_every_value
= flush
);
1308 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxContainerDepth"),
1309 obj
->opt
.max_container_depth
= (SIZE
) max_depth
);
1310 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxAnnotations"),
1311 obj
->opt
.max_annotation_count
= (SIZE
) max_ann
);
1312 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("tempBufferSize"),
1313 obj
->opt
.temp_buffer_size
= (SIZE
) temp
);
1315 static ZEND_METHOD(ion_Writer_Writer
, writeNull
)
1317 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1320 ZEND_PARSE_PARAMETERS_NONE();
1322 ION_CHECK(ion_writer_write_null(obj
->writer
));
1324 static ZEND_METHOD(ion_Writer_Writer
, writeTypedNull
)
1326 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1329 zend_object
*typ_obj
;
1330 ZEND_PARSE_PARAMETERS_START(1, 1)
1331 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1332 ZEND_PARSE_PARAMETERS_END();
1334 ION_CHECK(ion_writer_write_typed_null(obj
->writer
, ion_type_from_enum(typ_obj
)));
1336 static ZEND_METHOD(ion_Writer_Writer
, writeBool
)
1338 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1342 ZEND_PARSE_PARAMETERS_START(1, 1)
1344 ZEND_PARSE_PARAMETERS_END();
1346 ION_CHECK(ion_writer_write_bool(obj
->writer
, b
));
1348 static ZEND_METHOD(ion_Writer_Writer
, writeInt
)
1350 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1355 ZEND_PARSE_PARAMETERS_START(1, 1)
1356 Z_PARAM_STR_OR_LONG(s
, l
)
1357 ZEND_PARSE_PARAMETERS_END();
1361 ION_CHECK(ion_int_alloc(obj
->writer
, &i
));
1362 ION_CHECK(ion_int_from_chars(i
, s
->val
, s
->len
));
1363 ION_CHECK(ion_writer_write_ion_int(obj
->writer
, i
));
1366 ION_CHECK(ion_writer_write_int64(obj
->writer
, l
));
1369 static ZEND_METHOD(ion_Writer_Writer
, writeFloat
)
1371 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1375 ZEND_PARSE_PARAMETERS_START(1, 1)
1377 ZEND_PARSE_PARAMETERS_END();
1379 ION_CHECK(ion_writer_write_double(obj
->writer
, d
));
1381 static ZEND_METHOD(ion_Writer_Writer
, writeDecimal
)
1383 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1386 zend_object
*dec_obj
;
1387 zend_string
*dec_str
;
1388 ZEND_PARSE_PARAMETERS_START(1, 1)
1389 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj
, ce_Decimal
, dec_str
)
1390 ZEND_PARSE_PARAMETERS_END();
1393 decContext
*ctx
= &php_ion_globals
.decimal
.ctx
;
1394 ION_DECIMAL dec
= {0};
1397 php_ion_writer_options
*opt_obj
= php_ion_obj(writer_options
, obj
->opt
);
1398 if (opt_obj
->opt
.decimal_context
) {
1399 ctx
= opt_obj
->opt
.decimal_context
;
1402 ION_CHECK(ion_decimal_from_string(&dec
, dec_str
->val
, ctx
));
1403 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
));
1405 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
1406 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
1409 static ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
1411 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1414 zend_object
*ts_obj
;
1415 zend_string
*ts_str
;
1416 ZEND_PARSE_PARAMETERS_START(1, 1)
1417 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
1418 ZEND_PARSE_PARAMETERS_END();
1420 decContext
*ctx
= NULL
;
1422 ctx
= php_ion_obj(reader_options
, obj
->opt
)->opt
.decimal_context
;
1425 ION_TIMESTAMP tmp
= {0};
1428 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1430 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1432 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1434 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1436 static ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1438 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1441 zend_object
*sym_obj
;
1442 zend_string
*sym_str
;
1443 ZEND_PARSE_PARAMETERS_START(1, 1)
1444 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1445 ZEND_PARSE_PARAMETERS_END();
1449 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1451 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1453 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1456 static ZEND_METHOD(ion_Writer_Writer
, writeString
)
1458 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1462 ZEND_PARSE_PARAMETERS_START(1, 1)
1464 ZEND_PARSE_PARAMETERS_END();
1467 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1469 static ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1471 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1475 ZEND_PARSE_PARAMETERS_START(1, 1)
1477 ZEND_PARSE_PARAMETERS_END();
1479 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1481 static ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1483 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1487 ZEND_PARSE_PARAMETERS_START(1, 1)
1489 ZEND_PARSE_PARAMETERS_END();
1491 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1493 static ZEND_METHOD(ion_Writer_Writer
, startLob
)
1495 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1498 zend_object
*typ_obj
;
1499 ZEND_PARSE_PARAMETERS_START(1, 1)
1500 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1501 ZEND_PARSE_PARAMETERS_END();
1503 ION_CHECK(ion_writer_start_lob(obj
->writer
, ion_type_from_enum(typ_obj
)));
1505 static ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1507 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1511 ZEND_PARSE_PARAMETERS_START(1, 1)
1513 ZEND_PARSE_PARAMETERS_END();
1515 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1517 static ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1519 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1522 ZEND_PARSE_PARAMETERS_NONE();
1524 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1526 static ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1528 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1531 zend_object
*typ_obj
;
1532 ZEND_PARSE_PARAMETERS_START(1, 1)
1533 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1534 ZEND_PARSE_PARAMETERS_END();
1536 ION_CHECK(ion_writer_start_container(obj
->writer
, ion_type_from_enum(typ_obj
)));
1538 static ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1540 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1543 ZEND_PARSE_PARAMETERS_NONE();
1545 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1547 static ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1549 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1552 zend_object
*sym_obj
;
1553 zend_string
*sym_str
;
1554 ZEND_PARSE_PARAMETERS_START(1, 1)
1555 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1556 ZEND_PARSE_PARAMETERS_END();
1560 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1562 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1564 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1567 static ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1569 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1574 ZEND_PARSE_PARAMETERS_START(1, -1)
1575 Z_PARAM_VARIADIC('+', args
, argc
);
1576 ZEND_PARSE_PARAMETERS_END();
1578 for (unsigned i
= 0; i
< argc
; ++i
) {
1579 switch (Z_TYPE(args
[i
])) {
1582 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1586 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1591 static ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1593 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1596 ZEND_PARSE_PARAMETERS_NONE();
1599 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1602 static ZEND_METHOD(ion_Writer_Writer
, flush
)
1604 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1607 ZEND_PARSE_PARAMETERS_NONE();
1610 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1611 RETURN_LONG(flushed
);
1613 static ZEND_METHOD(ion_Writer_Writer
, finish
)
1615 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1618 ZEND_PARSE_PARAMETERS_NONE();
1621 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1622 RETURN_LONG(flushed
);
1624 static ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1626 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1629 zval
*za_opt
= NULL
;
1630 ZEND_PARSE_PARAMETERS_START(0, 1)
1632 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj
->opt
, ce_Writer_Options
, ce_Writer_Options
, za_opt
)
1633 ZEND_PARSE_PARAMETERS_END();
1635 obj
->type
= BUFFER_WRITER
;
1636 php_ion_writer_ctor(obj
);
1638 OBJ_RELEASE(obj
->opt
);
1641 static ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1643 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1646 ZEND_PARSE_PARAMETERS_NONE();
1648 RETVAL_STR(php_ion_writer_buffer_copy(obj
));
1650 static ZEND_METHOD(ion_Writer_Buffer_Writer
, resetBuffer
)
1652 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1655 ZEND_PARSE_PARAMETERS_NONE();
1657 php_ion_writer_buffer_reset(obj
);
1659 static ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1661 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1664 zval
*zstream
, *za_opt
= NULL
;
1665 ZEND_PARSE_PARAMETERS_START(1, 2)
1666 Z_PARAM_RESOURCE(zstream
)
1668 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj
->opt
, ce_Writer_Options
, ce_Writer_Options
, za_opt
)
1669 ZEND_PARSE_PARAMETERS_END();
1671 obj
->type
= STREAM_WRITER
;
1672 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1674 php_ion_writer_ctor(obj
);
1676 OBJ_RELEASE(obj
->opt
);
1679 static ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1681 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1684 ZEND_PARSE_PARAMETERS_NONE();
1685 PTR_CHECK(obj
->stream
.ptr
);
1687 GC_ADDREF(obj
->stream
.ptr
->res
);
1688 RETURN_RES(obj
->stream
.ptr
->res
);
1691 static ZEND_METHOD(ion_Serializer_Serializer
, __construct
)
1693 php_ion_serializer
*obj
= php_ion_obj(serializer
, Z_OBJ_P(ZEND_THIS
));
1696 obj
->call_magic
= true;
1698 ZEND_PARSE_PARAMETERS_START(0, 3)
1700 Z_PARAM_BOOL(obj
->multi_seq
)
1701 Z_PARAM_BOOL(obj
->call_magic
)
1702 Z_PARAM_STR_OR_NULL(obj
->call_custom
)
1703 ZEND_PARSE_PARAMETERS_END();
1705 php_ion_serializer_ctor(obj
);
1707 static ZEND_METHOD(ion_Serializer_Serializer
, serialize
)
1709 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1711 zval
*data
, *za_opt
= NULL
;
1712 zend_object
*zo_wri
= NULL
;
1713 ZEND_PARSE_PARAMETERS_START(1, 2)
1716 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_wri
, ce_Writer
, ce_Writer_Options
, za_opt
)
1717 ZEND_PARSE_PARAMETERS_END();
1719 php_ion_serializer
*ser
= php_ion_obj(serializer
, obj
);
1721 php_ion_serialize(ser
, data
, return_value
);
1725 OBJ_RELEASE(zo_wri
);
1728 static ZEND_FUNCTION(ion_serialize
)
1730 zval
*data
, *za_ser
= NULL
;
1731 zend_object
*zo_ser
= NULL
;
1732 ZEND_PARSE_PARAMETERS_START(1, 2)
1735 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_ser
, ce_Serializer
, ce_Serializer_Serializer
, za_ser
)
1736 ZEND_PARSE_PARAMETERS_END();
1738 if (!zo_ser
|| zo_ser
->ce
== ce_Serializer_Serializer
) {
1739 // default, fast path
1740 php_ion_serializer
*ser
= zo_ser
? php_ion_obj(serializer
, zo_ser
) : NULL
;
1741 php_ion_serialize(ser
, data
, return_value
);
1743 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "serialize", return_value
, data
);
1747 OBJ_RELEASE(zo_ser
);
1751 static ZEND_METHOD(ion_Unserializer_Unserializer
, __construct
)
1753 php_ion_unserializer
*obj
= php_ion_obj(unserializer
, Z_OBJ_P(ZEND_THIS
));
1756 obj
->call_magic
= true;
1758 ZEND_PARSE_PARAMETERS_START(0, 3)
1760 Z_PARAM_BOOL(obj
->multi_seq
)
1761 Z_PARAM_BOOL(obj
->call_magic
)
1762 Z_PARAM_STR_OR_NULL(obj
->call_custom
)
1763 ZEND_PARSE_PARAMETERS_END();
1765 php_ion_unserializer_ctor(obj
);
1767 static ZEND_METHOD(ion_Unserializer_Unserializer
, unserialize
)
1769 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1771 zval
*data
, *za_opt
= NULL
;
1772 zend_object
*zo_rdr
= NULL
;
1773 ZEND_PARSE_PARAMETERS_START(1, 2)
1776 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_rdr
, ce_Reader
, ce_Reader_Options
, za_opt
)
1777 ZEND_PARSE_PARAMETERS_END();
1779 php_ion_unserializer
*ser
= php_ion_obj(unserializer
, obj
);
1781 php_ion_unserialize(ser
, data
, return_value
);
1785 OBJ_RELEASE(zo_rdr
);
1788 static ZEND_FUNCTION(ion_unserialize
)
1790 zval
*data
, *za_ser
= NULL
;
1791 zend_object
*zo_ser
= NULL
;
1792 ZEND_PARSE_PARAMETERS_START(1, 2)
1795 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_ser
, ce_Unserializer
, ce_Unserializer_Unserializer
, za_ser
)
1796 ZEND_PARSE_PARAMETERS_END();
1798 if (!zo_ser
|| zo_ser
->ce
== ce_Unserializer_Unserializer
) {
1799 // default, fast path
1800 php_ion_unserializer
*ser
= zo_ser
? php_ion_obj(unserializer
, zo_ser
) : NULL
;
1801 php_ion_unserialize(ser
, data
, return_value
);
1803 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "unserialize", return_value
, data
);
1807 OBJ_RELEASE(zo_ser
);
1811 PHP_RINIT_FUNCTION(ion
)
1813 #if defined(ZTS) && defined(COMPILE_DL_ION)
1814 ZEND_TSRMLS_CACHE_UPDATE();
1817 php_ion_globals_symbols_init();
1818 php_ion_globals_serializer_init();
1819 php_ion_globals_unserializer_init();
1823 PHP_RSHUTDOWN_FUNCTION(ion
)
1825 php_ion_globals_unserializer_dtor();
1826 php_ion_globals_serializer_dtor();
1827 php_ion_globals_symbols_dtor();
1831 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
1832 { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, ((type_mask) | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0))), default_value },
1833 #include "ion_arginfo.h"
1835 // spl_iterators.h includes ext/pcre/php_pcre.h which might not find pcre2.h
1836 extern PHPAPI zend_class_entry
*spl_ce_RecursiveIterator
;
1838 PHP_MINIT_FUNCTION(ion
)
1841 if (SUCCESS
!= g_sym_init()) {
1844 g_intern_str_init();
1847 php_ion_register(catalog
, Catalog
, zend_ce_countable
);
1850 php_ion_register(decimal
, Decimal
);
1851 php_ion_register(decimal_ctx
, Decimal_Context
);
1852 ce_Decimal_Context_Rounding
= register_class_ion_Decimal_Context_Rounding();
1855 ce_Exception
= register_class_ion_Exception(zend_ce_exception
);
1858 ce_LOB
= register_class_ion_LOB();
1861 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1862 php_ion_register(reader_options
, Reader_Options
);
1863 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1864 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1865 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1866 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1867 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1870 ce_Serializer
= register_class_ion_Serializer();
1871 php_ion_register(serializer
, Serializer_Serializer
, ce_Serializer
);
1874 php_ion_register(symbol
, Symbol
);
1875 oh_Symbol
.compare
= php_ion_symbol_zval_compare
;
1876 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1877 php_ion_register(symbol_table
, Symbol_Table
);
1878 ce_Symbol_Table
->create_object
= NULL
;
1879 ce_Symbol_Table_Local
= register_class_ion_Symbol_Table_Local(ce_Symbol_Table
);
1880 ce_Symbol_Table_Local
->create_object
= create_ion_Symbol_Table
;
1881 ce_Symbol_Table_Shared
= register_class_ion_Symbol_Table_Shared(ce_Symbol_Table
);
1882 ce_Symbol_Table_Shared
->create_object
= create_ion_Symbol_Table
;
1883 ce_Symbol_Enum
= register_class_ion_Symbol_Enum();
1884 ce_Symbol_Table_System
= register_class_ion_Symbol_System(ce_Symbol_Enum
);
1885 ce_Symbol_Table_PHP
= register_class_ion_Symbol_PHP(ce_Symbol_Enum
);
1888 ce_Timestamp
= register_class_ion_Timestamp(php_date_get_date_ce());
1889 ce_Timestamp_Format
= register_class_ion_Timestamp_Format();
1890 ce_Timestamp_Precision
= register_class_ion_Timestamp_Precision();
1893 ce_Type
= register_class_ion_Type();
1896 ce_Writer
= register_class_ion_Writer();
1897 php_ion_register(writer_options
, Writer_Options
);
1898 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1899 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1900 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1901 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1902 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1905 ce_Unserializer
= register_class_ion_Unserializer();
1906 php_ion_register(unserializer
, Unserializer_Unserializer
, ce_Unserializer
);
1911 PHP_MSHUTDOWN_FUNCTION(ion
)
1917 PHP_MINFO_FUNCTION(ion
)
1919 php_info_print_table_start();
1920 php_info_print_table_header(2, "ion support", "enabled");
1921 php_info_print_table_row(2, "ion version", PHP_ION_VERSION
);
1922 php_info_print_table_row(2, "ion-c version", "unknown");
1923 php_info_print_table_end();
1926 PHP_GINIT_FUNCTION(ion
)
1928 memset(ion_globals
, 0, sizeof(*ion_globals
));
1930 php_ion_decimal_ctx_init_max(&ion_globals
->decimal
.ctx
, DEC_ROUND_HALF_EVEN
);
1931 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_max
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MAX
);
1932 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_min
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MIN
);
1935 PHP_GSHUTDOWN_FUNCTION(ion
)
1939 static zend_module_dep ion_module_deps
[] = {
1940 ZEND_MOD_REQUIRED("date")
1941 ZEND_MOD_REQUIRED("spl")
1945 zend_module_entry ion_module_entry
= {
1946 STANDARD_MODULE_HEADER_EX
,
1949 "ion", /* Extension name */
1950 ext_functions
, /* zend_function_entry */
1951 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1952 PHP_MSHUTDOWN(ion
), /* PHP_MSHUTDOWN - Module shutdown */
1953 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1954 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1955 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1956 PHP_ION_VERSION
, /* Version */
1957 ZEND_MODULE_GLOBALS(ion
),
1958 PHP_GINIT(ion
), /* PHP_GINIT */
1959 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1961 STANDARD_MODULE_PROPERTIES_EX
1964 #ifdef COMPILE_DL_ION
1966 ZEND_TSRMLS_CACHE_DEFINE()
1968 ZEND_GET_MODULE(ion
)