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(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_Reader_Options
, __construct
)
230 php_ion_reader_options
*opt
= php_ion_obj(reader_options
, Z_OBJ_P(ZEND_THIS
));
231 zend_bool ret_sys_val
= false, skip_validation
= false;
232 zend_long ch_nl
= 0xa, max_depth
= 10, max_ann
, max_ann_buf
= 512,
233 sym_thr
= 0x1000, uval_thr
= 0x1000, chunk_thr
= 0x1000, alloc_pgsz
= 0x1000;
237 ZEND_PARSE_PARAMETERS_START(0, 13)
239 // public readonly ?\ion\Catalog $catalog = null,
240 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cat
, ce_Catalog
)
241 // public readonly ?\ion\Decimal\Context $decimalContext = null,
242 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->dec_ctx
, ce_Decimal_Context
)
243 // public readonly ?\Closure $onContextChange = null,
244 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cb
, zend_ce_closure
);
245 // public readonly bool $returnSystemValues = false,
246 Z_PARAM_BOOL(ret_sys_val
)
247 // public readonly int $newLine = 0xa,
249 // public readonly int $maxContainerDepth = 10,
250 Z_PARAM_LONG(max_depth
)
251 // public readonly int $maxAnnotations = 10,
252 Z_PARAM_LONG(max_ann
)
253 // public readonly int $maxAnnotationBuffered = 512,
254 Z_PARAM_LONG(max_ann_buf
)
255 // public readonly int $symbolThreshold = 4096,
256 Z_PARAM_LONG(sym_thr
)
257 // public readonly int $userValueThreshold = 4096,
258 Z_PARAM_LONG(uval_thr
)
259 // public readonly int $chunkThreshold = 4096,
260 Z_PARAM_LONG(chunk_thr
)
261 // public readonly int $allocationPageSize = 4096,
262 Z_PARAM_LONG(alloc_pgsz
)
263 // public readonly bool $skipCharacterValidation = false,
264 Z_PARAM_BOOL(skip_validation
)
265 ZEND_PARSE_PARAMETERS_END();
267 opt
->opt
.context_change_notifier
= EMPTY_READER_CHANGE_NOTIFIER
;
269 update_property_obj(&opt
->std
, ZEND_STRL("onContextChange"), opt
->cb
);
272 update_property_obj(&opt
->std
, ZEND_STRL("catalog"), opt
->cat
);
273 opt
->opt
.pcatalog
= php_ion_obj(catalog
, opt
->cat
)->cat
;
276 update_property_obj(&opt
->std
, ZEND_STRL("decimalContext"), opt
->dec_ctx
);
277 opt
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, opt
->dec_ctx
)->ctx
;
279 zend_update_property_bool(opt
->std
.ce
, &opt
->std
, ZEND_STRL("returnSystemValues"),
280 opt
->opt
.return_system_values
= ret_sys_val
);
281 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("newLine"),
282 opt
->opt
.new_line_char
= ch_nl
);
283 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxContainerDepth"),
284 opt
->opt
.max_container_depth
= max_depth
);
285 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationCount"),
286 opt
->opt
.max_annotation_count
= max_ann
);
287 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationBuffered"),
288 opt
->opt
.max_annotation_buffered
= max_ann_buf
);
289 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("symbolThreshold"),
290 opt
->opt
.symbol_threshold
= sym_thr
);
291 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("userValueThreshold"),
292 opt
->opt
.user_value_threshold
= uval_thr
);
293 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("chunkThreshold"),
294 opt
->opt
.chunk_threshold
= chunk_thr
);
295 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("allocationPageSize"),
296 opt
->opt
.allocation_page_size
= alloc_pgsz
);
297 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("skipCharacterValidation"),
298 opt
->opt
.skip_character_validation
= skip_validation
);
300 ZEND_METHOD(ion_Reader_Reader
, hasChildren
)
302 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
305 ZEND_PARSE_PARAMETERS_NONE();
308 ION_CHECK(ion_reader_get_type(obj
->reader
, &t
));
309 switch (ION_TYPE_INT(t
)) {
320 ZEND_METHOD(ion_Reader_Reader
, getChildren
)
322 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
325 ZEND_PARSE_PARAMETERS_NONE();
327 ION_CHECK(ion_reader_step_in(obj
->reader
));
329 RETURN_ZVAL(ZEND_THIS
, 1, 0);
331 ZEND_METHOD(ion_Reader_Reader
, rewind
)
333 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
336 ZEND_PARSE_PARAMETERS_NONE();
338 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
340 ZEND_METHOD(ion_Reader_Reader
, next
)
342 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
345 ZEND_PARSE_PARAMETERS_NONE();
347 if (obj
->state
== tid_EOF
) {
349 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
351 ION_CHECK(ion_reader_step_out(obj
->reader
));
354 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
356 ZEND_METHOD(ion_Reader_Reader
, valid
)
358 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
361 ZEND_PARSE_PARAMETERS_NONE();
362 RETURN_BOOL(obj
->state
!= tid_none
&& obj
->state
!= tid_EOF
);
364 ZEND_METHOD(ion_Reader_Reader
, key
)
366 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
369 ZEND_PARSE_PARAMETERS_NONE();
370 RETURN_IONTYPE(obj
->state
);
372 ZEND_METHOD(ion_Reader_Reader
, current
)
374 ZEND_PARSE_PARAMETERS_NONE();
375 RETURN_ZVAL(ZEND_THIS
, 1, 0);
377 ZEND_METHOD(ion_Reader_Reader
, getType
)
379 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
382 ZEND_PARSE_PARAMETERS_NONE();
385 ION_CHECK(ion_reader_get_type(obj
->reader
, &typ
));
388 ZEND_METHOD(ion_Reader_Reader
, hasAnnotations
)
390 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
393 ZEND_PARSE_PARAMETERS_NONE();
396 ION_CHECK(ion_reader_has_any_annotations(obj
->reader
, &has
));
399 ZEND_METHOD(ion_Reader_Reader
, hasAnnotation
)
401 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
404 zend_string
*ann_zstr
;
405 ZEND_PARSE_PARAMETERS_START(1, 1);
406 Z_PARAM_STR(ann_zstr
);
407 ZEND_PARSE_PARAMETERS_END();
411 ION_CHECK(ion_reader_has_annotation(obj
->reader
, ion_string_from_zend(&ann_istr
, ann_zstr
), &has
));
414 ZEND_METHOD(ion_Reader_Reader
, isNull
)
416 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
419 ZEND_PARSE_PARAMETERS_NONE();
422 ION_CHECK(ion_reader_is_null(obj
->reader
, &is
));
425 ZEND_METHOD(ion_Reader_Reader
, isInStruct
)
427 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
430 ZEND_PARSE_PARAMETERS_NONE();
433 ION_CHECK(ion_reader_is_in_struct(obj
->reader
, &is
));
436 ZEND_METHOD(ion_Reader_Reader
, getFieldName
)
438 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
441 ZEND_PARSE_PARAMETERS_NONE();
444 ION_CHECK(ion_reader_get_field_name(obj
->reader
, &name
));
445 RETURN_STRINGL((char *) name
.value
, name
.length
);
447 ZEND_METHOD(ion_Reader_Reader
, getFieldNameSymbol
)
449 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
452 ZEND_PARSE_PARAMETERS_NONE();
455 ION_CHECK(ion_reader_get_field_name_symbol(obj
->reader
, &sym_ptr
));
457 php_ion_symbol_zval(sym_ptr
, return_value
);
459 ZEND_METHOD(ion_Reader_Reader
, getAnnotations
)
461 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
464 ZEND_PARSE_PARAMETERS_NONE();
468 max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
472 ION_STRING
*ptr
= ecalloc(sizeof(*ptr
), max
);
473 iERR err
= ion_reader_get_annotations(obj
->reader
, ptr
, max
, &count
);
475 array_init_size(return_value
, count
);
476 for (int32_t i
= 0; i
< count
; ++i
) {
477 add_next_index_str(return_value
, zend_string_from_ion(&ptr
[i
]));
483 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbols
)
485 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
488 ZEND_PARSE_PARAMETERS_NONE();
490 int32_t count
, max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
491 ION_SYMBOL
*ptr
= ecalloc(sizeof(*ptr
), max
);
492 iERR err
= ion_reader_get_annotation_symbols(obj
->reader
, ptr
, max
, &count
);
494 array_init_size(return_value
, count
);
495 for (int32_t i
= 0; i
< count
; ++i
) {
497 php_ion_symbol_zval(&ptr
[i
], &zsym
);
498 add_next_index_zval(return_value
, &zsym
);
504 ZEND_METHOD(ion_Reader_Reader
, countAnnotations
)
506 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
509 ZEND_PARSE_PARAMETERS_NONE();
512 ION_CHECK(ion_reader_get_annotation_count(obj
->reader
, &sz
));
515 ZEND_METHOD(ion_Reader_Reader
, getAnnotation
)
517 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
521 ZEND_PARSE_PARAMETERS_START(1, 1)
523 ZEND_PARSE_PARAMETERS_END();
526 ION_CHECK(ion_reader_get_an_annotation(obj
->reader
, idx
, &ann
));
527 RETURN_STRINGL((char *) ann
.value
, ann
.length
);
529 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbol
)
531 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
535 ZEND_PARSE_PARAMETERS_START(1, 1)
537 ZEND_PARSE_PARAMETERS_END();
540 ION_CHECK(ion_reader_get_an_annotation_symbol(obj
->reader
, idx
, &sym
));
541 php_ion_symbol_zval(&sym
, return_value
);
543 ZEND_METHOD(ion_Reader_Reader
, readNull
)
545 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
548 ZEND_PARSE_PARAMETERS_NONE();
551 ION_CHECK(ion_reader_read_null(obj
->reader
, &typ
));
552 RETURN_OBJ_COPY(php_ion_type_fetch(typ
));
554 ZEND_METHOD(ion_Reader_Reader
, readBool
)
556 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
559 ZEND_PARSE_PARAMETERS_NONE();
562 ION_CHECK(ion_reader_read_bool(obj
->reader
, &b
));
565 ZEND_METHOD(ion_Reader_Reader
, readInt
)
567 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
570 ZEND_PARSE_PARAMETERS_NONE();
572 php_ion_reader_read_int(obj
->reader
, return_value
);
574 ZEND_METHOD(ion_Reader_Reader
, readFloat
)
576 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
579 ZEND_PARSE_PARAMETERS_NONE();
581 ION_CHECK(ion_reader_read_double(obj
->reader
, &Z_DVAL_P(return_value
)));
583 ZEND_METHOD(ion_Reader_Reader
, readDecimal
)
585 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
588 ZEND_PARSE_PARAMETERS_NONE();
590 object_init_ex(return_value
, ce_Decimal
);
591 php_ion_decimal
*dec
= php_ion_obj(decimal
, Z_OBJ_P(return_value
));
592 ION_CHECK(ion_reader_read_ion_decimal(obj
->reader
, &dec
->dec
));
593 php_ion_decimal_ctor(dec
);
595 ZEND_METHOD(ion_Reader_Reader
, readTimestamp
)
597 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
600 ZEND_PARSE_PARAMETERS_NONE();
602 php_ion_reader_read_timestamp(obj
->reader
, obj
->opt
? &php_ion_obj(reader_options
, obj
->opt
)->opt
: NULL
, return_value
);
604 ZEND_METHOD(ion_Reader_Reader
, readSymbol
)
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_ion_symbol(obj
->reader
, &sym
));
613 php_ion_symbol_zval(&sym
, return_value
);
615 ZEND_METHOD(ion_Reader_Reader
, readString
)
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_string(obj
->reader
, &str
));
624 RETURN_STRINGL((char *) str
.value
, str
.length
);
627 typedef iERR (*read_part_fn
)(ION_READER
*, BYTE
*, SIZE
, SIZE
*);
628 static void read_part(INTERNAL_FUNCTION_PARAMETERS
, read_part_fn fn
)
630 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
635 zend_long len
= 0x1000;
636 ZEND_PARSE_PARAMETERS_START(1, 1)
640 ZEND_PARSE_PARAMETERS_END();
644 if (Z_TYPE_P(ref
) == IS_STRING
&& Z_STRLEN_P(ref
) == len
) {
649 zstr
= zend_string_alloc(len
, 0);
653 ION_CHECK(fn(obj
->reader
, (BYTE
*) zstr
->val
, zstr
->len
, &read
), goto fail
);
655 if (read
< zstr
->len
) {
656 zstr
= zend_string_truncate(zstr
, read
, 0);
662 if (zstr
!= Z_STR_P(ref
)) {
663 zend_string_release(zstr
);
665 ZVAL_EMPTY_STRING(ref
);
668 ZEND_METHOD(ion_Reader_Reader
, readStringPart
)
670 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_partial_string
);
672 ZEND_METHOD(ion_Reader_Reader
, readLob
)
674 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
677 ZEND_PARSE_PARAMETERS_NONE();
679 php_ion_reader_read_lob(obj
->reader
, return_value
);
681 ZEND_METHOD(ion_Reader_Reader
, readLobPart
)
683 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_lob_partial_bytes
);
685 ZEND_METHOD(ion_Reader_Reader
, getPosition
)
687 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
690 ZEND_PARSE_PARAMETERS_NONE();
694 ION_CHECK(ion_reader_get_position(obj
->reader
, &bytes
, &dummy
, &dummy
));
697 ZEND_METHOD(ion_Reader_Reader
, getDepth
)
699 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
702 ZEND_PARSE_PARAMETERS_NONE();
705 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
708 ZEND_METHOD(ion_Reader_Reader
, seek
)
710 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
713 zend_long off
, len
= -1;
714 ZEND_PARSE_PARAMETERS_START(1, 2)
718 ZEND_PARSE_PARAMETERS_END();
720 ION_CHECK(ion_reader_seek(obj
->reader
, off
, len
));
722 ZEND_METHOD(ion_Reader_Reader
, getValueOffset
)
724 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
727 ZEND_PARSE_PARAMETERS_NONE();
730 ION_CHECK(ion_reader_get_value_offset(obj
->reader
, &off
));
733 ZEND_METHOD(ion_Reader_Reader
, getValueLength
)
735 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
738 ZEND_PARSE_PARAMETERS_NONE();
741 ION_CHECK(ion_reader_get_value_length(obj
->reader
, &len
));
744 ZEND_METHOD(ion_Reader_Buffer_Reader
, __construct
)
746 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
750 ZEND_PARSE_PARAMETERS_START(1, 2)
753 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
754 ZEND_PARSE_PARAMETERS_END();
756 obj
->type
= BUFFER_READER
;
757 obj
->buffer
= zend_string_copy(zstr
);
759 php_ion_reader_ctor(obj
);
761 ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
763 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
766 ZEND_PARSE_PARAMETERS_NONE();
767 RETURN_STR_COPY(obj
->buffer
);
770 ZEND_METHOD(ion_Reader_Stream_Reader
, __construct
)
772 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
776 ZEND_PARSE_PARAMETERS_START(1, 2)
777 Z_PARAM_RESOURCE(zstream
)
779 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
780 ZEND_PARSE_PARAMETERS_END();
782 obj
->type
= STREAM_READER
;
783 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
785 php_ion_reader_ctor(obj
);
787 ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
789 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
792 ZEND_PARSE_PARAMETERS_NONE();
793 PTR_CHECK(obj
->stream
.ptr
);
795 GC_ADDREF(obj
->stream
.ptr
->res
);
796 RETURN_RES(obj
->stream
.ptr
->res
);
798 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
800 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
804 ZEND_PARSE_PARAMETERS_START(1, 1);
805 Z_PARAM_RESOURCE(zstream
);
806 ZEND_PARSE_PARAMETERS_END();
808 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
810 if (obj
->stream
.ptr
) {
811 zend_list_delete(obj
->stream
.ptr
->res
);
813 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
814 PTR_CHECK(obj
->stream
.ptr
);
817 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
819 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
824 ZEND_PARSE_PARAMETERS_START(1, 2);
825 Z_PARAM_RESOURCE(zstream
);
827 ZEND_PARSE_PARAMETERS_END();
829 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
831 if (obj
->stream
.ptr
) {
832 zend_list_delete(obj
->stream
.ptr
->res
);
834 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
835 PTR_CHECK(obj
->stream
.ptr
);
838 ZEND_METHOD(ion_Writer_Options
, __construct
)
840 php_ion_writer_options
*obj
= php_ion_obj(writer_options
, Z_OBJ_P(ZEND_THIS
));
843 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
844 tabs
= true, small_cntr_inl
= true, suppress_sys
= false, flush
= false;
845 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x400, alloc
= 0x1000;
846 ZEND_PARSE_PARAMETERS_START(0, 16)
848 //public readonly ?\ion\Catalog $catalog = null,
849 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
850 //public readonly ?\ion\Collection $encodingSymbolTable = null,
851 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->col
, ce_Collection
)
852 //public readonly ?\ion\Decimal\Context $decimalContext = null,
853 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
854 //public readonly bool $outputBinary = false,
856 //public readonly bool $compactFloats = false,
857 Z_PARAM_BOOL(compact_floats
)
858 //public readonly bool $escapeNonAscii = false,
860 //public readonly bool $prettyPrint = false,
862 //public readonly bool $indentTabs = true,
864 //public readonly int $indentSize = 2,
866 //public readonly bool $smallContainersInline = true,
867 Z_PARAM_BOOL(small_cntr_inl
)
868 //public readonly bool $suppressSystemValues = false,
869 Z_PARAM_BOOL(suppress_sys
)
870 //public readonly bool $flushEveryValue = false,
872 //public readonly int $maxContainerDepth = 10,
873 Z_PARAM_LONG(max_depth
)
874 //public readonly int $maxAnnotations = 10,
875 Z_PARAM_LONG(max_ann
)
876 //public readonly int $tempBufferSize = 0x400,
878 //public readonly int $allocationPageSize = 0x1000,
880 ZEND_PARSE_PARAMETERS_END();
883 update_property_obj(&obj
->std
, ZEND_STRL("catalog"), obj
->cat
);
884 obj
->opt
.pcatalog
= php_ion_obj(catalog
, obj
->cat
)->cat
;
890 update_property_obj(&obj
->std
, ZEND_STRL("decimalContext"), obj
->dec_ctx
);
891 obj
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, obj
->dec_ctx
)->ctx
;
893 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("outputBinary"),
894 obj
->opt
.output_as_binary
= binary
);
895 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("comactFloats"),
896 obj
->opt
.compact_floats
= compact_floats
);
897 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("excapeNonAscii"),
898 obj
->opt
.escape_all_non_ascii
= escape
);
899 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("prettyPrint"),
900 obj
->opt
.pretty_print
= pretty
);
901 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentTabs"),
902 obj
->opt
.indent_with_tabs
= tabs
);
903 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentSize"),
904 obj
->opt
.indent_size
= indent
);
905 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("smallContainersInline"),
906 obj
->opt
.small_containers_in_line
= small_cntr_inl
);
907 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("suppressSystemValues"),
908 obj
->opt
.supress_system_values
= suppress_sys
);
909 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("flushEveryValue"),
910 obj
->opt
.flush_every_value
= flush
);
911 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxContainerDepth"),
912 obj
->opt
.max_container_depth
= max_depth
);
913 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxAnnotations"),
914 obj
->opt
.max_annotation_count
= max_ann
);
915 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("tempBufferSize"),
916 obj
->opt
.temp_buffer_size
= temp
);
917 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("allocationPageSize"),
918 obj
->opt
.allocation_page_size
= alloc
);
920 ZEND_METHOD(ion_Writer_Writer
, writeNull
)
922 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
925 ZEND_PARSE_PARAMETERS_NONE();
927 ION_CHECK(ion_writer_write_null(obj
->writer
));
929 ZEND_METHOD(ion_Writer_Writer
, writeTypedNull
)
931 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
934 zend_object
*typ_obj
;
935 ZEND_PARSE_PARAMETERS_START(1, 1)
936 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
937 ZEND_PARSE_PARAMETERS_END();
939 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
941 ION_CHECK(ion_writer_write_typed_null(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
943 ZEND_METHOD(ion_Writer_Writer
, writeBool
)
945 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
949 ZEND_PARSE_PARAMETERS_START(1, 1)
951 ZEND_PARSE_PARAMETERS_END();
953 ION_CHECK(ion_writer_write_bool(obj
->writer
, b
));
955 ZEND_METHOD(ion_Writer_Writer
, writeInt
)
957 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
962 ZEND_PARSE_PARAMETERS_START(1, 1)
963 Z_PARAM_STR_OR_LONG(s
, l
)
964 ZEND_PARSE_PARAMETERS_END();
968 ION_CHECK(ion_int_alloc(obj
->writer
, &i
));
969 ION_CHECK(ion_int_from_chars(i
, s
->val
, s
->len
));
970 ION_CHECK(ion_writer_write_ion_int(obj
->writer
, i
));
973 ION_CHECK(ion_writer_write_int64(obj
->writer
, l
));
976 ZEND_METHOD(ion_Writer_Writer
, writeFloat
)
978 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
982 ZEND_PARSE_PARAMETERS_START(1, 1)
984 ZEND_PARSE_PARAMETERS_END();
986 ION_CHECK(ion_writer_write_double(obj
->writer
, d
));
988 ZEND_METHOD(ion_Writer_Writer
, writeDecimal
)
990 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
993 zend_object
*dec_obj
;
994 zend_string
*dec_str
;
995 ZEND_PARSE_PARAMETERS_START(1, 1)
996 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj
, ce_Decimal
, dec_str
)
997 ZEND_PARSE_PARAMETERS_END();
1001 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&s
, dec_str
)));
1003 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
1004 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
1007 ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
1009 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1012 zend_object
*ts_obj
;
1013 zend_string
*ts_str
;
1014 ZEND_PARSE_PARAMETERS_START(1, 1)
1015 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
1016 ZEND_PARSE_PARAMETERS_END();
1018 decContext
*ctx
= NULL
;
1020 ctx
= php_ion_obj(reader_options
, obj
->opt
)->opt
.decimal_context
;
1023 ION_TIMESTAMP tmp
= {0};
1026 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1028 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1030 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1032 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1034 ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1036 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1039 zend_object
*sym_obj
;
1040 zend_string
*sym_str
;
1041 ZEND_PARSE_PARAMETERS_START(1, 1)
1042 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1043 ZEND_PARSE_PARAMETERS_END();
1047 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1049 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1051 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1054 ZEND_METHOD(ion_Writer_Writer
, writeString
)
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();
1065 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1067 ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1069 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1073 ZEND_PARSE_PARAMETERS_START(1, 1)
1075 ZEND_PARSE_PARAMETERS_END();
1077 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1079 ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1081 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1085 ZEND_PARSE_PARAMETERS_START(1, 1)
1087 ZEND_PARSE_PARAMETERS_END();
1089 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1091 ZEND_METHOD(ion_Writer_Writer
, startLob
)
1093 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1096 zend_object
*typ_obj
;
1097 ZEND_PARSE_PARAMETERS_START(1, 1)
1098 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1099 ZEND_PARSE_PARAMETERS_END();
1101 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1103 ION_CHECK(ion_writer_start_lob(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1105 ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1107 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1111 ZEND_PARSE_PARAMETERS_START(1, 1)
1113 ZEND_PARSE_PARAMETERS_END();
1115 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1117 ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1119 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1122 ZEND_PARSE_PARAMETERS_NONE();
1124 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1126 ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1128 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1131 zend_object
*typ_obj
;
1132 ZEND_PARSE_PARAMETERS_START(1, 1)
1133 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1134 ZEND_PARSE_PARAMETERS_END();
1136 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1138 ION_CHECK(ion_writer_start_container(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1140 ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1142 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1145 ZEND_PARSE_PARAMETERS_NONE();
1147 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1149 ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1151 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1154 zend_object
*sym_obj
;
1155 zend_string
*sym_str
;
1156 ZEND_PARSE_PARAMETERS_START(1, 1)
1157 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1158 ZEND_PARSE_PARAMETERS_END();
1162 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1164 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1166 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1169 ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1171 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1176 ZEND_PARSE_PARAMETERS_START(1, -1)
1177 Z_PARAM_VARIADIC('+', args
, argc
);
1178 ZEND_PARSE_PARAMETERS_END();
1180 for (unsigned i
= 0; i
< argc
; ++i
) {
1181 switch (Z_TYPE(args
[i
])) {
1184 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1188 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1193 ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1195 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1198 ZEND_PARSE_PARAMETERS_NONE();
1201 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1204 ZEND_METHOD(ion_Writer_Writer
, flush
)
1206 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1209 ZEND_PARSE_PARAMETERS_NONE();
1212 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1213 if (obj
->type
== BUFFER_WRITER
) {
1214 smart_str_0(&obj
->buffer
.str
);
1216 RETURN_LONG(flushed
);
1218 ZEND_METHOD(ion_Writer_Writer
, finish
)
1220 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1223 ZEND_PARSE_PARAMETERS_NONE();
1226 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1227 if (obj
->type
== BUFFER_WRITER
) {
1228 smart_str_0(&obj
->buffer
.str
);
1230 RETURN_LONG(flushed
);
1232 ZEND_METHOD(ion_Writer_Writer
, writeOne
)
1235 ZEND_METHOD(ion_Writer_Writer
, writeAll
)
1238 ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1240 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1244 ZEND_PARSE_PARAMETERS_START(1, 2)
1247 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1248 ZEND_PARSE_PARAMETERS_END();
1250 obj
->type
= BUFFER_WRITER
;
1251 ZVAL_COPY(&obj
->buffer
.val
, ref
);
1252 zval_dtor(Z_REFVAL_P(ref
));
1254 php_ion_writer_ctor(obj
);
1256 ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1258 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1261 ZEND_PARSE_PARAMETERS_NONE();
1263 RETVAL_STR(zend_string_dup(obj
->buffer
.str
.s
, 0));
1265 ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1267 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1271 ZEND_PARSE_PARAMETERS_START(1, 2)
1272 Z_PARAM_RESOURCE(zstream
)
1274 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1275 ZEND_PARSE_PARAMETERS_END();
1277 obj
->type
= STREAM_WRITER
;
1278 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1280 php_ion_writer_ctor(obj
);
1282 ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1284 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1287 ZEND_PARSE_PARAMETERS_NONE();
1288 PTR_CHECK(obj
->stream
.ptr
);
1290 GC_ADDREF(obj
->stream
.ptr
->res
);
1291 RETURN_RES(obj
->stream
.ptr
->res
);
1294 ZEND_METHOD(ion_Serializer_PHP
, __construct
)
1296 php_ion_serializer_php
*obj
= php_ion_obj(serializer_php
, Z_OBJ_P(ZEND_THIS
));
1299 ZEND_PARSE_PARAMETERS_START(0, 3)
1301 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1302 Z_PARAM_BOOL(obj
->serializer
.call_magic
)
1303 Z_PARAM_STR_OR_NULL(obj
->serializer
.call_custom
)
1304 ZEND_PARSE_PARAMETERS_END();
1306 php_ion_serializer_php_ctor(obj
);
1308 ZEND_METHOD(ion_Serializer_PHP
, __invoke
)
1310 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1313 ZEND_PARSE_PARAMETERS_START(1, 1)
1315 ZEND_PARSE_PARAMETERS_END();
1317 if (obj
->ce
== ce_Serializer_PHP
) {
1318 // default, fast path
1319 php_ion_serialize(&php_ion_obj(serializer_php
, obj
)->serializer
, data
, return_value
);
1321 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "serialize", return_value
, data
);
1324 ZEND_FUNCTION(ion_serialize
)
1327 zend_object
*zo_ser
= NULL
;
1328 ZEND_PARSE_PARAMETERS_START(1, 2)
1331 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Serializer
)
1332 ZEND_PARSE_PARAMETERS_END();
1334 if (!zo_ser
|| zo_ser
->ce
== ce_Serializer_PHP
) {
1335 // default, fast path
1336 php_ion_serializer
*ser
= zo_ser
? &php_ion_obj(serializer_php
, zo_ser
)->serializer
: NULL
;
1337 php_ion_serialize(ser
, data
, return_value
);
1339 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1342 ZEND_METHOD(ion_Serializer_PHP
, serialize
)
1344 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1347 ZEND_PARSE_PARAMETERS_START(1, 1)
1349 ZEND_PARSE_PARAMETERS_END();
1352 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1355 ZEND_METHOD(ion_Unserializer_PHP
, __construct
)
1357 php_ion_unserializer_php
*obj
= php_ion_obj(unserializer_php
, Z_OBJ_P(ZEND_THIS
));
1359 ZEND_PARSE_PARAMETERS_START(0, 3)
1361 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
1362 Z_PARAM_BOOL(obj
->unserializer
.call_magic
)
1363 Z_PARAM_STR_OR_NULL(obj
->unserializer
.call_custom
)
1364 ZEND_PARSE_PARAMETERS_END();
1366 php_ion_unserializer_php_ctor(obj
);
1368 ZEND_METHOD(ion_Unserializer_PHP
, __invoke
)
1370 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1373 ZEND_PARSE_PARAMETERS_START(1, 1)
1375 ZEND_PARSE_PARAMETERS_END();
1377 if (obj
->ce
== ce_Unserializer_PHP
) {
1378 php_ion_unserialize(&php_ion_obj(unserializer_php
, obj
)->unserializer
, data
, return_value
);
1380 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "unserialize", return_value
, data
);
1383 ZEND_FUNCTION(ion_unserialize
)
1386 zend_object
*zo_ser
= NULL
;
1387 ZEND_PARSE_PARAMETERS_START(1, 2)
1390 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser
, ce_Unserializer
)
1391 ZEND_PARSE_PARAMETERS_END();
1393 if (!zo_ser
|| zo_ser
->ce
== ce_Unserializer_PHP
) {
1394 // default, fast path
1395 php_ion_unserializer
*ser
= zo_ser
? &php_ion_obj(unserializer_php
, zo_ser
)->unserializer
: NULL
;
1396 php_ion_unserialize(ser
, data
, return_value
);
1398 zend_call_method_with_1_params(zo_ser
, NULL
, NULL
, "__invoke", return_value
, data
);
1401 ZEND_METHOD(ion_Unserializer_PHP
, unserialize
)
1403 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1406 ZEND_PARSE_PARAMETERS_START(1, 1)
1408 ZEND_PARSE_PARAMETERS_END();
1411 zend_throw_exception_ex(spl_ce_BadMethodCallException
, 0, "Not implemented");
1414 PHP_RINIT_FUNCTION(ion
)
1416 #if defined(ZTS) && defined(COMPILE_DL_ION)
1417 ZEND_TSRMLS_CACHE_UPDATE();
1420 php_ion_globals_serializer_init();
1421 php_ion_globals_unserializer_init();
1425 PHP_RSHUTDOWN_FUNCTION(ion
)
1427 php_ion_globals_serializer_dtor();
1428 php_ion_globals_unserializer_dtor();
1432 PHP_MINIT_FUNCTION(ion
)
1434 ce_Annotation
= register_class_ion_Annotation();
1436 php_ion_register(type
, Type
);
1437 php_ion_register(symbol
, Symbol
);
1438 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1439 php_ion_register(symbol_table
, Symbol_Table
);
1441 ce_Symbol_System
= register_class_ion_Symbol_System();
1442 ce_Symbol_System_SID
= register_class_ion_Symbol_System_SID();
1444 ce_Collection
= register_class_ion_Collection();
1446 php_ion_register(decimal
, Decimal
);
1447 php_ion_register(decimal_ctx
, Decimal_Context
);
1448 php_ion_register(timestamp
, Timestamp
, php_date_get_date_ce());
1449 ce_Timestamp_Precision
= register_class_ion_Timestamp_Precision();
1450 php_ion_register(catalog
, Catalog
);
1452 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1454 php_ion_register(reader_options
, Reader_Options
);
1455 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1457 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1458 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1459 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1460 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1462 ce_Writer
= register_class_ion_Writer();
1464 php_ion_register(writer_options
, Writer_Options
);
1465 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1467 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1468 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1469 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1470 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1472 ce_Serializer
= register_class_ion_Serializer();
1473 php_ion_register(serializer_php
, Serializer_PHP
, ce_Serializer
);
1474 ce_Unserializer
= register_class_ion_Unserializer();
1475 php_ion_register(unserializer_php
, Unserializer_PHP
, ce_Unserializer
);
1480 PHP_MINFO_FUNCTION(ion
)
1482 php_info_print_table_start();
1483 php_info_print_table_header(2, "ion support", "enabled");
1484 php_info_print_table_end();
1487 PHP_GINIT_FUNCTION(ion
)
1489 memset(ion_globals
, 0, sizeof(*ion_globals
));
1491 PHP_GSHUTDOWN_FUNCTION(ion
)
1495 static zend_module_dep ion_module_deps
[] = {
1496 ZEND_MOD_REQUIRED("spl")
1500 zend_module_entry ion_module_entry
= {
1501 STANDARD_MODULE_HEADER_EX
,
1504 "ion", /* Extension name */
1505 ext_functions
, /* zend_function_entry */
1506 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1507 NULL
, /* PHP_MSHUTDOWN - Module shutdown */
1508 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1509 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1510 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1511 PHP_ION_VERSION
, /* Version */
1512 ZEND_MODULE_GLOBALS(ion
),
1513 PHP_GINIT(ion
), /* PHP_GINIT */
1514 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1516 STANDARD_MODULE_PROPERTIES_EX
1519 #ifdef COMPILE_DL_ION
1521 ZEND_TSRMLS_CACHE_DEFINE()
1523 ZEND_GET_MODULE(ion
)