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 obj
->type
= BUFFER_READER
;
1157 obj
->buffer
= zend_string_copy(zstr
);
1159 php_ion_reader_ctor(obj
);
1161 OBJ_RELEASE(obj
->opt
);
1164 static ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
1166 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1169 ZEND_PARSE_PARAMETERS_NONE();
1170 RETURN_STR_COPY(obj
->buffer
);
1173 static ZEND_METHOD(ion_Reader_Stream_Reader
, __construct
)
1175 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1178 zval
*zstream
, *za_opt
= NULL
;
1179 ZEND_PARSE_PARAMETERS_START(1, 2)
1180 Z_PARAM_RESOURCE(zstream
)
1182 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj
->opt
, ce_Reader_Options
, ce_Reader_Options
, za_opt
)
1183 ZEND_PARSE_PARAMETERS_END();
1185 obj
->type
= STREAM_READER
;
1186 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1188 php_ion_reader_ctor(obj
);
1190 OBJ_RELEASE(obj
->opt
);
1193 static ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
1195 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1198 ZEND_PARSE_PARAMETERS_NONE();
1199 PTR_CHECK(obj
->stream
.ptr
);
1201 GC_ADDREF(obj
->stream
.ptr
->res
);
1202 RETURN_RES(obj
->stream
.ptr
->res
);
1204 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
1206 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1210 ZEND_PARSE_PARAMETERS_START(1, 1);
1211 Z_PARAM_RESOURCE(zstream
);
1212 ZEND_PARSE_PARAMETERS_END();
1214 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
1216 if (obj
->stream
.ptr
) {
1217 zend_list_delete(obj
->stream
.ptr
->res
);
1219 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1220 PTR_CHECK(obj
->stream
.ptr
);
1221 Z_ADDREF_P(zstream
);
1223 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
1225 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1230 ZEND_PARSE_PARAMETERS_START(2, 2);
1231 Z_PARAM_RESOURCE(zstream
);
1232 Z_PARAM_LONG(length
)
1233 ZEND_PARSE_PARAMETERS_END();
1235 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
1237 if (obj
->stream
.ptr
) {
1238 zend_list_delete(obj
->stream
.ptr
->res
);
1240 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1241 PTR_CHECK(obj
->stream
.ptr
);
1242 Z_ADDREF_P(zstream
);
1244 static ZEND_METHOD(ion_Writer_Options
, __construct
)
1246 php_ion_writer_options
*obj
= php_ion_obj(writer_options
, Z_OBJ_P(ZEND_THIS
));
1249 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
1250 tabs
= true, flush
= false;
1251 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x4000;
1252 ZEND_PARSE_PARAMETERS_START(0, 12)
1254 //public readonly ?\ion\Catalog $catalog = null,
1255 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
1256 //public readonly ?\ion\Decimal\Context $decimalContext = null,
1257 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
1258 //public readonly bool $outputBinary = false,
1259 Z_PARAM_BOOL(binary
)
1260 //public readonly bool $compactFloats = false,
1261 Z_PARAM_BOOL(compact_floats
)
1262 //public readonly bool $escapeNonAscii = false,
1263 Z_PARAM_BOOL(escape
)
1264 //public readonly bool $prettyPrint = false,
1265 Z_PARAM_BOOL(pretty
)
1266 //public readonly bool $indentTabs = true,
1268 //public readonly int $indentSize = 2,
1269 Z_PARAM_LONG(indent
)
1270 //public readonly bool $flushEveryValue = false,
1272 //public readonly int $maxContainerDepth = 10,
1273 Z_PARAM_LONG(max_depth
)
1274 //public readonly int $maxAnnotations = 10,
1275 Z_PARAM_LONG(max_ann
)
1276 //public readonly int $tempBufferSize = 0x4000,
1278 ZEND_PARSE_PARAMETERS_END();
1281 update_property_obj(&obj
->std
, ZEND_STRL("catalog"), obj
->cat
);
1282 obj
->opt
.pcatalog
= php_ion_obj(catalog
, obj
->cat
)->cat
;
1284 zend_update_property_null(NULL
, &obj
->std
, ZEND_STRL("catalog"));
1287 update_property_obj(&obj
->std
, ZEND_STRL("decimalContext"), obj
->dec_ctx
);
1288 obj
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, obj
->dec_ctx
)->ctx
;
1290 zend_update_property_null(NULL
, &obj
->std
, ZEND_STRL("decimalContext"));
1292 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("outputBinary"),
1293 obj
->opt
.output_as_binary
= binary
);
1294 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("compactFloats"),
1295 obj
->opt
.compact_floats
= compact_floats
);
1296 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("escapeNonAscii"),
1297 obj
->opt
.escape_all_non_ascii
= escape
);
1298 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("prettyPrint"),
1299 obj
->opt
.pretty_print
= pretty
);
1300 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentTabs"),
1301 obj
->opt
.indent_with_tabs
= tabs
);
1302 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentSize"),
1303 obj
->opt
.indent_size
= (SIZE
) indent
);
1304 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("flushEveryValue"),
1305 obj
->opt
.flush_every_value
= flush
);
1306 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxContainerDepth"),
1307 obj
->opt
.max_container_depth
= (SIZE
) max_depth
);
1308 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxAnnotations"),
1309 obj
->opt
.max_annotation_count
= (SIZE
) max_ann
);
1310 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("tempBufferSize"),
1311 obj
->opt
.temp_buffer_size
= (SIZE
) temp
);
1313 static ZEND_METHOD(ion_Writer_Writer
, writeNull
)
1315 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1318 ZEND_PARSE_PARAMETERS_NONE();
1320 ION_CHECK(ion_writer_write_null(obj
->writer
));
1322 static ZEND_METHOD(ion_Writer_Writer
, writeTypedNull
)
1324 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1327 zend_object
*typ_obj
;
1328 ZEND_PARSE_PARAMETERS_START(1, 1)
1329 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1330 ZEND_PARSE_PARAMETERS_END();
1332 ION_CHECK(ion_writer_write_typed_null(obj
->writer
, ion_type_from_enum(typ_obj
)));
1334 static ZEND_METHOD(ion_Writer_Writer
, writeBool
)
1336 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1340 ZEND_PARSE_PARAMETERS_START(1, 1)
1342 ZEND_PARSE_PARAMETERS_END();
1344 ION_CHECK(ion_writer_write_bool(obj
->writer
, b
));
1346 static ZEND_METHOD(ion_Writer_Writer
, writeInt
)
1348 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1353 ZEND_PARSE_PARAMETERS_START(1, 1)
1354 Z_PARAM_STR_OR_LONG(s
, l
)
1355 ZEND_PARSE_PARAMETERS_END();
1359 ION_CHECK(ion_int_alloc(obj
->writer
, &i
));
1360 ION_CHECK(ion_int_from_chars(i
, s
->val
, s
->len
));
1361 ION_CHECK(ion_writer_write_ion_int(obj
->writer
, i
));
1364 ION_CHECK(ion_writer_write_int64(obj
->writer
, l
));
1367 static ZEND_METHOD(ion_Writer_Writer
, writeFloat
)
1369 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1373 ZEND_PARSE_PARAMETERS_START(1, 1)
1375 ZEND_PARSE_PARAMETERS_END();
1377 ION_CHECK(ion_writer_write_double(obj
->writer
, d
));
1379 static ZEND_METHOD(ion_Writer_Writer
, writeDecimal
)
1381 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1384 zend_object
*dec_obj
;
1385 zend_string
*dec_str
;
1386 ZEND_PARSE_PARAMETERS_START(1, 1)
1387 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj
, ce_Decimal
, dec_str
)
1388 ZEND_PARSE_PARAMETERS_END();
1391 decContext
*ctx
= &php_ion_globals
.decimal
.ctx
;
1392 ION_DECIMAL dec
= {0};
1395 php_ion_writer_options
*opt_obj
= php_ion_obj(writer_options
, obj
->opt
);
1396 if (opt_obj
->opt
.decimal_context
) {
1397 ctx
= opt_obj
->opt
.decimal_context
;
1400 ION_CHECK(ion_decimal_from_string(&dec
, dec_str
->val
, ctx
));
1401 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
));
1403 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
1404 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
1407 static ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
1409 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1412 zend_object
*ts_obj
;
1413 zend_string
*ts_str
;
1414 ZEND_PARSE_PARAMETERS_START(1, 1)
1415 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
1416 ZEND_PARSE_PARAMETERS_END();
1418 decContext
*ctx
= NULL
;
1420 ctx
= php_ion_obj(reader_options
, obj
->opt
)->opt
.decimal_context
;
1423 ION_TIMESTAMP tmp
= {0};
1426 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1428 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1430 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1432 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1434 static ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1436 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1439 zend_object
*sym_obj
;
1440 zend_string
*sym_str
;
1441 ZEND_PARSE_PARAMETERS_START(1, 1)
1442 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1443 ZEND_PARSE_PARAMETERS_END();
1447 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1449 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1451 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1454 static ZEND_METHOD(ion_Writer_Writer
, writeString
)
1456 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1460 ZEND_PARSE_PARAMETERS_START(1, 1)
1462 ZEND_PARSE_PARAMETERS_END();
1465 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1467 static ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1469 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1473 ZEND_PARSE_PARAMETERS_START(1, 1)
1475 ZEND_PARSE_PARAMETERS_END();
1477 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1479 static ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1481 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1485 ZEND_PARSE_PARAMETERS_START(1, 1)
1487 ZEND_PARSE_PARAMETERS_END();
1489 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1491 static ZEND_METHOD(ion_Writer_Writer
, startLob
)
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_lob(obj
->writer
, ion_type_from_enum(typ_obj
)));
1503 static ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1505 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1509 ZEND_PARSE_PARAMETERS_START(1, 1)
1511 ZEND_PARSE_PARAMETERS_END();
1513 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1515 static ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1517 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1520 ZEND_PARSE_PARAMETERS_NONE();
1522 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1524 static ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1526 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1529 zend_object
*typ_obj
;
1530 ZEND_PARSE_PARAMETERS_START(1, 1)
1531 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1532 ZEND_PARSE_PARAMETERS_END();
1534 ION_CHECK(ion_writer_start_container(obj
->writer
, ion_type_from_enum(typ_obj
)));
1536 static ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1538 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1541 ZEND_PARSE_PARAMETERS_NONE();
1543 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1545 static ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1547 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1550 zend_object
*sym_obj
;
1551 zend_string
*sym_str
;
1552 ZEND_PARSE_PARAMETERS_START(1, 1)
1553 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1554 ZEND_PARSE_PARAMETERS_END();
1558 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1560 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1562 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1565 static ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1567 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1572 ZEND_PARSE_PARAMETERS_START(1, -1)
1573 Z_PARAM_VARIADIC('+', args
, argc
);
1574 ZEND_PARSE_PARAMETERS_END();
1576 for (unsigned i
= 0; i
< argc
; ++i
) {
1577 switch (Z_TYPE(args
[i
])) {
1580 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1584 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1589 static ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1591 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1594 ZEND_PARSE_PARAMETERS_NONE();
1597 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1600 static ZEND_METHOD(ion_Writer_Writer
, flush
)
1602 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1605 ZEND_PARSE_PARAMETERS_NONE();
1608 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1609 RETURN_LONG(flushed
);
1611 static ZEND_METHOD(ion_Writer_Writer
, finish
)
1613 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1616 ZEND_PARSE_PARAMETERS_NONE();
1619 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1620 RETURN_LONG(flushed
);
1622 static ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1624 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1627 zval
*za_opt
= NULL
;
1628 ZEND_PARSE_PARAMETERS_START(0, 1)
1630 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj
->opt
, ce_Writer_Options
, ce_Writer_Options
, za_opt
)
1631 ZEND_PARSE_PARAMETERS_END();
1633 obj
->type
= BUFFER_WRITER
;
1634 php_ion_writer_ctor(obj
);
1636 OBJ_RELEASE(obj
->opt
);
1639 static ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1641 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1644 ZEND_PARSE_PARAMETERS_NONE();
1646 RETVAL_STR(php_ion_writer_buffer_copy(obj
));
1648 static ZEND_METHOD(ion_Writer_Buffer_Writer
, resetBuffer
)
1650 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1653 ZEND_PARSE_PARAMETERS_NONE();
1655 php_ion_writer_buffer_reset(obj
);
1657 static ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1659 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1662 zval
*zstream
, *za_opt
= NULL
;
1663 ZEND_PARSE_PARAMETERS_START(1, 2)
1664 Z_PARAM_RESOURCE(zstream
)
1666 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj
->opt
, ce_Writer_Options
, ce_Writer_Options
, za_opt
)
1667 ZEND_PARSE_PARAMETERS_END();
1669 obj
->type
= STREAM_WRITER
;
1670 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1672 php_ion_writer_ctor(obj
);
1674 OBJ_RELEASE(obj
->opt
);
1677 static ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1679 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1682 ZEND_PARSE_PARAMETERS_NONE();
1683 PTR_CHECK(obj
->stream
.ptr
);
1685 GC_ADDREF(obj
->stream
.ptr
->res
);
1686 RETURN_RES(obj
->stream
.ptr
->res
);
1689 static ZEND_METHOD(ion_Serializer_Serializer
, __construct
)
1691 php_ion_serializer
*obj
= php_ion_obj(serializer
, Z_OBJ_P(ZEND_THIS
));
1694 obj
->call_magic
= true;
1696 ZEND_PARSE_PARAMETERS_START(0, 3)
1698 Z_PARAM_BOOL(obj
->multi_seq
)
1699 Z_PARAM_BOOL(obj
->call_magic
)
1700 Z_PARAM_STR_OR_NULL(obj
->call_custom
)
1701 ZEND_PARSE_PARAMETERS_END();
1703 php_ion_serializer_ctor(obj
);
1705 static ZEND_METHOD(ion_Serializer_Serializer
, serialize
)
1707 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1709 zval
*data
, *za_opt
= NULL
;
1710 zend_object
*zo_wri
= NULL
;
1711 ZEND_PARSE_PARAMETERS_START(1, 2)
1714 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_wri
, ce_Writer
, ce_Writer_Options
, za_opt
)
1715 ZEND_PARSE_PARAMETERS_END();
1717 php_ion_serializer
*ser
= php_ion_obj(serializer
, obj
);
1719 php_ion_serialize(ser
, data
, return_value
);
1723 OBJ_RELEASE(zo_wri
);
1726 static ZEND_FUNCTION(ion_serialize
)
1728 zval
*data
, *za_ser
= NULL
;
1729 zend_object
*zo_ser
= NULL
;
1730 ZEND_PARSE_PARAMETERS_START(1, 2)
1733 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_ser
, ce_Serializer
, ce_Serializer_Serializer
, za_ser
)
1734 ZEND_PARSE_PARAMETERS_END();
1736 if (!zo_ser
|| zo_ser
->ce
== ce_Serializer_Serializer
) {
1737 // default, fast path
1738 php_ion_serializer
*ser
= zo_ser
? php_ion_obj(serializer
, zo_ser
) : NULL
;
1739 php_ion_serialize(ser
, data
, return_value
);
1741 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "serialize", return_value
, data
);
1745 OBJ_RELEASE(zo_ser
);
1749 static ZEND_METHOD(ion_Unserializer_Unserializer
, __construct
)
1751 php_ion_unserializer
*obj
= php_ion_obj(unserializer
, Z_OBJ_P(ZEND_THIS
));
1754 obj
->call_magic
= true;
1756 ZEND_PARSE_PARAMETERS_START(0, 3)
1758 Z_PARAM_BOOL(obj
->multi_seq
)
1759 Z_PARAM_BOOL(obj
->call_magic
)
1760 Z_PARAM_STR_OR_NULL(obj
->call_custom
)
1761 ZEND_PARSE_PARAMETERS_END();
1763 php_ion_unserializer_ctor(obj
);
1765 static ZEND_METHOD(ion_Unserializer_Unserializer
, unserialize
)
1767 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1769 zval
*data
, *za_opt
= NULL
;
1770 zend_object
*zo_rdr
= NULL
;
1771 ZEND_PARSE_PARAMETERS_START(1, 2)
1774 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_rdr
, ce_Reader
, ce_Reader_Options
, za_opt
)
1775 ZEND_PARSE_PARAMETERS_END();
1777 php_ion_unserializer
*ser
= php_ion_obj(unserializer
, obj
);
1779 php_ion_unserialize(ser
, data
, return_value
);
1783 OBJ_RELEASE(zo_rdr
);
1786 static ZEND_FUNCTION(ion_unserialize
)
1788 zval
*data
, *za_ser
= NULL
;
1789 zend_object
*zo_ser
= NULL
;
1790 ZEND_PARSE_PARAMETERS_START(1, 2)
1793 Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_ser
, ce_Unserializer
, ce_Unserializer_Unserializer
, za_ser
)
1794 ZEND_PARSE_PARAMETERS_END();
1796 if (!zo_ser
|| zo_ser
->ce
== ce_Unserializer_Unserializer
) {
1797 // default, fast path
1798 php_ion_unserializer
*ser
= zo_ser
? php_ion_obj(unserializer
, zo_ser
) : NULL
;
1799 php_ion_unserialize(ser
, data
, return_value
);
1801 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "unserialize", return_value
, data
);
1805 OBJ_RELEASE(zo_ser
);
1809 PHP_RINIT_FUNCTION(ion
)
1811 #if defined(ZTS) && defined(COMPILE_DL_ION)
1812 ZEND_TSRMLS_CACHE_UPDATE();
1815 php_ion_globals_symbols_init();
1816 php_ion_globals_serializer_init();
1817 php_ion_globals_unserializer_init();
1821 PHP_RSHUTDOWN_FUNCTION(ion
)
1823 php_ion_globals_unserializer_dtor();
1824 php_ion_globals_serializer_dtor();
1825 php_ion_globals_symbols_dtor();
1829 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
1830 { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, ((type_mask) | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0))), default_value },
1831 #include "ion_arginfo.h"
1833 // spl_iterators.h includes ext/pcre/php_pcre.h which might not find pcre2.h
1834 extern PHPAPI zend_class_entry
*spl_ce_RecursiveIterator
;
1836 PHP_MINIT_FUNCTION(ion
)
1839 if (SUCCESS
!= g_sym_init()) {
1842 g_intern_str_init();
1845 php_ion_register(catalog
, Catalog
, zend_ce_countable
);
1848 php_ion_register(decimal
, Decimal
);
1849 php_ion_register(decimal_ctx
, Decimal_Context
);
1850 ce_Decimal_Context_Rounding
= register_class_ion_Decimal_Context_Rounding();
1853 ce_Exception
= register_class_ion_Exception(zend_ce_exception
);
1856 ce_LOB
= register_class_ion_LOB();
1859 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1860 php_ion_register(reader_options
, Reader_Options
);
1861 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1862 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1863 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1864 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1865 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1868 ce_Serializer
= register_class_ion_Serializer();
1869 php_ion_register(serializer
, Serializer_Serializer
, ce_Serializer
);
1872 php_ion_register(symbol
, Symbol
);
1873 oh_Symbol
.compare
= php_ion_symbol_zval_compare
;
1874 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1875 php_ion_register(symbol_table
, Symbol_Table
);
1876 ce_Symbol_Table
->create_object
= NULL
;
1877 ce_Symbol_Table_Local
= register_class_ion_Symbol_Table_Local(ce_Symbol_Table
);
1878 ce_Symbol_Table_Local
->create_object
= create_ion_Symbol_Table
;
1879 ce_Symbol_Table_Shared
= register_class_ion_Symbol_Table_Shared(ce_Symbol_Table
);
1880 ce_Symbol_Table_Shared
->create_object
= create_ion_Symbol_Table
;
1881 ce_Symbol_Enum
= register_class_ion_Symbol_Enum();
1882 ce_Symbol_Table_System
= register_class_ion_Symbol_System(ce_Symbol_Enum
);
1883 ce_Symbol_Table_PHP
= register_class_ion_Symbol_PHP(ce_Symbol_Enum
);
1886 ce_Timestamp
= register_class_ion_Timestamp(php_date_get_date_ce());
1887 ce_Timestamp_Format
= register_class_ion_Timestamp_Format();
1888 ce_Timestamp_Precision
= register_class_ion_Timestamp_Precision();
1891 ce_Type
= register_class_ion_Type();
1894 ce_Writer
= register_class_ion_Writer();
1895 php_ion_register(writer_options
, Writer_Options
);
1896 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1897 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1898 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1899 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1900 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1903 ce_Unserializer
= register_class_ion_Unserializer();
1904 php_ion_register(unserializer
, Unserializer_Unserializer
, ce_Unserializer
);
1909 PHP_MSHUTDOWN_FUNCTION(ion
)
1911 if (g_sym_tab_php
) {
1912 ion_symbol_table_close(g_sym_tab_php
);
1914 zend_hash_destroy(&g_sym_hash
);
1918 PHP_MINFO_FUNCTION(ion
)
1920 php_info_print_table_start();
1921 php_info_print_table_header(2, "ion support", "enabled");
1922 php_info_print_table_row(2, "ion version", PHP_ION_VERSION
);
1923 php_info_print_table_row(2, "ion-c version", "unknown");
1924 php_info_print_table_end();
1927 PHP_GINIT_FUNCTION(ion
)
1929 memset(ion_globals
, 0, sizeof(*ion_globals
));
1931 php_ion_decimal_ctx_init_max(&ion_globals
->decimal
.ctx
, DEC_ROUND_HALF_EVEN
);
1932 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_max
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MAX
);
1933 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_min
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MIN
);
1936 PHP_GSHUTDOWN_FUNCTION(ion
)
1940 static zend_module_dep ion_module_deps
[] = {
1941 ZEND_MOD_REQUIRED("date")
1942 ZEND_MOD_REQUIRED("spl")
1946 zend_module_entry ion_module_entry
= {
1947 STANDARD_MODULE_HEADER_EX
,
1950 "ion", /* Extension name */
1951 ext_functions
, /* zend_function_entry */
1952 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1953 PHP_MSHUTDOWN(ion
), /* PHP_MSHUTDOWN - Module shutdown */
1954 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1955 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1956 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1957 PHP_ION_VERSION
, /* Version */
1958 ZEND_MODULE_GLOBALS(ion
),
1959 PHP_GINIT(ion
), /* PHP_GINIT */
1960 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1962 STANDARD_MODULE_PROPERTIES_EX
1965 #ifdef COMPILE_DL_ION
1967 ZEND_TSRMLS_CACHE_DEFINE()
1969 ZEND_GET_MODULE(ion
)