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 #define Z_PARAM_HASH_OR_INSTANCE_OF_NULL(za_dest, zo_inst, ce_inst) \
52 Z_PARAM_PROLOGUE(0, 0) { \
54 if (zend_parse_arg_array(_arg, &(_arr), true, 0)) { \
55 za_dest = Z_ARRVAL_P(_arr); \
57 zend_object *_obj = NULL; \
58 if (zend_parse_arg_obj(_arg, &_obj, ce, true)) { \
59 za_dest = _obj->handlers->get_properties(_obj); \
60 } else if (zend_parse_arg_obj(_arg, &(zo_inst), ce_inst, true)) { \
62 _error = ce->name->val; \
63 _error_code = ZPP_ERROR_WRONG_CLASS_OR_NULL; \
69 static ZEND_METHOD(ion_Symbol_ImportLocation
, __construct
)
71 php_ion_symbol_iloc
*obj
= php_ion_obj(symbol_iloc
, Z_OBJ_P(ZEND_THIS
));
75 ZEND_PARSE_PARAMETERS_START(2, 2)
76 Z_PARAM_STR(obj
->name
)
77 Z_PARAM_LONG(location
)
78 ZEND_PARSE_PARAMETERS_END();
80 obj
->loc
.location
= (SID
) location
;
81 php_ion_symbol_iloc_ctor(obj
);
83 static ZEND_METHOD(ion_Symbol
, __construct
)
85 php_ion_symbol
*obj
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
89 ZEND_PARSE_PARAMETERS_START(0, 3)
91 Z_PARAM_STR_OR_NULL(obj
->value
)
93 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->iloc
, ce_Symbol_ImportLocation
)
94 ZEND_PARSE_PARAMETERS_END();
96 obj
->sym
.sid
= (SID
) sid
;
97 php_ion_symbol_ctor(obj
);
99 static ZEND_METHOD(ion_Symbol
, equals
)
101 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
104 zend_object
*other_obj
;
105 ZEND_PARSE_PARAMETERS_START(1, 1)
106 Z_PARAM_OBJ_OF_CLASS(other_obj
, ce_Symbol
)
107 ZEND_PARSE_PARAMETERS_END();
110 iERR err
= ion_symbol_is_equal(
112 &php_ion_obj(symbol
, other_obj
)->sym
, &eq
);
116 static ZEND_METHOD(ion_Symbol
, __toString
)
118 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
121 ZEND_PARSE_PARAMETERS_NONE();
124 RETURN_EMPTY_STRING();
126 RETURN_STR_COPY(sym
->value
);
128 static ZEND_METHOD(ion_Symbol_Enum
, toSymbol
)
130 ZEND_PARSE_PARAMETERS_NONE();
132 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
135 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
137 RETVAL_ZVAL(zsym
, 1, 0);
139 static ZEND_METHOD(ion_Symbol_Enum
, toSID
)
141 ZEND_PARSE_PARAMETERS_NONE();
143 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
146 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
150 RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym
), Z_OBJ_P(zsym
), ZEND_STRL("sid"), 0, &tmp
), 1, 0);
152 static ZEND_METHOD(ion_Symbol_Enum
, toString
)
154 ZEND_PARSE_PARAMETERS_NONE();
156 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
159 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
163 RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym
), Z_OBJ_P(zsym
), ZEND_STRL("value"), 0, &tmp
), 1, 0);
165 static ZEND_METHOD(ion_Symbol_System
, asTable
)
167 ZEND_PARSE_PARAMETERS_NONE();
169 object_init_ex(return_value
, ce_Symbol_Table_Shared
);
170 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(return_value
));
171 ION_CHECK(ion_symbol_table_get_system_table(&obj
->tab
, 1));
172 php_ion_symbol_table_ctor(obj
);
173 ion_symbol_table_lock(obj
->tab
);
175 static ZEND_METHOD(ion_Symbol_PHP
, asTable
)
177 ZEND_PARSE_PARAMETERS_NONE();
179 object_init_ex(return_value
, ce_Symbol_Table_Shared
);
180 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(return_value
));
181 obj
->tab
= g_sym_tab_php
;
182 php_ion_symbol_table_ctor(obj
);
183 ion_symbol_table_lock(obj
->tab
);
185 static ZEND_METHOD(ion_Symbol_Table_Local
, __construct
)
187 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
190 ZEND_PARSE_PARAMETERS_NONE();
192 ION_CHECK(ion_symbol_table_open_with_type(&obj
->tab
, NULL
, ist_LOCAL
));
193 obj
->dtor
= ion_symbol_table_close
;
196 static ZEND_METHOD(ion_Symbol_Table_Local
, import
)
198 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
201 zend_object
*zo_import
;
202 ZEND_PARSE_PARAMETERS_START(1, 1)
203 Z_PARAM_OBJ_OF_CLASS(zo_import
, ce_Symbol_Table
);
204 ZEND_PARSE_PARAMETERS_END();
206 php_ion_symbol_table_import(obj
, php_ion_obj(symbol_table
, zo_import
));
208 static ZEND_METHOD(ion_Symbol_Table_Shared
, __construct
)
210 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
214 zend_long version
= 1;
215 HashTable
*ht_sym
= NULL
;
216 ZEND_PARSE_PARAMETERS_START(1, 3)
219 Z_PARAM_LONG(version
)
220 Z_PARAM_ARRAY_HT_OR_NULL(ht_sym
)
221 ZEND_PARSE_PARAMETERS_END();
223 ION_CHECK(ion_symbol_table_open_with_type(&obj
->tab
, NULL
, ist_SHARED
));
224 obj
->dtor
= ion_symbol_table_close
;
227 ION_CHECK(ion_symbol_table_set_name(obj
->tab
, ion_string_from_zend(&is
, zname
)));
228 ION_CHECK(ion_symbol_table_set_version(obj
->tab
, version
));
230 php_ion_symbol_table_ctor(obj
);
233 if (ht_sym
) ZEND_HASH_FOREACH_VAL(ht_sym
, zsym
)
235 zend_string
*str
= zval_get_string(zsym
);
241 ION_CHECK(ion_symbol_table_add_symbol(obj
->tab
, ion_string_from_zend(&istr
, str
), NULL
), zend_string_release(str
));
242 zend_string_release(str
);
244 ZEND_HASH_FOREACH_END();
246 static ZEND_METHOD(ion_Symbol_Table
, getMaxId
)
248 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
251 ZEND_PARSE_PARAMETERS_NONE();
254 ION_CHECK(ion_symbol_table_get_max_sid(obj
->tab
, &max_sid
));
255 RETURN_LONG(max_sid
);
257 static ZEND_METHOD(ion_Symbol_Table
, add
)
259 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
262 zend_object
*zo_sym
= NULL
;
263 zend_string
*zs_sym
= NULL
;
264 ZEND_PARSE_PARAMETERS_START(1, 1)
265 Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_sym
, ce_Symbol
, zs_sym
)
266 ZEND_PARSE_PARAMETERS_END();
270 ZVAL_OBJ(&z_sym
, zo_sym
);
271 zs_sym
= zval_get_string(&z_sym
);
276 ION_CHECK(ion_symbol_table_add_symbol(obj
->tab
, ion_string_from_zend(&is
, zs_sym
), &sid
),
278 zend_string_release(zs_sym
);
281 zend_string_release(zs_sym
);
285 static ZEND_METHOD(ion_Symbol_Table
, find
)
287 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
291 zend_string
*zstring
= NULL
;
292 ZEND_PARSE_PARAMETERS_START(1, 1)
293 Z_PARAM_STR_OR_LONG(zstring
, zsid
)
294 ZEND_PARSE_PARAMETERS_END();
299 ION_CHECK(ion_symbol_table_find_by_name(obj
->tab
, ion_string_from_zend(&is
, zstring
), &sid
));
303 ION_CHECK(ion_symbol_table_get_symbol(obj
->tab
, zsid
, &sym
));
305 php_ion_symbol_table_symbol_zval(obj
, sym
, return_value
);
308 static ZEND_METHOD(ion_Symbol_Table
, findLocal
)
310 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
314 zend_string
*zstring
;
315 ZEND_PARSE_PARAMETERS_START(1, 1)
316 Z_PARAM_STR_OR_LONG(zstring
, zsid
)
317 ZEND_PARSE_PARAMETERS_END();
322 ION_CHECK(ion_symbol_table_find_by_name(obj
->tab
, ion_string_from_zend(&is
, zstring
), &sid
));
326 ION_CHECK(ion_symbol_table_get_local_symbol(obj
->tab
, zsid
, &sym
));
328 php_ion_symbol_table_symbol_zval(obj
, sym
, return_value
);
331 static ZEND_METHOD(ion_Catalog
, __construct
)
333 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
336 ZEND_PARSE_PARAMETERS_NONE();
338 php_ion_catalog_ctor(obj
);
340 static ZEND_METHOD(ion_Catalog
, count
)
342 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
345 ZEND_PARSE_PARAMETERS_NONE();
348 ION_CHECK(ion_catalog_get_symbol_table_count(obj
->cat
, &c
));
351 static ZEND_METHOD(ion_Catalog
, add
)
353 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
356 zend_object
*zo_symtab
;
357 ZEND_PARSE_PARAMETERS_START(1, 1)
358 Z_PARAM_OBJ_OF_CLASS(zo_symtab
, ce_Symbol_Table
)
359 ZEND_PARSE_PARAMETERS_END();
361 php_ion_symbol_table
*o_symtab
= php_ion_obj(symbol_table
, zo_symtab
);
362 php_ion_catalog_add_symbol_table(obj
, o_symtab
);
365 static ZEND_METHOD(ion_Catalog
, remove
)
367 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
370 zend_object
*zo_symtab
= NULL
;
371 zend_string
*zs_symtab
= NULL
;
372 ZEND_PARSE_PARAMETERS_START(1, 1)
373 Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_symtab
, ce_Symbol_Table
, zs_symtab
)
374 ZEND_PARSE_PARAMETERS_END();
379 zval
*ztabs
= zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("symbolTables"), 0, &tmp
);
383 zend_ulong idx
= (uintptr_t) &zo_symtab
->gc
;
384 RETVAL_BOOL(SUCCESS
== zend_hash_index_del(Z_ARRVAL_P(ztabs
), idx
));
385 ION_CHECK(ion_catalog_release_symbol_table(obj
->cat
, php_ion_obj(symbol_table
, zo_symtab
)->tab
));
387 bool deleted
= false;
388 ION_SYMBOL_TABLE
*tab
;
390 ion_string_from_zend(&is
, zs_symtab
);
393 ION_CHECK(ion_catalog_find_best_match(obj
->cat
, &is
, 0, &tab
));
395 ION_CHECK(ion_catalog_release_symbol_table(obj
->cat
, tab
));
399 RETVAL_BOOL(deleted
);
403 static ZEND_METHOD(ion_Catalog
, find
)
405 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
408 zend_long zversion
= 0;
410 ZEND_PARSE_PARAMETERS_START(1, 2)
413 Z_PARAM_LONG(zversion
)
414 ZEND_PARSE_PARAMETERS_END();
417 ION_SYMBOL_TABLE
*tab_ptr
= NULL
;
418 ION_CHECK(ion_catalog_find_symbol_table(obj
->cat
, ion_string_from_zend(&is
, zname
), zversion
, &tab_ptr
));
420 php_ion_catalog_symbol_table_zval(obj
, tab_ptr
, return_value
);
423 static ZEND_METHOD(ion_Catalog
, findBest
)
425 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
428 zend_long zversion
= 0;
430 ZEND_PARSE_PARAMETERS_START(1, 2)
433 Z_PARAM_LONG(zversion
)
434 ZEND_PARSE_PARAMETERS_END();
437 ION_SYMBOL_TABLE
*tab_ptr
= NULL
;
438 ION_CHECK(ion_catalog_find_best_match(obj
->cat
, ion_string_from_zend(&is
, zname
), zversion
, &tab_ptr
));
440 php_ion_catalog_symbol_table_zval(obj
, tab_ptr
, return_value
);
443 static ZEND_METHOD(ion_Timestamp
, __construct
)
445 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
449 zend_object
*precision_obj
= NULL
, *format_obj
= NULL
;
450 zend_string
*fmt
= NULL
, *dt
= NULL
, *tz
= NULL
;
451 zend_object
*tz_obj
= NULL
;
452 zval z_tz_tmp
, *z_tz_ptr
= NULL
;
453 ZEND_PARSE_PARAMETERS_START(1, 4)
454 Z_PARAM_OBJ_OF_CLASS_OR_LONG(precision_obj
, ce_Timestamp_Precision
, precision
)
456 Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL(format_obj
, ce_Timestamp_Format
, fmt
)
457 Z_PARAM_STR_OR_NULL(dt
)
458 Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL(tz_obj
, php_date_get_timezone_ce(), tz
)
459 ZEND_PARSE_PARAMETERS_END();
462 precision
= Z_LVAL_P(zend_enum_fetch_case_value(precision_obj
));
465 fmt
= Z_STR_P(zend_enum_fetch_case_value(format_obj
));
468 ZVAL_OBJ(z_tz_ptr
= &z_tz_tmp
, tz_obj
);
470 // there's no public API, so call timezone_open
471 zend_function
*tz_open
= zend_fetch_function_str(ZEND_STRL("timezone_open"));
474 ZVAL_STR(&z_arg
, tz
);
475 zend_call_known_function(tz_open
, NULL
, NULL
, z_tz_ptr
= &z_tz_tmp
, 1, &z_arg
, NULL
);
478 php_ion_timestamp_ctor(obj
, precision
, fmt
, dt
, z_tz_ptr
);
479 if (tz
&& z_tz_ptr
) {
480 zval_ptr_dtor(z_tz_ptr
);
483 static ZEND_METHOD(ion_Timestamp
, __toString
)
485 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
488 ZEND_PARSE_PARAMETERS_NONE();
492 zend_call_method_with_1_params(&obj
->std
, obj
->std
.ce
, NULL
, "format", return_value
,
493 zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("format"), 0, &fmt
));
495 static ZEND_METHOD(ion_Decimal_Context
, __construct
)
497 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(ZEND_THIS
));
501 zend_object
*o_round
= NULL
;
502 zend_long digits
, emax
, emin
, round
;
503 ZEND_PARSE_PARAMETERS_START(5, 5)
507 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
509 ZEND_PARSE_PARAMETERS_END();
512 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
514 php_ion_decimal_ctx_init(&obj
->ctx
, digits
, emax
, emin
, round
, clamp
); // NOLINT(cppcoreguidelines-narrowing-conversions)
515 php_ion_decimal_ctx_ctor(obj
, o_round
);
517 static inline void make_decimal_ctx(INTERNAL_FUNCTION_PARAMETERS
, int kind
)
519 ZEND_PARSE_PARAMETERS_NONE();
521 object_init_ex(return_value
, ce_Decimal_Context
);
522 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
523 decContextDefault(&obj
->ctx
, kind
);
524 php_ion_decimal_ctx_ctor(obj
, NULL
);
526 static ZEND_METHOD(ion_Decimal_Context
, Dec32
)
528 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL32
);
530 static ZEND_METHOD(ion_Decimal_Context
, Dec64
)
532 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL64
);
534 static ZEND_METHOD(ion_Decimal_Context
, Dec128
)
536 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL128
);
538 static ZEND_METHOD(ion_Decimal_Context
, DecMax
)
540 zend_object
*o_round
= NULL
;
541 zend_long round
= DEC_ROUND_HALF_EVEN
;
542 ZEND_PARSE_PARAMETERS_START(0, 1)
544 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
545 ZEND_PARSE_PARAMETERS_END();
548 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
550 object_init_ex(return_value
, ce_Decimal_Context
);
551 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
552 php_ion_decimal_ctx_init_max(&obj
->ctx
, round
);
553 php_ion_decimal_ctx_ctor(obj
, o_round
);
555 static ZEND_METHOD(ion_Decimal
, __construct
)
557 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
562 ZEND_PARSE_PARAMETERS_START(1, 2)
563 Z_PARAM_STR_OR_LONG(zstr
, num
)
565 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->ctx
, ce_Decimal_Context
)
566 ZEND_PARSE_PARAMETERS_END();
572 object_init_ex(&zdc
, ce_Decimal_Context
);
573 obj
->ctx
= Z_OBJ(zdc
);
574 php_ion_decimal_ctx_ctor(php_ion_obj(decimal_ctx
, obj
->ctx
), NULL
);
577 decContext
*ctx
= &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
;
580 ION_CHECK(ion_decimal_from_string(&obj
->dec
, zstr
->val
, ctx
), OBJ_RELEASE(obj
->ctx
));
582 php_ion_decimal_from_zend_long(&obj
->dec
, ctx
, num
);
585 php_ion_decimal_ctor(obj
);
586 OBJ_RELEASE(obj
->ctx
);
588 static ZEND_METHOD(ion_Decimal
, equals
)
590 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
593 zend_object
*dec_obj
;
594 ZEND_PARSE_PARAMETERS_START(1, 1)
595 Z_PARAM_OBJ_OF_CLASS(dec_obj
, ce_Decimal
)
596 ZEND_PARSE_PARAMETERS_END();
599 ION_CHECK(ion_decimal_equals(&obj
->dec
, &php_ion_obj(decimal
, dec_obj
)->dec
,
600 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &is
));
603 static ZEND_METHOD(ion_Decimal
, __toString
)
605 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
608 ZEND_PARSE_PARAMETERS_NONE();
610 RETURN_STR(php_ion_decimal_to_string(&obj
->dec
));
612 static ZEND_METHOD(ion_Decimal
, toInt
)
614 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
617 ZEND_PARSE_PARAMETERS_NONE();
620 php_ion_decimal_to_zend_long(&obj
->dec
, &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
, &l
);
623 static ZEND_METHOD(ion_Decimal
, isInt
)
625 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
628 ZEND_PARSE_PARAMETERS_NONE();
630 RETURN_BOOL(ion_decimal_is_integer(&obj
->dec
));
632 static ZEND_METHOD(ion_LOB
, __construct
)
635 zend_object
*type
= NULL
;
636 ZEND_PARSE_PARAMETERS_START(1, 2)
639 Z_PARAM_OBJ_OF_CLASS(type
, ce_Type
)
640 ZEND_PARSE_PARAMETERS_END();
643 type
= zend_enum_get_case_cstr(ce_Type
, "CLob");
645 update_property_obj(Z_OBJ_P(ZEND_THIS
), ZEND_STRL("type"), type
);
646 zend_update_property_str(Z_OBJCE_P(ZEND_THIS
), Z_OBJ_P(ZEND_THIS
), ZEND_STRL("value"), value
);
648 static ZEND_METHOD(ion_Reader_Reader
, __construct
)
650 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
654 zval
*zstream
= NULL
;
655 zend_bool ret_sys_val
= false, skip_validation
= false;
656 zend_long max_depth
= 10, max_ann
= 10, ann_buf_siz
= 0x4000, tmp_buf_siz
= 0x4000;
657 ZEND_PARSE_PARAMETERS_START(1, 10)
658 Z_PARAM_PROLOGUE(0, 0)
659 if (!instanceof_function(obj
->std
.ce
, ce_Reader_Buffer
) &&
660 zend_parse_arg_resource(_arg
, &zstream
, 0)) {
661 obj
->type
= STREAM_READER
;
662 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
663 PTR_CHECK(obj
->stream
.ptr
);
664 GC_ADDREF(obj
->stream
.ptr
->res
);
665 } else if (!instanceof_function(obj
->std
.ce
, ce_Reader_Stream
) &&
666 zend_parse_arg_str(_arg
, &obj
->buffer
, 0, _i
)) {
667 obj
->type
= BUFFER_READER
;
668 zend_string_addref(obj
->buffer
);
670 _error_code
= ZPP_ERROR_WRONG_ARG
;
671 _error
= "of type string or resource";
675 // public readonly ?\ion\Catalog $catalog = null,
676 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
677 // public readonly ?\ion\Decimal\Context $decimalContext = null,
678 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
679 // public readonly ?\Closure $onContextChange = null,
680 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cb
, zend_ce_closure
);
681 // public readonly bool $returnSystemValues = false,
682 Z_PARAM_BOOL(ret_sys_val
)
683 // public readonly int $maxContainerDepth = 10,
684 Z_PARAM_LONG(max_depth
)
685 // public readonly int $maxAnnotations = 10,
686 Z_PARAM_LONG(max_ann
)
687 // public readonly int $annotationBufferSize = 0x4000,
688 Z_PARAM_LONG(ann_buf_siz
)
689 // public readonly int $tempBufferSize = 0x4000,
690 Z_PARAM_LONG(tmp_buf_siz
)
691 // public readonly bool $skipCharacterValidation = false,
692 Z_PARAM_BOOL(skip_validation
)
693 ZEND_PARSE_PARAMETERS_END();
695 obj
->options
.return_system_values
= ret_sys_val
;
696 obj
->options
.max_container_depth
= (SIZE
) max_depth
;
697 obj
->options
.max_annotation_count
= (SIZE
) max_ann
;
698 obj
->options
.max_annotation_buffered
= (SIZE
) ann_buf_siz
;
699 obj
->options
.chunk_threshold
= (SIZE
) tmp_buf_siz
;
700 obj
->options
.user_value_threshold
= (SIZE
) tmp_buf_siz
;
701 obj
->options
.symbol_threshold
= (SIZE
) tmp_buf_siz
;
702 obj
->options
.skip_character_validation
= skip_validation
;
704 php_ion_reader_ctor(obj
);
706 static ZEND_METHOD(ion_Reader_Reader
, hasChildren
)
708 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
711 ZEND_PARSE_PARAMETERS_NONE();
714 ION_CHECK(ion_reader_get_type(obj
->reader
, &t
));
715 switch (ION_TYPE_INT(t
)) {
726 static ZEND_METHOD(ion_Reader_Reader
, getChildren
)
728 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
731 ZEND_PARSE_PARAMETERS_NONE();
733 ION_CHECK(ion_reader_step_in(obj
->reader
));
735 RETURN_ZVAL(ZEND_THIS
, 1, 0);
737 static ZEND_METHOD(ion_Reader_Reader
, rewind
)
739 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
742 ZEND_PARSE_PARAMETERS_NONE();
744 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
746 static ZEND_METHOD(ion_Reader_Reader
, next
)
748 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
751 ZEND_PARSE_PARAMETERS_NONE();
753 if (obj
->state
== tid_EOF
) {
755 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
757 ION_CHECK(ion_reader_step_out(obj
->reader
));
760 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
762 static ZEND_METHOD(ion_Reader_Reader
, valid
)
764 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
767 ZEND_PARSE_PARAMETERS_NONE();
768 RETURN_BOOL(obj
->state
!= tid_none
&& obj
->state
!= tid_EOF
);
770 static ZEND_METHOD(ion_Reader_Reader
, key
)
772 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
775 ZEND_PARSE_PARAMETERS_NONE();
776 RETURN_IONTYPE(obj
->state
);
778 static ZEND_METHOD(ion_Reader_Reader
, current
)
780 ZEND_PARSE_PARAMETERS_NONE();
781 RETURN_ZVAL(ZEND_THIS
, 1, 0);
783 static ZEND_METHOD(ion_Reader_Reader
, getType
)
785 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
788 ZEND_PARSE_PARAMETERS_NONE();
791 ION_CHECK(ion_reader_get_type(obj
->reader
, &typ
));
794 static ZEND_METHOD(ion_Reader_Reader
, hasAnnotations
)
796 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
799 ZEND_PARSE_PARAMETERS_NONE();
802 ION_CHECK(ion_reader_has_any_annotations(obj
->reader
, &has
));
805 static ZEND_METHOD(ion_Reader_Reader
, hasAnnotation
)
807 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
810 zend_string
*ann_zstr
;
811 ZEND_PARSE_PARAMETERS_START(1, 1);
812 Z_PARAM_STR(ann_zstr
);
813 ZEND_PARSE_PARAMETERS_END();
817 ION_CHECK(ion_reader_has_annotation(obj
->reader
, ion_string_from_zend(&ann_istr
, ann_zstr
), &has
));
820 static ZEND_METHOD(ion_Reader_Reader
, isNull
)
822 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
825 ZEND_PARSE_PARAMETERS_NONE();
828 ION_CHECK(ion_reader_is_null(obj
->reader
, &is
));
831 static ZEND_METHOD(ion_Reader_Reader
, isInStruct
)
833 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
836 ZEND_PARSE_PARAMETERS_NONE();
839 ION_CHECK(ion_reader_is_in_struct(obj
->reader
, &is
));
842 static ZEND_METHOD(ion_Reader_Reader
, getFieldName
)
844 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
847 ZEND_PARSE_PARAMETERS_NONE();
850 ION_CHECK(ion_reader_get_field_name(obj
->reader
, &name
));
851 RETURN_STRINGL((char *) name
.value
, name
.length
);
853 static ZEND_METHOD(ion_Reader_Reader
, getFieldNameSymbol
)
855 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
858 ZEND_PARSE_PARAMETERS_NONE();
861 ION_CHECK(ion_reader_get_field_name_symbol(obj
->reader
, &sym_ptr
));
863 php_ion_symbol_zval(sym_ptr
, return_value
);
865 static ZEND_METHOD(ion_Reader_Reader
, getAnnotations
)
867 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
870 ZEND_PARSE_PARAMETERS_NONE();
873 if (obj
->options
.max_annotation_count
) {
874 max
= obj
->options
.max_annotation_count
;
878 ION_STRING
*ptr
= ecalloc(sizeof(*ptr
), max
);
879 iERR err
= ion_reader_get_annotations(obj
->reader
, ptr
, max
, &count
);
881 array_init_size(return_value
, count
);
882 for (int32_t i
= 0; i
< count
; ++i
) {
883 add_next_index_str(return_value
, zend_string_from_ion(&ptr
[i
]));
889 static ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbols
)
891 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
894 ZEND_PARSE_PARAMETERS_NONE();
897 if (obj
->options
.max_annotation_count
) {
898 max
= obj
->options
.max_annotation_count
;
902 ION_SYMBOL
*ptr
= ecalloc(sizeof(*ptr
), max
);
903 iERR err
= ion_reader_get_annotation_symbols(obj
->reader
, ptr
, max
, &count
);
905 array_init_size(return_value
, count
);
906 for (int32_t i
= 0; i
< count
; ++i
) {
908 php_ion_symbol_zval(&ptr
[i
], &zsym
);
909 add_next_index_zval(return_value
, &zsym
);
915 static ZEND_METHOD(ion_Reader_Reader
, countAnnotations
)
917 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
920 ZEND_PARSE_PARAMETERS_NONE();
923 ION_CHECK(ion_reader_get_annotation_count(obj
->reader
, &sz
));
926 static ZEND_METHOD(ion_Reader_Reader
, getAnnotation
)
928 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
932 ZEND_PARSE_PARAMETERS_START(1, 1)
934 ZEND_PARSE_PARAMETERS_END();
937 ION_CHECK(ion_reader_get_an_annotation(obj
->reader
, idx
, &ann
));
938 RETURN_STRINGL((char *) ann
.value
, ann
.length
);
940 static ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbol
)
942 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
946 ZEND_PARSE_PARAMETERS_START(1, 1)
948 ZEND_PARSE_PARAMETERS_END();
951 ION_CHECK(ion_reader_get_an_annotation_symbol(obj
->reader
, idx
, &sym
));
952 php_ion_symbol_zval(&sym
, return_value
);
954 static ZEND_METHOD(ion_Reader_Reader
, readNull
)
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_null(obj
->reader
, &typ
));
965 static ZEND_METHOD(ion_Reader_Reader
, readBool
)
967 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
970 ZEND_PARSE_PARAMETERS_NONE();
973 ION_CHECK(ion_reader_read_bool(obj
->reader
, &b
));
976 static ZEND_METHOD(ion_Reader_Reader
, readInt
)
978 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
981 ZEND_PARSE_PARAMETERS_NONE();
983 php_ion_reader_read_int(obj
->reader
, return_value
);
985 static ZEND_METHOD(ion_Reader_Reader
, readFloat
)
987 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
990 ZEND_PARSE_PARAMETERS_NONE();
993 ION_CHECK(ion_reader_read_double(obj
->reader
, &dval
));
996 static ZEND_METHOD(ion_Reader_Reader
, readDecimal
)
998 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1001 ZEND_PARSE_PARAMETERS_NONE();
1003 object_init_ex(return_value
, ce_Decimal
);
1004 php_ion_decimal
*dec
= php_ion_obj(decimal
, Z_OBJ_P(return_value
));
1005 ION_CHECK(ion_reader_read_ion_decimal(obj
->reader
, &dec
->dec
));
1006 php_ion_decimal_ctor(dec
);
1008 static ZEND_METHOD(ion_Reader_Reader
, readTimestamp
)
1010 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1013 ZEND_PARSE_PARAMETERS_NONE();
1015 php_ion_reader_read_timestamp(obj
->reader
, &obj
->options
, return_value
);
1017 static ZEND_METHOD(ion_Reader_Reader
, readSymbol
)
1019 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1022 ZEND_PARSE_PARAMETERS_NONE();
1025 ION_CHECK(ion_reader_read_ion_symbol(obj
->reader
, &sym
));
1026 php_ion_symbol_zval(&sym
, return_value
);
1028 static ZEND_METHOD(ion_Reader_Reader
, readString
)
1030 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1033 ZEND_PARSE_PARAMETERS_NONE();
1036 ION_CHECK(ion_reader_read_string(obj
->reader
, &str
));
1037 RETURN_STRINGL((char *) str
.value
, str
.length
);
1040 typedef iERR (*read_part_fn
)(ION_READER
*, BYTE
*, SIZE
, SIZE
*);
1041 static void read_part(INTERNAL_FUNCTION_PARAMETERS
, read_part_fn fn
)
1043 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1048 zend_long len
= 0x1000;
1049 ZEND_PARSE_PARAMETERS_START(1, 1)
1053 ZEND_PARSE_PARAMETERS_END();
1057 if (Z_TYPE_P(ref
) == IS_STRING
&& Z_STRLEN_P(ref
) == len
) {
1059 zstr
= Z_STR_P(ref
);
1062 zstr
= zend_string_alloc(len
, 0);
1066 ION_CHECK(fn(obj
->reader
, (BYTE
*) zstr
->val
, zstr
->len
, &read
), goto fail
);
1068 if (read
< zstr
->len
) {
1069 zstr
= zend_string_truncate(zstr
, read
, 0);
1071 ZVAL_STR(ref
, zstr
);
1075 zend_string_release(zstr
);
1076 ZVAL_EMPTY_STRING(ref
);
1079 static ZEND_METHOD(ion_Reader_Reader
, readStringPart
)
1081 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_partial_string
);
1083 static ZEND_METHOD(ion_Reader_Reader
, readLob
)
1085 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1088 ZEND_PARSE_PARAMETERS_NONE();
1090 php_ion_reader_read_lob(obj
->reader
, return_value
);
1092 static ZEND_METHOD(ion_Reader_Reader
, readLobPart
)
1094 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_lob_partial_bytes
);
1096 static ZEND_METHOD(ion_Reader_Reader
, getPosition
)
1098 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1101 ZEND_PARSE_PARAMETERS_NONE();
1105 ION_CHECK(ion_reader_get_position(obj
->reader
, &bytes
, &dummy
, &dummy
));
1108 static ZEND_METHOD(ion_Reader_Reader
, getDepth
)
1110 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1113 ZEND_PARSE_PARAMETERS_NONE();
1116 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
1119 static ZEND_METHOD(ion_Reader_Reader
, seek
)
1121 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1124 zend_long off
, len
= -1;
1125 ZEND_PARSE_PARAMETERS_START(1, 2)
1129 ZEND_PARSE_PARAMETERS_END();
1131 ION_CHECK(ion_reader_seek(obj
->reader
, off
, len
));
1133 static ZEND_METHOD(ion_Reader_Reader
, getValueOffset
)
1135 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1138 ZEND_PARSE_PARAMETERS_NONE();
1141 ION_CHECK(ion_reader_get_value_offset(obj
->reader
, &off
));
1144 static ZEND_METHOD(ion_Reader_Reader
, getValueLength
)
1146 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1149 ZEND_PARSE_PARAMETERS_NONE();
1152 ION_CHECK(ion_reader_get_value_length(obj
->reader
, &len
));
1156 static ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
1158 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1161 ZEND_PARSE_PARAMETERS_NONE();
1162 RETURN_STR_COPY(obj
->buffer
);
1165 static ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
1167 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1170 ZEND_PARSE_PARAMETERS_NONE();
1171 PTR_CHECK(obj
->stream
.ptr
);
1173 GC_ADDREF(obj
->stream
.ptr
->res
);
1174 RETURN_RES(obj
->stream
.ptr
->res
);
1176 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
1178 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1182 ZEND_PARSE_PARAMETERS_START(1, 1);
1183 Z_PARAM_RESOURCE(zstream
);
1184 ZEND_PARSE_PARAMETERS_END();
1186 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
1188 if (obj
->stream
.ptr
) {
1189 zend_list_delete(obj
->stream
.ptr
->res
);
1191 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1192 PTR_CHECK(obj
->stream
.ptr
);
1193 Z_ADDREF_P(zstream
);
1195 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
1197 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1202 ZEND_PARSE_PARAMETERS_START(2, 2);
1203 Z_PARAM_RESOURCE(zstream
);
1204 Z_PARAM_LONG(length
)
1205 ZEND_PARSE_PARAMETERS_END();
1207 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
1209 if (obj
->stream
.ptr
) {
1210 zend_list_delete(obj
->stream
.ptr
->res
);
1212 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1213 PTR_CHECK(obj
->stream
.ptr
);
1214 Z_ADDREF_P(zstream
);
1217 static void _ion_Writer_Writer___construct(bool stream_writer
, INTERNAL_FUNCTION_PARAMETERS
)
1219 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1222 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
1223 tabs
= true, flush
= false;
1224 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x4000;
1225 ZEND_PARSE_PARAMETERS_START(0 + stream_writer
, 12 + stream_writer
)
1226 if (!stream_writer
) {
1227 obj
->type
= BUFFER_WRITER
;
1229 Z_PARAM_PROLOGUE(0, 0)
1230 obj
->type
= STREAM_WRITER
;
1231 zval
*zstream
= NULL
;
1232 if (zend_parse_arg_resource(_arg
, &zstream
, 0)) {
1233 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1234 PTR_CHECK(obj
->stream
.ptr
);
1235 GC_ADDREF(obj
->stream
.ptr
->res
);
1237 _error_code
= Z_EXPECTED_RESOURCE
;
1238 _error
= "of type resource";
1243 //public readonly ?\ion\Catalog $catalog = null,
1244 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
1245 //public readonly ?\ion\Decimal\Context $decimalContext = null,
1246 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
1247 //public readonly bool $outputBinary = false,
1248 Z_PARAM_BOOL(binary
)
1249 //public readonly bool $compactFloats = false,
1250 Z_PARAM_BOOL(compact_floats
)
1251 //public readonly bool $escapeNonAscii = false,
1252 Z_PARAM_BOOL(escape
)
1253 //public readonly bool $prettyPrint = false,
1254 Z_PARAM_BOOL(pretty
)
1255 //public readonly bool $indentTabs = true,
1257 //public readonly int $indentSize = 2,
1258 Z_PARAM_LONG(indent
)
1259 //public readonly bool $flushEveryValue = false,
1261 //public readonly int $maxContainerDepth = 10,
1262 Z_PARAM_LONG(max_depth
)
1263 //public readonly int $maxAnnotations = 10,
1264 Z_PARAM_LONG(max_ann
)
1265 //public readonly int $tempBufferSize = 0x4000,
1267 ZEND_PARSE_PARAMETERS_END();
1269 obj
->options
.output_as_binary
= binary
;
1270 obj
->options
.compact_floats
= compact_floats
;
1271 obj
->options
.escape_all_non_ascii
= escape
;
1272 obj
->options
.pretty_print
= pretty
;
1273 obj
->options
.indent_with_tabs
= tabs
;
1274 obj
->options
.indent_size
= (SIZE
) indent
;
1275 obj
->options
.flush_every_value
= flush
;
1276 obj
->options
.max_container_depth
= (SIZE
) max_depth
;
1277 obj
->options
.max_annotation_count
= (SIZE
) max_ann
;
1278 obj
->options
.temp_buffer_size
= (SIZE
) temp
;
1280 php_ion_writer_ctor(obj
);
1283 static ZEND_METHOD(ion_Writer_Writer
, __construct
)
1285 _ion_Writer_Writer___construct(false, INTERNAL_FUNCTION_PARAM_PASSTHRU
);
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};
1368 if (obj
->options
.decimal_context
) {
1369 ctx
= obj
->options
.decimal_context
;
1371 ION_CHECK(ion_decimal_from_string(&dec
, dec_str
->val
, ctx
));
1372 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
));
1374 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
1375 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
1378 static ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
1380 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1383 zend_object
*ts_obj
;
1384 zend_string
*ts_str
;
1385 ZEND_PARSE_PARAMETERS_START(1, 1)
1386 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
1387 ZEND_PARSE_PARAMETERS_END();
1389 decContext
*ctx
= obj
->options
.decimal_context
;
1390 ION_TIMESTAMP tmp
= {0};
1393 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1395 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1397 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1399 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1401 static ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1403 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1406 zend_object
*sym_obj
;
1407 zend_string
*sym_str
;
1408 ZEND_PARSE_PARAMETERS_START(1, 1)
1409 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1410 ZEND_PARSE_PARAMETERS_END();
1414 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1416 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1418 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1421 static ZEND_METHOD(ion_Writer_Writer
, writeString
)
1423 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1427 ZEND_PARSE_PARAMETERS_START(1, 1)
1429 ZEND_PARSE_PARAMETERS_END();
1432 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1434 static ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1436 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1440 ZEND_PARSE_PARAMETERS_START(1, 1)
1442 ZEND_PARSE_PARAMETERS_END();
1444 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1446 static ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1448 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1452 ZEND_PARSE_PARAMETERS_START(1, 1)
1454 ZEND_PARSE_PARAMETERS_END();
1456 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1458 static ZEND_METHOD(ion_Writer_Writer
, startLob
)
1460 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1463 zend_object
*typ_obj
;
1464 ZEND_PARSE_PARAMETERS_START(1, 1)
1465 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1466 ZEND_PARSE_PARAMETERS_END();
1468 ION_CHECK(ion_writer_start_lob(obj
->writer
, ion_type_from_enum(typ_obj
)));
1470 static ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1472 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1476 ZEND_PARSE_PARAMETERS_START(1, 1)
1478 ZEND_PARSE_PARAMETERS_END();
1480 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1482 static ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1484 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1487 ZEND_PARSE_PARAMETERS_NONE();
1489 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1491 static ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1493 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1496 zend_object
*typ_obj
;
1497 ZEND_PARSE_PARAMETERS_START(1, 1)
1498 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1499 ZEND_PARSE_PARAMETERS_END();
1501 ION_CHECK(ion_writer_start_container(obj
->writer
, ion_type_from_enum(typ_obj
)));
1503 static ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1505 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1508 ZEND_PARSE_PARAMETERS_NONE();
1510 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1512 static ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1514 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1517 zend_object
*sym_obj
;
1518 zend_string
*sym_str
;
1519 ZEND_PARSE_PARAMETERS_START(1, 1)
1520 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1521 ZEND_PARSE_PARAMETERS_END();
1525 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1527 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1529 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1532 static ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1534 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1539 ZEND_PARSE_PARAMETERS_START(1, -1)
1540 Z_PARAM_VARIADIC('+', args
, argc
);
1541 ZEND_PARSE_PARAMETERS_END();
1543 for (unsigned i
= 0; i
< argc
; ++i
) {
1544 switch (Z_TYPE(args
[i
])) {
1547 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1551 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1556 static ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1558 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1561 ZEND_PARSE_PARAMETERS_NONE();
1564 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1567 static ZEND_METHOD(ion_Writer_Writer
, flush
)
1569 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1572 ZEND_PARSE_PARAMETERS_NONE();
1575 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1576 RETURN_LONG(flushed
);
1578 static ZEND_METHOD(ion_Writer_Writer
, finish
)
1580 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1583 ZEND_PARSE_PARAMETERS_NONE();
1586 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1587 RETURN_LONG(flushed
);
1589 static ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1591 _ion_Writer_Writer___construct(false, INTERNAL_FUNCTION_PARAM_PASSTHRU
);
1593 static ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1595 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1598 ZEND_PARSE_PARAMETERS_NONE();
1600 RETVAL_STR(php_ion_writer_buffer_copy(obj
));
1602 static ZEND_METHOD(ion_Writer_Buffer_Writer
, resetBuffer
)
1604 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1607 ZEND_PARSE_PARAMETERS_NONE();
1609 php_ion_writer_buffer_reset(obj
);
1611 static ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1613 _ion_Writer_Writer___construct(true, INTERNAL_FUNCTION_PARAM_PASSTHRU
);
1615 static ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1617 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1620 ZEND_PARSE_PARAMETERS_NONE();
1621 PTR_CHECK(obj
->stream
.ptr
);
1623 GC_ADDREF(obj
->stream
.ptr
->res
);
1624 RETURN_RES(obj
->stream
.ptr
->res
);
1627 static ZEND_METHOD(ion_Serializer_Serializer
, __construct
)
1629 php_ion_serializer
*obj
= php_ion_obj(serializer
, Z_OBJ_P(ZEND_THIS
));
1632 obj
->call_magic
= true;
1634 ZEND_PARSE_PARAMETERS_START(0, 3)
1636 Z_PARAM_BOOL(obj
->multi_seq
)
1637 Z_PARAM_BOOL(obj
->call_magic
)
1638 Z_PARAM_STR_OR_NULL(obj
->call_custom
)
1639 ZEND_PARSE_PARAMETERS_END();
1641 php_ion_serializer_ctor(obj
);
1643 static ZEND_METHOD(ion_Serializer_Serializer
, serialize
)
1645 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1648 zend_object
*zo_wri
= NULL
;
1649 zend_array
*za_named
= NULL
;
1650 ZEND_PARSE_PARAMETERS_START(1, 2)
1653 Z_PARAM_PROLOGUE(0, 0)
1654 if (!zend_parse_arg_obj(_arg
, &zo_wri
, ce_Writer
, true)) {
1655 if (!zend_parse_arg_array_ht(_arg
, &za_named
, false, false, false)) {
1656 _error_code
= ZPP_ERROR_WRONG_ARG
;
1657 _error
= "of type array or \\ion\\Writer";
1660 zo_wri
= create_ion_Writer_Writer(ce_Writer_Buffer_Writer
);
1661 call_constructor(zo_wri
, 0, NULL
, za_named
);
1662 ION_CATCH(OBJ_RELEASE(zo_wri
));
1664 ZEND_PARSE_PARAMETERS_END();
1666 php_ion_serializer
*ser
= php_ion_obj(serializer
, obj
);
1668 php_ion_serialize(ser
, data
, return_value
);
1672 OBJ_RELEASE(zo_wri
);
1675 static ZEND_FUNCTION(ion_serialize
)
1678 zend_object
*zo_ser
= NULL
;
1679 zend_array
*za_named
= NULL
;
1680 ZEND_PARSE_PARAMETERS_START(1, 2)
1683 Z_PARAM_PROLOGUE(0, 0)
1684 if (!zend_parse_arg_obj(_arg
, &zo_ser
, ce_Serializer
, true)) {
1685 if (!zend_parse_arg_array_ht(_arg
, &za_named
, false, false, false)) {
1686 _error_code
= ZPP_ERROR_WRONG_ARG
;
1687 _error
= "of type array or \\ion\\Writer";
1690 zo_ser
= create_ion_Serializer_Serializer(NULL
);
1691 call_constructor(zo_ser
, 0, NULL
, za_named
);
1692 ION_CATCH(OBJ_RELEASE(zo_ser
));
1694 ZEND_PARSE_PARAMETERS_END();
1696 if (!zo_ser
|| zo_ser
->ce
== ce_Serializer_Serializer
) {
1697 // default, fast path
1698 php_ion_serialize(php_ion_obj(serializer
, zo_ser
), data
, return_value
);
1700 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "serialize", return_value
, data
);
1704 OBJ_RELEASE(zo_ser
);
1708 static ZEND_METHOD(ion_Unserializer_Unserializer
, __construct
)
1710 php_ion_unserializer
*obj
= php_ion_obj(unserializer
, Z_OBJ_P(ZEND_THIS
));
1713 obj
->call_magic
= true;
1715 ZEND_PARSE_PARAMETERS_START(0, 3)
1717 Z_PARAM_BOOL(obj
->multi_seq
)
1718 Z_PARAM_BOOL(obj
->call_magic
)
1719 Z_PARAM_STR_OR_NULL(obj
->call_custom
)
1720 ZEND_PARSE_PARAMETERS_END();
1722 php_ion_unserializer_ctor(obj
);
1724 static ZEND_METHOD(ion_Unserializer_Unserializer
, unserialize
)
1727 ZEND_PARSE_PARAMETERS_START(1, 1)
1729 ZEND_PARSE_PARAMETERS_END();
1731 php_ion_unserialize(php_ion_obj(unserializer
, Z_OBJ_P(ZEND_THIS
)), data
, return_value
);
1733 static ZEND_FUNCTION(ion_unserialize
)
1736 zend_object
*zo_ser
= NULL
;
1737 zend_array
*za_named
= NULL
;
1738 ZEND_PARSE_PARAMETERS_START(1, 2)
1741 Z_PARAM_PROLOGUE(0, 0)
1742 if (!zend_parse_arg_obj(_arg
, &zo_ser
, ce_Unserializer
, true)) {
1743 if (!zend_parse_arg_array_ht(_arg
, &za_named
, false, false, false)) {
1744 _error_code
= ZPP_ERROR_WRONG_ARG
;
1745 _error
= "of type array of \\ion\\Unserializer";
1748 zo_ser
= create_ion_Unserializer_Unserializer(NULL
);
1749 call_constructor(zo_ser
, 0, NULL
, za_named
);
1750 ION_CATCH(OBJ_RELEASE(zo_ser
));
1752 ZEND_PARSE_PARAMETERS_END();
1754 if (!zo_ser
|| zo_ser
->ce
== ce_Unserializer_Unserializer
) {
1755 // default, fast path
1756 php_ion_unserialize(php_ion_obj(unserializer
, zo_ser
), data
, return_value
);
1758 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "unserialize", return_value
, data
);
1762 OBJ_RELEASE(zo_ser
);
1766 PHP_RINIT_FUNCTION(ion
)
1768 #if defined(ZTS) && defined(COMPILE_DL_ION)
1769 ZEND_TSRMLS_CACHE_UPDATE();
1772 php_ion_globals_symbols_init();
1773 php_ion_globals_serializer_init();
1774 php_ion_globals_unserializer_init();
1778 PHP_RSHUTDOWN_FUNCTION(ion
)
1780 php_ion_globals_unserializer_dtor();
1781 php_ion_globals_serializer_dtor();
1782 php_ion_globals_symbols_dtor();
1786 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
1787 { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, ((type_mask) | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0))), default_value },
1788 #include "ion_arginfo.h"
1790 // spl_iterators.h includes ext/pcre/php_pcre.h which might not find pcre2.h
1791 extern PHPAPI zend_class_entry
*spl_ce_RecursiveIterator
;
1793 PHP_MINIT_FUNCTION(ion
)
1796 if (SUCCESS
!= g_sym_init()) {
1799 g_intern_str_init();
1802 php_ion_register(catalog
, Catalog
, zend_ce_countable
);
1805 php_ion_register(decimal
, Decimal
);
1806 php_ion_register(decimal_ctx
, Decimal_Context
);
1807 ce_Decimal_Context_Rounding
= register_class_ion_Decimal_Context_Rounding();
1810 ce_Exception
= register_class_ion_Exception(zend_ce_exception
);
1813 ce_LOB
= register_class_ion_LOB();
1816 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1817 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1818 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1819 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1820 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1821 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1824 ce_Serializer
= register_class_ion_Serializer();
1825 php_ion_register(serializer
, Serializer_Serializer
, ce_Serializer
);
1828 php_ion_register(symbol
, Symbol
);
1829 oh_Symbol
.compare
= php_ion_symbol_zval_compare
;
1830 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1831 php_ion_register(symbol_table
, Symbol_Table
);
1832 ce_Symbol_Table
->create_object
= NULL
;
1833 ce_Symbol_Table_Local
= register_class_ion_Symbol_Table_Local(ce_Symbol_Table
);
1834 ce_Symbol_Table_Local
->create_object
= create_ion_Symbol_Table
;
1835 ce_Symbol_Table_Shared
= register_class_ion_Symbol_Table_Shared(ce_Symbol_Table
);
1836 ce_Symbol_Table_Shared
->create_object
= create_ion_Symbol_Table
;
1837 ce_Symbol_Enum
= register_class_ion_Symbol_Enum();
1838 ce_Symbol_Table_System
= register_class_ion_Symbol_System(ce_Symbol_Enum
);
1839 ce_Symbol_Table_PHP
= register_class_ion_Symbol_PHP(ce_Symbol_Enum
);
1842 ce_Timestamp
= register_class_ion_Timestamp(php_date_get_date_ce());
1843 ce_Timestamp_Format
= register_class_ion_Timestamp_Format();
1844 ce_Timestamp_Precision
= register_class_ion_Timestamp_Precision();
1847 ce_Type
= register_class_ion_Type();
1850 ce_Writer
= register_class_ion_Writer();
1851 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1852 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1853 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1854 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1855 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1858 ce_Unserializer
= register_class_ion_Unserializer();
1859 php_ion_register(unserializer
, Unserializer_Unserializer
, ce_Unserializer
);
1864 PHP_MSHUTDOWN_FUNCTION(ion
)
1870 PHP_MINFO_FUNCTION(ion
)
1872 php_info_print_table_start();
1873 php_info_print_table_header(2, "ion support", "enabled");
1874 php_info_print_table_row(2, "ion version", PHP_ION_VERSION
);
1875 php_info_print_table_row(2, "ion-c version", "unknown");
1876 php_info_print_table_end();
1879 PHP_GINIT_FUNCTION(ion
)
1881 memset(ion_globals
, 0, sizeof(*ion_globals
));
1883 php_ion_decimal_ctx_init_max(&ion_globals
->decimal
.ctx
, DEC_ROUND_HALF_EVEN
);
1884 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_max
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MAX
);
1885 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_min
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MIN
);
1888 PHP_GSHUTDOWN_FUNCTION(ion
)
1892 static zend_module_dep ion_module_deps
[] = {
1893 ZEND_MOD_REQUIRED("date")
1894 ZEND_MOD_REQUIRED("spl")
1898 zend_module_entry ion_module_entry
= {
1899 STANDARD_MODULE_HEADER_EX
,
1902 "ion", /* Extension name */
1903 ext_functions
, /* zend_function_entry */
1904 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1905 PHP_MSHUTDOWN(ion
), /* PHP_MSHUTDOWN - Module shutdown */
1906 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1907 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1908 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1909 PHP_ION_VERSION
, /* Version */
1910 ZEND_MODULE_GLOBALS(ion
),
1911 PHP_GINIT(ion
), /* PHP_GINIT */
1912 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1914 STANDARD_MODULE_PROPERTIES_EX
1917 #ifdef COMPILE_DL_ION
1919 ZEND_TSRMLS_CACHE_DEFINE()
1921 ZEND_GET_MODULE(ion
)