2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2021, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
18 #include "ext/standard/info.h"
20 #include "Zend/zend_enum.h"
21 #include "Zend/zend_exceptions.h"
22 #include "Zend/zend_closures.h"
23 #include "Zend/zend_interfaces.h"
24 #include "Zend/zend_smart_str.h"
26 #include "ext/date/php_date.h"
27 #include "ext/spl/spl_exceptions.h"
28 #include "ext/spl/spl_iterators.h"
31 #include "ion_private.h"
33 static ZEND_METHOD(ion_Symbol_ImportLocation
, __construct
)
35 php_ion_symbol_iloc
*obj
= php_ion_obj(symbol_iloc
, Z_OBJ_P(ZEND_THIS
));
39 ZEND_PARSE_PARAMETERS_START(2, 2)
40 Z_PARAM_STR(obj
->name
)
41 Z_PARAM_LONG(location
)
42 ZEND_PARSE_PARAMETERS_END();
44 obj
->loc
.location
= location
;
45 php_ion_symbol_iloc_ctor(obj
);
47 static ZEND_METHOD(ion_Symbol
, __construct
)
49 php_ion_symbol
*obj
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
53 ZEND_PARSE_PARAMETERS_START(0, 3)
55 Z_PARAM_STR_OR_NULL(obj
->value
)
57 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->iloc
, ce_Symbol_ImportLocation
)
58 ZEND_PARSE_PARAMETERS_END();
61 php_ion_symbol_ctor(obj
);
63 static ZEND_METHOD(ion_Symbol
, equals
)
65 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
68 zend_object
*other_obj
;
69 ZEND_PARSE_PARAMETERS_START(1, 1)
70 Z_PARAM_OBJ_OF_CLASS(other_obj
, ce_Symbol
)
71 ZEND_PARSE_PARAMETERS_END();
74 iERR err
= ion_symbol_is_equal(
76 &php_ion_obj(symbol
, other_obj
)->sym
, &eq
);
80 static ZEND_METHOD(ion_Symbol
, __toString
)
82 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
85 ZEND_PARSE_PARAMETERS_NONE();
88 RETURN_EMPTY_STRING();
90 RETURN_STR_COPY(sym
->value
);
92 static ZEND_METHOD(ion_Symbol_Enum
, toSymbol
)
94 ZEND_PARSE_PARAMETERS_NONE();
96 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
99 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
101 RETVAL_ZVAL(zsym
, 1, 0);
103 static ZEND_METHOD(ion_Symbol_Enum
, toSID
)
105 ZEND_PARSE_PARAMETERS_NONE();
107 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
110 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
114 RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym
), Z_OBJ_P(zsym
), ZEND_STRL("sid"), 0, &tmp
), 1, 0);
116 static ZEND_METHOD(ion_Symbol_Enum
, toString
)
118 ZEND_PARSE_PARAMETERS_NONE();
120 zval
*zc
= zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS
));
123 zval
*zsym
= php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc
));
127 RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym
), Z_OBJ_P(zsym
), ZEND_STRL("value"), 0, &tmp
), 1, 0);
129 static ZEND_FUNCTION(ion_Symbol_Table_System
)
131 ZEND_PARSE_PARAMETERS_NONE();
133 object_init_ex(return_value
, ce_Symbol_Table_Shared
);
134 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(return_value
));
135 ION_CHECK(ion_symbol_table_get_system_table(&obj
->tab
, 1));
136 php_ion_symbol_table_ctor(obj
);
137 ion_symbol_table_lock(obj
->tab
);
139 static ZEND_FUNCTION(ion_Symbol_Table_PHP
)
141 ZEND_PARSE_PARAMETERS_NONE();
143 object_init_ex(return_value
, ce_Symbol_Table_Shared
);
144 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(return_value
));
145 obj
->tab
= g_sym_tab_php
;
146 php_ion_symbol_table_ctor(obj
);
147 ion_symbol_table_lock(obj
->tab
);
149 static ZEND_METHOD(ion_Symbol_Table_Local
, __construct
)
151 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
154 ZEND_PARSE_PARAMETERS_NONE();
156 ION_CHECK(ion_symbol_table_open_with_type(&obj
->tab
, NULL
, ist_LOCAL
));
157 obj
->dtor
= ion_symbol_table_close
;
160 static ZEND_METHOD(ion_Symbol_Table_Local
, import
)
162 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
165 zend_object
*zo_import
;
166 ZEND_PARSE_PARAMETERS_START(1, 1)
167 Z_PARAM_OBJ_OF_CLASS(zo_import
, ce_Symbol_Table
);
168 ZEND_PARSE_PARAMETERS_END();
170 php_ion_symbol_table_import(obj
, php_ion_obj(symbol_table
, zo_import
));
172 static ZEND_METHOD(ion_Symbol_Table_Shared
, __construct
)
174 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
178 zend_long version
= 1;
179 HashTable
*ht_sym
= NULL
;
180 ZEND_PARSE_PARAMETERS_START(1, 3)
183 Z_PARAM_LONG(version
)
184 Z_PARAM_ARRAY_HT_OR_NULL(ht_sym
)
185 ZEND_PARSE_PARAMETERS_END();
187 ION_CHECK(ion_symbol_table_open_with_type(&obj
->tab
, NULL
, ist_SHARED
));
188 obj
->dtor
= ion_symbol_table_close
;
191 ION_CHECK(ion_symbol_table_set_name(obj
->tab
, ion_string_from_zend(&is
, zname
)));
192 ION_CHECK(ion_symbol_table_set_version(obj
->tab
, version
));
194 php_ion_symbol_table_ctor(obj
);
197 if (ht_sym
) ZEND_HASH_FOREACH_VAL(ht_sym
, zsym
)
199 zend_string
*str
= zval_get_string(zsym
);
205 ION_CHECK(ion_symbol_table_add_symbol(obj
->tab
, ion_string_from_zend(&is
, str
), NULL
), zend_string_release(str
));
206 zend_string_release(str
);
208 ZEND_HASH_FOREACH_END();
210 static ZEND_METHOD(ion_Symbol_Table
, getMaxId
)
212 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
215 ZEND_PARSE_PARAMETERS_NONE();
218 ION_CHECK(ion_symbol_table_get_max_sid(obj
->tab
, &max_sid
));
219 RETURN_LONG(max_sid
);
221 static ZEND_METHOD(ion_Symbol_Table
, add
)
223 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
226 zend_object
*zo_sym
= NULL
;
227 zend_string
*zs_sym
= NULL
;
228 ZEND_PARSE_PARAMETERS_START(1, 1)
229 Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_sym
, ce_Symbol
, zs_sym
)
230 ZEND_PARSE_PARAMETERS_END();
234 ZVAL_OBJ(&z_sym
, zo_sym
);
235 zs_sym
= zval_get_string(&z_sym
);
240 ION_CHECK(ion_symbol_table_add_symbol(obj
->tab
, ion_string_from_zend(&is
, zs_sym
), &sid
),
242 zend_string_release(zs_sym
);
245 zend_string_release(zs_sym
);
249 static ZEND_METHOD(ion_Symbol_Table
, find
)
251 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
255 zend_string
*zstring
= NULL
;
256 ZEND_PARSE_PARAMETERS_START(1, 1)
257 Z_PARAM_STR_OR_LONG(zstring
, zsid
)
258 ZEND_PARSE_PARAMETERS_END();
263 ION_CHECK(ion_symbol_table_find_by_name(obj
->tab
, ion_string_from_zend(&is
, zstring
), &sid
));
267 ION_CHECK(ion_symbol_table_get_symbol(obj
->tab
, zsid
, &sym
));
269 php_ion_symbol_table_symbol_zval(obj
, sym
, return_value
);
272 static ZEND_METHOD(ion_Symbol_Table
, findLocal
)
274 php_ion_symbol_table
*obj
= php_ion_obj(symbol_table
, Z_OBJ_P(ZEND_THIS
));
278 zend_string
*zstring
;
279 ZEND_PARSE_PARAMETERS_START(1, 1)
280 Z_PARAM_STR_OR_LONG(zstring
, zsid
)
281 ZEND_PARSE_PARAMETERS_END();
286 ION_CHECK(ion_symbol_table_find_by_name(obj
->tab
, ion_string_from_zend(&is
, zstring
), &sid
));
290 ION_CHECK(ion_symbol_table_get_local_symbol(obj
->tab
, zsid
, &sym
));
292 php_ion_symbol_table_symbol_zval(obj
, sym
, return_value
);
295 static ZEND_METHOD(ion_Catalog
, __construct
)
297 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
300 ZEND_PARSE_PARAMETERS_NONE();
302 php_ion_catalog_ctor(obj
);
304 static ZEND_METHOD(ion_Catalog
, count
)
306 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
309 ZEND_PARSE_PARAMETERS_NONE();
312 ION_CHECK(ion_catalog_get_symbol_table_count(obj
->cat
, &c
));
315 static ZEND_METHOD(ion_Catalog
, add
)
317 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
320 zend_object
*zo_symtab
;
321 ZEND_PARSE_PARAMETERS_START(1, 1)
322 Z_PARAM_OBJ_OF_CLASS(zo_symtab
, ce_Symbol_Table
)
323 ZEND_PARSE_PARAMETERS_END();
325 php_ion_symbol_table
*o_symtab
= php_ion_obj(symbol_table
, zo_symtab
);
326 php_ion_catalog_add_symbol_table(obj
, o_symtab
);
329 static ZEND_METHOD(ion_Catalog
, remove
)
331 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
334 zend_object
*zo_symtab
= NULL
;
335 zend_string
*zs_symtab
= NULL
;
336 ZEND_PARSE_PARAMETERS_START(1, 1)
337 Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_symtab
, ce_Symbol_Table
, zs_symtab
)
338 ZEND_PARSE_PARAMETERS_END();
343 zval
*ztabs
= zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("symbolTables"), 0, &tmp
);
347 zend_ulong idx
= (uintptr_t) &zo_symtab
->gc
;
348 RETVAL_BOOL(SUCCESS
== zend_hash_index_del(Z_ARRVAL_P(ztabs
), idx
));
349 ION_CHECK(ion_catalog_release_symbol_table(obj
->cat
, php_ion_obj(symbol_table
, zo_symtab
)->tab
));
351 bool deleted
= false;
352 ION_SYMBOL_TABLE
*tab
;
354 ion_string_from_zend(&is
, zs_symtab
);
357 ION_CHECK(ion_catalog_find_best_match(obj
->cat
, &is
, 0, &tab
));
359 ION_CHECK(ion_catalog_release_symbol_table(obj
->cat
, tab
));
363 RETVAL_BOOL(deleted
);
367 static ZEND_METHOD(ion_Catalog
, find
)
369 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
372 zend_long zversion
= 0;
374 ZEND_PARSE_PARAMETERS_START(1, 2)
377 Z_PARAM_LONG(zversion
)
378 ZEND_PARSE_PARAMETERS_END();
381 ION_SYMBOL_TABLE
*tab_ptr
= NULL
;
382 ION_CHECK(ion_catalog_find_symbol_table(obj
->cat
, ion_string_from_zend(&is
, zname
), zversion
, &tab_ptr
));
384 php_ion_catalog_symbol_table_zval(obj
, tab_ptr
, return_value
);
387 static ZEND_METHOD(ion_Catalog
, findBest
)
389 php_ion_catalog
*obj
= php_ion_obj(catalog
, Z_OBJ_P(ZEND_THIS
));
392 zend_long zversion
= 0;
394 ZEND_PARSE_PARAMETERS_START(1, 2)
397 Z_PARAM_LONG(zversion
)
398 ZEND_PARSE_PARAMETERS_END();
401 ION_SYMBOL_TABLE
*tab_ptr
= NULL
;
402 ION_CHECK(ion_catalog_find_best_match(obj
->cat
, ion_string_from_zend(&is
, zname
), zversion
, &tab_ptr
));
404 php_ion_catalog_symbol_table_zval(obj
, tab_ptr
, return_value
);
407 static ZEND_METHOD(ion_Timestamp
, __construct
)
409 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
413 zend_object
*precision_obj
;
414 zend_string
*fmt
= NULL
, *dt
= NULL
;
416 ZEND_PARSE_PARAMETERS_START(1, 4)
417 Z_PARAM_OBJ_OF_CLASS_OR_LONG(precision_obj
, ce_Timestamp_Precision
, precision
)
419 Z_PARAM_STR_OR_NULL(fmt
)
420 Z_PARAM_STR_OR_NULL(dt
)
422 ZEND_PARSE_PARAMETERS_END();
425 precision
= Z_LVAL_P(zend_enum_fetch_case_value(precision_obj
));
427 php_ion_timestamp_ctor(obj
, precision
, fmt
, dt
, tz
);
429 static ZEND_METHOD(ion_Timestamp
, __toString
)
431 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
434 ZEND_PARSE_PARAMETERS_NONE();
438 zend_call_method_with_1_params(&obj
->std
, obj
->std
.ce
, NULL
, "format", return_value
,
439 zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("format"), 0, &fmt
));
441 static ZEND_METHOD(ion_Decimal_Context
, __construct
)
443 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(ZEND_THIS
));
447 zend_object
*o_round
= NULL
;
448 zend_long digits
, emax
, emin
, round
;
449 ZEND_PARSE_PARAMETERS_START(5, 5)
453 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
455 ZEND_PARSE_PARAMETERS_END();
458 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
460 php_ion_decimal_ctx_init(&obj
->ctx
, digits
, emax
, emin
, round
, clamp
);
461 php_ion_decimal_ctx_ctor(obj
, o_round
);
463 static inline void make_decimal_ctx(INTERNAL_FUNCTION_PARAMETERS
, int kind
)
465 ZEND_PARSE_PARAMETERS_NONE();
467 object_init_ex(return_value
, ce_Decimal_Context
);
468 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
469 decContextDefault(&obj
->ctx
, kind
);
470 php_ion_decimal_ctx_ctor(obj
, NULL
);
472 static ZEND_METHOD(ion_Decimal_Context
, Dec32
)
474 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL32
);
476 static ZEND_METHOD(ion_Decimal_Context
, Dec64
)
478 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL64
);
480 static ZEND_METHOD(ion_Decimal_Context
, Dec128
)
482 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL128
);
484 static ZEND_METHOD(ion_Decimal_Context
, DecMax
)
486 zend_object
*o_round
= NULL
;
487 zend_long round
= DEC_ROUND_HALF_EVEN
;
488 ZEND_PARSE_PARAMETERS_START(0, 1)
490 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 object_init_ex(return_value
, ce_Decimal_Context
);
497 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
498 php_ion_decimal_ctx_init_max(&obj
->ctx
, round
);
499 php_ion_decimal_ctx_ctor(obj
, o_round
);
501 static ZEND_METHOD(ion_Decimal
, __construct
)
503 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
508 ZEND_PARSE_PARAMETERS_START(1, 2)
509 Z_PARAM_STR_OR_LONG(zstr
, num
)
511 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->ctx
, ce_Decimal_Context
)
512 ZEND_PARSE_PARAMETERS_END();
518 object_init_ex(&zdc
, ce_Decimal_Context
);
519 obj
->ctx
= Z_OBJ(zdc
);
520 php_ion_decimal_ctx_ctor(php_ion_obj(decimal_ctx
, obj
->ctx
), NULL
);
523 decContext
*ctx
= &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
;
526 ION_CHECK(ion_decimal_from_string(&obj
->dec
, zstr
->val
, ctx
), OBJ_RELEASE(obj
->ctx
));
528 php_ion_decimal_from_zend_long(&obj
->dec
, ctx
, num
);
531 php_ion_decimal_ctor(obj
);
532 OBJ_RELEASE(obj
->ctx
);
534 static ZEND_METHOD(ion_Decimal
, equals
)
536 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
539 zend_object
*dec_obj
;
540 ZEND_PARSE_PARAMETERS_START(1, 1)
541 Z_PARAM_OBJ_OF_CLASS(dec_obj
, ce_Decimal
)
542 ZEND_PARSE_PARAMETERS_END();
545 ION_CHECK(ion_decimal_equals(&obj
->dec
, &php_ion_obj(decimal
, dec_obj
)->dec
,
546 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &is
));
549 static ZEND_METHOD(ion_Decimal
, __toString
)
551 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
554 ZEND_PARSE_PARAMETERS_NONE();
556 RETURN_STR(php_ion_decimal_to_string(&obj
->dec
));
558 static ZEND_METHOD(ion_Decimal
, toInt
)
560 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
563 ZEND_PARSE_PARAMETERS_NONE();
566 php_ion_decimal_to_zend_long(&obj
->dec
, &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
, &l
);
569 static ZEND_METHOD(ion_Decimal
, isInt
)
571 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
574 ZEND_PARSE_PARAMETERS_NONE();
576 RETURN_BOOL(ion_decimal_is_integer(&obj
->dec
));
578 static ZEND_METHOD(ion_LOB
, __construct
)
581 zend_object
*type
= NULL
;
582 ZEND_PARSE_PARAMETERS_START(1, 2)
585 Z_PARAM_OBJ_OF_CLASS(type
, ce_Type
)
586 ZEND_PARSE_PARAMETERS_END();
589 type
= zend_enum_get_case_cstr(ce_Type
, "CLob");
591 update_property_obj(Z_OBJ_P(ZEND_THIS
), ZEND_STRL("type"), type
);
592 zend_update_property_str(Z_OBJCE_P(ZEND_THIS
), Z_OBJ_P(ZEND_THIS
), ZEND_STRL("value"), value
);
594 static ZEND_METHOD(ion_Reader_Options
, __construct
)
596 php_ion_reader_options
*opt
= php_ion_obj(reader_options
, Z_OBJ_P(ZEND_THIS
));
597 zend_bool ret_sys_val
= false, skip_validation
= false;
598 zend_long ch_nl
= 0xa, max_depth
= 10, max_ann
= 10, max_ann_buf
= 512,
599 sym_thr
= 0x4000, uval_thr
= 0x4000, chunk_thr
= 0x4000, alloc_pgsz
= 0x10000;
603 ZEND_PARSE_PARAMETERS_START(0, 13)
605 // public readonly ?\ion\Catalog $catalog = null,
606 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cat
, ce_Catalog
)
607 // public readonly ?\ion\Decimal\Context $decimalContext = null,
608 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->dec_ctx
, ce_Decimal_Context
)
609 // public readonly ?\Closure $onContextChange = null,
610 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cb
, zend_ce_closure
);
611 // public readonly bool $returnSystemValues = false,
612 Z_PARAM_BOOL(ret_sys_val
)
613 // public readonly int $newLine = 0xa,
615 // public readonly int $maxContainerDepth = 10,
616 Z_PARAM_LONG(max_depth
)
617 // public readonly int $maxAnnotations = 10,
618 Z_PARAM_LONG(max_ann
)
619 // public readonly int $maxAnnotationBuffered = 512,
620 Z_PARAM_LONG(max_ann_buf
)
621 // public readonly int $symbolThreshold = 0x4000,
622 Z_PARAM_LONG(sym_thr
)
623 // public readonly int $userValueThreshold = 0x4000,
624 Z_PARAM_LONG(uval_thr
)
625 // public readonly int $chunkThreshold = 0x4000,
626 Z_PARAM_LONG(chunk_thr
)
627 // public readonly int $allocationPageSize = 0x10000,
628 Z_PARAM_LONG(alloc_pgsz
)
629 // public readonly bool $skipCharacterValidation = false,
630 Z_PARAM_BOOL(skip_validation
)
631 ZEND_PARSE_PARAMETERS_END();
633 opt
->opt
.context_change_notifier
= EMPTY_READER_CHANGE_NOTIFIER
;
635 update_property_obj(&opt
->std
, ZEND_STRL("onContextChange"), opt
->cb
);
638 update_property_obj(&opt
->std
, ZEND_STRL("catalog"), opt
->cat
);
639 opt
->opt
.pcatalog
= php_ion_obj(catalog
, opt
->cat
)->cat
;
642 update_property_obj(&opt
->std
, ZEND_STRL("decimalContext"), opt
->dec_ctx
);
643 opt
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, opt
->dec_ctx
)->ctx
;
645 zend_update_property_bool(opt
->std
.ce
, &opt
->std
, ZEND_STRL("returnSystemValues"),
646 opt
->opt
.return_system_values
= ret_sys_val
);
647 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("newLine"),
648 opt
->opt
.new_line_char
= ch_nl
);
649 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxContainerDepth"),
650 opt
->opt
.max_container_depth
= max_depth
);
651 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationCount"),
652 opt
->opt
.max_annotation_count
= max_ann
);
653 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationBuffered"),
654 opt
->opt
.max_annotation_buffered
= max_ann_buf
);
655 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("symbolThreshold"),
656 opt
->opt
.symbol_threshold
= sym_thr
);
657 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("userValueThreshold"),
658 opt
->opt
.user_value_threshold
= uval_thr
);
659 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("chunkThreshold"),
660 opt
->opt
.chunk_threshold
= chunk_thr
);
661 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("allocationPageSize"),
662 opt
->opt
.allocation_page_size
= alloc_pgsz
);
663 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("skipCharacterValidation"),
664 opt
->opt
.skip_character_validation
= skip_validation
);
666 static ZEND_METHOD(ion_Reader_Reader
, hasChildren
)
668 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
671 ZEND_PARSE_PARAMETERS_NONE();
674 ION_CHECK(ion_reader_get_type(obj
->reader
, &t
));
675 switch (ION_TYPE_INT(t
)) {
686 static ZEND_METHOD(ion_Reader_Reader
, getChildren
)
688 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
691 ZEND_PARSE_PARAMETERS_NONE();
693 ION_CHECK(ion_reader_step_in(obj
->reader
));
695 RETURN_ZVAL(ZEND_THIS
, 1, 0);
697 static ZEND_METHOD(ion_Reader_Reader
, rewind
)
699 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
702 ZEND_PARSE_PARAMETERS_NONE();
704 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
706 static ZEND_METHOD(ion_Reader_Reader
, next
)
708 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
711 ZEND_PARSE_PARAMETERS_NONE();
713 if (obj
->state
== tid_EOF
) {
715 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
717 ION_CHECK(ion_reader_step_out(obj
->reader
));
720 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
722 static ZEND_METHOD(ion_Reader_Reader
, valid
)
724 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
727 ZEND_PARSE_PARAMETERS_NONE();
728 RETURN_BOOL(obj
->state
!= tid_none
&& obj
->state
!= tid_EOF
);
730 static ZEND_METHOD(ion_Reader_Reader
, key
)
732 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
735 ZEND_PARSE_PARAMETERS_NONE();
736 RETURN_IONTYPE(obj
->state
);
738 static ZEND_METHOD(ion_Reader_Reader
, current
)
740 ZEND_PARSE_PARAMETERS_NONE();
741 RETURN_ZVAL(ZEND_THIS
, 1, 0);
743 static ZEND_METHOD(ion_Reader_Reader
, getType
)
745 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
748 ZEND_PARSE_PARAMETERS_NONE();
751 ION_CHECK(ion_reader_get_type(obj
->reader
, &typ
));
754 static ZEND_METHOD(ion_Reader_Reader
, hasAnnotations
)
756 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
759 ZEND_PARSE_PARAMETERS_NONE();
762 ION_CHECK(ion_reader_has_any_annotations(obj
->reader
, &has
));
765 static ZEND_METHOD(ion_Reader_Reader
, hasAnnotation
)
767 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
770 zend_string
*ann_zstr
;
771 ZEND_PARSE_PARAMETERS_START(1, 1);
772 Z_PARAM_STR(ann_zstr
);
773 ZEND_PARSE_PARAMETERS_END();
777 ION_CHECK(ion_reader_has_annotation(obj
->reader
, ion_string_from_zend(&ann_istr
, ann_zstr
), &has
));
780 static ZEND_METHOD(ion_Reader_Reader
, isNull
)
782 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
785 ZEND_PARSE_PARAMETERS_NONE();
788 ION_CHECK(ion_reader_is_null(obj
->reader
, &is
));
791 static ZEND_METHOD(ion_Reader_Reader
, isInStruct
)
793 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
796 ZEND_PARSE_PARAMETERS_NONE();
799 ION_CHECK(ion_reader_is_in_struct(obj
->reader
, &is
));
802 static ZEND_METHOD(ion_Reader_Reader
, getFieldName
)
804 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
807 ZEND_PARSE_PARAMETERS_NONE();
810 ION_CHECK(ion_reader_get_field_name(obj
->reader
, &name
));
811 RETURN_STRINGL((char *) name
.value
, name
.length
);
813 static ZEND_METHOD(ion_Reader_Reader
, getFieldNameSymbol
)
815 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
818 ZEND_PARSE_PARAMETERS_NONE();
821 ION_CHECK(ion_reader_get_field_name_symbol(obj
->reader
, &sym_ptr
));
823 php_ion_symbol_zval(sym_ptr
, return_value
);
825 static ZEND_METHOD(ion_Reader_Reader
, getAnnotations
)
827 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
830 ZEND_PARSE_PARAMETERS_NONE();
834 max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
838 ION_STRING
*ptr
= ecalloc(sizeof(*ptr
), max
);
839 iERR err
= ion_reader_get_annotations(obj
->reader
, ptr
, max
, &count
);
841 array_init_size(return_value
, count
);
842 for (int32_t i
= 0; i
< count
; ++i
) {
843 add_next_index_str(return_value
, zend_string_from_ion(&ptr
[i
]));
849 static ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbols
)
851 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
854 ZEND_PARSE_PARAMETERS_NONE();
856 int32_t count
, max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
857 ION_SYMBOL
*ptr
= ecalloc(sizeof(*ptr
), max
);
858 iERR err
= ion_reader_get_annotation_symbols(obj
->reader
, ptr
, max
, &count
);
860 array_init_size(return_value
, count
);
861 for (int32_t i
= 0; i
< count
; ++i
) {
863 php_ion_symbol_zval(&ptr
[i
], &zsym
);
864 add_next_index_zval(return_value
, &zsym
);
870 static ZEND_METHOD(ion_Reader_Reader
, countAnnotations
)
872 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
875 ZEND_PARSE_PARAMETERS_NONE();
878 ION_CHECK(ion_reader_get_annotation_count(obj
->reader
, &sz
));
881 static ZEND_METHOD(ion_Reader_Reader
, getAnnotation
)
883 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
887 ZEND_PARSE_PARAMETERS_START(1, 1)
889 ZEND_PARSE_PARAMETERS_END();
892 ION_CHECK(ion_reader_get_an_annotation(obj
->reader
, idx
, &ann
));
893 RETURN_STRINGL((char *) ann
.value
, ann
.length
);
895 static ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbol
)
897 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
901 ZEND_PARSE_PARAMETERS_START(1, 1)
903 ZEND_PARSE_PARAMETERS_END();
906 ION_CHECK(ion_reader_get_an_annotation_symbol(obj
->reader
, idx
, &sym
));
907 php_ion_symbol_zval(&sym
, return_value
);
909 static ZEND_METHOD(ion_Reader_Reader
, readNull
)
911 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
914 ZEND_PARSE_PARAMETERS_NONE();
917 ION_CHECK(ion_reader_read_null(obj
->reader
, &typ
));
918 RETURN_OBJ_COPY(php_ion_type_fetch(typ
));
920 static ZEND_METHOD(ion_Reader_Reader
, readBool
)
922 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
925 ZEND_PARSE_PARAMETERS_NONE();
928 ION_CHECK(ion_reader_read_bool(obj
->reader
, &b
));
931 static ZEND_METHOD(ion_Reader_Reader
, readInt
)
933 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
936 ZEND_PARSE_PARAMETERS_NONE();
938 php_ion_reader_read_int(obj
->reader
, return_value
);
940 static ZEND_METHOD(ion_Reader_Reader
, readFloat
)
942 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
945 ZEND_PARSE_PARAMETERS_NONE();
947 ION_CHECK(ion_reader_read_double(obj
->reader
, &Z_DVAL_P(return_value
)));
949 static ZEND_METHOD(ion_Reader_Reader
, readDecimal
)
951 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
954 ZEND_PARSE_PARAMETERS_NONE();
956 object_init_ex(return_value
, ce_Decimal
);
957 php_ion_decimal
*dec
= php_ion_obj(decimal
, Z_OBJ_P(return_value
));
958 ION_CHECK(ion_reader_read_ion_decimal(obj
->reader
, &dec
->dec
));
959 php_ion_decimal_ctor(dec
);
961 static ZEND_METHOD(ion_Reader_Reader
, readTimestamp
)
963 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
966 ZEND_PARSE_PARAMETERS_NONE();
968 php_ion_reader_read_timestamp(obj
->reader
, obj
->opt
? &php_ion_obj(reader_options
, obj
->opt
)->opt
: NULL
, return_value
);
970 static ZEND_METHOD(ion_Reader_Reader
, readSymbol
)
972 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
975 ZEND_PARSE_PARAMETERS_NONE();
978 ION_CHECK(ion_reader_read_ion_symbol(obj
->reader
, &sym
));
979 php_ion_symbol_zval(&sym
, return_value
);
981 static ZEND_METHOD(ion_Reader_Reader
, readString
)
983 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
986 ZEND_PARSE_PARAMETERS_NONE();
989 ION_CHECK(ion_reader_read_string(obj
->reader
, &str
));
990 RETURN_STRINGL((char *) str
.value
, str
.length
);
993 typedef iERR (*read_part_fn
)(ION_READER
*, BYTE
*, SIZE
, SIZE
*);
994 static void read_part(INTERNAL_FUNCTION_PARAMETERS
, read_part_fn fn
)
996 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1001 zend_long len
= 0x1000;
1002 ZEND_PARSE_PARAMETERS_START(1, 1)
1006 ZEND_PARSE_PARAMETERS_END();
1010 if (Z_TYPE_P(ref
) == IS_STRING
&& Z_STRLEN_P(ref
) == len
) {
1012 zstr
= Z_STR_P(ref
);
1015 zstr
= zend_string_alloc(len
, 0);
1019 ION_CHECK(fn(obj
->reader
, (BYTE
*) zstr
->val
, zstr
->len
, &read
), goto fail
);
1021 if (read
< zstr
->len
) {
1022 zstr
= zend_string_truncate(zstr
, read
, 0);
1024 ZVAL_STR(ref
, zstr
);
1028 if (zstr
!= Z_STR_P(ref
)) {
1029 zend_string_release(zstr
);
1031 ZVAL_EMPTY_STRING(ref
);
1034 static ZEND_METHOD(ion_Reader_Reader
, readStringPart
)
1036 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_partial_string
);
1038 static ZEND_METHOD(ion_Reader_Reader
, readLob
)
1040 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1043 ZEND_PARSE_PARAMETERS_NONE();
1045 php_ion_reader_read_lob(obj
->reader
, return_value
);
1047 static ZEND_METHOD(ion_Reader_Reader
, readLobPart
)
1049 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_lob_partial_bytes
);
1051 static ZEND_METHOD(ion_Reader_Reader
, getPosition
)
1053 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1056 ZEND_PARSE_PARAMETERS_NONE();
1060 ION_CHECK(ion_reader_get_position(obj
->reader
, &bytes
, &dummy
, &dummy
));
1063 static ZEND_METHOD(ion_Reader_Reader
, getDepth
)
1065 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1068 ZEND_PARSE_PARAMETERS_NONE();
1071 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
1074 static ZEND_METHOD(ion_Reader_Reader
, seek
)
1076 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1079 zend_long off
, len
= -1;
1080 ZEND_PARSE_PARAMETERS_START(1, 2)
1084 ZEND_PARSE_PARAMETERS_END();
1086 ION_CHECK(ion_reader_seek(obj
->reader
, off
, len
));
1088 static ZEND_METHOD(ion_Reader_Reader
, getValueOffset
)
1090 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1093 ZEND_PARSE_PARAMETERS_NONE();
1096 ION_CHECK(ion_reader_get_value_offset(obj
->reader
, &off
));
1099 static ZEND_METHOD(ion_Reader_Reader
, getValueLength
)
1101 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1104 ZEND_PARSE_PARAMETERS_NONE();
1107 ION_CHECK(ion_reader_get_value_length(obj
->reader
, &len
));
1110 static ZEND_METHOD(ion_Reader_Buffer_Reader
, __construct
)
1112 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1116 ZEND_PARSE_PARAMETERS_START(1, 2)
1119 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1120 ZEND_PARSE_PARAMETERS_END();
1122 obj
->type
= BUFFER_READER
;
1123 obj
->buffer
= zend_string_copy(zstr
);
1125 php_ion_reader_ctor(obj
);
1127 static ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
1129 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1132 ZEND_PARSE_PARAMETERS_NONE();
1133 RETURN_STR_COPY(obj
->buffer
);
1136 static ZEND_METHOD(ion_Reader_Stream_Reader
, __construct
)
1138 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1142 ZEND_PARSE_PARAMETERS_START(1, 2)
1143 Z_PARAM_RESOURCE(zstream
)
1145 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1146 ZEND_PARSE_PARAMETERS_END();
1148 obj
->type
= STREAM_READER
;
1149 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1151 php_ion_reader_ctor(obj
);
1153 static ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
1155 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1158 ZEND_PARSE_PARAMETERS_NONE();
1159 PTR_CHECK(obj
->stream
.ptr
);
1161 GC_ADDREF(obj
->stream
.ptr
->res
);
1162 RETURN_RES(obj
->stream
.ptr
->res
);
1164 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
1166 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1170 ZEND_PARSE_PARAMETERS_START(1, 1);
1171 Z_PARAM_RESOURCE(zstream
);
1172 ZEND_PARSE_PARAMETERS_END();
1174 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
1176 if (obj
->stream
.ptr
) {
1177 zend_list_delete(obj
->stream
.ptr
->res
);
1179 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1180 PTR_CHECK(obj
->stream
.ptr
);
1181 Z_ADDREF_P(zstream
);
1183 static ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
1185 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
1190 ZEND_PARSE_PARAMETERS_START(1, 2);
1191 Z_PARAM_RESOURCE(zstream
);
1192 Z_PARAM_LONG(length
)
1193 ZEND_PARSE_PARAMETERS_END();
1195 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
1197 if (obj
->stream
.ptr
) {
1198 zend_list_delete(obj
->stream
.ptr
->res
);
1200 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1201 PTR_CHECK(obj
->stream
.ptr
);
1202 Z_ADDREF_P(zstream
);
1204 static ZEND_METHOD(ion_Writer_Options
, __construct
)
1206 php_ion_writer_options
*obj
= php_ion_obj(writer_options
, Z_OBJ_P(ZEND_THIS
));
1209 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
1210 tabs
= true, small_cntr_inl
= true, suppress_sys
= false, flush
= false;
1211 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x4000, alloc
= 0x10000;
1212 ZEND_PARSE_PARAMETERS_START(0, 16)
1214 //public readonly ?\ion\Catalog $catalog = null,
1215 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
1216 //public readonly ?\ion\Decimal\Context $decimalContext = null,
1217 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
1218 //public readonly bool $outputBinary = false,
1219 Z_PARAM_BOOL(binary
)
1220 //public readonly bool $compactFloats = false,
1221 Z_PARAM_BOOL(compact_floats
)
1222 //public readonly bool $escapeNonAscii = false,
1223 Z_PARAM_BOOL(escape
)
1224 //public readonly bool $prettyPrint = false,
1225 Z_PARAM_BOOL(pretty
)
1226 //public readonly bool $indentTabs = true,
1228 //public readonly int $indentSize = 2,
1229 Z_PARAM_LONG(indent
)
1230 //public readonly bool $smallContainersInline = true,
1231 Z_PARAM_BOOL(small_cntr_inl
)
1232 //public readonly bool $suppressSystemValues = false,
1233 Z_PARAM_BOOL(suppress_sys
)
1234 //public readonly bool $flushEveryValue = false,
1236 //public readonly int $maxContainerDepth = 10,
1237 Z_PARAM_LONG(max_depth
)
1238 //public readonly int $maxAnnotations = 10,
1239 Z_PARAM_LONG(max_ann
)
1240 //public readonly int $tempBufferSize = 0x4000,
1242 //public readonly int $allocationPageSize = 0x10000,
1244 ZEND_PARSE_PARAMETERS_END();
1247 update_property_obj(&obj
->std
, ZEND_STRL("catalog"), obj
->cat
);
1248 obj
->opt
.pcatalog
= php_ion_obj(catalog
, obj
->cat
)->cat
;
1251 update_property_obj(&obj
->std
, ZEND_STRL("decimalContext"), obj
->dec_ctx
);
1252 obj
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, obj
->dec_ctx
)->ctx
;
1254 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("outputBinary"),
1255 obj
->opt
.output_as_binary
= binary
);
1256 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("comactFloats"),
1257 obj
->opt
.compact_floats
= compact_floats
);
1258 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("excapeNonAscii"),
1259 obj
->opt
.escape_all_non_ascii
= escape
);
1260 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("prettyPrint"),
1261 obj
->opt
.pretty_print
= pretty
);
1262 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentTabs"),
1263 obj
->opt
.indent_with_tabs
= tabs
);
1264 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentSize"),
1265 obj
->opt
.indent_size
= indent
);
1266 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("smallContainersInline"),
1267 obj
->opt
.small_containers_in_line
= small_cntr_inl
);
1268 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("suppressSystemValues"),
1269 obj
->opt
.supress_system_values
= suppress_sys
);
1270 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("flushEveryValue"),
1271 obj
->opt
.flush_every_value
= flush
);
1272 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxContainerDepth"),
1273 obj
->opt
.max_container_depth
= max_depth
);
1274 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxAnnotations"),
1275 obj
->opt
.max_annotation_count
= max_ann
);
1276 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("tempBufferSize"),
1277 obj
->opt
.temp_buffer_size
= temp
);
1278 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("allocationPageSize"),
1279 obj
->opt
.allocation_page_size
= alloc
);
1281 static ZEND_METHOD(ion_Writer_Writer
, writeNull
)
1283 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1286 ZEND_PARSE_PARAMETERS_NONE();
1288 ION_CHECK(ion_writer_write_null(obj
->writer
));
1290 static ZEND_METHOD(ion_Writer_Writer
, writeTypedNull
)
1292 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1295 zend_object
*typ_obj
;
1296 ZEND_PARSE_PARAMETERS_START(1, 1)
1297 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1298 ZEND_PARSE_PARAMETERS_END();
1300 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1302 ION_CHECK(ion_writer_write_typed_null(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1304 static ZEND_METHOD(ion_Writer_Writer
, writeBool
)
1306 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1310 ZEND_PARSE_PARAMETERS_START(1, 1)
1312 ZEND_PARSE_PARAMETERS_END();
1314 ION_CHECK(ion_writer_write_bool(obj
->writer
, b
));
1316 static ZEND_METHOD(ion_Writer_Writer
, writeInt
)
1318 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1323 ZEND_PARSE_PARAMETERS_START(1, 1)
1324 Z_PARAM_STR_OR_LONG(s
, l
)
1325 ZEND_PARSE_PARAMETERS_END();
1329 ION_CHECK(ion_int_alloc(obj
->writer
, &i
));
1330 ION_CHECK(ion_int_from_chars(i
, s
->val
, s
->len
));
1331 ION_CHECK(ion_writer_write_ion_int(obj
->writer
, i
));
1334 ION_CHECK(ion_writer_write_int64(obj
->writer
, l
));
1337 static ZEND_METHOD(ion_Writer_Writer
, writeFloat
)
1339 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1343 ZEND_PARSE_PARAMETERS_START(1, 1)
1345 ZEND_PARSE_PARAMETERS_END();
1347 ION_CHECK(ion_writer_write_double(obj
->writer
, d
));
1349 static ZEND_METHOD(ion_Writer_Writer
, writeDecimal
)
1351 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1354 zend_object
*dec_obj
;
1355 zend_string
*dec_str
;
1356 ZEND_PARSE_PARAMETERS_START(1, 1)
1357 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj
, ce_Decimal
, dec_str
)
1358 ZEND_PARSE_PARAMETERS_END();
1362 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&s
, dec_str
)));
1364 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
1365 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
1368 static ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
1370 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1373 zend_object
*ts_obj
;
1374 zend_string
*ts_str
;
1375 ZEND_PARSE_PARAMETERS_START(1, 1)
1376 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
1377 ZEND_PARSE_PARAMETERS_END();
1379 decContext
*ctx
= NULL
;
1381 ctx
= php_ion_obj(reader_options
, obj
->opt
)->opt
.decimal_context
;
1384 ION_TIMESTAMP tmp
= {0};
1387 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1389 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1391 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1393 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1395 static ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1397 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1400 zend_object
*sym_obj
;
1401 zend_string
*sym_str
;
1402 ZEND_PARSE_PARAMETERS_START(1, 1)
1403 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1404 ZEND_PARSE_PARAMETERS_END();
1408 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1410 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1412 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1415 static ZEND_METHOD(ion_Writer_Writer
, writeString
)
1417 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1421 ZEND_PARSE_PARAMETERS_START(1, 1)
1423 ZEND_PARSE_PARAMETERS_END();
1426 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1428 static ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1430 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1434 ZEND_PARSE_PARAMETERS_START(1, 1)
1436 ZEND_PARSE_PARAMETERS_END();
1438 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1440 static ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1442 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1446 ZEND_PARSE_PARAMETERS_START(1, 1)
1448 ZEND_PARSE_PARAMETERS_END();
1450 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1452 static ZEND_METHOD(ion_Writer_Writer
, startLob
)
1454 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1457 zend_object
*typ_obj
;
1458 ZEND_PARSE_PARAMETERS_START(1, 1)
1459 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1460 ZEND_PARSE_PARAMETERS_END();
1462 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1464 ION_CHECK(ion_writer_start_lob(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1466 static ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1468 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1472 ZEND_PARSE_PARAMETERS_START(1, 1)
1474 ZEND_PARSE_PARAMETERS_END();
1476 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1478 static ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1480 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1483 ZEND_PARSE_PARAMETERS_NONE();
1485 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1487 static ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1489 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1492 zend_object
*typ_obj
;
1493 ZEND_PARSE_PARAMETERS_START(1, 1)
1494 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1495 ZEND_PARSE_PARAMETERS_END();
1497 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1499 ION_CHECK(ion_writer_start_container(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1501 static ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1503 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1506 ZEND_PARSE_PARAMETERS_NONE();
1508 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1510 static ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1512 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1515 zend_object
*sym_obj
;
1516 zend_string
*sym_str
;
1517 ZEND_PARSE_PARAMETERS_START(1, 1)
1518 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1519 ZEND_PARSE_PARAMETERS_END();
1523 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1525 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1527 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1530 static ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1532 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1537 ZEND_PARSE_PARAMETERS_START(1, -1)
1538 Z_PARAM_VARIADIC('+', args
, argc
);
1539 ZEND_PARSE_PARAMETERS_END();
1541 for (unsigned i
= 0; i
< argc
; ++i
) {
1542 switch (Z_TYPE(args
[i
])) {
1545 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1549 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1554 static ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1556 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1559 ZEND_PARSE_PARAMETERS_NONE();
1562 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1565 static ZEND_METHOD(ion_Writer_Writer
, flush
)
1567 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1570 ZEND_PARSE_PARAMETERS_NONE();
1573 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1574 if (obj
->type
== BUFFER_WRITER
) {
1575 smart_str_0(&obj
->buffer
.str
);
1577 RETURN_LONG(flushed
);
1579 static ZEND_METHOD(ion_Writer_Writer
, finish
)
1581 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1584 ZEND_PARSE_PARAMETERS_NONE();
1587 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1588 if (obj
->type
== BUFFER_WRITER
) {
1589 smart_str_0(&obj
->buffer
.str
);
1591 RETURN_LONG(flushed
);
1593 static ZEND_METHOD(ion_Writer_Writer
, writeOne
)
1596 static ZEND_METHOD(ion_Writer_Writer
, writeAll
)
1599 static ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1601 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1605 ZEND_PARSE_PARAMETERS_START(1, 2)
1608 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1609 ZEND_PARSE_PARAMETERS_END();
1611 obj
->type
= BUFFER_WRITER
;
1612 ZVAL_COPY(&obj
->buffer
.val
, ref
);
1613 zval_dtor(Z_REFVAL_P(ref
));
1615 php_ion_writer_ctor(obj
);
1617 static ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1619 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1622 ZEND_PARSE_PARAMETERS_NONE();
1624 RETVAL_STR(zend_string_dup(obj
->buffer
.str
.s
, 0));
1626 static ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1628 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1632 ZEND_PARSE_PARAMETERS_START(1, 2)
1633 Z_PARAM_RESOURCE(zstream
)
1635 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1636 ZEND_PARSE_PARAMETERS_END();
1638 obj
->type
= STREAM_WRITER
;
1639 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1641 php_ion_writer_ctor(obj
);
1643 static ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1645 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1648 ZEND_PARSE_PARAMETERS_NONE();
1649 PTR_CHECK(obj
->stream
.ptr
);
1651 GC_ADDREF(obj
->stream
.ptr
->res
);
1652 RETURN_RES(obj
->stream
.ptr
->res
);
1655 static ZEND_METHOD(ion_Serializer_PHP
, __construct
)
1657 php_ion_serializer_php
*obj
= php_ion_obj(serializer_php
, Z_OBJ_P(ZEND_THIS
));
1660 obj
->serializer
.call_magic
= true;
1662 ZEND_PARSE_PARAMETERS_START(0, 3)
1664 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1665 Z_PARAM_BOOL(obj
->serializer
.multi_seq
)
1666 Z_PARAM_BOOL(obj
->serializer
.call_magic
)
1667 Z_PARAM_STR_OR_NULL(obj
->serializer
.call_custom
)
1668 ZEND_PARSE_PARAMETERS_END();
1670 php_ion_serializer_php_ctor(obj
);
1672 static ZEND_METHOD(ion_Serializer_PHP
, __invoke
)
1674 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1677 ZEND_PARSE_PARAMETERS_START(1, 1)
1679 ZEND_PARSE_PARAMETERS_END();
1681 if (obj
->ce
== ce_Serializer_PHP
) {
1682 // default, fast path
1683 php_ion_serialize(&php_ion_obj(serializer_php
, obj
)->serializer
, data
, return_value
);
1685 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "serialize", return_value
, data
);
1688 static ZEND_FUNCTION(ion_serialize
)
1691 zend_object
*zo_ser
= NULL
;
1692 ZEND_PARSE_PARAMETERS_START(1, 2)
1695 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Serializer
)
1696 ZEND_PARSE_PARAMETERS_END();
1698 if (!zo_ser
|| zo_ser
->ce
== ce_Serializer_PHP
) {
1699 // default, fast path
1700 php_ion_serializer
*ser
= zo_ser
? &php_ion_obj(serializer_php
, zo_ser
)->serializer
: NULL
;
1701 php_ion_serialize(ser
, data
, return_value
);
1703 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1706 static ZEND_METHOD(ion_Serializer_PHP
, serialize
)
1708 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1711 ZEND_PARSE_PARAMETERS_START(1, 1)
1713 ZEND_PARSE_PARAMETERS_END();
1716 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1719 static ZEND_METHOD(ion_Unserializer_PHP
, __construct
)
1721 php_ion_unserializer_php
*obj
= php_ion_obj(unserializer_php
, Z_OBJ_P(ZEND_THIS
));
1724 obj
->unserializer
.call_magic
= true;
1726 ZEND_PARSE_PARAMETERS_START(0, 3)
1728 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1729 Z_PARAM_BOOL(obj
->unserializer
.multi_seq
)
1730 Z_PARAM_BOOL(obj
->unserializer
.call_magic
)
1731 Z_PARAM_STR_OR_NULL(obj
->unserializer
.call_custom
)
1732 ZEND_PARSE_PARAMETERS_END();
1734 php_ion_unserializer_php_ctor(obj
);
1736 static ZEND_METHOD(ion_Unserializer_PHP
, __invoke
)
1738 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1741 ZEND_PARSE_PARAMETERS_START(1, 1)
1743 ZEND_PARSE_PARAMETERS_END();
1745 if (obj
->ce
== ce_Unserializer_PHP
) {
1746 php_ion_unserialize(&php_ion_obj(unserializer_php
, obj
)->unserializer
, data
, return_value
);
1748 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "unserialize", return_value
, data
);
1751 static ZEND_FUNCTION(ion_unserialize
)
1754 zend_object
*zo_ser
= NULL
;
1755 ZEND_PARSE_PARAMETERS_START(1, 2)
1758 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Unserializer
)
1759 ZEND_PARSE_PARAMETERS_END();
1761 if (!zo_ser
|| zo_ser
->ce
== ce_Unserializer_PHP
) {
1762 // default, fast path
1763 php_ion_unserializer
*ser
= zo_ser
? &php_ion_obj(unserializer_php
, zo_ser
)->unserializer
: NULL
;
1764 php_ion_unserialize(ser
, data
, return_value
);
1766 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1769 static ZEND_METHOD(ion_Unserializer_PHP
, unserialize
)
1771 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1774 ZEND_PARSE_PARAMETERS_START(1, 1)
1776 ZEND_PARSE_PARAMETERS_END();
1779 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1782 PHP_RINIT_FUNCTION(ion
)
1784 #if defined(ZTS) && defined(COMPILE_DL_ION)
1785 ZEND_TSRMLS_CACHE_UPDATE();
1788 php_ion_globals_symbols_init();
1789 php_ion_globals_serializer_init();
1790 php_ion_globals_unserializer_init();
1794 PHP_RSHUTDOWN_FUNCTION(ion
)
1796 php_ion_globals_unserializer_dtor();
1797 php_ion_globals_serializer_dtor();
1798 php_ion_globals_symbols_dtor();
1802 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
1803 { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), default_value },
1804 #include "ion_arginfo.h"
1806 PHP_MINIT_FUNCTION(ion
)
1809 if (SUCCESS
!= g_sym_init()) {
1814 php_ion_register(catalog
, Catalog
, zend_ce_countable
);
1817 php_ion_register(decimal
, Decimal
);
1818 php_ion_register(decimal_ctx
, Decimal_Context
);
1819 ce_Decimal_Context_Rounding
= register_class_ion_Decimal_Context_Rounding();
1822 ce_LOB
= register_class_ion_LOB();
1825 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1826 php_ion_register(reader_options
, Reader_Options
);
1827 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1828 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1829 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1830 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1831 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1834 ce_Serializer
= register_class_ion_Serializer();
1835 php_ion_register(serializer_php
, Serializer_PHP
, ce_Serializer
);
1838 php_ion_register(symbol
, Symbol
);
1839 oh_Symbol
.compare
= php_ion_symbol_zval_compare
;
1840 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1841 php_ion_register(symbol_table
, Symbol_Table
);
1842 ce_Symbol_Table
->create_object
= NULL
;
1843 ce_Symbol_Table_Local
= register_class_ion_Symbol_Table_Local(ce_Symbol_Table
);
1844 ce_Symbol_Table_Local
->create_object
= create_ion_Symbol_Table
;
1845 ce_Symbol_Table_Shared
= register_class_ion_Symbol_Table_Shared(ce_Symbol_Table
);
1846 ce_Symbol_Table_Shared
->create_object
= create_ion_Symbol_Table
;
1847 ce_Symbol_Enum
= register_class_ion_Symbol_Enum();
1848 ce_Symbol_Table_System
= register_class_ion_Symbol_Table_System(ce_Symbol_Enum
);
1849 ce_Symbol_Table_PHP
= register_class_ion_Symbol_Table_PHP(ce_Symbol_Enum
);
1852 ce_Timestamp
= register_class_ion_Timestamp(php_date_get_date_ce());
1853 ce_Timestamp_Precision
= register_class_ion_Timestamp_Precision();
1856 php_ion_register(type
, Type
);
1859 ce_Writer
= register_class_ion_Writer();
1860 php_ion_register(writer_options
, Writer_Options
);
1861 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1862 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1863 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1864 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1865 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1868 ce_Unserializer
= register_class_ion_Unserializer();
1869 php_ion_register(unserializer_php
, Unserializer_PHP
, ce_Unserializer
);
1874 PHP_MSHUTDOWN_FUNCTION(ion
)
1876 if (g_sym_tab_php
) {
1877 ion_symbol_table_close(g_sym_tab_php
);
1879 zend_hash_destroy(&g_sym_hash
);
1883 PHP_MINFO_FUNCTION(ion
)
1885 php_info_print_table_start();
1886 php_info_print_table_header(2, "ion support", "enabled");
1887 php_info_print_table_end();
1890 PHP_GINIT_FUNCTION(ion
)
1892 memset(ion_globals
, 0, sizeof(*ion_globals
));
1894 php_ion_decimal_ctx_init_max(&ion_globals
->decimal
.ctx
, DEC_ROUND_HALF_EVEN
);
1895 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_max
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MAX
);
1896 php_ion_decimal_from_zend_long(&ion_globals
->decimal
.zend_min
, &ion_globals
->decimal
.ctx
, ZEND_LONG_MIN
);
1899 PHP_GSHUTDOWN_FUNCTION(ion
)
1903 static zend_module_dep ion_module_deps
[] = {
1904 ZEND_MOD_REQUIRED("date")
1905 ZEND_MOD_REQUIRED("spl")
1909 zend_module_entry ion_module_entry
= {
1910 STANDARD_MODULE_HEADER_EX
,
1913 "ion", /* Extension name */
1914 ext_functions
, /* zend_function_entry */
1915 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1916 PHP_MSHUTDOWN(ion
), /* PHP_MSHUTDOWN - Module shutdown */
1917 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1918 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1919 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1920 PHP_ION_VERSION
, /* Version */
1921 ZEND_MODULE_GLOBALS(ion
),
1922 PHP_GINIT(ion
), /* PHP_GINIT */
1923 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1925 STANDARD_MODULE_PROPERTIES_EX
1928 #ifdef COMPILE_DL_ION
1930 ZEND_TSRMLS_CACHE_DEFINE()
1932 ZEND_GET_MODULE(ion
)