From: Michael Wallner Date: Wed, 22 Dec 2021 17:30:28 +0000 (+0100) Subject: fix ion type arguments X-Git-Tag: v0.1.0~55 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=7f13ba773badf13721ed7a392257cdb991dc9379;p=awesomized%2Fext-ion fix ion type arguments --- diff --git a/ion.c b/ion.c index 45f34b8..c252457 100644 --- a/ion.c +++ b/ion.c @@ -924,7 +924,7 @@ static ZEND_METHOD(ion_Reader_Reader, readNull) ION_TYPE typ; ION_CHECK(ion_reader_read_null(obj->reader, &typ)); - RETURN_OBJ_COPY(php_ion_type_fetch(typ)); + RETURN_IONTYPE(typ); } static ZEND_METHOD(ion_Reader_Reader, readBool) { @@ -1310,9 +1310,7 @@ static ZEND_METHOD(ion_Writer_Writer, writeTypedNull) Z_PARAM_OBJ_OF_CLASS(typ_obj, ce_Type) ZEND_PARSE_PARAMETERS_END(); - php_ion_type *typ = php_ion_obj(type, typ_obj); - OBJ_CHECK(typ); - ION_CHECK(ion_writer_write_typed_null(obj->writer, php_ion_obj(type, typ)->typ)); + ION_CHECK(ion_writer_write_typed_null(obj->writer, ion_type_from_enum(typ_obj))); } static ZEND_METHOD(ion_Writer_Writer, writeBool) { @@ -1472,9 +1470,7 @@ static ZEND_METHOD(ion_Writer_Writer, startLob) Z_PARAM_OBJ_OF_CLASS(typ_obj, ce_Type) ZEND_PARSE_PARAMETERS_END(); - php_ion_type *typ = php_ion_obj(type, typ_obj); - OBJ_CHECK(typ); - ION_CHECK(ion_writer_start_lob(obj->writer, php_ion_obj(type, typ)->typ)); + ION_CHECK(ion_writer_start_lob(obj->writer, ion_type_from_enum(typ_obj))); } static ZEND_METHOD(ion_Writer_Writer, appendLob) { @@ -1507,9 +1503,7 @@ static ZEND_METHOD(ion_Writer_Writer, startContainer) Z_PARAM_OBJ_OF_CLASS(typ_obj, ce_Type) ZEND_PARSE_PARAMETERS_END(); - php_ion_type *typ = php_ion_obj(type, typ_obj); - OBJ_CHECK(typ); - ION_CHECK(ion_writer_start_container(obj->writer, php_ion_obj(type, typ)->typ)); + ION_CHECK(ion_writer_start_container(obj->writer, ion_type_from_enum(typ_obj))); } static ZEND_METHOD(ion_Writer_Writer, finishContainer) { @@ -1833,7 +1827,7 @@ PHP_MINIT_FUNCTION(ion) ce_Timestamp_Precision = register_class_ion_Timestamp_Precision(); // Type - php_ion_register(type, Type); + ce_Type = register_class_ion_Type(); // Writer ce_Writer = register_class_ion_Writer(); diff --git a/ion_private.h b/ion_private.h index 0831df3..5993af0 100644 --- a/ion_private.h +++ b/ion_private.h @@ -413,13 +413,6 @@ static inline void update_property_obj(zend_object *obj, const char *n, size_t l zend_update_property(obj->ce, obj, n, l, &zobj); } -typedef struct php_ion_type { - ION_TYPE typ; - zend_object std; -} php_ion_type; - -php_ion_decl(type, Type); - #define RETURN_IONTYPE(typ) do { \ zend_object *__zo = php_ion_type_fetch(typ); \ if (UNEXPECTED(!__zo)) { \ @@ -440,6 +433,11 @@ static inline zend_object *php_ion_type_fetch(ION_TYPE typ) return zend_enum_get_case(ce_Type, Z_STR_P(ztype)); } +static inline ION_TYPE ion_type_from_enum(zend_object *zo) +{ + return Z_LVAL_P(zend_enum_fetch_case_value(zo)); +} + typedef struct php_ion_symbol_iloc { ION_SYMBOL_IMPORT_LOCATION loc; zend_string *name;