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 */
34 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
35 { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), default_value },
36 #include "ion_arginfo.h"
37 #include "ion_private.h"
39 ZEND_METHOD(ion_Symbol_ImportLocation
, __construct
)
42 php_ion_symbol_iloc
*obj
= php_ion_obj(symbol_iloc
, Z_OBJ_P(ZEND_THIS
));
46 ZEND_PARSE_PARAMETERS_START(2, 2)
47 Z_PARAM_STR(obj
->name
)
48 Z_PARAM_LONG(location
)
49 ZEND_PARSE_PARAMETERS_END();
51 obj
->loc
.location
= location
;
52 php_ion_symbol_iloc_ctor(obj
);
54 ZEND_METHOD(ion_Symbol
, __construct
)
57 php_ion_symbol
*obj
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
61 ZEND_PARSE_PARAMETERS_START(1, 3)
62 Z_PARAM_STR(obj
->value
)
65 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->iloc
, ce_Symbol_ImportLocation
)
66 ZEND_PARSE_PARAMETERS_END();
69 php_ion_symbol_ctor(obj
);
71 ZEND_METHOD(ion_Symbol
, equals
)
73 zend_object
*other_obj
;
74 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
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_Timestamp
, __construct
)
92 zend_string
*fmt
= NULL
, *dt
= NULL
;
94 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
97 ZEND_PARSE_PARAMETERS_START(1, 4)
98 Z_PARAM_LONG(precision
)
100 Z_PARAM_STR_OR_NULL(fmt
)
103 ZEND_PARSE_PARAMETERS_END();
105 php_ion_timestamp_ctor(obj
, precision
, fmt
, dt
, tz
);
107 ZEND_METHOD(ion_Timestamp
, __toString
)
109 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
112 ZEND_PARSE_PARAMETERS_NONE();
116 zend_call_method_with_1_params(&obj
->std
, obj
->std
.ce
, NULL
, "format", return_value
,
117 zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("format"), 0, &fmt
));
119 ZEND_METHOD(ion_Decimal_Context
, __construct
)
121 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(ZEND_THIS
));
124 zend_long bits
= 128;
125 ZEND_PARSE_PARAMETERS_START(0, 1)
128 ZEND_PARSE_PARAMETERS_END();
130 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("bits"), bits
);
131 php_ion_decimal_ctx_ctor(obj
);
133 ZEND_METHOD(ion_Decimal
, __construct
)
135 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
140 ZEND_PARSE_PARAMETERS_START(1, 2)
141 Z_PARAM_STR_OR_LONG(zstr
, num
)
143 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->ctx
, ce_Decimal_Context
)
144 ZEND_PARSE_PARAMETERS_END();
150 object_init_ex(&zdc
, ce_Decimal_Context
);
151 obj
->ctx
= Z_OBJ(zdc
);
152 php_ion_decimal_ctx_ctor(php_ion_obj(decimal_ctx
, obj
->ctx
));
156 ION_CHECK(ion_decimal_from_string(&obj
->dec
, zstr
->val
,
157 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
));
158 } else if (num
<= INT32_MAX
&& num
>= INT32_MIN
) {
159 ION_CHECK(ion_decimal_from_int32(&obj
->dec
, num
));
160 } else if (num
> 0 && num
<= UINT32_MAX
) {
161 ION_CHECK(ion_decimal_from_uint32(&obj
->dec
, num
));
163 zend_throw_exception_ex(spl_ce_OverflowException
, 0,
164 "Integer value out of bounds: " ZEND_LONG_FMT
" (INT32_MIN < n < UINT32_MAX)", num
);
168 php_ion_decimal_ctor(obj
);
169 OBJ_RELEASE(obj
->ctx
);
171 ZEND_METHOD(ion_Decimal
, equals
)
173 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
176 zend_object
*dec_obj
;
177 ZEND_PARSE_PARAMETERS_START(1, 1)
178 Z_PARAM_OBJ_OF_CLASS(dec_obj
, ce_Decimal
)
179 ZEND_PARSE_PARAMETERS_END();
182 ION_CHECK(ion_decimal_equals(&obj
->dec
, &php_ion_obj(decimal
, dec_obj
)->dec
,
183 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &is
));
186 ZEND_METHOD(ion_Decimal
, __toString
)
188 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
191 ZEND_PARSE_PARAMETERS_NONE();
193 RETURN_STR(php_ion_decimal_to_string(&obj
->dec
));
195 ZEND_METHOD(ion_Decimal
, toInt
)
197 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
200 ZEND_PARSE_PARAMETERS_NONE();
203 php_ion_decimal_to_int(&obj
->dec
, &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
, &l
);
206 ZEND_METHOD(ion_Decimal
, isInt
)
208 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
211 ZEND_PARSE_PARAMETERS_NONE();
213 RETURN_BOOL(ion_decimal_is_integer(&obj
->dec
));
215 ZEND_METHOD(ion_Reader_Options
, __construct
)
217 php_ion_reader_options
*opt
= php_ion_obj(reader_options
, Z_OBJ_P(ZEND_THIS
));
218 zend_bool ret_sys_val
= false, skip_validation
= false;
219 zend_long ch_nl
= 0xa, max_depth
= 10, max_ann
, max_ann_buf
= 512,
220 sym_thr
= 0x1000, uval_thr
= 0x1000, chunk_thr
= 0x1000, alloc_pgsz
= 0x1000;
224 ZEND_PARSE_PARAMETERS_START(0, 13)
226 // public readonly ?\ion\Catalog $catalog = null,
227 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cat
, ce_Catalog
)
228 // public readonly ?\ion\Decimal\Context $decimalContext = null,
229 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->dec_ctx
, ce_Decimal_Context
)
230 // public readonly ?\Closure $onContextChange = null,
231 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cb
, zend_ce_closure
);
232 // public readonly bool $returnSystemValues = false,
233 Z_PARAM_BOOL(ret_sys_val
)
234 // public readonly int $newLine = 0xa,
236 // public readonly int $maxContainerDepth = 10,
237 Z_PARAM_LONG(max_depth
)
238 // public readonly int $maxAnnotations = 10,
239 Z_PARAM_LONG(max_ann
)
240 // public readonly int $maxAnnotationBuffered = 512,
241 Z_PARAM_LONG(max_ann_buf
)
242 // public readonly int $symbolThreshold = 4096,
243 Z_PARAM_LONG(sym_thr
)
244 // public readonly int $userValueThreshold = 4096,
245 Z_PARAM_LONG(uval_thr
)
246 // public readonly int $chunkThreshold = 4096,
247 Z_PARAM_LONG(chunk_thr
)
248 // public readonly int $allocationPageSize = 4096,
249 Z_PARAM_LONG(alloc_pgsz
)
250 // public readonly bool $skipCharacterValidation = false,
251 Z_PARAM_BOOL(skip_validation
)
252 ZEND_PARSE_PARAMETERS_END();
254 opt
->opt
.context_change_notifier
= EMPTY_READER_CHANGE_NOTIFIER
;
256 update_property_obj(&opt
->std
, ZEND_STRL("onContextChange"), opt
->cb
);
259 update_property_obj(&opt
->std
, ZEND_STRL("catalog"), opt
->cat
);
260 opt
->opt
.pcatalog
= php_ion_obj(catalog
, opt
->cat
)->cat
;
263 update_property_obj(&opt
->std
, ZEND_STRL("decimalContext"), opt
->dec_ctx
);
264 opt
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, opt
->dec_ctx
)->ctx
;
266 zend_update_property_bool(opt
->std
.ce
, &opt
->std
, ZEND_STRL("returnSystemValues"),
267 opt
->opt
.return_system_values
= ret_sys_val
);
268 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("newLine"),
269 opt
->opt
.new_line_char
= ch_nl
);
270 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxContainerDepth"),
271 opt
->opt
.max_container_depth
= max_depth
);
272 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationCount"),
273 opt
->opt
.max_annotation_count
= max_ann
);
274 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationBuffered"),
275 opt
->opt
.max_annotation_buffered
= max_ann_buf
);
276 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("symbolThreshold"),
277 opt
->opt
.symbol_threshold
= sym_thr
);
278 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("userValueThreshold"),
279 opt
->opt
.user_value_threshold
= uval_thr
);
280 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("chunkThreshold"),
281 opt
->opt
.chunk_threshold
= chunk_thr
);
282 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("allocationPageSize"),
283 opt
->opt
.allocation_page_size
= alloc_pgsz
);
284 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("skipCharacterValidation"),
285 opt
->opt
.skip_character_validation
= skip_validation
);
287 ZEND_METHOD(ion_Reader_Reader
, hasChildren
)
289 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
292 ZEND_PARSE_PARAMETERS_NONE();
295 ION_CHECK(ion_reader_get_type(obj
->reader
, &t
));
296 switch (ION_TYPE_INT(t
)) {
307 ZEND_METHOD(ion_Reader_Reader
, getChildren
)
309 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
312 ZEND_PARSE_PARAMETERS_NONE();
314 ION_CHECK(ion_reader_step_in(obj
->reader
));
316 RETURN_ZVAL(ZEND_THIS
, 1, 0);
318 ZEND_METHOD(ion_Reader_Reader
, rewind
)
320 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
323 ZEND_PARSE_PARAMETERS_NONE();
325 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
327 ZEND_METHOD(ion_Reader_Reader
, next
)
329 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
332 ZEND_PARSE_PARAMETERS_NONE();
334 if (obj
->state
== tid_EOF
) {
336 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
338 ION_CHECK(ion_reader_step_out(obj
->reader
));
341 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
343 ZEND_METHOD(ion_Reader_Reader
, valid
)
345 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
348 ZEND_PARSE_PARAMETERS_NONE();
349 RETURN_BOOL(obj
->state
!= tid_none
&& obj
->state
!= tid_EOF
);
351 ZEND_METHOD(ion_Reader_Reader
, key
)
353 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
356 ZEND_PARSE_PARAMETERS_NONE();
357 RETURN_IONTYPE(obj
->state
);
359 ZEND_METHOD(ion_Reader_Reader
, current
)
361 ZEND_PARSE_PARAMETERS_NONE();
362 RETURN_ZVAL(ZEND_THIS
, 1, 0);
364 ZEND_METHOD(ion_Reader_Reader
, getType
)
366 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
369 ZEND_PARSE_PARAMETERS_NONE();
372 ION_CHECK(ion_reader_get_type(obj
->reader
, &typ
));
375 ZEND_METHOD(ion_Reader_Reader
, hasAnnotations
)
377 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
380 ZEND_PARSE_PARAMETERS_NONE();
383 ION_CHECK(ion_reader_has_any_annotations(obj
->reader
, &has
));
386 ZEND_METHOD(ion_Reader_Reader
, hasAnnotation
)
388 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
391 zend_string
*ann_zstr
;
392 ZEND_PARSE_PARAMETERS_START(1, 1);
393 Z_PARAM_STR(ann_zstr
);
394 ZEND_PARSE_PARAMETERS_END();
398 ION_CHECK(ion_reader_has_annotation(obj
->reader
, ion_string_from_zend(&ann_istr
, ann_zstr
), &has
));
401 ZEND_METHOD(ion_Reader_Reader
, isNull
)
403 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
406 ZEND_PARSE_PARAMETERS_NONE();
409 ION_CHECK(ion_reader_is_null(obj
->reader
, &is
));
412 ZEND_METHOD(ion_Reader_Reader
, isInStruct
)
414 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
417 ZEND_PARSE_PARAMETERS_NONE();
420 ION_CHECK(ion_reader_is_in_struct(obj
->reader
, &is
));
423 ZEND_METHOD(ion_Reader_Reader
, getFieldName
)
425 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
428 ZEND_PARSE_PARAMETERS_NONE();
431 ION_CHECK(ion_reader_get_field_name(obj
->reader
, &name
));
432 RETURN_STRINGL((char *) name
.value
, name
.length
);
434 ZEND_METHOD(ion_Reader_Reader
, getFieldNameSymbol
)
436 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
439 ZEND_PARSE_PARAMETERS_NONE();
442 ION_CHECK(ion_reader_get_field_name_symbol(obj
->reader
, &sym_ptr
));
444 php_ion_symbol_zval(sym_ptr
, return_value
);
446 ZEND_METHOD(ion_Reader_Reader
, getAnnotations
)
448 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
451 ZEND_PARSE_PARAMETERS_NONE();
455 max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
459 ION_STRING
*ptr
= ecalloc(sizeof(*ptr
), max
);
460 iERR err
= ion_reader_get_annotations(obj
->reader
, ptr
, max
, &count
);
462 array_init_size(return_value
, count
);
463 for (int32_t i
= 0; i
< count
; ++i
) {
464 add_next_index_str(return_value
, zend_string_from_ion(&ptr
[i
]));
470 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbols
)
472 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
475 ZEND_PARSE_PARAMETERS_NONE();
477 int32_t count
, max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
478 ION_SYMBOL
*ptr
= ecalloc(sizeof(*ptr
), max
);
479 iERR err
= ion_reader_get_annotation_symbols(obj
->reader
, ptr
, max
, &count
);
481 array_init_size(return_value
, count
);
482 for (int32_t i
= 0; i
< count
; ++i
) {
484 php_ion_symbol_zval(&ptr
[i
], &zsym
);
485 add_next_index_zval(return_value
, &zsym
);
491 ZEND_METHOD(ion_Reader_Reader
, countAnnotations
)
493 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
496 ZEND_PARSE_PARAMETERS_NONE();
499 ION_CHECK(ion_reader_get_annotation_count(obj
->reader
, &sz
));
502 ZEND_METHOD(ion_Reader_Reader
, getAnnotation
)
504 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
508 ZEND_PARSE_PARAMETERS_START(1, 1)
510 ZEND_PARSE_PARAMETERS_END();
513 ION_CHECK(ion_reader_get_an_annotation(obj
->reader
, idx
, &ann
));
514 RETURN_STRINGL((char *) ann
.value
, ann
.length
);
516 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbol
)
518 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
522 ZEND_PARSE_PARAMETERS_START(1, 1)
524 ZEND_PARSE_PARAMETERS_END();
527 ION_CHECK(ion_reader_get_an_annotation_symbol(obj
->reader
, idx
, &sym
));
528 php_ion_symbol_zval(&sym
, return_value
);
530 ZEND_METHOD(ion_Reader_Reader
, readNull
)
532 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
535 ZEND_PARSE_PARAMETERS_NONE();
538 ION_CHECK(ion_reader_read_null(obj
->reader
, &typ
));
539 RETURN_OBJ_COPY(php_ion_type_fetch(typ
));
541 ZEND_METHOD(ion_Reader_Reader
, readBool
)
543 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
546 ZEND_PARSE_PARAMETERS_NONE();
549 ION_CHECK(ion_reader_read_bool(obj
->reader
, &b
));
552 ZEND_METHOD(ion_Reader_Reader
, readInt
)
554 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
557 ZEND_PARSE_PARAMETERS_NONE();
559 php_ion_unserialize_int(obj
, return_value
);
561 ZEND_METHOD(ion_Reader_Reader
, readFloat
)
563 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
566 ZEND_PARSE_PARAMETERS_NONE();
568 ION_CHECK(ion_reader_read_double(obj
->reader
, &Z_DVAL_P(return_value
)));
570 ZEND_METHOD(ion_Reader_Reader
, readDecimal
)
572 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
575 ZEND_PARSE_PARAMETERS_NONE();
577 object_init_ex(return_value
, ce_Decimal
);
578 php_ion_decimal
*dec
= php_ion_obj(decimal
, Z_OBJ_P(return_value
));
579 ION_CHECK(ion_reader_read_ion_decimal(obj
->reader
, &dec
->dec
));
580 php_ion_decimal_ctor(dec
);
582 ZEND_METHOD(ion_Reader_Reader
, readTimestamp
)
584 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
587 ZEND_PARSE_PARAMETERS_NONE();
589 php_ion_unserialize_timestamp(obj
, return_value
);
591 ZEND_METHOD(ion_Reader_Reader
, readSymbol
)
593 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
596 ZEND_PARSE_PARAMETERS_NONE();
599 ION_CHECK(ion_reader_read_ion_symbol(obj
->reader
, &sym
));
600 php_ion_symbol_zval(&sym
, return_value
);
602 ZEND_METHOD(ion_Reader_Reader
, readString
)
604 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
607 ZEND_PARSE_PARAMETERS_NONE();
610 ION_CHECK(ion_reader_read_string(obj
->reader
, &str
));
611 RETURN_STRINGL((char *) str
.value
, str
.length
);
614 typedef iERR (*read_part_fn
)(ION_READER
*, BYTE
*, SIZE
, SIZE
*);
615 static void read_part(INTERNAL_FUNCTION_PARAMETERS
, read_part_fn fn
)
617 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
622 zend_long len
= 0x1000;
623 ZEND_PARSE_PARAMETERS_START(1, 1)
627 ZEND_PARSE_PARAMETERS_END();
631 if (Z_TYPE_P(ref
) == IS_STRING
&& Z_STRLEN_P(ref
) == len
) {
636 zstr
= zend_string_alloc(len
, 0);
640 ION_CHECK(fn(obj
->reader
, (BYTE
*) zstr
->val
, zstr
->len
, &read
), goto fail
);
642 if (read
< zstr
->len
) {
643 zstr
= zend_string_truncate(zstr
, read
, 0);
649 if (zstr
!= Z_STR_P(ref
)) {
650 zend_string_release(zstr
);
652 ZVAL_EMPTY_STRING(ref
);
655 ZEND_METHOD(ion_Reader_Reader
, readStringPart
)
657 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_partial_string
);
659 ZEND_METHOD(ion_Reader_Reader
, readLob
)
661 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
664 ZEND_PARSE_PARAMETERS_NONE();
666 php_ion_unserialize_lob(obj
, return_value
);
668 ZEND_METHOD(ion_Reader_Reader
, readLobPart
)
670 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_lob_partial_bytes
);
672 ZEND_METHOD(ion_Reader_Reader
, getPosition
)
674 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
677 ZEND_PARSE_PARAMETERS_NONE();
681 ION_CHECK(ion_reader_get_position(obj
->reader
, &bytes
, &dummy
, &dummy
));
684 ZEND_METHOD(ion_Reader_Reader
, getDepth
)
686 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
689 ZEND_PARSE_PARAMETERS_NONE();
692 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
695 ZEND_METHOD(ion_Reader_Reader
, seek
)
697 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
700 zend_long off
, len
= -1;
701 ZEND_PARSE_PARAMETERS_START(1, 2)
705 ZEND_PARSE_PARAMETERS_END();
707 ION_CHECK(ion_reader_seek(obj
->reader
, off
, len
));
709 ZEND_METHOD(ion_Reader_Reader
, getValueOffset
)
711 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
714 ZEND_PARSE_PARAMETERS_NONE();
717 ION_CHECK(ion_reader_get_value_offset(obj
->reader
, &off
));
720 ZEND_METHOD(ion_Reader_Reader
, getValueLength
)
722 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
725 ZEND_PARSE_PARAMETERS_NONE();
728 ION_CHECK(ion_reader_get_value_length(obj
->reader
, &len
));
731 ZEND_METHOD(ion_Reader_Buffer_Reader
, __construct
)
733 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
737 ZEND_PARSE_PARAMETERS_START(1, 2)
740 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
741 ZEND_PARSE_PARAMETERS_END();
743 obj
->type
= BUFFER_READER
;
744 obj
->buffer
= zend_string_copy(zstr
);
746 php_ion_reader_ctor(obj
);
748 ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
750 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
753 ZEND_PARSE_PARAMETERS_NONE();
754 RETURN_STR_COPY(obj
->buffer
);
757 ZEND_METHOD(ion_Reader_Stream_Reader
, __construct
)
759 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
763 ZEND_PARSE_PARAMETERS_START(1, 2)
764 Z_PARAM_RESOURCE(zstream
)
766 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
767 ZEND_PARSE_PARAMETERS_END();
769 obj
->type
= STREAM_READER
;
770 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
772 php_ion_reader_ctor(obj
);
774 ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
776 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
779 ZEND_PARSE_PARAMETERS_NONE();
780 PTR_CHECK(obj
->stream
.ptr
);
782 GC_ADDREF(obj
->stream
.ptr
->res
);
783 RETURN_RES(obj
->stream
.ptr
->res
);
785 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
787 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
791 ZEND_PARSE_PARAMETERS_START(1, 1);
792 Z_PARAM_RESOURCE(zstream
);
793 ZEND_PARSE_PARAMETERS_END();
795 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
797 if (obj
->stream
.ptr
) {
798 zend_list_delete(obj
->stream
.ptr
->res
);
800 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
801 PTR_CHECK(obj
->stream
.ptr
);
804 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
806 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
811 ZEND_PARSE_PARAMETERS_START(1, 2);
812 Z_PARAM_RESOURCE(zstream
);
814 ZEND_PARSE_PARAMETERS_END();
816 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
818 if (obj
->stream
.ptr
) {
819 zend_list_delete(obj
->stream
.ptr
->res
);
821 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
822 PTR_CHECK(obj
->stream
.ptr
);
825 ZEND_METHOD(ion_Writer_Options
, __construct
)
827 php_ion_writer_options
*obj
= php_ion_obj(writer_options
, Z_OBJ_P(ZEND_THIS
));
830 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
831 tabs
= true, small_cntr_inl
= true, suppress_sys
= false, flush
= false;
832 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x400, alloc
= 0x1000;
833 ZEND_PARSE_PARAMETERS_START(0, 16)
835 //public readonly ?\ion\Catalog $catalog = null,
836 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
837 //public readonly ?\ion\Collection $encodingSymbolTable = null,
838 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->col
, ce_Collection
)
839 //public readonly ?\ion\Decimal\Context $decimalContext = null,
840 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
841 //public readonly bool $outputBinary = false,
843 //public readonly bool $compactFloats = false,
844 Z_PARAM_BOOL(compact_floats
)
845 //public readonly bool $escapeNonAscii = false,
847 //public readonly bool $prettyPrint = false,
849 //public readonly bool $indentTabs = true,
851 //public readonly int $indentSize = 2,
853 //public readonly bool $smallContainersInline = true,
854 Z_PARAM_BOOL(small_cntr_inl
)
855 //public readonly bool $suppressSystemValues = false,
856 Z_PARAM_BOOL(suppress_sys
)
857 //public readonly bool $flushEveryValue = false,
859 //public readonly int $maxContainerDepth = 10,
860 Z_PARAM_LONG(max_depth
)
861 //public readonly int $maxAnnotations = 10,
862 Z_PARAM_LONG(max_ann
)
863 //public readonly int $tempBufferSize = 0x400,
865 //public readonly int $allocationPageSize = 0x1000,
867 ZEND_PARSE_PARAMETERS_END();
870 update_property_obj(&obj
->std
, ZEND_STRL("catalog"), obj
->cat
);
871 obj
->opt
.pcatalog
= php_ion_obj(catalog
, obj
->cat
)->cat
;
877 update_property_obj(&obj
->std
, ZEND_STRL("decimalContext"), obj
->dec_ctx
);
878 obj
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, obj
->dec_ctx
)->ctx
;
880 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("outputBinary"),
881 obj
->opt
.output_as_binary
= binary
);
882 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("comactFloats"),
883 obj
->opt
.compact_floats
= compact_floats
);
884 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("excapeNonAscii"),
885 obj
->opt
.escape_all_non_ascii
= escape
);
886 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("prettyPrint"),
887 obj
->opt
.pretty_print
= pretty
);
888 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentTabs"),
889 obj
->opt
.indent_with_tabs
= tabs
);
890 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentSize"),
891 obj
->opt
.indent_size
= indent
);
892 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("smallContainersInline"),
893 obj
->opt
.small_containers_in_line
= small_cntr_inl
);
894 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("suppressSystemValues"),
895 obj
->opt
.supress_system_values
= suppress_sys
);
896 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("flushEveryValue"),
897 obj
->opt
.flush_every_value
= flush
);
898 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxContainerDepth"),
899 obj
->opt
.max_container_depth
= max_depth
);
900 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxAnnotations"),
901 obj
->opt
.max_annotation_count
= max_ann
);
902 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("tempBufferSize"),
903 obj
->opt
.temp_buffer_size
= temp
);
904 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("allocationPageSize"),
905 obj
->opt
.allocation_page_size
= alloc
);
907 ZEND_METHOD(ion_Writer_Writer
, writeNull
)
909 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
912 ZEND_PARSE_PARAMETERS_NONE();
914 ION_CHECK(ion_writer_write_null(obj
->writer
));
916 ZEND_METHOD(ion_Writer_Writer
, writeTypedNull
)
918 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
921 zend_object
*typ_obj
;
922 ZEND_PARSE_PARAMETERS_START(1, 1)
923 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
924 ZEND_PARSE_PARAMETERS_END();
926 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
928 ION_CHECK(ion_writer_write_typed_null(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
930 ZEND_METHOD(ion_Writer_Writer
, writeBool
)
932 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
936 ZEND_PARSE_PARAMETERS_START(1, 1)
938 ZEND_PARSE_PARAMETERS_END();
940 ION_CHECK(ion_writer_write_bool(obj
->writer
, b
));
942 ZEND_METHOD(ion_Writer_Writer
, writeInt
)
944 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
949 ZEND_PARSE_PARAMETERS_START(1, 1)
950 Z_PARAM_STR_OR_LONG(s
, l
)
951 ZEND_PARSE_PARAMETERS_END();
955 ION_CHECK(ion_int_alloc(obj
->writer
, &i
));
956 ION_CHECK(ion_int_from_chars(i
, s
->val
, s
->len
));
957 ION_CHECK(ion_writer_write_ion_int(obj
->writer
, i
));
960 ION_CHECK(ion_writer_write_int64(obj
->writer
, l
));
963 ZEND_METHOD(ion_Writer_Writer
, writeFloat
)
965 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
969 ZEND_PARSE_PARAMETERS_START(1, 1)
971 ZEND_PARSE_PARAMETERS_END();
973 ION_CHECK(ion_writer_write_double(obj
->writer
, d
));
975 ZEND_METHOD(ion_Writer_Writer
, writeDecimal
)
977 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
980 zend_object
*dec_obj
;
981 zend_string
*dec_str
;
982 ZEND_PARSE_PARAMETERS_START(1, 1)
983 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj
, ce_Decimal
, dec_str
)
984 ZEND_PARSE_PARAMETERS_END();
988 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&s
, dec_str
)));
990 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
991 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
994 ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
996 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1000 zend_string
*ts_str
;
1001 ZEND_PARSE_PARAMETERS_START(1, 1)
1002 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
1003 ZEND_PARSE_PARAMETERS_END();
1005 decContext
*ctx
= NULL
;
1007 ctx
= php_ion_obj(reader_options
, obj
->opt
)->opt
.decimal_context
;
1010 ION_TIMESTAMP tmp
= {0};
1013 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1015 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1017 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1019 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1021 ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1023 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1026 zend_object
*sym_obj
;
1027 zend_string
*sym_str
;
1028 ZEND_PARSE_PARAMETERS_START(1, 1)
1029 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1030 ZEND_PARSE_PARAMETERS_END();
1034 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1036 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1038 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1041 ZEND_METHOD(ion_Writer_Writer
, writeString
)
1043 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1047 ZEND_PARSE_PARAMETERS_START(1, 1)
1049 ZEND_PARSE_PARAMETERS_END();
1052 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1054 ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1056 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1060 ZEND_PARSE_PARAMETERS_START(1, 1)
1062 ZEND_PARSE_PARAMETERS_END();
1064 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1066 ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1068 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1072 ZEND_PARSE_PARAMETERS_START(1, 1)
1074 ZEND_PARSE_PARAMETERS_END();
1076 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1078 ZEND_METHOD(ion_Writer_Writer
, startLob
)
1080 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1083 zend_object
*typ_obj
;
1084 ZEND_PARSE_PARAMETERS_START(1, 1)
1085 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1086 ZEND_PARSE_PARAMETERS_END();
1088 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1090 ION_CHECK(ion_writer_start_lob(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1092 ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1094 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1098 ZEND_PARSE_PARAMETERS_START(1, 1)
1100 ZEND_PARSE_PARAMETERS_END();
1102 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1104 ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1106 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1109 ZEND_PARSE_PARAMETERS_NONE();
1111 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1113 ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1115 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1118 zend_object
*typ_obj
;
1119 ZEND_PARSE_PARAMETERS_START(1, 1)
1120 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1121 ZEND_PARSE_PARAMETERS_END();
1123 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1125 ION_CHECK(ion_writer_start_container(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1127 ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1129 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1132 ZEND_PARSE_PARAMETERS_NONE();
1134 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1136 ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1138 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1141 zend_object
*sym_obj
;
1142 zend_string
*sym_str
;
1143 ZEND_PARSE_PARAMETERS_START(1, 1)
1144 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1145 ZEND_PARSE_PARAMETERS_END();
1149 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1151 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1153 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1156 ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1158 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1163 ZEND_PARSE_PARAMETERS_START(1, -1)
1164 Z_PARAM_VARIADIC('+', args
, argc
);
1165 ZEND_PARSE_PARAMETERS_END();
1167 for (unsigned i
= 0; i
< argc
; ++i
) {
1168 switch (Z_TYPE(args
[i
])) {
1171 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1175 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1180 ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1182 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1185 ZEND_PARSE_PARAMETERS_NONE();
1188 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1191 ZEND_METHOD(ion_Writer_Writer
, flush
)
1193 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1196 ZEND_PARSE_PARAMETERS_NONE();
1199 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1200 if (obj
->type
== BUFFER_WRITER
) {
1201 smart_str_0(&obj
->buffer
.str
);
1203 RETURN_LONG(flushed
);
1205 ZEND_METHOD(ion_Writer_Writer
, finish
)
1207 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1210 ZEND_PARSE_PARAMETERS_NONE();
1213 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1214 if (obj
->type
== BUFFER_WRITER
) {
1215 smart_str_0(&obj
->buffer
.str
);
1217 RETURN_LONG(flushed
);
1219 ZEND_METHOD(ion_Writer_Writer
, writeOne
)
1222 ZEND_METHOD(ion_Writer_Writer
, writeAll
)
1225 ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1227 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1231 ZEND_PARSE_PARAMETERS_START(1, 2)
1234 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1235 ZEND_PARSE_PARAMETERS_END();
1237 obj
->type
= BUFFER_WRITER
;
1238 ZVAL_COPY(&obj
->buffer
.val
, ref
);
1239 zval_dtor(Z_REFVAL_P(ref
));
1241 php_ion_writer_ctor(obj
);
1243 ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1245 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1248 ZEND_PARSE_PARAMETERS_NONE();
1250 RETVAL_STR(zend_string_dup(obj
->buffer
.str
.s
, 0));
1252 ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1254 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1258 ZEND_PARSE_PARAMETERS_START(1, 2)
1259 Z_PARAM_RESOURCE(zstream
)
1261 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1262 ZEND_PARSE_PARAMETERS_END();
1264 obj
->type
= STREAM_WRITER
;
1265 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1267 php_ion_writer_ctor(obj
);
1269 ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1271 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1274 ZEND_PARSE_PARAMETERS_NONE();
1275 PTR_CHECK(obj
->stream
.ptr
);
1277 GC_ADDREF(obj
->stream
.ptr
->res
);
1278 RETURN_RES(obj
->stream
.ptr
->res
);
1281 ZEND_METHOD(ion_PHP_Serializer
, __construct
)
1283 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1285 zend_object
*writer_obj
;
1286 zend_bool call_magic
= true;
1287 zend_string
*call_custom
= NULL
;
1288 ZEND_PARSE_PARAMETERS_START(1, 3)
1289 Z_PARAM_OBJ_OF_CLASS(writer_obj
, ce_Writer
)
1291 Z_PARAM_BOOL(call_magic
)
1292 Z_PARAM_STR_OR_NULL(call_custom
)
1293 ZEND_PARSE_PARAMETERS_END();
1295 update_property_obj(obj
, ZEND_STRL("writer"), writer_obj
);
1296 zend_update_property_bool(obj
->ce
, obj
, ZEND_STRL("callMagicSerialize"),
1297 php_ion_obj(writer
, writer_obj
)->php
.call_magic_serialize
= call_magic
);
1299 zend_update_property_str(obj
->ce
, obj
, ZEND_STRL("callCustomSerialize"), call_custom
);
1300 php_ion_obj(writer
, writer_obj
)->php
.custom_serialize
= zend_string_tolower(call_custom
);
1302 zend_update_property_null(obj
->ce
, obj
, ZEND_STRL("callCustomSerialize"));
1305 ZEND_METHOD(ion_PHP_Serializer
, __invoke
)
1307 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1310 ZEND_PARSE_PARAMETERS_START(1, 1)
1312 ZEND_PARSE_PARAMETERS_END();
1315 if ((zwriter
= zend_read_property(obj
->ce
, obj
, ZEND_STRL("writer"), 0, &tmp
))) {
1316 if (Z_OBJCE_P(zwriter
) == ce_Writer_Buffer_Writer
|| Z_OBJCE_P(zwriter
) == ce_Writer_Stream_Writer
) {
1317 php_ion_writer
*writer
= php_ion_obj(writer
, Z_OBJ_P(zwriter
));
1318 php_ion_serialize(writer
, data
, &writer
->buffer
.val
);
1319 RETURN_STR_COPY(writer
->buffer
.str
.s
);
1321 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "serialize", return_value
, data
);
1325 ZEND_METHOD(ion_PHP_Serializer
, serialize
)
1327 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1330 ZEND_PARSE_PARAMETERS_START(1, 1)
1332 ZEND_PARSE_PARAMETERS_END();
1336 ZEND_METHOD(ion_PHP_Unserializer
, __construct
)
1338 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1340 zend_object
*reader_obj
;
1341 zend_bool call_magic
= true;
1342 zend_string
*call_custom
= NULL
;
1343 ZEND_PARSE_PARAMETERS_START(1, 3)
1344 Z_PARAM_OBJ_OF_CLASS(reader_obj
, ce_Reader
)
1346 Z_PARAM_BOOL(call_magic
)
1347 Z_PARAM_STR_OR_NULL(call_custom
)
1348 ZEND_PARSE_PARAMETERS_END();
1350 update_property_obj(obj
, ZEND_STRL("reader"), reader_obj
);
1351 zend_update_property_bool(obj
->ce
, obj
, ZEND_STRL("callMagicUnserialize"),
1352 php_ion_obj(reader
, reader_obj
)->php
.call_magic_unserialize
= call_magic
);
1354 zend_update_property_str(obj
->ce
, obj
, ZEND_STRL("callCustomUnserialize"), call_custom
);
1355 php_ion_obj(reader
, reader_obj
)->php
.custom_unserialize
= zend_string_tolower(call_custom
);
1357 zend_update_property_null(obj
->ce
, obj
, ZEND_STRL("callCustomUnserialize"));
1360 ZEND_METHOD(ion_PHP_Unserializer
, __invoke
)
1362 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1365 if (zend_read_property(obj
->ce
, obj
, ZEND_STRL("reader"), 0, &zreader
)) {
1366 if (Z_OBJCE(zreader
) == ce_Reader_Buffer_Reader
|| Z_OBJCE(zreader
) == ce_Reader_Stream_Reader
) {
1367 php_ion_unserialize(php_ion_obj(reader
, Z_OBJ(zreader
)), NULL
, return_value
);
1369 zend_call_method_with_0_params(obj
, obj
->ce
, NULL
/* TODO */, "unserialize", return_value
);
1373 ZEND_METHOD(ion_PHP_Unserializer
, unserialize
)
1375 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1377 ZEND_PARSE_PARAMETERS_NONE();
1382 ZEND_FUNCTION(ion_serialize
)
1385 zend_object
*zo_opt
= NULL
;
1386 ZEND_PARSE_PARAMETERS_START(1, 2)
1389 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_opt
, ce_Writer_Options
)
1390 ZEND_PARSE_PARAMETERS_END();
1393 object_init_ex(&zwriter
, ce_Writer_Buffer_Writer
);
1395 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ(zwriter
));
1397 obj
->type
= BUFFER_WRITER
;
1398 obj
->php
.call_magic_serialize
= true;
1399 php_ion_writer_ctor(obj
);
1401 php_ion_serialize(obj
, zv
, return_value
);
1402 zval_ptr_dtor(&zwriter
);
1404 ZEND_FUNCTION(ion_unserialize
)
1407 zend_object
*zo_opt
= NULL
;
1408 ZEND_PARSE_PARAMETERS_START(1, 2)
1411 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_opt
, ce_Reader_Options
)
1412 ZEND_PARSE_PARAMETERS_END();
1415 object_init_ex(&zreader
, ce_Reader_Buffer_Reader
);
1417 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ(zreader
));
1419 obj
->type
= BUFFER_READER
;
1420 obj
->buffer
= zend_string_copy(zstr
);
1421 obj
->php
.call_magic_unserialize
= true;
1422 php_ion_reader_ctor(obj
);
1423 php_ion_unserialize(obj
, NULL
, return_value
);
1424 zval_ptr_dtor(&zreader
);
1427 PHP_RINIT_FUNCTION(ion
)
1429 #if defined(ZTS) && defined(COMPILE_DL_ION)
1430 ZEND_TSRMLS_CACHE_UPDATE();
1433 php_ion_globals_serializer_init();
1434 php_ion_globals_unserializer_init();
1438 PHP_RSHUTDOWN_FUNCTION(ion
)
1440 php_ion_globals_serializer_dtor();
1441 php_ion_globals_unserializer_dtor();
1445 php_ion_decl(type
, Type
);
1446 php_ion_decl(symbol
, Symbol
, php_ion_symbol_dtor(obj
));
1447 php_ion_decl(symbol_iloc
, Symbol_ImportLocation
, php_ion_symbol_iloc_dtor(obj
));
1448 php_ion_decl(symbol_table
, Symbol_Table
);
1449 php_ion_decl(decimal
, Decimal
, php_ion_decimal_dtor(obj
));
1450 php_ion_decl(decimal_ctx
, Decimal_Context
);
1451 php_ion_decl(timestamp
, Timestamp
, php_ion_timestamp_dtor(obj
));
1452 php_ion_decl(catalog
, Catalog
);
1453 php_ion_decl(reader_options
, Reader_Options
);
1454 php_ion_decl(reader
, Reader_Reader
, php_ion_reader_dtor(obj
));
1455 php_ion_decl(writer_options
, Writer_Options
);
1456 php_ion_decl(writer
, Writer_Writer
, php_ion_writer_dtor(obj
));
1458 PHP_MINIT_FUNCTION(ion
)
1460 ce_Annotation
= register_class_ion_Annotation();
1462 php_ion_register(type
, Type
);
1463 php_ion_register(symbol
, Symbol
);
1464 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1465 php_ion_register(symbol_table
, Symbol_Table
);
1467 ce_Symbol_System
= register_class_ion_Symbol_System();
1468 ce_Symbol_System_SID
= register_class_ion_Symbol_System_SID();
1470 ce_Collection
= register_class_ion_Collection();
1472 php_ion_register(decimal
, Decimal
);
1473 php_ion_register(decimal_ctx
, Decimal_Context
);
1474 php_ion_register(timestamp
, Timestamp
, php_date_get_date_ce());
1475 php_ion_register(catalog
, Catalog
);
1477 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1479 php_ion_register(reader_options
, Reader_Options
);
1480 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1482 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1483 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1484 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1485 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1487 ce_Writer
= register_class_ion_Writer();
1489 php_ion_register(writer_options
, Writer_Options
);
1490 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1492 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1493 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1494 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1495 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1497 ce_PHP_Serializer
= register_class_ion_PHP_Serializer();
1498 ce_PHP_Unserializer
= register_class_ion_PHP_Unserializer();
1503 PHP_MINFO_FUNCTION(ion
)
1505 php_info_print_table_start();
1506 php_info_print_table_header(2, "ion support", "enabled");
1507 php_info_print_table_end();
1510 PHP_GINIT_FUNCTION(ion
)
1512 memset(ion_globals
, 0, sizeof(*ion_globals
));
1514 PHP_GSHUTDOWN_FUNCTION(ion
)
1518 static zend_module_dep ion_module_deps
[] = {
1519 ZEND_MOD_REQUIRED("spl")
1523 zend_module_entry ion_module_entry
= {
1524 STANDARD_MODULE_HEADER_EX
,
1527 "ion", /* Extension name */
1528 ext_functions
, /* zend_function_entry */
1529 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1530 NULL
, /* PHP_MSHUTDOWN - Module shutdown */
1531 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1532 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1533 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1534 PHP_ION_VERSION
, /* Version */
1535 ZEND_MODULE_GLOBALS(ion
),
1536 PHP_GINIT(ion
), /* PHP_GINIT */
1537 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1539 STANDARD_MODULE_PROPERTIES_EX
1542 #ifdef COMPILE_DL_ION
1544 ZEND_TSRMLS_CACHE_DEFINE()
1546 ZEND_GET_MODULE(ion
)