From 7b91707b6d7cb6537351c291a6d78e491fb059f8 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 12 Jan 2022 16:03:52 +0100 Subject: [PATCH] coverage++ --- Makefile.frag | 2 +- config.m4 | 6 + ion.c | 21 ++-- ion.stub.php | 8 +- ion_arginfo.h | 158 ++++++++++++--------------- ion_private.h | 45 ++++---- tests/Catalog.phpt | 22 +++- tests/Decimal/Context.phpt | 13 +++ tests/Symbol/Table.phpt | 20 ++++ tests/Timestamp.phpt | 14 +++ tests/Writer.phpt | 95 ++++++++++++++++ tests/Writer/Options.phpt | 5 +- tests/serialize/multisequence.phpt | 14 +++ tests/unserialize/multisequence.phpt | 21 ++++ 14 files changed, 313 insertions(+), 131 deletions(-) create mode 100644 tests/Writer.phpt create mode 100644 tests/serialize/multisequence.phpt create mode 100644 tests/unserialize/multisequence.phpt diff --git a/Makefile.frag b/Makefile.frag index 6a88b58..4097980 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -7,7 +7,7 @@ $(builddir)/ion-c/build: mkdir -p $@ +cd $@ && CFLAGS=-w CXXFLAGS=-w \ $(CMAKE) -Wno-dev --log-level=ERROR \ - -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_BUILD_TYPE=$(LIB_IONC_BUILD) \ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ $(srcdir)/ion-c diff --git a/config.m4 b/config.m4 index 28b6ee2..ad903f9 100644 --- a/config.m4 +++ b/config.m4 @@ -51,6 +51,12 @@ AC_DEFUN([ION_BUNDLE], [dnl EXTRA_LDFLAGS_PROGRAM="$EXTRA_LDFLAGS_PROGRAM -L$builddir/ionc -L$builddir/decNumber" fi + if test "$PHP_DEBUG" = 1; then + LIB_IONC_BUILD=Debug + else + LIB_IONC_BUILD=Release + fi + PHP_SUBST(LIB_IONC_BUILD) PHP_ADD_MAKEFILE_FRAGMENT() ]) AC_DEFUN([ION_CHECK_LIB], [dnl diff --git a/ion.c b/ion.c index 28d5a5c..f101f4c 100644 --- a/ion.c +++ b/ion.c @@ -1225,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) @@ -1376,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)); @@ -1598,12 +1607,6 @@ static ZEND_METHOD(ion_Writer_Writer, finish) ION_CHECK(ion_writer_finish(obj->writer, &flushed)); 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)); diff --git a/ion.stub.php b/ion.stub.php index 7818dde..750ee9c 100644 --- a/ion.stub.php +++ b/ion.stub.php @@ -465,8 +465,8 @@ interface Writer { public function flush() : int; public function finish() : int; - public function writeOne(Reader $reader) : void; - public function writeAll(Reader $reader) : void; + // public function writeOne(Reader $reader) : void; + // public function writeAll(Reader $reader) : void; // public function getCatalog() : Catalog; // public function setCatalog(Catalog $catalog) : void; @@ -504,8 +504,8 @@ abstract class Writer implements \ion\Writer { public function flush() : int {} public function finish() : int {} - public function writeOne(\ion\Reader $reader) : void {} - public function writeAll(\ion\Reader $reader) : void {} + // public function writeOne(\ion\Reader $reader) : void {} + // public function writeAll(\ion\Reader $reader) : void {} } namespace ion\Writer; diff --git a/ion_arginfo.h b/ion_arginfo.h index 5015b69..d23af5c 100644 --- a/ion_arginfo.h +++ b/ion_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: aafe212ff9dd7fd15753fa5b6a3c127a51073241 */ + * Stub hash: 3308325e021d22db87092646b58d431f8f988532 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_ion_Symbol_Table_PHP, 0, 0, ion\\Symbol\\Table, 0) ZEND_END_ARG_INFO() @@ -16,6 +16,21 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ion_unserialize, 0, 1, IS_MIXED, ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, unserializer, ion\\Unserializer, 1, "null") ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Symbol___construct, 0, 0, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, value, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sid, IS_LONG, 0, "-1") + ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, importLocation, ion\\Symbol\\ImportLocation, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Symbol_equals, 0, 1, _IS_BOOL, 0) + ZEND_ARG_OBJ_INFO(0, symbol, ion\\Symbol, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Symbol___toString, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_ion_Symbol_toString arginfo_class_ion_Symbol___toString + ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Symbol_ImportLocation___construct, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, location, IS_LONG, 0) @@ -27,34 +42,19 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Symbol_Enum_toSID, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Symbol_Enum_toString, 0, 0, IS_STRING, 0) -ZEND_END_ARG_INFO() +#define arginfo_class_ion_Symbol_Enum_toString arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Symbol_Table_System_toSymbol arginfo_class_ion_Symbol_Enum_toSymbol #define arginfo_class_ion_Symbol_Table_System_toSID arginfo_class_ion_Symbol_Enum_toSID -#define arginfo_class_ion_Symbol_Table_System_toString arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Symbol_Table_System_toString arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Symbol_Table_PHP_toSymbol arginfo_class_ion_Symbol_Enum_toSymbol #define arginfo_class_ion_Symbol_Table_PHP_toSID arginfo_class_ion_Symbol_Enum_toSID -#define arginfo_class_ion_Symbol_Table_PHP_toString arginfo_class_ion_Symbol_Enum_toString - -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Symbol___construct, 0, 0, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, value, IS_STRING, 1, "null") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sid, IS_LONG, 0, "-1") - ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, importLocation, ion\\Symbol\\ImportLocation, 1, "null") -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Symbol_equals, 0, 1, _IS_BOOL, 0) - ZEND_ARG_OBJ_INFO(0, symbol, ion\\Symbol, 0) -ZEND_END_ARG_INFO() - -#define arginfo_class_ion_Symbol___toString arginfo_class_ion_Symbol_Enum_toString - -#define arginfo_class_ion_Symbol_toString arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Symbol_Table_PHP_toString arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Symbol_Table_getMaxId arginfo_class_ion_Symbol_Enum_toSID @@ -150,9 +150,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Decimal_isInt, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() -#define arginfo_class_ion_Decimal___toString arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Decimal___toString arginfo_class_ion_Symbol___toString -#define arginfo_class_ion_Decimal_toString arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Decimal_toString arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Decimal_toInt arginfo_class_ion_Symbol_Enum_toSID @@ -163,7 +163,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Timestamp___construct, 0, 0, 1) ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, timezone, DateTimeZone, 1, "null") ZEND_END_ARG_INFO() -#define arginfo_class_ion_Timestamp___toString arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Timestamp___toString arginfo_class_ion_Symbol___toString ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ion_Reader_getType, 0, 0, ion\\Type, 0) ZEND_END_ARG_INFO() @@ -178,7 +178,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_ion_Reader_isInStruct arginfo_class_ion_Decimal_isInt -#define arginfo_class_ion_Reader_getFieldName arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Reader_getFieldName arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Reader_getFieldNameSymbol arginfo_class_ion_Symbol_Enum_toSymbol @@ -215,14 +215,14 @@ ZEND_END_ARG_INFO() #define arginfo_class_ion_Reader_readSymbol arginfo_class_ion_Symbol_Enum_toSymbol -#define arginfo_class_ion_Reader_readString arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Reader_readString arginfo_class_ion_Symbol___toString ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Reader_readStringPart, 0, 1, _IS_BOOL, 0) ZEND_ARG_INFO(1, string) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "0x1000") ZEND_END_ARG_INFO() -#define arginfo_class_ion_Reader_readLob arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Reader_readLob arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Reader_readLobPart arginfo_class_ion_Reader_readStringPart @@ -282,7 +282,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_ion_Reader_Reader_isInStruct arginfo_class_ion_Decimal_isInt -#define arginfo_class_ion_Reader_Reader_getFieldName arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Reader_Reader_getFieldName arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Reader_Reader_getFieldNameSymbol arginfo_class_ion_Symbol_Enum_toSymbol @@ -310,11 +310,11 @@ ZEND_END_ARG_INFO() #define arginfo_class_ion_Reader_Reader_readSymbol arginfo_class_ion_Symbol_Enum_toSymbol -#define arginfo_class_ion_Reader_Reader_readString arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Reader_Reader_readString arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Reader_Reader_readStringPart arginfo_class_ion_Reader_readStringPart -#define arginfo_class_ion_Reader_Reader_readLob arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Reader_Reader_readLob arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Reader_Reader_readLobPart arginfo_class_ion_Reader_readStringPart @@ -328,14 +328,14 @@ ZEND_END_ARG_INFO() #define arginfo_class_ion_Reader_Reader_getValueLength arginfo_class_ion_Symbol_Enum_toSID -#define arginfo_class_ion_Reader_Buffer_getBuffer arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Reader_Buffer_getBuffer arginfo_class_ion_Symbol___toString 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_INFO_WITH_DEFAULT_VALUE(0, options, ion\\Reader\\Options, 1, "null") ZEND_END_ARG_INFO() -#define arginfo_class_ion_Reader_Buffer_Reader_getBuffer arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Reader_Buffer_Reader_getBuffer arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Reader_Stream_getStream arginfo_class_ion_Symbol_Table_Local___construct @@ -441,12 +441,6 @@ ZEND_END_ARG_INFO() #define arginfo_class_ion_Writer_finish arginfo_class_ion_Symbol_Enum_toSID -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Writer_writeOne, 0, 1, IS_VOID, 0) - ZEND_ARG_OBJ_INFO(0, reader, ion\\Reader, 0) -ZEND_END_ARG_INFO() - -#define arginfo_class_ion_Writer_writeAll arginfo_class_ion_Writer_writeOne - #define arginfo_class_ion_Writer_Writer_writeNull arginfo_class_ion_Reader_Reader_rewind #define arginfo_class_ion_Writer_Writer_writeTypedNull arginfo_class_ion_Writer_writeTypedNull @@ -489,11 +483,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_ion_Writer_Writer_finish arginfo_class_ion_Symbol_Enum_toSID -#define arginfo_class_ion_Writer_Writer_writeOne arginfo_class_ion_Writer_writeOne - -#define arginfo_class_ion_Writer_Writer_writeAll arginfo_class_ion_Writer_writeOne - -#define arginfo_class_ion_Writer_Buffer_getBuffer arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Writer_Buffer_getBuffer arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Writer_Buffer_resetBuffer arginfo_class_ion_Reader_Reader_rewind @@ -501,7 +491,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Writer_Buffer_Writer___construct, 0, 0, ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, options, ion\\Writer\\Options, 1, "null") ZEND_END_ARG_INFO() -#define arginfo_class_ion_Writer_Buffer_Writer_getBuffer arginfo_class_ion_Symbol_Enum_toString +#define arginfo_class_ion_Writer_Buffer_Writer_getBuffer arginfo_class_ion_Symbol___toString #define arginfo_class_ion_Writer_Buffer_Writer_resetBuffer arginfo_class_ion_Reader_Reader_rewind @@ -545,10 +535,10 @@ static ZEND_FUNCTION(ion_Symbol_Table_PHP); static ZEND_FUNCTION(ion_Symbol_Table_System); static ZEND_FUNCTION(ion_serialize); static ZEND_FUNCTION(ion_unserialize); -static ZEND_METHOD(ion_Symbol_ImportLocation, __construct); static ZEND_METHOD(ion_Symbol, __construct); static ZEND_METHOD(ion_Symbol, equals); static ZEND_METHOD(ion_Symbol, __toString); +static ZEND_METHOD(ion_Symbol_ImportLocation, __construct); static ZEND_METHOD(ion_Symbol_Table_Local, __construct); static ZEND_METHOD(ion_Symbol_Table_Local, import); static ZEND_METHOD(ion_Symbol_Table_Shared, __construct); @@ -635,8 +625,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_Writer, writeOne); -static ZEND_METHOD(ion_Writer_Writer, writeAll); static ZEND_METHOD(ion_Writer_Buffer_Writer, __construct); static ZEND_METHOD(ion_Writer_Buffer_Writer, getBuffer); static ZEND_METHOD(ion_Writer_Buffer_Writer, resetBuffer); @@ -662,6 +650,15 @@ static const zend_function_entry class_ion_Type_methods[] = { }; +static const zend_function_entry class_ion_Symbol_methods[] = { + ZEND_ME(ion_Symbol, __construct, arginfo_class_ion_Symbol___construct, ZEND_ACC_PUBLIC) + ZEND_ME(ion_Symbol, equals, arginfo_class_ion_Symbol_equals, ZEND_ACC_PUBLIC) + ZEND_ME(ion_Symbol, __toString, arginfo_class_ion_Symbol___toString, ZEND_ACC_PUBLIC) + ZEND_MALIAS(ion_Symbol, toString, __toString, arginfo_class_ion_Symbol_toString, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; + + static const zend_function_entry class_ion_Symbol_ImportLocation_methods[] = { ZEND_ME(ion_Symbol_ImportLocation, __construct, arginfo_class_ion_Symbol_ImportLocation___construct, ZEND_ACC_PUBLIC) ZEND_FE_END @@ -692,15 +689,6 @@ static const zend_function_entry class_ion_Symbol_Table_PHP_methods[] = { }; -static const zend_function_entry class_ion_Symbol_methods[] = { - ZEND_ME(ion_Symbol, __construct, arginfo_class_ion_Symbol___construct, ZEND_ACC_PUBLIC) - ZEND_ME(ion_Symbol, equals, arginfo_class_ion_Symbol_equals, ZEND_ACC_PUBLIC) - ZEND_ME(ion_Symbol, __toString, arginfo_class_ion_Symbol___toString, ZEND_ACC_PUBLIC) - ZEND_MALIAS(ion_Symbol, toString, __toString, arginfo_class_ion_Symbol_toString, ZEND_ACC_PUBLIC) - ZEND_FE_END -}; - - static const zend_function_entry class_ion_Symbol_Table_methods[] = { ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Symbol_Table, getMaxId, arginfo_class_ion_Symbol_Table_getMaxId, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Symbol_Table, add, arginfo_class_ion_Symbol_Table_add, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) @@ -928,8 +916,6 @@ static const zend_function_entry class_ion_Writer_methods[] = { ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Writer, getDepth, arginfo_class_ion_Writer_getDepth, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Writer, flush, arginfo_class_ion_Writer_flush, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Writer, finish, arginfo_class_ion_Writer_finish, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) - ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Writer, writeOne, arginfo_class_ion_Writer_writeOne, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) - ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Writer, writeAll, arginfo_class_ion_Writer_writeAll, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) ZEND_FE_END }; @@ -956,8 +942,6 @@ static const zend_function_entry class_ion_Writer_Writer_methods[] = { ZEND_ME(ion_Writer_Writer, getDepth, arginfo_class_ion_Writer_Writer_getDepth, ZEND_ACC_PUBLIC) ZEND_ME(ion_Writer_Writer, flush, arginfo_class_ion_Writer_Writer_flush, ZEND_ACC_PUBLIC) ZEND_ME(ion_Writer_Writer, finish, arginfo_class_ion_Writer_Writer_finish, ZEND_ACC_PUBLIC) - ZEND_ME(ion_Writer_Writer, writeOne, arginfo_class_ion_Writer_Writer_writeOne, ZEND_ACC_PUBLIC) - ZEND_ME(ion_Writer_Writer, writeAll, arginfo_class_ion_Writer_Writer_writeAll, ZEND_ACC_PUBLIC) ZEND_FE_END }; @@ -1086,6 +1070,35 @@ static zend_class_entry *register_class_ion_Type(void) return class_entry; } +static zend_class_entry *register_class_ion_Symbol(void) +{ + zend_class_entry ce, *class_entry; + + INIT_NS_CLASS_ENTRY(ce, "ion", "Symbol", class_ion_Symbol_methods); + class_entry = zend_register_internal_class_ex(&ce, NULL); + + zval property_value_default_value; + ZVAL_UNDEF(&property_value_default_value); + zend_string *property_value_name = zend_string_init("value", sizeof("value") - 1, 1); + zend_declare_typed_property(class_entry, property_value_name, &property_value_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL)); + zend_string_release(property_value_name); + + zval property_sid_default_value; + ZVAL_UNDEF(&property_sid_default_value); + zend_string *property_sid_name = zend_string_init("sid", sizeof("sid") - 1, 1); + zend_declare_typed_property(class_entry, property_sid_name, &property_sid_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG)); + zend_string_release(property_sid_name); + + zend_string *property_importLocation_class_ion_Symbol_ImportLocation = zend_string_init("ion\\Symbol\\ImportLocation", sizeof("ion\\Symbol\\ImportLocation")-1, 1); + zval property_importLocation_default_value; + ZVAL_UNDEF(&property_importLocation_default_value); + zend_string *property_importLocation_name = zend_string_init("importLocation", sizeof("importLocation") - 1, 1); + zend_declare_typed_property(class_entry, property_importLocation_name, &property_importLocation_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_CLASS(property_importLocation_class_ion_Symbol_ImportLocation, 0, MAY_BE_NULL)); + zend_string_release(property_importLocation_name); + + return class_entry; +} + static zend_class_entry *register_class_ion_Symbol_ImportLocation(void) { zend_class_entry ce, *class_entry; @@ -1229,35 +1242,6 @@ static zend_class_entry *register_class_ion_Symbol_Table_PHP(zend_class_entry *c return class_entry; } -static zend_class_entry *register_class_ion_Symbol(void) -{ - zend_class_entry ce, *class_entry; - - INIT_NS_CLASS_ENTRY(ce, "ion", "Symbol", class_ion_Symbol_methods); - class_entry = zend_register_internal_class_ex(&ce, NULL); - - zval property_value_default_value; - ZVAL_UNDEF(&property_value_default_value); - zend_string *property_value_name = zend_string_init("value", sizeof("value") - 1, 1); - zend_declare_typed_property(class_entry, property_value_name, &property_value_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL)); - zend_string_release(property_value_name); - - zval property_sid_default_value; - ZVAL_UNDEF(&property_sid_default_value); - zend_string *property_sid_name = zend_string_init("sid", sizeof("sid") - 1, 1); - zend_declare_typed_property(class_entry, property_sid_name, &property_sid_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG)); - zend_string_release(property_sid_name); - - zend_string *property_importLocation_class_ion_Symbol_ImportLocation = zend_string_init("ion\\Symbol\\ImportLocation", sizeof("ion\\Symbol\\ImportLocation")-1, 1); - zval property_importLocation_default_value; - ZVAL_UNDEF(&property_importLocation_default_value); - zend_string *property_importLocation_name = zend_string_init("importLocation", sizeof("importLocation") - 1, 1); - zend_declare_typed_property(class_entry, property_importLocation_name, &property_importLocation_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_CLASS(property_importLocation_class_ion_Symbol_ImportLocation, 0, MAY_BE_NULL)); - zend_string_release(property_importLocation_name); - - return class_entry; -} - static zend_class_entry *register_class_ion_Symbol_Table(void) { zend_class_entry ce, *class_entry; diff --git a/ion_private.h b/ion_private.h index c721229..722efe6 100644 --- a/ion_private.h +++ b/ion_private.h @@ -404,7 +404,7 @@ LOCAL void *php_ion_obj_ex(void *obj, ptrdiff_t offset) { #define ION_CHECK_RETURN(r, err, ...) do { \ iERR __err = err; \ - if (__err) { \ + if (UNEXPECTED(__err)) { \ zend_throw_exception_ex(spl_ce_RuntimeException, __err, "%s: %s", ion_error_to_str(__err), #err); \ __VA_ARGS__; \ return r; \ @@ -415,14 +415,14 @@ LOCAL void *php_ion_obj_ex(void *obj, ptrdiff_t offset) { ION_CHECK_RETURN(, err, __VA_ARGS__) #define ION_CATCH(...) do { \ - if (EG(exception)) { \ + if (UNEXPECTED(EG(exception))) { \ __VA_ARGS__; \ return; \ } \ } while (0) #define PTR_CHECK_RETURN(ret, ptr, ...) do { \ - if (!(ptr)) { \ + if (UNEXPECTED(!(ptr))) { \ zend_throw_error(NULL, "Uninitialized object"); \ __VA_ARGS__; \ return ret; \ @@ -455,15 +455,6 @@ LOCAL void update_property_obj(zend_object *obj, const char *n, size_t l, zend_o zend_update_property(obj->ce, obj, n, l, &zobj); } -LOCAL zend_object *get_property_obj(zend_object *obj, const char *n, size_t l, int type) -{ - zval tmp, *zv = zend_read_property(obj->ce, obj, n, l, 0, &tmp); - if (zv && type & Z_TYPE_P(zv)) { - return Z_PTR_P(zv); - } - return NULL; -} - #define RETURN_IONTYPE(typ) do { \ zend_object *__zo = php_ion_type_fetch(typ); \ if (UNEXPECTED(!__zo)) { \ @@ -642,13 +633,17 @@ LOCAL void php_ion_symbol_table_ctor(php_ion_symbol_table *obj) { OBJ_CHECK(obj); - ION_STRING is; - if (IERR_OK == ion_symbol_table_get_name(obj->tab, &is)) { - zend_update_property_stringl(obj->std.ce, &obj->std, ZEND_STRL("name"), (char *) is.value, is.length); - } - int32_t iv; - if (IERR_OK == ion_symbol_table_get_version(obj->tab, &iv)) { - zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("version"), iv); + ION_SYMBOL_TABLE_TYPE typ = ist_EMPTY; + ion_symbol_table_get_type(obj->tab, &typ); + if (typ != ist_LOCAL) { + ION_STRING is; + if (IERR_OK == ion_symbol_table_get_name(obj->tab, &is)) { + zend_update_property_stringl(obj->std.ce, &obj->std, ZEND_STRL("name"), (char *) is.value, is.length); + } + int32_t iv; + if (IERR_OK == ion_symbol_table_get_version(obj->tab, &iv)) { + zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("version"), iv); + } } } @@ -910,7 +905,7 @@ LOCAL zend_string *php_dt_format_from_precision(uint8_t precision) case ION_TS_YEAR: return php_ion_timestamp_format_fetch(g_intern_str.Year); default: - return zend_one_char_string['c']; + return ZSTR_CHAR('c'); } } @@ -1120,11 +1115,9 @@ LOCAL void php_ion_catalog_symbol_table_zval(php_ion_catalog *obj, ION_SYMBOL_TA } } - php_error_docref(NULL, E_NOTICE, "Previously unknown ion\\Symbol\\Table encountered: %s", key->val); - object_init_ex(return_value, ce_Symbol_Table_Shared); php_ion_symbol_table *o_tab = php_ion_obj(symbol_table, Z_OBJ_P(return_value)); - OBJ_CHECK(o_tab, zend_string_release(key)); + o_tab->tab = tab; php_ion_symbol_table_ctor(o_tab); if (ztabs) { @@ -1691,8 +1684,8 @@ LOCAL void php_ion_serialize_object_std(php_ion_serializer *ser, zend_object *zo LOCAL void php_ion_serialize_object_lob(php_ion_serializer *ser, zend_object *zobject) { - zval tmp_type, *type = zend_read_property(NULL, zobject, ZEND_STRL("type"), 0, &tmp_type); - zval tmp_value, *value = zend_read_property(NULL, zobject, ZEND_STRL("value"), 0, &tmp_value); + zval tmp_type, *type = zend_read_property_ex(NULL, zobject, ZSTR_KNOWN(ZEND_STR_TYPE), 0, &tmp_type); + zval tmp_value, *value = zend_read_property_ex(NULL, zobject, ZSTR_KNOWN(ZEND_STR_VALUE), 0, &tmp_value); switch (Z_LVAL_P(zend_enum_fetch_case_value(Z_OBJ_P(type)))) { case tid_BLOB_INT: ION_CHECK(ion_writer_write_blob(ser->writer, (BYTE *) Z_STRVAL_P(value), Z_STRLEN_P(value))); @@ -2098,7 +2091,7 @@ LOCAL void php_ion_unserialize_field_name(php_ion_unserializer *ser, zend_string *key = zend_string_init(ptr, end - ptr, 0); break; case 1: - *key = zend_one_char_string[*name.value]; + *key = ZSTR_CHAR(*name.value); break; default: if (is_prop) { diff --git a/tests/Catalog.phpt b/tests/Catalog.phpt index 1ee713f..a30db7e 100644 --- a/tests/Catalog.phpt +++ b/tests/Catalog.phpt @@ -8,7 +8,7 @@ TEST $c = new ion\Catalog; var_dump(count($c)); -$c->add(ion\Symbol\Table\PHP()); +$c->add($php = ion\Symbol\Table\PHP()); var_dump(count($c)); $c->add(new ion\Symbol\Table\Shared("shared", 1, ["foo", "bar", "baz"])); var_dump(count($c)); @@ -23,7 +23,14 @@ var_dump($c->findBest("shared")); $c->remove("shared"); var_dump(count($c)); -var_dump(clone $c); +var_dump($d = clone $c); +$c->remove($php); +$c->remove($php); +unset($c); +var_dump(count($d)); +var_dump($d->find("PHP", 1)); +$d->remove($php); +var_dump(count($d)); ?> DONE --EXPECTF-- @@ -121,4 +128,15 @@ object(ion\Catalog)#%d (1) { array(0) { } } +int(1) +object(ion\Symbol\Table\Shared)#%d (3) { + ["name"]=> + string(3) "PHP" + ["version"]=> + int(1) + ["symbols":"ion\Symbol\Table\Shared":private]=> + array(0) { + } +} +int(0) DONE diff --git a/tests/Decimal/Context.phpt b/tests/Decimal/Context.phpt index b3a9ada..665dd53 100644 --- a/tests/Decimal/Context.phpt +++ b/tests/Decimal/Context.phpt @@ -9,6 +9,7 @@ var_dump(ion\Decimal\Context::Dec32()); var_dump(ion\Decimal\Context::Dec64()); var_dump(ion\Decimal\Context::Dec128()); var_dump(ion\Decimal\Context::DecMax()); +var_dump(ion\Decimal\Context::DecMax(ion\Decimal\Context\Rounding::Down05Up)); var_dump(clone new ion\Decimal\Context(12, 999, -999, ion\Decimal\Context\Rounding::Down05Up, true)); ?> DONE @@ -62,6 +63,18 @@ object(ion\Decimal\Context)#%d (5) { ["clamp"]=> bool(false) } +object(ion\Decimal\Context)#%d (5) { + ["digits"]=> + int(999999999) + ["eMax"]=> + int(999999999) + ["eMin"]=> + int(-999999999) + ["round"]=> + enum(ion\Decimal\Context\Rounding::Down05Up) + ["clamp"]=> + bool(false) +} object(ion\Decimal\Context)#%d (5) { ["digits"]=> int(12) diff --git a/tests/Symbol/Table.phpt b/tests/Symbol/Table.phpt index 12c70e9..9fdc862 100644 --- a/tests/Symbol/Table.phpt +++ b/tests/Symbol/Table.phpt @@ -44,6 +44,9 @@ var_dump($local->add("sym4")); var_dump($local->find("sym4")); var_dump($local->findLocal("sym4")); var_dump($local->getMaxId()); + +var_dump(clone $local); +var_dump(clone $shared); ?> DONE --EXPECTF-- @@ -159,4 +162,21 @@ object(ion\Symbol)#%d (3) { NULL } int(23) +object(ion\Symbol\Table\Local)#%d (2) { + ["imports":"ion\Symbol\Table\Local":private]=> + array(0) { + } + ["symbols":"ion\Symbol\Table\Local":private]=> + array(0) { + } +} +object(ion\Symbol\Table\Shared)#%d (3) { + ["name"]=> + string(6) "shared" + ["version"]=> + int(1) + ["symbols":"ion\Symbol\Table\Shared":private]=> + array(0) { + } +} DONE diff --git a/tests/Timestamp.phpt b/tests/Timestamp.phpt index e92905b..88ca90f 100644 --- a/tests/Timestamp.phpt +++ b/tests/Timestamp.phpt @@ -21,6 +21,7 @@ var_dump($t=new Timestamp(Timestamp\Precision::Min, datetime:"2020-10-01"),(stri $t->setTimezone(new DateTimeZone("Europe/Helsinki")); var_dump((string) $t); var_dump($t=new Timestamp(Timestamp\Precision::Day, "!Y-m", "2000-10"),(string)$t); +var_dump($t=new Timestamp(Timestamp\Precision::MinTZ, Timestamp\Format::MinTZ, "2000-10-20T11:11CET"),(string)$t); var_dump(ion\unserialize(ion\serialize(clone new ion\Timestamp(ion\Timestamp\Precision::Sec, DateTime::RFC3339, "1971-02-03T04:05:06Z")))); ?> DONE @@ -80,6 +81,19 @@ object(ion\Timestamp)#%d (5) { string(3) "CET" } string(11) "2000-10-01T" +object(ion\Timestamp)#%d (5) { + ["precision"]=> + int(151) + ["format"]=> + string(11) "Y-m-d\TH:iP" + ["date"]=> + string(26) "2000-10-20 11:11:00.000000" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "CET" +} +string(22) "2000-10-20T11:11+01:00" object(ion\Timestamp)#%d (3) { ["precision"]=> int(55) diff --git a/tests/Writer.phpt b/tests/Writer.phpt new file mode 100644 index 0000000..816803c --- /dev/null +++ b/tests/Writer.phpt @@ -0,0 +1,95 @@ +--TEST-- +ion\Writer +--EXTENSIONS-- +ion +--INI-- +date.timezone=UTC +--FILE-- +TEST +writeNull(); +echo "\n"; +$w->writeTypedNull(ion\Type::Int); +echo "\n"; +$w->writeBool(true); +echo "\n"; +$w->writeBool(false); +echo "\n"; +$w->writeInt(0); +echo "\n"; +$w->writeInt(123); +echo "\n"; +$w->writeInt(-123); +echo "\n"; +$w->writeInt("12345678901234567890"); +echo "\n"; +$w->writeFloat(1e0); +echo "\n"; +$w->writeFloat(-.0); +echo "\n"; +$w->writeDecimal("1.23"); +echo "\n"; +$w->writeDecimal(new ion\Decimal(-123)); +echo "\n"; +$w->writeTimestamp("2001T"); +echo "\n"; +$w->writeTimestamp(new ion\Timestamp(ion\Timestamp\Precision::Frac)); +echo "\n"; +$w->writeSymbol("a"); +echo "\n"; +$w->writeSymbol(new ion\Symbol("b")); +echo "\n"; +$w->writeString("abc"); +echo "\n"; +$w->writeCLob("clob"); +echo "\n"; +$w->writeBLob("blob"); +echo "\n"; +$w->startLob(ion\Type::CLob); +$w->appendLob("clob"); +$w->finishLob(); +echo "\n"; +$w->startContainer(ion\Type::Struct); +$w->writeFieldName("prop"); +$w->writeAnnotation(ion\Symbol\Table\PHP::Property->toSymbol()); +$w->writeInt($w->getDepth()); +$w->writeFieldName(new ion\Symbol("priv")); +$w->writeAnnotation("a","b","c"); +$w->writeInt($w->getDepth()); +$w->finishContainer(); +echo "\n"; +$w->writeInt($w->getDepth()); +$w->finish(); +echo "\n"; + +?> +DONE +--EXPECTF-- +TEST +null + null.int + true + false + 0 + 123 + -123 + 12345678901234567890 + 1e+0 + -0e0 + 1.23 + -123d0 + 2001T + %r\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+%r-00:00 + a + b + "abc" + {{"clob"}} + {{YmxvYg==}} + {{"clob"}} + {prop:p::1,priv:a::b::c::1} + 0 +DONE diff --git a/tests/Writer/Options.phpt b/tests/Writer/Options.phpt index f6a066b..b673ac7 100644 --- a/tests/Writer/Options.phpt +++ b/tests/Writer/Options.phpt @@ -13,6 +13,7 @@ $o = new ion\Writer\Options( decimalContext: ion\Decimal\Context::Dec64(), outputBinary: true, maxContainerDepth: 20, + allocationPageSize: 0x20000 ); var_dump($o, clone $o); ?> @@ -128,7 +129,7 @@ object(ion\Writer\Options)#%d (15) { ["tempBufferSize"]=> int(16384) ["allocationPageSize"]=> - int(65536) + int(131072) } object(ion\Writer\Options)#%d (15) { ["catalog"]=> @@ -175,6 +176,6 @@ object(ion\Writer\Options)#%d (15) { ["tempBufferSize"]=> int(16384) ["allocationPageSize"]=> - int(65536) + int(131072) } DONE diff --git a/tests/serialize/multisequence.phpt b/tests/serialize/multisequence.phpt new file mode 100644 index 0000000..f4f6d5b --- /dev/null +++ b/tests/serialize/multisequence.phpt @@ -0,0 +1,14 @@ +--TEST-- +ion\serialize/multi sequence +--EXTENSIONS-- +ion +--FILE-- +TEST + +DONE +--EXPECT-- +TEST +1 2 3 +DONE diff --git a/tests/unserialize/multisequence.phpt b/tests/unserialize/multisequence.phpt new file mode 100644 index 0000000..e52e83e --- /dev/null +++ b/tests/unserialize/multisequence.phpt @@ -0,0 +1,21 @@ +--TEST-- +ion\unserialize/multi sequence +--EXTENSIONS-- +ion +--FILE-- +TEST + +DONE +--EXPECT-- +TEST +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +DONE -- 2.30.2