docs: attempt to fix gh-pages
[awesomized/ext-ion] / ion.c
diff --git a/ion.c b/ion.c
index fe7a38e4b6f732649434ca153c17a3a19a0cf288..f101f4c6c8a5f21b23af2ad2cbd6b40171b4173b 100644 (file)
--- a/ion.c
+++ b/ion.c
@@ -864,7 +864,12 @@ static ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbols)
 
        ZEND_PARSE_PARAMETERS_NONE();
 
-       int32_t count, max = php_ion_obj(reader_options, obj->opt)->opt.max_annotation_count;
+       int32_t count, max;
+       if (obj->opt) {
+               max = php_ion_obj(reader_options, obj->opt)->opt.max_annotation_count;
+       } else {
+               max = 10;
+       }
        ION_SYMBOL *ptr = ecalloc(sizeof(*ptr), max);
        iERR err = ion_reader_get_annotation_symbols(obj->reader, ptr, max, &count);
        if (!err) {
@@ -955,7 +960,9 @@ static ZEND_METHOD(ion_Reader_Reader, readFloat)
 
        ZEND_PARSE_PARAMETERS_NONE();
 
-       ION_CHECK(ion_reader_read_double(obj->reader, &Z_DVAL_P(return_value)));
+       double dval;
+       ION_CHECK(ion_reader_read_double(obj->reader, &dval));
+       RETURN_DOUBLE(dval);
 }
 static ZEND_METHOD(ion_Reader_Reader, readDecimal)
 {
@@ -1196,7 +1203,7 @@ static ZEND_METHOD(ion_Reader_Stream_Reader, resetStreamWithLength)
 
        zval *zstream;
        zend_long length;
-       ZEND_PARSE_PARAMETERS_START(1, 2);
+       ZEND_PARSE_PARAMETERS_START(2, 2);
                Z_PARAM_RESOURCE(zstream);
                Z_PARAM_LONG(length)
        ZEND_PARSE_PARAMETERS_END();
@@ -1218,7 +1225,7 @@ static ZEND_METHOD(ion_Writer_Options, __construct)
        zend_bool binary = false, compact_floats = false, escape = false, pretty = false,
                        tabs = true, small_cntr_inl = true, suppress_sys = false, flush = false;
        zend_long indent = 2, max_depth = 10, max_ann = 10, temp = 0x4000, alloc = 0x10000;
-       ZEND_PARSE_PARAMETERS_START(0, 16)
+       ZEND_PARSE_PARAMETERS_START(0, 15)
                Z_PARAM_OPTIONAL
                //public readonly ?\ion\Catalog $catalog = null,
                Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->cat, ce_Catalog)
@@ -1369,8 +1376,17 @@ static ZEND_METHOD(ion_Writer_Writer, writeDecimal)
        ZEND_PARSE_PARAMETERS_END();
 
        if (dec_str) {
-               ION_STRING s;
-               ION_CHECK(ion_writer_write_string(obj->writer, ion_string_from_zend(&s, dec_str)));
+               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;
+                       }
+               }
+               ION_CHECK(ion_decimal_from_string(&dec, dec_str->val, ctx));
+               ION_CHECK(ion_writer_write_ion_decimal(obj->writer, &dec));
        } else {
                php_ion_decimal *dec = php_ion_obj(decimal, dec_obj);
                ION_CHECK(ion_writer_write_ion_decimal(obj->writer, &dec->dec));
@@ -1578,9 +1594,6 @@ static ZEND_METHOD(ion_Writer_Writer, flush)
 
        SIZE flushed;
        ION_CHECK(ion_writer_flush(obj->writer, &flushed));
-       if (obj->type == BUFFER_WRITER) {
-               smart_str_0(&obj->buffer.str);
-       }
        RETURN_LONG(flushed);
 }
 static ZEND_METHOD(ion_Writer_Writer, finish)
@@ -1592,33 +1605,19 @@ static ZEND_METHOD(ion_Writer_Writer, finish)
 
        SIZE flushed;
        ION_CHECK(ion_writer_finish(obj->writer, &flushed));
-       if (obj->type == BUFFER_WRITER) {
-               smart_str_0(&obj->buffer.str);
-       }
        RETURN_LONG(flushed);
 }
-static ZEND_METHOD(ion_Writer_Writer, writeOne)
-{
-}
-static ZEND_METHOD(ion_Writer_Writer, writeAll)
-{
-}
 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 *ref;
-       ZEND_PARSE_PARAMETERS_START(1, 2)
-               Z_PARAM_ZVAL(ref)
+       ZEND_PARSE_PARAMETERS_START(0, 1)
                Z_PARAM_OPTIONAL
                Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->opt, ce_Writer_Options)
        ZEND_PARSE_PARAMETERS_END();
 
        obj->type = BUFFER_WRITER;
-       ZVAL_COPY(&obj->buffer.val, ref);
-       zval_dtor(Z_REFVAL_P(ref));
-
        php_ion_writer_ctor(obj);
 }
 static ZEND_METHOD(ion_Writer_Buffer_Writer, getBuffer)
@@ -1628,7 +1627,16 @@ static ZEND_METHOD(ion_Writer_Buffer_Writer, getBuffer)
 
        ZEND_PARSE_PARAMETERS_NONE();
 
-       RETVAL_STR(zend_string_dup(obj->buffer.str.s, 0));
+       RETVAL_STR(php_ion_writer_buffer_copy(obj));
+}
+static ZEND_METHOD(ion_Writer_Buffer_Writer, resetBuffer)
+{
+       php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
+       OBJ_CHECK(obj);
+
+       ZEND_PARSE_PARAMETERS_NONE();
+
+       php_ion_writer_buffer_reset(obj);
 }
 static ZEND_METHOD(ion_Writer_Stream_Writer, __construct)
 {