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
)
41 php_ion_symbol_iloc
*obj
= php_ion_obj(symbol_iloc
, Z_OBJ_P(ZEND_THIS
));
45 ZEND_PARSE_PARAMETERS_START(2, 2)
46 Z_PARAM_STR(obj
->name
)
47 Z_PARAM_LONG(location
)
48 ZEND_PARSE_PARAMETERS_END();
50 obj
->loc
.location
= location
;
51 php_ion_symbol_iloc_ctor(obj
);
53 ZEND_METHOD(ion_Symbol
, __construct
)
55 php_ion_symbol
*obj
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
59 ZEND_PARSE_PARAMETERS_START(0, 3)
61 Z_PARAM_STR_OR_NULL(obj
->value
)
63 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->iloc
, ce_Symbol_ImportLocation
)
64 ZEND_PARSE_PARAMETERS_END();
67 php_ion_symbol_ctor(obj
);
69 ZEND_METHOD(ion_Symbol
, equals
)
71 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
74 zend_object
*other_obj
;
75 ZEND_PARSE_PARAMETERS_START(1, 1)
76 Z_PARAM_OBJ_OF_CLASS(other_obj
, ce_Symbol
)
77 ZEND_PARSE_PARAMETERS_END();
80 iERR err
= ion_symbol_is_equal(
82 &php_ion_obj(symbol
, other_obj
)->sym
, &eq
);
86 ZEND_METHOD(ion_Symbol
, __toString
)
88 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
91 ZEND_PARSE_PARAMETERS_NONE();
94 RETURN_EMPTY_STRING();
96 RETURN_STR_COPY(sym
->value
);
98 ZEND_METHOD(ion_Timestamp
, __construct
)
100 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
104 zend_object
*precision_obj
;
105 zend_string
*fmt
= NULL
, *dt
= NULL
;
107 ZEND_PARSE_PARAMETERS_START(1, 4)
108 Z_PARAM_OBJ_OF_CLASS_OR_LONG(precision_obj
, ce_Timestamp_Precision
, precision
)
110 Z_PARAM_STR_OR_NULL(fmt
)
111 Z_PARAM_STR_OR_NULL(dt
)
113 ZEND_PARSE_PARAMETERS_END();
116 precision
= Z_LVAL_P(zend_enum_fetch_case_value(precision_obj
));
118 php_ion_timestamp_ctor(obj
, precision
, fmt
, dt
, tz
);
120 ZEND_METHOD(ion_Timestamp
, __toString
)
122 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
125 ZEND_PARSE_PARAMETERS_NONE();
129 zend_call_method_with_1_params(&obj
->std
, obj
->std
.ce
, NULL
, "format", return_value
,
130 zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("format"), 0, &fmt
));
132 ZEND_METHOD(ion_Decimal_Context
, __construct
)
134 php_ion_decimal_ctx
*obj
= php_ion_obj(decimal_ctx
, Z_OBJ_P(ZEND_THIS
));
137 zend_long bits
= 128;
138 ZEND_PARSE_PARAMETERS_START(0, 1)
141 ZEND_PARSE_PARAMETERS_END();
143 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("bits"), bits
);
144 php_ion_decimal_ctx_ctor(obj
);
146 ZEND_METHOD(ion_Decimal
, __construct
)
148 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
153 ZEND_PARSE_PARAMETERS_START(1, 2)
154 Z_PARAM_STR_OR_LONG(zstr
, num
)
156 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->ctx
, ce_Decimal_Context
)
157 ZEND_PARSE_PARAMETERS_END();
163 object_init_ex(&zdc
, ce_Decimal_Context
);
164 obj
->ctx
= Z_OBJ(zdc
);
165 php_ion_decimal_ctx_ctor(php_ion_obj(decimal_ctx
, obj
->ctx
));
169 ION_CHECK(ion_decimal_from_string(&obj
->dec
, zstr
->val
,
170 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
));
171 } else if (num
<= INT32_MAX
&& num
>= INT32_MIN
) {
172 ION_CHECK(ion_decimal_from_int32(&obj
->dec
, num
));
173 } else if (num
> 0 && num
<= UINT32_MAX
) {
174 ION_CHECK(ion_decimal_from_uint32(&obj
->dec
, num
));
176 zend_throw_exception_ex(spl_ce_OverflowException
, 0,
177 "Integer value out of bounds: " ZEND_LONG_FMT
" (INT32_MIN < n < UINT32_MAX)", num
);
181 php_ion_decimal_ctor(obj
);
182 OBJ_RELEASE(obj
->ctx
);
184 ZEND_METHOD(ion_Decimal
, equals
)
186 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
189 zend_object
*dec_obj
;
190 ZEND_PARSE_PARAMETERS_START(1, 1)
191 Z_PARAM_OBJ_OF_CLASS(dec_obj
, ce_Decimal
)
192 ZEND_PARSE_PARAMETERS_END();
195 ION_CHECK(ion_decimal_equals(&obj
->dec
, &php_ion_obj(decimal
, dec_obj
)->dec
,
196 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &is
));
199 ZEND_METHOD(ion_Decimal
, __toString
)
201 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
204 ZEND_PARSE_PARAMETERS_NONE();
206 RETURN_STR(php_ion_decimal_to_string(&obj
->dec
));
208 ZEND_METHOD(ion_Decimal
, toInt
)
210 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
213 ZEND_PARSE_PARAMETERS_NONE();
216 php_ion_decimal_to_int(&obj
->dec
, &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
, &l
);
219 ZEND_METHOD(ion_Decimal
, isInt
)
221 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
224 ZEND_PARSE_PARAMETERS_NONE();
226 RETURN_BOOL(ion_decimal_is_integer(&obj
->dec
));
228 ZEND_METHOD(ion_LOB
, __construct
)
231 zend_object
*type
= NULL
;
232 ZEND_PARSE_PARAMETERS_START(1, 2)
235 Z_PARAM_OBJ_OF_CLASS(type
, ce_Type
)
236 ZEND_PARSE_PARAMETERS_END();
239 type
= zend_enum_get_case_cstr(ce_Type
, "CLob");
241 update_property_obj(Z_OBJ_P(ZEND_THIS
), ZEND_STRL("type"), type
);
242 zend_update_property_str(Z_OBJCE_P(ZEND_THIS
), Z_OBJ_P(ZEND_THIS
), ZEND_STRL("value"), value
);
244 ZEND_METHOD(ion_Reader_Options
, __construct
)
246 php_ion_reader_options
*opt
= php_ion_obj(reader_options
, Z_OBJ_P(ZEND_THIS
));
247 zend_bool ret_sys_val
= false, skip_validation
= false;
248 zend_long ch_nl
= 0xa, max_depth
= 10, max_ann
, max_ann_buf
= 512,
249 sym_thr
= 0x1000, uval_thr
= 0x1000, chunk_thr
= 0x1000, alloc_pgsz
= 0x1000;
253 ZEND_PARSE_PARAMETERS_START(0, 13)
255 // public readonly ?\ion\Catalog $catalog = null,
256 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cat
, ce_Catalog
)
257 // public readonly ?\ion\Decimal\Context $decimalContext = null,
258 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->dec_ctx
, ce_Decimal_Context
)
259 // public readonly ?\Closure $onContextChange = null,
260 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cb
, zend_ce_closure
);
261 // public readonly bool $returnSystemValues = false,
262 Z_PARAM_BOOL(ret_sys_val
)
263 // public readonly int $newLine = 0xa,
265 // public readonly int $maxContainerDepth = 10,
266 Z_PARAM_LONG(max_depth
)
267 // public readonly int $maxAnnotations = 10,
268 Z_PARAM_LONG(max_ann
)
269 // public readonly int $maxAnnotationBuffered = 512,
270 Z_PARAM_LONG(max_ann_buf
)
271 // public readonly int $symbolThreshold = 4096,
272 Z_PARAM_LONG(sym_thr
)
273 // public readonly int $userValueThreshold = 4096,
274 Z_PARAM_LONG(uval_thr
)
275 // public readonly int $chunkThreshold = 4096,
276 Z_PARAM_LONG(chunk_thr
)
277 // public readonly int $allocationPageSize = 4096,
278 Z_PARAM_LONG(alloc_pgsz
)
279 // public readonly bool $skipCharacterValidation = false,
280 Z_PARAM_BOOL(skip_validation
)
281 ZEND_PARSE_PARAMETERS_END();
283 opt
->opt
.context_change_notifier
= EMPTY_READER_CHANGE_NOTIFIER
;
285 update_property_obj(&opt
->std
, ZEND_STRL("onContextChange"), opt
->cb
);
288 update_property_obj(&opt
->std
, ZEND_STRL("catalog"), opt
->cat
);
289 opt
->opt
.pcatalog
= php_ion_obj(catalog
, opt
->cat
)->cat
;
292 update_property_obj(&opt
->std
, ZEND_STRL("decimalContext"), opt
->dec_ctx
);
293 opt
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, opt
->dec_ctx
)->ctx
;
295 zend_update_property_bool(opt
->std
.ce
, &opt
->std
, ZEND_STRL("returnSystemValues"),
296 opt
->opt
.return_system_values
= ret_sys_val
);
297 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("newLine"),
298 opt
->opt
.new_line_char
= ch_nl
);
299 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxContainerDepth"),
300 opt
->opt
.max_container_depth
= max_depth
);
301 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationCount"),
302 opt
->opt
.max_annotation_count
= max_ann
);
303 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationBuffered"),
304 opt
->opt
.max_annotation_buffered
= max_ann_buf
);
305 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("symbolThreshold"),
306 opt
->opt
.symbol_threshold
= sym_thr
);
307 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("userValueThreshold"),
308 opt
->opt
.user_value_threshold
= uval_thr
);
309 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("chunkThreshold"),
310 opt
->opt
.chunk_threshold
= chunk_thr
);
311 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("allocationPageSize"),
312 opt
->opt
.allocation_page_size
= alloc_pgsz
);
313 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("skipCharacterValidation"),
314 opt
->opt
.skip_character_validation
= skip_validation
);
316 ZEND_METHOD(ion_Reader_Reader
, hasChildren
)
318 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
321 ZEND_PARSE_PARAMETERS_NONE();
324 ION_CHECK(ion_reader_get_type(obj
->reader
, &t
));
325 switch (ION_TYPE_INT(t
)) {
336 ZEND_METHOD(ion_Reader_Reader
, getChildren
)
338 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
341 ZEND_PARSE_PARAMETERS_NONE();
343 ION_CHECK(ion_reader_step_in(obj
->reader
));
345 RETURN_ZVAL(ZEND_THIS
, 1, 0);
347 ZEND_METHOD(ion_Reader_Reader
, rewind
)
349 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
352 ZEND_PARSE_PARAMETERS_NONE();
354 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
356 ZEND_METHOD(ion_Reader_Reader
, next
)
358 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
361 ZEND_PARSE_PARAMETERS_NONE();
363 if (obj
->state
== tid_EOF
) {
365 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
367 ION_CHECK(ion_reader_step_out(obj
->reader
));
370 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
372 ZEND_METHOD(ion_Reader_Reader
, valid
)
374 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
377 ZEND_PARSE_PARAMETERS_NONE();
378 RETURN_BOOL(obj
->state
!= tid_none
&& obj
->state
!= tid_EOF
);
380 ZEND_METHOD(ion_Reader_Reader
, key
)
382 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
385 ZEND_PARSE_PARAMETERS_NONE();
386 RETURN_IONTYPE(obj
->state
);
388 ZEND_METHOD(ion_Reader_Reader
, current
)
390 ZEND_PARSE_PARAMETERS_NONE();
391 RETURN_ZVAL(ZEND_THIS
, 1, 0);
393 ZEND_METHOD(ion_Reader_Reader
, getType
)
395 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
398 ZEND_PARSE_PARAMETERS_NONE();
401 ION_CHECK(ion_reader_get_type(obj
->reader
, &typ
));
404 ZEND_METHOD(ion_Reader_Reader
, hasAnnotations
)
406 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
409 ZEND_PARSE_PARAMETERS_NONE();
412 ION_CHECK(ion_reader_has_any_annotations(obj
->reader
, &has
));
415 ZEND_METHOD(ion_Reader_Reader
, hasAnnotation
)
417 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
420 zend_string
*ann_zstr
;
421 ZEND_PARSE_PARAMETERS_START(1, 1);
422 Z_PARAM_STR(ann_zstr
);
423 ZEND_PARSE_PARAMETERS_END();
427 ION_CHECK(ion_reader_has_annotation(obj
->reader
, ion_string_from_zend(&ann_istr
, ann_zstr
), &has
));
430 ZEND_METHOD(ion_Reader_Reader
, isNull
)
432 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
435 ZEND_PARSE_PARAMETERS_NONE();
438 ION_CHECK(ion_reader_is_null(obj
->reader
, &is
));
441 ZEND_METHOD(ion_Reader_Reader
, isInStruct
)
443 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
446 ZEND_PARSE_PARAMETERS_NONE();
449 ION_CHECK(ion_reader_is_in_struct(obj
->reader
, &is
));
452 ZEND_METHOD(ion_Reader_Reader
, getFieldName
)
454 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
457 ZEND_PARSE_PARAMETERS_NONE();
460 ION_CHECK(ion_reader_get_field_name(obj
->reader
, &name
));
461 RETURN_STRINGL((char *) name
.value
, name
.length
);
463 ZEND_METHOD(ion_Reader_Reader
, getFieldNameSymbol
)
465 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
468 ZEND_PARSE_PARAMETERS_NONE();
471 ION_CHECK(ion_reader_get_field_name_symbol(obj
->reader
, &sym_ptr
));
473 php_ion_symbol_zval(sym_ptr
, return_value
);
475 ZEND_METHOD(ion_Reader_Reader
, getAnnotations
)
477 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
480 ZEND_PARSE_PARAMETERS_NONE();
484 max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
488 ION_STRING
*ptr
= ecalloc(sizeof(*ptr
), max
);
489 iERR err
= ion_reader_get_annotations(obj
->reader
, ptr
, max
, &count
);
491 array_init_size(return_value
, count
);
492 for (int32_t i
= 0; i
< count
; ++i
) {
493 add_next_index_str(return_value
, zend_string_from_ion(&ptr
[i
]));
499 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbols
)
501 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
504 ZEND_PARSE_PARAMETERS_NONE();
506 int32_t count
, max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
507 ION_SYMBOL
*ptr
= ecalloc(sizeof(*ptr
), max
);
508 iERR err
= ion_reader_get_annotation_symbols(obj
->reader
, ptr
, max
, &count
);
510 array_init_size(return_value
, count
);
511 for (int32_t i
= 0; i
< count
; ++i
) {
513 php_ion_symbol_zval(&ptr
[i
], &zsym
);
514 add_next_index_zval(return_value
, &zsym
);
520 ZEND_METHOD(ion_Reader_Reader
, countAnnotations
)
522 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
525 ZEND_PARSE_PARAMETERS_NONE();
528 ION_CHECK(ion_reader_get_annotation_count(obj
->reader
, &sz
));
531 ZEND_METHOD(ion_Reader_Reader
, getAnnotation
)
533 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
537 ZEND_PARSE_PARAMETERS_START(1, 1)
539 ZEND_PARSE_PARAMETERS_END();
542 ION_CHECK(ion_reader_get_an_annotation(obj
->reader
, idx
, &ann
));
543 RETURN_STRINGL((char *) ann
.value
, ann
.length
);
545 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbol
)
547 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
551 ZEND_PARSE_PARAMETERS_START(1, 1)
553 ZEND_PARSE_PARAMETERS_END();
556 ION_CHECK(ion_reader_get_an_annotation_symbol(obj
->reader
, idx
, &sym
));
557 php_ion_symbol_zval(&sym
, return_value
);
559 ZEND_METHOD(ion_Reader_Reader
, readNull
)
561 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
564 ZEND_PARSE_PARAMETERS_NONE();
567 ION_CHECK(ion_reader_read_null(obj
->reader
, &typ
));
568 RETURN_OBJ_COPY(php_ion_type_fetch(typ
));
570 ZEND_METHOD(ion_Reader_Reader
, readBool
)
572 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
575 ZEND_PARSE_PARAMETERS_NONE();
578 ION_CHECK(ion_reader_read_bool(obj
->reader
, &b
));
581 ZEND_METHOD(ion_Reader_Reader
, readInt
)
583 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
586 ZEND_PARSE_PARAMETERS_NONE();
588 php_ion_reader_read_int(obj
->reader
, return_value
);
590 ZEND_METHOD(ion_Reader_Reader
, readFloat
)
592 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
595 ZEND_PARSE_PARAMETERS_NONE();
597 ION_CHECK(ion_reader_read_double(obj
->reader
, &Z_DVAL_P(return_value
)));
599 ZEND_METHOD(ion_Reader_Reader
, readDecimal
)
601 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
604 ZEND_PARSE_PARAMETERS_NONE();
606 object_init_ex(return_value
, ce_Decimal
);
607 php_ion_decimal
*dec
= php_ion_obj(decimal
, Z_OBJ_P(return_value
));
608 ION_CHECK(ion_reader_read_ion_decimal(obj
->reader
, &dec
->dec
));
609 php_ion_decimal_ctor(dec
);
611 ZEND_METHOD(ion_Reader_Reader
, readTimestamp
)
613 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
616 ZEND_PARSE_PARAMETERS_NONE();
618 php_ion_reader_read_timestamp(obj
->reader
, obj
->opt
? &php_ion_obj(reader_options
, obj
->opt
)->opt
: NULL
, return_value
);
620 ZEND_METHOD(ion_Reader_Reader
, readSymbol
)
622 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
625 ZEND_PARSE_PARAMETERS_NONE();
628 ION_CHECK(ion_reader_read_ion_symbol(obj
->reader
, &sym
));
629 php_ion_symbol_zval(&sym
, return_value
);
631 ZEND_METHOD(ion_Reader_Reader
, readString
)
633 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
636 ZEND_PARSE_PARAMETERS_NONE();
639 ION_CHECK(ion_reader_read_string(obj
->reader
, &str
));
640 RETURN_STRINGL((char *) str
.value
, str
.length
);
643 typedef iERR (*read_part_fn
)(ION_READER
*, BYTE
*, SIZE
, SIZE
*);
644 static void read_part(INTERNAL_FUNCTION_PARAMETERS
, read_part_fn fn
)
646 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
651 zend_long len
= 0x1000;
652 ZEND_PARSE_PARAMETERS_START(1, 1)
656 ZEND_PARSE_PARAMETERS_END();
660 if (Z_TYPE_P(ref
) == IS_STRING
&& Z_STRLEN_P(ref
) == len
) {
665 zstr
= zend_string_alloc(len
, 0);
669 ION_CHECK(fn(obj
->reader
, (BYTE
*) zstr
->val
, zstr
->len
, &read
), goto fail
);
671 if (read
< zstr
->len
) {
672 zstr
= zend_string_truncate(zstr
, read
, 0);
678 if (zstr
!= Z_STR_P(ref
)) {
679 zend_string_release(zstr
);
681 ZVAL_EMPTY_STRING(ref
);
684 ZEND_METHOD(ion_Reader_Reader
, readStringPart
)
686 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_partial_string
);
688 ZEND_METHOD(ion_Reader_Reader
, readLob
)
690 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
693 ZEND_PARSE_PARAMETERS_NONE();
695 php_ion_reader_read_lob(obj
->reader
, return_value
);
697 ZEND_METHOD(ion_Reader_Reader
, readLobPart
)
699 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_lob_partial_bytes
);
701 ZEND_METHOD(ion_Reader_Reader
, getPosition
)
703 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
706 ZEND_PARSE_PARAMETERS_NONE();
710 ION_CHECK(ion_reader_get_position(obj
->reader
, &bytes
, &dummy
, &dummy
));
713 ZEND_METHOD(ion_Reader_Reader
, getDepth
)
715 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
718 ZEND_PARSE_PARAMETERS_NONE();
721 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
724 ZEND_METHOD(ion_Reader_Reader
, seek
)
726 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
729 zend_long off
, len
= -1;
730 ZEND_PARSE_PARAMETERS_START(1, 2)
734 ZEND_PARSE_PARAMETERS_END();
736 ION_CHECK(ion_reader_seek(obj
->reader
, off
, len
));
738 ZEND_METHOD(ion_Reader_Reader
, getValueOffset
)
740 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
743 ZEND_PARSE_PARAMETERS_NONE();
746 ION_CHECK(ion_reader_get_value_offset(obj
->reader
, &off
));
749 ZEND_METHOD(ion_Reader_Reader
, getValueLength
)
751 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
754 ZEND_PARSE_PARAMETERS_NONE();
757 ION_CHECK(ion_reader_get_value_length(obj
->reader
, &len
));
760 ZEND_METHOD(ion_Reader_Buffer_Reader
, __construct
)
762 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
766 ZEND_PARSE_PARAMETERS_START(1, 2)
769 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
770 ZEND_PARSE_PARAMETERS_END();
772 obj
->type
= BUFFER_READER
;
773 obj
->buffer
= zend_string_copy(zstr
);
775 php_ion_reader_ctor(obj
);
777 ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
779 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
782 ZEND_PARSE_PARAMETERS_NONE();
783 RETURN_STR_COPY(obj
->buffer
);
786 ZEND_METHOD(ion_Reader_Stream_Reader
, __construct
)
788 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
792 ZEND_PARSE_PARAMETERS_START(1, 2)
793 Z_PARAM_RESOURCE(zstream
)
795 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
796 ZEND_PARSE_PARAMETERS_END();
798 obj
->type
= STREAM_READER
;
799 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
801 php_ion_reader_ctor(obj
);
803 ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
805 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
808 ZEND_PARSE_PARAMETERS_NONE();
809 PTR_CHECK(obj
->stream
.ptr
);
811 GC_ADDREF(obj
->stream
.ptr
->res
);
812 RETURN_RES(obj
->stream
.ptr
->res
);
814 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
816 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
820 ZEND_PARSE_PARAMETERS_START(1, 1);
821 Z_PARAM_RESOURCE(zstream
);
822 ZEND_PARSE_PARAMETERS_END();
824 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
826 if (obj
->stream
.ptr
) {
827 zend_list_delete(obj
->stream
.ptr
->res
);
829 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
830 PTR_CHECK(obj
->stream
.ptr
);
833 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
835 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
840 ZEND_PARSE_PARAMETERS_START(1, 2);
841 Z_PARAM_RESOURCE(zstream
);
843 ZEND_PARSE_PARAMETERS_END();
845 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
847 if (obj
->stream
.ptr
) {
848 zend_list_delete(obj
->stream
.ptr
->res
);
850 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
851 PTR_CHECK(obj
->stream
.ptr
);
854 ZEND_METHOD(ion_Writer_Options
, __construct
)
856 php_ion_writer_options
*obj
= php_ion_obj(writer_options
, Z_OBJ_P(ZEND_THIS
));
859 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
860 tabs
= true, small_cntr_inl
= true, suppress_sys
= false, flush
= false;
861 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x400, alloc
= 0x1000;
862 ZEND_PARSE_PARAMETERS_START(0, 16)
864 //public readonly ?\ion\Catalog $catalog = null,
865 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
866 //public readonly ?\ion\Collection $encodingSymbolTable = null,
867 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->col
, ce_Collection
)
868 //public readonly ?\ion\Decimal\Context $decimalContext = null,
869 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
870 //public readonly bool $outputBinary = false,
872 //public readonly bool $compactFloats = false,
873 Z_PARAM_BOOL(compact_floats
)
874 //public readonly bool $escapeNonAscii = false,
876 //public readonly bool $prettyPrint = false,
878 //public readonly bool $indentTabs = true,
880 //public readonly int $indentSize = 2,
882 //public readonly bool $smallContainersInline = true,
883 Z_PARAM_BOOL(small_cntr_inl
)
884 //public readonly bool $suppressSystemValues = false,
885 Z_PARAM_BOOL(suppress_sys
)
886 //public readonly bool $flushEveryValue = false,
888 //public readonly int $maxContainerDepth = 10,
889 Z_PARAM_LONG(max_depth
)
890 //public readonly int $maxAnnotations = 10,
891 Z_PARAM_LONG(max_ann
)
892 //public readonly int $tempBufferSize = 0x400,
894 //public readonly int $allocationPageSize = 0x1000,
896 ZEND_PARSE_PARAMETERS_END();
899 update_property_obj(&obj
->std
, ZEND_STRL("catalog"), obj
->cat
);
900 obj
->opt
.pcatalog
= php_ion_obj(catalog
, obj
->cat
)->cat
;
906 update_property_obj(&obj
->std
, ZEND_STRL("decimalContext"), obj
->dec_ctx
);
907 obj
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, obj
->dec_ctx
)->ctx
;
909 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("outputBinary"),
910 obj
->opt
.output_as_binary
= binary
);
911 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("comactFloats"),
912 obj
->opt
.compact_floats
= compact_floats
);
913 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("excapeNonAscii"),
914 obj
->opt
.escape_all_non_ascii
= escape
);
915 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("prettyPrint"),
916 obj
->opt
.pretty_print
= pretty
);
917 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentTabs"),
918 obj
->opt
.indent_with_tabs
= tabs
);
919 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentSize"),
920 obj
->opt
.indent_size
= indent
);
921 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("smallContainersInline"),
922 obj
->opt
.small_containers_in_line
= small_cntr_inl
);
923 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("suppressSystemValues"),
924 obj
->opt
.supress_system_values
= suppress_sys
);
925 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("flushEveryValue"),
926 obj
->opt
.flush_every_value
= flush
);
927 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxContainerDepth"),
928 obj
->opt
.max_container_depth
= max_depth
);
929 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxAnnotations"),
930 obj
->opt
.max_annotation_count
= max_ann
);
931 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("tempBufferSize"),
932 obj
->opt
.temp_buffer_size
= temp
);
933 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("allocationPageSize"),
934 obj
->opt
.allocation_page_size
= alloc
);
936 ZEND_METHOD(ion_Writer_Writer
, writeNull
)
938 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
941 ZEND_PARSE_PARAMETERS_NONE();
943 ION_CHECK(ion_writer_write_null(obj
->writer
));
945 ZEND_METHOD(ion_Writer_Writer
, writeTypedNull
)
947 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
950 zend_object
*typ_obj
;
951 ZEND_PARSE_PARAMETERS_START(1, 1)
952 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
953 ZEND_PARSE_PARAMETERS_END();
955 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
957 ION_CHECK(ion_writer_write_typed_null(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
959 ZEND_METHOD(ion_Writer_Writer
, writeBool
)
961 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
965 ZEND_PARSE_PARAMETERS_START(1, 1)
967 ZEND_PARSE_PARAMETERS_END();
969 ION_CHECK(ion_writer_write_bool(obj
->writer
, b
));
971 ZEND_METHOD(ion_Writer_Writer
, writeInt
)
973 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
978 ZEND_PARSE_PARAMETERS_START(1, 1)
979 Z_PARAM_STR_OR_LONG(s
, l
)
980 ZEND_PARSE_PARAMETERS_END();
984 ION_CHECK(ion_int_alloc(obj
->writer
, &i
));
985 ION_CHECK(ion_int_from_chars(i
, s
->val
, s
->len
));
986 ION_CHECK(ion_writer_write_ion_int(obj
->writer
, i
));
989 ION_CHECK(ion_writer_write_int64(obj
->writer
, l
));
992 ZEND_METHOD(ion_Writer_Writer
, writeFloat
)
994 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
998 ZEND_PARSE_PARAMETERS_START(1, 1)
1000 ZEND_PARSE_PARAMETERS_END();
1002 ION_CHECK(ion_writer_write_double(obj
->writer
, d
));
1004 ZEND_METHOD(ion_Writer_Writer
, writeDecimal
)
1006 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1009 zend_object
*dec_obj
;
1010 zend_string
*dec_str
;
1011 ZEND_PARSE_PARAMETERS_START(1, 1)
1012 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj
, ce_Decimal
, dec_str
)
1013 ZEND_PARSE_PARAMETERS_END();
1017 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&s
, dec_str
)));
1019 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
1020 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
1023 ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
1025 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1028 zend_object
*ts_obj
;
1029 zend_string
*ts_str
;
1030 ZEND_PARSE_PARAMETERS_START(1, 1)
1031 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
1032 ZEND_PARSE_PARAMETERS_END();
1034 decContext
*ctx
= NULL
;
1036 ctx
= php_ion_obj(reader_options
, obj
->opt
)->opt
.decimal_context
;
1039 ION_TIMESTAMP tmp
= {0};
1042 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1044 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1046 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1048 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1050 ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1052 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1055 zend_object
*sym_obj
;
1056 zend_string
*sym_str
;
1057 ZEND_PARSE_PARAMETERS_START(1, 1)
1058 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1059 ZEND_PARSE_PARAMETERS_END();
1063 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1065 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1067 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1070 ZEND_METHOD(ion_Writer_Writer
, writeString
)
1072 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1076 ZEND_PARSE_PARAMETERS_START(1, 1)
1078 ZEND_PARSE_PARAMETERS_END();
1081 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1083 ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1085 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1089 ZEND_PARSE_PARAMETERS_START(1, 1)
1091 ZEND_PARSE_PARAMETERS_END();
1093 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1095 ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1097 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1101 ZEND_PARSE_PARAMETERS_START(1, 1)
1103 ZEND_PARSE_PARAMETERS_END();
1105 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1107 ZEND_METHOD(ion_Writer_Writer
, startLob
)
1109 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1112 zend_object
*typ_obj
;
1113 ZEND_PARSE_PARAMETERS_START(1, 1)
1114 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1115 ZEND_PARSE_PARAMETERS_END();
1117 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1119 ION_CHECK(ion_writer_start_lob(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1121 ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1123 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1127 ZEND_PARSE_PARAMETERS_START(1, 1)
1129 ZEND_PARSE_PARAMETERS_END();
1131 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1133 ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1135 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1138 ZEND_PARSE_PARAMETERS_NONE();
1140 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1142 ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1144 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1147 zend_object
*typ_obj
;
1148 ZEND_PARSE_PARAMETERS_START(1, 1)
1149 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1150 ZEND_PARSE_PARAMETERS_END();
1152 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1154 ION_CHECK(ion_writer_start_container(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1156 ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1158 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1161 ZEND_PARSE_PARAMETERS_NONE();
1163 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1165 ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1167 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1170 zend_object
*sym_obj
;
1171 zend_string
*sym_str
;
1172 ZEND_PARSE_PARAMETERS_START(1, 1)
1173 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1174 ZEND_PARSE_PARAMETERS_END();
1178 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1180 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1182 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1185 ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1187 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1192 ZEND_PARSE_PARAMETERS_START(1, -1)
1193 Z_PARAM_VARIADIC('+', args
, argc
);
1194 ZEND_PARSE_PARAMETERS_END();
1196 for (unsigned i
= 0; i
< argc
; ++i
) {
1197 switch (Z_TYPE(args
[i
])) {
1200 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1204 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1209 ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1211 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1214 ZEND_PARSE_PARAMETERS_NONE();
1217 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1220 ZEND_METHOD(ion_Writer_Writer
, flush
)
1222 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1225 ZEND_PARSE_PARAMETERS_NONE();
1228 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1229 if (obj
->type
== BUFFER_WRITER
) {
1230 smart_str_0(&obj
->buffer
.str
);
1232 RETURN_LONG(flushed
);
1234 ZEND_METHOD(ion_Writer_Writer
, finish
)
1236 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1239 ZEND_PARSE_PARAMETERS_NONE();
1242 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1243 if (obj
->type
== BUFFER_WRITER
) {
1244 smart_str_0(&obj
->buffer
.str
);
1246 RETURN_LONG(flushed
);
1248 ZEND_METHOD(ion_Writer_Writer
, writeOne
)
1251 ZEND_METHOD(ion_Writer_Writer
, writeAll
)
1254 ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1256 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1260 ZEND_PARSE_PARAMETERS_START(1, 2)
1263 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1264 ZEND_PARSE_PARAMETERS_END();
1266 obj
->type
= BUFFER_WRITER
;
1267 ZVAL_COPY(&obj
->buffer
.val
, ref
);
1268 zval_dtor(Z_REFVAL_P(ref
));
1270 php_ion_writer_ctor(obj
);
1272 ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1274 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1277 ZEND_PARSE_PARAMETERS_NONE();
1279 RETVAL_STR(zend_string_dup(obj
->buffer
.str
.s
, 0));
1281 ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1283 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1287 ZEND_PARSE_PARAMETERS_START(1, 2)
1288 Z_PARAM_RESOURCE(zstream
)
1290 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1291 ZEND_PARSE_PARAMETERS_END();
1293 obj
->type
= STREAM_WRITER
;
1294 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1296 php_ion_writer_ctor(obj
);
1298 ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1300 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1303 ZEND_PARSE_PARAMETERS_NONE();
1304 PTR_CHECK(obj
->stream
.ptr
);
1306 GC_ADDREF(obj
->stream
.ptr
->res
);
1307 RETURN_RES(obj
->stream
.ptr
->res
);
1310 ZEND_METHOD(ion_Serializer_PHP
, __construct
)
1312 php_ion_serializer_php
*obj
= php_ion_obj(serializer_php
, Z_OBJ_P(ZEND_THIS
));
1315 ZEND_PARSE_PARAMETERS_START(0, 3)
1317 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1318 Z_PARAM_BOOL(obj
->serializer
.call_magic
)
1319 Z_PARAM_STR_OR_NULL(obj
->serializer
.call_custom
)
1320 ZEND_PARSE_PARAMETERS_END();
1322 php_ion_serializer_php_ctor(obj
);
1324 ZEND_METHOD(ion_Serializer_PHP
, __invoke
)
1326 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1329 ZEND_PARSE_PARAMETERS_START(1, 1)
1331 ZEND_PARSE_PARAMETERS_END();
1333 if (obj
->ce
== ce_Serializer_PHP
) {
1334 // default, fast path
1335 php_ion_serialize(&php_ion_obj(serializer_php
, obj
)->serializer
, data
, return_value
);
1337 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "serialize", return_value
, data
);
1340 ZEND_FUNCTION(ion_serialize
)
1343 zend_object
*zo_ser
= NULL
;
1344 ZEND_PARSE_PARAMETERS_START(1, 2)
1347 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Serializer
)
1348 ZEND_PARSE_PARAMETERS_END();
1350 if (!zo_ser
|| zo_ser
->ce
== ce_Serializer_PHP
) {
1351 // default, fast path
1352 php_ion_serializer
*ser
= zo_ser
? &php_ion_obj(serializer_php
, zo_ser
)->serializer
: NULL
;
1353 php_ion_serialize(ser
, data
, return_value
);
1355 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1358 ZEND_METHOD(ion_Serializer_PHP
, serialize
)
1360 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1363 ZEND_PARSE_PARAMETERS_START(1, 1)
1365 ZEND_PARSE_PARAMETERS_END();
1368 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1371 ZEND_METHOD(ion_Unserializer_PHP
, __construct
)
1373 php_ion_unserializer_php
*obj
= php_ion_obj(unserializer_php
, Z_OBJ_P(ZEND_THIS
));
1375 ZEND_PARSE_PARAMETERS_START(0, 3)
1377 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1378 Z_PARAM_BOOL(obj
->unserializer
.call_magic
)
1379 Z_PARAM_STR_OR_NULL(obj
->unserializer
.call_custom
)
1380 ZEND_PARSE_PARAMETERS_END();
1382 php_ion_unserializer_php_ctor(obj
);
1384 ZEND_METHOD(ion_Unserializer_PHP
, __invoke
)
1386 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1389 ZEND_PARSE_PARAMETERS_START(1, 1)
1391 ZEND_PARSE_PARAMETERS_END();
1393 if (obj
->ce
== ce_Unserializer_PHP
) {
1394 php_ion_unserialize(&php_ion_obj(unserializer_php
, obj
)->unserializer
, data
, return_value
);
1396 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "unserialize", return_value
, data
);
1399 ZEND_FUNCTION(ion_unserialize
)
1402 zend_object
*zo_ser
= NULL
;
1403 ZEND_PARSE_PARAMETERS_START(1, 2)
1406 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Unserializer
)
1407 ZEND_PARSE_PARAMETERS_END();
1409 if (!zo_ser
|| zo_ser
->ce
== ce_Unserializer_PHP
) {
1410 // default, fast path
1411 php_ion_unserializer
*ser
= zo_ser
? &php_ion_obj(unserializer_php
, zo_ser
)->unserializer
: NULL
;
1412 php_ion_unserialize(ser
, data
, return_value
);
1414 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1417 ZEND_METHOD(ion_Unserializer_PHP
, unserialize
)
1419 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1422 ZEND_PARSE_PARAMETERS_START(1, 1)
1424 ZEND_PARSE_PARAMETERS_END();
1427 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1430 PHP_RINIT_FUNCTION(ion
)
1432 #if defined(ZTS) && defined(COMPILE_DL_ION)
1433 ZEND_TSRMLS_CACHE_UPDATE();
1436 php_ion_globals_serializer_init();
1437 php_ion_globals_unserializer_init();
1441 PHP_RSHUTDOWN_FUNCTION(ion
)
1443 php_ion_globals_serializer_dtor();
1444 php_ion_globals_unserializer_dtor();
1448 PHP_MINIT_FUNCTION(ion
)
1450 ce_Annotation
= register_class_ion_Annotation();
1452 php_ion_register(type
, Type
);
1453 php_ion_register(symbol
, Symbol
);
1454 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1455 php_ion_register(symbol_table
, Symbol_Table
);
1457 ce_Symbol_System
= register_class_ion_Symbol_System();
1458 ce_Symbol_System_SID
= register_class_ion_Symbol_System_SID();
1460 ce_Collection
= register_class_ion_Collection();
1461 ce_LOB
= register_class_ion_LOB();
1463 php_ion_register(decimal
, Decimal
);
1464 php_ion_register(decimal_ctx
, Decimal_Context
);
1465 php_ion_register(timestamp
, Timestamp
, php_date_get_date_ce());
1466 ce_Timestamp_Precision
= register_class_ion_Timestamp_Precision();
1467 php_ion_register(catalog
, Catalog
);
1469 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1471 php_ion_register(reader_options
, Reader_Options
);
1472 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1474 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1475 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1476 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1477 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1479 ce_Writer
= register_class_ion_Writer();
1481 php_ion_register(writer_options
, Writer_Options
);
1482 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1484 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1485 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1486 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1487 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1489 ce_Serializer
= register_class_ion_Serializer();
1490 php_ion_register(serializer_php
, Serializer_PHP
, ce_Serializer
);
1491 ce_Unserializer
= register_class_ion_Unserializer();
1492 php_ion_register(unserializer_php
, Unserializer_PHP
, ce_Unserializer
);
1497 PHP_MINFO_FUNCTION(ion
)
1499 php_info_print_table_start();
1500 php_info_print_table_header(2, "ion support", "enabled");
1501 php_info_print_table_end();
1504 PHP_GINIT_FUNCTION(ion
)
1506 memset(ion_globals
, 0, sizeof(*ion_globals
));
1508 PHP_GSHUTDOWN_FUNCTION(ion
)
1512 static zend_module_dep ion_module_deps
[] = {
1513 ZEND_MOD_REQUIRED("spl")
1517 zend_module_entry ion_module_entry
= {
1518 STANDARD_MODULE_HEADER_EX
,
1521 "ion", /* Extension name */
1522 ext_functions
, /* zend_function_entry */
1523 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1524 NULL
, /* PHP_MSHUTDOWN - Module shutdown */
1525 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1526 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1527 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1528 PHP_ION_VERSION
, /* Version */
1529 ZEND_MODULE_GLOBALS(ion
),
1530 PHP_GINIT(ion
), /* PHP_GINIT */
1531 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1533 STANDARD_MODULE_PROPERTIES_EX
1536 #ifdef COMPILE_DL_ION
1538 ZEND_TSRMLS_CACHE_DEFINE()
1540 ZEND_GET_MODULE(ion
)