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"
30 #define DECNUMDIGITS 34 /* DECQUAD_Pmax */
33 static decContext g_dec_ctx
;
34 static ION_DECIMAL g_ion_dec_zend_max
, g_ion_dec_zend_min
;
37 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
38 { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), default_value },
39 #include "ion_arginfo.h"
40 #include "ion_private.h"
42 ZEND_METHOD(ion_Symbol_ImportLocation
, __construct
)
44 php_ion_symbol_iloc
*obj
= php_ion_obj(symbol_iloc
, Z_OBJ_P(ZEND_THIS
));
48 ZEND_PARSE_PARAMETERS_START(2, 2)
49 Z_PARAM_STR(obj
->name
)
50 Z_PARAM_LONG(location
)
51 ZEND_PARSE_PARAMETERS_END();
53 obj
->loc
.location
= location
;
54 php_ion_symbol_iloc_ctor(obj
);
56 ZEND_METHOD(ion_Symbol
, __construct
)
58 php_ion_symbol
*obj
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
62 ZEND_PARSE_PARAMETERS_START(0, 3)
64 Z_PARAM_STR_OR_NULL(obj
->value
)
66 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->iloc
, ce_Symbol_ImportLocation
)
67 ZEND_PARSE_PARAMETERS_END();
70 php_ion_symbol_ctor(obj
);
72 ZEND_METHOD(ion_Symbol
, equals
)
74 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
77 zend_object
*other_obj
;
78 ZEND_PARSE_PARAMETERS_START(1, 1)
79 Z_PARAM_OBJ_OF_CLASS(other_obj
, ce_Symbol
)
80 ZEND_PARSE_PARAMETERS_END();
83 iERR err
= ion_symbol_is_equal(
85 &php_ion_obj(symbol
, other_obj
)->sym
, &eq
);
89 ZEND_METHOD(ion_Symbol
, __toString
)
91 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
94 ZEND_PARSE_PARAMETERS_NONE();
97 RETURN_EMPTY_STRING();
99 RETURN_STR_COPY(sym
->value
);
101 ZEND_METHOD(ion_Timestamp
, __construct
)
103 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
107 zend_object
*precision_obj
;
108 zend_string
*fmt
= NULL
, *dt
= NULL
;
110 ZEND_PARSE_PARAMETERS_START(1, 4)
111 Z_PARAM_OBJ_OF_CLASS_OR_LONG(precision_obj
, ce_Timestamp_Precision
, precision
)
113 Z_PARAM_STR_OR_NULL(fmt
)
114 Z_PARAM_STR_OR_NULL(dt
)
116 ZEND_PARSE_PARAMETERS_END();
119 precision
= Z_LVAL_P(zend_enum_fetch_case_value(precision_obj
));
121 php_ion_timestamp_ctor(obj
, precision
, fmt
, dt
, tz
);
123 ZEND_METHOD(ion_Timestamp
, __toString
)
125 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
128 ZEND_PARSE_PARAMETERS_NONE();
132 zend_call_method_with_1_params(&obj
->std
, obj
->std
.ce
, NULL
, "format", return_value
,
133 zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("format"), 0, &fmt
));
135 ZEND_METHOD(ion_Decimal_Context
, __construct
)
137 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(ZEND_THIS
));
141 zend_object
*o_round
= NULL
;
142 zend_long digits
, emax
, emin
, round
;
143 ZEND_PARSE_PARAMETERS_START(5, 5)
147 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
149 ZEND_PARSE_PARAMETERS_END();
152 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
154 php_ion_decimal_ctx_init(&obj
->ctx
, digits
, emax
, emin
, round
, clamp
);
155 php_ion_decimal_ctx_ctor(obj
, o_round
);
157 static inline void make_decimal_ctx(INTERNAL_FUNCTION_PARAMETERS
, int kind
)
159 ZEND_PARSE_PARAMETERS_NONE();
161 object_init_ex(return_value
, ce_Decimal_Context
);
162 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
163 decContextDefault(&obj
->ctx
, kind
);
164 php_ion_decimal_ctx_ctor(obj
, NULL
);
166 ZEND_METHOD(ion_Decimal_Context
, Dec32
)
168 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL32
);
170 ZEND_METHOD(ion_Decimal_Context
, Dec64
)
172 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL64
);
174 ZEND_METHOD(ion_Decimal_Context
, Dec128
)
176 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL128
);
178 ZEND_METHOD(ion_Decimal_Context
, DecMax
)
180 zend_object
*o_round
= NULL
;
181 zend_long round
= DEC_ROUND_HALF_EVEN
;
182 ZEND_PARSE_PARAMETERS_START(0, 1)
184 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
185 ZEND_PARSE_PARAMETERS_END();
188 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
190 object_init_ex(return_value
, ce_Decimal_Context
);
191 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
192 php_ion_decimal_ctx_init_max(&obj
->ctx
, round
);
193 php_ion_decimal_ctx_ctor(obj
, o_round
);
195 ZEND_METHOD(ion_Decimal
, __construct
)
197 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
202 ZEND_PARSE_PARAMETERS_START(1, 2)
203 Z_PARAM_STR_OR_LONG(zstr
, num
)
205 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->ctx
, ce_Decimal_Context
)
206 ZEND_PARSE_PARAMETERS_END();
212 object_init_ex(&zdc
, ce_Decimal_Context
);
213 obj
->ctx
= Z_OBJ(zdc
);
214 php_ion_decimal_ctx_ctor(php_ion_obj(decimal_ctx
, obj
->ctx
), NULL
);
217 decContext
*ctx
= &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
;
220 ION_CHECK(ion_decimal_from_string(&obj
->dec
, zstr
->val
, ctx
), OBJ_RELEASE(obj
->ctx
));
222 php_ion_decimal_from_zend_long(&obj
->dec
, ctx
, num
);
225 php_ion_decimal_ctor(obj
);
226 OBJ_RELEASE(obj
->ctx
);
228 ZEND_METHOD(ion_Decimal
, equals
)
230 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
233 zend_object
*dec_obj
;
234 ZEND_PARSE_PARAMETERS_START(1, 1)
235 Z_PARAM_OBJ_OF_CLASS(dec_obj
, ce_Decimal
)
236 ZEND_PARSE_PARAMETERS_END();
239 ION_CHECK(ion_decimal_equals(&obj
->dec
, &php_ion_obj(decimal
, dec_obj
)->dec
,
240 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &is
));
243 ZEND_METHOD(ion_Decimal
, __toString
)
245 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
248 ZEND_PARSE_PARAMETERS_NONE();
250 RETURN_STR(php_ion_decimal_to_string(&obj
->dec
));
252 ZEND_METHOD(ion_Decimal
, toInt
)
254 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
257 ZEND_PARSE_PARAMETERS_NONE();
260 php_ion_decimal_to_zend_long(&obj
->dec
, &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
, &l
);
263 ZEND_METHOD(ion_Decimal
, isInt
)
265 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
268 ZEND_PARSE_PARAMETERS_NONE();
270 RETURN_BOOL(ion_decimal_is_integer(&obj
->dec
));
272 ZEND_METHOD(ion_LOB
, __construct
)
275 zend_object
*type
= NULL
;
276 ZEND_PARSE_PARAMETERS_START(1, 2)
279 Z_PARAM_OBJ_OF_CLASS(type
, ce_Type
)
280 ZEND_PARSE_PARAMETERS_END();
283 type
= zend_enum_get_case_cstr(ce_Type
, "CLob");
285 update_property_obj(Z_OBJ_P(ZEND_THIS
), ZEND_STRL("type"), type
);
286 zend_update_property_str(Z_OBJCE_P(ZEND_THIS
), Z_OBJ_P(ZEND_THIS
), ZEND_STRL("value"), value
);
288 ZEND_METHOD(ion_Reader_Options
, __construct
)
290 php_ion_reader_options
*opt
= php_ion_obj(reader_options
, Z_OBJ_P(ZEND_THIS
));
291 zend_bool ret_sys_val
= false, skip_validation
= false;
292 zend_long ch_nl
= 0xa, max_depth
= 10, max_ann
, max_ann_buf
= 512,
293 sym_thr
= 0x1000, uval_thr
= 0x1000, chunk_thr
= 0x1000, alloc_pgsz
= 0x1000;
297 ZEND_PARSE_PARAMETERS_START(0, 13)
299 // public readonly ?\ion\Catalog $catalog = null,
300 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cat
, ce_Catalog
)
301 // public readonly ?\ion\Decimal\Context $decimalContext = null,
302 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->dec_ctx
, ce_Decimal_Context
)
303 // public readonly ?\Closure $onContextChange = null,
304 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cb
, zend_ce_closure
);
305 // public readonly bool $returnSystemValues = false,
306 Z_PARAM_BOOL(ret_sys_val
)
307 // public readonly int $newLine = 0xa,
309 // public readonly int $maxContainerDepth = 10,
310 Z_PARAM_LONG(max_depth
)
311 // public readonly int $maxAnnotations = 10,
312 Z_PARAM_LONG(max_ann
)
313 // public readonly int $maxAnnotationBuffered = 512,
314 Z_PARAM_LONG(max_ann_buf
)
315 // public readonly int $symbolThreshold = 4096,
316 Z_PARAM_LONG(sym_thr
)
317 // public readonly int $userValueThreshold = 4096,
318 Z_PARAM_LONG(uval_thr
)
319 // public readonly int $chunkThreshold = 4096,
320 Z_PARAM_LONG(chunk_thr
)
321 // public readonly int $allocationPageSize = 4096,
322 Z_PARAM_LONG(alloc_pgsz
)
323 // public readonly bool $skipCharacterValidation = false,
324 Z_PARAM_BOOL(skip_validation
)
325 ZEND_PARSE_PARAMETERS_END();
327 opt
->opt
.context_change_notifier
= EMPTY_READER_CHANGE_NOTIFIER
;
329 update_property_obj(&opt
->std
, ZEND_STRL("onContextChange"), opt
->cb
);
332 update_property_obj(&opt
->std
, ZEND_STRL("catalog"), opt
->cat
);
333 opt
->opt
.pcatalog
= php_ion_obj(catalog
, opt
->cat
)->cat
;
336 update_property_obj(&opt
->std
, ZEND_STRL("decimalContext"), opt
->dec_ctx
);
337 opt
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, opt
->dec_ctx
)->ctx
;
339 zend_update_property_bool(opt
->std
.ce
, &opt
->std
, ZEND_STRL("returnSystemValues"),
340 opt
->opt
.return_system_values
= ret_sys_val
);
341 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("newLine"),
342 opt
->opt
.new_line_char
= ch_nl
);
343 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxContainerDepth"),
344 opt
->opt
.max_container_depth
= max_depth
);
345 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationCount"),
346 opt
->opt
.max_annotation_count
= max_ann
);
347 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationBuffered"),
348 opt
->opt
.max_annotation_buffered
= max_ann_buf
);
349 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("symbolThreshold"),
350 opt
->opt
.symbol_threshold
= sym_thr
);
351 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("userValueThreshold"),
352 opt
->opt
.user_value_threshold
= uval_thr
);
353 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("chunkThreshold"),
354 opt
->opt
.chunk_threshold
= chunk_thr
);
355 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("allocationPageSize"),
356 opt
->opt
.allocation_page_size
= alloc_pgsz
);
357 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("skipCharacterValidation"),
358 opt
->opt
.skip_character_validation
= skip_validation
);
360 ZEND_METHOD(ion_Reader_Reader
, hasChildren
)
362 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
365 ZEND_PARSE_PARAMETERS_NONE();
368 ION_CHECK(ion_reader_get_type(obj
->reader
, &t
));
369 switch (ION_TYPE_INT(t
)) {
380 ZEND_METHOD(ion_Reader_Reader
, getChildren
)
382 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
385 ZEND_PARSE_PARAMETERS_NONE();
387 ION_CHECK(ion_reader_step_in(obj
->reader
));
389 RETURN_ZVAL(ZEND_THIS
, 1, 0);
391 ZEND_METHOD(ion_Reader_Reader
, rewind
)
393 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
396 ZEND_PARSE_PARAMETERS_NONE();
398 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
400 ZEND_METHOD(ion_Reader_Reader
, next
)
402 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
405 ZEND_PARSE_PARAMETERS_NONE();
407 if (obj
->state
== tid_EOF
) {
409 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
411 ION_CHECK(ion_reader_step_out(obj
->reader
));
414 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
416 ZEND_METHOD(ion_Reader_Reader
, valid
)
418 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
421 ZEND_PARSE_PARAMETERS_NONE();
422 RETURN_BOOL(obj
->state
!= tid_none
&& obj
->state
!= tid_EOF
);
424 ZEND_METHOD(ion_Reader_Reader
, key
)
426 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
429 ZEND_PARSE_PARAMETERS_NONE();
430 RETURN_IONTYPE(obj
->state
);
432 ZEND_METHOD(ion_Reader_Reader
, current
)
434 ZEND_PARSE_PARAMETERS_NONE();
435 RETURN_ZVAL(ZEND_THIS
, 1, 0);
437 ZEND_METHOD(ion_Reader_Reader
, getType
)
439 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
442 ZEND_PARSE_PARAMETERS_NONE();
445 ION_CHECK(ion_reader_get_type(obj
->reader
, &typ
));
448 ZEND_METHOD(ion_Reader_Reader
, hasAnnotations
)
450 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
453 ZEND_PARSE_PARAMETERS_NONE();
456 ION_CHECK(ion_reader_has_any_annotations(obj
->reader
, &has
));
459 ZEND_METHOD(ion_Reader_Reader
, hasAnnotation
)
461 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
464 zend_string
*ann_zstr
;
465 ZEND_PARSE_PARAMETERS_START(1, 1);
466 Z_PARAM_STR(ann_zstr
);
467 ZEND_PARSE_PARAMETERS_END();
471 ION_CHECK(ion_reader_has_annotation(obj
->reader
, ion_string_from_zend(&ann_istr
, ann_zstr
), &has
));
474 ZEND_METHOD(ion_Reader_Reader
, isNull
)
476 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
479 ZEND_PARSE_PARAMETERS_NONE();
482 ION_CHECK(ion_reader_is_null(obj
->reader
, &is
));
485 ZEND_METHOD(ion_Reader_Reader
, isInStruct
)
487 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
490 ZEND_PARSE_PARAMETERS_NONE();
493 ION_CHECK(ion_reader_is_in_struct(obj
->reader
, &is
));
496 ZEND_METHOD(ion_Reader_Reader
, getFieldName
)
498 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
501 ZEND_PARSE_PARAMETERS_NONE();
504 ION_CHECK(ion_reader_get_field_name(obj
->reader
, &name
));
505 RETURN_STRINGL((char *) name
.value
, name
.length
);
507 ZEND_METHOD(ion_Reader_Reader
, getFieldNameSymbol
)
509 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
512 ZEND_PARSE_PARAMETERS_NONE();
515 ION_CHECK(ion_reader_get_field_name_symbol(obj
->reader
, &sym_ptr
));
517 php_ion_symbol_zval(sym_ptr
, return_value
);
519 ZEND_METHOD(ion_Reader_Reader
, getAnnotations
)
521 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
524 ZEND_PARSE_PARAMETERS_NONE();
528 max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
532 ION_STRING
*ptr
= ecalloc(sizeof(*ptr
), max
);
533 iERR err
= ion_reader_get_annotations(obj
->reader
, ptr
, max
, &count
);
535 array_init_size(return_value
, count
);
536 for (int32_t i
= 0; i
< count
; ++i
) {
537 add_next_index_str(return_value
, zend_string_from_ion(&ptr
[i
]));
543 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbols
)
545 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
548 ZEND_PARSE_PARAMETERS_NONE();
550 int32_t count
, max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
551 ION_SYMBOL
*ptr
= ecalloc(sizeof(*ptr
), max
);
552 iERR err
= ion_reader_get_annotation_symbols(obj
->reader
, ptr
, max
, &count
);
554 array_init_size(return_value
, count
);
555 for (int32_t i
= 0; i
< count
; ++i
) {
557 php_ion_symbol_zval(&ptr
[i
], &zsym
);
558 add_next_index_zval(return_value
, &zsym
);
564 ZEND_METHOD(ion_Reader_Reader
, countAnnotations
)
566 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
569 ZEND_PARSE_PARAMETERS_NONE();
572 ION_CHECK(ion_reader_get_annotation_count(obj
->reader
, &sz
));
575 ZEND_METHOD(ion_Reader_Reader
, getAnnotation
)
577 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
581 ZEND_PARSE_PARAMETERS_START(1, 1)
583 ZEND_PARSE_PARAMETERS_END();
586 ION_CHECK(ion_reader_get_an_annotation(obj
->reader
, idx
, &ann
));
587 RETURN_STRINGL((char *) ann
.value
, ann
.length
);
589 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbol
)
591 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
595 ZEND_PARSE_PARAMETERS_START(1, 1)
597 ZEND_PARSE_PARAMETERS_END();
600 ION_CHECK(ion_reader_get_an_annotation_symbol(obj
->reader
, idx
, &sym
));
601 php_ion_symbol_zval(&sym
, return_value
);
603 ZEND_METHOD(ion_Reader_Reader
, readNull
)
605 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
608 ZEND_PARSE_PARAMETERS_NONE();
611 ION_CHECK(ion_reader_read_null(obj
->reader
, &typ
));
612 RETURN_OBJ_COPY(php_ion_type_fetch(typ
));
614 ZEND_METHOD(ion_Reader_Reader
, readBool
)
616 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
619 ZEND_PARSE_PARAMETERS_NONE();
622 ION_CHECK(ion_reader_read_bool(obj
->reader
, &b
));
625 ZEND_METHOD(ion_Reader_Reader
, readInt
)
627 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
630 ZEND_PARSE_PARAMETERS_NONE();
632 php_ion_reader_read_int(obj
->reader
, return_value
);
634 ZEND_METHOD(ion_Reader_Reader
, readFloat
)
636 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
639 ZEND_PARSE_PARAMETERS_NONE();
641 ION_CHECK(ion_reader_read_double(obj
->reader
, &Z_DVAL_P(return_value
)));
643 ZEND_METHOD(ion_Reader_Reader
, readDecimal
)
645 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
648 ZEND_PARSE_PARAMETERS_NONE();
650 object_init_ex(return_value
, ce_Decimal
);
651 php_ion_decimal
*dec
= php_ion_obj(decimal
, Z_OBJ_P(return_value
));
652 ION_CHECK(ion_reader_read_ion_decimal(obj
->reader
, &dec
->dec
));
653 php_ion_decimal_ctor(dec
);
655 ZEND_METHOD(ion_Reader_Reader
, readTimestamp
)
657 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
660 ZEND_PARSE_PARAMETERS_NONE();
662 php_ion_reader_read_timestamp(obj
->reader
, obj
->opt
? &php_ion_obj(reader_options
, obj
->opt
)->opt
: NULL
, return_value
);
664 ZEND_METHOD(ion_Reader_Reader
, readSymbol
)
666 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
669 ZEND_PARSE_PARAMETERS_NONE();
672 ION_CHECK(ion_reader_read_ion_symbol(obj
->reader
, &sym
));
673 php_ion_symbol_zval(&sym
, return_value
);
675 ZEND_METHOD(ion_Reader_Reader
, readString
)
677 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
680 ZEND_PARSE_PARAMETERS_NONE();
683 ION_CHECK(ion_reader_read_string(obj
->reader
, &str
));
684 RETURN_STRINGL((char *) str
.value
, str
.length
);
687 typedef iERR (*read_part_fn
)(ION_READER
*, BYTE
*, SIZE
, SIZE
*);
688 static void read_part(INTERNAL_FUNCTION_PARAMETERS
, read_part_fn fn
)
690 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
695 zend_long len
= 0x1000;
696 ZEND_PARSE_PARAMETERS_START(1, 1)
700 ZEND_PARSE_PARAMETERS_END();
704 if (Z_TYPE_P(ref
) == IS_STRING
&& Z_STRLEN_P(ref
) == len
) {
709 zstr
= zend_string_alloc(len
, 0);
713 ION_CHECK(fn(obj
->reader
, (BYTE
*) zstr
->val
, zstr
->len
, &read
), goto fail
);
715 if (read
< zstr
->len
) {
716 zstr
= zend_string_truncate(zstr
, read
, 0);
722 if (zstr
!= Z_STR_P(ref
)) {
723 zend_string_release(zstr
);
725 ZVAL_EMPTY_STRING(ref
);
728 ZEND_METHOD(ion_Reader_Reader
, readStringPart
)
730 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_partial_string
);
732 ZEND_METHOD(ion_Reader_Reader
, readLob
)
734 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
737 ZEND_PARSE_PARAMETERS_NONE();
739 php_ion_reader_read_lob(obj
->reader
, return_value
);
741 ZEND_METHOD(ion_Reader_Reader
, readLobPart
)
743 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_lob_partial_bytes
);
745 ZEND_METHOD(ion_Reader_Reader
, getPosition
)
747 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
750 ZEND_PARSE_PARAMETERS_NONE();
754 ION_CHECK(ion_reader_get_position(obj
->reader
, &bytes
, &dummy
, &dummy
));
757 ZEND_METHOD(ion_Reader_Reader
, getDepth
)
759 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
762 ZEND_PARSE_PARAMETERS_NONE();
765 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
768 ZEND_METHOD(ion_Reader_Reader
, seek
)
770 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
773 zend_long off
, len
= -1;
774 ZEND_PARSE_PARAMETERS_START(1, 2)
778 ZEND_PARSE_PARAMETERS_END();
780 ION_CHECK(ion_reader_seek(obj
->reader
, off
, len
));
782 ZEND_METHOD(ion_Reader_Reader
, getValueOffset
)
784 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
787 ZEND_PARSE_PARAMETERS_NONE();
790 ION_CHECK(ion_reader_get_value_offset(obj
->reader
, &off
));
793 ZEND_METHOD(ion_Reader_Reader
, getValueLength
)
795 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
798 ZEND_PARSE_PARAMETERS_NONE();
801 ION_CHECK(ion_reader_get_value_length(obj
->reader
, &len
));
804 ZEND_METHOD(ion_Reader_Buffer_Reader
, __construct
)
806 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
810 ZEND_PARSE_PARAMETERS_START(1, 2)
813 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
814 ZEND_PARSE_PARAMETERS_END();
816 obj
->type
= BUFFER_READER
;
817 obj
->buffer
= zend_string_copy(zstr
);
819 php_ion_reader_ctor(obj
);
821 ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
823 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
826 ZEND_PARSE_PARAMETERS_NONE();
827 RETURN_STR_COPY(obj
->buffer
);
830 ZEND_METHOD(ion_Reader_Stream_Reader
, __construct
)
832 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
836 ZEND_PARSE_PARAMETERS_START(1, 2)
837 Z_PARAM_RESOURCE(zstream
)
839 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
840 ZEND_PARSE_PARAMETERS_END();
842 obj
->type
= STREAM_READER
;
843 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
845 php_ion_reader_ctor(obj
);
847 ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
849 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
852 ZEND_PARSE_PARAMETERS_NONE();
853 PTR_CHECK(obj
->stream
.ptr
);
855 GC_ADDREF(obj
->stream
.ptr
->res
);
856 RETURN_RES(obj
->stream
.ptr
->res
);
858 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
860 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
864 ZEND_PARSE_PARAMETERS_START(1, 1);
865 Z_PARAM_RESOURCE(zstream
);
866 ZEND_PARSE_PARAMETERS_END();
868 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
870 if (obj
->stream
.ptr
) {
871 zend_list_delete(obj
->stream
.ptr
->res
);
873 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
874 PTR_CHECK(obj
->stream
.ptr
);
877 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
879 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
884 ZEND_PARSE_PARAMETERS_START(1, 2);
885 Z_PARAM_RESOURCE(zstream
);
887 ZEND_PARSE_PARAMETERS_END();
889 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
891 if (obj
->stream
.ptr
) {
892 zend_list_delete(obj
->stream
.ptr
->res
);
894 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
895 PTR_CHECK(obj
->stream
.ptr
);
898 ZEND_METHOD(ion_Writer_Options
, __construct
)
900 php_ion_writer_options
*obj
= php_ion_obj(writer_options
, Z_OBJ_P(ZEND_THIS
));
903 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
904 tabs
= true, small_cntr_inl
= true, suppress_sys
= false, flush
= false;
905 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x400, alloc
= 0x1000;
906 ZEND_PARSE_PARAMETERS_START(0, 16)
908 //public readonly ?\ion\Catalog $catalog = null,
909 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
910 //public readonly ?\ion\Collection $encodingSymbolTable = null,
911 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->col
, ce_Collection
)
912 //public readonly ?\ion\Decimal\Context $decimalContext = null,
913 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
914 //public readonly bool $outputBinary = false,
916 //public readonly bool $compactFloats = false,
917 Z_PARAM_BOOL(compact_floats
)
918 //public readonly bool $escapeNonAscii = false,
920 //public readonly bool $prettyPrint = false,
922 //public readonly bool $indentTabs = true,
924 //public readonly int $indentSize = 2,
926 //public readonly bool $smallContainersInline = true,
927 Z_PARAM_BOOL(small_cntr_inl
)
928 //public readonly bool $suppressSystemValues = false,
929 Z_PARAM_BOOL(suppress_sys
)
930 //public readonly bool $flushEveryValue = false,
932 //public readonly int $maxContainerDepth = 10,
933 Z_PARAM_LONG(max_depth
)
934 //public readonly int $maxAnnotations = 10,
935 Z_PARAM_LONG(max_ann
)
936 //public readonly int $tempBufferSize = 0x400,
938 //public readonly int $allocationPageSize = 0x1000,
940 ZEND_PARSE_PARAMETERS_END();
943 update_property_obj(&obj
->std
, ZEND_STRL("catalog"), obj
->cat
);
944 obj
->opt
.pcatalog
= php_ion_obj(catalog
, obj
->cat
)->cat
;
950 update_property_obj(&obj
->std
, ZEND_STRL("decimalContext"), obj
->dec_ctx
);
951 obj
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, obj
->dec_ctx
)->ctx
;
953 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("outputBinary"),
954 obj
->opt
.output_as_binary
= binary
);
955 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("comactFloats"),
956 obj
->opt
.compact_floats
= compact_floats
);
957 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("excapeNonAscii"),
958 obj
->opt
.escape_all_non_ascii
= escape
);
959 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("prettyPrint"),
960 obj
->opt
.pretty_print
= pretty
);
961 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentTabs"),
962 obj
->opt
.indent_with_tabs
= tabs
);
963 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentSize"),
964 obj
->opt
.indent_size
= indent
);
965 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("smallContainersInline"),
966 obj
->opt
.small_containers_in_line
= small_cntr_inl
);
967 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("suppressSystemValues"),
968 obj
->opt
.supress_system_values
= suppress_sys
);
969 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("flushEveryValue"),
970 obj
->opt
.flush_every_value
= flush
);
971 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxContainerDepth"),
972 obj
->opt
.max_container_depth
= max_depth
);
973 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxAnnotations"),
974 obj
->opt
.max_annotation_count
= max_ann
);
975 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("tempBufferSize"),
976 obj
->opt
.temp_buffer_size
= temp
);
977 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("allocationPageSize"),
978 obj
->opt
.allocation_page_size
= alloc
);
980 ZEND_METHOD(ion_Writer_Writer
, writeNull
)
982 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
985 ZEND_PARSE_PARAMETERS_NONE();
987 ION_CHECK(ion_writer_write_null(obj
->writer
));
989 ZEND_METHOD(ion_Writer_Writer
, writeTypedNull
)
991 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
994 zend_object
*typ_obj
;
995 ZEND_PARSE_PARAMETERS_START(1, 1)
996 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
997 ZEND_PARSE_PARAMETERS_END();
999 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1001 ION_CHECK(ion_writer_write_typed_null(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1003 ZEND_METHOD(ion_Writer_Writer
, writeBool
)
1005 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1009 ZEND_PARSE_PARAMETERS_START(1, 1)
1011 ZEND_PARSE_PARAMETERS_END();
1013 ION_CHECK(ion_writer_write_bool(obj
->writer
, b
));
1015 ZEND_METHOD(ion_Writer_Writer
, writeInt
)
1017 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1022 ZEND_PARSE_PARAMETERS_START(1, 1)
1023 Z_PARAM_STR_OR_LONG(s
, l
)
1024 ZEND_PARSE_PARAMETERS_END();
1028 ION_CHECK(ion_int_alloc(obj
->writer
, &i
));
1029 ION_CHECK(ion_int_from_chars(i
, s
->val
, s
->len
));
1030 ION_CHECK(ion_writer_write_ion_int(obj
->writer
, i
));
1033 ION_CHECK(ion_writer_write_int64(obj
->writer
, l
));
1036 ZEND_METHOD(ion_Writer_Writer
, writeFloat
)
1038 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1042 ZEND_PARSE_PARAMETERS_START(1, 1)
1044 ZEND_PARSE_PARAMETERS_END();
1046 ION_CHECK(ion_writer_write_double(obj
->writer
, d
));
1048 ZEND_METHOD(ion_Writer_Writer
, writeDecimal
)
1050 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1053 zend_object
*dec_obj
;
1054 zend_string
*dec_str
;
1055 ZEND_PARSE_PARAMETERS_START(1, 1)
1056 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj
, ce_Decimal
, dec_str
)
1057 ZEND_PARSE_PARAMETERS_END();
1061 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&s
, dec_str
)));
1063 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
1064 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
1067 ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
1069 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1072 zend_object
*ts_obj
;
1073 zend_string
*ts_str
;
1074 ZEND_PARSE_PARAMETERS_START(1, 1)
1075 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
1076 ZEND_PARSE_PARAMETERS_END();
1078 decContext
*ctx
= NULL
;
1080 ctx
= php_ion_obj(reader_options
, obj
->opt
)->opt
.decimal_context
;
1083 ION_TIMESTAMP tmp
= {0};
1086 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1088 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1090 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1092 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1094 ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1096 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1099 zend_object
*sym_obj
;
1100 zend_string
*sym_str
;
1101 ZEND_PARSE_PARAMETERS_START(1, 1)
1102 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1103 ZEND_PARSE_PARAMETERS_END();
1107 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1109 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1111 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1114 ZEND_METHOD(ion_Writer_Writer
, writeString
)
1116 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1120 ZEND_PARSE_PARAMETERS_START(1, 1)
1122 ZEND_PARSE_PARAMETERS_END();
1125 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1127 ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1129 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1133 ZEND_PARSE_PARAMETERS_START(1, 1)
1135 ZEND_PARSE_PARAMETERS_END();
1137 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1139 ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1141 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1145 ZEND_PARSE_PARAMETERS_START(1, 1)
1147 ZEND_PARSE_PARAMETERS_END();
1149 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1151 ZEND_METHOD(ion_Writer_Writer
, startLob
)
1153 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1156 zend_object
*typ_obj
;
1157 ZEND_PARSE_PARAMETERS_START(1, 1)
1158 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1159 ZEND_PARSE_PARAMETERS_END();
1161 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1163 ION_CHECK(ion_writer_start_lob(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1165 ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1167 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1171 ZEND_PARSE_PARAMETERS_START(1, 1)
1173 ZEND_PARSE_PARAMETERS_END();
1175 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1177 ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1179 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1182 ZEND_PARSE_PARAMETERS_NONE();
1184 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1186 ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1188 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1191 zend_object
*typ_obj
;
1192 ZEND_PARSE_PARAMETERS_START(1, 1)
1193 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1194 ZEND_PARSE_PARAMETERS_END();
1196 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1198 ION_CHECK(ion_writer_start_container(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1200 ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1202 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1205 ZEND_PARSE_PARAMETERS_NONE();
1207 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1209 ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1211 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1214 zend_object
*sym_obj
;
1215 zend_string
*sym_str
;
1216 ZEND_PARSE_PARAMETERS_START(1, 1)
1217 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1218 ZEND_PARSE_PARAMETERS_END();
1222 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1224 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1226 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1229 ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1231 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1236 ZEND_PARSE_PARAMETERS_START(1, -1)
1237 Z_PARAM_VARIADIC('+', args
, argc
);
1238 ZEND_PARSE_PARAMETERS_END();
1240 for (unsigned i
= 0; i
< argc
; ++i
) {
1241 switch (Z_TYPE(args
[i
])) {
1244 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1248 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1253 ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1255 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1258 ZEND_PARSE_PARAMETERS_NONE();
1261 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1264 ZEND_METHOD(ion_Writer_Writer
, flush
)
1266 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1269 ZEND_PARSE_PARAMETERS_NONE();
1272 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1273 if (obj
->type
== BUFFER_WRITER
) {
1274 smart_str_0(&obj
->buffer
.str
);
1276 RETURN_LONG(flushed
);
1278 ZEND_METHOD(ion_Writer_Writer
, finish
)
1280 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1283 ZEND_PARSE_PARAMETERS_NONE();
1286 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1287 if (obj
->type
== BUFFER_WRITER
) {
1288 smart_str_0(&obj
->buffer
.str
);
1290 RETURN_LONG(flushed
);
1292 ZEND_METHOD(ion_Writer_Writer
, writeOne
)
1295 ZEND_METHOD(ion_Writer_Writer
, writeAll
)
1298 ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1300 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1304 ZEND_PARSE_PARAMETERS_START(1, 2)
1307 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1308 ZEND_PARSE_PARAMETERS_END();
1310 obj
->type
= BUFFER_WRITER
;
1311 ZVAL_COPY(&obj
->buffer
.val
, ref
);
1312 zval_dtor(Z_REFVAL_P(ref
));
1314 php_ion_writer_ctor(obj
);
1316 ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1318 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1321 ZEND_PARSE_PARAMETERS_NONE();
1323 RETVAL_STR(zend_string_dup(obj
->buffer
.str
.s
, 0));
1325 ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1327 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1331 ZEND_PARSE_PARAMETERS_START(1, 2)
1332 Z_PARAM_RESOURCE(zstream
)
1334 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1335 ZEND_PARSE_PARAMETERS_END();
1337 obj
->type
= STREAM_WRITER
;
1338 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1340 php_ion_writer_ctor(obj
);
1342 ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1344 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1347 ZEND_PARSE_PARAMETERS_NONE();
1348 PTR_CHECK(obj
->stream
.ptr
);
1350 GC_ADDREF(obj
->stream
.ptr
->res
);
1351 RETURN_RES(obj
->stream
.ptr
->res
);
1354 ZEND_METHOD(ion_Serializer_PHP
, __construct
)
1356 php_ion_serializer_php
*obj
= php_ion_obj(serializer_php
, Z_OBJ_P(ZEND_THIS
));
1359 obj
->serializer
.call_magic
= true;
1361 ZEND_PARSE_PARAMETERS_START(0, 3)
1363 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1364 Z_PARAM_BOOL(obj
->serializer
.multi_seq
)
1365 Z_PARAM_BOOL(obj
->serializer
.call_magic
)
1366 Z_PARAM_STR_OR_NULL(obj
->serializer
.call_custom
)
1367 ZEND_PARSE_PARAMETERS_END();
1369 php_ion_serializer_php_ctor(obj
);
1371 ZEND_METHOD(ion_Serializer_PHP
, __invoke
)
1373 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1376 ZEND_PARSE_PARAMETERS_START(1, 1)
1378 ZEND_PARSE_PARAMETERS_END();
1380 if (obj
->ce
== ce_Serializer_PHP
) {
1381 // default, fast path
1382 php_ion_serialize(&php_ion_obj(serializer_php
, obj
)->serializer
, data
, return_value
);
1384 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "serialize", return_value
, data
);
1387 ZEND_FUNCTION(ion_serialize
)
1390 zend_object
*zo_ser
= NULL
;
1391 ZEND_PARSE_PARAMETERS_START(1, 2)
1394 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Serializer
)
1395 ZEND_PARSE_PARAMETERS_END();
1397 if (!zo_ser
|| zo_ser
->ce
== ce_Serializer_PHP
) {
1398 // default, fast path
1399 php_ion_serializer
*ser
= zo_ser
? &php_ion_obj(serializer_php
, zo_ser
)->serializer
: NULL
;
1400 php_ion_serialize(ser
, data
, return_value
);
1402 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1405 ZEND_METHOD(ion_Serializer_PHP
, serialize
)
1407 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1410 ZEND_PARSE_PARAMETERS_START(1, 1)
1412 ZEND_PARSE_PARAMETERS_END();
1415 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1418 ZEND_METHOD(ion_Unserializer_PHP
, __construct
)
1420 php_ion_unserializer_php
*obj
= php_ion_obj(unserializer_php
, Z_OBJ_P(ZEND_THIS
));
1423 obj
->unserializer
.call_magic
= true;
1425 ZEND_PARSE_PARAMETERS_START(0, 3)
1427 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1428 Z_PARAM_BOOL(obj
->unserializer
.multi_seq
)
1429 Z_PARAM_BOOL(obj
->unserializer
.call_magic
)
1430 Z_PARAM_STR_OR_NULL(obj
->unserializer
.call_custom
)
1431 ZEND_PARSE_PARAMETERS_END();
1433 php_ion_unserializer_php_ctor(obj
);
1435 ZEND_METHOD(ion_Unserializer_PHP
, __invoke
)
1437 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1440 ZEND_PARSE_PARAMETERS_START(1, 1)
1442 ZEND_PARSE_PARAMETERS_END();
1444 if (obj
->ce
== ce_Unserializer_PHP
) {
1445 php_ion_unserialize(&php_ion_obj(unserializer_php
, obj
)->unserializer
, data
, return_value
);
1447 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "unserialize", return_value
, data
);
1450 ZEND_FUNCTION(ion_unserialize
)
1453 zend_object
*zo_ser
= NULL
;
1454 ZEND_PARSE_PARAMETERS_START(1, 2)
1457 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Unserializer
)
1458 ZEND_PARSE_PARAMETERS_END();
1460 if (!zo_ser
|| zo_ser
->ce
== ce_Unserializer_PHP
) {
1461 // default, fast path
1462 php_ion_unserializer
*ser
= zo_ser
? &php_ion_obj(unserializer_php
, zo_ser
)->unserializer
: NULL
;
1463 php_ion_unserialize(ser
, data
, return_value
);
1465 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1468 ZEND_METHOD(ion_Unserializer_PHP
, unserialize
)
1470 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1473 ZEND_PARSE_PARAMETERS_START(1, 1)
1475 ZEND_PARSE_PARAMETERS_END();
1478 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1481 PHP_RINIT_FUNCTION(ion
)
1483 #if defined(ZTS) && defined(COMPILE_DL_ION)
1484 ZEND_TSRMLS_CACHE_UPDATE();
1487 php_ion_globals_serializer_init();
1488 php_ion_globals_unserializer_init();
1492 PHP_RSHUTDOWN_FUNCTION(ion
)
1494 php_ion_globals_serializer_dtor();
1495 php_ion_globals_unserializer_dtor();
1499 PHP_MINIT_FUNCTION(ion
)
1502 php_ion_decimal_ctx_init_max(&g_dec_ctx
, DEC_ROUND_HALF_EVEN
);
1503 php_ion_decimal_from_zend_long(&g_ion_dec_zend_max
, &g_dec_ctx
, ZEND_LONG_MAX
);
1504 php_ion_decimal_from_zend_long(&g_ion_dec_zend_min
, &g_dec_ctx
, ZEND_LONG_MIN
);
1507 ce_Annotation
= register_class_ion_Annotation();
1510 ce_Collection
= register_class_ion_Collection();
1513 php_ion_register(decimal
, Decimal
);
1514 php_ion_register(decimal_ctx
, Decimal_Context
);
1515 ce_Decimal_Context_Rounding
= register_class_ion_Decimal_Context_Rounding();
1518 ce_LOB
= register_class_ion_LOB();
1521 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1522 php_ion_register(reader_options
, Reader_Options
);
1523 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1524 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1525 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1526 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1527 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1530 ce_Serializer
= register_class_ion_Serializer();
1531 php_ion_register(serializer_php
, Serializer_PHP
, ce_Serializer
);
1534 php_ion_register(symbol
, Symbol
);
1535 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1536 php_ion_register(symbol_table
, Symbol_Table
);
1537 ce_Symbol_System
= register_class_ion_Symbol_System();
1538 ce_Symbol_System_SID
= register_class_ion_Symbol_System_SID();
1541 php_ion_register(timestamp
, Timestamp
, php_date_get_date_ce());
1542 ce_Timestamp_Precision
= register_class_ion_Timestamp_Precision();
1543 php_ion_register(catalog
, Catalog
);
1546 php_ion_register(type
, Type
);
1549 ce_Writer
= register_class_ion_Writer();
1550 php_ion_register(writer_options
, Writer_Options
);
1551 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1552 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1553 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1554 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1555 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1558 ce_Unserializer
= register_class_ion_Unserializer();
1559 php_ion_register(unserializer_php
, Unserializer_PHP
, ce_Unserializer
);
1564 PHP_MSHUTDOWN_FUNCTION(ion
)
1568 PHP_MINFO_FUNCTION(ion
)
1570 php_info_print_table_start();
1571 php_info_print_table_header(2, "ion support", "enabled");
1572 php_info_print_table_end();
1575 PHP_GINIT_FUNCTION(ion
)
1577 memset(ion_globals
, 0, sizeof(*ion_globals
));
1579 PHP_GSHUTDOWN_FUNCTION(ion
)
1583 static zend_module_dep ion_module_deps
[] = {
1584 ZEND_MOD_REQUIRED("spl")
1588 zend_module_entry ion_module_entry
= {
1589 STANDARD_MODULE_HEADER_EX
,
1592 "ion", /* Extension name */
1593 ext_functions
, /* zend_function_entry */
1594 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1595 PHP_MSHUTDOWN(ion
), /* PHP_MSHUTDOWN - Module shutdown */
1596 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1597 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1598 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1599 PHP_ION_VERSION
, /* Version */
1600 ZEND_MODULE_GLOBALS(ion
),
1601 PHP_GINIT(ion
), /* PHP_GINIT */
1602 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1604 STANDARD_MODULE_PROPERTIES_EX
1607 #ifdef COMPILE_DL_ION
1609 ZEND_TSRMLS_CACHE_DEFINE()
1611 ZEND_GET_MODULE(ion
)