fix timestamp support
[awesomized/ext-ion] / ion.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: ion |
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 +--------------------------------------------------------------------+
11 */
12
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
16
17 #include "php.h"
18 #include "ext/standard/info.h"
19
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"
25
26 #include "ext/date/php_date.h"
27 #include "ext/spl/spl_exceptions.h"
28 #include "ext/spl/spl_iterators.h"
29
30 #define DECNUMDIGITS 34 /* DECQUAD_Pmax */
31 #include "ionc/ion.h"
32
33 static decContext g_dec_ctx;
34 static ION_DECIMAL g_ion_dec_zend_max, g_ion_dec_zend_min;
35
36 #include "php_ion.h"
37 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
38 { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), default_value },
39 #include "ion_arginfo.h"
40 #include "ion_private.h"
41
42 ZEND_METHOD(ion_Symbol_ImportLocation, __construct)
43 {
44 php_ion_symbol_iloc *obj = php_ion_obj(symbol_iloc, Z_OBJ_P(ZEND_THIS));
45 PTR_CHECK(obj);
46
47 zend_long location;
48 ZEND_PARSE_PARAMETERS_START(2, 2)
49 Z_PARAM_STR(obj->name)
50 Z_PARAM_LONG(location)
51 ZEND_PARSE_PARAMETERS_END();
52
53 obj->loc.location = location;
54 php_ion_symbol_iloc_ctor(obj);
55 }
56 ZEND_METHOD(ion_Symbol, __construct)
57 {
58 php_ion_symbol *obj = php_ion_obj(symbol, Z_OBJ_P(ZEND_THIS));
59 PTR_CHECK(obj);
60
61 zend_long sid = -1;
62 ZEND_PARSE_PARAMETERS_START(0, 3)
63 Z_PARAM_OPTIONAL
64 Z_PARAM_STR_OR_NULL(obj->value)
65 Z_PARAM_LONG(sid)
66 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->iloc, ce_Symbol_ImportLocation)
67 ZEND_PARSE_PARAMETERS_END();
68
69 obj->sym.sid = sid;
70 php_ion_symbol_ctor(obj);
71 }
72 ZEND_METHOD(ion_Symbol, equals)
73 {
74 php_ion_symbol *sym = php_ion_obj(symbol, Z_OBJ_P(ZEND_THIS));
75 OBJ_CHECK(sym);
76
77 zend_object *other_obj;
78 ZEND_PARSE_PARAMETERS_START(1, 1)
79 Z_PARAM_OBJ_OF_CLASS(other_obj, ce_Symbol)
80 ZEND_PARSE_PARAMETERS_END();
81
82 BOOL eq = FALSE;
83 iERR err = ion_symbol_is_equal(
84 &sym->sym,
85 &php_ion_obj(symbol, other_obj)->sym, &eq);
86 ION_CHECK(err);
87 RETVAL_BOOL(eq);
88 }
89 ZEND_METHOD(ion_Symbol, __toString)
90 {
91 php_ion_symbol *sym = php_ion_obj(symbol, Z_OBJ_P(ZEND_THIS));
92 OBJ_CHECK(sym);
93
94 ZEND_PARSE_PARAMETERS_NONE();
95
96 if (!sym->value) {
97 RETURN_EMPTY_STRING();
98 }
99 RETURN_STR_COPY(sym->value);
100 }
101 ZEND_METHOD(ion_Timestamp, __construct)
102 {
103 php_ion_timestamp *obj = php_ion_obj(timestamp, Z_OBJ_P(ZEND_THIS));
104 PTR_CHECK(obj);
105
106 zend_long precision;
107 zend_object *precision_obj;
108 zend_string *fmt = NULL, *dt = NULL;
109 zval *tz = NULL;
110 ZEND_PARSE_PARAMETERS_START(1, 4)
111 Z_PARAM_OBJ_OF_CLASS_OR_LONG(precision_obj, ce_Timestamp_Precision, precision)
112 Z_PARAM_OPTIONAL
113 Z_PARAM_STR_OR_NULL(fmt)
114 Z_PARAM_STR_OR_NULL(dt)
115 Z_PARAM_ZVAL(tz)
116 ZEND_PARSE_PARAMETERS_END();
117
118 if (precision_obj) {
119 precision = Z_LVAL_P(zend_enum_fetch_case_value(precision_obj));
120 }
121 php_ion_timestamp_ctor(obj, precision, fmt, dt, tz);
122 }
123 ZEND_METHOD(ion_Timestamp, __toString)
124 {
125 php_ion_timestamp *obj = php_ion_obj(timestamp, Z_OBJ_P(ZEND_THIS));
126 OBJ_CHECK(obj);
127
128 ZEND_PARSE_PARAMETERS_NONE();
129
130 zval fmt;
131 ZVAL_NULL(&fmt);
132 zend_call_method_with_1_params(&obj->std, obj->std.ce, NULL, "format", return_value,
133 zend_read_property(obj->std.ce, &obj->std, ZEND_STRL("format"), 0, &fmt));
134 }
135 ZEND_METHOD(ion_Decimal_Context, __construct)
136 {
137 php_ion_decimal_ctx *obj = php_ion_obj(decimal_ctx, Z_OBJ_P(ZEND_THIS));
138 PTR_CHECK(obj);
139
140 zend_bool clamp;
141 zend_object *o_round = NULL;
142 zend_long digits, emax, emin, round;
143 ZEND_PARSE_PARAMETERS_START(5, 5)
144 Z_PARAM_LONG(digits)
145 Z_PARAM_LONG(emax)
146 Z_PARAM_LONG(emin)
147 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round, ce_Decimal_Context_Rounding, round)
148 Z_PARAM_BOOL(clamp)
149 ZEND_PARSE_PARAMETERS_END();
150
151 if (o_round) {
152 round = Z_LVAL_P(zend_enum_fetch_case_value(o_round));
153 }
154 php_ion_decimal_ctx_init(&obj->ctx, digits, emax, emin, round, clamp);
155 php_ion_decimal_ctx_ctor(obj, o_round);
156 }
157 static inline void make_decimal_ctx(INTERNAL_FUNCTION_PARAMETERS, int kind)
158 {
159 ZEND_PARSE_PARAMETERS_NONE();
160
161 object_init_ex(return_value, ce_Decimal_Context);
162 php_ion_decimal_ctx *obj = php_ion_obj(decimal_ctx, Z_OBJ_P(return_value));
163 decContextDefault(&obj->ctx, kind);
164 php_ion_decimal_ctx_ctor(obj, NULL);
165 }
166 ZEND_METHOD(ion_Decimal_Context, Dec32)
167 {
168 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, DEC_INIT_DECIMAL32);
169 }
170 ZEND_METHOD(ion_Decimal_Context, Dec64)
171 {
172 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, DEC_INIT_DECIMAL64);
173 }
174 ZEND_METHOD(ion_Decimal_Context, Dec128)
175 {
176 make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, DEC_INIT_DECIMAL128);
177 }
178 ZEND_METHOD(ion_Decimal_Context, DecMax)
179 {
180 zend_object *o_round = NULL;
181 zend_long round = DEC_ROUND_HALF_EVEN;
182 ZEND_PARSE_PARAMETERS_START(0, 1)
183 Z_PARAM_OPTIONAL
184 Z_PARAM_OBJ_OF_CLASS_OR_LONG(o_round, ce_Decimal_Context_Rounding, round)
185 ZEND_PARSE_PARAMETERS_END();
186
187 if (o_round) {
188 round = Z_LVAL_P(zend_enum_fetch_case_value(o_round));
189 }
190 object_init_ex(return_value, ce_Decimal_Context);
191 php_ion_decimal_ctx *obj = php_ion_obj(decimal_ctx, Z_OBJ_P(return_value));
192 php_ion_decimal_ctx_init_max(&obj->ctx, round);
193 php_ion_decimal_ctx_ctor(obj, o_round);
194 }
195 ZEND_METHOD(ion_Decimal, __construct)
196 {
197 php_ion_decimal *obj = php_ion_obj(decimal, Z_OBJ_P(ZEND_THIS));
198 PTR_CHECK(obj);
199
200 zend_long num;
201 zend_string *zstr;
202 ZEND_PARSE_PARAMETERS_START(1, 2)
203 Z_PARAM_STR_OR_LONG(zstr, num)
204 Z_PARAM_OPTIONAL
205 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->ctx, ce_Decimal_Context)
206 ZEND_PARSE_PARAMETERS_END();
207
208 if (obj->ctx) {
209 GC_ADDREF(obj->ctx);
210 } else {
211 zval zdc;
212 object_init_ex(&zdc, ce_Decimal_Context);
213 obj->ctx = Z_OBJ(zdc);
214 php_ion_decimal_ctx_ctor(php_ion_obj(decimal_ctx, obj->ctx), NULL);
215 }
216
217 decContext *ctx = &php_ion_obj(decimal_ctx, obj->ctx)->ctx;
218
219 if (zstr) {
220 ION_CHECK(ion_decimal_from_string(&obj->dec, zstr->val, ctx), OBJ_RELEASE(obj->ctx));
221 } else {
222 php_ion_decimal_from_zend_long(&obj->dec, ctx, num);
223 }
224
225 php_ion_decimal_ctor(obj);
226 OBJ_RELEASE(obj->ctx);
227 }
228 ZEND_METHOD(ion_Decimal, equals)
229 {
230 php_ion_decimal *obj = php_ion_obj(decimal, Z_OBJ_P(ZEND_THIS));
231 PTR_CHECK(obj);
232
233 zend_object *dec_obj;
234 ZEND_PARSE_PARAMETERS_START(1, 1)
235 Z_PARAM_OBJ_OF_CLASS(dec_obj, ce_Decimal)
236 ZEND_PARSE_PARAMETERS_END();
237
238 BOOL is = FALSE;
239 ION_CHECK(ion_decimal_equals(&obj->dec, &php_ion_obj(decimal, dec_obj)->dec,
240 obj->ctx ? &php_ion_obj(decimal_ctx, obj->ctx)->ctx : NULL, &is));
241 RETURN_BOOL(is);
242 }
243 ZEND_METHOD(ion_Decimal, __toString)
244 {
245 php_ion_decimal *obj = php_ion_obj(decimal, Z_OBJ_P(ZEND_THIS));
246 PTR_CHECK(obj);
247
248 ZEND_PARSE_PARAMETERS_NONE();
249
250 RETURN_STR(php_ion_decimal_to_string(&obj->dec));
251 }
252 ZEND_METHOD(ion_Decimal, toInt)
253 {
254 php_ion_decimal *obj = php_ion_obj(decimal, Z_OBJ_P(ZEND_THIS));
255 PTR_CHECK(obj);
256
257 ZEND_PARSE_PARAMETERS_NONE();
258
259 zend_long l;
260 php_ion_decimal_to_zend_long(&obj->dec, &php_ion_obj(decimal_ctx, obj->ctx)->ctx, &l);
261 RETURN_LONG(l);
262 }
263 ZEND_METHOD(ion_Decimal, isInt)
264 {
265 php_ion_decimal *obj = php_ion_obj(decimal, Z_OBJ_P(ZEND_THIS));
266 PTR_CHECK(obj);
267
268 ZEND_PARSE_PARAMETERS_NONE();
269
270 RETURN_BOOL(ion_decimal_is_integer(&obj->dec));
271 }
272 ZEND_METHOD(ion_LOB, __construct)
273 {
274 zend_string *value;
275 zend_object *type = NULL;
276 ZEND_PARSE_PARAMETERS_START(1, 2)
277 Z_PARAM_STR(value)
278 Z_PARAM_OPTIONAL
279 Z_PARAM_OBJ_OF_CLASS(type, ce_Type)
280 ZEND_PARSE_PARAMETERS_END();
281
282 if (!type) {
283 type = zend_enum_get_case_cstr(ce_Type, "CLob");
284 }
285 update_property_obj(Z_OBJ_P(ZEND_THIS), ZEND_STRL("type"), type);
286 zend_update_property_str(Z_OBJCE_P(ZEND_THIS), Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), value);
287 }
288 ZEND_METHOD(ion_Reader_Options, __construct)
289 {
290 php_ion_reader_options *opt = php_ion_obj(reader_options, Z_OBJ_P(ZEND_THIS));
291 zend_bool ret_sys_val = false, skip_validation = false;
292 zend_long ch_nl = 0xa, max_depth = 10, max_ann, max_ann_buf = 512,
293 sym_thr = 0x1000, uval_thr = 0x1000, chunk_thr = 0x1000, alloc_pgsz = 0x1000;
294
295 PTR_CHECK(opt);
296
297 ZEND_PARSE_PARAMETERS_START(0, 13)
298 Z_PARAM_OPTIONAL
299 // public readonly ?\ion\Catalog $catalog = null,
300 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt->cat, ce_Catalog)
301 // public readonly ?\ion\Decimal\Context $decimalContext = null,
302 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt->dec_ctx, ce_Decimal_Context)
303 // public readonly ?\Closure $onContextChange = null,
304 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt->cb, zend_ce_closure);
305 // public readonly bool $returnSystemValues = false,
306 Z_PARAM_BOOL(ret_sys_val)
307 // public readonly int $newLine = 0xa,
308 Z_PARAM_LONG(ch_nl)
309 // public readonly int $maxContainerDepth = 10,
310 Z_PARAM_LONG(max_depth)
311 // public readonly int $maxAnnotations = 10,
312 Z_PARAM_LONG(max_ann)
313 // public readonly int $maxAnnotationBuffered = 512,
314 Z_PARAM_LONG(max_ann_buf)
315 // public readonly int $symbolThreshold = 4096,
316 Z_PARAM_LONG(sym_thr)
317 // public readonly int $userValueThreshold = 4096,
318 Z_PARAM_LONG(uval_thr)
319 // public readonly int $chunkThreshold = 4096,
320 Z_PARAM_LONG(chunk_thr)
321 // public readonly int $allocationPageSize = 4096,
322 Z_PARAM_LONG(alloc_pgsz)
323 // public readonly bool $skipCharacterValidation = false,
324 Z_PARAM_BOOL(skip_validation)
325 ZEND_PARSE_PARAMETERS_END();
326
327 opt->opt.context_change_notifier = EMPTY_READER_CHANGE_NOTIFIER;
328 if (opt->cb) {
329 update_property_obj(&opt->std, ZEND_STRL("onContextChange"), opt->cb);
330 }
331 if (opt->cat) {
332 update_property_obj(&opt->std, ZEND_STRL("catalog"), opt->cat);
333 opt->opt.pcatalog = php_ion_obj(catalog, opt->cat)->cat;
334 }
335 if (opt->dec_ctx) {
336 update_property_obj(&opt->std, ZEND_STRL("decimalContext"), opt->dec_ctx);
337 opt->opt.decimal_context = &php_ion_obj(decimal_ctx, opt->dec_ctx)->ctx;
338 }
339 zend_update_property_bool(opt->std.ce, &opt->std, ZEND_STRL("returnSystemValues"),
340 opt->opt.return_system_values = ret_sys_val);
341 zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("newLine"),
342 opt->opt.new_line_char = ch_nl);
343 zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("maxContainerDepth"),
344 opt->opt.max_container_depth = max_depth);
345 zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("maxAnnotationCount"),
346 opt->opt.max_annotation_count = max_ann);
347 zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("maxAnnotationBuffered"),
348 opt->opt.max_annotation_buffered = max_ann_buf);
349 zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("symbolThreshold"),
350 opt->opt.symbol_threshold = sym_thr);
351 zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("userValueThreshold"),
352 opt->opt.user_value_threshold = uval_thr);
353 zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("chunkThreshold"),
354 opt->opt.chunk_threshold = chunk_thr);
355 zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("allocationPageSize"),
356 opt->opt.allocation_page_size = alloc_pgsz);
357 zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("skipCharacterValidation"),
358 opt->opt.skip_character_validation = skip_validation);
359 }
360 ZEND_METHOD(ion_Reader_Reader, hasChildren)
361 {
362 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
363
364 OBJ_CHECK(obj);
365 ZEND_PARSE_PARAMETERS_NONE();
366
367 ION_TYPE t;
368 ION_CHECK(ion_reader_get_type(obj->reader, &t));
369 switch (ION_TYPE_INT(t)) {
370 case tid_LIST_INT:
371 case tid_SEXP_INT:
372 case tid_STRUCT_INT:
373 RETVAL_TRUE;
374 break;
375 default:
376 RETVAL_FALSE;
377 break;
378 }
379 }
380 ZEND_METHOD(ion_Reader_Reader, getChildren)
381 {
382 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
383 OBJ_CHECK(obj);
384
385 ZEND_PARSE_PARAMETERS_NONE();
386
387 ION_CHECK(ion_reader_step_in(obj->reader));
388
389 RETURN_ZVAL(ZEND_THIS, 1, 0);
390 }
391 ZEND_METHOD(ion_Reader_Reader, rewind)
392 {
393 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
394 OBJ_CHECK(obj);
395
396 ZEND_PARSE_PARAMETERS_NONE();
397
398 ION_CHECK(ion_reader_next(obj->reader, &obj->state));
399 }
400 ZEND_METHOD(ion_Reader_Reader, next)
401 {
402 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
403 OBJ_CHECK(obj);
404
405 ZEND_PARSE_PARAMETERS_NONE();
406
407 if (obj->state == tid_EOF) {
408 SIZE depth = 0;
409 ION_CHECK(ion_reader_get_depth(obj->reader, &depth));
410 if (depth) {
411 ION_CHECK(ion_reader_step_out(obj->reader));
412 }
413 }
414 ION_CHECK(ion_reader_next(obj->reader, &obj->state));
415 }
416 ZEND_METHOD(ion_Reader_Reader, valid)
417 {
418 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
419 OBJ_CHECK(obj);
420
421 ZEND_PARSE_PARAMETERS_NONE();
422 RETURN_BOOL(obj->state != tid_none && obj->state != tid_EOF);
423 }
424 ZEND_METHOD(ion_Reader_Reader, key)
425 {
426 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
427 OBJ_CHECK(obj);
428
429 ZEND_PARSE_PARAMETERS_NONE();
430 RETURN_IONTYPE(obj->state);
431 }
432 ZEND_METHOD(ion_Reader_Reader, current)
433 {
434 ZEND_PARSE_PARAMETERS_NONE();
435 RETURN_ZVAL(ZEND_THIS, 1, 0);
436 }
437 ZEND_METHOD(ion_Reader_Reader, getType)
438 {
439 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
440 OBJ_CHECK(obj);
441
442 ZEND_PARSE_PARAMETERS_NONE();
443
444 ION_TYPE typ;
445 ION_CHECK(ion_reader_get_type(obj->reader, &typ));
446 RETURN_IONTYPE(typ);
447 }
448 ZEND_METHOD(ion_Reader_Reader, hasAnnotations)
449 {
450 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
451 OBJ_CHECK(obj);
452
453 ZEND_PARSE_PARAMETERS_NONE();
454
455 BOOL has = FALSE;
456 ION_CHECK(ion_reader_has_any_annotations(obj->reader, &has));
457 RETURN_BOOL(has);
458 }
459 ZEND_METHOD(ion_Reader_Reader, hasAnnotation)
460 {
461 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
462 OBJ_CHECK(obj);
463
464 zend_string *ann_zstr;
465 ZEND_PARSE_PARAMETERS_START(1, 1);
466 Z_PARAM_STR(ann_zstr);
467 ZEND_PARSE_PARAMETERS_END();
468
469 ION_STRING ann_istr;
470 BOOL has = FALSE;
471 ION_CHECK(ion_reader_has_annotation(obj->reader, ion_string_from_zend(&ann_istr, ann_zstr), &has));
472 RETURN_BOOL(has);
473 }
474 ZEND_METHOD(ion_Reader_Reader, isNull)
475 {
476 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
477 OBJ_CHECK(obj);
478
479 ZEND_PARSE_PARAMETERS_NONE();
480
481 BOOL is = FALSE;
482 ION_CHECK(ion_reader_is_null(obj->reader, &is));
483 RETURN_BOOL(is);
484 }
485 ZEND_METHOD(ion_Reader_Reader, isInStruct)
486 {
487 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
488 OBJ_CHECK(obj);
489
490 ZEND_PARSE_PARAMETERS_NONE();
491
492 BOOL is = FALSE;
493 ION_CHECK(ion_reader_is_in_struct(obj->reader, &is));
494 RETURN_BOOL(is);
495 }
496 ZEND_METHOD(ion_Reader_Reader, getFieldName)
497 {
498 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
499 OBJ_CHECK(obj);
500
501 ZEND_PARSE_PARAMETERS_NONE();
502
503 ION_STRING name;
504 ION_CHECK(ion_reader_get_field_name(obj->reader, &name));
505 RETURN_STRINGL((char *) name.value, name.length);
506 }
507 ZEND_METHOD(ion_Reader_Reader, getFieldNameSymbol)
508 {
509 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
510 OBJ_CHECK(obj);
511
512 ZEND_PARSE_PARAMETERS_NONE();
513
514 ION_SYMBOL *sym_ptr;
515 ION_CHECK(ion_reader_get_field_name_symbol(obj->reader, &sym_ptr));
516
517 php_ion_symbol_zval(sym_ptr, return_value);
518 }
519 ZEND_METHOD(ion_Reader_Reader, getAnnotations)
520 {
521 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
522 OBJ_CHECK(obj);
523
524 ZEND_PARSE_PARAMETERS_NONE();
525
526 int32_t count, max;
527 if (obj->opt) {
528 max = php_ion_obj(reader_options, obj->opt)->opt.max_annotation_count;
529 } else {
530 max = 10;
531 }
532 ION_STRING *ptr = ecalloc(sizeof(*ptr), max);
533 iERR err = ion_reader_get_annotations(obj->reader, ptr, max, &count);
534 if (!err) {
535 array_init_size(return_value, count);
536 for (int32_t i = 0; i < count; ++i) {
537 add_next_index_str(return_value, zend_string_from_ion(&ptr[i]));
538 }
539 }
540 efree(ptr);
541 ION_CHECK(err);
542 }
543 ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbols)
544 {
545 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
546 OBJ_CHECK(obj);
547
548 ZEND_PARSE_PARAMETERS_NONE();
549
550 int32_t count, max = php_ion_obj(reader_options, obj->opt)->opt.max_annotation_count;
551 ION_SYMBOL *ptr = ecalloc(sizeof(*ptr), max);
552 iERR err = ion_reader_get_annotation_symbols(obj->reader, ptr, max, &count);
553 if (!err) {
554 array_init_size(return_value, count);
555 for (int32_t i = 0; i < count; ++i) {
556 zval zsym;
557 php_ion_symbol_zval(&ptr[i], &zsym);
558 add_next_index_zval(return_value, &zsym);
559 }
560 }
561 efree(ptr);
562 ION_CHECK(err);
563 }
564 ZEND_METHOD(ion_Reader_Reader, countAnnotations)
565 {
566 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
567 OBJ_CHECK(obj);
568
569 ZEND_PARSE_PARAMETERS_NONE();
570
571 SIZE sz = 0;
572 ION_CHECK(ion_reader_get_annotation_count(obj->reader, &sz));
573 RETURN_LONG(sz);
574 }
575 ZEND_METHOD(ion_Reader_Reader, getAnnotation)
576 {
577 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
578 OBJ_CHECK(obj);
579
580 zend_long idx;
581 ZEND_PARSE_PARAMETERS_START(1, 1)
582 Z_PARAM_LONG(idx);
583 ZEND_PARSE_PARAMETERS_END();
584
585 ION_STRING ann;
586 ION_CHECK(ion_reader_get_an_annotation(obj->reader, idx, &ann));
587 RETURN_STRINGL((char *) ann.value, ann.length);
588 }
589 ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbol)
590 {
591 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
592 OBJ_CHECK(obj);
593
594 zend_long idx;
595 ZEND_PARSE_PARAMETERS_START(1, 1)
596 Z_PARAM_LONG(idx);
597 ZEND_PARSE_PARAMETERS_END();
598
599 ION_SYMBOL sym;
600 ION_CHECK(ion_reader_get_an_annotation_symbol(obj->reader, idx, &sym));
601 php_ion_symbol_zval(&sym, return_value);
602 }
603 ZEND_METHOD(ion_Reader_Reader, readNull)
604 {
605 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
606 OBJ_CHECK(obj);
607
608 ZEND_PARSE_PARAMETERS_NONE();
609
610 ION_TYPE typ;
611 ION_CHECK(ion_reader_read_null(obj->reader, &typ));
612 RETURN_OBJ_COPY(php_ion_type_fetch(typ));
613 }
614 ZEND_METHOD(ion_Reader_Reader, readBool)
615 {
616 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
617 OBJ_CHECK(obj);
618
619 ZEND_PARSE_PARAMETERS_NONE();
620
621 BOOL b;
622 ION_CHECK(ion_reader_read_bool(obj->reader, &b));
623 RETURN_BOOL(b);
624 }
625 ZEND_METHOD(ion_Reader_Reader, readInt)
626 {
627 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
628 OBJ_CHECK(obj);
629
630 ZEND_PARSE_PARAMETERS_NONE();
631
632 php_ion_reader_read_int(obj->reader, return_value);
633 }
634 ZEND_METHOD(ion_Reader_Reader, readFloat)
635 {
636 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
637 OBJ_CHECK(obj);
638
639 ZEND_PARSE_PARAMETERS_NONE();
640
641 ION_CHECK(ion_reader_read_double(obj->reader, &Z_DVAL_P(return_value)));
642 }
643 ZEND_METHOD(ion_Reader_Reader, readDecimal)
644 {
645 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
646 OBJ_CHECK(obj);
647
648 ZEND_PARSE_PARAMETERS_NONE();
649
650 object_init_ex(return_value, ce_Decimal);
651 php_ion_decimal *dec = php_ion_obj(decimal, Z_OBJ_P(return_value));
652 ION_CHECK(ion_reader_read_ion_decimal(obj->reader, &dec->dec));
653 php_ion_decimal_ctor(dec);
654 }
655 ZEND_METHOD(ion_Reader_Reader, readTimestamp)
656 {
657 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
658 OBJ_CHECK(obj);
659
660 ZEND_PARSE_PARAMETERS_NONE();
661
662 php_ion_reader_read_timestamp(obj->reader, obj->opt ? &php_ion_obj(reader_options, obj->opt)->opt : NULL, return_value);
663 }
664 ZEND_METHOD(ion_Reader_Reader, readSymbol)
665 {
666 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
667 OBJ_CHECK(obj);
668
669 ZEND_PARSE_PARAMETERS_NONE();
670
671 ION_SYMBOL sym;
672 ION_CHECK(ion_reader_read_ion_symbol(obj->reader, &sym));
673 php_ion_symbol_zval(&sym, return_value);
674 }
675 ZEND_METHOD(ion_Reader_Reader, readString)
676 {
677 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
678 OBJ_CHECK(obj);
679
680 ZEND_PARSE_PARAMETERS_NONE();
681
682 ION_STRING str;
683 ION_CHECK(ion_reader_read_string(obj->reader, &str));
684 RETURN_STRINGL((char *) str.value, str.length);
685 }
686
687 typedef iERR (*read_part_fn)(ION_READER *, BYTE *, SIZE, SIZE *);
688 static void read_part(INTERNAL_FUNCTION_PARAMETERS, read_part_fn fn)
689 {
690 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
691 OBJ_CHECK(obj);
692
693 zval *ref;
694 zend_string *zstr;
695 zend_long len = 0x1000;
696 ZEND_PARSE_PARAMETERS_START(1, 1)
697 Z_PARAM_ZVAL(ref)
698 Z_PARAM_OPTIONAL
699 Z_PARAM_LONG(len)
700 ZEND_PARSE_PARAMETERS_END();
701
702 ZVAL_DEREF(ref);
703
704 if (Z_TYPE_P(ref) == IS_STRING && Z_STRLEN_P(ref) == len) {
705 /* reuse */
706 zstr = Z_STR_P(ref);
707 } else {
708 zval_dtor(ref);
709 zstr = zend_string_alloc(len, 0);
710 }
711
712 SIZE read = 0;
713 ION_CHECK(fn(obj->reader, (BYTE *) zstr->val, zstr->len, &read), goto fail);
714 if (read > 0) {
715 if (read < zstr->len) {
716 zstr = zend_string_truncate(zstr, read, 0);
717 }
718 ZVAL_STR(ref, zstr);
719 RETURN_TRUE;
720 }
721 fail:
722 if (zstr != Z_STR_P(ref)) {
723 zend_string_release(zstr);
724 }
725 ZVAL_EMPTY_STRING(ref);
726 RETURN_FALSE;
727 }
728 ZEND_METHOD(ion_Reader_Reader, readStringPart)
729 {
730 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU, ion_reader_read_partial_string);
731 }
732 ZEND_METHOD(ion_Reader_Reader, readLob)
733 {
734 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
735 OBJ_CHECK(obj);
736
737 ZEND_PARSE_PARAMETERS_NONE();
738
739 php_ion_reader_read_lob(obj->reader, return_value);
740 }
741 ZEND_METHOD(ion_Reader_Reader, readLobPart)
742 {
743 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU, ion_reader_read_lob_partial_bytes);
744 }
745 ZEND_METHOD(ion_Reader_Reader, getPosition)
746 {
747 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
748 OBJ_CHECK(obj);
749
750 ZEND_PARSE_PARAMETERS_NONE();
751
752 int64_t bytes = 0;
753 int32_t dummy;
754 ION_CHECK(ion_reader_get_position(obj->reader, &bytes, &dummy, &dummy));
755 RETURN_LONG(bytes);
756 }
757 ZEND_METHOD(ion_Reader_Reader, getDepth)
758 {
759 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
760 OBJ_CHECK(obj);
761
762 ZEND_PARSE_PARAMETERS_NONE();
763
764 SIZE depth = 0;
765 ION_CHECK(ion_reader_get_depth(obj->reader, &depth));
766 RETURN_LONG(depth);
767 }
768 ZEND_METHOD(ion_Reader_Reader, seek)
769 {
770 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
771 OBJ_CHECK(obj);
772
773 zend_long off, len = -1;
774 ZEND_PARSE_PARAMETERS_START(1, 2)
775 Z_PARAM_LONG(off)
776 Z_PARAM_OPTIONAL
777 Z_PARAM_LONG(len)
778 ZEND_PARSE_PARAMETERS_END();
779
780 ION_CHECK(ion_reader_seek(obj->reader, off, len));
781 }
782 ZEND_METHOD(ion_Reader_Reader, getValueOffset)
783 {
784 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
785 OBJ_CHECK(obj);
786
787 ZEND_PARSE_PARAMETERS_NONE();
788
789 POSITION off = 0;
790 ION_CHECK(ion_reader_get_value_offset(obj->reader, &off));
791 RETURN_LONG(off);
792 }
793 ZEND_METHOD(ion_Reader_Reader, getValueLength)
794 {
795 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
796 OBJ_CHECK(obj);
797
798 ZEND_PARSE_PARAMETERS_NONE();
799
800 SIZE len = 0;
801 ION_CHECK(ion_reader_get_value_length(obj->reader, &len));
802 RETURN_LONG(len);
803 }
804 ZEND_METHOD(ion_Reader_Buffer_Reader, __construct)
805 {
806 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
807 PTR_CHECK(obj);
808
809 zend_string *zstr;
810 ZEND_PARSE_PARAMETERS_START(1, 2)
811 Z_PARAM_STR(zstr)
812 Z_PARAM_OPTIONAL
813 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->opt, ce_Reader_Options)
814 ZEND_PARSE_PARAMETERS_END();
815
816 obj->type = BUFFER_READER;
817 obj->buffer = zend_string_copy(zstr);
818
819 php_ion_reader_ctor(obj);
820 }
821 ZEND_METHOD(ion_Reader_Buffer_Reader, getBuffer)
822 {
823 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
824 OBJ_CHECK(obj);
825
826 ZEND_PARSE_PARAMETERS_NONE();
827 RETURN_STR_COPY(obj->buffer);
828 }
829
830 ZEND_METHOD(ion_Reader_Stream_Reader, __construct)
831 {
832 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
833 PTR_CHECK(obj);
834
835 zval *zstream;
836 ZEND_PARSE_PARAMETERS_START(1, 2)
837 Z_PARAM_RESOURCE(zstream)
838 Z_PARAM_OPTIONAL
839 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->opt, ce_Reader_Options)
840 ZEND_PARSE_PARAMETERS_END();
841
842 obj->type = STREAM_READER;
843 php_stream_from_zval_no_verify(obj->stream.ptr, zstream);
844
845 php_ion_reader_ctor(obj);
846 }
847 ZEND_METHOD(ion_Reader_Stream_Reader, getStream)
848 {
849 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
850 OBJ_CHECK(obj);
851
852 ZEND_PARSE_PARAMETERS_NONE();
853 PTR_CHECK(obj->stream.ptr);
854
855 GC_ADDREF(obj->stream.ptr->res);
856 RETURN_RES(obj->stream.ptr->res);
857 }
858 ZEND_METHOD(ion_Reader_Stream_Reader, resetStream)
859 {
860 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
861 OBJ_CHECK(obj);
862
863 zval *zstream;
864 ZEND_PARSE_PARAMETERS_START(1, 1);
865 Z_PARAM_RESOURCE(zstream);
866 ZEND_PARSE_PARAMETERS_END();
867
868 ION_CHECK(ion_reader_reset_stream(&obj->reader, obj, php_ion_reader_stream_handler));
869
870 if (obj->stream.ptr) {
871 zend_list_delete(obj->stream.ptr->res);
872 }
873 php_stream_from_zval_no_verify(obj->stream.ptr, zstream);
874 PTR_CHECK(obj->stream.ptr);
875 Z_ADDREF_P(zstream);
876 }
877 ZEND_METHOD(ion_Reader_Stream_Reader, resetStreamWithLength)
878 {
879 php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
880 OBJ_CHECK(obj);
881
882 zval *zstream;
883 zend_long length;
884 ZEND_PARSE_PARAMETERS_START(1, 2);
885 Z_PARAM_RESOURCE(zstream);
886 Z_PARAM_LONG(length)
887 ZEND_PARSE_PARAMETERS_END();
888
889 ION_CHECK(ion_reader_reset_stream_with_length(&obj->reader, obj, php_ion_reader_stream_handler, length));
890
891 if (obj->stream.ptr) {
892 zend_list_delete(obj->stream.ptr->res);
893 }
894 php_stream_from_zval_no_verify(obj->stream.ptr, zstream);
895 PTR_CHECK(obj->stream.ptr);
896 Z_ADDREF_P(zstream);
897 }
898 ZEND_METHOD(ion_Writer_Options, __construct)
899 {
900 php_ion_writer_options *obj = php_ion_obj(writer_options, Z_OBJ_P(ZEND_THIS));
901 PTR_CHECK(obj);
902
903 zend_bool binary = false, compact_floats = false, escape = false, pretty = false,
904 tabs = true, small_cntr_inl = true, suppress_sys = false, flush = false;
905 zend_long indent = 2, max_depth = 10, max_ann = 10, temp = 0x400, alloc = 0x1000;
906 ZEND_PARSE_PARAMETERS_START(0, 16)
907 Z_PARAM_OPTIONAL
908 //public readonly ?\ion\Catalog $catalog = null,
909 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->cat, ce_Catalog)
910 //public readonly ?\ion\Collection $encodingSymbolTable = null,
911 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->col, ce_Collection)
912 //public readonly ?\ion\Decimal\Context $decimalContext = null,
913 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->dec_ctx, ce_Decimal_Context)
914 //public readonly bool $outputBinary = false,
915 Z_PARAM_BOOL(binary)
916 //public readonly bool $compactFloats = false,
917 Z_PARAM_BOOL(compact_floats)
918 //public readonly bool $escapeNonAscii = false,
919 Z_PARAM_BOOL(escape)
920 //public readonly bool $prettyPrint = false,
921 Z_PARAM_BOOL(pretty)
922 //public readonly bool $indentTabs = true,
923 Z_PARAM_BOOL(tabs)
924 //public readonly int $indentSize = 2,
925 Z_PARAM_LONG(indent)
926 //public readonly bool $smallContainersInline = true,
927 Z_PARAM_BOOL(small_cntr_inl)
928 //public readonly bool $suppressSystemValues = false,
929 Z_PARAM_BOOL(suppress_sys)
930 //public readonly bool $flushEveryValue = false,
931 Z_PARAM_BOOL(flush)
932 //public readonly int $maxContainerDepth = 10,
933 Z_PARAM_LONG(max_depth)
934 //public readonly int $maxAnnotations = 10,
935 Z_PARAM_LONG(max_ann)
936 //public readonly int $tempBufferSize = 0x400,
937 Z_PARAM_LONG(temp)
938 //public readonly int $allocationPageSize = 0x1000,
939 Z_PARAM_LONG(alloc)
940 ZEND_PARSE_PARAMETERS_END();
941
942 if (obj->cat) {
943 update_property_obj(&obj->std, ZEND_STRL("catalog"), obj->cat);
944 obj->opt.pcatalog = php_ion_obj(catalog, obj->cat)->cat;
945 }
946 if (obj->col) {
947 // TODO
948 }
949 if (obj->dec_ctx) {
950 update_property_obj(&obj->std, ZEND_STRL("decimalContext"), obj->dec_ctx);
951 obj->opt.decimal_context = &php_ion_obj(decimal_ctx, obj->dec_ctx)->ctx;
952 }
953 zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("outputBinary"),
954 obj->opt.output_as_binary = binary);
955 zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("comactFloats"),
956 obj->opt.compact_floats = compact_floats);
957 zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("excapeNonAscii"),
958 obj->opt.escape_all_non_ascii = escape);
959 zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("prettyPrint"),
960 obj->opt.pretty_print = pretty);
961 zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("indentTabs"),
962 obj->opt.indent_with_tabs = tabs);
963 zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("indentSize"),
964 obj->opt.indent_size = indent);
965 zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("smallContainersInline"),
966 obj->opt.small_containers_in_line = small_cntr_inl);
967 zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("suppressSystemValues"),
968 obj->opt.supress_system_values = suppress_sys);
969 zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("flushEveryValue"),
970 obj->opt.flush_every_value = flush);
971 zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("maxContainerDepth"),
972 obj->opt.max_container_depth = max_depth);
973 zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("maxAnnotations"),
974 obj->opt.max_annotation_count = max_ann);
975 zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("tempBufferSize"),
976 obj->opt.temp_buffer_size = temp);
977 zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("allocationPageSize"),
978 obj->opt.allocation_page_size = alloc);
979 }
980 ZEND_METHOD(ion_Writer_Writer, writeNull)
981 {
982 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
983 OBJ_CHECK(obj);
984
985 ZEND_PARSE_PARAMETERS_NONE();
986
987 ION_CHECK(ion_writer_write_null(obj->writer));
988 }
989 ZEND_METHOD(ion_Writer_Writer, writeTypedNull)
990 {
991 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
992 OBJ_CHECK(obj);
993
994 zend_object *typ_obj;
995 ZEND_PARSE_PARAMETERS_START(1, 1)
996 Z_PARAM_OBJ_OF_CLASS(typ_obj, ce_Type)
997 ZEND_PARSE_PARAMETERS_END();
998
999 php_ion_type *typ = php_ion_obj(type, typ_obj);
1000 OBJ_CHECK(typ);
1001 ION_CHECK(ion_writer_write_typed_null(obj->writer, php_ion_obj(type, typ)->typ));
1002 }
1003 ZEND_METHOD(ion_Writer_Writer, writeBool)
1004 {
1005 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1006 OBJ_CHECK(obj);
1007
1008 zend_bool b;
1009 ZEND_PARSE_PARAMETERS_START(1, 1)
1010 Z_PARAM_BOOL(b)
1011 ZEND_PARSE_PARAMETERS_END();
1012
1013 ION_CHECK(ion_writer_write_bool(obj->writer, b));
1014 }
1015 ZEND_METHOD(ion_Writer_Writer, writeInt)
1016 {
1017 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1018 OBJ_CHECK(obj);
1019
1020 zend_long l;
1021 zend_string *s;
1022 ZEND_PARSE_PARAMETERS_START(1, 1)
1023 Z_PARAM_STR_OR_LONG(s, l)
1024 ZEND_PARSE_PARAMETERS_END();
1025
1026 if (s) {
1027 ION_INT *i;
1028 ION_CHECK(ion_int_alloc(obj->writer, &i));
1029 ION_CHECK(ion_int_from_chars(i, s->val, s->len));
1030 ION_CHECK(ion_writer_write_ion_int(obj->writer, i));
1031 ion_int_free(i);
1032 } else {
1033 ION_CHECK(ion_writer_write_int64(obj->writer, l));
1034 }
1035 }
1036 ZEND_METHOD(ion_Writer_Writer, writeFloat)
1037 {
1038 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1039 OBJ_CHECK(obj);
1040
1041 double d;
1042 ZEND_PARSE_PARAMETERS_START(1, 1)
1043 Z_PARAM_DOUBLE(d)
1044 ZEND_PARSE_PARAMETERS_END();
1045
1046 ION_CHECK(ion_writer_write_double(obj->writer, d));
1047 }
1048 ZEND_METHOD(ion_Writer_Writer, writeDecimal)
1049 {
1050 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1051 OBJ_CHECK(obj);
1052
1053 zend_object *dec_obj;
1054 zend_string *dec_str;
1055 ZEND_PARSE_PARAMETERS_START(1, 1)
1056 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj, ce_Decimal, dec_str)
1057 ZEND_PARSE_PARAMETERS_END();
1058
1059 if (dec_str) {
1060 ION_STRING s;
1061 ION_CHECK(ion_writer_write_string(obj->writer, ion_string_from_zend(&s, dec_str)));
1062 } else {
1063 php_ion_decimal *dec = php_ion_obj(decimal, dec_obj);
1064 ION_CHECK(ion_writer_write_ion_decimal(obj->writer, &dec->dec));
1065 }
1066 }
1067 ZEND_METHOD(ion_Writer_Writer, writeTimestamp)
1068 {
1069 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1070 OBJ_CHECK(obj);
1071
1072 zend_object *ts_obj;
1073 zend_string *ts_str;
1074 ZEND_PARSE_PARAMETERS_START(1, 1)
1075 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj, ce_Timestamp, ts_str)
1076 ZEND_PARSE_PARAMETERS_END();
1077
1078 decContext *ctx = NULL;
1079 if (obj->opt) {
1080 ctx = php_ion_obj(reader_options, obj->opt)->opt.decimal_context;
1081 }
1082
1083 ION_TIMESTAMP tmp = {0};
1084 if (ts_str) {
1085 SIZE used;
1086 ION_CHECK(ion_timestamp_parse(&tmp, ts_str->val, ts_str->len, &used, ctx));
1087 } else {
1088 php_ion_timestamp *ts = php_ion_obj(timestamp, ts_obj);
1089 OBJ_CHECK(ts);
1090 ion_timestamp_from_php(&tmp, ts, ctx);
1091 }
1092 ION_CHECK(ion_writer_write_timestamp(obj->writer, &tmp));
1093 }
1094 ZEND_METHOD(ion_Writer_Writer, writeSymbol)
1095 {
1096 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1097 OBJ_CHECK(obj);
1098
1099 zend_object *sym_obj;
1100 zend_string *sym_str;
1101 ZEND_PARSE_PARAMETERS_START(1, 1)
1102 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj, ce_Symbol, sym_str);
1103 ZEND_PARSE_PARAMETERS_END();
1104
1105 if (sym_str) {
1106 ION_STRING is;
1107 ION_CHECK(ion_writer_write_symbol(obj->writer, ion_string_from_zend(&is, sym_str)));
1108 } else {
1109 php_ion_symbol *sym = php_ion_obj(symbol, sym_obj);
1110 PTR_CHECK(sym);
1111 ION_CHECK(ion_writer_write_ion_symbol(obj->writer, &sym->sym));
1112 }
1113 }
1114 ZEND_METHOD(ion_Writer_Writer, writeString)
1115 {
1116 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1117 OBJ_CHECK(obj);
1118
1119 zend_string *str;
1120 ZEND_PARSE_PARAMETERS_START(1, 1)
1121 Z_PARAM_STR(str)
1122 ZEND_PARSE_PARAMETERS_END();
1123
1124 ION_STRING is;
1125 ION_CHECK(ion_writer_write_string(obj->writer, ion_string_from_zend(&is, str)));
1126 }
1127 ZEND_METHOD(ion_Writer_Writer, writeCLob)
1128 {
1129 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1130 OBJ_CHECK(obj);
1131
1132 zend_string *str;
1133 ZEND_PARSE_PARAMETERS_START(1, 1)
1134 Z_PARAM_STR(str)
1135 ZEND_PARSE_PARAMETERS_END();
1136
1137 ION_CHECK(ion_writer_write_clob(obj->writer, (BYTE *) str->val, str->len));
1138 }
1139 ZEND_METHOD(ion_Writer_Writer, writeBLob)
1140 {
1141 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1142 OBJ_CHECK(obj);
1143
1144 zend_string *str;
1145 ZEND_PARSE_PARAMETERS_START(1, 1)
1146 Z_PARAM_STR(str)
1147 ZEND_PARSE_PARAMETERS_END();
1148
1149 ION_CHECK(ion_writer_write_blob(obj->writer, (BYTE *) str->val, str->len));
1150 }
1151 ZEND_METHOD(ion_Writer_Writer, startLob)
1152 {
1153 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1154 OBJ_CHECK(obj);
1155
1156 zend_object *typ_obj;
1157 ZEND_PARSE_PARAMETERS_START(1, 1)
1158 Z_PARAM_OBJ_OF_CLASS(typ_obj, ce_Type)
1159 ZEND_PARSE_PARAMETERS_END();
1160
1161 php_ion_type *typ = php_ion_obj(type, typ_obj);
1162 OBJ_CHECK(typ);
1163 ION_CHECK(ion_writer_start_lob(obj->writer, php_ion_obj(type, typ)->typ));
1164 }
1165 ZEND_METHOD(ion_Writer_Writer, appendLob)
1166 {
1167 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1168 OBJ_CHECK(obj);
1169
1170 zend_string *str;
1171 ZEND_PARSE_PARAMETERS_START(1, 1)
1172 Z_PARAM_STR(str)
1173 ZEND_PARSE_PARAMETERS_END();
1174
1175 ION_CHECK(ion_writer_append_lob(obj->writer, (BYTE *) str->val, str->len));
1176 }
1177 ZEND_METHOD(ion_Writer_Writer, finishLob)
1178 {
1179 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1180 OBJ_CHECK(obj);
1181
1182 ZEND_PARSE_PARAMETERS_NONE();
1183
1184 ION_CHECK(ion_writer_finish_lob(obj->writer));
1185 }
1186 ZEND_METHOD(ion_Writer_Writer, startContainer)
1187 {
1188 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1189 OBJ_CHECK(obj);
1190
1191 zend_object *typ_obj;
1192 ZEND_PARSE_PARAMETERS_START(1, 1)
1193 Z_PARAM_OBJ_OF_CLASS(typ_obj, ce_Type)
1194 ZEND_PARSE_PARAMETERS_END();
1195
1196 php_ion_type *typ = php_ion_obj(type, typ_obj);
1197 OBJ_CHECK(typ);
1198 ION_CHECK(ion_writer_start_container(obj->writer, php_ion_obj(type, typ)->typ));
1199 }
1200 ZEND_METHOD(ion_Writer_Writer, finishContainer)
1201 {
1202 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1203 OBJ_CHECK(obj);
1204
1205 ZEND_PARSE_PARAMETERS_NONE();
1206
1207 ION_CHECK(ion_writer_finish_container(obj->writer));
1208 }
1209 ZEND_METHOD(ion_Writer_Writer, writeFieldName)
1210 {
1211 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1212 OBJ_CHECK(obj);
1213
1214 zend_object *sym_obj;
1215 zend_string *sym_str;
1216 ZEND_PARSE_PARAMETERS_START(1, 1)
1217 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj, ce_Symbol, sym_str);
1218 ZEND_PARSE_PARAMETERS_END();
1219
1220 if (sym_str) {
1221 ION_STRING is;
1222 ION_CHECK(ion_writer_write_field_name(obj->writer, ion_string_from_zend(&is, sym_str)));
1223 } else {
1224 php_ion_symbol *sym = php_ion_obj(symbol, sym_obj);
1225 PTR_CHECK(sym);
1226 ION_CHECK(ion_writer_write_field_name_symbol(obj->writer, &sym->sym));
1227 }
1228 }
1229 ZEND_METHOD(ion_Writer_Writer, writeAnnotation)
1230 {
1231 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1232 OBJ_CHECK(obj);
1233
1234 zval *args;
1235 unsigned argc;
1236 ZEND_PARSE_PARAMETERS_START(1, -1)
1237 Z_PARAM_VARIADIC('+', args, argc);
1238 ZEND_PARSE_PARAMETERS_END();
1239
1240 for (unsigned i = 0; i < argc; ++i) {
1241 switch (Z_TYPE(args[i])) {
1242 case IS_STRING:
1243 ION_STRING is;
1244 ION_CHECK(ion_writer_add_annotation(obj->writer, ion_string_from_zend(&is, Z_STR(args[i]))));
1245 break;
1246
1247 case IS_OBJECT:
1248 ION_CHECK(ion_writer_add_annotation_symbol(obj->writer, &php_ion_obj(symbol, Z_OBJ(args[i]))->sym));
1249 break;
1250 }
1251 }
1252 }
1253 ZEND_METHOD(ion_Writer_Writer, getDepth)
1254 {
1255 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1256 OBJ_CHECK(obj);
1257
1258 ZEND_PARSE_PARAMETERS_NONE();
1259
1260 SIZE depth;
1261 ION_CHECK(ion_writer_get_depth(obj->writer, &depth));
1262 RETURN_LONG(depth);
1263 }
1264 ZEND_METHOD(ion_Writer_Writer, flush)
1265 {
1266 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1267 OBJ_CHECK(obj);
1268
1269 ZEND_PARSE_PARAMETERS_NONE();
1270
1271 SIZE flushed;
1272 ION_CHECK(ion_writer_flush(obj->writer, &flushed));
1273 if (obj->type == BUFFER_WRITER) {
1274 smart_str_0(&obj->buffer.str);
1275 }
1276 RETURN_LONG(flushed);
1277 }
1278 ZEND_METHOD(ion_Writer_Writer, finish)
1279 {
1280 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1281 OBJ_CHECK(obj);
1282
1283 ZEND_PARSE_PARAMETERS_NONE();
1284
1285 SIZE flushed;
1286 ION_CHECK(ion_writer_finish(obj->writer, &flushed));
1287 if (obj->type == BUFFER_WRITER) {
1288 smart_str_0(&obj->buffer.str);
1289 }
1290 RETURN_LONG(flushed);
1291 }
1292 ZEND_METHOD(ion_Writer_Writer, writeOne)
1293 {
1294 }
1295 ZEND_METHOD(ion_Writer_Writer, writeAll)
1296 {
1297 }
1298 ZEND_METHOD(ion_Writer_Buffer_Writer, __construct)
1299 {
1300 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1301 PTR_CHECK(obj);
1302
1303 zval *ref;
1304 ZEND_PARSE_PARAMETERS_START(1, 2)
1305 Z_PARAM_ZVAL(ref)
1306 Z_PARAM_OPTIONAL
1307 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->opt, ce_Writer_Options)
1308 ZEND_PARSE_PARAMETERS_END();
1309
1310 obj->type = BUFFER_WRITER;
1311 ZVAL_COPY(&obj->buffer.val, ref);
1312 zval_dtor(Z_REFVAL_P(ref));
1313
1314 php_ion_writer_ctor(obj);
1315 }
1316 ZEND_METHOD(ion_Writer_Buffer_Writer, getBuffer)
1317 {
1318 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1319 OBJ_CHECK(obj);
1320
1321 ZEND_PARSE_PARAMETERS_NONE();
1322
1323 RETVAL_STR(zend_string_dup(obj->buffer.str.s, 0));
1324 }
1325 ZEND_METHOD(ion_Writer_Stream_Writer, __construct)
1326 {
1327 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1328 PTR_CHECK(obj);
1329
1330 zval *zstream;
1331 ZEND_PARSE_PARAMETERS_START(1, 2)
1332 Z_PARAM_RESOURCE(zstream)
1333 Z_PARAM_OPTIONAL
1334 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->opt, ce_Writer_Options)
1335 ZEND_PARSE_PARAMETERS_END();
1336
1337 obj->type = STREAM_WRITER;
1338 php_stream_from_zval_no_verify(obj->stream.ptr, zstream);
1339
1340 php_ion_writer_ctor(obj);
1341 }
1342 ZEND_METHOD(ion_Writer_Stream_Writer, getStream)
1343 {
1344 php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
1345 OBJ_CHECK(obj);
1346
1347 ZEND_PARSE_PARAMETERS_NONE();
1348 PTR_CHECK(obj->stream.ptr);
1349
1350 GC_ADDREF(obj->stream.ptr->res);
1351 RETURN_RES(obj->stream.ptr->res);
1352 }
1353
1354 ZEND_METHOD(ion_Serializer_PHP, __construct)
1355 {
1356 php_ion_serializer_php *obj = php_ion_obj(serializer_php, Z_OBJ_P(ZEND_THIS));
1357 PTR_CHECK(obj);
1358
1359 obj->serializer.call_magic = true;
1360
1361 ZEND_PARSE_PARAMETERS_START(0, 3)
1362 Z_PARAM_OPTIONAL
1363 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->opt, ce_Writer_Options)
1364 Z_PARAM_BOOL(obj->serializer.multi_seq)
1365 Z_PARAM_BOOL(obj->serializer.call_magic)
1366 Z_PARAM_STR_OR_NULL(obj->serializer.call_custom)
1367 ZEND_PARSE_PARAMETERS_END();
1368
1369 php_ion_serializer_php_ctor(obj);
1370 }
1371 ZEND_METHOD(ion_Serializer_PHP, __invoke)
1372 {
1373 zend_object *obj = Z_OBJ_P(ZEND_THIS);
1374
1375 zval *data;
1376 ZEND_PARSE_PARAMETERS_START(1, 1)
1377 Z_PARAM_ZVAL(data)
1378 ZEND_PARSE_PARAMETERS_END();
1379
1380 if (obj->ce == ce_Serializer_PHP) {
1381 // default, fast path
1382 php_ion_serialize(&php_ion_obj(serializer_php, obj)->serializer, data, return_value);
1383 } else {
1384 zend_call_method_with_1_params(obj, obj->ce, NULL /* TODO */, "serialize", return_value, data);
1385 }
1386 }
1387 ZEND_FUNCTION(ion_serialize)
1388 {
1389 zval *data;
1390 zend_object *zo_ser = NULL;
1391 ZEND_PARSE_PARAMETERS_START(1, 2)
1392 Z_PARAM_ZVAL(data)
1393 Z_PARAM_OPTIONAL
1394 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser, ce_Serializer)
1395 ZEND_PARSE_PARAMETERS_END();
1396
1397 if (!zo_ser || zo_ser->ce == ce_Serializer_PHP) {
1398 // default, fast path
1399 php_ion_serializer *ser = zo_ser ? &php_ion_obj(serializer_php, zo_ser)->serializer : NULL;
1400 php_ion_serialize(ser, data, return_value);
1401 } else {
1402 zend_call_method_with_1_params(zo_ser, NULL, NULL, "__invoke", return_value, data);
1403 }
1404 }
1405 ZEND_METHOD(ion_Serializer_PHP, serialize)
1406 {
1407 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1408
1409 zval *data;
1410 ZEND_PARSE_PARAMETERS_START(1, 1)
1411 Z_PARAM_ZVAL(data)
1412 ZEND_PARSE_PARAMETERS_END();
1413
1414 // TODO
1415 zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Not implemented");
1416 }
1417
1418 ZEND_METHOD(ion_Unserializer_PHP, __construct)
1419 {
1420 php_ion_unserializer_php *obj = php_ion_obj(unserializer_php, Z_OBJ_P(ZEND_THIS));
1421 PTR_CHECK(obj);
1422
1423 obj->unserializer.call_magic = true;
1424
1425 ZEND_PARSE_PARAMETERS_START(0, 3)
1426 Z_PARAM_OPTIONAL
1427 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->opt, ce_Reader_Options)
1428 Z_PARAM_BOOL(obj->unserializer.multi_seq)
1429 Z_PARAM_BOOL(obj->unserializer.call_magic)
1430 Z_PARAM_STR_OR_NULL(obj->unserializer.call_custom)
1431 ZEND_PARSE_PARAMETERS_END();
1432
1433 php_ion_unserializer_php_ctor(obj);
1434 }
1435 ZEND_METHOD(ion_Unserializer_PHP, __invoke)
1436 {
1437 zend_object *obj = Z_OBJ_P(ZEND_THIS);
1438
1439 zval *data;
1440 ZEND_PARSE_PARAMETERS_START(1, 1)
1441 Z_PARAM_ZVAL(data)
1442 ZEND_PARSE_PARAMETERS_END();
1443
1444 if (obj->ce == ce_Unserializer_PHP) {
1445 php_ion_unserialize(&php_ion_obj(unserializer_php, obj)->unserializer, data, return_value);
1446 } else {
1447 zend_call_method_with_1_params(obj, obj->ce, NULL /* TODO */, "unserialize", return_value, data);
1448 }
1449 }
1450 ZEND_FUNCTION(ion_unserialize)
1451 {
1452 zval *data;
1453 zend_object *zo_ser = NULL;
1454 ZEND_PARSE_PARAMETERS_START(1, 2)
1455 Z_PARAM_ZVAL(data)
1456 Z_PARAM_OPTIONAL
1457 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_ser, ce_Unserializer)
1458 ZEND_PARSE_PARAMETERS_END();
1459
1460 if (!zo_ser || zo_ser->ce == ce_Unserializer_PHP) {
1461 // default, fast path
1462 php_ion_unserializer *ser = zo_ser ? &php_ion_obj(unserializer_php, zo_ser)->unserializer : NULL;
1463 php_ion_unserialize(ser, data, return_value);
1464 } else {
1465 zend_call_method_with_1_params(zo_ser, NULL, NULL, "__invoke", return_value, data);
1466 }
1467 }
1468 ZEND_METHOD(ion_Unserializer_PHP, unserialize)
1469 {
1470 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1471
1472 zval *data;
1473 ZEND_PARSE_PARAMETERS_START(1, 1)
1474 Z_PARAM_ZVAL(data)
1475 ZEND_PARSE_PARAMETERS_END();
1476
1477 // TODO
1478 zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Not implemented");
1479 }
1480
1481 PHP_RINIT_FUNCTION(ion)
1482 {
1483 #if defined(ZTS) && defined(COMPILE_DL_ION)
1484 ZEND_TSRMLS_CACHE_UPDATE();
1485 #endif
1486
1487 php_ion_globals_serializer_init();
1488 php_ion_globals_unserializer_init();
1489 return SUCCESS;
1490 }
1491
1492 PHP_RSHUTDOWN_FUNCTION(ion)
1493 {
1494 php_ion_globals_serializer_dtor();
1495 php_ion_globals_unserializer_dtor();
1496 return SUCCESS;
1497 }
1498
1499 PHP_MINIT_FUNCTION(ion)
1500 {
1501 // globals
1502 php_ion_decimal_ctx_init_max(&g_dec_ctx, DEC_ROUND_HALF_EVEN);
1503 php_ion_decimal_from_zend_long(&g_ion_dec_zend_max, &g_dec_ctx, ZEND_LONG_MAX);
1504 php_ion_decimal_from_zend_long(&g_ion_dec_zend_min, &g_dec_ctx, ZEND_LONG_MIN);
1505
1506 // Annotation
1507 ce_Annotation = register_class_ion_Annotation();
1508
1509 // Catalog
1510 php_ion_register(catalog, Catalog);
1511
1512 // Collection
1513 ce_Collection = register_class_ion_Collection();
1514
1515 // Decimal
1516 php_ion_register(decimal, Decimal);
1517 php_ion_register(decimal_ctx, Decimal_Context);
1518 ce_Decimal_Context_Rounding = register_class_ion_Decimal_Context_Rounding();
1519
1520 // LOB
1521 ce_LOB = register_class_ion_LOB();
1522
1523 // Reader
1524 ce_Reader = register_class_ion_Reader(spl_ce_RecursiveIterator);
1525 php_ion_register(reader_options, Reader_Options);
1526 php_ion_register(reader, Reader_Reader, ce_Reader);
1527 ce_Reader_Buffer = register_class_ion_Reader_Buffer(ce_Reader);
1528 ce_Reader_Buffer_Reader = register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader, ce_Reader_Buffer);
1529 ce_Reader_Stream = register_class_ion_Reader_Stream(ce_Reader);
1530 ce_Reader_Stream_Reader = register_class_ion_Reader_Stream_Reader(ce_Reader_Reader, ce_Reader_Stream);
1531
1532 // Serializer
1533 ce_Serializer = register_class_ion_Serializer();
1534 php_ion_register(serializer_php, Serializer_PHP, ce_Serializer);
1535
1536 // Symbol
1537 php_ion_register(symbol, Symbol);
1538 oh_Symbol.compare = php_ion_symbol_zval_compare;
1539 php_ion_register(symbol_iloc, Symbol_ImportLocation);
1540 php_ion_register(symbol_table, Symbol_Table);
1541 ce_Symbol_System = register_class_ion_Symbol_System();
1542 ce_Symbol_System_SID = register_class_ion_Symbol_System_SID();
1543
1544 // Timestamp
1545 ce_Timestamp = register_class_ion_Timestamp(php_date_get_date_ce());
1546 ce_Timestamp_Precision = register_class_ion_Timestamp_Precision();
1547
1548 // Type
1549 php_ion_register(type, Type);
1550
1551 // Writer
1552 ce_Writer = register_class_ion_Writer();
1553 php_ion_register(writer_options, Writer_Options);
1554 php_ion_register(writer, Writer_Writer, ce_Writer);
1555 ce_Writer_Buffer = register_class_ion_Writer_Buffer(ce_Writer);
1556 ce_Writer_Buffer_Writer = register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer, ce_Writer_Buffer);
1557 ce_Writer_Stream = register_class_ion_Writer_Stream(ce_Writer);
1558 ce_Writer_Stream_Writer = register_class_ion_Writer_Stream_Writer(ce_Writer_Writer, ce_Writer_Stream);
1559
1560 // Unserializer
1561 ce_Unserializer = register_class_ion_Unserializer();
1562 php_ion_register(unserializer_php, Unserializer_PHP, ce_Unserializer);
1563
1564 return SUCCESS;
1565 }
1566
1567 PHP_MSHUTDOWN_FUNCTION(ion)
1568 {
1569 return SUCCESS;
1570 }
1571 PHP_MINFO_FUNCTION(ion)
1572 {
1573 php_info_print_table_start();
1574 php_info_print_table_header(2, "ion support", "enabled");
1575 php_info_print_table_end();
1576 }
1577
1578 PHP_GINIT_FUNCTION(ion)
1579 {
1580 memset(ion_globals, 0, sizeof(*ion_globals));
1581 }
1582 PHP_GSHUTDOWN_FUNCTION(ion)
1583 {
1584 }
1585
1586 static zend_module_dep ion_module_deps[] = {
1587 ZEND_MOD_REQUIRED("date")
1588 ZEND_MOD_REQUIRED("spl")
1589 ZEND_MOD_END
1590 };
1591
1592 zend_module_entry ion_module_entry = {
1593 STANDARD_MODULE_HEADER_EX,
1594 NULL,
1595 ion_module_deps,
1596 "ion", /* Extension name */
1597 ext_functions, /* zend_function_entry */
1598 PHP_MINIT(ion), /* PHP_MINIT - Module initialization */
1599 PHP_MSHUTDOWN(ion), /* PHP_MSHUTDOWN - Module shutdown */
1600 PHP_RINIT(ion), /* PHP_RINIT - Request initialization */
1601 PHP_RSHUTDOWN(ion), /* PHP_RSHUTDOWN - Request shutdown */
1602 PHP_MINFO(ion), /* PHP_MINFO - Module info */
1603 PHP_ION_VERSION, /* Version */
1604 ZEND_MODULE_GLOBALS(ion),
1605 PHP_GINIT(ion), /* PHP_GINIT */
1606 PHP_GSHUTDOWN(ion), /* PHP_GSHUTDOWN */
1607 NULL,
1608 STANDARD_MODULE_PROPERTIES_EX
1609 };
1610
1611 #ifdef COMPILE_DL_ION
1612 # ifdef ZTS
1613 ZEND_TSRMLS_CACHE_DEFINE()
1614 # endif
1615 ZEND_GET_MODULE(ion)
1616 #endif