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_INT
*g_ion_int_zend_max
, *g_ion_int_zend_min
;
35 static ION_DECIMAL g_ion_dec_zend_max
, g_ion_dec_zend_min
;
38 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
39 { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), default_value },
40 #include "ion_arginfo.h"
41 #include "ion_private.h"
43 ZEND_METHOD(ion_Symbol_ImportLocation
, __construct
)
45 php_ion_symbol_iloc
*obj
= php_ion_obj(symbol_iloc
, Z_OBJ_P(ZEND_THIS
));
49 ZEND_PARSE_PARAMETERS_START(2, 2)
50 Z_PARAM_STR(obj
->name
)
51 Z_PARAM_LONG(location
)
52 ZEND_PARSE_PARAMETERS_END();
54 obj
->loc
.location
= location
;
55 php_ion_symbol_iloc_ctor(obj
);
57 ZEND_METHOD(ion_Symbol
, __construct
)
59 php_ion_symbol
*obj
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
63 ZEND_PARSE_PARAMETERS_START(0, 3)
65 Z_PARAM_STR_OR_NULL(obj
->value
)
67 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->iloc
, ce_Symbol_ImportLocation
)
68 ZEND_PARSE_PARAMETERS_END();
71 php_ion_symbol_ctor(obj
);
73 ZEND_METHOD(ion_Symbol
, equals
)
75 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
78 zend_object
*other_obj
;
79 ZEND_PARSE_PARAMETERS_START(1, 1)
80 Z_PARAM_OBJ_OF_CLASS(other_obj
, ce_Symbol
)
81 ZEND_PARSE_PARAMETERS_END();
84 iERR err
= ion_symbol_is_equal(
86 &php_ion_obj(symbol
, other_obj
)->sym
, &eq
);
90 ZEND_METHOD(ion_Symbol
, __toString
)
92 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
95 ZEND_PARSE_PARAMETERS_NONE();
98 RETURN_EMPTY_STRING();
100 RETURN_STR_COPY(sym
->value
);
102 ZEND_METHOD(ion_Timestamp
, __construct
)
104 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
108 zend_object
*precision_obj
;
109 zend_string
*fmt
= NULL
, *dt
= NULL
;
111 ZEND_PARSE_PARAMETERS_START(1, 4)
112 Z_PARAM_OBJ_OF_CLASS_OR_LONG(precision_obj
, ce_Timestamp_Precision
, precision
)
114 Z_PARAM_STR_OR_NULL(fmt
)
115 Z_PARAM_STR_OR_NULL(dt
)
117 ZEND_PARSE_PARAMETERS_END();
120 precision
= Z_LVAL_P(zend_enum_fetch_case_value(precision_obj
));
122 php_ion_timestamp_ctor(obj
, precision
, fmt
, dt
, tz
);
124 ZEND_METHOD(ion_Timestamp
, __toString
)
126 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
129 ZEND_PARSE_PARAMETERS_NONE();
133 zend_call_method_with_1_params(&obj
->std
, obj
->std
.ce
, NULL
, "format", return_value
,
134 zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("format"), 0, &fmt
));
136 ZEND_METHOD(ion_Decimal_Context
, __construct
)
138 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(ZEND_THIS
));
142 zend_object
*o_round
= NULL
;
143 zend_long digits
, emax
, emin
, round
;
144 ZEND_PARSE_PARAMETERS_START(5, 5)
148 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
150 ZEND_PARSE_PARAMETERS_END();
153 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
155 php_ion_decimal_ctx_init(&obj
->ctx
, digits
, emax
, emin
, round
, clamp
);
156 php_ion_decimal_ctx_ctor(obj
, o_round
);
158 static inline void make_decimal_ctx(INTERNAL_FUNCTION_PARAMETERS
, int kind
)
160 ZEND_PARSE_PARAMETERS_NONE();
162 object_init_ex(return_value
, ce_Decimal_Context
);
163 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
164 decContextDefault(&obj
->ctx
, kind
);
165 php_ion_decimal_ctx_ctor(obj
, NULL
);
167 ZEND_METHOD(ion_Decimal_Context
, Dec32
)
169 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL32
);
171 ZEND_METHOD(ion_Decimal_Context
, Dec64
)
173 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL64
);
175 ZEND_METHOD(ion_Decimal_Context
, Dec128
)
177 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU
, DEC_INIT_DECIMAL128
);
179 ZEND_METHOD(ion_Decimal_Context
, DecMax
)
181 zend_object
*o_round
= NULL
;
182 zend_long round
= DEC_ROUND_HALF_EVEN
;
183 ZEND_PARSE_PARAMETERS_START(0, 1)
185 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round
, ce_Decimal_Context_Rounding
, round
)
186 ZEND_PARSE_PARAMETERS_END();
189 round
= Z_LVAL_P(zend_enum_fetch_case_value(o_round
));
191 object_init_ex(return_value
, ce_Decimal_Context
);
192 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(return_value
));
193 php_ion_decimal_ctx_init_max(&obj
->ctx
, round
);
194 php_ion_decimal_ctx_ctor(obj
, o_round
);
196 ZEND_METHOD(ion_Decimal
, __construct
)
198 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
203 ZEND_PARSE_PARAMETERS_START(1, 2)
204 Z_PARAM_STR_OR_LONG(zstr
, num
)
206 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->ctx
, ce_Decimal_Context
)
207 ZEND_PARSE_PARAMETERS_END();
213 object_init_ex(&zdc
, ce_Decimal_Context
);
214 obj
->ctx
= Z_OBJ(zdc
);
215 php_ion_decimal_ctx_ctor(php_ion_obj(decimal_ctx
, obj
->ctx
), NULL
);
218 decContext
*ctx
= &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
;
221 ION_CHECK(ion_decimal_from_string(&obj
->dec
, zstr
->val
, ctx
), OBJ_RELEASE(obj
->ctx
));
223 php_ion_decimal_from_zend_long(&obj
->dec
, ctx
, num
);
226 php_ion_decimal_ctor(obj
);
227 OBJ_RELEASE(obj
->ctx
);
229 ZEND_METHOD(ion_Decimal
, equals
)
231 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
234 zend_object
*dec_obj
;
235 ZEND_PARSE_PARAMETERS_START(1, 1)
236 Z_PARAM_OBJ_OF_CLASS(dec_obj
, ce_Decimal
)
237 ZEND_PARSE_PARAMETERS_END();
240 ION_CHECK(ion_decimal_equals(&obj
->dec
, &php_ion_obj(decimal
, dec_obj
)->dec
,
241 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &is
));
244 ZEND_METHOD(ion_Decimal
, __toString
)
246 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
249 ZEND_PARSE_PARAMETERS_NONE();
251 RETURN_STR(php_ion_decimal_to_string(&obj
->dec
));
253 ZEND_METHOD(ion_Decimal
, toInt
)
255 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
258 ZEND_PARSE_PARAMETERS_NONE();
261 php_ion_decimal_to_zend_long(&obj
->dec
, &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
, &l
);
264 ZEND_METHOD(ion_Decimal
, isInt
)
266 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
269 ZEND_PARSE_PARAMETERS_NONE();
271 RETURN_BOOL(ion_decimal_is_integer(&obj
->dec
));
273 ZEND_METHOD(ion_LOB
, __construct
)
276 zend_object
*type
= NULL
;
277 ZEND_PARSE_PARAMETERS_START(1, 2)
280 Z_PARAM_OBJ_OF_CLASS(type
, ce_Type
)
281 ZEND_PARSE_PARAMETERS_END();
284 type
= zend_enum_get_case_cstr(ce_Type
, "CLob");
286 update_property_obj(Z_OBJ_P(ZEND_THIS
), ZEND_STRL("type"), type
);
287 zend_update_property_str(Z_OBJCE_P(ZEND_THIS
), Z_OBJ_P(ZEND_THIS
), ZEND_STRL("value"), value
);
289 ZEND_METHOD(ion_Reader_Options
, __construct
)
291 php_ion_reader_options
*opt
= php_ion_obj(reader_options
, Z_OBJ_P(ZEND_THIS
));
292 zend_bool ret_sys_val
= false, skip_validation
= false;
293 zend_long ch_nl
= 0xa, max_depth
= 10, max_ann
, max_ann_buf
= 512,
294 sym_thr
= 0x1000, uval_thr
= 0x1000, chunk_thr
= 0x1000, alloc_pgsz
= 0x1000;
298 ZEND_PARSE_PARAMETERS_START(0, 13)
300 // public readonly ?\ion\Catalog $catalog = null,
301 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cat
, ce_Catalog
)
302 // public readonly ?\ion\Decimal\Context $decimalContext = null,
303 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->dec_ctx
, ce_Decimal_Context
)
304 // public readonly ?\Closure $onContextChange = null,
305 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cb
, zend_ce_closure
);
306 // public readonly bool $returnSystemValues = false,
307 Z_PARAM_BOOL(ret_sys_val
)
308 // public readonly int $newLine = 0xa,
310 // public readonly int $maxContainerDepth = 10,
311 Z_PARAM_LONG(max_depth
)
312 // public readonly int $maxAnnotations = 10,
313 Z_PARAM_LONG(max_ann
)
314 // public readonly int $maxAnnotationBuffered = 512,
315 Z_PARAM_LONG(max_ann_buf
)
316 // public readonly int $symbolThreshold = 4096,
317 Z_PARAM_LONG(sym_thr
)
318 // public readonly int $userValueThreshold = 4096,
319 Z_PARAM_LONG(uval_thr
)
320 // public readonly int $chunkThreshold = 4096,
321 Z_PARAM_LONG(chunk_thr
)
322 // public readonly int $allocationPageSize = 4096,
323 Z_PARAM_LONG(alloc_pgsz
)
324 // public readonly bool $skipCharacterValidation = false,
325 Z_PARAM_BOOL(skip_validation
)
326 ZEND_PARSE_PARAMETERS_END();
328 opt
->opt
.context_change_notifier
= EMPTY_READER_CHANGE_NOTIFIER
;
330 update_property_obj(&opt
->std
, ZEND_STRL("onContextChange"), opt
->cb
);
333 update_property_obj(&opt
->std
, ZEND_STRL("catalog"), opt
->cat
);
334 opt
->opt
.pcatalog
= php_ion_obj(catalog
, opt
->cat
)->cat
;
337 update_property_obj(&opt
->std
, ZEND_STRL("decimalContext"), opt
->dec_ctx
);
338 opt
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, opt
->dec_ctx
)->ctx
;
340 zend_update_property_bool(opt
->std
.ce
, &opt
->std
, ZEND_STRL("returnSystemValues"),
341 opt
->opt
.return_system_values
= ret_sys_val
);
342 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("newLine"),
343 opt
->opt
.new_line_char
= ch_nl
);
344 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxContainerDepth"),
345 opt
->opt
.max_container_depth
= max_depth
);
346 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationCount"),
347 opt
->opt
.max_annotation_count
= max_ann
);
348 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationBuffered"),
349 opt
->opt
.max_annotation_buffered
= max_ann_buf
);
350 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("symbolThreshold"),
351 opt
->opt
.symbol_threshold
= sym_thr
);
352 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("userValueThreshold"),
353 opt
->opt
.user_value_threshold
= uval_thr
);
354 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("chunkThreshold"),
355 opt
->opt
.chunk_threshold
= chunk_thr
);
356 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("allocationPageSize"),
357 opt
->opt
.allocation_page_size
= alloc_pgsz
);
358 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("skipCharacterValidation"),
359 opt
->opt
.skip_character_validation
= skip_validation
);
361 ZEND_METHOD(ion_Reader_Reader
, hasChildren
)
363 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
366 ZEND_PARSE_PARAMETERS_NONE();
369 ION_CHECK(ion_reader_get_type(obj
->reader
, &t
));
370 switch (ION_TYPE_INT(t
)) {
381 ZEND_METHOD(ion_Reader_Reader
, getChildren
)
383 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
386 ZEND_PARSE_PARAMETERS_NONE();
388 ION_CHECK(ion_reader_step_in(obj
->reader
));
390 RETURN_ZVAL(ZEND_THIS
, 1, 0);
392 ZEND_METHOD(ion_Reader_Reader
, rewind
)
394 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
397 ZEND_PARSE_PARAMETERS_NONE();
399 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
401 ZEND_METHOD(ion_Reader_Reader
, next
)
403 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
406 ZEND_PARSE_PARAMETERS_NONE();
408 if (obj
->state
== tid_EOF
) {
410 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
412 ION_CHECK(ion_reader_step_out(obj
->reader
));
415 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
417 ZEND_METHOD(ion_Reader_Reader
, valid
)
419 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
422 ZEND_PARSE_PARAMETERS_NONE();
423 RETURN_BOOL(obj
->state
!= tid_none
&& obj
->state
!= tid_EOF
);
425 ZEND_METHOD(ion_Reader_Reader
, key
)
427 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
430 ZEND_PARSE_PARAMETERS_NONE();
431 RETURN_IONTYPE(obj
->state
);
433 ZEND_METHOD(ion_Reader_Reader
, current
)
435 ZEND_PARSE_PARAMETERS_NONE();
436 RETURN_ZVAL(ZEND_THIS
, 1, 0);
438 ZEND_METHOD(ion_Reader_Reader
, getType
)
440 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
443 ZEND_PARSE_PARAMETERS_NONE();
446 ION_CHECK(ion_reader_get_type(obj
->reader
, &typ
));
449 ZEND_METHOD(ion_Reader_Reader
, hasAnnotations
)
451 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
454 ZEND_PARSE_PARAMETERS_NONE();
457 ION_CHECK(ion_reader_has_any_annotations(obj
->reader
, &has
));
460 ZEND_METHOD(ion_Reader_Reader
, hasAnnotation
)
462 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
465 zend_string
*ann_zstr
;
466 ZEND_PARSE_PARAMETERS_START(1, 1);
467 Z_PARAM_STR(ann_zstr
);
468 ZEND_PARSE_PARAMETERS_END();
472 ION_CHECK(ion_reader_has_annotation(obj
->reader
, ion_string_from_zend(&ann_istr
, ann_zstr
), &has
));
475 ZEND_METHOD(ion_Reader_Reader
, isNull
)
477 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
480 ZEND_PARSE_PARAMETERS_NONE();
483 ION_CHECK(ion_reader_is_null(obj
->reader
, &is
));
486 ZEND_METHOD(ion_Reader_Reader
, isInStruct
)
488 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
491 ZEND_PARSE_PARAMETERS_NONE();
494 ION_CHECK(ion_reader_is_in_struct(obj
->reader
, &is
));
497 ZEND_METHOD(ion_Reader_Reader
, getFieldName
)
499 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
502 ZEND_PARSE_PARAMETERS_NONE();
505 ION_CHECK(ion_reader_get_field_name(obj
->reader
, &name
));
506 RETURN_STRINGL((char *) name
.value
, name
.length
);
508 ZEND_METHOD(ion_Reader_Reader
, getFieldNameSymbol
)
510 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
513 ZEND_PARSE_PARAMETERS_NONE();
516 ION_CHECK(ion_reader_get_field_name_symbol(obj
->reader
, &sym_ptr
));
518 php_ion_symbol_zval(sym_ptr
, return_value
);
520 ZEND_METHOD(ion_Reader_Reader
, getAnnotations
)
522 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
525 ZEND_PARSE_PARAMETERS_NONE();
529 max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
533 ION_STRING
*ptr
= ecalloc(sizeof(*ptr
), max
);
534 iERR err
= ion_reader_get_annotations(obj
->reader
, ptr
, max
, &count
);
536 array_init_size(return_value
, count
);
537 for (int32_t i
= 0; i
< count
; ++i
) {
538 add_next_index_str(return_value
, zend_string_from_ion(&ptr
[i
]));
544 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbols
)
546 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
549 ZEND_PARSE_PARAMETERS_NONE();
551 int32_t count
, max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
552 ION_SYMBOL
*ptr
= ecalloc(sizeof(*ptr
), max
);
553 iERR err
= ion_reader_get_annotation_symbols(obj
->reader
, ptr
, max
, &count
);
555 array_init_size(return_value
, count
);
556 for (int32_t i
= 0; i
< count
; ++i
) {
558 php_ion_symbol_zval(&ptr
[i
], &zsym
);
559 add_next_index_zval(return_value
, &zsym
);
565 ZEND_METHOD(ion_Reader_Reader
, countAnnotations
)
567 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
570 ZEND_PARSE_PARAMETERS_NONE();
573 ION_CHECK(ion_reader_get_annotation_count(obj
->reader
, &sz
));
576 ZEND_METHOD(ion_Reader_Reader
, getAnnotation
)
578 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
582 ZEND_PARSE_PARAMETERS_START(1, 1)
584 ZEND_PARSE_PARAMETERS_END();
587 ION_CHECK(ion_reader_get_an_annotation(obj
->reader
, idx
, &ann
));
588 RETURN_STRINGL((char *) ann
.value
, ann
.length
);
590 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbol
)
592 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
596 ZEND_PARSE_PARAMETERS_START(1, 1)
598 ZEND_PARSE_PARAMETERS_END();
601 ION_CHECK(ion_reader_get_an_annotation_symbol(obj
->reader
, idx
, &sym
));
602 php_ion_symbol_zval(&sym
, return_value
);
604 ZEND_METHOD(ion_Reader_Reader
, readNull
)
606 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
609 ZEND_PARSE_PARAMETERS_NONE();
612 ION_CHECK(ion_reader_read_null(obj
->reader
, &typ
));
613 RETURN_OBJ_COPY(php_ion_type_fetch(typ
));
615 ZEND_METHOD(ion_Reader_Reader
, readBool
)
617 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
620 ZEND_PARSE_PARAMETERS_NONE();
623 ION_CHECK(ion_reader_read_bool(obj
->reader
, &b
));
626 ZEND_METHOD(ion_Reader_Reader
, readInt
)
628 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
631 ZEND_PARSE_PARAMETERS_NONE();
633 php_ion_reader_read_int(obj
->reader
, return_value
);
635 ZEND_METHOD(ion_Reader_Reader
, readFloat
)
637 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
640 ZEND_PARSE_PARAMETERS_NONE();
642 ION_CHECK(ion_reader_read_double(obj
->reader
, &Z_DVAL_P(return_value
)));
644 ZEND_METHOD(ion_Reader_Reader
, readDecimal
)
646 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
649 ZEND_PARSE_PARAMETERS_NONE();
651 object_init_ex(return_value
, ce_Decimal
);
652 php_ion_decimal
*dec
= php_ion_obj(decimal
, Z_OBJ_P(return_value
));
653 ION_CHECK(ion_reader_read_ion_decimal(obj
->reader
, &dec
->dec
));
654 php_ion_decimal_ctor(dec
);
656 ZEND_METHOD(ion_Reader_Reader
, readTimestamp
)
658 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
661 ZEND_PARSE_PARAMETERS_NONE();
663 php_ion_reader_read_timestamp(obj
->reader
, obj
->opt
? &php_ion_obj(reader_options
, obj
->opt
)->opt
: NULL
, return_value
);
665 ZEND_METHOD(ion_Reader_Reader
, readSymbol
)
667 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
670 ZEND_PARSE_PARAMETERS_NONE();
673 ION_CHECK(ion_reader_read_ion_symbol(obj
->reader
, &sym
));
674 php_ion_symbol_zval(&sym
, return_value
);
676 ZEND_METHOD(ion_Reader_Reader
, readString
)
678 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
681 ZEND_PARSE_PARAMETERS_NONE();
684 ION_CHECK(ion_reader_read_string(obj
->reader
, &str
));
685 RETURN_STRINGL((char *) str
.value
, str
.length
);
688 typedef iERR (*read_part_fn
)(ION_READER
*, BYTE
*, SIZE
, SIZE
*);
689 static void read_part(INTERNAL_FUNCTION_PARAMETERS
, read_part_fn fn
)
691 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
696 zend_long len
= 0x1000;
697 ZEND_PARSE_PARAMETERS_START(1, 1)
701 ZEND_PARSE_PARAMETERS_END();
705 if (Z_TYPE_P(ref
) == IS_STRING
&& Z_STRLEN_P(ref
) == len
) {
710 zstr
= zend_string_alloc(len
, 0);
714 ION_CHECK(fn(obj
->reader
, (BYTE
*) zstr
->val
, zstr
->len
, &read
), goto fail
);
716 if (read
< zstr
->len
) {
717 zstr
= zend_string_truncate(zstr
, read
, 0);
723 if (zstr
!= Z_STR_P(ref
)) {
724 zend_string_release(zstr
);
726 ZVAL_EMPTY_STRING(ref
);
729 ZEND_METHOD(ion_Reader_Reader
, readStringPart
)
731 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_partial_string
);
733 ZEND_METHOD(ion_Reader_Reader
, readLob
)
735 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
738 ZEND_PARSE_PARAMETERS_NONE();
740 php_ion_reader_read_lob(obj
->reader
, return_value
);
742 ZEND_METHOD(ion_Reader_Reader
, readLobPart
)
744 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_lob_partial_bytes
);
746 ZEND_METHOD(ion_Reader_Reader
, getPosition
)
748 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
751 ZEND_PARSE_PARAMETERS_NONE();
755 ION_CHECK(ion_reader_get_position(obj
->reader
, &bytes
, &dummy
, &dummy
));
758 ZEND_METHOD(ion_Reader_Reader
, getDepth
)
760 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
763 ZEND_PARSE_PARAMETERS_NONE();
766 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
769 ZEND_METHOD(ion_Reader_Reader
, seek
)
771 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
774 zend_long off
, len
= -1;
775 ZEND_PARSE_PARAMETERS_START(1, 2)
779 ZEND_PARSE_PARAMETERS_END();
781 ION_CHECK(ion_reader_seek(obj
->reader
, off
, len
));
783 ZEND_METHOD(ion_Reader_Reader
, getValueOffset
)
785 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
788 ZEND_PARSE_PARAMETERS_NONE();
791 ION_CHECK(ion_reader_get_value_offset(obj
->reader
, &off
));
794 ZEND_METHOD(ion_Reader_Reader
, getValueLength
)
796 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
799 ZEND_PARSE_PARAMETERS_NONE();
802 ION_CHECK(ion_reader_get_value_length(obj
->reader
, &len
));
805 ZEND_METHOD(ion_Reader_Buffer_Reader
, __construct
)
807 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
811 ZEND_PARSE_PARAMETERS_START(1, 2)
814 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
815 ZEND_PARSE_PARAMETERS_END();
817 obj
->type
= BUFFER_READER
;
818 obj
->buffer
= zend_string_copy(zstr
);
820 php_ion_reader_ctor(obj
);
822 ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
824 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
827 ZEND_PARSE_PARAMETERS_NONE();
828 RETURN_STR_COPY(obj
->buffer
);
831 ZEND_METHOD(ion_Reader_Stream_Reader
, __construct
)
833 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
837 ZEND_PARSE_PARAMETERS_START(1, 2)
838 Z_PARAM_RESOURCE(zstream
)
840 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
841 ZEND_PARSE_PARAMETERS_END();
843 obj
->type
= STREAM_READER
;
844 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
846 php_ion_reader_ctor(obj
);
848 ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
850 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
853 ZEND_PARSE_PARAMETERS_NONE();
854 PTR_CHECK(obj
->stream
.ptr
);
856 GC_ADDREF(obj
->stream
.ptr
->res
);
857 RETURN_RES(obj
->stream
.ptr
->res
);
859 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
861 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
865 ZEND_PARSE_PARAMETERS_START(1, 1);
866 Z_PARAM_RESOURCE(zstream
);
867 ZEND_PARSE_PARAMETERS_END();
869 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
871 if (obj
->stream
.ptr
) {
872 zend_list_delete(obj
->stream
.ptr
->res
);
874 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
875 PTR_CHECK(obj
->stream
.ptr
);
878 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
880 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
885 ZEND_PARSE_PARAMETERS_START(1, 2);
886 Z_PARAM_RESOURCE(zstream
);
888 ZEND_PARSE_PARAMETERS_END();
890 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
892 if (obj
->stream
.ptr
) {
893 zend_list_delete(obj
->stream
.ptr
->res
);
895 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
896 PTR_CHECK(obj
->stream
.ptr
);
899 ZEND_METHOD(ion_Writer_Options
, __construct
)
901 php_ion_writer_options
*obj
= php_ion_obj(writer_options
, Z_OBJ_P(ZEND_THIS
));
904 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
905 tabs
= true, small_cntr_inl
= true, suppress_sys
= false, flush
= false;
906 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x400, alloc
= 0x1000;
907 ZEND_PARSE_PARAMETERS_START(0, 16)
909 //public readonly ?\ion\Catalog $catalog = null,
910 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
911 //public readonly ?\ion\Collection $encodingSymbolTable = null,
912 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->col
, ce_Collection
)
913 //public readonly ?\ion\Decimal\Context $decimalContext = null,
914 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
915 //public readonly bool $outputBinary = false,
917 //public readonly bool $compactFloats = false,
918 Z_PARAM_BOOL(compact_floats
)
919 //public readonly bool $escapeNonAscii = false,
921 //public readonly bool $prettyPrint = false,
923 //public readonly bool $indentTabs = true,
925 //public readonly int $indentSize = 2,
927 //public readonly bool $smallContainersInline = true,
928 Z_PARAM_BOOL(small_cntr_inl
)
929 //public readonly bool $suppressSystemValues = false,
930 Z_PARAM_BOOL(suppress_sys
)
931 //public readonly bool $flushEveryValue = false,
933 //public readonly int $maxContainerDepth = 10,
934 Z_PARAM_LONG(max_depth
)
935 //public readonly int $maxAnnotations = 10,
936 Z_PARAM_LONG(max_ann
)
937 //public readonly int $tempBufferSize = 0x400,
939 //public readonly int $allocationPageSize = 0x1000,
941 ZEND_PARSE_PARAMETERS_END();
944 update_property_obj(&obj
->std
, ZEND_STRL("catalog"), obj
->cat
);
945 obj
->opt
.pcatalog
= php_ion_obj(catalog
, obj
->cat
)->cat
;
951 update_property_obj(&obj
->std
, ZEND_STRL("decimalContext"), obj
->dec_ctx
);
952 obj
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, obj
->dec_ctx
)->ctx
;
954 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("outputBinary"),
955 obj
->opt
.output_as_binary
= binary
);
956 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("comactFloats"),
957 obj
->opt
.compact_floats
= compact_floats
);
958 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("excapeNonAscii"),
959 obj
->opt
.escape_all_non_ascii
= escape
);
960 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("prettyPrint"),
961 obj
->opt
.pretty_print
= pretty
);
962 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentTabs"),
963 obj
->opt
.indent_with_tabs
= tabs
);
964 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentSize"),
965 obj
->opt
.indent_size
= indent
);
966 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("smallContainersInline"),
967 obj
->opt
.small_containers_in_line
= small_cntr_inl
);
968 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("suppressSystemValues"),
969 obj
->opt
.supress_system_values
= suppress_sys
);
970 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("flushEveryValue"),
971 obj
->opt
.flush_every_value
= flush
);
972 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxContainerDepth"),
973 obj
->opt
.max_container_depth
= max_depth
);
974 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxAnnotations"),
975 obj
->opt
.max_annotation_count
= max_ann
);
976 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("tempBufferSize"),
977 obj
->opt
.temp_buffer_size
= temp
);
978 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("allocationPageSize"),
979 obj
->opt
.allocation_page_size
= alloc
);
981 ZEND_METHOD(ion_Writer_Writer
, writeNull
)
983 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
986 ZEND_PARSE_PARAMETERS_NONE();
988 ION_CHECK(ion_writer_write_null(obj
->writer
));
990 ZEND_METHOD(ion_Writer_Writer
, writeTypedNull
)
992 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
995 zend_object
*typ_obj
;
996 ZEND_PARSE_PARAMETERS_START(1, 1)
997 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
998 ZEND_PARSE_PARAMETERS_END();
1000 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1002 ION_CHECK(ion_writer_write_typed_null(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1004 ZEND_METHOD(ion_Writer_Writer
, writeBool
)
1006 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1010 ZEND_PARSE_PARAMETERS_START(1, 1)
1012 ZEND_PARSE_PARAMETERS_END();
1014 ION_CHECK(ion_writer_write_bool(obj
->writer
, b
));
1016 ZEND_METHOD(ion_Writer_Writer
, writeInt
)
1018 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1023 ZEND_PARSE_PARAMETERS_START(1, 1)
1024 Z_PARAM_STR_OR_LONG(s
, l
)
1025 ZEND_PARSE_PARAMETERS_END();
1029 ION_CHECK(ion_int_alloc(obj
->writer
, &i
));
1030 ION_CHECK(ion_int_from_chars(i
, s
->val
, s
->len
));
1031 ION_CHECK(ion_writer_write_ion_int(obj
->writer
, i
));
1034 ION_CHECK(ion_writer_write_int64(obj
->writer
, l
));
1037 ZEND_METHOD(ion_Writer_Writer
, writeFloat
)
1039 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1043 ZEND_PARSE_PARAMETERS_START(1, 1)
1045 ZEND_PARSE_PARAMETERS_END();
1047 ION_CHECK(ion_writer_write_double(obj
->writer
, d
));
1049 ZEND_METHOD(ion_Writer_Writer
, writeDecimal
)
1051 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1054 zend_object
*dec_obj
;
1055 zend_string
*dec_str
;
1056 ZEND_PARSE_PARAMETERS_START(1, 1)
1057 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj
, ce_Decimal
, dec_str
)
1058 ZEND_PARSE_PARAMETERS_END();
1062 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&s
, dec_str
)));
1064 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
1065 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
1068 ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
1070 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1073 zend_object
*ts_obj
;
1074 zend_string
*ts_str
;
1075 ZEND_PARSE_PARAMETERS_START(1, 1)
1076 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
1077 ZEND_PARSE_PARAMETERS_END();
1079 decContext
*ctx
= NULL
;
1081 ctx
= php_ion_obj(reader_options
, obj
->opt
)->opt
.decimal_context
;
1084 ION_TIMESTAMP tmp
= {0};
1087 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1089 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1091 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1093 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1095 ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1097 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1100 zend_object
*sym_obj
;
1101 zend_string
*sym_str
;
1102 ZEND_PARSE_PARAMETERS_START(1, 1)
1103 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1104 ZEND_PARSE_PARAMETERS_END();
1108 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1110 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1112 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1115 ZEND_METHOD(ion_Writer_Writer
, writeString
)
1117 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1121 ZEND_PARSE_PARAMETERS_START(1, 1)
1123 ZEND_PARSE_PARAMETERS_END();
1126 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1128 ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1130 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1134 ZEND_PARSE_PARAMETERS_START(1, 1)
1136 ZEND_PARSE_PARAMETERS_END();
1138 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1140 ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1142 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1146 ZEND_PARSE_PARAMETERS_START(1, 1)
1148 ZEND_PARSE_PARAMETERS_END();
1150 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1152 ZEND_METHOD(ion_Writer_Writer
, startLob
)
1154 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1157 zend_object
*typ_obj
;
1158 ZEND_PARSE_PARAMETERS_START(1, 1)
1159 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1160 ZEND_PARSE_PARAMETERS_END();
1162 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1164 ION_CHECK(ion_writer_start_lob(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1166 ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1168 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1172 ZEND_PARSE_PARAMETERS_START(1, 1)
1174 ZEND_PARSE_PARAMETERS_END();
1176 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1178 ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1180 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1183 ZEND_PARSE_PARAMETERS_NONE();
1185 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1187 ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1189 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1192 zend_object
*typ_obj
;
1193 ZEND_PARSE_PARAMETERS_START(1, 1)
1194 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1195 ZEND_PARSE_PARAMETERS_END();
1197 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1199 ION_CHECK(ion_writer_start_container(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1201 ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1203 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1206 ZEND_PARSE_PARAMETERS_NONE();
1208 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1210 ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1212 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1215 zend_object
*sym_obj
;
1216 zend_string
*sym_str
;
1217 ZEND_PARSE_PARAMETERS_START(1, 1)
1218 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1219 ZEND_PARSE_PARAMETERS_END();
1223 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1225 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1227 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1230 ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1232 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1237 ZEND_PARSE_PARAMETERS_START(1, -1)
1238 Z_PARAM_VARIADIC('+', args
, argc
);
1239 ZEND_PARSE_PARAMETERS_END();
1241 for (unsigned i
= 0; i
< argc
; ++i
) {
1242 switch (Z_TYPE(args
[i
])) {
1245 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1249 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1254 ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1256 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1259 ZEND_PARSE_PARAMETERS_NONE();
1262 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1265 ZEND_METHOD(ion_Writer_Writer
, flush
)
1267 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1270 ZEND_PARSE_PARAMETERS_NONE();
1273 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1274 if (obj
->type
== BUFFER_WRITER
) {
1275 smart_str_0(&obj
->buffer
.str
);
1277 RETURN_LONG(flushed
);
1279 ZEND_METHOD(ion_Writer_Writer
, finish
)
1281 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1284 ZEND_PARSE_PARAMETERS_NONE();
1287 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1288 if (obj
->type
== BUFFER_WRITER
) {
1289 smart_str_0(&obj
->buffer
.str
);
1291 RETURN_LONG(flushed
);
1293 ZEND_METHOD(ion_Writer_Writer
, writeOne
)
1296 ZEND_METHOD(ion_Writer_Writer
, writeAll
)
1299 ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1301 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1305 ZEND_PARSE_PARAMETERS_START(1, 2)
1308 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1309 ZEND_PARSE_PARAMETERS_END();
1311 obj
->type
= BUFFER_WRITER
;
1312 ZVAL_COPY(&obj
->buffer
.val
, ref
);
1313 zval_dtor(Z_REFVAL_P(ref
));
1315 php_ion_writer_ctor(obj
);
1317 ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1319 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1322 ZEND_PARSE_PARAMETERS_NONE();
1324 RETVAL_STR(zend_string_dup(obj
->buffer
.str
.s
, 0));
1326 ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1328 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1332 ZEND_PARSE_PARAMETERS_START(1, 2)
1333 Z_PARAM_RESOURCE(zstream
)
1335 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1336 ZEND_PARSE_PARAMETERS_END();
1338 obj
->type
= STREAM_WRITER
;
1339 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1341 php_ion_writer_ctor(obj
);
1343 ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1345 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1348 ZEND_PARSE_PARAMETERS_NONE();
1349 PTR_CHECK(obj
->stream
.ptr
);
1351 GC_ADDREF(obj
->stream
.ptr
->res
);
1352 RETURN_RES(obj
->stream
.ptr
->res
);
1355 ZEND_METHOD(ion_Serializer_PHP
, __construct
)
1357 php_ion_serializer_php
*obj
= php_ion_obj(serializer_php
, Z_OBJ_P(ZEND_THIS
));
1360 obj
->serializer
.call_magic
= true;
1362 ZEND_PARSE_PARAMETERS_START(0, 3)
1364 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1365 Z_PARAM_BOOL(obj
->serializer
.multi_seq
)
1366 Z_PARAM_BOOL(obj
->serializer
.call_magic
)
1367 Z_PARAM_STR_OR_NULL(obj
->serializer
.call_custom
)
1368 ZEND_PARSE_PARAMETERS_END();
1370 php_ion_serializer_php_ctor(obj
);
1372 ZEND_METHOD(ion_Serializer_PHP
, __invoke
)
1374 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1377 ZEND_PARSE_PARAMETERS_START(1, 1)
1379 ZEND_PARSE_PARAMETERS_END();
1381 if (obj
->ce
== ce_Serializer_PHP
) {
1382 // default, fast path
1383 php_ion_serialize(&php_ion_obj(serializer_php
, obj
)->serializer
, data
, return_value
);
1385 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "serialize", return_value
, data
);
1388 ZEND_FUNCTION(ion_serialize
)
1391 zend_object
*zo_ser
= NULL
;
1392 ZEND_PARSE_PARAMETERS_START(1, 2)
1395 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Serializer
)
1396 ZEND_PARSE_PARAMETERS_END();
1398 if (!zo_ser
|| zo_ser
->ce
== ce_Serializer_PHP
) {
1399 // default, fast path
1400 php_ion_serializer
*ser
= zo_ser
? &php_ion_obj(serializer_php
, zo_ser
)->serializer
: NULL
;
1401 php_ion_serialize(ser
, data
, return_value
);
1403 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1406 ZEND_METHOD(ion_Serializer_PHP
, serialize
)
1408 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1411 ZEND_PARSE_PARAMETERS_START(1, 1)
1413 ZEND_PARSE_PARAMETERS_END();
1416 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1419 ZEND_METHOD(ion_Unserializer_PHP
, __construct
)
1421 php_ion_unserializer_php
*obj
= php_ion_obj(unserializer_php
, Z_OBJ_P(ZEND_THIS
));
1424 obj
->unserializer
.call_magic
= true;
1426 ZEND_PARSE_PARAMETERS_START(0, 3)
1428 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1429 Z_PARAM_BOOL(obj
->unserializer
.multi_seq
)
1430 Z_PARAM_BOOL(obj
->unserializer
.call_magic
)
1431 Z_PARAM_STR_OR_NULL(obj
->unserializer
.call_custom
)
1432 ZEND_PARSE_PARAMETERS_END();
1434 php_ion_unserializer_php_ctor(obj
);
1436 ZEND_METHOD(ion_Unserializer_PHP
, __invoke
)
1438 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1441 ZEND_PARSE_PARAMETERS_START(1, 1)
1443 ZEND_PARSE_PARAMETERS_END();
1445 if (obj
->ce
== ce_Unserializer_PHP
) {
1446 php_ion_unserialize(&php_ion_obj(unserializer_php
, obj
)->unserializer
, data
, return_value
);
1448 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "unserialize", return_value
, data
);
1451 ZEND_FUNCTION(ion_unserialize
)
1454 zend_object
*zo_ser
= NULL
;
1455 ZEND_PARSE_PARAMETERS_START(1, 2)
1458 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Unserializer
)
1459 ZEND_PARSE_PARAMETERS_END();
1461 if (!zo_ser
|| zo_ser
->ce
== ce_Unserializer_PHP
) {
1462 // default, fast path
1463 php_ion_unserializer
*ser
= zo_ser
? &php_ion_obj(unserializer_php
, zo_ser
)->unserializer
: NULL
;
1464 php_ion_unserialize(ser
, data
, return_value
);
1466 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1469 ZEND_METHOD(ion_Unserializer_PHP
, unserialize
)
1471 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1474 ZEND_PARSE_PARAMETERS_START(1, 1)
1476 ZEND_PARSE_PARAMETERS_END();
1479 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1482 PHP_RINIT_FUNCTION(ion
)
1484 #if defined(ZTS) && defined(COMPILE_DL_ION)
1485 ZEND_TSRMLS_CACHE_UPDATE();
1488 php_ion_globals_serializer_init();
1489 php_ion_globals_unserializer_init();
1493 PHP_RSHUTDOWN_FUNCTION(ion
)
1495 php_ion_globals_serializer_dtor();
1496 php_ion_globals_unserializer_dtor();
1500 PHP_MINIT_FUNCTION(ion
)
1503 php_ion_decimal_ctx_init_max(&g_dec_ctx
, DEC_ROUND_HALF_EVEN
);
1504 php_ion_decimal_from_zend_long(&g_ion_dec_zend_max
, &g_dec_ctx
, ZEND_LONG_MAX
);
1505 php_ion_decimal_from_zend_long(&g_ion_dec_zend_min
, &g_dec_ctx
, ZEND_LONG_MIN
);
1508 ce_Annotation
= register_class_ion_Annotation();
1511 ce_Collection
= register_class_ion_Collection();
1514 php_ion_register(decimal
, Decimal
);
1515 php_ion_register(decimal_ctx
, Decimal_Context
);
1516 ce_Decimal_Context_Rounding
= register_class_ion_Decimal_Context_Rounding();
1519 ce_LOB
= register_class_ion_LOB();
1522 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1523 php_ion_register(reader_options
, Reader_Options
);
1524 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1525 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1526 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1527 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1528 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1531 ce_Serializer
= register_class_ion_Serializer();
1532 php_ion_register(serializer_php
, Serializer_PHP
, ce_Serializer
);
1535 php_ion_register(symbol
, Symbol
);
1536 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1537 php_ion_register(symbol_table
, Symbol_Table
);
1538 ce_Symbol_System
= register_class_ion_Symbol_System();
1539 ce_Symbol_System_SID
= register_class_ion_Symbol_System_SID();
1542 php_ion_register(timestamp
, Timestamp
, php_date_get_date_ce());
1543 ce_Timestamp_Precision
= register_class_ion_Timestamp_Precision();
1544 php_ion_register(catalog
, Catalog
);
1547 php_ion_register(type
, Type
);
1550 ce_Writer
= register_class_ion_Writer();
1551 php_ion_register(writer_options
, Writer_Options
);
1552 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1553 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1554 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1555 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1556 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1559 ce_Unserializer
= register_class_ion_Unserializer();
1560 php_ion_register(unserializer_php
, Unserializer_PHP
, ce_Unserializer
);
1565 PHP_MSHUTDOWN_FUNCTION(ion
)
1569 PHP_MINFO_FUNCTION(ion
)
1571 php_info_print_table_start();
1572 php_info_print_table_header(2, "ion support", "enabled");
1573 php_info_print_table_end();
1576 PHP_GINIT_FUNCTION(ion
)
1578 memset(ion_globals
, 0, sizeof(*ion_globals
));
1580 PHP_GSHUTDOWN_FUNCTION(ion
)
1584 static zend_module_dep ion_module_deps
[] = {
1585 ZEND_MOD_REQUIRED("spl")
1589 zend_module_entry ion_module_entry
= {
1590 STANDARD_MODULE_HEADER_EX
,
1593 "ion", /* Extension name */
1594 ext_functions
, /* zend_function_entry */
1595 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1596 PHP_MSHUTDOWN(ion
), /* PHP_MSHUTDOWN - Module shutdown */
1597 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1598 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1599 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1600 PHP_ION_VERSION
, /* Version */
1601 ZEND_MODULE_GLOBALS(ion
),
1602 PHP_GINIT(ion
), /* PHP_GINIT */
1603 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1605 STANDARD_MODULE_PROPERTIES_EX
1608 #ifdef COMPILE_DL_ION
1610 ZEND_TSRMLS_CACHE_DEFINE()
1612 ZEND_GET_MODULE(ion
)