remove Options classes
authorMichael Wallner <mike@php.net>
Thu, 28 Apr 2022 13:14:52 +0000 (15:14 +0200)
committerMichael Wallner <mike@php.net>
Thu, 28 Apr 2022 13:14:52 +0000 (15:14 +0200)
ion.c
ion.stub.php
ion_arginfo.h
ion_private.h
tests/Reader/Options.phpt [deleted file]
tests/Symbol/Table/Local.phpt
tests/Symbol/Table/Shared.phpt
tests/Writer.phpt
tests/Writer/Options.phpt [deleted file]
tests/~integration/detect_utf8.phpt
tests/~integration/no_decimals.phpt

diff --git a/ion.c b/ion.c
index 207909f3d167318e7a60e9372c7e80fb603383e9..e84d62518e153b35a3c16add6b7a4d1e183a3a61 100644 (file)
--- a/ion.c
+++ b/ion.c
                } \
        }
 
+#define Z_PARAM_HASH_OR_INSTANCE_OF_NULL(za_dest, zo_inst, ce_inst) \
+       Z_PARAM_PROLOGUE(0, 0) {                                                    \
+        zval *_arr;                                                                     \
+               if (zend_parse_arg_array(_arg, &(_arr), true, 0)) {                     \
+                za_dest = Z_ARRVAL_P(_arr);                                                                    \
+               } else {                                                         \
+                       zend_object *_obj = NULL; \
+                       if (zend_parse_arg_obj(_arg, &_obj, ce, true)) { \
+                za_dest = _obj->handlers->get_properties(_obj); \
+                       } else if (zend_parse_arg_obj(_arg, &(zo_inst), ce_inst, true)) { \
+                       } else { \
+                               _error = ce->name->val; \
+                               _error_code = ZPP_ERROR_WRONG_CLASS_OR_NULL; \
+                               break; \
+                       } \
+               } \
+       }
+
 static ZEND_METHOD(ion_Symbol_ImportLocation, __construct)
 {
        php_ion_symbol_iloc *obj = php_ion_obj(symbol_iloc, Z_OBJ_P(ZEND_THIS));
@@ -627,22 +645,39 @@ static ZEND_METHOD(ion_LOB, __construct)
        update_property_obj(Z_OBJ_P(ZEND_THIS), ZEND_STRL("type"), type);
        zend_update_property_str(Z_OBJCE_P(ZEND_THIS), Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), value);
 }
-static ZEND_METHOD(ion_Reader_Options, __construct)
+static ZEND_METHOD(ion_Reader_Reader, __construct)
 {
-       php_ion_reader_options *opt = php_ion_obj(reader_options, Z_OBJ_P(ZEND_THIS));
-       zend_bool ret_sys_val = false, skip_validation = false;
-       zend_long max_depth = 10, max_ann = 10, ann_buf_siz = 0x4000, tmp_buf_siz = 0x4000;
+       php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
 
-       PTR_CHECK(opt);
+       PTR_CHECK(obj);
 
-       ZEND_PARSE_PARAMETERS_START(0, 9)
+       zval *zstream = NULL;
+       zend_bool ret_sys_val = false, skip_validation = false;
+       zend_long max_depth = 10, max_ann = 10, ann_buf_siz = 0x4000, tmp_buf_siz = 0x4000;
+       ZEND_PARSE_PARAMETERS_START(1, 10)
+               Z_PARAM_PROLOGUE(0, 0)
+               if (!instanceof_function(obj->std.ce, ce_Reader_Buffer) &&
+                               zend_parse_arg_resource(_arg, &zstream, 0)) {
+                       obj->type = STREAM_READER;
+                       php_stream_from_zval_no_verify(obj->stream.ptr, zstream);
+                       PTR_CHECK(obj->stream.ptr);
+                       GC_ADDREF(obj->stream.ptr->res);
+               } else if (!instanceof_function(obj->std.ce, ce_Reader_Stream) &&
+                               zend_parse_arg_str(_arg, &obj->buffer, 0, _i)) {
+                       obj->type = BUFFER_READER;
+                       zend_string_addref(obj->buffer);
+               } else {
+                       _error_code = ZPP_ERROR_WRONG_ARG;
+                       _error = "of type string or resource";
+                       break;
+               }
                Z_PARAM_OPTIONAL
         // public readonly ?\ion\Catalog $catalog = null,
-               Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt->cat, ce_Catalog)
+               Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->cat, ce_Catalog)
         // public readonly ?\ion\Decimal\Context $decimalContext = null,
-               Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt->dec_ctx, ce_Decimal_Context)
+               Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->dec_ctx, ce_Decimal_Context)
         // public readonly ?\Closure $onContextChange = null,
-               Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt->cb, zend_ce_closure);
+               Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->cb, zend_ce_closure);
         // public readonly bool $returnSystemValues = false,
                Z_PARAM_BOOL(ret_sys_val)
         // public readonly int $maxContainerDepth = 10,
@@ -657,39 +692,16 @@ static ZEND_METHOD(ion_Reader_Options, __construct)
                Z_PARAM_BOOL(skip_validation)
        ZEND_PARSE_PARAMETERS_END();
 
-       if (opt->cb) {
-               zval zcb;
-               ZVAL_OBJ(&zcb, opt->cb);
-               zend_fcall_info_init(&zcb, 0, &opt->ccn.fci, &opt->ccn.fcc, NULL, NULL);
-               opt->opt.context_change_notifier.context = &opt->ccn;
-               update_property_obj(&opt->std, ZEND_STRL("onContextChange"), opt->cb);
-       } else {
-               zend_update_property_null(NULL, &opt->std, ZEND_STRL("onContextChange"));
-       }
-       if (opt->cat) {
-               update_property_obj(&opt->std, ZEND_STRL("catalog"), opt->cat);
-               opt->opt.pcatalog = php_ion_obj(catalog, opt->cat)->cat;
-       } else {
-               zend_update_property_null(NULL, &opt->std, ZEND_STRL("catalog"));
-       }
-       if (opt->dec_ctx) {
-               update_property_obj(&opt->std, ZEND_STRL("decimalContext"), opt->dec_ctx);
-               opt->opt.decimal_context = &php_ion_obj(decimal_ctx, opt->dec_ctx)->ctx;
-       } else {
-               zend_update_property_null(NULL, &opt->std, ZEND_STRL("decimalContext"));
-       }
-       zend_update_property_bool(opt->std.ce, &opt->std, ZEND_STRL("returnSystemValues"),
-               opt->opt.return_system_values = ret_sys_val);
-       zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("maxContainerDepth"),
-               opt->opt.max_container_depth = (SIZE) max_depth);
-       zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("maxAnnotations"),
-               opt->opt.max_annotation_count = (SIZE) max_ann);
-       zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("annotationBufferSize"),
-               opt->opt.max_annotation_buffered = (SIZE) ann_buf_siz);
-       zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("tempBufferSize"),
-               opt->opt.chunk_threshold = opt->opt.user_value_threshold = opt->opt.symbol_threshold = (SIZE) tmp_buf_siz);
-       zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("skipCharacterValidation"),
-               opt->opt.skip_character_validation = (SIZE) skip_validation);
+       obj->options.return_system_values = ret_sys_val;
+       obj->options.max_container_depth = (SIZE) max_depth;
+       obj->options.max_annotation_count = (SIZE) max_ann;
+       obj->options.max_annotation_buffered = (SIZE) ann_buf_siz;
+       obj->options.chunk_threshold = (SIZE) tmp_buf_siz;
+       obj->options.user_value_threshold = (SIZE) tmp_buf_siz;
+       obj->options.symbol_threshold = (SIZE) tmp_buf_siz;
+       obj->options.skip_character_validation = skip_validation;
+
+       php_ion_reader_ctor(obj);
 }
 static ZEND_METHOD(ion_Reader_Reader, hasChildren)
 {
@@ -858,8 +870,8 @@ static ZEND_METHOD(ion_Reader_Reader, getAnnotations)
        ZEND_PARSE_PARAMETERS_NONE();
 
        int32_t count, max;
-       if (obj->opt) {
-               max = php_ion_obj(reader_options, obj->opt)->opt.max_annotation_count;
+       if (obj->options.max_annotation_count) {
+               max = obj->options.max_annotation_count;
        } else {
                max = 10;
        }
@@ -882,8 +894,8 @@ static ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbols)
        ZEND_PARSE_PARAMETERS_NONE();
 
        int32_t count, max;
-       if (obj->opt) {
-               max = php_ion_obj(reader_options, obj->opt)->opt.max_annotation_count;
+       if (obj->options.max_annotation_count) {
+               max = obj->options.max_annotation_count;
        } else {
                max = 10;
        }
@@ -1000,7 +1012,7 @@ static ZEND_METHOD(ion_Reader_Reader, readTimestamp)
 
        ZEND_PARSE_PARAMETERS_NONE();
 
-       php_ion_reader_read_timestamp(obj->reader, obj->opt ? &php_ion_obj(reader_options, obj->opt)->opt : NULL, return_value);
+       php_ion_reader_read_timestamp(obj->reader, &obj->options, return_value);
 }
 static ZEND_METHOD(ion_Reader_Reader, readSymbol)
 {
@@ -1140,28 +1152,7 @@ static ZEND_METHOD(ion_Reader_Reader, getValueLength)
        ION_CHECK(ion_reader_get_value_length(obj->reader, &len));
        RETURN_LONG(len);
 }
-static ZEND_METHOD(ion_Reader_Buffer_Reader, __construct)
-{
-       php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
-       PTR_CHECK(obj);
-
-       zend_string *zstr;
-       zval *za_opt = NULL;
-       ZEND_PARSE_PARAMETERS_START(1, 2)
-               Z_PARAM_STR(zstr)
-               Z_PARAM_OPTIONAL
-               Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj->opt, ce_Reader_Options, ce_Reader_Options, za_opt)
-       ZEND_PARSE_PARAMETERS_END();
-       if (za_opt) {
-               update_property_obj_ex(ce_Reader_Reader, &obj->std, ZEND_STRL("options"), obj->opt);
-               OBJ_RELEASE(obj->opt);
-       }
-
-       obj->type = BUFFER_READER;
-       obj->buffer = zend_string_copy(zstr);
 
-       php_ion_reader_ctor(obj);
-}
 static ZEND_METHOD(ion_Reader_Buffer_Reader, getBuffer)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
@@ -1171,27 +1162,6 @@ static ZEND_METHOD(ion_Reader_Buffer_Reader, getBuffer)
        RETURN_STR_COPY(obj->buffer);
 }
 
-static ZEND_METHOD(ion_Reader_Stream_Reader, __construct)
-{
-       php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
-       PTR_CHECK(obj);
-
-       zval *zstream, *za_opt = NULL;
-       ZEND_PARSE_PARAMETERS_START(1, 2)
-               Z_PARAM_RESOURCE(zstream)
-               Z_PARAM_OPTIONAL
-               Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj->opt, ce_Reader_Options, ce_Reader_Options, za_opt)
-       ZEND_PARSE_PARAMETERS_END();
-       if (za_opt) {
-               update_property_obj_ex(ce_Reader_Reader, &obj->std, ZEND_STRL("options"), obj->opt);
-               OBJ_RELEASE(obj->opt);
-       }
-
-       obj->type = STREAM_READER;
-       php_stream_from_zval_no_verify(obj->stream.ptr, zstream);
-
-       php_ion_reader_ctor(obj);
-}
 static ZEND_METHOD(ion_Reader_Stream_Reader, getStream)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
@@ -1243,15 +1213,32 @@ static ZEND_METHOD(ion_Reader_Stream_Reader, resetStreamWithLength)
        PTR_CHECK(obj->stream.ptr);
        Z_ADDREF_P(zstream);
 }
-static ZEND_METHOD(ion_Writer_Options, __construct)
+
+static void _ion_Writer_Writer___construct(bool stream_writer, INTERNAL_FUNCTION_PARAMETERS)
 {
-       php_ion_writer_options *obj = php_ion_obj(writer_options, Z_OBJ_P(ZEND_THIS));
+       php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
 
        zend_bool binary = false, compact_floats = false, escape = false, pretty = false,
                        tabs = true, flush = false;
        zend_long indent = 2, max_depth = 10, max_ann = 10, temp = 0x4000;
-       ZEND_PARSE_PARAMETERS_START(0, 12)
+       ZEND_PARSE_PARAMETERS_START(0 + stream_writer, 12 + stream_writer)
+               if (!stream_writer) {
+                       obj->type = BUFFER_WRITER;
+               } else  {
+                       Z_PARAM_PROLOGUE(0, 0)
+                       obj->type = STREAM_WRITER;
+                       zval *zstream = NULL;
+                       if (zend_parse_arg_resource(_arg, &zstream, 0)) {
+                               php_stream_from_zval_no_verify(obj->stream.ptr, zstream);
+                               PTR_CHECK(obj->stream.ptr);
+                               GC_ADDREF(obj->stream.ptr->res);
+                       } else {
+                               _error_code = Z_EXPECTED_RESOURCE;
+                               _error = "of type resource";
+                               break;
+                       }
+               }
                Z_PARAM_OPTIONAL
                //public readonly ?\ion\Catalog $catalog = null,
                Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->cat, ce_Catalog)
@@ -1279,38 +1266,23 @@ static ZEND_METHOD(ion_Writer_Options, __construct)
                Z_PARAM_LONG(temp)
        ZEND_PARSE_PARAMETERS_END();
 
-       if (obj->cat) {
-               update_property_obj(&obj->std, ZEND_STRL("catalog"), obj->cat);
-               obj->opt.pcatalog = php_ion_obj(catalog, obj->cat)->cat;
-       } else {
-               zend_update_property_null(NULL, &obj->std, ZEND_STRL("catalog"));
-       }
-       if (obj->dec_ctx) {
-               update_property_obj(&obj->std, ZEND_STRL("decimalContext"), obj->dec_ctx);
-               obj->opt.decimal_context = &php_ion_obj(decimal_ctx, obj->dec_ctx)->ctx;
-       } else {
-               zend_update_property_null(NULL, &obj->std, ZEND_STRL("decimalContext"));
-       }
-       zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("outputBinary"),
-                       obj->opt.output_as_binary = binary);
-       zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("compactFloats"),
-                       obj->opt.compact_floats = compact_floats);
-       zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("escapeNonAscii"),
-                       obj->opt.escape_all_non_ascii = escape);
-       zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("prettyPrint"),
-                       obj->opt.pretty_print = pretty);
-       zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("indentTabs"),
-                       obj->opt.indent_with_tabs = tabs);
-       zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("indentSize"),
-                       obj->opt.indent_size = (SIZE) indent);
-       zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("flushEveryValue"),
-                       obj->opt.flush_every_value = flush);
-       zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("maxContainerDepth"),
-                       obj->opt.max_container_depth = (SIZE) max_depth);
-       zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("maxAnnotations"),
-                       obj->opt.max_annotation_count = (SIZE) max_ann);
-       zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("tempBufferSize"),
-                       obj->opt.temp_buffer_size = (SIZE) temp);
+       obj->options.output_as_binary = binary;
+       obj->options.compact_floats = compact_floats;
+       obj->options.escape_all_non_ascii = escape;
+       obj->options.pretty_print = pretty;
+       obj->options.indent_with_tabs = tabs;
+       obj->options.indent_size = (SIZE) indent;
+       obj->options.flush_every_value = flush;
+       obj->options.max_container_depth = (SIZE) max_depth;
+       obj->options.max_annotation_count = (SIZE) max_ann;
+       obj->options.temp_buffer_size = (SIZE) temp;
+
+       php_ion_writer_ctor(obj);
+}
+
+static ZEND_METHOD(ion_Writer_Writer, __construct)
+{
+       _ion_Writer_Writer___construct(false, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 }
 static ZEND_METHOD(ion_Writer_Writer, writeNull)
 {
@@ -1393,11 +1365,8 @@ static ZEND_METHOD(ion_Writer_Writer, writeDecimal)
                decContext *ctx = &php_ion_globals.decimal.ctx;
                ION_DECIMAL dec = {0};
 
-               if (obj->opt) {
-                       php_ion_writer_options *opt_obj = php_ion_obj(writer_options, obj->opt);
-                       if (opt_obj->opt.decimal_context) {
-                               ctx = opt_obj->opt.decimal_context;
-                       }
+               if (obj->options.decimal_context) {
+                       ctx = obj->options.decimal_context;
                }
                ION_CHECK(ion_decimal_from_string(&dec, dec_str->val, ctx));
                ION_CHECK(ion_writer_write_ion_decimal(obj->writer, &dec));
@@ -1417,11 +1386,7 @@ static ZEND_METHOD(ion_Writer_Writer, writeTimestamp)
                Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj, ce_Timestamp, ts_str)
        ZEND_PARSE_PARAMETERS_END();
 
-       decContext *ctx = NULL;
-       if (obj->opt) {
-               ctx = php_ion_obj(reader_options, obj->opt)->opt.decimal_context;
-       }
-
+       decContext *ctx = obj->options.decimal_context;
        ION_TIMESTAMP tmp = {0};
        if (ts_str) {
                SIZE used;
@@ -1623,20 +1588,7 @@ static ZEND_METHOD(ion_Writer_Writer, finish)
 }
 static ZEND_METHOD(ion_Writer_Buffer_Writer, __construct)
 {
-       php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
-       PTR_CHECK(obj);
-
-       zval *za_opt = NULL;
-       ZEND_PARSE_PARAMETERS_START(0, 1)
-               Z_PARAM_OPTIONAL
-               Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj->opt, ce_Writer_Options, ce_Writer_Options, za_opt)
-       ZEND_PARSE_PARAMETERS_END();
-
-       obj->type = BUFFER_WRITER;
-       php_ion_writer_ctor(obj);
-       if (za_opt) {
-               OBJ_RELEASE(obj->opt);
-       }
+       _ion_Writer_Writer___construct(false, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 }
 static ZEND_METHOD(ion_Writer_Buffer_Writer, getBuffer)
 {
@@ -1658,23 +1610,7 @@ static ZEND_METHOD(ion_Writer_Buffer_Writer, resetBuffer)
 }
 static ZEND_METHOD(ion_Writer_Stream_Writer, __construct)
 {
-       php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
-       PTR_CHECK(obj);
-
-       zval *zstream, *za_opt = NULL;
-       ZEND_PARSE_PARAMETERS_START(1, 2)
-               Z_PARAM_RESOURCE(zstream)
-               Z_PARAM_OPTIONAL
-               Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj->opt, ce_Writer_Options, ce_Writer_Options, za_opt)
-       ZEND_PARSE_PARAMETERS_END();
-
-       obj->type = STREAM_WRITER;
-       php_stream_from_zval_no_verify(obj->stream.ptr, zstream);
-
-       php_ion_writer_ctor(obj);
-       if (za_opt) {
-               OBJ_RELEASE(obj->opt);
-       }
+       _ion_Writer_Writer___construct(true, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 }
 static ZEND_METHOD(ion_Writer_Stream_Writer, getStream)
 {
@@ -1708,12 +1644,23 @@ static ZEND_METHOD(ion_Serializer_Serializer, serialize)
 {
        zend_object *obj = Z_OBJ_P(ZEND_THIS);
 
-       zval *data, *za_opt = NULL;
+       zval *data;
        zend_object *zo_wri = NULL;
+       zend_array *za_named = NULL;
        ZEND_PARSE_PARAMETERS_START(1, 2)
                Z_PARAM_ZVAL(data)
                Z_PARAM_OPTIONAL
-               Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_wri, ce_Writer, ce_Writer_Options, za_opt)
+               Z_PARAM_PROLOGUE(0, 0)
+               if (!zend_parse_arg_obj(_arg, &zo_wri, ce_Writer, true)) {
+                       if (!zend_parse_arg_array_ht(_arg, &za_named, false, false, false)) {
+                               _error_code = ZPP_ERROR_WRONG_ARG;
+                               _error = "of type array or \\ion\\Writer";
+                               break;
+                       }
+                       zo_wri = create_ion_Writer_Writer(ce_Writer_Buffer_Writer);
+                       call_constructor(zo_wri, 0, NULL, za_named);
+                       ION_CATCH(OBJ_RELEASE(zo_wri));
+               }
        ZEND_PARSE_PARAMETERS_END();
 
        php_ion_serializer *ser = php_ion_obj(serializer, obj);
@@ -1721,29 +1668,39 @@ static ZEND_METHOD(ion_Serializer_Serializer, serialize)
        php_ion_serialize(ser, data, return_value);
        ser->wri = NULL;
 
-       if (za_opt) {
+       if (za_named) {
                OBJ_RELEASE(zo_wri);
        }
 }
 static ZEND_FUNCTION(ion_serialize)
 {
-       zval *data, *za_ser = NULL;
+       zval *data;
        zend_object *zo_ser = NULL;
+       zend_array *za_named = NULL;
        ZEND_PARSE_PARAMETERS_START(1, 2)
                Z_PARAM_ZVAL(data)
                Z_PARAM_OPTIONAL
-               Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_ser, ce_Serializer, ce_Serializer_Serializer, za_ser)
+               Z_PARAM_PROLOGUE(0, 0)
+               if (!zend_parse_arg_obj(_arg, &zo_ser, ce_Serializer, true)) {
+                       if (!zend_parse_arg_array_ht(_arg, &za_named, false, false, false)) {
+                               _error_code = ZPP_ERROR_WRONG_ARG;
+                               _error = "of type array or \\ion\\Writer";
+                               break;
+                       }
+                       zo_ser = create_ion_Serializer_Serializer(NULL);
+                       call_constructor(zo_ser, 0, NULL, za_named);
+                       ION_CATCH(OBJ_RELEASE(zo_ser));
+               }
        ZEND_PARSE_PARAMETERS_END();
 
        if (!zo_ser || zo_ser->ce == ce_Serializer_Serializer) {
                // default, fast path
-               php_ion_serializer *ser = zo_ser ? php_ion_obj(serializer, zo_ser) : NULL;
-               php_ion_serialize(ser, data, return_value);
+               php_ion_serialize(php_ion_obj(serializer, zo_ser), data, return_value);
        } else {
                zend_call_method_with_1_params(zo_ser, NULL, NULL, "serialize", return_value, data);
        }
 
-       if (za_ser) {
+       if (za_named) {
                OBJ_RELEASE(zo_ser);
        }
 }
@@ -1766,44 +1723,42 @@ static ZEND_METHOD(ion_Unserializer_Unserializer, __construct)
 }
 static ZEND_METHOD(ion_Unserializer_Unserializer, unserialize)
 {
-       zend_object *obj = Z_OBJ_P(ZEND_THIS);
-
-       zval *data, *za_opt = NULL;
-       zend_object *zo_rdr = NULL;
-       ZEND_PARSE_PARAMETERS_START(1, 2)
+       zval *data;
+       ZEND_PARSE_PARAMETERS_START(1, 1)
                Z_PARAM_ZVAL(data)
-               Z_PARAM_OPTIONAL
-               Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_rdr, ce_Reader, ce_Reader_Options, za_opt)
        ZEND_PARSE_PARAMETERS_END();
 
-       php_ion_unserializer *ser = php_ion_obj(unserializer, obj);
-       ser->rdr = zo_rdr;
-       php_ion_unserialize(ser, data, return_value);
-       ser->rdr = NULL;
-
-       if (za_opt) {
-               OBJ_RELEASE(zo_rdr);
-       }
+       php_ion_unserialize(php_ion_obj(unserializer, Z_OBJ_P(ZEND_THIS)), data, return_value);
 }
 static ZEND_FUNCTION(ion_unserialize)
 {
-       zval *data, *za_ser = NULL;
+       zval *data;
        zend_object *zo_ser = NULL;
+       zend_array *za_named = NULL;
        ZEND_PARSE_PARAMETERS_START(1, 2)
                Z_PARAM_ZVAL(data)
                Z_PARAM_OPTIONAL
-               Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(zo_ser, ce_Unserializer, ce_Unserializer_Unserializer, za_ser)
+               Z_PARAM_PROLOGUE(0, 0)
+               if (!zend_parse_arg_obj(_arg, &zo_ser, ce_Unserializer, true)) {
+                       if (!zend_parse_arg_array_ht(_arg, &za_named, false, false, false)) {
+                               _error_code = ZPP_ERROR_WRONG_ARG;
+                               _error = "of type array of \\ion\\Unserializer";
+                               break;
+                       }
+                       zo_ser = create_ion_Unserializer_Unserializer(NULL);
+                       call_constructor(zo_ser, 0, NULL, za_named);
+                       ION_CATCH(OBJ_RELEASE(zo_ser));
+               }
        ZEND_PARSE_PARAMETERS_END();
 
        if (!zo_ser || zo_ser->ce == ce_Unserializer_Unserializer) {
                // default, fast path
-               php_ion_unserializer *ser = zo_ser ? php_ion_obj(unserializer, zo_ser) : NULL;
-               php_ion_unserialize(ser, data, return_value);
+               php_ion_unserialize(php_ion_obj(unserializer, zo_ser), data, return_value);
        } else {
                zend_call_method_with_1_params(zo_ser, NULL, NULL, "unserialize", return_value, data);
        }
 
-       if (za_ser) {
+       if (za_named) {
                OBJ_RELEASE(zo_ser);
        }
 }
@@ -1859,7 +1814,6 @@ PHP_MINIT_FUNCTION(ion)
 
        // Reader
        ce_Reader = register_class_ion_Reader(spl_ce_RecursiveIterator);
-       php_ion_register(reader_options, Reader_Options);
        php_ion_register(reader, Reader_Reader, ce_Reader);
        ce_Reader_Buffer = register_class_ion_Reader_Buffer(ce_Reader);
        ce_Reader_Buffer_Reader = register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader, ce_Reader_Buffer);
@@ -1894,7 +1848,6 @@ PHP_MINIT_FUNCTION(ion)
 
        // Writer
        ce_Writer = register_class_ion_Writer();
-       php_ion_register(writer_options, Writer_Options);
        php_ion_register(writer, Writer_Writer, ce_Writer);
        ce_Writer_Buffer = register_class_ion_Writer_Buffer(ce_Writer);
        ce_Writer_Buffer_Writer = register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer, ce_Writer_Buffer);
index ac7dda8093392a4c3ee5b70cab208017da90b689..c41b77ace00616d715aa06dc685f481c24a5c711 100644 (file)
@@ -48,14 +48,14 @@ function unserialize($data, Unserializer|array|null $unserializer = null) : mixe
  * Serializer interface, used to customize ion\serialize()'s behavior.
  */
 interface Serializer {
-    public function serialize(mixed $data, \ion\Writer|\ion\Writer\Options|array|null $writer = null) : mixed;
+    public function serialize(mixed $data, Writer|array|null $writer = null) : mixed;
 }
 
 /**
  * Unserializer interface, used to customize ion\unserialize()'s behavior.
  */
 interface Unserializer {
-    /** @param \ion\Reader|string|resource $data */
+    /** @param Reader|string|resource $data */
     public function unserialize($data) : mixed;
 }
 
@@ -689,10 +689,14 @@ enum Format : string {
 namespace ion\Reader;
 
 /**
- * Reader options.
+ * Base implementation of ION readers.
  */
-class Options {
+abstract class Reader implements \ion\Reader {
+    /**
+     * @param string|resource $data The string or resource to read from.
+     */
     public function __construct(
+        $data,
         /**
          * ION catalog to use for symbol lookup.
          */
@@ -730,16 +734,6 @@ class Options {
          */
         public readonly bool $skipCharacterValidation = false,
     ) {}
-}
-
-/**
- * Base implementation of ION readers.
- */
-abstract class Reader implements \ion\Reader {
-    /**
-     * Reader options.
-     */
-    public readonly ?Options $options;
 
     public function hasChildren() : bool {}
     public function getChildren() : \ion\Reader {}
@@ -794,7 +788,7 @@ abstract class Reader implements \ion\Reader {
  */
 interface Buffer extends \ion\Reader {
     /**
-     * Get the buffer read from.
+     * Get the buffer being read from.
      *
      * @return string The buffer read from.
      */
@@ -806,7 +800,7 @@ interface Buffer extends \ion\Reader {
  */
 interface Stream extends \ion\Reader {
     /**
-     * Get the stream read from.
+     * Get the stream being read from.
      *
      * @return resource The stream read from.
      */
@@ -834,16 +828,6 @@ namespace ion\Reader\Buffer;
  * ION buffer reader.
  */
 class Reader extends \ion\Reader\Reader implements \ion\Reader\Buffer {
-    /**
-     * Create a new string buffer reader.
-     *
-     * @param string $buffer The buffer to read from.
-     * @param \ion\Reader\Options|array|null $options Reader options.
-     */
-    public function __construct(
-        string $buffer,
-        \ion\Reader\Options|array|null $options = null,
-    ) {}
 
     public function getBuffer() : string {}
 }
@@ -854,16 +838,6 @@ namespace ion\Reader\Stream;
  * ION stream reader.
  */
 class Reader extends \ion\Reader\Reader implements \ion\Reader\Stream {
-    /**
-     * Create a new stream reader.
-     *
-     * @param resource $stream The stream to read from.
-     * @param \ion\Reader\Options|array|null $options Reader options.
-     */
-    public function __construct(
-        $stream,
-        \ion\Reader\Options|array|null $options = null,
-    ) {}
 
     /**
      * Get the stream read from.
@@ -881,11 +855,11 @@ class Reader extends \ion\Reader\Reader implements \ion\Reader\Stream {
 namespace ion\Writer;
 
 /**
- * ION writer options.
+ * Base implementation of common functionality of ION writers.
  */
-class Options {
+abstract class Writer implements \ion\Writer {
     /**
-     * Create custom ION writer options.
+     * Create custom ION writer.
      */
     public function __construct(
         /**
@@ -937,12 +911,7 @@ class Options {
          */
         public readonly int $tempBufferSize = 0x4000,
     ) {}
-}
 
-/**
- * Base implementation of common functionality of ION writers.
- */
-abstract class Writer implements \ion\Writer {
     public function writeNull() : void {}
     public function writeTypedNull(\ion\Type $type) : void {}
     public function writeBool(bool $value) : void {}
@@ -1005,17 +974,9 @@ interface Stream extends \ion\Writer {
 namespace ion\Writer\Buffer;
 
 /**
- * IO buffer writer.
+ * ION buffer writer.
  */
 class Writer extends \ion\Writer\Writer implements \ion\Writer\Buffer {
-    /**
-     * Create a new buffer writer.
-     *
-     * @param \ion\Writer\Options|array|null $options Writer options.
-     */
-    public function __construct(
-        \ion\Writer\Options|array|null $options = null,
-    ) {}
 
     public function getBuffer() : string {}
     public function resetBuffer() : void {}
@@ -1031,11 +992,57 @@ class Writer extends \ion\Writer\Writer implements \ion\Writer\Stream {
      * Create a new stream writer.
      *
      * @param resource $stream The stream to write to.
-     * @param \ion\Writer\Options|array|null $options Writer options.
      */
     public function __construct(
         $stream,
-        \ion\Writer\Options|array|null $options = null,
+        /**
+         * ION catalog to use for symbol lookup.
+         */
+        public readonly ?\ion\Catalog $catalog = null,
+        /**
+         * Decimal context to use.
+         */
+        public readonly ?\ion\Decimal\Context $decimalContext = null,
+        /**
+         * Whether to output binary ION.
+         */
+        public readonly bool $outputBinary = false,
+        /**
+         * Whether to write doubles which fit in 32 bits as floats.
+         */
+        public readonly bool $compactFloats = false,
+        /**
+         * Whether to slash-escape all non ASCII bytes.
+         */
+        public readonly bool $escapeNonAscii = false,
+        /**
+         * Whether to produce pretty-printed output.
+         */
+        public readonly bool $prettyPrint = false,
+        /**
+         * Whether to indent with tabs, when pretty-printing.
+         */
+        public readonly bool $indentTabs = true,
+        /**
+         * The number of spaces to use for indentation instead of tabs, when pretty-printing.
+         */
+        public readonly int $indentSize = 2,
+        /**
+         * Whether to immediately flush every value written.
+         */
+        public readonly bool $flushEveryValue = false,
+        /**
+         * Maximum depth of nested containers.
+         */
+        public readonly int $maxContainerDepth = 10,
+        /**
+         * The maximum number of annotations allowed on a single value.
+         */
+        public readonly int $maxAnnotations = 10,
+        /**
+         * Temporary buffer size.
+         */
+        public readonly int $tempBufferSize = 0x4000,
     ) {}
     /**
      * @return resource
@@ -1066,7 +1073,7 @@ class Serializer implements \ion\Serializer {
         public readonly ?string $callCustomSerialize = null,
     ) {}
 
-    public function serialize(mixed $data, \ion\Writer|\ion\Writer\Options|array|null $writer = null) : mixed {}
+    public function serialize(mixed $data, \ion\Writer|array|null $writer = null) : mixed {}
 }
 
 namespace ion\Unserializer;
index aea20af2d586f2e64efd67a188c713d6c60f752e..3394b783a827784d518b9ad42d92b44c34f544af 100644 (file)
@@ -1,5 +1,5 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 771b0ba1db693b7506ff427a667d029630caca09 */
+ * Stub hash: 8b6aeb4c5c0a8a5af0f5a55cbf09fb2846032c07 */
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ion_serialize, 0, 1, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, data, IS_MIXED, 0)
@@ -13,7 +13,7 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Serializer_serialize, 0, 1, IS_MIXED, 0)
        ZEND_ARG_TYPE_INFO(0, data, IS_MIXED, 0)
-       ZEND_ARG_OBJ_TYPE_MASK(0, writer, ion\\Writer|ion\\Writer\\Options, MAY_BE_ARRAY|MAY_BE_NULL, "null")
+       ZEND_ARG_OBJ_TYPE_MASK(0, writer, ion\\Writer, MAY_BE_ARRAY|MAY_BE_NULL, "null")
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Unserializer_unserialize, 0, 1, IS_MIXED, 0)
@@ -313,7 +313,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ion_Decimal_Context_DecMax,
        ZEND_ARG_OBJ_TYPE_MASK(0, round, ion\\Decimal\\Context\\Rounding, MAY_BE_LONG, "ion\\Decimal\\Context\\Rounding::HalfEven")
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Reader_Options___construct, 0, 0, 0)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Reader_Reader___construct, 0, 0, 1)
+       ZEND_ARG_INFO(0, data)
        ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, catalog, ion\\Catalog, 1, "null")
        ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, decimalContext, ion\\Decimal\\Context, 1, "null")
        ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, onContextChange, Closure, 1, "null")
@@ -410,25 +411,15 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Reader_Stream_resetStr
        ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Reader_Buffer_Reader___construct, 0, 0, 1)
-       ZEND_ARG_TYPE_INFO(0, buffer, IS_STRING, 0)
-       ZEND_ARG_OBJ_TYPE_MASK(0, options, ion\\Reader\\Options, MAY_BE_ARRAY|MAY_BE_NULL, "null")
-ZEND_END_ARG_INFO()
-
 #define arginfo_class_ion_Reader_Buffer_Reader_getBuffer arginfo_class_ion_Symbol___toString
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Reader_Stream_Reader___construct, 0, 0, 1)
-       ZEND_ARG_INFO(0, stream)
-       ZEND_ARG_OBJ_TYPE_MASK(0, options, ion\\Reader\\Options, MAY_BE_ARRAY|MAY_BE_NULL, "null")
-ZEND_END_ARG_INFO()
-
 #define arginfo_class_ion_Reader_Stream_Reader_getStream arginfo_class_ion_Catalog___construct
 
 #define arginfo_class_ion_Reader_Stream_Reader_resetStream arginfo_class_ion_Reader_Stream_resetStream
 
 #define arginfo_class_ion_Reader_Stream_Reader_resetStreamWithLength arginfo_class_ion_Reader_Stream_resetStreamWithLength
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Writer_Options___construct, 0, 0, 0)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Writer_Writer___construct, 0, 0, 0)
        ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, catalog, ion\\Catalog, 1, "null")
        ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, decimalContext, ion\\Decimal\\Context, 1, "null")
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, outputBinary, _IS_BOOL, 0, "false")
@@ -491,17 +482,24 @@ ZEND_END_ARG_INFO()
 
 #define arginfo_class_ion_Writer_Stream_getStream arginfo_class_ion_Catalog___construct
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Writer_Buffer_Writer___construct, 0, 0, 0)
-       ZEND_ARG_OBJ_TYPE_MASK(0, options, ion\\Writer\\Options, MAY_BE_ARRAY|MAY_BE_NULL, "null")
-ZEND_END_ARG_INFO()
-
 #define arginfo_class_ion_Writer_Buffer_Writer_getBuffer arginfo_class_ion_Symbol___toString
 
 #define arginfo_class_ion_Writer_Buffer_Writer_resetBuffer arginfo_class_ion_Writer_writeNull
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Writer_Stream_Writer___construct, 0, 0, 1)
        ZEND_ARG_INFO(0, stream)
-       ZEND_ARG_OBJ_TYPE_MASK(0, options, ion\\Writer\\Options, MAY_BE_ARRAY|MAY_BE_NULL, "null")
+       ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, catalog, ion\\Catalog, 1, "null")
+       ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, decimalContext, ion\\Decimal\\Context, 1, "null")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, outputBinary, _IS_BOOL, 0, "false")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, compactFloats, _IS_BOOL, 0, "false")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, escapeNonAscii, _IS_BOOL, 0, "false")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, prettyPrint, _IS_BOOL, 0, "false")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, indentTabs, _IS_BOOL, 0, "true")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, indentSize, IS_LONG, 0, "2")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flushEveryValue, _IS_BOOL, 0, "false")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, maxContainerDepth, IS_LONG, 0, "10")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, maxAnnotations, IS_LONG, 0, "10")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, tempBufferSize, IS_LONG, 0, "0x4000")
 ZEND_END_ARG_INFO()
 
 #define arginfo_class_ion_Writer_Stream_Writer_getStream arginfo_class_ion_Catalog___construct
@@ -553,7 +551,7 @@ static ZEND_METHOD(ion_Decimal_Context, Dec32);
 static ZEND_METHOD(ion_Decimal_Context, Dec64);
 static ZEND_METHOD(ion_Decimal_Context, Dec128);
 static ZEND_METHOD(ion_Decimal_Context, DecMax);
-static ZEND_METHOD(ion_Reader_Options, __construct);
+static ZEND_METHOD(ion_Reader_Reader, __construct);
 static ZEND_METHOD(ion_Reader_Reader, hasChildren);
 static ZEND_METHOD(ion_Reader_Reader, getChildren);
 static ZEND_METHOD(ion_Reader_Reader, rewind);
@@ -589,13 +587,11 @@ static ZEND_METHOD(ion_Reader_Reader, getDepth);
 static ZEND_METHOD(ion_Reader_Reader, seek);
 static ZEND_METHOD(ion_Reader_Reader, getValueOffset);
 static ZEND_METHOD(ion_Reader_Reader, getValueLength);
-static ZEND_METHOD(ion_Reader_Buffer_Reader, __construct);
 static ZEND_METHOD(ion_Reader_Buffer_Reader, getBuffer);
-static ZEND_METHOD(ion_Reader_Stream_Reader, __construct);
 static ZEND_METHOD(ion_Reader_Stream_Reader, getStream);
 static ZEND_METHOD(ion_Reader_Stream_Reader, resetStream);
 static ZEND_METHOD(ion_Reader_Stream_Reader, resetStreamWithLength);
-static ZEND_METHOD(ion_Writer_Options, __construct);
+static ZEND_METHOD(ion_Writer_Writer, __construct);
 static ZEND_METHOD(ion_Writer_Writer, writeNull);
 static ZEND_METHOD(ion_Writer_Writer, writeTypedNull);
 static ZEND_METHOD(ion_Writer_Writer, writeBool);
@@ -617,7 +613,6 @@ static ZEND_METHOD(ion_Writer_Writer, writeAnnotation);
 static ZEND_METHOD(ion_Writer_Writer, getDepth);
 static ZEND_METHOD(ion_Writer_Writer, flush);
 static ZEND_METHOD(ion_Writer_Writer, finish);
-static ZEND_METHOD(ion_Writer_Buffer_Writer, __construct);
 static ZEND_METHOD(ion_Writer_Buffer_Writer, getBuffer);
 static ZEND_METHOD(ion_Writer_Buffer_Writer, resetBuffer);
 static ZEND_METHOD(ion_Writer_Stream_Writer, __construct);
@@ -847,13 +842,8 @@ static const zend_function_entry class_ion_Timestamp_Format_methods[] = {
 };
 
 
-static const zend_function_entry class_ion_Reader_Options_methods[] = {
-       ZEND_ME(ion_Reader_Options, __construct, arginfo_class_ion_Reader_Options___construct, ZEND_ACC_PUBLIC)
-       ZEND_FE_END
-};
-
-
 static const zend_function_entry class_ion_Reader_Reader_methods[] = {
+       ZEND_ME(ion_Reader_Reader, __construct, arginfo_class_ion_Reader_Reader___construct, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Reader_Reader, hasChildren, arginfo_class_ion_Reader_Reader_hasChildren, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Reader_Reader, getChildren, arginfo_class_ion_Reader_Reader_getChildren, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Reader_Reader, rewind, arginfo_class_ion_Reader_Reader_rewind, ZEND_ACC_PUBLIC)
@@ -908,14 +898,12 @@ static const zend_function_entry class_ion_Reader_Stream_methods[] = {
 
 
 static const zend_function_entry class_ion_Reader_Buffer_Reader_methods[] = {
-       ZEND_ME(ion_Reader_Buffer_Reader, __construct, arginfo_class_ion_Reader_Buffer_Reader___construct, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Reader_Buffer_Reader, getBuffer, arginfo_class_ion_Reader_Buffer_Reader_getBuffer, ZEND_ACC_PUBLIC)
        ZEND_FE_END
 };
 
 
 static const zend_function_entry class_ion_Reader_Stream_Reader_methods[] = {
-       ZEND_ME(ion_Reader_Stream_Reader, __construct, arginfo_class_ion_Reader_Stream_Reader___construct, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Reader_Stream_Reader, getStream, arginfo_class_ion_Reader_Stream_Reader_getStream, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Reader_Stream_Reader, resetStream, arginfo_class_ion_Reader_Stream_Reader_resetStream, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Reader_Stream_Reader, resetStreamWithLength, arginfo_class_ion_Reader_Stream_Reader_resetStreamWithLength, ZEND_ACC_PUBLIC)
@@ -923,13 +911,8 @@ static const zend_function_entry class_ion_Reader_Stream_Reader_methods[] = {
 };
 
 
-static const zend_function_entry class_ion_Writer_Options_methods[] = {
-       ZEND_ME(ion_Writer_Options, __construct, arginfo_class_ion_Writer_Options___construct, ZEND_ACC_PUBLIC)
-       ZEND_FE_END
-};
-
-
 static const zend_function_entry class_ion_Writer_Writer_methods[] = {
+       ZEND_ME(ion_Writer_Writer, __construct, arginfo_class_ion_Writer_Writer___construct, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Writer_Writer, writeNull, arginfo_class_ion_Writer_Writer_writeNull, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Writer_Writer, writeTypedNull, arginfo_class_ion_Writer_Writer_writeTypedNull, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Writer_Writer, writeBool, arginfo_class_ion_Writer_Writer_writeBool, ZEND_ACC_PUBLIC)
@@ -969,7 +952,6 @@ static const zend_function_entry class_ion_Writer_Stream_methods[] = {
 
 
 static const zend_function_entry class_ion_Writer_Buffer_Writer_methods[] = {
-       ZEND_ME(ion_Writer_Buffer_Writer, __construct, arginfo_class_ion_Writer_Buffer_Writer___construct, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Writer_Buffer_Writer, getBuffer, arginfo_class_ion_Writer_Buffer_Writer_getBuffer, ZEND_ACC_PUBLIC)
        ZEND_ME(ion_Writer_Buffer_Writer, resetBuffer, arginfo_class_ion_Writer_Buffer_Writer_resetBuffer, ZEND_ACC_PUBLIC)
        ZEND_FE_END
@@ -1612,12 +1594,14 @@ static zend_class_entry *register_class_ion_Timestamp_Format(void)
        return class_entry;
 }
 
-static zend_class_entry *register_class_ion_Reader_Options(void)
+static zend_class_entry *register_class_ion_Reader_Reader(zend_class_entry *class_entry_ion_Reader)
 {
        zend_class_entry ce, *class_entry;
 
-       INIT_NS_CLASS_ENTRY(ce, "ion\\Reader", "Options", class_ion_Reader_Options_methods);
+       INIT_NS_CLASS_ENTRY(ce, "ion\\Reader", "Reader", class_ion_Reader_Reader_methods);
        class_entry = zend_register_internal_class_ex(&ce, NULL);
+       class_entry->ce_flags |= ZEND_ACC_ABSTRACT;
+       zend_class_implements(class_entry, 1, class_entry_ion_Reader);
 
        zend_string *property_catalog_class_ion_Catalog = zend_string_init("ion\\Catalog", sizeof("ion\\Catalog")-1, 1);
        zval property_catalog_default_value;
@@ -1679,25 +1663,6 @@ static zend_class_entry *register_class_ion_Reader_Options(void)
        return class_entry;
 }
 
-static zend_class_entry *register_class_ion_Reader_Reader(zend_class_entry *class_entry_ion_Reader)
-{
-       zend_class_entry ce, *class_entry;
-
-       INIT_NS_CLASS_ENTRY(ce, "ion\\Reader", "Reader", class_ion_Reader_Reader_methods);
-       class_entry = zend_register_internal_class_ex(&ce, NULL);
-       class_entry->ce_flags |= ZEND_ACC_ABSTRACT;
-       zend_class_implements(class_entry, 1, class_entry_ion_Reader);
-
-       zend_string *property_options_class_ion_Reader_Options = zend_string_init("ion\\Reader\\Options", sizeof("ion\\Reader\\Options")-1, 1);
-       zval property_options_default_value;
-       ZVAL_UNDEF(&property_options_default_value);
-       zend_string *property_options_name = zend_string_init("options", sizeof("options") - 1, 1);
-       zend_declare_typed_property(class_entry, property_options_name, &property_options_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_CLASS(property_options_class_ion_Reader_Options, 0, MAY_BE_NULL));
-       zend_string_release(property_options_name);
-
-       return class_entry;
-}
-
 static zend_class_entry *register_class_ion_Reader_Buffer(zend_class_entry *class_entry_ion_Reader)
 {
        zend_class_entry ce, *class_entry;
@@ -1742,12 +1707,14 @@ static zend_class_entry *register_class_ion_Reader_Stream_Reader(zend_class_entr
        return class_entry;
 }
 
-static zend_class_entry *register_class_ion_Writer_Options(void)
+static zend_class_entry *register_class_ion_Writer_Writer(zend_class_entry *class_entry_ion_Writer)
 {
        zend_class_entry ce, *class_entry;
 
-       INIT_NS_CLASS_ENTRY(ce, "ion\\Writer", "Options", class_ion_Writer_Options_methods);
+       INIT_NS_CLASS_ENTRY(ce, "ion\\Writer", "Writer", class_ion_Writer_Writer_methods);
        class_entry = zend_register_internal_class_ex(&ce, NULL);
+       class_entry->ce_flags |= ZEND_ACC_ABSTRACT;
+       zend_class_implements(class_entry, 1, class_entry_ion_Writer);
 
        zend_string *property_catalog_class_ion_Catalog = zend_string_init("ion\\Catalog", sizeof("ion\\Catalog")-1, 1);
        zval property_catalog_default_value;
@@ -1826,18 +1793,6 @@ static zend_class_entry *register_class_ion_Writer_Options(void)
        return class_entry;
 }
 
-static zend_class_entry *register_class_ion_Writer_Writer(zend_class_entry *class_entry_ion_Writer)
-{
-       zend_class_entry ce, *class_entry;
-
-       INIT_NS_CLASS_ENTRY(ce, "ion\\Writer", "Writer", class_ion_Writer_Writer_methods);
-       class_entry = zend_register_internal_class_ex(&ce, NULL);
-       class_entry->ce_flags |= ZEND_ACC_ABSTRACT;
-       zend_class_implements(class_entry, 1, class_entry_ion_Writer);
-
-       return class_entry;
-}
-
 static zend_class_entry *register_class_ion_Writer_Buffer(zend_class_entry *class_entry_ion_Writer)
 {
        zend_class_entry ce, *class_entry;
@@ -1879,6 +1834,80 @@ static zend_class_entry *register_class_ion_Writer_Stream_Writer(zend_class_entr
        class_entry = zend_register_internal_class_ex(&ce, class_entry_ion_Writer_Writer);
        zend_class_implements(class_entry, 1, class_entry_ion_Writer_Stream);
 
+       zend_string *property_catalog_class_ion_Catalog = zend_string_init("ion\\Catalog", sizeof("ion\\Catalog")-1, 1);
+       zval property_catalog_default_value;
+       ZVAL_UNDEF(&property_catalog_default_value);
+       zend_string *property_catalog_name = zend_string_init("catalog", sizeof("catalog") - 1, 1);
+       zend_declare_typed_property(class_entry, property_catalog_name, &property_catalog_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_CLASS(property_catalog_class_ion_Catalog, 0, MAY_BE_NULL));
+       zend_string_release(property_catalog_name);
+
+       zend_string *property_decimalContext_class_ion_Decimal_Context = zend_string_init("ion\\Decimal\\Context", sizeof("ion\\Decimal\\Context")-1, 1);
+       zval property_decimalContext_default_value;
+       ZVAL_UNDEF(&property_decimalContext_default_value);
+       zend_string *property_decimalContext_name = zend_string_init("decimalContext", sizeof("decimalContext") - 1, 1);
+       zend_declare_typed_property(class_entry, property_decimalContext_name, &property_decimalContext_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_CLASS(property_decimalContext_class_ion_Decimal_Context, 0, MAY_BE_NULL));
+       zend_string_release(property_decimalContext_name);
+
+       zval property_outputBinary_default_value;
+       ZVAL_UNDEF(&property_outputBinary_default_value);
+       zend_string *property_outputBinary_name = zend_string_init("outputBinary", sizeof("outputBinary") - 1, 1);
+       zend_declare_typed_property(class_entry, property_outputBinary_name, &property_outputBinary_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL));
+       zend_string_release(property_outputBinary_name);
+
+       zval property_compactFloats_default_value;
+       ZVAL_UNDEF(&property_compactFloats_default_value);
+       zend_string *property_compactFloats_name = zend_string_init("compactFloats", sizeof("compactFloats") - 1, 1);
+       zend_declare_typed_property(class_entry, property_compactFloats_name, &property_compactFloats_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL));
+       zend_string_release(property_compactFloats_name);
+
+       zval property_escapeNonAscii_default_value;
+       ZVAL_UNDEF(&property_escapeNonAscii_default_value);
+       zend_string *property_escapeNonAscii_name = zend_string_init("escapeNonAscii", sizeof("escapeNonAscii") - 1, 1);
+       zend_declare_typed_property(class_entry, property_escapeNonAscii_name, &property_escapeNonAscii_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL));
+       zend_string_release(property_escapeNonAscii_name);
+
+       zval property_prettyPrint_default_value;
+       ZVAL_UNDEF(&property_prettyPrint_default_value);
+       zend_string *property_prettyPrint_name = zend_string_init("prettyPrint", sizeof("prettyPrint") - 1, 1);
+       zend_declare_typed_property(class_entry, property_prettyPrint_name, &property_prettyPrint_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL));
+       zend_string_release(property_prettyPrint_name);
+
+       zval property_indentTabs_default_value;
+       ZVAL_UNDEF(&property_indentTabs_default_value);
+       zend_string *property_indentTabs_name = zend_string_init("indentTabs", sizeof("indentTabs") - 1, 1);
+       zend_declare_typed_property(class_entry, property_indentTabs_name, &property_indentTabs_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL));
+       zend_string_release(property_indentTabs_name);
+
+       zval property_indentSize_default_value;
+       ZVAL_UNDEF(&property_indentSize_default_value);
+       zend_string *property_indentSize_name = zend_string_init("indentSize", sizeof("indentSize") - 1, 1);
+       zend_declare_typed_property(class_entry, property_indentSize_name, &property_indentSize_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
+       zend_string_release(property_indentSize_name);
+
+       zval property_flushEveryValue_default_value;
+       ZVAL_UNDEF(&property_flushEveryValue_default_value);
+       zend_string *property_flushEveryValue_name = zend_string_init("flushEveryValue", sizeof("flushEveryValue") - 1, 1);
+       zend_declare_typed_property(class_entry, property_flushEveryValue_name, &property_flushEveryValue_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL));
+       zend_string_release(property_flushEveryValue_name);
+
+       zval property_maxContainerDepth_default_value;
+       ZVAL_UNDEF(&property_maxContainerDepth_default_value);
+       zend_string *property_maxContainerDepth_name = zend_string_init("maxContainerDepth", sizeof("maxContainerDepth") - 1, 1);
+       zend_declare_typed_property(class_entry, property_maxContainerDepth_name, &property_maxContainerDepth_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
+       zend_string_release(property_maxContainerDepth_name);
+
+       zval property_maxAnnotations_default_value;
+       ZVAL_UNDEF(&property_maxAnnotations_default_value);
+       zend_string *property_maxAnnotations_name = zend_string_init("maxAnnotations", sizeof("maxAnnotations") - 1, 1);
+       zend_declare_typed_property(class_entry, property_maxAnnotations_name, &property_maxAnnotations_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
+       zend_string_release(property_maxAnnotations_name);
+
+       zval property_tempBufferSize_default_value;
+       ZVAL_UNDEF(&property_tempBufferSize_default_value);
+       zend_string *property_tempBufferSize_name = zend_string_init("tempBufferSize", sizeof("tempBufferSize") - 1, 1);
+       zend_declare_typed_property(class_entry, property_tempBufferSize_name, &property_tempBufferSize_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
+       zend_string_release(property_tempBufferSize_name);
+
        return class_entry;
 }
 
index 344d20e6d172920c1696727e052ff86960175d30..21e355879bfaf57d65a099b3b77d5b453a5c9140 100644 (file)
@@ -231,7 +231,6 @@ static zend_class_entry
        *ce_Exception,
        *ce_LOB,
        *ce_Reader,
-       *ce_Reader_Options,
        *ce_Reader_Reader,
        *ce_Reader_Buffer,
        *ce_Reader_Stream,
@@ -254,7 +253,6 @@ static zend_class_entry
        *ce_Unserializer,
        *ce_Unserializer_Unserializer,
        *ce_Writer,
-       *ce_Writer_Options,
        *ce_Writer_Buffer,
        *ce_Writer_Buffer_Writer,
        *ce_Writer_Stream,
@@ -1158,25 +1156,13 @@ static void php_ion_catalog_symbol_table_zval(php_ion_catalog *obj, ION_SYMBOL_T
 
 php_ion_decl(catalog, Catalog);
 
-typedef struct php_ion_reader_options_ccn_ctx {
+typedef struct php_ion_reader_ccn_ctx {
        zend_object *obj;
        zend_fcall_info fci;
        zend_fcall_info_cache fcc;
-} php_ion_reader_options_ccn_ctx;
-
-typedef struct php_ion_reader_options {
-       ION_READER_OPTIONS opt;
-       php_ion_reader_options_ccn_ctx ccn;
-       zend_object *cat, *dec_ctx, *cb, std;
-} php_ion_reader_options;
-
-static void php_ion_reader_options_dtor(php_ion_reader_options *obj)
-{
-       if (obj->cb) {
-               zend_fcall_info_args_clear(&obj->ccn.fci, true);
-       }
-}
+} php_ion_reader_ccn_ctx;
 
+/*
 static void php_ion_reader_options_copy(php_ion_reader_options *new_obj, php_ion_reader_options *old_obj)
 {
        zend_objects_clone_members(&new_obj->std, &old_obj->std);
@@ -1192,8 +1178,7 @@ static void php_ion_reader_options_copy(php_ion_reader_options *new_obj, php_ion
                new_obj->opt.context_change_notifier.context = &new_obj->ccn;
        }
 }
-
-php_ion_decl(reader_options, Reader_Options);
+*/
 
 typedef struct php_ion_reader {
        ION_READER *reader;
@@ -1209,7 +1194,10 @@ typedef struct php_ion_reader {
                        ION_STRING buf;
                } stream;
        };
-       zend_object *opt, std;
+
+       ION_READER_OPTIONS options;
+       php_ion_reader_ccn_ctx ccn;
+       zend_object *cat, *dec_ctx, *cb, std;
 } php_ion_reader;
 
 static iERR php_ion_reader_stream_handler(struct _ion_user_stream *user)
@@ -1243,7 +1231,7 @@ static iERR on_context_change(void *context, ION_COLLECTION *imports)
        iERR e = IERR_OK;
 
        if (context) {
-               php_ion_reader_options_ccn_ctx *ctx = context;
+               php_ion_reader_ccn_ctx *ctx = context;
 
                zval zobj;
                ZVAL_OBJ(&zobj, ctx->obj);
@@ -1259,27 +1247,50 @@ static iERR on_context_change(void *context, ION_COLLECTION *imports)
 static void php_ion_reader_ctor(php_ion_reader *obj)
 {
        iERR err;
-       php_ion_reader_options *opt = php_ion_obj(reader_options, obj->opt);
 
-       if (!opt) {
-               obj->opt = object_construct(ce_Reader_Options, 0, NULL, NULL);
-               update_property_obj_ex(ce_Reader_Reader, &obj->std, ZEND_STRL("options"), obj->opt);
-               OBJ_RELEASE(obj->opt);
-       } else if (opt->opt.context_change_notifier.context) {
-               php_ion_reader_options_ccn_ctx *ctx = opt->opt.context_change_notifier.context;
-               ctx->obj = &obj->std;
-               opt->opt.context_change_notifier.notify = on_context_change;
+       if (obj->cb) {
+               zval zcb;
+               ZVAL_OBJ(&zcb, obj->cb);
+               zend_fcall_info_init(&zcb, 0, &obj->ccn.fci, &obj->ccn.fcc, NULL, NULL);
+               obj->ccn.obj = &obj->std;
+               obj->options.context_change_notifier.context = &obj->ccn;
+               obj->options.context_change_notifier.notify = on_context_change;
+               update_property_obj_ex(ce_Reader_Reader,&obj->std, ZEND_STRL("onContextChange"), obj->cb);
+       } else {
+               zend_update_property_null(ce_Reader_Reader, &obj->std, ZEND_STRL("onContextChange"));
+       }
+       if (obj->cat) {
+               update_property_obj_ex(ce_Reader_Reader,&obj->std, ZEND_STRL("catalog"), obj->cat);
+               obj->options.pcatalog = php_ion_obj(catalog, obj->cat)->cat;
+       } else {
+               zend_update_property_null(ce_Reader_Reader, &obj->std, ZEND_STRL("catalog"));
        }
+       if (obj->dec_ctx) {
+               update_property_obj_ex(ce_Reader_Reader,&obj->std, ZEND_STRL("decimalContext"), obj->dec_ctx);
+               obj->options.decimal_context = &php_ion_obj(decimal_ctx, obj->dec_ctx)->ctx;
+       } else {
+               zend_update_property_null(ce_Reader_Reader, &obj->std, ZEND_STRL("decimalContext"));
+       }
+
+       zend_update_property_bool(ce_Reader_Reader, &obj->std, ZEND_STRL("returnSystemValues"),
+                                                         obj->options.return_system_values);
+       zend_update_property_long(ce_Reader_Reader, &obj->std, ZEND_STRL("maxContainerDepth"),
+                                                         obj->options.max_container_depth);
+       zend_update_property_long(ce_Reader_Reader, &obj->std, ZEND_STRL("maxAnnotations"),
+                                                         obj->options.max_annotation_count);
+       zend_update_property_long(ce_Reader_Reader, &obj->std, ZEND_STRL("annotationBufferSize"),
+                                                         obj->options.max_annotation_buffered);
+       zend_update_property_long(ce_Reader_Reader, &obj->std, ZEND_STRL("tempBufferSize"),
+                                                         obj->options.chunk_threshold);
+       zend_update_property_bool(ce_Reader_Reader, &obj->std, ZEND_STRL("skipCharacterValidation"),
+                                                         obj->options.skip_character_validation);
+       
        if (obj->type == STREAM_READER) {
-               PTR_CHECK(obj->stream.ptr);
-               GC_ADDREF(obj->stream.ptr->res);
-
-               obj->stream.buf.length = opt && opt->opt.chunk_threshold ? opt->opt.chunk_threshold : 0x4000;
+               obj->stream.buf.length = obj->options.chunk_threshold ? obj->options.chunk_threshold : 0x4000;
                obj->stream.buf.value = emalloc(obj->stream.buf.length);
-               err = ion_reader_open_stream(&obj->reader, obj, php_ion_reader_stream_handler, opt ? &opt->opt : NULL);
-
+               err = ion_reader_open_stream(&obj->reader, obj, php_ion_reader_stream_handler, &obj->options);
        } else {
-               err = ion_reader_open_buffer(&obj->reader, (BYTE *) obj->buffer->val, (SIZE) obj->buffer->len, opt ? &opt->opt : NULL);
+               err = ion_reader_open_buffer(&obj->reader, (BYTE *) obj->buffer->val, (SIZE) obj->buffer->len, &obj->options);
        }
 
        ION_CHECK(err);
@@ -1291,6 +1302,9 @@ static void php_ion_reader_dtor(php_ion_reader *obj)
        if (obj->reader) {
                ion_reader_close(obj->reader);
        }
+       if (obj->cb) {
+               zend_fcall_info_args_clear(&obj->ccn.fci, true);
+       }
        if (obj->type == STREAM_READER) {
                if (obj->stream.buf.value) {
                        efree(obj->stream.buf.value);
@@ -1309,26 +1323,6 @@ static void php_ion_reader_dtor(php_ion_reader *obj)
 php_ion_decl_noclone(reader, Reader_Reader);
 #define clone_ion_Reader_Reader NULL
 
-typedef struct php_ion_writer_options {
-       ION_WRITER_OPTIONS opt;
-       zend_object *cat, *dec_ctx, std;
-} php_ion_writer_options;
-
-static void php_ion_writer_options_copy(php_ion_writer_options *new_obj, php_ion_writer_options *old_obj)
-{
-       zend_objects_clone_members(&new_obj->std, &old_obj->std);
-
-       new_obj->opt = old_obj->opt;
-       new_obj->cat = old_obj->cat;
-       new_obj->dec_ctx = old_obj->dec_ctx;
-}
-
-static void php_ion_writer_options_dtor(php_ion_writer_options *obj)
-{
-}
-
-php_ion_decl(writer_options, Writer_Options);
-
 typedef struct php_ion_writer {
        ION_WRITER *writer;
        enum {
@@ -1345,7 +1339,9 @@ typedef struct php_ion_writer {
                        php_stream *ptr;
                } stream;
        };
-       zend_object *opt, std;
+
+       ION_WRITER_OPTIONS options;
+       zend_object *cat, *dec_ctx, std;
 
 } php_ion_writer;
 
@@ -1364,12 +1360,9 @@ static iERR php_ion_writer_stream_handler(struct _ion_user_stream *user)
        return IERR_OK;
 }
 
-static void php_ion_writer_stream_init(php_ion_writer *obj, php_ion_writer_options *opt)
+static void php_ion_writer_stream_init(php_ion_writer *obj)
 {
-       PTR_CHECK(obj->stream.ptr);
-       GC_ADDREF(obj->stream.ptr->res);
-
-       obj->stream.buf.length = opt ? opt->opt.temp_buffer_size : 0x1000;
+       obj->stream.buf.length = obj->options.temp_buffer_size ? obj->options.temp_buffer_size : 0x1000;
        obj->stream.buf.value = emalloc(obj->stream.buf.length);
 }
 
@@ -1441,12 +1434,12 @@ static iERR php_ion_writer_buffer_handler(struct _ion_user_stream *user)
        return IERR_OK;
 }
 
-static void php_ion_writer_options_init_shared_imports(php_ion_writer_options *opt)
+static void php_ion_writer_init_shared_imports(php_ion_writer *obj)
 {
-       php_ion_catalog *cat = php_ion_obj(catalog, opt->cat);
+       php_ion_catalog *cat = php_ion_obj(catalog, obj->cat);
        OBJ_CHECK(cat);
 
-       ION_CHECK(ion_writer_options_initialize_shared_imports(&opt->opt));
+       ION_CHECK(ion_writer_options_initialize_shared_imports(&obj->options));
 
        ION_COLLECTION *col = php_ion_catalog_collection(cat);
        if (!ION_COLLECTION_IS_EMPTY(col)) {
@@ -1457,7 +1450,7 @@ static void php_ion_writer_options_init_shared_imports(php_ion_writer_options *o
                        ION_SYMBOL_TABLE **ptr;
                        ION_COLLECTION_NEXT(cur, ptr);
                        if (*ptr) {
-                               ION_CHECK(ion_writer_options_add_shared_imports_symbol_tables(&opt->opt, ptr, 1));
+                               ION_CHECK(ion_writer_options_add_shared_imports_symbol_tables(&obj->options, ptr, 1));
                        }
                }
        }
@@ -1465,30 +1458,51 @@ static void php_ion_writer_options_init_shared_imports(php_ion_writer_options *o
 
 static void php_ion_writer_ctor(php_ion_writer *obj)
 {
-       php_ion_writer_options *opt = NULL;
-
-       if (obj->opt) {
-               update_property_obj(&obj->std, ZEND_STRL("options"), obj->opt);
-               opt = php_ion_obj(writer_options, obj->opt);
-               if (opt->cat) {
-                       php_ion_writer_options_init_shared_imports(opt);
-               }
+       if (obj->dec_ctx) {
+               update_property_obj_ex(ce_Writer_Writer, &obj->std, ZEND_STRL("decimalContext"), obj->dec_ctx);
+               obj->options.decimal_context = &php_ion_obj(decimal_ctx, obj->dec_ctx)->ctx;
        } else {
-               obj->opt = object_construct(ce_Writer_Options, 0, NULL, NULL);
-               update_property_obj_ex(ce_Writer_Options, &obj->std, ZEND_STRL("options"), obj->opt);
-               OBJ_RELEASE(obj->opt);
+               zend_update_property_null(ce_Writer_Writer, &obj->std, ZEND_STRL("decimalContext"));
        }
+       if (obj->cat) {
+               update_property_obj_ex(ce_Writer_Writer, &obj->std, ZEND_STRL("catalog"), obj->cat);
+               obj->options.pcatalog = php_ion_obj(catalog, obj->cat)->cat;
+               php_ion_writer_init_shared_imports(obj);
+       } else {
+               zend_update_property_null(ce_Writer_Writer, &obj->std, ZEND_STRL("catalog"));
+       }
+
+       zend_update_property_bool(ce_Writer_Writer, &obj->std, ZEND_STRL("outputBinary"),
+                                                         obj->options.output_as_binary);
+       zend_update_property_bool(ce_Writer_Writer, &obj->std, ZEND_STRL("compactFloats"),
+                                                         obj->options.compact_floats);
+       zend_update_property_bool(ce_Writer_Writer, &obj->std, ZEND_STRL("escapeNonAscii"),
+                                                         obj->options.escape_all_non_ascii);
+       zend_update_property_bool(ce_Writer_Writer, &obj->std, ZEND_STRL("prettyPrint"),
+                                                         obj->options.pretty_print);
+       zend_update_property_bool(ce_Writer_Writer, &obj->std, ZEND_STRL("indentTabs"),
+                                                         obj->options.indent_with_tabs);
+       zend_update_property_long(ce_Writer_Writer, &obj->std, ZEND_STRL("indentSize"),
+                                                         obj->options.indent_size);
+       zend_update_property_bool(ce_Writer_Writer, &obj->std, ZEND_STRL("flushEveryValue"),
+                                                         obj->options.flush_every_value);
+       zend_update_property_long(ce_Writer_Writer, &obj->std, ZEND_STRL("maxContainerDepth"),
+                                                         obj->options.max_container_depth);
+       zend_update_property_long(ce_Writer_Writer, &obj->std, ZEND_STRL("maxAnnotations"),
+                                                         obj->options.max_annotation_count);
+       zend_update_property_long(ce_Writer_Writer, &obj->std, ZEND_STRL("tempBufferSize"),
+                                                         obj->options.temp_buffer_size);
 
        ION_STREAM_HANDLER h;
        if (obj->type == STREAM_WRITER) {
                h = php_ion_writer_stream_handler;
-               php_ion_writer_stream_init(obj, opt);
+               php_ion_writer_stream_init(obj);
        } else {
                h = php_ion_writer_buffer_handler;
                php_ion_writer_buffer_init(obj);
        }
 
-       ION_CHECK(ion_writer_open_stream(&obj->writer, h, obj, opt ? &opt->opt : NULL));
+       ION_CHECK(ion_writer_open_stream(&obj->writer, h, obj, &obj->options));
        OBJ_CHECK(obj);
 }
 
@@ -1497,11 +1511,8 @@ static void php_ion_writer_dtor(php_ion_writer *obj)
        if (obj->writer) {
                ion_writer_close(obj->writer);
        }
-       if (obj->opt) {
-               php_ion_writer_options *opt = php_ion_obj(writer_options, obj->opt);
-               if (opt->cat) {
-                       ion_writer_options_close_shared_imports(&opt->opt);
-               }
+       if (obj->cat) {
+               ion_writer_options_close_shared_imports(&obj->options);
        }
        if (obj->type == STREAM_WRITER) {
                if (obj->stream.buf.value) {
@@ -1869,7 +1880,7 @@ static void php_ion_serialize_object(php_ion_serializer *ser, zend_object *zobje
                        } else if (special_ce == ce_Timestamp) {
                                ION_TIMESTAMP its;
                                php_ion_timestamp *pts = php_ion_obj(timestamp, zobject);
-                               decContext *ctx = php_ion_obj(writer_options, php_ion_obj(writer, ser->wri)->opt)->opt.decimal_context;
+                               decContext *ctx = php_ion_obj(writer, ser->wri)->options.decimal_context;
                                ION_CHECK(ion_writer_write_timestamp(php_ion_obj(writer, ser->wri)->writer, ion_timestamp_from_php(&its, pts, ctx)));
                        } else {
                                assert(special_ce == ce_LOB);
@@ -2112,20 +2123,13 @@ void php_ion_serialize(php_ion_serializer *ser, zval *zv, zval *return_value)
                ION_CATCH();
        }
 
-       if (!ser->wri || !instanceof_function(ser->wri->ce, ce_Writer)) {
+       if (!ser->wri) {
                zo_wri = create_ion_Writer_Writer(ce_Writer_Buffer_Writer);
-               php_ion_writer *wri = php_ion_obj(writer, zo_wri);
-               wri->type = BUFFER_WRITER;
-               if (ser->wri && instanceof_function(ser->wri->ce, ce_Writer_Options)) {
-                       wri->opt = ser->wri;
-               }
-               php_ion_writer_ctor(wri);
+               php_ion_writer_ctor(php_ion_obj(writer, zo_wri));
                ser->wri = zo_wri;
        }
 
-       if (!EG(exception)) {
-               php_ion_serialize_ex(ser, zv);
-       }
+       php_ion_serialize_ex(ser, zv);
 
        /* make sure to flush when done, else str.s might not contain everything until the writer is closed */
        if (can_serialize_fast(ser)) {
@@ -2137,6 +2141,7 @@ void php_ion_serialize(php_ion_serializer *ser, zval *zv, zval *return_value)
 
        if (zo_wri) {
                OBJ_RELEASE(zo_wri);
+               ser->wri = NULL;
        }
        if (zo_ser) {
                OBJ_RELEASE(zo_ser);
@@ -2862,7 +2867,7 @@ static void php_ion_unserialize_zval(php_ion_unserializer *ser, zval *return_val
        case tid_TIMESTAMP_INT:
                if (can_unserialize_fast(ser)) {
                        php_ion_reader *reader = php_ion_obj(reader, ser->rdr);
-                       php_ion_reader_read_timestamp(reader->reader, &php_ion_obj(reader_options, reader->opt)->opt, return_value);
+                       php_ion_reader_read_timestamp(reader->reader, &reader->options, return_value);
                } else {
                        zend_call_method_with_0_params(&ser->std, NULL, NULL, "readTimestamp", return_value);
                }
@@ -2967,35 +2972,46 @@ static void php_ion_unserialize_ex(php_ion_unserializer *ser, zval *return_value
 
 static php_ion_reader *create_unserialize_reader(zval *zdata)
 {
-       zend_object *zo_reader;
-       php_ion_reader *reader = NULL;
        ZVAL_DEREF(zdata);
 
-       if (Z_TYPE_P(zdata) == IS_RESOURCE) {
-               zo_reader = create_ion_Reader_Reader(ce_Reader_Stream_Reader);
-               reader = php_ion_obj(reader, zo_reader);
-               reader->type = STREAM_READER;
-               php_stream_from_zval_no_verify(reader->stream.ptr, zdata);
-       } else if (Z_TYPE_P(zdata) <= IS_STRING) {
-               zo_reader = create_ion_Reader_Reader(ce_Reader_Buffer_Reader);
-               reader = php_ion_obj(reader, zo_reader);
-               reader->type = BUFFER_READER;
-               reader->buffer = zval_get_string(zdata);
-       } else if (Z_TYPE_P(zdata) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zdata), ce_Reader)) {
+       if (Z_TYPE_P(zdata) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zdata), ce_Reader)) {
                Z_ADDREF_P(zdata);
-               reader = php_ion_obj(reader, Z_OBJ_P(zdata));
+               return php_ion_obj(reader, Z_OBJ_P(zdata));
        } else {
-               zend_throw_exception_ex(ce_Exception, IERR_INVALID_ARG,
-                                                               "Invalid source to unserialize: expected string or resource, got %s",
-                                                               zend_zval_type_name(zdata));
-       }
+               zend_object *zo_reader = NULL;
+               php_ion_reader *reader = NULL;
+
+               if (Z_TYPE_P(zdata) == IS_RESOURCE) {
+                       zo_reader = create_ion_Reader_Reader(ce_Reader_Stream_Reader);
+                       reader = php_ion_obj(reader, zo_reader);
+                       reader->type = STREAM_READER;
+                       php_stream_from_zval_no_verify(reader->stream.ptr, zdata);
+                       PTR_CHECK_RETURN(NULL, reader->stream.ptr, OBJ_RELEASE(zo_reader));
+                       GC_ADDREF(reader->stream.ptr->res);
+                       php_ion_reader_ctor(reader);
+               } else if (Z_TYPE_P(zdata) <= IS_STRING) {
+                       zo_reader = create_ion_Reader_Reader(ce_Reader_Buffer_Reader);
+                       reader = php_ion_obj(reader, zo_reader);
+                       reader->type = BUFFER_READER;
+                       reader->buffer = zval_get_string(zdata);
+                       ION_CATCH_RETURN(NULL, OBJ_RELEASE(zo_reader));
+                       php_ion_reader_ctor(reader);
+               } else {
+                       zend_throw_exception_ex(ce_Exception, IERR_INVALID_ARG,
+                                                                       "Invalid source to unserialize: expected string or resource, got %s",
+                                                                       zend_zval_type_name(zdata));
+               }
 
-       return reader;
+               ION_CATCH_RETURN(NULL, if (zo_reader) {
+                       OBJ_RELEASE(zo_reader);
+               });
+               return reader;
+       }
 }
 
 void php_ion_unserialize(php_ion_unserializer *ser, zval *zdata, zval *return_value)
 {
-       zend_object *zo_opt = NULL, *zo_ser = NULL;
+       zend_object *zo_ser = NULL;
 
        if (!ser) {
                zo_ser = create_ion_Unserializer_Unserializer(NULL);
@@ -3008,20 +3024,14 @@ void php_ion_unserialize(php_ion_unserializer *ser, zval *zdata, zval *return_va
 
        php_ion_reader *reader = create_unserialize_reader(zdata);
        if (reader) {
-               if (ser->rdr && instanceof_function(ser->rdr->ce, ce_Reader_Options)) {
-                       zo_opt = reader->opt = ser->rdr;
-               }
-               php_ion_reader_ctor(reader);
                ser->rdr = &reader->std;
                if (!EG(exception)) {
                        php_ion_unserialize_ex(ser, return_value);
                }
                OBJ_RELEASE(&reader->std);
+               ser->rdr = NULL;
        }
 
-       if (zo_opt)  {
-               OBJ_RELEASE(zo_opt);
-       }
        if (zo_ser) {
                OBJ_RELEASE(zo_ser);
        }
diff --git a/tests/Reader/Options.phpt b/tests/Reader/Options.phpt
deleted file mode 100644 (file)
index b3d9c36..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
---TEST--
-ion\Reader\Options
---EXTENSIONS--
-ion
---FILE--
-TEST
-<?php
-$o = new ion\Reader\Options;
-var_dump($o, clone $o);
-
-$o = new ion\Reader\Options(
-       catalog: new ion\Catalog,
-       decimalContext: ion\Decimal\Context::Dec32(),
-       onContextChange: function(ion\Reader $r) {},
-       returnSystemValues: true,
-       skipCharacterValidation: true,
-);
-var_dump($o, clone $o);
-?>
-DONE
---EXPECTF--
-TEST
-object(ion\Reader\Options)#%d (9) {
-  ["catalog"]=>
-  NULL
-  ["decimalContext"]=>
-  NULL
-  ["onContextChange"]=>
-  NULL
-  ["returnSystemValues"]=>
-  bool(false)
-  ["maxContainerDepth"]=>
-  int(10)
-  ["maxAnnotations"]=>
-  int(10)
-  ["annotationBufferSize"]=>
-  int(16384)
-  ["tempBufferSize"]=>
-  int(16384)
-  ["skipCharacterValidation"]=>
-  bool(false)
-}
-object(ion\Reader\Options)#%d (9) {
-  ["catalog"]=>
-  NULL
-  ["decimalContext"]=>
-  NULL
-  ["onContextChange"]=>
-  NULL
-  ["returnSystemValues"]=>
-  bool(false)
-  ["maxContainerDepth"]=>
-  int(10)
-  ["maxAnnotations"]=>
-  int(10)
-  ["annotationBufferSize"]=>
-  int(16384)
-  ["tempBufferSize"]=>
-  int(16384)
-  ["skipCharacterValidation"]=>
-  bool(false)
-}
-object(ion\Reader\Options)#%d (9) {
-  ["catalog"]=>
-  object(ion\Catalog)#%d (1) {
-    ["symbolTables":"ion\Catalog":private]=>
-    array(0) {
-    }
-  }
-  ["decimalContext"]=>
-  object(ion\Decimal\Context)#%d (5) {
-    ["digits"]=>
-    int(7)
-    ["eMax"]=>
-    int(96)
-    ["eMin"]=>
-    int(-95)
-    ["round"]=>
-    int(3)
-    ["clamp"]=>
-    bool(true)
-  }
-  ["onContextChange"]=>
-  object(Closure)#%d (1) {
-    ["parameter"]=>
-    array(1) {
-      ["$r"]=>
-      string(10) "<required>"
-    }
-  }
-  ["returnSystemValues"]=>
-  bool(true)
-  ["maxContainerDepth"]=>
-  int(10)
-  ["maxAnnotations"]=>
-  int(10)
-  ["annotationBufferSize"]=>
-  int(16384)
-  ["tempBufferSize"]=>
-  int(16384)
-  ["skipCharacterValidation"]=>
-  bool(true)
-}
-object(ion\Reader\Options)#%d (9) {
-  ["catalog"]=>
-  object(ion\Catalog)#%d (1) {
-    ["symbolTables":"ion\Catalog":private]=>
-    array(0) {
-    }
-  }
-  ["decimalContext"]=>
-  object(ion\Decimal\Context)#%d (5) {
-    ["digits"]=>
-    int(7)
-    ["eMax"]=>
-    int(96)
-    ["eMin"]=>
-    int(-95)
-    ["round"]=>
-    int(3)
-    ["clamp"]=>
-    bool(true)
-  }
-  ["onContextChange"]=>
-  object(Closure)#%d (1) {
-    ["parameter"]=>
-    array(1) {
-      ["$r"]=>
-      string(10) "<required>"
-    }
-  }
-  ["returnSystemValues"]=>
-  bool(true)
-  ["maxContainerDepth"]=>
-  int(10)
-  ["maxAnnotations"]=>
-  int(10)
-  ["annotationBufferSize"]=>
-  int(16384)
-  ["tempBufferSize"]=>
-  int(16384)
-  ["skipCharacterValidation"]=>
-  bool(true)
-}
-DONE
index 1aa7be59f25cb258859829e14d19039f5e42c7d5..163b32cd4bd02ac2ee3708a3dcf720f46f467f91 100644 (file)
@@ -6,7 +6,7 @@ ion
 TEST
 <?php
 
-$w = new ion\Writer\Buffer\Writer(new ion\Writer\Options(outputBinary: true));
+$w = new ion\Writer\Buffer\Writer(outputBinary: true);
 
 $w->writeSymbol("local1");
 $w->writeSymbol("local1");
index b7957656faf685ded7f88017154a525d0bcbd578..f957f52d10c8157829d4cc5f11233a2ba0c3ab9d 100644 (file)
@@ -8,7 +8,7 @@ TEST
 
 $c = new ion\Catalog;
 $c->add(new ion\Symbol\Table\Shared("shared", 1, ["shared1", "shared2"]));
-$w = new ion\Writer\Buffer\Writer(new ion\Writer\Options(catalog: $c, outputBinary: true));
+$w = new ion\Writer\Buffer\Writer(catalog: $c, outputBinary: true);
 
 $w->writeSymbol("shared1");
 $w->writeSymbol("shared1");
@@ -38,10 +38,10 @@ foreach ($s as $sym) {
 }
 
 $u = new ion\Unserializer\Unserializer(multiSequence: true);
-var_dump($u->unserialize(new ion\Reader\Buffer\Reader($w->getBuffer(), [
-               "catalog" => $c,
-               "onContextChange" => fn(ion\Reader $r) => print("on_context_change\n")
-])));
+var_dump($u->unserialize(new ion\Reader\Buffer\Reader($w->getBuffer(),
+               catalog: $c,
+               onContextChange: fn(ion\Reader $r) => print("on_context_change\n")
+)));
 
 ?>
 DONE
index 1a04a14385ac9ac341e6f35dc601f7f63683e85d..201db836210320a44aa14658df21445a26175b74 100644 (file)
@@ -8,8 +8,7 @@ date.timezone=UTC
 TEST
 <?php
 
-$w = new ion\Writer\Stream\Writer(STDOUT,
-       new ion\Writer\Options(flushEveryValue: true));
+$w = new ion\Writer\Stream\Writer(STDOUT, flushEveryValue: true);
 
 $w->writeNull();
 echo "\n";
diff --git a/tests/Writer/Options.phpt b/tests/Writer/Options.phpt
deleted file mode 100644 (file)
index 8f7e0cc..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
---TEST--
-ion\Writer\Options
---EXTENSIONS--
-ion
---FILE--
-TEST
-<?php
-$o = new ion\Writer\Options;
-var_dump($o, clone $o);
-
-$o = new ion\Writer\Options(
-       catalog: new ion\Catalog,
-       decimalContext: ion\Decimal\Context::Dec64(),
-       outputBinary: true,
-       maxContainerDepth: 20,
-       tempBufferSize: 0x20000
-);
-var_dump($o, clone $o);
-?>
-DONE
---EXPECTF--
-TEST
-object(ion\Writer\Options)#%d (12) {
-  ["catalog"]=>
-  NULL
-  ["decimalContext"]=>
-  NULL
-  ["outputBinary"]=>
-  bool(false)
-  ["compactFloats"]=>
-  bool(false)
-  ["escapeNonAscii"]=>
-  bool(false)
-  ["prettyPrint"]=>
-  bool(false)
-  ["indentTabs"]=>
-  bool(true)
-  ["indentSize"]=>
-  int(2)
-  ["flushEveryValue"]=>
-  bool(false)
-  ["maxContainerDepth"]=>
-  int(10)
-  ["maxAnnotations"]=>
-  int(10)
-  ["tempBufferSize"]=>
-  int(16384)
-}
-object(ion\Writer\Options)#%d (12) {
-  ["catalog"]=>
-  NULL
-  ["decimalContext"]=>
-  NULL
-  ["outputBinary"]=>
-  bool(false)
-  ["compactFloats"]=>
-  bool(false)
-  ["escapeNonAscii"]=>
-  bool(false)
-  ["prettyPrint"]=>
-  bool(false)
-  ["indentTabs"]=>
-  bool(true)
-  ["indentSize"]=>
-  int(2)
-  ["flushEveryValue"]=>
-  bool(false)
-  ["maxContainerDepth"]=>
-  int(10)
-  ["maxAnnotations"]=>
-  int(10)
-  ["tempBufferSize"]=>
-  int(16384)
-}
-object(ion\Writer\Options)#%d (12) {
-  ["catalog"]=>
-  object(ion\Catalog)#%d (1) {
-    ["symbolTables":"ion\Catalog":private]=>
-    array(0) {
-    }
-  }
-  ["decimalContext"]=>
-  object(ion\Decimal\Context)#%d (5) {
-    ["digits"]=>
-    int(16)
-    ["eMax"]=>
-    int(384)
-    ["eMin"]=>
-    int(-383)
-    ["round"]=>
-    int(3)
-    ["clamp"]=>
-    bool(true)
-  }
-  ["outputBinary"]=>
-  bool(true)
-  ["compactFloats"]=>
-  bool(false)
-  ["escapeNonAscii"]=>
-  bool(false)
-  ["prettyPrint"]=>
-  bool(false)
-  ["indentTabs"]=>
-  bool(true)
-  ["indentSize"]=>
-  int(2)
-  ["flushEveryValue"]=>
-  bool(false)
-  ["maxContainerDepth"]=>
-  int(20)
-  ["maxAnnotations"]=>
-  int(10)
-  ["tempBufferSize"]=>
-  int(131072)
-}
-object(ion\Writer\Options)#%d (12) {
-  ["catalog"]=>
-  object(ion\Catalog)#%d (1) {
-    ["symbolTables":"ion\Catalog":private]=>
-    array(0) {
-    }
-  }
-  ["decimalContext"]=>
-  object(ion\Decimal\Context)#%d (5) {
-    ["digits"]=>
-    int(16)
-    ["eMax"]=>
-    int(384)
-    ["eMin"]=>
-    int(-383)
-    ["round"]=>
-    int(3)
-    ["clamp"]=>
-    bool(true)
-  }
-  ["outputBinary"]=>
-  bool(true)
-  ["compactFloats"]=>
-  bool(false)
-  ["escapeNonAscii"]=>
-  bool(false)
-  ["prettyPrint"]=>
-  bool(false)
-  ["indentTabs"]=>
-  bool(true)
-  ["indentSize"]=>
-  int(2)
-  ["flushEveryValue"]=>
-  bool(false)
-  ["maxContainerDepth"]=>
-  int(20)
-  ["maxAnnotations"]=>
-  int(10)
-  ["tempBufferSize"]=>
-  int(131072)
-}
-DONE
index e9fee64a0f807e006a1951348f71610ea55b056e..a21b5b10335758d544f01b93093603200524cf9a 100644 (file)
@@ -7,7 +7,7 @@ TEST
 <?php
 
 class AutoUtf8 extends ion\Serializer\Serializer {
-       public function serialize(mixed $data, \ion\Writer\Options|\ion\Writer|array|null $writer = null): mixed {
+       public function serialize(mixed $data, \ion\Writer|array|null $writer = null): mixed {
                return parent::serialize($data, new class extends \ion\Writer\Buffer\Writer {
                        private function iterate(string $s) : Generator {
                                for ($i = 0; $i < grapheme_strlen($s); ++$i) {
index c81c3ab80727e2baa4ff1c08b87d133d23399cb8..29f23fcc8140b941fdf4ac2f0b7abe1b0333dff2 100644 (file)
@@ -7,7 +7,7 @@ TEST
 <?php
 
 class NoDecimals extends ion\Serializer\Serializer {
-       public function serialize(mixed $data, \ion\Writer\Options|\ion\Writer|array|null $writer = null): mixed {
+       public function serialize(mixed $data, \ion\Writer|array|null $writer = null): mixed {
                return parent::serialize($data, new class extends \ion\Writer\Buffer\Writer {
                        public function writeDecimal(\ion\Decimal|string $value): void {
                                if ($value instanceof \ion\Decimal) {