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