improve symbol/table/catalog support
authorMichael Wallner <mike@php.net>
Fri, 17 Dec 2021 19:28:39 +0000 (20:28 +0100)
committerMichael Wallner <mike@php.net>
Fri, 17 Dec 2021 19:28:39 +0000 (20:28 +0100)
ion.c
ion.stub.php
ion_arginfo.h
ion_private.h
tests/Symbol/Table.phpt [new file with mode: 0644]

diff --git a/ion.c b/ion.c
index ab7f80b552f4bcb332eae06c5e7f725090c38af2..5d10462038921384ae05cf1d43e31b49f3f20e4b 100644 (file)
--- a/ion.c
+++ b/ion.c
 #include "ext/spl/spl_exceptions.h"
 #include "ext/spl/spl_iterators.h"
 
-#define DECNUMDIGITS 34 /* DECQUAD_Pmax */
-#include "ionc/ion.h"
-
-static decContext g_dec_ctx;
-static ION_DECIMAL g_ion_dec_zend_max, g_ion_dec_zend_min;
-
 #include "php_ion.h"
-#define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
-       { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), default_value },
-#include "ion_arginfo.h"
 #include "ion_private.h"
 
-ZEND_METHOD(ion_Symbol_ImportLocation, __construct)
+static ZEND_METHOD(ion_Symbol_ImportLocation, __construct)
 {
        php_ion_symbol_iloc *obj = php_ion_obj(symbol_iloc, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -53,7 +44,7 @@ ZEND_METHOD(ion_Symbol_ImportLocation, __construct)
        obj->loc.location = location;
        php_ion_symbol_iloc_ctor(obj);
 }
-ZEND_METHOD(ion_Symbol, __construct)
+static ZEND_METHOD(ion_Symbol, __construct)
 {
        php_ion_symbol *obj = php_ion_obj(symbol, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -69,7 +60,7 @@ ZEND_METHOD(ion_Symbol, __construct)
        obj->sym.sid = sid;
        php_ion_symbol_ctor(obj);
 }
-ZEND_METHOD(ion_Symbol, equals)
+static ZEND_METHOD(ion_Symbol, equals)
 {
        php_ion_symbol *sym = php_ion_obj(symbol, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(sym);
@@ -86,7 +77,7 @@ ZEND_METHOD(ion_Symbol, equals)
        ION_CHECK(err);
        RETVAL_BOOL(eq);
 }
-ZEND_METHOD(ion_Symbol, __toString)
+static ZEND_METHOD(ion_Symbol, __toString)
 {
        php_ion_symbol *sym = php_ion_obj(symbol, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(sym);
@@ -98,7 +89,315 @@ ZEND_METHOD(ion_Symbol, __toString)
        }
        RETURN_STR_COPY(sym->value);
 }
-ZEND_METHOD(ion_Timestamp, __construct)
+static ZEND_METHOD(ion_Symbol_Enum, toSymbol)
+{
+       ZEND_PARSE_PARAMETERS_NONE();
+
+       zval *zc = zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS));
+       PTR_CHECK(zc);
+
+       zval *zsym = php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc));
+       PTR_CHECK(zsym);
+       RETVAL_ZVAL(zsym, 1, 0);
+}
+static ZEND_METHOD(ion_Symbol_Enum, toSID)
+{
+       ZEND_PARSE_PARAMETERS_NONE();
+
+       zval *zc = zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS));
+       PTR_CHECK(zc);
+
+       zval *zsym = php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc));
+       PTR_CHECK(zsym);
+
+       zval tmp;
+       RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym), Z_OBJ_P(zsym), ZEND_STRL("sid"), 0, &tmp), 1, 0);
+}
+static ZEND_METHOD(ion_Symbol_Enum, toString)
+{
+       ZEND_PARSE_PARAMETERS_NONE();
+
+       zval *zc = zend_enum_fetch_case_name(Z_OBJ_P(ZEND_THIS));
+       PTR_CHECK(zc);
+
+       zval *zsym = php_ion_global_symbol_fetch_by_enum(Z_STR_P(zc));
+       PTR_CHECK(zsym);
+
+       zval tmp;
+       RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(zsym), Z_OBJ_P(zsym), ZEND_STRL("value"), 0, &tmp), 1, 0);
+}
+static ZEND_FUNCTION(ion_Symbol_Table_System)
+{
+       ZEND_PARSE_PARAMETERS_NONE();
+
+       object_init_ex(return_value, ce_Symbol_Table_Shared);
+       php_ion_symbol_table *obj = php_ion_obj(symbol_table, Z_OBJ_P(return_value));
+       ION_CHECK(ion_symbol_table_get_system_table(&obj->tab, 1));
+       php_ion_symbol_table_ctor(obj);
+       ion_symbol_table_lock(obj->tab);
+}
+static ZEND_FUNCTION(ion_Symbol_Table_PHP)
+{
+       ZEND_PARSE_PARAMETERS_NONE();
+
+       object_init_ex(return_value, ce_Symbol_Table_Shared);
+       php_ion_symbol_table *obj = php_ion_obj(symbol_table, Z_OBJ_P(return_value));
+       obj->tab = g_sym_tab_php;
+       php_ion_symbol_table_ctor(obj);
+       ion_symbol_table_lock(obj->tab);
+}
+static ZEND_METHOD(ion_Symbol_Table_Local, __construct)
+{
+       php_ion_symbol_table *obj = php_ion_obj(symbol_table, Z_OBJ_P(ZEND_THIS));
+       PTR_CHECK(obj);
+
+       ZEND_PARSE_PARAMETERS_NONE();
+
+       ION_CHECK(ion_symbol_table_open_with_type(&obj->tab, NULL, ist_LOCAL));
+       obj->dtor = ion_symbol_table_close;
+       OBJ_CHECK(obj);
+}
+static ZEND_METHOD(ion_Symbol_Table_Local, import)
+{
+       php_ion_symbol_table *obj = php_ion_obj(symbol_table, Z_OBJ_P(ZEND_THIS));
+       OBJ_CHECK(obj);
+
+       zend_object *zo_import;
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_OBJ_OF_CLASS(zo_import, ce_Symbol_Table);
+       ZEND_PARSE_PARAMETERS_END();
+
+       php_ion_symbol_table_import(obj, php_ion_obj(symbol_table, zo_import));
+}
+static ZEND_METHOD(ion_Symbol_Table_Shared, __construct)
+{
+       php_ion_symbol_table *obj = php_ion_obj(symbol_table, Z_OBJ_P(ZEND_THIS));
+       PTR_CHECK(obj);
+
+       zend_string *zname;
+       zend_long version = 1;
+       ZEND_PARSE_PARAMETERS_START(1, 2)
+               Z_PARAM_STR(zname)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_LONG(version)
+       ZEND_PARSE_PARAMETERS_END();
+
+       ION_CHECK(ion_symbol_table_open_with_type(&obj->tab, NULL, ist_SHARED));
+       obj->dtor = ion_symbol_table_close;
+
+       ION_STRING is;
+       ION_CHECK(ion_symbol_table_set_name(obj->tab, ion_string_from_zend(&is, zname)));
+       ION_CHECK(ion_symbol_table_set_version(obj->tab, version));
+
+       php_ion_symbol_table_ctor(obj);
+}
+static ZEND_METHOD(ion_Symbol_Table, getMaxId)
+{
+       php_ion_symbol_table *obj = php_ion_obj(symbol_table, Z_OBJ_P(ZEND_THIS));
+       OBJ_CHECK(obj);
+
+       ZEND_PARSE_PARAMETERS_NONE();
+
+       SID max_sid;
+       ION_CHECK(ion_symbol_table_get_max_sid(obj->tab, &max_sid));
+       RETURN_LONG(max_sid);
+}
+static ZEND_METHOD(ion_Symbol_Table, add)
+{
+       php_ion_symbol_table *obj = php_ion_obj(symbol_table, Z_OBJ_P(ZEND_THIS));
+       OBJ_CHECK(obj);
+
+       zend_object *zo_sym = NULL;
+       zend_string *zs_sym = NULL;
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_sym, ce_Symbol, zs_sym)
+       ZEND_PARSE_PARAMETERS_END();
+
+       if (zo_sym) {
+               zval z_sym;
+               ZVAL_OBJ(&z_sym, zo_sym);
+               zs_sym = zval_get_string(&z_sym);
+               ION_CATCH();
+       }
+       SID sid;
+       ION_STRING is;
+       ION_CHECK(ion_symbol_table_add_symbol(obj->tab, ion_string_from_zend(&is, zs_sym), &sid),
+                       if (zo_sym) {
+                               zend_string_release(zs_sym);
+                       });
+       if (zo_sym) {
+               zend_string_release(zs_sym);
+       }
+       RETURN_LONG(sid);
+}
+static ZEND_METHOD(ion_Symbol_Table, find)
+{
+       php_ion_symbol_table *obj = php_ion_obj(symbol_table, Z_OBJ_P(ZEND_THIS));
+       OBJ_CHECK(obj);
+
+       zend_long zsid;
+       zend_string *zstring = NULL;
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_STR_OR_LONG(zstring, zsid)
+       ZEND_PARSE_PARAMETERS_END();
+
+       if (zstring) {
+               SID sid;
+               ION_STRING is;
+               ION_CHECK(ion_symbol_table_find_by_name(obj->tab, ion_string_from_zend(&is, zstring), &sid));
+               zsid = sid;
+       }
+       ION_SYMBOL *sym;
+       ION_CHECK(ion_symbol_table_get_symbol(obj->tab, zsid, &sym));
+       if (sym) {
+               php_ion_symbol_table_symbol_zval(obj, sym, return_value);
+       }
+}
+static ZEND_METHOD(ion_Symbol_Table, findLocal)
+{
+       php_ion_symbol_table *obj = php_ion_obj(symbol_table, Z_OBJ_P(ZEND_THIS));
+       OBJ_CHECK(obj);
+
+       zend_long zsid;
+       zend_string *zstring;
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_STR_OR_LONG(zstring, zsid)
+       ZEND_PARSE_PARAMETERS_END();
+
+       if (zstring) {
+               SID sid;
+               ION_STRING is;
+               ION_CHECK(ion_symbol_table_find_by_name(obj->tab, ion_string_from_zend(&is, zstring), &sid));
+               zsid = sid;
+       }
+       ION_SYMBOL *sym;
+       ION_CHECK(ion_symbol_table_get_local_symbol(obj->tab, zsid, &sym));
+       if (sym) {
+               php_ion_symbol_table_symbol_zval(obj, sym, return_value);
+       }
+}
+static ZEND_METHOD(ion_Catalog, __construct)
+{
+       php_ion_catalog *obj = php_ion_obj(catalog, Z_OBJ_P(ZEND_THIS));
+       PTR_CHECK(obj);
+
+       ZEND_PARSE_PARAMETERS_NONE();
+
+       php_ion_catalog_ctor(obj);
+}
+static ZEND_METHOD(ion_Catalog, count)
+{
+       php_ion_catalog *obj = php_ion_obj(catalog, Z_OBJ_P(ZEND_THIS));
+       OBJ_CHECK(obj);
+
+       ZEND_PARSE_PARAMETERS_NONE();
+
+       int32_t c;
+       ION_CHECK(ion_catalog_get_symbol_table_count(obj->cat, &c));
+       RETURN_LONG(c);
+}
+static ZEND_METHOD(ion_Catalog, add)
+{
+       php_ion_catalog *obj = php_ion_obj(catalog, Z_OBJ_P(ZEND_THIS));
+       OBJ_CHECK(obj);
+
+       zend_object *zo_symtab;
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_OBJ_OF_CLASS(zo_symtab, ce_Symbol_Table)
+       ZEND_PARSE_PARAMETERS_END();
+
+       php_ion_symbol_table *o_symtab = php_ion_obj(symbol_table, zo_symtab);
+       php_ion_catalog_add_symbol_table(obj, o_symtab);
+}
+struct remove_symtab_ctx {
+       const char *name;
+       zend_bool deleted;
+};
+static int remove_symtab(zval *ztab, void *ctx)
+{
+       struct remove_symtab_ctx *rsc = ctx;
+       php_ion_symbol_table *tab = php_ion_obj(symbol_table, Z_OBJ_P(ztab));
+       if (tab && tab->tab) {
+               ION_STRING is;
+               if (IERR_OK == ion_symbol_table_get_name(tab->tab, &is)) {
+                       if (strcmp((const char *) is.value, rsc->name)) {
+                               return ZEND_HASH_APPLY_KEEP;
+                       }
+               }
+       }
+       rsc->deleted = true;
+       return ZEND_HASH_APPLY_REMOVE;
+
+}
+static ZEND_METHOD(ion_Catalog, remove)
+{
+       php_ion_catalog *obj = php_ion_obj(catalog, Z_OBJ_P(ZEND_THIS));
+       OBJ_CHECK(obj);
+
+       zend_object *zo_symtab = NULL;
+       zend_string *zs_symtab = NULL;
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_OBJ_OF_CLASS_OR_STR(zo_symtab, ce_Symbol_Table, zs_symtab)
+       ZEND_PARSE_PARAMETERS_END();
+
+       RETVAL_FALSE;
+
+       zval tmp;
+       zval *ztabs = zend_read_property(obj->std.ce, &obj->std, ZEND_STRL("symbolTables"), 0, &tmp);
+       if (ztabs) {
+               if (zo_symtab) {
+                       // fast path
+                       zend_ulong idx = (uintptr_t) &zo_symtab->gc;
+                       RETURN_BOOL(SUCCESS == zend_hash_index_del(Z_ARRVAL_P(ztabs), idx));
+               } else {
+                       // iterate over all symbol tables and delete any with matching name
+                       struct remove_symtab_ctx ctx = {zs_symtab->val, false};
+                       zend_hash_apply_with_argument(Z_ARRVAL_P(ztabs), remove_symtab, &ctx);
+                       RETURN_BOOL(ctx.deleted);
+               }
+       }
+}
+static ZEND_METHOD(ion_Catalog, find)
+{
+       php_ion_catalog *obj = php_ion_obj(catalog, Z_OBJ_P(ZEND_THIS));
+       OBJ_CHECK(obj);
+
+       zend_long zversion = 0;
+       zend_string *zname;
+       ZEND_PARSE_PARAMETERS_START(1, 2)
+               Z_PARAM_STR(zname)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_LONG(zversion)
+       ZEND_PARSE_PARAMETERS_END();
+
+       ION_STRING is;
+       ION_SYMBOL_TABLE *tab_ptr = NULL;
+       ION_CHECK(ion_catalog_find_symbol_table(obj->cat, ion_string_from_zend(&is, zname), zversion, &tab_ptr));
+       if (tab_ptr) {
+               php_ion_catalog_symbol_table_zval(obj, tab_ptr, return_value);
+       }
+}
+static ZEND_METHOD(ion_Catalog, findBest)
+{
+       php_ion_catalog *obj = php_ion_obj(catalog, Z_OBJ_P(ZEND_THIS));
+       OBJ_CHECK(obj);
+
+       zend_long zversion = 0;
+       zend_string *zname;
+       ZEND_PARSE_PARAMETERS_START(1, 2)
+               Z_PARAM_STR(zname)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_LONG(zversion)
+       ZEND_PARSE_PARAMETERS_END();
+
+       ION_STRING is;
+       ION_SYMBOL_TABLE *tab_ptr = NULL;
+       ION_CHECK(ion_catalog_find_best_match(obj->cat, ion_string_from_zend(&is, zname), zversion, &tab_ptr));
+       if (tab_ptr) {
+               php_ion_catalog_symbol_table_zval(obj, tab_ptr, return_value);
+       }
+}
+static ZEND_METHOD(ion_Timestamp, __construct)
 {
        php_ion_timestamp *obj = php_ion_obj(timestamp, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -120,7 +419,7 @@ ZEND_METHOD(ion_Timestamp, __construct)
        }
        php_ion_timestamp_ctor(obj, precision, fmt, dt, tz);
 }
-ZEND_METHOD(ion_Timestamp, __toString)
+static ZEND_METHOD(ion_Timestamp, __toString)
 {
        php_ion_timestamp *obj = php_ion_obj(timestamp, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -132,7 +431,7 @@ ZEND_METHOD(ion_Timestamp, __toString)
        zend_call_method_with_1_params(&obj->std, obj->std.ce, NULL, "format", return_value,
                zend_read_property(obj->std.ce, &obj->std, ZEND_STRL("format"), 0, &fmt));
 }
-ZEND_METHOD(ion_Decimal_Context, __construct)
+static ZEND_METHOD(ion_Decimal_Context, __construct)
 {
        php_ion_decimal_ctx *obj = php_ion_obj(decimal_ctx, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -163,19 +462,19 @@ static inline void make_decimal_ctx(INTERNAL_FUNCTION_PARAMETERS, int kind)
        decContextDefault(&obj->ctx, kind);
        php_ion_decimal_ctx_ctor(obj, NULL);
 }
-ZEND_METHOD(ion_Decimal_Context, Dec32)
+static ZEND_METHOD(ion_Decimal_Context, Dec32)
 {
        make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, DEC_INIT_DECIMAL32);
 }
-ZEND_METHOD(ion_Decimal_Context, Dec64)
+static ZEND_METHOD(ion_Decimal_Context, Dec64)
 {
        make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, DEC_INIT_DECIMAL64);
 }
-ZEND_METHOD(ion_Decimal_Context, Dec128)
+static ZEND_METHOD(ion_Decimal_Context, Dec128)
 {
        make_decimal_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, DEC_INIT_DECIMAL128);
 }
-ZEND_METHOD(ion_Decimal_Context, DecMax)
+static ZEND_METHOD(ion_Decimal_Context, DecMax)
 {
        zend_object *o_round = NULL;
        zend_long round = DEC_ROUND_HALF_EVEN;
@@ -192,7 +491,7 @@ ZEND_METHOD(ion_Decimal_Context, DecMax)
        php_ion_decimal_ctx_init_max(&obj->ctx, round);
        php_ion_decimal_ctx_ctor(obj, o_round);
 }
-ZEND_METHOD(ion_Decimal, __construct)
+static ZEND_METHOD(ion_Decimal, __construct)
 {
        php_ion_decimal *obj = php_ion_obj(decimal, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -225,7 +524,7 @@ ZEND_METHOD(ion_Decimal, __construct)
        php_ion_decimal_ctor(obj);
        OBJ_RELEASE(obj->ctx);
 }
-ZEND_METHOD(ion_Decimal, equals)
+static ZEND_METHOD(ion_Decimal, equals)
 {
        php_ion_decimal *obj = php_ion_obj(decimal, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -240,7 +539,7 @@ ZEND_METHOD(ion_Decimal, equals)
                obj->ctx ? &php_ion_obj(decimal_ctx, obj->ctx)->ctx : NULL, &is));
        RETURN_BOOL(is);
 }
-ZEND_METHOD(ion_Decimal, __toString)
+static ZEND_METHOD(ion_Decimal, __toString)
 {
        php_ion_decimal *obj = php_ion_obj(decimal, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -249,7 +548,7 @@ ZEND_METHOD(ion_Decimal, __toString)
 
        RETURN_STR(php_ion_decimal_to_string(&obj->dec));
 }
-ZEND_METHOD(ion_Decimal, toInt)
+static ZEND_METHOD(ion_Decimal, toInt)
 {
        php_ion_decimal *obj = php_ion_obj(decimal, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -260,7 +559,7 @@ ZEND_METHOD(ion_Decimal, toInt)
        php_ion_decimal_to_zend_long(&obj->dec, &php_ion_obj(decimal_ctx, obj->ctx)->ctx, &l);
        RETURN_LONG(l);
 }
-ZEND_METHOD(ion_Decimal, isInt)
+static ZEND_METHOD(ion_Decimal, isInt)
 {
        php_ion_decimal *obj = php_ion_obj(decimal, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -269,7 +568,7 @@ ZEND_METHOD(ion_Decimal, isInt)
 
        RETURN_BOOL(ion_decimal_is_integer(&obj->dec));
 }
-ZEND_METHOD(ion_LOB, __construct)
+static ZEND_METHOD(ion_LOB, __construct)
 {
        zend_string *value;
        zend_object *type = NULL;
@@ -285,7 +584,7 @@ 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);
 }
-ZEND_METHOD(ion_Reader_Options, __construct)
+static ZEND_METHOD(ion_Reader_Options, __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;
@@ -357,7 +656,7 @@ ZEND_METHOD(ion_Reader_Options, __construct)
        zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("skipCharacterValidation"),
                opt->opt.skip_character_validation = skip_validation);
 }
-ZEND_METHOD(ion_Reader_Reader, hasChildren)
+static ZEND_METHOD(ion_Reader_Reader, hasChildren)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
 
@@ -377,7 +676,7 @@ ZEND_METHOD(ion_Reader_Reader, hasChildren)
                        break;
        }
 }
-ZEND_METHOD(ion_Reader_Reader, getChildren)
+static ZEND_METHOD(ion_Reader_Reader, getChildren)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -388,7 +687,7 @@ ZEND_METHOD(ion_Reader_Reader, getChildren)
 
        RETURN_ZVAL(ZEND_THIS, 1, 0);
 }
-ZEND_METHOD(ion_Reader_Reader, rewind)
+static ZEND_METHOD(ion_Reader_Reader, rewind)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -397,7 +696,7 @@ ZEND_METHOD(ion_Reader_Reader, rewind)
 
        ION_CHECK(ion_reader_next(obj->reader, &obj->state));
 }
-ZEND_METHOD(ion_Reader_Reader, next)
+static ZEND_METHOD(ion_Reader_Reader, next)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -413,7 +712,7 @@ ZEND_METHOD(ion_Reader_Reader, next)
        }
        ION_CHECK(ion_reader_next(obj->reader, &obj->state));
 }
-ZEND_METHOD(ion_Reader_Reader, valid)
+static ZEND_METHOD(ion_Reader_Reader, valid)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -421,7 +720,7 @@ ZEND_METHOD(ion_Reader_Reader, valid)
        ZEND_PARSE_PARAMETERS_NONE();
        RETURN_BOOL(obj->state != tid_none && obj->state != tid_EOF);
 }
-ZEND_METHOD(ion_Reader_Reader, key)
+static ZEND_METHOD(ion_Reader_Reader, key)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -429,12 +728,12 @@ ZEND_METHOD(ion_Reader_Reader, key)
        ZEND_PARSE_PARAMETERS_NONE();
        RETURN_IONTYPE(obj->state);
 }
-ZEND_METHOD(ion_Reader_Reader, current)
+static ZEND_METHOD(ion_Reader_Reader, current)
 {
        ZEND_PARSE_PARAMETERS_NONE();
        RETURN_ZVAL(ZEND_THIS, 1, 0);
 }
-ZEND_METHOD(ion_Reader_Reader, getType)
+static ZEND_METHOD(ion_Reader_Reader, getType)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -445,7 +744,7 @@ ZEND_METHOD(ion_Reader_Reader, getType)
        ION_CHECK(ion_reader_get_type(obj->reader, &typ));
        RETURN_IONTYPE(typ);
 }
-ZEND_METHOD(ion_Reader_Reader, hasAnnotations)
+static ZEND_METHOD(ion_Reader_Reader, hasAnnotations)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -456,7 +755,7 @@ ZEND_METHOD(ion_Reader_Reader, hasAnnotations)
        ION_CHECK(ion_reader_has_any_annotations(obj->reader, &has));
        RETURN_BOOL(has);
 }
-ZEND_METHOD(ion_Reader_Reader, hasAnnotation)
+static ZEND_METHOD(ion_Reader_Reader, hasAnnotation)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -471,7 +770,7 @@ ZEND_METHOD(ion_Reader_Reader, hasAnnotation)
        ION_CHECK(ion_reader_has_annotation(obj->reader, ion_string_from_zend(&ann_istr, ann_zstr), &has));
        RETURN_BOOL(has);
 }
-ZEND_METHOD(ion_Reader_Reader, isNull)
+static ZEND_METHOD(ion_Reader_Reader, isNull)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -482,7 +781,7 @@ ZEND_METHOD(ion_Reader_Reader, isNull)
        ION_CHECK(ion_reader_is_null(obj->reader, &is));
        RETURN_BOOL(is);
 }
-ZEND_METHOD(ion_Reader_Reader, isInStruct)
+static ZEND_METHOD(ion_Reader_Reader, isInStruct)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -493,7 +792,7 @@ ZEND_METHOD(ion_Reader_Reader, isInStruct)
        ION_CHECK(ion_reader_is_in_struct(obj->reader, &is));
        RETURN_BOOL(is);
 }
-ZEND_METHOD(ion_Reader_Reader, getFieldName)
+static ZEND_METHOD(ion_Reader_Reader, getFieldName)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -504,7 +803,7 @@ ZEND_METHOD(ion_Reader_Reader, getFieldName)
        ION_CHECK(ion_reader_get_field_name(obj->reader, &name));
        RETURN_STRINGL((char *) name.value, name.length);
 }
-ZEND_METHOD(ion_Reader_Reader, getFieldNameSymbol)
+static ZEND_METHOD(ion_Reader_Reader, getFieldNameSymbol)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -516,7 +815,7 @@ ZEND_METHOD(ion_Reader_Reader, getFieldNameSymbol)
 
        php_ion_symbol_zval(sym_ptr, return_value);
 }
-ZEND_METHOD(ion_Reader_Reader, getAnnotations)
+static ZEND_METHOD(ion_Reader_Reader, getAnnotations)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -540,7 +839,7 @@ ZEND_METHOD(ion_Reader_Reader, getAnnotations)
        efree(ptr);
        ION_CHECK(err);
 }
-ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbols)
+static ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbols)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -561,7 +860,7 @@ ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbols)
        efree(ptr);
        ION_CHECK(err);
 }
-ZEND_METHOD(ion_Reader_Reader, countAnnotations)
+static ZEND_METHOD(ion_Reader_Reader, countAnnotations)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -572,7 +871,7 @@ ZEND_METHOD(ion_Reader_Reader, countAnnotations)
        ION_CHECK(ion_reader_get_annotation_count(obj->reader, &sz));
        RETURN_LONG(sz);
 }
-ZEND_METHOD(ion_Reader_Reader, getAnnotation)
+static ZEND_METHOD(ion_Reader_Reader, getAnnotation)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -586,7 +885,7 @@ ZEND_METHOD(ion_Reader_Reader, getAnnotation)
        ION_CHECK(ion_reader_get_an_annotation(obj->reader, idx, &ann));
        RETURN_STRINGL((char *) ann.value, ann.length);
 }
-ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbol)
+static ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbol)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -600,7 +899,7 @@ ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbol)
        ION_CHECK(ion_reader_get_an_annotation_symbol(obj->reader, idx, &sym));
        php_ion_symbol_zval(&sym, return_value);
 }
-ZEND_METHOD(ion_Reader_Reader, readNull)
+static ZEND_METHOD(ion_Reader_Reader, readNull)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -611,7 +910,7 @@ ZEND_METHOD(ion_Reader_Reader, readNull)
        ION_CHECK(ion_reader_read_null(obj->reader, &typ));
        RETURN_OBJ_COPY(php_ion_type_fetch(typ));
 }
-ZEND_METHOD(ion_Reader_Reader, readBool)
+static ZEND_METHOD(ion_Reader_Reader, readBool)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -622,7 +921,7 @@ ZEND_METHOD(ion_Reader_Reader, readBool)
        ION_CHECK(ion_reader_read_bool(obj->reader, &b));
        RETURN_BOOL(b);
 }
-ZEND_METHOD(ion_Reader_Reader, readInt)
+static ZEND_METHOD(ion_Reader_Reader, readInt)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -631,7 +930,7 @@ ZEND_METHOD(ion_Reader_Reader, readInt)
 
        php_ion_reader_read_int(obj->reader, return_value);
 }
-ZEND_METHOD(ion_Reader_Reader, readFloat)
+static ZEND_METHOD(ion_Reader_Reader, readFloat)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -640,7 +939,7 @@ ZEND_METHOD(ion_Reader_Reader, readFloat)
 
        ION_CHECK(ion_reader_read_double(obj->reader, &Z_DVAL_P(return_value)));
 }
-ZEND_METHOD(ion_Reader_Reader, readDecimal)
+static ZEND_METHOD(ion_Reader_Reader, readDecimal)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -652,7 +951,7 @@ ZEND_METHOD(ion_Reader_Reader, readDecimal)
        ION_CHECK(ion_reader_read_ion_decimal(obj->reader, &dec->dec));
        php_ion_decimal_ctor(dec);
 }
-ZEND_METHOD(ion_Reader_Reader, readTimestamp)
+static ZEND_METHOD(ion_Reader_Reader, readTimestamp)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -661,7 +960,7 @@ ZEND_METHOD(ion_Reader_Reader, readTimestamp)
 
        php_ion_reader_read_timestamp(obj->reader, obj->opt ? &php_ion_obj(reader_options, obj->opt)->opt : NULL, return_value);
 }
-ZEND_METHOD(ion_Reader_Reader, readSymbol)
+static ZEND_METHOD(ion_Reader_Reader, readSymbol)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -672,7 +971,7 @@ ZEND_METHOD(ion_Reader_Reader, readSymbol)
        ION_CHECK(ion_reader_read_ion_symbol(obj->reader, &sym));
        php_ion_symbol_zval(&sym, return_value);
 }
-ZEND_METHOD(ion_Reader_Reader, readString)
+static ZEND_METHOD(ion_Reader_Reader, readString)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -725,11 +1024,11 @@ fail:
        ZVAL_EMPTY_STRING(ref);
        RETURN_FALSE;
 }
-ZEND_METHOD(ion_Reader_Reader, readStringPart)
+static ZEND_METHOD(ion_Reader_Reader, readStringPart)
 {
        read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU, ion_reader_read_partial_string);
 }
-ZEND_METHOD(ion_Reader_Reader, readLob)
+static ZEND_METHOD(ion_Reader_Reader, readLob)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -738,11 +1037,11 @@ ZEND_METHOD(ion_Reader_Reader, readLob)
 
        php_ion_reader_read_lob(obj->reader, return_value);
 }
-ZEND_METHOD(ion_Reader_Reader, readLobPart)
+static ZEND_METHOD(ion_Reader_Reader, readLobPart)
 {
        read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU, ion_reader_read_lob_partial_bytes);
 }
-ZEND_METHOD(ion_Reader_Reader, getPosition)
+static ZEND_METHOD(ion_Reader_Reader, getPosition)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -754,7 +1053,7 @@ ZEND_METHOD(ion_Reader_Reader, getPosition)
        ION_CHECK(ion_reader_get_position(obj->reader, &bytes, &dummy, &dummy));
        RETURN_LONG(bytes);
 }
-ZEND_METHOD(ion_Reader_Reader, getDepth)
+static ZEND_METHOD(ion_Reader_Reader, getDepth)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -765,7 +1064,7 @@ ZEND_METHOD(ion_Reader_Reader, getDepth)
        ION_CHECK(ion_reader_get_depth(obj->reader, &depth));
        RETURN_LONG(depth);
 }
-ZEND_METHOD(ion_Reader_Reader, seek)
+static ZEND_METHOD(ion_Reader_Reader, seek)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -779,7 +1078,7 @@ ZEND_METHOD(ion_Reader_Reader, seek)
 
        ION_CHECK(ion_reader_seek(obj->reader, off, len));
 }
-ZEND_METHOD(ion_Reader_Reader, getValueOffset)
+static ZEND_METHOD(ion_Reader_Reader, getValueOffset)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -790,7 +1089,7 @@ ZEND_METHOD(ion_Reader_Reader, getValueOffset)
        ION_CHECK(ion_reader_get_value_offset(obj->reader, &off));
        RETURN_LONG(off);
 }
-ZEND_METHOD(ion_Reader_Reader, getValueLength)
+static ZEND_METHOD(ion_Reader_Reader, getValueLength)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -801,7 +1100,7 @@ ZEND_METHOD(ion_Reader_Reader, getValueLength)
        ION_CHECK(ion_reader_get_value_length(obj->reader, &len));
        RETURN_LONG(len);
 }
-ZEND_METHOD(ion_Reader_Buffer_Reader, __construct)
+static ZEND_METHOD(ion_Reader_Buffer_Reader, __construct)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -818,7 +1117,7 @@ ZEND_METHOD(ion_Reader_Buffer_Reader, __construct)
 
        php_ion_reader_ctor(obj);
 }
-ZEND_METHOD(ion_Reader_Buffer_Reader, getBuffer)
+static ZEND_METHOD(ion_Reader_Buffer_Reader, getBuffer)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -827,7 +1126,7 @@ ZEND_METHOD(ion_Reader_Buffer_Reader, getBuffer)
        RETURN_STR_COPY(obj->buffer);
 }
 
-ZEND_METHOD(ion_Reader_Stream_Reader, __construct)
+static ZEND_METHOD(ion_Reader_Stream_Reader, __construct)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -844,7 +1143,7 @@ ZEND_METHOD(ion_Reader_Stream_Reader, __construct)
 
        php_ion_reader_ctor(obj);
 }
-ZEND_METHOD(ion_Reader_Stream_Reader, getStream)
+static ZEND_METHOD(ion_Reader_Stream_Reader, getStream)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -855,7 +1154,7 @@ ZEND_METHOD(ion_Reader_Stream_Reader, getStream)
        GC_ADDREF(obj->stream.ptr->res);
        RETURN_RES(obj->stream.ptr->res);
 }
-ZEND_METHOD(ion_Reader_Stream_Reader, resetStream)
+static ZEND_METHOD(ion_Reader_Stream_Reader, resetStream)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -874,7 +1173,7 @@ ZEND_METHOD(ion_Reader_Stream_Reader, resetStream)
        PTR_CHECK(obj->stream.ptr);
        Z_ADDREF_P(zstream);
 }
-ZEND_METHOD(ion_Reader_Stream_Reader, resetStreamWithLength)
+static ZEND_METHOD(ion_Reader_Stream_Reader, resetStreamWithLength)
 {
        php_ion_reader *obj = php_ion_obj(reader, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -895,7 +1194,7 @@ ZEND_METHOD(ion_Reader_Stream_Reader, resetStreamWithLength)
        PTR_CHECK(obj->stream.ptr);
        Z_ADDREF_P(zstream);
 }
-ZEND_METHOD(ion_Writer_Options, __construct)
+static ZEND_METHOD(ion_Writer_Options, __construct)
 {
        php_ion_writer_options *obj = php_ion_obj(writer_options, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -977,7 +1276,7 @@ ZEND_METHOD(ion_Writer_Options, __construct)
        zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("allocationPageSize"),
                        obj->opt.allocation_page_size = alloc);
 }
-ZEND_METHOD(ion_Writer_Writer, writeNull)
+static ZEND_METHOD(ion_Writer_Writer, writeNull)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -986,7 +1285,7 @@ ZEND_METHOD(ion_Writer_Writer, writeNull)
 
        ION_CHECK(ion_writer_write_null(obj->writer));
 }
-ZEND_METHOD(ion_Writer_Writer, writeTypedNull)
+static ZEND_METHOD(ion_Writer_Writer, writeTypedNull)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1000,7 +1299,7 @@ ZEND_METHOD(ion_Writer_Writer, writeTypedNull)
        OBJ_CHECK(typ);
        ION_CHECK(ion_writer_write_typed_null(obj->writer, php_ion_obj(type, typ)->typ));
 }
-ZEND_METHOD(ion_Writer_Writer, writeBool)
+static ZEND_METHOD(ion_Writer_Writer, writeBool)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1012,7 +1311,7 @@ ZEND_METHOD(ion_Writer_Writer, writeBool)
 
        ION_CHECK(ion_writer_write_bool(obj->writer, b));
 }
-ZEND_METHOD(ion_Writer_Writer, writeInt)
+static ZEND_METHOD(ion_Writer_Writer, writeInt)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1033,7 +1332,7 @@ ZEND_METHOD(ion_Writer_Writer, writeInt)
                ION_CHECK(ion_writer_write_int64(obj->writer, l));
        }
 }
-ZEND_METHOD(ion_Writer_Writer, writeFloat)
+static ZEND_METHOD(ion_Writer_Writer, writeFloat)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1045,7 +1344,7 @@ ZEND_METHOD(ion_Writer_Writer, writeFloat)
 
        ION_CHECK(ion_writer_write_double(obj->writer, d));
 }
-ZEND_METHOD(ion_Writer_Writer, writeDecimal)
+static ZEND_METHOD(ion_Writer_Writer, writeDecimal)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1064,7 +1363,7 @@ ZEND_METHOD(ion_Writer_Writer, writeDecimal)
                ION_CHECK(ion_writer_write_ion_decimal(obj->writer, &dec->dec));
        }
 }
-ZEND_METHOD(ion_Writer_Writer, writeTimestamp)
+static ZEND_METHOD(ion_Writer_Writer, writeTimestamp)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1091,7 +1390,7 @@ ZEND_METHOD(ion_Writer_Writer, writeTimestamp)
        }
        ION_CHECK(ion_writer_write_timestamp(obj->writer, &tmp));
 }
-ZEND_METHOD(ion_Writer_Writer, writeSymbol)
+static ZEND_METHOD(ion_Writer_Writer, writeSymbol)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1111,7 +1410,7 @@ ZEND_METHOD(ion_Writer_Writer, writeSymbol)
                ION_CHECK(ion_writer_write_ion_symbol(obj->writer, &sym->sym));
        }
 }
-ZEND_METHOD(ion_Writer_Writer, writeString)
+static ZEND_METHOD(ion_Writer_Writer, writeString)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1124,7 +1423,7 @@ ZEND_METHOD(ion_Writer_Writer, writeString)
        ION_STRING is;
        ION_CHECK(ion_writer_write_string(obj->writer, ion_string_from_zend(&is, str)));
 }
-ZEND_METHOD(ion_Writer_Writer, writeCLob)
+static ZEND_METHOD(ion_Writer_Writer, writeCLob)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1136,7 +1435,7 @@ ZEND_METHOD(ion_Writer_Writer, writeCLob)
 
        ION_CHECK(ion_writer_write_clob(obj->writer, (BYTE *) str->val, str->len));
 }
-ZEND_METHOD(ion_Writer_Writer, writeBLob)
+static ZEND_METHOD(ion_Writer_Writer, writeBLob)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1148,7 +1447,7 @@ ZEND_METHOD(ion_Writer_Writer, writeBLob)
 
        ION_CHECK(ion_writer_write_blob(obj->writer, (BYTE *) str->val, str->len));
 }
-ZEND_METHOD(ion_Writer_Writer, startLob)
+static ZEND_METHOD(ion_Writer_Writer, startLob)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1162,7 +1461,7 @@ ZEND_METHOD(ion_Writer_Writer, startLob)
        OBJ_CHECK(typ);
        ION_CHECK(ion_writer_start_lob(obj->writer, php_ion_obj(type, typ)->typ));
 }
-ZEND_METHOD(ion_Writer_Writer, appendLob)
+static ZEND_METHOD(ion_Writer_Writer, appendLob)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1174,7 +1473,7 @@ ZEND_METHOD(ion_Writer_Writer, appendLob)
 
        ION_CHECK(ion_writer_append_lob(obj->writer, (BYTE *) str->val, str->len));
 }
-ZEND_METHOD(ion_Writer_Writer, finishLob)
+static ZEND_METHOD(ion_Writer_Writer, finishLob)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1183,7 +1482,7 @@ ZEND_METHOD(ion_Writer_Writer, finishLob)
 
        ION_CHECK(ion_writer_finish_lob(obj->writer));
 }
-ZEND_METHOD(ion_Writer_Writer, startContainer)
+static ZEND_METHOD(ion_Writer_Writer, startContainer)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1197,7 +1496,7 @@ ZEND_METHOD(ion_Writer_Writer, startContainer)
        OBJ_CHECK(typ);
        ION_CHECK(ion_writer_start_container(obj->writer, php_ion_obj(type, typ)->typ));
 }
-ZEND_METHOD(ion_Writer_Writer, finishContainer)
+static ZEND_METHOD(ion_Writer_Writer, finishContainer)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1206,7 +1505,7 @@ ZEND_METHOD(ion_Writer_Writer, finishContainer)
 
        ION_CHECK(ion_writer_finish_container(obj->writer));
 }
-ZEND_METHOD(ion_Writer_Writer, writeFieldName)
+static ZEND_METHOD(ion_Writer_Writer, writeFieldName)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1226,7 +1525,7 @@ ZEND_METHOD(ion_Writer_Writer, writeFieldName)
                ION_CHECK(ion_writer_write_field_name_symbol(obj->writer, &sym->sym));
        }
 }
-ZEND_METHOD(ion_Writer_Writer, writeAnnotation)
+static ZEND_METHOD(ion_Writer_Writer, writeAnnotation)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1250,7 +1549,7 @@ ZEND_METHOD(ion_Writer_Writer, writeAnnotation)
                }
        }
 }
-ZEND_METHOD(ion_Writer_Writer, getDepth)
+static ZEND_METHOD(ion_Writer_Writer, getDepth)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1261,7 +1560,7 @@ ZEND_METHOD(ion_Writer_Writer, getDepth)
        ION_CHECK(ion_writer_get_depth(obj->writer, &depth));
        RETURN_LONG(depth);
 }
-ZEND_METHOD(ion_Writer_Writer, flush)
+static ZEND_METHOD(ion_Writer_Writer, flush)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1275,7 +1574,7 @@ ZEND_METHOD(ion_Writer_Writer, flush)
        }
        RETURN_LONG(flushed);
 }
-ZEND_METHOD(ion_Writer_Writer, finish)
+static ZEND_METHOD(ion_Writer_Writer, finish)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1289,13 +1588,13 @@ ZEND_METHOD(ion_Writer_Writer, finish)
        }
        RETURN_LONG(flushed);
 }
-ZEND_METHOD(ion_Writer_Writer, writeOne)
+static ZEND_METHOD(ion_Writer_Writer, writeOne)
 {
 }
-ZEND_METHOD(ion_Writer_Writer, writeAll)
+static ZEND_METHOD(ion_Writer_Writer, writeAll)
 {
 }
-ZEND_METHOD(ion_Writer_Buffer_Writer, __construct)
+static ZEND_METHOD(ion_Writer_Buffer_Writer, __construct)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -1313,7 +1612,7 @@ ZEND_METHOD(ion_Writer_Buffer_Writer, __construct)
 
        php_ion_writer_ctor(obj);
 }
-ZEND_METHOD(ion_Writer_Buffer_Writer, getBuffer)
+static ZEND_METHOD(ion_Writer_Buffer_Writer, getBuffer)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1322,7 +1621,7 @@ ZEND_METHOD(ion_Writer_Buffer_Writer, getBuffer)
 
        RETVAL_STR(zend_string_dup(obj->buffer.str.s, 0));
 }
-ZEND_METHOD(ion_Writer_Stream_Writer, __construct)
+static ZEND_METHOD(ion_Writer_Stream_Writer, __construct)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -1339,7 +1638,7 @@ ZEND_METHOD(ion_Writer_Stream_Writer, __construct)
 
        php_ion_writer_ctor(obj);
 }
-ZEND_METHOD(ion_Writer_Stream_Writer, getStream)
+static ZEND_METHOD(ion_Writer_Stream_Writer, getStream)
 {
        php_ion_writer *obj = php_ion_obj(writer, Z_OBJ_P(ZEND_THIS));
        OBJ_CHECK(obj);
@@ -1351,7 +1650,7 @@ ZEND_METHOD(ion_Writer_Stream_Writer, getStream)
        RETURN_RES(obj->stream.ptr->res);
 }
 
-ZEND_METHOD(ion_Serializer_PHP, __construct)
+static ZEND_METHOD(ion_Serializer_PHP, __construct)
 {
        php_ion_serializer_php *obj = php_ion_obj(serializer_php, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -1368,7 +1667,7 @@ ZEND_METHOD(ion_Serializer_PHP, __construct)
 
        php_ion_serializer_php_ctor(obj);
 }
-ZEND_METHOD(ion_Serializer_PHP, __invoke)
+static ZEND_METHOD(ion_Serializer_PHP, __invoke)
 {
        zend_object *obj = Z_OBJ_P(ZEND_THIS);
 
@@ -1384,7 +1683,7 @@ ZEND_METHOD(ion_Serializer_PHP, __invoke)
                zend_call_method_with_1_params(obj, obj->ce, NULL /* TODO */, "serialize", return_value, data);
        }
 }
-ZEND_FUNCTION(ion_serialize)
+static ZEND_FUNCTION(ion_serialize)
 {
        zval *data;
        zend_object *zo_ser = NULL;
@@ -1402,7 +1701,7 @@ ZEND_FUNCTION(ion_serialize)
                zend_call_method_with_1_params(zo_ser, NULL, NULL, "__invoke", return_value, data);
        }
 }
-ZEND_METHOD(ion_Serializer_PHP, serialize)
+static ZEND_METHOD(ion_Serializer_PHP, serialize)
 {
        //zend_object *obj = Z_OBJ_P(ZEND_THIS);
 
@@ -1415,7 +1714,7 @@ ZEND_METHOD(ion_Serializer_PHP, serialize)
        zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Not implemented");
 }
 
-ZEND_METHOD(ion_Unserializer_PHP, __construct)
+static ZEND_METHOD(ion_Unserializer_PHP, __construct)
 {
        php_ion_unserializer_php *obj = php_ion_obj(unserializer_php, Z_OBJ_P(ZEND_THIS));
        PTR_CHECK(obj);
@@ -1432,7 +1731,7 @@ ZEND_METHOD(ion_Unserializer_PHP, __construct)
 
        php_ion_unserializer_php_ctor(obj);
 }
-ZEND_METHOD(ion_Unserializer_PHP, __invoke)
+static ZEND_METHOD(ion_Unserializer_PHP, __invoke)
 {
        zend_object *obj = Z_OBJ_P(ZEND_THIS);
 
@@ -1447,7 +1746,7 @@ ZEND_METHOD(ion_Unserializer_PHP, __invoke)
                zend_call_method_with_1_params(obj, obj->ce, NULL /* TODO */, "unserialize", return_value, data);
        }
 }
-ZEND_FUNCTION(ion_unserialize)
+static ZEND_FUNCTION(ion_unserialize)
 {
        zval *data;
        zend_object *zo_ser = NULL;
@@ -1465,7 +1764,7 @@ ZEND_FUNCTION(ion_unserialize)
                zend_call_method_with_1_params(zo_ser, NULL, NULL, "__invoke", return_value, data);
        }
 }
-ZEND_METHOD(ion_Unserializer_PHP, unserialize)
+static ZEND_METHOD(ion_Unserializer_PHP, unserialize)
 {
        //zend_object *obj = Z_OBJ_P(ZEND_THIS);
 
@@ -1484,6 +1783,7 @@ PHP_RINIT_FUNCTION(ion)
        ZEND_TSRMLS_CACHE_UPDATE();
 #endif
 
+       php_ion_globals_symbols_init();
        php_ion_globals_serializer_init();
        php_ion_globals_unserializer_init();
        return SUCCESS;
@@ -1491,25 +1791,25 @@ PHP_RINIT_FUNCTION(ion)
 
 PHP_RSHUTDOWN_FUNCTION(ion)
 {
-       php_ion_globals_serializer_dtor();
        php_ion_globals_unserializer_dtor();
+       php_ion_globals_serializer_dtor();
+       php_ion_globals_symbols_dtor();
        return SUCCESS;
 }
 
+#define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
+       { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), default_value },
+#include "ion_arginfo.h"
+
 PHP_MINIT_FUNCTION(ion)
 {
        // true globals
-       php_ion_decimal_from_zend_long(&g_ion_dec_zend_max, &g_dec_ctx, ZEND_LONG_MAX);
-       php_ion_decimal_from_zend_long(&g_ion_dec_zend_min, &g_dec_ctx, ZEND_LONG_MIN);
-
-       // Annotation
-       ce_Annotation = register_class_ion_Annotation();
+       if (SUCCESS != g_sym_init())  {
+               return FAILURE;
+       }
 
        // Catalog
-       php_ion_register(catalog, Catalog);
-
-       // Collection
-       ce_Collection = register_class_ion_Collection();
+       php_ion_register(catalog, Catalog, zend_ce_countable);
 
        // Decimal
        php_ion_register(decimal, Decimal);
@@ -1537,8 +1837,14 @@ PHP_MINIT_FUNCTION(ion)
        oh_Symbol.compare = php_ion_symbol_zval_compare;
        php_ion_register(symbol_iloc, Symbol_ImportLocation);
        php_ion_register(symbol_table, Symbol_Table);
-       ce_Symbol_System = register_class_ion_Symbol_System();
-       ce_Symbol_System_SID = register_class_ion_Symbol_System_SID();
+       ce_Symbol_Table->create_object = NULL;
+       ce_Symbol_Table_Local = register_class_ion_Symbol_Table_Local(ce_Symbol_Table);
+       ce_Symbol_Table_Local->create_object = create_ion_Symbol_Table;
+       ce_Symbol_Table_Shared = register_class_ion_Symbol_Table_Shared(ce_Symbol_Table);
+       ce_Symbol_Table_Shared->create_object = create_ion_Symbol_Table;
+       ce_Symbol_Enum = register_class_ion_Symbol_Enum();
+       ce_Symbol_Table_System = register_class_ion_Symbol_Table_System(ce_Symbol_Enum);
+       ce_Symbol_Table_PHP = register_class_ion_Symbol_Table_PHP(ce_Symbol_Enum);
 
        // Timestamp
        ce_Timestamp = register_class_ion_Timestamp(php_date_get_date_ce());
@@ -1565,8 +1871,13 @@ PHP_MINIT_FUNCTION(ion)
 
 PHP_MSHUTDOWN_FUNCTION(ion)
 {
+       if (g_sym_tab_php) {
+               ion_symbol_table_close(g_sym_tab_php);
+       }
+       zend_hash_destroy(&g_sym_hash);
        return SUCCESS;
 }
+
 PHP_MINFO_FUNCTION(ion)
 {
        php_info_print_table_start();
@@ -1578,8 +1889,11 @@ PHP_GINIT_FUNCTION(ion)
 {
        memset(ion_globals, 0, sizeof(*ion_globals));
 
-       php_ion_decimal_ctx_init_max(&ion_globals->decimal_ctx, DEC_ROUND_HALF_EVEN);
+       php_ion_decimal_ctx_init_max(&ion_globals->decimal.ctx, DEC_ROUND_HALF_EVEN);
+       php_ion_decimal_from_zend_long(&ion_globals->decimal.zend_max, &ion_globals->decimal.ctx, ZEND_LONG_MAX);
+       php_ion_decimal_from_zend_long(&ion_globals->decimal.zend_min, &ion_globals->decimal.ctx, ZEND_LONG_MIN);
 }
+
 PHP_GSHUTDOWN_FUNCTION(ion)
 {
 }
index ef6bbef557dde54347c345df4bba220ec3c5951b..8e5d6aca4f8a81da5cdceb436106fe2e0c773896 100644 (file)
@@ -1,6 +1,10 @@
 <?php
 
-/** @generate-class-entries */
+/**
+ * @generate-class-entries static
+ * @generate-function-entries static
+ */
+
 
 namespace ion;
 enum Type : int {
@@ -23,22 +27,6 @@ enum Type : int {
     case NONE       =-0x200;
 }
 
-enum Annotation : string {
-    case PHP            = "PHP";
-
-    case REFERENCE      = "R";
-    case BACKREF        = "r";
-
-    case OBJECT         = "o";
-    case CLASS_OBJ      = "c";
-    case MAGIC_OBJ      = "O";
-    case CUSTOM_OBJ     = "C";
-    case SERIALIZABLE   = "S";
-    case ENUM           = "E";
-
-    case PROPERTY       = "p";
-}
-
 namespace ion\Symbol;
 class ImportLocation {
     public function __construct(
@@ -48,7 +36,14 @@ class ImportLocation {
 }
 
 namespace ion\Symbol;
-enum System : string {
+interface Enum {
+    public function toSymbol() : \ion\Symbol;
+    public function toSID() : int;
+    public function toString() : string;
+}
+
+namespace ion\Symbol\Table;
+enum System : string implements \ion\Symbol\Enum {
     case Ion                = '$ion';
     case Ivm_1_0            = '$ion_1_0';
     case IonSymbolTable     = '$ion_symbol_table';
@@ -58,19 +53,34 @@ enum System : string {
     case Symbols            = 'symbols';
     case MaxId              = 'max_id';
     case SharedSymbolTable  = '$ion_shared_symbol_table';
+
+    /** @alias ion\Symbol\Enum::toSymbol */
+    public function toSymbol() : \ion\Symbol {}
+    /** @alias ion\Symbol\Enum::toSID */
+    public function toSID() : int {}
+    /** @alias ion\Symbol\Enum::toString */
+    public function toString() : string {}
 }
 
-namespace ion\Symbol\System;
-enum SID : int {
-    case Ion                = 1;
-    case Ivm_1_0            = 2;
-    case IonSymbolTable     = 3;
-    case Name               = 4;
-    case Version            = 5;
-    case Imports            = 6;
-    case Symbols            = 7;
-    case MaxId              = 8;
-    case SharedSymbolTable  = 9;
+namespace ion\Symbol\Table;
+enum PHP : string implements \ion\Symbol\Enum {
+    case PHP            = 'PHP';
+    case Reference      = 'R';
+    case Backref        = 'r';
+    case Property       = 'p';
+    case Object         = 'o';
+    case ClassObject    = 'c';
+    case MagicObject    = 'O';
+    case CustomObject   = 'C';
+    case Enum           = 'E';
+    case Serializable   = 'S';
+
+    /** @alias ion\Symbol\Enum::toSymbol */
+    public function toSymbol() : \ion\Symbol {}
+    /** @alias ion\Symbol\Enum::toSID */
+    public function toSID() : int {}
+    /** @alias ion\Symbol\Enum::toString */
+    public function toString() : string {}
 }
 
 namespace ion;
@@ -88,17 +98,70 @@ class Symbol {
 }
 
 namespace ion\Symbol;
-class Table {
+interface Table {
+    public function getMaxId() : int;
 
+    public function add(\ion\Symbol|string $symbol) : int;
+    public function find(string|int $id) : ?\ion\Symbol;
+    public function findLocal(string|int $id) : ?\ion\Symbol;
 }
 
-namespace ion;
-class Catalog {
+namespace ion\Symbol\Table;
+function PHP() : \ion\Symbol\Table {}
+function System() : \ion\Symbol\Table {}
+
+namespace ion\Symbol\Table;
+class Local implements \ion\Symbol\Table {
+    private array $imports = [];
+    private array $symbols = [];
+
+    public function __construct() {}
+    public function import(\ion\Symbol\Table $table) : void {}
+
+    /** @alias ion\Symbol\Table::getMaxId */
+    public function getMaxId() : int {}
+
+    /** @alias ion\Symbol\Table::add */
+    public function add(\ion\Symbol|string $symbol) : int {}
+    /** @alias ion\Symbol\Table::find */
+    public function find(string|int $id) : ?\ion\Symbol {}
+    /** @alias ion\Symbol\Table::findLocal */
+    public function findLocal(string|int $id) : ?\ion\Symbol {}
+}
+
+namespace ion\Symbol\Table;
+class Shared implements \ion\Symbol\Table {
+    private array $symbols = [];
+
+    public function __construct(
+        public readonly string $name,
+        public readonly int $version = 1,
+    ) {}
+
+    /** @alias ion\Symbol\Table::getMaxId */
+    public function getMaxId() : int {}
+
+    /** @alias ion\Symbol\Table::add */
+    public function add(\ion\Symbol|string $symbol) : int {}
+    /** @alias ion\Symbol\Table::find */
+    public function find(string|int $id) : ?\ion\Symbol {}
+    /** @alias ion\Symbol\Table::findLocal */
+    public function findLocal(string|int $id) : ?\ion\Symbol {}
 }
 
 namespace ion;
-class Collection {
+class Catalog implements Countable {
+    private array $symbolTables = [];
+
+    public function __construct() {}
+
+    public function count() : int {}
+
+    public function add(Symbol\Table $table) : void {}
+    public function remove(Symbol\Table|string $table) : bool {}
 
+    public function find(string $name, int $version = 0) : ?Symbol\Table {}
+    public function findBest(string $name, int $version = 0) : ?Symbol\Table {}
 }
 
 namespace ion;
index 5d48e0316e953506816bd885a864be9a7134e7ff..da8a3fbb8ffe075fefa8891de95fe374c289b926 100644 (file)
@@ -1,5 +1,10 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 31c610f8d923117a4e69635ba3eb9387087f66fd */
+ * Stub hash: 943d369644718978b3b990f4345d51bed5f71366 */
+
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_ion_Symbol_Table_PHP, 0, 0, ion\\Symbol\\Table, 0)
+ZEND_END_ARG_INFO()
+
+#define arginfo_ion_Symbol_Table_System arginfo_ion_Symbol_Table_PHP
 
 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)
@@ -16,6 +21,27 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Symbol_ImportLocation___construct, 0, 0
        ZEND_ARG_TYPE_INFO(0, location, IS_LONG, 0)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ion_Symbol_Enum_toSymbol, 0, 0, ion\\Symbol, 0)
+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_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_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")
@@ -26,10 +52,66 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Symbol_equals, 0, 1, _
        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)
+#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_getMaxId arginfo_class_ion_Symbol_Enum_toSID
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Symbol_Table_add, 0, 1, IS_LONG, 0)
+       ZEND_ARG_OBJ_TYPE_MASK(0, symbol, ion\\Symbol, MAY_BE_STRING, NULL)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ion_Symbol_Table_find, 0, 1, ion\\Symbol, 1)
+       ZEND_ARG_TYPE_MASK(0, id, MAY_BE_STRING|MAY_BE_LONG, NULL)
+ZEND_END_ARG_INFO()
+
+#define arginfo_class_ion_Symbol_Table_findLocal arginfo_class_ion_Symbol_Table_find
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Symbol_Table_Local___construct, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Symbol_Table_Local_import, 0, 1, IS_VOID, 0)
+       ZEND_ARG_OBJ_INFO(0, table, ion\\Symbol\\Table, 0)
+ZEND_END_ARG_INFO()
+
+#define arginfo_class_ion_Symbol_Table_Local_getMaxId arginfo_class_ion_Symbol_Enum_toSID
+
+#define arginfo_class_ion_Symbol_Table_Local_add arginfo_class_ion_Symbol_Table_add
+
+#define arginfo_class_ion_Symbol_Table_Local_find arginfo_class_ion_Symbol_Table_find
+
+#define arginfo_class_ion_Symbol_Table_Local_findLocal arginfo_class_ion_Symbol_Table_find
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Symbol_Table_Shared___construct, 0, 0, 1)
+       ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, version, IS_LONG, 0, "1")
 ZEND_END_ARG_INFO()
 
-#define arginfo_class_ion_Symbol_toString arginfo_class_ion_Symbol___toString
+#define arginfo_class_ion_Symbol_Table_Shared_getMaxId arginfo_class_ion_Symbol_Enum_toSID
+
+#define arginfo_class_ion_Symbol_Table_Shared_add arginfo_class_ion_Symbol_Table_add
+
+#define arginfo_class_ion_Symbol_Table_Shared_find arginfo_class_ion_Symbol_Table_find
+
+#define arginfo_class_ion_Symbol_Table_Shared_findLocal arginfo_class_ion_Symbol_Table_find
+
+#define arginfo_class_ion_Catalog___construct arginfo_class_ion_Symbol_Table_Local___construct
+
+#define arginfo_class_ion_Catalog_count arginfo_class_ion_Symbol_Enum_toSID
+
+#define arginfo_class_ion_Catalog_add arginfo_class_ion_Symbol_Table_Local_import
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Catalog_remove, 0, 1, _IS_BOOL, 0)
+       ZEND_ARG_OBJ_TYPE_MASK(0, table, ion\\Symbol\\Table, MAY_BE_STRING, NULL)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ion_Catalog_find, 0, 1, ion\\Symbol\\Table, 1)
+       ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, version, IS_LONG, 0, "0")
+ZEND_END_ARG_INFO()
+
+#define arginfo_class_ion_Catalog_findBest arginfo_class_ion_Catalog_find
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_LOB___construct, 0, 0, 1)
        ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0)
@@ -67,12 +149,11 @@ 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___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_toString arginfo_class_ion_Symbol_Enum_toString
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Decimal_toInt, 0, 0, IS_LONG, 0)
-ZEND_END_ARG_INFO()
+#define arginfo_class_ion_Decimal_toInt arginfo_class_ion_Symbol_Enum_toSID
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Timestamp___construct, 0, 0, 1)
        ZEND_ARG_OBJ_TYPE_MASK(0, precision, ion\\Timestamp\\Precision, MAY_BE_LONG, NULL)
@@ -81,7 +162,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___toString
+#define arginfo_class_ion_Timestamp___toString arginfo_class_ion_Symbol_Enum_toString
 
 ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ion_Reader_getType, 0, 0, ion\\Type, 0)
 ZEND_END_ARG_INFO()
@@ -96,17 +177,16 @@ 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___toString
+#define arginfo_class_ion_Reader_getFieldName arginfo_class_ion_Symbol_Enum_toString
 
-ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ion_Reader_getFieldNameSymbol, 0, 0, ion\\Symbol, 0)
-ZEND_END_ARG_INFO()
+#define arginfo_class_ion_Reader_getFieldNameSymbol arginfo_class_ion_Symbol_Enum_toSymbol
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Reader_getAnnotations, 0, 0, IS_ARRAY, 0)
 ZEND_END_ARG_INFO()
 
 #define arginfo_class_ion_Reader_getAnnotationSymbols arginfo_class_ion_Reader_getAnnotations
 
-#define arginfo_class_ion_Reader_countAnnotations arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Reader_countAnnotations arginfo_class_ion_Symbol_Enum_toSID
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Reader_getAnnotation, 0, 1, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
@@ -132,31 +212,31 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ion_Reader_readTimestamp, 0, 0, ion\\Timestamp, 0)
 ZEND_END_ARG_INFO()
 
-#define arginfo_class_ion_Reader_readSymbol arginfo_class_ion_Reader_getFieldNameSymbol
+#define arginfo_class_ion_Reader_readSymbol arginfo_class_ion_Symbol_Enum_toSymbol
 
-#define arginfo_class_ion_Reader_readString arginfo_class_ion_Symbol___toString
+#define arginfo_class_ion_Reader_readString arginfo_class_ion_Symbol_Enum_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___toString
+#define arginfo_class_ion_Reader_readLob arginfo_class_ion_Symbol_Enum_toString
 
 #define arginfo_class_ion_Reader_readLobPart arginfo_class_ion_Reader_readStringPart
 
-#define arginfo_class_ion_Reader_getPosition arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Reader_getPosition arginfo_class_ion_Symbol_Enum_toSID
 
-#define arginfo_class_ion_Reader_getDepth arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Reader_getDepth arginfo_class_ion_Symbol_Enum_toSID
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Reader_seek, 0, 1, IS_VOID, 0)
        ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "-1")
 ZEND_END_ARG_INFO()
 
-#define arginfo_class_ion_Reader_getValueOffset arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Reader_getValueOffset arginfo_class_ion_Symbol_Enum_toSID
 
-#define arginfo_class_ion_Reader_getValueLength arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Reader_getValueLength arginfo_class_ion_Symbol_Enum_toSID
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Reader_Options___construct, 0, 0, 0)
        ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, catalog, ion\\Catalog, 1, "null")
@@ -201,15 +281,15 @@ 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___toString
+#define arginfo_class_ion_Reader_Reader_getFieldName arginfo_class_ion_Symbol_Enum_toString
 
-#define arginfo_class_ion_Reader_Reader_getFieldNameSymbol arginfo_class_ion_Reader_getFieldNameSymbol
+#define arginfo_class_ion_Reader_Reader_getFieldNameSymbol arginfo_class_ion_Symbol_Enum_toSymbol
 
 #define arginfo_class_ion_Reader_Reader_getAnnotations arginfo_class_ion_Reader_getAnnotations
 
 #define arginfo_class_ion_Reader_Reader_getAnnotationSymbols arginfo_class_ion_Reader_getAnnotations
 
-#define arginfo_class_ion_Reader_Reader_countAnnotations arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Reader_Reader_countAnnotations arginfo_class_ion_Symbol_Enum_toSID
 
 #define arginfo_class_ion_Reader_Reader_getAnnotation arginfo_class_ion_Reader_getAnnotation
 
@@ -227,37 +307,36 @@ ZEND_END_ARG_INFO()
 
 #define arginfo_class_ion_Reader_Reader_readTimestamp arginfo_class_ion_Reader_readTimestamp
 
-#define arginfo_class_ion_Reader_Reader_readSymbol arginfo_class_ion_Reader_getFieldNameSymbol
+#define arginfo_class_ion_Reader_Reader_readSymbol arginfo_class_ion_Symbol_Enum_toSymbol
 
-#define arginfo_class_ion_Reader_Reader_readString arginfo_class_ion_Symbol___toString
+#define arginfo_class_ion_Reader_Reader_readString arginfo_class_ion_Symbol_Enum_toString
 
 #define arginfo_class_ion_Reader_Reader_readStringPart arginfo_class_ion_Reader_readStringPart
 
-#define arginfo_class_ion_Reader_Reader_readLob arginfo_class_ion_Symbol___toString
+#define arginfo_class_ion_Reader_Reader_readLob arginfo_class_ion_Symbol_Enum_toString
 
 #define arginfo_class_ion_Reader_Reader_readLobPart arginfo_class_ion_Reader_readStringPart
 
-#define arginfo_class_ion_Reader_Reader_getPosition arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Reader_Reader_getPosition arginfo_class_ion_Symbol_Enum_toSID
 
-#define arginfo_class_ion_Reader_Reader_getDepth arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Reader_Reader_getDepth arginfo_class_ion_Symbol_Enum_toSID
 
 #define arginfo_class_ion_Reader_Reader_seek arginfo_class_ion_Reader_seek
 
-#define arginfo_class_ion_Reader_Reader_getValueOffset arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Reader_Reader_getValueOffset arginfo_class_ion_Symbol_Enum_toSID
 
-#define arginfo_class_ion_Reader_Reader_getValueLength arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Reader_Reader_getValueLength arginfo_class_ion_Symbol_Enum_toSID
 
-#define arginfo_class_ion_Reader_Buffer_getBuffer arginfo_class_ion_Symbol___toString
+#define arginfo_class_ion_Reader_Buffer_getBuffer arginfo_class_ion_Symbol_Enum_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___toString
+#define arginfo_class_ion_Reader_Buffer_Reader_getBuffer arginfo_class_ion_Symbol_Enum_toString
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Reader_Stream_getStream, 0, 0, 0)
-ZEND_END_ARG_INFO()
+#define arginfo_class_ion_Reader_Stream_getStream arginfo_class_ion_Symbol_Table_Local___construct
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Reader_Stream_resetStream, 0, 1, IS_VOID, 0)
        ZEND_ARG_INFO(0, stream)
@@ -274,7 +353,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Reader_Stream_Reader___construct, 0, 0,
        ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, options, ion\\Reader\\Options, 1, "null")
 ZEND_END_ARG_INFO()
 
-#define arginfo_class_ion_Reader_Stream_Reader_getStream arginfo_class_ion_Reader_Stream_getStream
+#define arginfo_class_ion_Reader_Stream_Reader_getStream arginfo_class_ion_Symbol_Table_Local___construct
 
 #define arginfo_class_ion_Reader_Stream_Reader_resetStream arginfo_class_ion_Reader_Stream_resetStream
 
@@ -357,11 +436,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Writer_writeAnnotation
        ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(0, annotation, ion\\Symbol, MAY_BE_STRING, NULL)
 ZEND_END_ARG_INFO()
 
-#define arginfo_class_ion_Writer_getDepth arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Writer_getDepth arginfo_class_ion_Symbol_Enum_toSID
 
-#define arginfo_class_ion_Writer_flush arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Writer_flush arginfo_class_ion_Symbol_Enum_toSID
 
-#define arginfo_class_ion_Writer_finish arginfo_class_ion_Decimal_toInt
+#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)
@@ -405,33 +484,33 @@ ZEND_END_ARG_INFO()
 
 #define arginfo_class_ion_Writer_Writer_writeAnnotation arginfo_class_ion_Writer_writeAnnotation
 
-#define arginfo_class_ion_Writer_Writer_getDepth arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Writer_Writer_getDepth arginfo_class_ion_Symbol_Enum_toSID
 
-#define arginfo_class_ion_Writer_Writer_flush arginfo_class_ion_Decimal_toInt
+#define arginfo_class_ion_Writer_Writer_flush arginfo_class_ion_Symbol_Enum_toSID
 
-#define arginfo_class_ion_Writer_Writer_finish arginfo_class_ion_Decimal_toInt
+#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___toString
+#define arginfo_class_ion_Writer_Buffer_getBuffer arginfo_class_ion_Symbol_Enum_toString
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Writer_Buffer_Writer___construct, 0, 0, 1)
        ZEND_ARG_TYPE_INFO(1, buffer, IS_STRING, 1)
        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___toString
+#define arginfo_class_ion_Writer_Buffer_Writer_getBuffer arginfo_class_ion_Symbol_Enum_toString
 
-#define arginfo_class_ion_Writer_Stream_getStream arginfo_class_ion_Reader_Stream_getStream
+#define arginfo_class_ion_Writer_Stream_getStream arginfo_class_ion_Symbol_Table_Local___construct
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ion_Writer_Stream_Writer___construct, 0, 0, 1)
        ZEND_ARG_INFO(0, stream)
        ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, options, ion\\Writer\\Options, 1, "null")
 ZEND_END_ARG_INFO()
 
-#define arginfo_class_ion_Writer_Stream_Writer_getStream arginfo_class_ion_Reader_Stream_getStream
+#define arginfo_class_ion_Writer_Stream_Writer_getStream arginfo_class_ion_Symbol_Table_Local___construct
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ion_Serializer___invoke, 0, 1, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, data, IS_MIXED, 0)
@@ -464,104 +543,117 @@ ZEND_END_ARG_INFO()
 #define arginfo_class_ion_Unserializer_PHP_unserialize arginfo_class_ion_Unserializer___invoke
 
 
-ZEND_FUNCTION(ion_serialize);
-ZEND_FUNCTION(ion_unserialize);
-ZEND_METHOD(ion_Symbol_ImportLocation, __construct);
-ZEND_METHOD(ion_Symbol, __construct);
-ZEND_METHOD(ion_Symbol, equals);
-ZEND_METHOD(ion_Symbol, __toString);
-ZEND_METHOD(ion_LOB, __construct);
-ZEND_METHOD(ion_Decimal_Context, __construct);
-ZEND_METHOD(ion_Decimal_Context, Dec32);
-ZEND_METHOD(ion_Decimal_Context, Dec64);
-ZEND_METHOD(ion_Decimal_Context, Dec128);
-ZEND_METHOD(ion_Decimal_Context, DecMax);
-ZEND_METHOD(ion_Decimal, __construct);
-ZEND_METHOD(ion_Decimal, equals);
-ZEND_METHOD(ion_Decimal, isInt);
-ZEND_METHOD(ion_Decimal, __toString);
-ZEND_METHOD(ion_Decimal, toInt);
-ZEND_METHOD(ion_Timestamp, __construct);
-ZEND_METHOD(ion_Timestamp, __toString);
-ZEND_METHOD(ion_Reader_Options, __construct);
-ZEND_METHOD(ion_Reader_Reader, hasChildren);
-ZEND_METHOD(ion_Reader_Reader, getChildren);
-ZEND_METHOD(ion_Reader_Reader, rewind);
-ZEND_METHOD(ion_Reader_Reader, next);
-ZEND_METHOD(ion_Reader_Reader, valid);
-ZEND_METHOD(ion_Reader_Reader, key);
-ZEND_METHOD(ion_Reader_Reader, current);
-ZEND_METHOD(ion_Reader_Reader, getType);
-ZEND_METHOD(ion_Reader_Reader, hasAnnotations);
-ZEND_METHOD(ion_Reader_Reader, hasAnnotation);
-ZEND_METHOD(ion_Reader_Reader, isNull);
-ZEND_METHOD(ion_Reader_Reader, isInStruct);
-ZEND_METHOD(ion_Reader_Reader, getFieldName);
-ZEND_METHOD(ion_Reader_Reader, getFieldNameSymbol);
-ZEND_METHOD(ion_Reader_Reader, getAnnotations);
-ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbols);
-ZEND_METHOD(ion_Reader_Reader, countAnnotations);
-ZEND_METHOD(ion_Reader_Reader, getAnnotation);
-ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbol);
-ZEND_METHOD(ion_Reader_Reader, readNull);
-ZEND_METHOD(ion_Reader_Reader, readBool);
-ZEND_METHOD(ion_Reader_Reader, readInt);
-ZEND_METHOD(ion_Reader_Reader, readFloat);
-ZEND_METHOD(ion_Reader_Reader, readDecimal);
-ZEND_METHOD(ion_Reader_Reader, readTimestamp);
-ZEND_METHOD(ion_Reader_Reader, readSymbol);
-ZEND_METHOD(ion_Reader_Reader, readString);
-ZEND_METHOD(ion_Reader_Reader, readStringPart);
-ZEND_METHOD(ion_Reader_Reader, readLob);
-ZEND_METHOD(ion_Reader_Reader, readLobPart);
-ZEND_METHOD(ion_Reader_Reader, getPosition);
-ZEND_METHOD(ion_Reader_Reader, getDepth);
-ZEND_METHOD(ion_Reader_Reader, seek);
-ZEND_METHOD(ion_Reader_Reader, getValueOffset);
-ZEND_METHOD(ion_Reader_Reader, getValueLength);
-ZEND_METHOD(ion_Reader_Buffer_Reader, __construct);
-ZEND_METHOD(ion_Reader_Buffer_Reader, getBuffer);
-ZEND_METHOD(ion_Reader_Stream_Reader, __construct);
-ZEND_METHOD(ion_Reader_Stream_Reader, getStream);
-ZEND_METHOD(ion_Reader_Stream_Reader, resetStream);
-ZEND_METHOD(ion_Reader_Stream_Reader, resetStreamWithLength);
-ZEND_METHOD(ion_Writer_Options, __construct);
-ZEND_METHOD(ion_Writer_Writer, writeNull);
-ZEND_METHOD(ion_Writer_Writer, writeTypedNull);
-ZEND_METHOD(ion_Writer_Writer, writeBool);
-ZEND_METHOD(ion_Writer_Writer, writeInt);
-ZEND_METHOD(ion_Writer_Writer, writeFloat);
-ZEND_METHOD(ion_Writer_Writer, writeDecimal);
-ZEND_METHOD(ion_Writer_Writer, writeTimestamp);
-ZEND_METHOD(ion_Writer_Writer, writeSymbol);
-ZEND_METHOD(ion_Writer_Writer, writeString);
-ZEND_METHOD(ion_Writer_Writer, writeCLob);
-ZEND_METHOD(ion_Writer_Writer, writeBLob);
-ZEND_METHOD(ion_Writer_Writer, startLob);
-ZEND_METHOD(ion_Writer_Writer, appendLob);
-ZEND_METHOD(ion_Writer_Writer, finishLob);
-ZEND_METHOD(ion_Writer_Writer, startContainer);
-ZEND_METHOD(ion_Writer_Writer, finishContainer);
-ZEND_METHOD(ion_Writer_Writer, writeFieldName);
-ZEND_METHOD(ion_Writer_Writer, writeAnnotation);
-ZEND_METHOD(ion_Writer_Writer, getDepth);
-ZEND_METHOD(ion_Writer_Writer, flush);
-ZEND_METHOD(ion_Writer_Writer, finish);
-ZEND_METHOD(ion_Writer_Writer, writeOne);
-ZEND_METHOD(ion_Writer_Writer, writeAll);
-ZEND_METHOD(ion_Writer_Buffer_Writer, __construct);
-ZEND_METHOD(ion_Writer_Buffer_Writer, getBuffer);
-ZEND_METHOD(ion_Writer_Stream_Writer, __construct);
-ZEND_METHOD(ion_Writer_Stream_Writer, getStream);
-ZEND_METHOD(ion_Serializer_PHP, __construct);
-ZEND_METHOD(ion_Serializer_PHP, __invoke);
-ZEND_METHOD(ion_Serializer_PHP, serialize);
-ZEND_METHOD(ion_Unserializer_PHP, __construct);
-ZEND_METHOD(ion_Unserializer_PHP, __invoke);
-ZEND_METHOD(ion_Unserializer_PHP, unserialize);
+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_Table_Local, __construct);
+static ZEND_METHOD(ion_Symbol_Table_Local, import);
+static ZEND_METHOD(ion_Symbol_Table_Shared, __construct);
+static ZEND_METHOD(ion_Catalog, __construct);
+static ZEND_METHOD(ion_Catalog, count);
+static ZEND_METHOD(ion_Catalog, add);
+static ZEND_METHOD(ion_Catalog, remove);
+static ZEND_METHOD(ion_Catalog, find);
+static ZEND_METHOD(ion_Catalog, findBest);
+static ZEND_METHOD(ion_LOB, __construct);
+static ZEND_METHOD(ion_Decimal_Context, __construct);
+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_Decimal, __construct);
+static ZEND_METHOD(ion_Decimal, equals);
+static ZEND_METHOD(ion_Decimal, isInt);
+static ZEND_METHOD(ion_Decimal, __toString);
+static ZEND_METHOD(ion_Decimal, toInt);
+static ZEND_METHOD(ion_Timestamp, __construct);
+static ZEND_METHOD(ion_Timestamp, __toString);
+static ZEND_METHOD(ion_Reader_Options, __construct);
+static ZEND_METHOD(ion_Reader_Reader, hasChildren);
+static ZEND_METHOD(ion_Reader_Reader, getChildren);
+static ZEND_METHOD(ion_Reader_Reader, rewind);
+static ZEND_METHOD(ion_Reader_Reader, next);
+static ZEND_METHOD(ion_Reader_Reader, valid);
+static ZEND_METHOD(ion_Reader_Reader, key);
+static ZEND_METHOD(ion_Reader_Reader, current);
+static ZEND_METHOD(ion_Reader_Reader, getType);
+static ZEND_METHOD(ion_Reader_Reader, hasAnnotations);
+static ZEND_METHOD(ion_Reader_Reader, hasAnnotation);
+static ZEND_METHOD(ion_Reader_Reader, isNull);
+static ZEND_METHOD(ion_Reader_Reader, isInStruct);
+static ZEND_METHOD(ion_Reader_Reader, getFieldName);
+static ZEND_METHOD(ion_Reader_Reader, getFieldNameSymbol);
+static ZEND_METHOD(ion_Reader_Reader, getAnnotations);
+static ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbols);
+static ZEND_METHOD(ion_Reader_Reader, countAnnotations);
+static ZEND_METHOD(ion_Reader_Reader, getAnnotation);
+static ZEND_METHOD(ion_Reader_Reader, getAnnotationSymbol);
+static ZEND_METHOD(ion_Reader_Reader, readNull);
+static ZEND_METHOD(ion_Reader_Reader, readBool);
+static ZEND_METHOD(ion_Reader_Reader, readInt);
+static ZEND_METHOD(ion_Reader_Reader, readFloat);
+static ZEND_METHOD(ion_Reader_Reader, readDecimal);
+static ZEND_METHOD(ion_Reader_Reader, readTimestamp);
+static ZEND_METHOD(ion_Reader_Reader, readSymbol);
+static ZEND_METHOD(ion_Reader_Reader, readString);
+static ZEND_METHOD(ion_Reader_Reader, readStringPart);
+static ZEND_METHOD(ion_Reader_Reader, readLob);
+static ZEND_METHOD(ion_Reader_Reader, readLobPart);
+static ZEND_METHOD(ion_Reader_Reader, getPosition);
+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, writeNull);
+static ZEND_METHOD(ion_Writer_Writer, writeTypedNull);
+static ZEND_METHOD(ion_Writer_Writer, writeBool);
+static ZEND_METHOD(ion_Writer_Writer, writeInt);
+static ZEND_METHOD(ion_Writer_Writer, writeFloat);
+static ZEND_METHOD(ion_Writer_Writer, writeDecimal);
+static ZEND_METHOD(ion_Writer_Writer, writeTimestamp);
+static ZEND_METHOD(ion_Writer_Writer, writeSymbol);
+static ZEND_METHOD(ion_Writer_Writer, writeString);
+static ZEND_METHOD(ion_Writer_Writer, writeCLob);
+static ZEND_METHOD(ion_Writer_Writer, writeBLob);
+static ZEND_METHOD(ion_Writer_Writer, startLob);
+static ZEND_METHOD(ion_Writer_Writer, appendLob);
+static ZEND_METHOD(ion_Writer_Writer, finishLob);
+static ZEND_METHOD(ion_Writer_Writer, startContainer);
+static ZEND_METHOD(ion_Writer_Writer, finishContainer);
+static ZEND_METHOD(ion_Writer_Writer, writeFieldName);
+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_Stream_Writer, __construct);
+static ZEND_METHOD(ion_Writer_Stream_Writer, getStream);
+static ZEND_METHOD(ion_Serializer_PHP, __construct);
+static ZEND_METHOD(ion_Serializer_PHP, __invoke);
+static ZEND_METHOD(ion_Serializer_PHP, serialize);
+static ZEND_METHOD(ion_Unserializer_PHP, __construct);
+static ZEND_METHOD(ion_Unserializer_PHP, __invoke);
+static ZEND_METHOD(ion_Unserializer_PHP, unserialize);
 
 
 static const zend_function_entry ext_functions[] = {
+       ZEND_NS_RAW_FENTRY("ion\\Symbol\\Table", "PHP", ZEND_FN(ion_Symbol_Table_PHP), arginfo_ion_Symbol_Table_PHP, 0)
+       ZEND_NS_RAW_FENTRY("ion\\Symbol\\Table", "System", ZEND_FN(ion_Symbol_Table_System), arginfo_ion_Symbol_Table_System, 0)
        ZEND_NS_RAW_FENTRY("ion", "serialize", ZEND_FN(ion_serialize), arginfo_ion_serialize, 0)
        ZEND_NS_RAW_FENTRY("ion", "unserialize", ZEND_FN(ion_unserialize), arginfo_ion_unserialize, 0)
        ZEND_FE_END
@@ -573,23 +665,32 @@ static const zend_function_entry class_ion_Type_methods[] = {
 };
 
 
-static const zend_function_entry class_ion_Annotation_methods[] = {
+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
 };
 
 
-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)
+static const zend_function_entry class_ion_Symbol_Enum_methods[] = {
+       ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Symbol_Enum, toSymbol, arginfo_class_ion_Symbol_Enum_toSymbol, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
+       ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Symbol_Enum, toSID, arginfo_class_ion_Symbol_Enum_toSID, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
+       ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Symbol_Enum, toString, arginfo_class_ion_Symbol_Enum_toString, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
        ZEND_FE_END
 };
 
 
-static const zend_function_entry class_ion_Symbol_System_methods[] = {
+static const zend_function_entry class_ion_Symbol_Table_System_methods[] = {
+       ZEND_MALIAS(ion_Symbol_Enum, toSymbol, toSymbol, arginfo_class_ion_Symbol_Table_System_toSymbol, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Enum, toSID, toSID, arginfo_class_ion_Symbol_Table_System_toSID, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Enum, toString, toString, arginfo_class_ion_Symbol_Table_System_toString, ZEND_ACC_PUBLIC)
        ZEND_FE_END
 };
 
 
-static const zend_function_entry class_ion_Symbol_System_SID_methods[] = {
+static const zend_function_entry class_ion_Symbol_Table_PHP_methods[] = {
+       ZEND_MALIAS(ion_Symbol_Enum, toSymbol, toSymbol, arginfo_class_ion_Symbol_Table_PHP_toSymbol, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Enum, toSID, toSID, arginfo_class_ion_Symbol_Table_PHP_toSID, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Enum, toString, toString, arginfo_class_ion_Symbol_Table_PHP_toString, ZEND_ACC_PUBLIC)
        ZEND_FE_END
 };
 
@@ -604,16 +705,42 @@ static const zend_function_entry class_ion_Symbol_methods[] = {
 
 
 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)
+       ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Symbol_Table, find, arginfo_class_ion_Symbol_Table_find, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
+       ZEND_ABSTRACT_ME_WITH_FLAGS(ion_Symbol_Table, findLocal, arginfo_class_ion_Symbol_Table_findLocal, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
        ZEND_FE_END
 };
 
 
-static const zend_function_entry class_ion_Catalog_methods[] = {
+static const zend_function_entry class_ion_Symbol_Table_Local_methods[] = {
+       ZEND_ME(ion_Symbol_Table_Local, __construct, arginfo_class_ion_Symbol_Table_Local___construct, ZEND_ACC_PUBLIC)
+       ZEND_ME(ion_Symbol_Table_Local, import, arginfo_class_ion_Symbol_Table_Local_import, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Table, getMaxId, getMaxId, arginfo_class_ion_Symbol_Table_Local_getMaxId, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Table, add, add, arginfo_class_ion_Symbol_Table_Local_add, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Table, find, find, arginfo_class_ion_Symbol_Table_Local_find, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Table, findLocal, findLocal, arginfo_class_ion_Symbol_Table_Local_findLocal, ZEND_ACC_PUBLIC)
        ZEND_FE_END
 };
 
 
-static const zend_function_entry class_ion_Collection_methods[] = {
+static const zend_function_entry class_ion_Symbol_Table_Shared_methods[] = {
+       ZEND_ME(ion_Symbol_Table_Shared, __construct, arginfo_class_ion_Symbol_Table_Shared___construct, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Table, getMaxId, getMaxId, arginfo_class_ion_Symbol_Table_Shared_getMaxId, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Table, add, add, arginfo_class_ion_Symbol_Table_Shared_add, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Table, find, find, arginfo_class_ion_Symbol_Table_Shared_find, ZEND_ACC_PUBLIC)
+       ZEND_MALIAS(ion_Symbol_Table, findLocal, findLocal, arginfo_class_ion_Symbol_Table_Shared_findLocal, ZEND_ACC_PUBLIC)
+       ZEND_FE_END
+};
+
+
+static const zend_function_entry class_ion_Catalog_methods[] = {
+       ZEND_ME(ion_Catalog, __construct, arginfo_class_ion_Catalog___construct, ZEND_ACC_PUBLIC)
+       ZEND_ME(ion_Catalog, count, arginfo_class_ion_Catalog_count, ZEND_ACC_PUBLIC)
+       ZEND_ME(ion_Catalog, add, arginfo_class_ion_Catalog_add, ZEND_ACC_PUBLIC)
+       ZEND_ME(ion_Catalog, remove, arginfo_class_ion_Catalog_remove, ZEND_ACC_PUBLIC)
+       ZEND_ME(ion_Catalog, find, arginfo_class_ion_Catalog_find, ZEND_ACC_PUBLIC)
+       ZEND_ME(ion_Catalog, findBest, arginfo_class_ion_Catalog_findBest, ZEND_ACC_PUBLIC)
        ZEND_FE_END
 };
 
@@ -957,63 +1084,6 @@ static zend_class_entry *register_class_ion_Type(void)
        return class_entry;
 }
 
-static zend_class_entry *register_class_ion_Annotation(void)
-{
-       zend_class_entry *class_entry = zend_register_internal_enum("ion\\Annotation", IS_STRING, class_ion_Annotation_methods);
-
-       zval enum_case_PHP_value;
-       zend_string *enum_case_PHP_value_str = zend_string_init("PHP", sizeof("PHP") - 1, 1);
-       ZVAL_STR(&enum_case_PHP_value, enum_case_PHP_value_str);
-       zend_enum_add_case_cstr(class_entry, "PHP", &enum_case_PHP_value);
-
-       zval enum_case_REFERENCE_value;
-       zend_string *enum_case_REFERENCE_value_str = zend_string_init("R", sizeof("R") - 1, 1);
-       ZVAL_STR(&enum_case_REFERENCE_value, enum_case_REFERENCE_value_str);
-       zend_enum_add_case_cstr(class_entry, "REFERENCE", &enum_case_REFERENCE_value);
-
-       zval enum_case_BACKREF_value;
-       zend_string *enum_case_BACKREF_value_str = zend_string_init("r", sizeof("r") - 1, 1);
-       ZVAL_STR(&enum_case_BACKREF_value, enum_case_BACKREF_value_str);
-       zend_enum_add_case_cstr(class_entry, "BACKREF", &enum_case_BACKREF_value);
-
-       zval enum_case_OBJECT_value;
-       zend_string *enum_case_OBJECT_value_str = zend_string_init("o", sizeof("o") - 1, 1);
-       ZVAL_STR(&enum_case_OBJECT_value, enum_case_OBJECT_value_str);
-       zend_enum_add_case_cstr(class_entry, "OBJECT", &enum_case_OBJECT_value);
-
-       zval enum_case_CLASS_OBJ_value;
-       zend_string *enum_case_CLASS_OBJ_value_str = zend_string_init("c", sizeof("c") - 1, 1);
-       ZVAL_STR(&enum_case_CLASS_OBJ_value, enum_case_CLASS_OBJ_value_str);
-       zend_enum_add_case_cstr(class_entry, "CLASS_OBJ", &enum_case_CLASS_OBJ_value);
-
-       zval enum_case_MAGIC_OBJ_value;
-       zend_string *enum_case_MAGIC_OBJ_value_str = zend_string_init("O", sizeof("O") - 1, 1);
-       ZVAL_STR(&enum_case_MAGIC_OBJ_value, enum_case_MAGIC_OBJ_value_str);
-       zend_enum_add_case_cstr(class_entry, "MAGIC_OBJ", &enum_case_MAGIC_OBJ_value);
-
-       zval enum_case_CUSTOM_OBJ_value;
-       zend_string *enum_case_CUSTOM_OBJ_value_str = zend_string_init("C", sizeof("C") - 1, 1);
-       ZVAL_STR(&enum_case_CUSTOM_OBJ_value, enum_case_CUSTOM_OBJ_value_str);
-       zend_enum_add_case_cstr(class_entry, "CUSTOM_OBJ", &enum_case_CUSTOM_OBJ_value);
-
-       zval enum_case_SERIALIZABLE_value;
-       zend_string *enum_case_SERIALIZABLE_value_str = zend_string_init("S", sizeof("S") - 1, 1);
-       ZVAL_STR(&enum_case_SERIALIZABLE_value, enum_case_SERIALIZABLE_value_str);
-       zend_enum_add_case_cstr(class_entry, "SERIALIZABLE", &enum_case_SERIALIZABLE_value);
-
-       zval enum_case_ENUM_value;
-       zend_string *enum_case_ENUM_value_str = zend_string_init("E", sizeof("E") - 1, 1);
-       ZVAL_STR(&enum_case_ENUM_value, enum_case_ENUM_value_str);
-       zend_enum_add_case_cstr(class_entry, "ENUM", &enum_case_ENUM_value);
-
-       zval enum_case_PROPERTY_value;
-       zend_string *enum_case_PROPERTY_value_str = zend_string_init("p", sizeof("p") - 1, 1);
-       ZVAL_STR(&enum_case_PROPERTY_value, enum_case_PROPERTY_value_str);
-       zend_enum_add_case_cstr(class_entry, "PROPERTY", &enum_case_PROPERTY_value);
-
-       return class_entry;
-}
-
 static zend_class_entry *register_class_ion_Symbol_ImportLocation(void)
 {
        zend_class_entry ce, *class_entry;
@@ -1036,9 +1106,20 @@ static zend_class_entry *register_class_ion_Symbol_ImportLocation(void)
        return class_entry;
 }
 
-static zend_class_entry *register_class_ion_Symbol_System(void)
+static zend_class_entry *register_class_ion_Symbol_Enum(void)
+{
+       zend_class_entry ce, *class_entry;
+
+       INIT_NS_CLASS_ENTRY(ce, "ion\\Symbol", "Enum", class_ion_Symbol_Enum_methods);
+       class_entry = zend_register_internal_interface(&ce);
+
+       return class_entry;
+}
+
+static zend_class_entry *register_class_ion_Symbol_Table_System(zend_class_entry *class_entry_ion_Symbol_Enum)
 {
-       zend_class_entry *class_entry = zend_register_internal_enum("ion\\Symbol\\System", IS_STRING, class_ion_Symbol_System_methods);
+       zend_class_entry *class_entry = zend_register_internal_enum("ion\\Symbol\\Table\\System", IS_STRING, class_ion_Symbol_Table_System_methods);
+       zend_class_implements(class_entry, 1, class_entry_ion_Symbol_Enum);
 
        zval enum_case_Ion_value;
        zend_string *enum_case_Ion_value_str = zend_string_init("$ion", sizeof("$ion") - 1, 1);
@@ -1088,45 +1169,60 @@ static zend_class_entry *register_class_ion_Symbol_System(void)
        return class_entry;
 }
 
-static zend_class_entry *register_class_ion_Symbol_System_SID(void)
+static zend_class_entry *register_class_ion_Symbol_Table_PHP(zend_class_entry *class_entry_ion_Symbol_Enum)
 {
-       zend_class_entry *class_entry = zend_register_internal_enum("ion\\Symbol\\System\\SID", IS_LONG, class_ion_Symbol_System_SID_methods);
-
-       zval enum_case_Ion_value;
-       ZVAL_LONG(&enum_case_Ion_value, 1);
-       zend_enum_add_case_cstr(class_entry, "Ion", &enum_case_Ion_value);
+       zend_class_entry *class_entry = zend_register_internal_enum("ion\\Symbol\\Table\\PHP", IS_STRING, class_ion_Symbol_Table_PHP_methods);
+       zend_class_implements(class_entry, 1, class_entry_ion_Symbol_Enum);
 
-       zval enum_case_Ivm_1_0_value;
-       ZVAL_LONG(&enum_case_Ivm_1_0_value, 2);
-       zend_enum_add_case_cstr(class_entry, "Ivm_1_0", &enum_case_Ivm_1_0_value);
-
-       zval enum_case_IonSymbolTable_value;
-       ZVAL_LONG(&enum_case_IonSymbolTable_value, 3);
-       zend_enum_add_case_cstr(class_entry, "IonSymbolTable", &enum_case_IonSymbolTable_value);
-
-       zval enum_case_Name_value;
-       ZVAL_LONG(&enum_case_Name_value, 4);
-       zend_enum_add_case_cstr(class_entry, "Name", &enum_case_Name_value);
-
-       zval enum_case_Version_value;
-       ZVAL_LONG(&enum_case_Version_value, 5);
-       zend_enum_add_case_cstr(class_entry, "Version", &enum_case_Version_value);
-
-       zval enum_case_Imports_value;
-       ZVAL_LONG(&enum_case_Imports_value, 6);
-       zend_enum_add_case_cstr(class_entry, "Imports", &enum_case_Imports_value);
-
-       zval enum_case_Symbols_value;
-       ZVAL_LONG(&enum_case_Symbols_value, 7);
-       zend_enum_add_case_cstr(class_entry, "Symbols", &enum_case_Symbols_value);
-
-       zval enum_case_MaxId_value;
-       ZVAL_LONG(&enum_case_MaxId_value, 8);
-       zend_enum_add_case_cstr(class_entry, "MaxId", &enum_case_MaxId_value);
+       zval enum_case_PHP_value;
+       zend_string *enum_case_PHP_value_str = zend_string_init("PHP", sizeof("PHP") - 1, 1);
+       ZVAL_STR(&enum_case_PHP_value, enum_case_PHP_value_str);
+       zend_enum_add_case_cstr(class_entry, "PHP", &enum_case_PHP_value);
 
-       zval enum_case_SharedSymbolTable_value;
-       ZVAL_LONG(&enum_case_SharedSymbolTable_value, 9);
-       zend_enum_add_case_cstr(class_entry, "SharedSymbolTable", &enum_case_SharedSymbolTable_value);
+       zval enum_case_Reference_value;
+       zend_string *enum_case_Reference_value_str = zend_string_init("R", sizeof("R") - 1, 1);
+       ZVAL_STR(&enum_case_Reference_value, enum_case_Reference_value_str);
+       zend_enum_add_case_cstr(class_entry, "Reference", &enum_case_Reference_value);
+
+       zval enum_case_Backref_value;
+       zend_string *enum_case_Backref_value_str = zend_string_init("r", sizeof("r") - 1, 1);
+       ZVAL_STR(&enum_case_Backref_value, enum_case_Backref_value_str);
+       zend_enum_add_case_cstr(class_entry, "Backref", &enum_case_Backref_value);
+
+       zval enum_case_Property_value;
+       zend_string *enum_case_Property_value_str = zend_string_init("p", sizeof("p") - 1, 1);
+       ZVAL_STR(&enum_case_Property_value, enum_case_Property_value_str);
+       zend_enum_add_case_cstr(class_entry, "Property", &enum_case_Property_value);
+
+       zval enum_case_Object_value;
+       zend_string *enum_case_Object_value_str = zend_string_init("o", sizeof("o") - 1, 1);
+       ZVAL_STR(&enum_case_Object_value, enum_case_Object_value_str);
+       zend_enum_add_case_cstr(class_entry, "Object", &enum_case_Object_value);
+
+       zval enum_case_ClassObject_value;
+       zend_string *enum_case_ClassObject_value_str = zend_string_init("c", sizeof("c") - 1, 1);
+       ZVAL_STR(&enum_case_ClassObject_value, enum_case_ClassObject_value_str);
+       zend_enum_add_case_cstr(class_entry, "ClassObject", &enum_case_ClassObject_value);
+
+       zval enum_case_MagicObject_value;
+       zend_string *enum_case_MagicObject_value_str = zend_string_init("O", sizeof("O") - 1, 1);
+       ZVAL_STR(&enum_case_MagicObject_value, enum_case_MagicObject_value_str);
+       zend_enum_add_case_cstr(class_entry, "MagicObject", &enum_case_MagicObject_value);
+
+       zval enum_case_CustomObject_value;
+       zend_string *enum_case_CustomObject_value_str = zend_string_init("C", sizeof("C") - 1, 1);
+       ZVAL_STR(&enum_case_CustomObject_value, enum_case_CustomObject_value_str);
+       zend_enum_add_case_cstr(class_entry, "CustomObject", &enum_case_CustomObject_value);
+
+       zval enum_case_Enum_value;
+       zend_string *enum_case_Enum_value_str = zend_string_init("E", sizeof("E") - 1, 1);
+       ZVAL_STR(&enum_case_Enum_value, enum_case_Enum_value_str);
+       zend_enum_add_case_cstr(class_entry, "Enum", &enum_case_Enum_value);
+
+       zval enum_case_Serializable_value;
+       zend_string *enum_case_Serializable_value_str = zend_string_init("S", sizeof("S") - 1, 1);
+       ZVAL_STR(&enum_case_Serializable_value, enum_case_Serializable_value_str);
+       zend_enum_add_case_cstr(class_entry, "Serializable", &enum_case_Serializable_value);
 
        return class_entry;
 }
@@ -1165,27 +1261,76 @@ static zend_class_entry *register_class_ion_Symbol_Table(void)
        zend_class_entry ce, *class_entry;
 
        INIT_NS_CLASS_ENTRY(ce, "ion\\Symbol", "Table", class_ion_Symbol_Table_methods);
+       class_entry = zend_register_internal_interface(&ce);
+
+       return class_entry;
+}
+
+static zend_class_entry *register_class_ion_Symbol_Table_Local(zend_class_entry *class_entry_ion_Symbol_Table)
+{
+       zend_class_entry ce, *class_entry;
+
+       INIT_NS_CLASS_ENTRY(ce, "ion\\Symbol\\Table", "Local", class_ion_Symbol_Table_Local_methods);
        class_entry = zend_register_internal_class_ex(&ce, NULL);
+       zend_class_implements(class_entry, 1, class_entry_ion_Symbol_Table);
+
+       zval property_imports_default_value;
+       ZVAL_EMPTY_ARRAY(&property_imports_default_value);
+       zend_string *property_imports_name = zend_string_init("imports", sizeof("imports") - 1, 1);
+       zend_declare_typed_property(class_entry, property_imports_name, &property_imports_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY));
+       zend_string_release(property_imports_name);
+
+       zval property_symbols_default_value;
+       ZVAL_EMPTY_ARRAY(&property_symbols_default_value);
+       zend_string *property_symbols_name = zend_string_init("symbols", sizeof("symbols") - 1, 1);
+       zend_declare_typed_property(class_entry, property_symbols_name, &property_symbols_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY));
+       zend_string_release(property_symbols_name);
 
        return class_entry;
 }
 
-static zend_class_entry *register_class_ion_Catalog(void)
+static zend_class_entry *register_class_ion_Symbol_Table_Shared(zend_class_entry *class_entry_ion_Symbol_Table)
 {
        zend_class_entry ce, *class_entry;
 
-       INIT_NS_CLASS_ENTRY(ce, "ion", "Catalog", class_ion_Catalog_methods);
+       INIT_NS_CLASS_ENTRY(ce, "ion\\Symbol\\Table", "Shared", class_ion_Symbol_Table_Shared_methods);
        class_entry = zend_register_internal_class_ex(&ce, NULL);
+       zend_class_implements(class_entry, 1, class_entry_ion_Symbol_Table);
+
+       zval property_symbols_default_value;
+       ZVAL_EMPTY_ARRAY(&property_symbols_default_value);
+       zend_string *property_symbols_name = zend_string_init("symbols", sizeof("symbols") - 1, 1);
+       zend_declare_typed_property(class_entry, property_symbols_name, &property_symbols_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY));
+       zend_string_release(property_symbols_name);
+
+       zval property_name_default_value;
+       ZVAL_UNDEF(&property_name_default_value);
+       zend_string *property_name_name = zend_string_init("name", sizeof("name") - 1, 1);
+       zend_declare_typed_property(class_entry, property_name_name, &property_name_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
+       zend_string_release(property_name_name);
+
+       zval property_version_default_value;
+       ZVAL_UNDEF(&property_version_default_value);
+       zend_string *property_version_name = zend_string_init("version", sizeof("version") - 1, 1);
+       zend_declare_typed_property(class_entry, property_version_name, &property_version_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
+       zend_string_release(property_version_name);
 
        return class_entry;
 }
 
-static zend_class_entry *register_class_ion_Collection(void)
+static zend_class_entry *register_class_ion_Catalog(zend_class_entry *class_entry_ion_Countable)
 {
        zend_class_entry ce, *class_entry;
 
-       INIT_NS_CLASS_ENTRY(ce, "ion", "Collection", class_ion_Collection_methods);
+       INIT_NS_CLASS_ENTRY(ce, "ion", "Catalog", class_ion_Catalog_methods);
        class_entry = zend_register_internal_class_ex(&ce, NULL);
+       zend_class_implements(class_entry, 1, class_entry_ion_Countable);
+
+       zval property_symbolTables_default_value;
+       ZVAL_EMPTY_ARRAY(&property_symbolTables_default_value);
+       zend_string *property_symbolTables_name = zend_string_init("symbolTables", sizeof("symbolTables") - 1, 1);
+       zend_declare_typed_property(class_entry, property_symbolTables_name, &property_symbolTables_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY));
+       zend_string_release(property_symbolTables_name);
 
        return class_entry;
 }
index 888a4938bc418b1015f9fedaa52d0e64705ca932..4146fde539ab69467c466efe25c8bf2e19642491 100644 (file)
     +--------------------------------------------------------------------+
 */
 
-#include "ionc/ion.h"
-
 #include "php.h"
 #include "ext/date/php_date.h"
 
+#define DECNUMDIGITS 34 /* DECQUAD_Pmax */
+#include "ionc/ion.h"
+
+#define PHP_ION_SYMBOL_TABLE_VERSION 1
+#define PHP_ION_SYMBOL(e, s) {0, {sizeof(e)-1, (BYTE *) e}, {sizeof(s)-1, (BYTE *) s}},
+
+typedef struct php_ion_global_symbol {
+       SID id;
+       ION_STRING e;
+       ION_STRING s;
+} php_ion_global_symbol;
+
+static php_ion_global_symbol g_sym_tab_php_sym[] = {
+       PHP_ION_SYMBOL("PHP", "PHP")
+       PHP_ION_SYMBOL("Reference", "R")
+       PHP_ION_SYMBOL("Backref", "r")
+       PHP_ION_SYMBOL("Property", "p")
+       PHP_ION_SYMBOL("ClassObject", "c")
+       PHP_ION_SYMBOL("CustomObject", "C")
+       PHP_ION_SYMBOL("Object", "o")
+       PHP_ION_SYMBOL("MagicObject", "O")
+       PHP_ION_SYMBOL("Serializable", "S")
+       PHP_ION_SYMBOL("Enum", "E")
+       {0}
+};
+#undef PHP_ION_SYMBOL
+
+static ION_SYMBOL_TABLE *g_sym_tab_php;
+
+/* [SID => STRING, STRING => SID] */
+static HashTable g_sym_hash;
+/* [enum_case_name => SID] */
+static HashTable g_sym_map;
+
+#define ION_SYS_SYMBOL_SYMBOL_TABLE \
+       ION_SYS_SYMBOL_ION_SYMBOL_TABLE
+#define g_sym_add(enum_name, c_name) do { \
+       g_sym_hash_add(ION_SYS_SID_ ## c_name, ION_SYS_SYMBOL_ ## c_name, ION_SYS_STRLEN_ ## c_name); \
+       g_sym_map_add(ION_SYS_SID_ ## c_name, enum_name, sizeof(enum_name)-1); \
+} while (0)
+
+static inline void g_sym_hash_add(int sid, const char *str, size_t len)
+{
+       zval zl, zs;
+       ZVAL_LONG(&zl, sid);
+       ZVAL_STR(&zs, zend_string_init_interned(str, len ,1));
+       zend_hash_add(&g_sym_hash, Z_STR(zs), &zl);
+       zend_hash_index_add(&g_sym_hash, sid, &zs);
+}
+
+static inline void g_sym_map_add(int sid, const char *str, size_t len)
+{
+       zval zv;
+       ZVAL_LONG(&zv, sid);
+       zend_hash_str_add(&g_sym_map, str, len, &zv);
+}
+
+static inline int g_sym_init(void)
+{
+       zend_hash_init(&g_sym_hash, 0, NULL, NULL, 1);
+       zend_hash_init(&g_sym_map, 0, NULL, NULL, 1);
+
+       g_sym_hash_add(0, ZEND_STRL(""));
+       g_sym_map_add(0, ZEND_STRL(""));
+       g_sym_add("Ion", ION);
+       g_sym_add("Ivm_1_0", IVM);
+       g_sym_add("IonSymbolTable", SYMBOL_TABLE);
+       g_sym_add("Name", NAME);
+       g_sym_add("Version", VERSION);
+       g_sym_add("Imports", IMPORTS);
+       g_sym_add("Symbols", SYMBOLS);
+       g_sym_add("MaxId", MAX_ID);
+       g_sym_add("SharedSymbolTable", SHARED_SYMBOL_TABLE);
+
+       int sys_max_id = ION_SYS_SID_SHARED_SYMBOL_TABLE;
+
+       if (IERR_OK != ion_symbol_table_open_with_type(&g_sym_tab_php, NULL, ist_SHARED)) {
+               return FAILURE;
+       }
+       php_ion_global_symbol *ptr = g_sym_tab_php_sym;
+       ion_symbol_table_set_version(g_sym_tab_php, PHP_ION_SYMBOL_TABLE_VERSION);
+       ion_symbol_table_set_name(g_sym_tab_php, &ptr->s);
+       while (ptr->e.value) {
+               ion_symbol_table_add_symbol(g_sym_tab_php, &ptr->s, &ptr->id);
+               g_sym_hash_add(sys_max_id + ptr->id, (const char *) ptr->s.value, ptr->s.length);
+               g_sym_map_add(sys_max_id + ptr->id, (const char *) ptr->e.value, ptr->e.length);
+               ++ptr;
+       }
+       ion_symbol_table_lock(g_sym_tab_php);
+       return SUCCESS;
+}
+
 typedef struct php_ion_serializer {
        ION_WRITER *writer;
        ION_WRITER_OPTIONS *options;
@@ -57,7 +147,15 @@ typedef struct php_ion_unserializer {
 
 ZEND_BEGIN_MODULE_GLOBALS(ion)
 
-       decContext decimal_ctx;
+       struct {
+               decContext ctx;
+               ION_DECIMAL zend_max;
+               ION_DECIMAL zend_min;
+       } decimal;
+
+       struct {
+               HashTable cache;
+       } symbol;
 
        php_ion_serializer serializer;
        php_ion_unserializer unserializer;
@@ -77,6 +175,54 @@ ZEND_END_MODULE_GLOBALS(ion);
 
 ZEND_DECLARE_MODULE_GLOBALS(ion);
 
+static zend_class_entry
+       *ce_Catalog,
+       *ce_Collection,
+       *ce_Decimal,
+       *ce_Decimal_Context,
+       *ce_Decimal_Context_Rounding,
+       *ce_LOB,
+       *ce_Reader,
+       *ce_Reader_Options,
+       *ce_Reader_Reader,
+       *ce_Reader_Buffer,
+       *ce_Reader_Stream,
+       *ce_Reader_Buffer_Reader,
+       *ce_Reader_Stream_Reader,
+       *ce_Serializer,
+       *ce_Serializer_PHP,
+       *ce_Symbol,
+       *ce_Symbol_ImportLocation,
+       *ce_Symbol_Enum,
+       *ce_Symbol_Table,
+       *ce_Symbol_Table_Local,
+       *ce_Symbol_Table_PHP,
+       *ce_Symbol_Table_Shared,
+       *ce_Symbol_Table_System,
+       *ce_Timestamp,
+       *ce_Timestamp_Precision,
+       *ce_Type,
+       *ce_Unserializer,
+       *ce_Unserializer_PHP,
+       *ce_Writer,
+       *ce_Writer_Options,
+       *ce_Writer_Buffer,
+       *ce_Writer_Buffer_Writer,
+       *ce_Writer_Stream,
+       *ce_Writer_Stream_Writer,
+       *ce_Writer_Writer
+       ;
+
+static inline void php_ion_globals_symbols_init(void)
+{
+       zend_hash_init(&php_ion_globals.symbol.cache, 0, NULL, ZVAL_PTR_DTOR, 0);
+}
+
+static inline void php_ion_globals_symbols_dtor(void)
+{
+       zend_hash_destroy(&php_ion_globals.symbol.cache);
+}
+
 static inline void php_ion_globals_serializer_init(void)
 {
        php_ion_serializer *s = &php_ion_globals.serializer;
@@ -168,42 +314,6 @@ static inline void php_ion_globals_unserializer_dtor(void)
        zend_hash_destroy(s->tmp);
 }
 
-static zend_class_entry
-       *ce_Annotation,
-       *ce_Catalog,
-       *ce_Collection,
-       *ce_Decimal,
-       *ce_Decimal_Context,
-       *ce_Decimal_Context_Rounding,
-       *ce_LOB,
-       *ce_Reader,
-       *ce_Reader_Options,
-       *ce_Reader_Reader,
-       *ce_Reader_Buffer,
-       *ce_Reader_Stream,
-       *ce_Reader_Buffer_Reader,
-       *ce_Reader_Stream_Reader,
-       *ce_Serializer,
-       *ce_Serializer_PHP,
-       *ce_Symbol,
-       *ce_Symbol_ImportLocation,
-       *ce_Symbol_System,
-       *ce_Symbol_System_SID,
-       *ce_Symbol_Table,
-       *ce_Timestamp,
-       *ce_Timestamp_Precision,
-       *ce_Type,
-       *ce_Unserializer,
-       *ce_Unserializer_PHP,
-       *ce_Writer,
-       *ce_Writer_Options,
-       *ce_Writer_Buffer,
-       *ce_Writer_Buffer_Writer,
-       *ce_Writer_Stream,
-       *ce_Writer_Stream_Writer,
-       *ce_Writer_Writer
-       ;
-
 #define php_ion_decl(type, cname, ...) \
        static zend_object_handlers oh_ ## cname; \
        static inline zend_object *create_ion_ ## cname(zend_class_entry *ce) \
@@ -233,15 +343,18 @@ static zend_class_entry
 #define php_ion_obj(type, obj) \
        ((php_ion_ ## type *) (obj ? ((char *)(obj) - XtOffsetOf(php_ion_ ## type, std)) : NULL))
 
-#define ION_CHECK(err, ...) do { \
+#define ION_CHECK_RETURN(r, err, ...) do { \
        iERR __err = err; \
        if (__err) { \
                zend_throw_exception_ex(spl_ce_RuntimeException, __err, "%s: %s", ion_error_to_str(__err), #err); \
                __VA_ARGS__; \
-               return; \
+               return r; \
        } \
 } while (0)
 
+#define ION_CHECK(err, ...) \
+       ION_CHECK_RETURN(, err, __VA_ARGS__)
+
 #define ION_CATCH(...) do { \
        if (EG(exception)) { \
                __VA_ARGS__; \
@@ -257,9 +370,9 @@ static zend_class_entry
        } \
 } while (0)
 
-#define OBJ_CHECK(obj) do { \
-       PTR_CHECK(obj); \
-       PTR_CHECK(*((void **)obj)); \
+#define OBJ_CHECK(obj, ...) do { \
+       PTR_CHECK(obj, __VA_ARGS__); \
+       PTR_CHECK(*((void **)obj), __VA_ARGS__); \
 } while (0)
 
 static inline ION_STRING *ion_string_from_zend(ION_STRING *is, const zend_string *zs)
@@ -409,10 +522,76 @@ static inline void php_ion_symbol_zval(ION_SYMBOL *sym_ptr, zval *return_value)
 php_ion_decl(symbol, Symbol, php_ion_symbol_dtor(obj));
 
 typedef struct php_ion_symbol_table {
+       ION_SYMBOL_TABLE *tab;
+       int (*dtor)(ION_SYMBOL_TABLE *);
        zend_object std;
 } php_ion_symbol_table;
 
-php_ion_decl(symbol_table, Symbol_Table);
+static inline 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);
+       }
+}
+
+static inline void php_ion_symbol_table_dtor(php_ion_symbol_table *obj)
+{
+       if (obj->tab) {
+               if (obj->dtor) {
+                       obj->dtor(obj->tab);
+               }
+               obj->tab = NULL;
+       }
+}
+
+static inline void php_ion_symbol_table_import(php_ion_symbol_table *obj, php_ion_symbol_table *import)
+{
+       OBJ_CHECK(obj);
+       OBJ_CHECK(import);
+
+       zval tmp;
+       zval *zimports = zend_read_property(obj->std.ce, &obj->std, ZEND_STRL("imports"), 0, &tmp);
+       if (zimports) {
+               zend_ulong idx = (uintptr_t) &import->std.gc;
+               if (!zend_hash_index_exists(Z_ARRVAL_P(zimports), idx)) {
+                       ION_CHECK(ion_symbol_table_import_symbol_table(obj->tab, import->tab));
+
+                       SEPARATE_ARRAY(zimports);
+                       GC_ADDREF(&import->std);
+                       add_index_object(zimports, idx, &import->std);
+                       zend_update_property(obj->std.ce, &obj->std, ZEND_STRL("imports"), zimports);
+               }
+       }
+}
+
+static inline void php_ion_symbol_table_symbol_zval(php_ion_symbol_table *obj, ION_SYMBOL *sym, zval *return_value)
+{
+       zval tmp;
+       zval *zsyms = zend_read_property(obj->std.ce, &obj->std, ZEND_STRL("symbols"), 0, &tmp);
+       if (zsyms) {
+               zval *zsym = zend_hash_index_find(Z_ARRVAL_P(zsyms), sym->sid);
+               if (zsym) {
+                       RETURN_COPY(zsym);
+               }
+       }
+
+       php_ion_symbol_zval(sym, return_value);
+
+       if (zsyms) {
+               SEPARATE_ARRAY(zsyms);
+               ZVAL_ADDREF(return_value);
+               add_index_zval(zsyms, sym->sid, return_value);
+       }
+}
+
+php_ion_decl(symbol_table, Symbol_Table, php_ion_symbol_table_dtor(obj));
 
 typedef struct php_ion_decimal_ctx {
        decContext ctx;
@@ -500,13 +679,13 @@ static inline bool php_ion_decimal_fits_zend_long(php_ion_decimal *obj)
                return false;
        }
 
-       result  = 1;
-       ion_decimal_compare(&obj->dec, &g_ion_dec_zend_max, &php_ion_globals.decimal_ctx, &result);
+       result = 1;
+       ion_decimal_compare(&obj->dec, &php_ion_globals.decimal.zend_max, &php_ion_globals.decimal.ctx, &result);
        if (result == 1) {
                return false;
        }
        result = -1;
-       ion_decimal_compare(&obj->dec, &g_ion_dec_zend_min, &php_ion_globals.decimal_ctx, &result);
+       ion_decimal_compare(&obj->dec, &php_ion_globals.decimal.zend_min, &php_ion_globals.decimal.ctx, &result);
        if (result == -1) {
                return false;
        }
@@ -547,7 +726,7 @@ typedef php_date_obj php_ion_timestamp;
 static inline zend_long php_usec_from_ion(const decQuad *frac, decContext *ctx)
 {
        if (!ctx) {
-               ctx = &php_ion_globals.decimal_ctx;
+               ctx = &php_ion_globals.decimal.ctx;
        }
        decQuad microsecs, result;
        decQuadMultiply(&result, decQuadFromInt32(&microsecs, 1000000), frac, ctx);
@@ -557,7 +736,7 @@ static inline zend_long php_usec_from_ion(const decQuad *frac, decContext *ctx)
 static inline decQuad *ion_ts_frac_from_usec(decQuad *frac, zend_long usec, decContext *ctx)
 {
        if (!ctx) {
-               ctx = &php_ion_globals.decimal_ctx;
+               ctx = &php_ion_globals.decimal.ctx;
        }
        decQuad microsecs, us;
        return decQuadDivide(frac, decQuadFromInt32(&us, usec), decQuadFromInt32(&microsecs, 1000000), ctx);
@@ -682,7 +861,94 @@ typedef struct php_ion_catalog {
        zend_object std;
 } php_ion_catalog;
 
-php_ion_decl(catalog, Catalog);
+static inline void php_ion_catalog_ctor(php_ion_catalog *obj)
+{
+       ION_CHECK(ion_catalog_open(&obj->cat));
+}
+
+static inline void php_ion_catalog_dtor(php_ion_catalog *obj)
+{
+       if (obj->cat) {
+               ion_catalog_close(obj->cat);
+       }
+}
+
+static inline zend_string *ion_symbol_table_to_key(ION_SYMBOL_TABLE *tab)
+{
+       int32_t version;
+       ION_STRING is;
+       ION_CHECK_RETURN(NULL, ion_symbol_table_get_name(tab, &is));
+       ION_CHECK_RETURN(NULL, ion_symbol_table_get_version(tab, &version));
+
+       smart_str s = {0};
+       smart_str_appendl(&s, (char *) is.value, is.length);
+       smart_str_appendc(&s, ':');
+       smart_str_append_long(&s, version);
+       smart_str_0(&s);
+
+       return s.s;
+}
+
+static inline void php_ion_catalog_add_symbol_table(php_ion_catalog *obj, php_ion_symbol_table *tab)
+{
+       OBJ_CHECK(obj);
+       OBJ_CHECK(tab);
+
+       zval tmp;
+       zval *ztabs = zend_read_property(obj->std.ce, &obj->std, ZEND_STRL("symbolTables"), 0, &tmp);
+       if (ztabs) {
+               zend_ulong idx = (uintptr_t) &tab->std.gc;
+               if (!zend_hash_index_exists(Z_ARRVAL_P(ztabs), idx)) {
+                       zend_string *key = ion_symbol_table_to_key(tab->tab);
+                       if (key) {
+                               ION_CHECK(ion_catalog_add_symbol_table(obj->cat, tab->tab),
+                                               zend_string_release(key));
+                               SEPARATE_ARRAY(ztabs);
+                               GC_ADDREF(&tab->std);
+                               add_index_object(ztabs, idx, &tab->std);
+                               GC_ADDREF(&tab->std);
+                               add_assoc_object_ex(ztabs, key->val, key->len, &tab->std);
+                               zend_update_property(obj->std.ce, &obj->std, ZEND_STRL("symbolTables"), ztabs);
+                               zend_string_release(key);
+                       }
+               }
+       }
+}
+
+static inline void php_ion_catalog_symbol_table_zval(php_ion_catalog *obj, ION_SYMBOL_TABLE *tab, zval *return_value)
+{
+       zend_string *key = ion_symbol_table_to_key(tab);
+       PTR_CHECK(key);
+
+       zval tmp;
+       zval *ztabs = zend_read_property(obj->std.ce, &obj->std, ZEND_STRL("symbolTables"), 0, &tmp);
+       if (ztabs) {
+               zval *ztab = zend_hash_find(Z_ARRVAL_P(ztabs), key);
+               if (ztab) {
+                       zend_string_release(key);
+                       RETURN_COPY(ztab);
+               } else {
+                       fprintf(stderr, "FAIL\n");
+               }
+       }
+
+       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));
+       php_ion_symbol_table_ctor(o_tab);
+
+       if (ztabs) {
+               SEPARATE_ARRAY(ztabs);
+               ZVAL_ADDREF(return_value);
+               add_index_zval(ztabs, (uintptr_t) &o_tab->std.gc, return_value);
+               ZVAL_ADDREF(return_value);
+               add_assoc_zval_ex(ztabs, key->val, key->len, return_value);
+       }
+}
+
+php_ion_decl(catalog, Catalog, php_ion_catalog_dtor(obj));
 
 typedef struct php_ion_reader_options {
        ION_READER_OPTIONS opt;
@@ -982,13 +1248,14 @@ static inline void php_ion_serializer_php_ctor(php_ion_serializer_php *ser_obj)
        } else {
                zend_update_property_null(ser_obj->std.ce, &ser_obj->std, ZEND_STRL("callCustomSerialize"));
        }
-       if (ser_obj->opt) {
-               php_ion_writer_options *o_woptions = php_ion_obj(writer_options, ser_obj->opt);
-               ser_obj->serializer.options = &o_woptions->opt;
-               update_property_obj(&ser_obj->std, ZEND_STRL("writerOptions"), ser_obj->opt);
+       if (!ser_obj->opt) {
+               ser_obj->opt = create_ion_Writer_Options(NULL);
        } else {
-               zend_update_property_null(ser_obj->std.ce, &ser_obj->std, ZEND_STRL("writerOptions"));
+               GC_ADDREF(ser_obj->opt);
        }
+       ser_obj->serializer.options = &php_ion_obj(writer_options, ser_obj->opt)->opt;
+       update_property_obj(&ser_obj->std, ZEND_STRL("writerOptions"), ser_obj->opt);
+       GC_DELREF(ser_obj->opt);
 }
 
 static inline void php_ion_serializer_php_dtor(php_ion_serializer_php *obj)
@@ -1019,13 +1286,18 @@ static inline void php_ion_serialize_struct(php_ion_serializer *ser, zend_array
                                prop_name = k->val;
                                prop_len = k->len;
                        }
-                       ION_CHECK(ion_writer_write_field_name(ser->writer, ion_string_assign_cstr(&is, (char *) prop_name, prop_len)));
+                       ion_string_assign_cstr(&is, (char *) prop_name, prop_len);
                } else {
                        char buf[MAX_LENGTH_OF_LONG + 1], *end = buf + sizeof(buf) - 1;
                        char *ptr = zend_print_long_to_buf(end, (zend_long) h);
-                       ION_CHECK(ion_writer_write_field_name(ser->writer, ion_string_assign_cstr(&is, ptr, end - ptr)));
+                       ion_string_assign_cstr(&is, ptr, end - ptr);
                }
 
+               // WATCH OUT: field names need to be copied
+               ION_STRING fn;
+               ION_CHECK(ion_string_copy_to_owner(ser->writer, &fn, &is));
+               ION_CHECK(ion_writer_write_field_name(ser->writer, &fn));
+
                php_ion_serialize_zval(ser, v);
                ION_CATCH();
        ZEND_HASH_FOREACH_END();
@@ -1376,13 +1648,14 @@ static inline void php_ion_unserializer_php_ctor(php_ion_unserializer_php *ser_o
        } else {
                zend_update_property_null(ser_obj->std.ce, &ser_obj->std, ZEND_STRL("callCustomSerialize"));
        }
-       if (ser_obj->opt) {
-               php_ion_reader_options *o_roptions = php_ion_obj(reader_options, ser_obj->opt);
-               ser_obj->unserializer.options = &o_roptions->opt;
-               update_property_obj(&ser_obj->std, ZEND_STRL("readerOptions"), ser_obj->opt);
+       if (!ser_obj->opt) {
+               ser_obj->opt = create_ion_Reader_Options(NULL);
        } else {
-               zend_update_property_null(ser_obj->std.ce, &ser_obj->std, ZEND_STRL("readerOptions"));
+               GC_ADDREF(ser_obj->opt);
        }
+       ser_obj->unserializer.options = &php_ion_obj(reader_options, ser_obj->opt)->opt;
+       update_property_obj(&ser_obj->std, ZEND_STRL("readerOptions"), ser_obj->opt);
+       GC_DELREF(ser_obj->opt);
 }
 
 static inline void php_ion_unserializer_php_dtor(php_ion_unserializer_php *obj)
@@ -2055,3 +2328,24 @@ void php_ion_unserialize(php_ion_unserializer *ser, zval *zdata, zval *return_va
                OBJ_RELEASE(zo_ser);
        }
 }
+
+static inline zval *php_ion_global_symbol_fetch_by_enum(zend_string *name)
+{
+       zval *zgs = zend_hash_find(&php_ion_globals.symbol.cache, name);
+       if (!zgs) {
+               zval *zid = zend_hash_find(&g_sym_map, name);
+               if (zid) {
+                       zval *zss = zend_hash_index_find(&g_sym_hash, Z_LVAL_P(zid));
+                       if (zss) {
+                               zval zsym;
+                               object_init_ex(&zsym, ce_Symbol);
+                               php_ion_symbol *sym = php_ion_obj(symbol, Z_OBJ(zsym));
+                               sym->sym.sid = Z_LVAL_P(zid);
+                               sym->value = zval_get_string(zss);
+                               php_ion_symbol_ctor(sym);
+                               zgs = zend_hash_add(&php_ion_globals.symbol.cache, name, &zsym);
+                       }
+               }
+       }
+       return zgs;
+}
diff --git a/tests/Symbol/Table.phpt b/tests/Symbol/Table.phpt
new file mode 100644 (file)
index 0000000..f35bb10
--- /dev/null
@@ -0,0 +1,160 @@
+--TEST--
+ion\Symbol\Table
+--EXTENSIONS--
+ion
+--FILE--
+TEST
+<?php
+
+echo "global\n";
+var_dump(ion\Symbol\Table\System());
+var_dump(ion\Symbol\Table\PHP());
+var_dump(ion\Symbol\Table\PHP()->find(1));
+
+echo "shared\n";
+$shared = new ion\Symbol\Table\Shared("shared");
+
+echo "add 3 syms\n";
+var_dump(
+       $shared->add("sym1"),
+       $shared->add("sym2"),
+       $sid3 = $shared->add($s3 = new ion\Symbol("sym3")),
+);
+
+echo "s3, sid3\n";
+var_dump($s3, $sid3);
+
+echo "find sym3, sid3\n";
+var_dump($shared->find("sym3"));
+var_dump($shared->find($sid3));
+
+echo "local\n";
+$local = new ion\Symbol\Table\Local;
+echo "import PHP\n";
+$local->import(ion\Symbol\Table\PHP());
+echo "import shared\n";
+$local->import($shared);
+
+echo "find sym1, local sym1\n";
+var_dump($local->find("sym1"));
+var_dump($local->findLocal("sym1"));
+
+echo "add, find, local sym4\n";
+var_dump($local->add("sym4"));
+var_dump($local->find("sym4"));
+var_dump($local->findLocal("sym4"));
+?>
+DONE
+--EXPECTF--
+TEST
+global
+object(ion\Symbol\Table\Shared)#%d (3) {
+  ["symbols":"ion\Symbol\Table\Shared":private]=>
+  array(0) {
+  }
+  ["name"]=>
+  string(4) "$ion"
+  ["version"]=>
+  int(1)
+}
+object(ion\Symbol\Table\Shared)#%d (3) {
+  ["symbols":"ion\Symbol\Table\Shared":private]=>
+  array(0) {
+  }
+  ["name"]=>
+  string(3) "PHP"
+  ["version"]=>
+  int(1)
+}
+object(ion\Symbol)#%d (3) {
+  ["value"]=>
+  string(3) "PHP"
+  ["sid"]=>
+  int(1)
+  ["importLocation"]=>
+  object(ion\Symbol\ImportLocation)#%d (2) {
+    ["name"]=>
+    string(3) "PHP"
+    ["location"]=>
+    int(1)
+  }
+}
+shared
+add 3 syms
+int(1)
+int(2)
+int(3)
+s3, sid3
+object(ion\Symbol)#%d (3) {
+  ["value"]=>
+  string(4) "sym3"
+  ["sid"]=>
+  int(-1)
+  ["importLocation"]=>
+  NULL
+}
+int(3)
+find sym3, sid3
+object(ion\Symbol)#%d (3) {
+  ["value"]=>
+  string(4) "sym3"
+  ["sid"]=>
+  int(3)
+  ["importLocation"]=>
+  object(ion\Symbol\ImportLocation)#%d (2) {
+    ["name"]=>
+    string(6) "shared"
+    ["location"]=>
+    int(3)
+  }
+}
+object(ion\Symbol)#%d (3) {
+  ["value"]=>
+  string(4) "sym3"
+  ["sid"]=>
+  int(3)
+  ["importLocation"]=>
+  object(ion\Symbol\ImportLocation)#%d (2) {
+    ["name"]=>
+    string(6) "shared"
+    ["location"]=>
+    int(3)
+  }
+}
+local
+import PHP
+import shared
+find sym1, local sym1
+object(ion\Symbol)#%d (3) {
+  ["value"]=>
+  string(4) "sym1"
+  ["sid"]=>
+  int(1)
+  ["importLocation"]=>
+  object(ion\Symbol\ImportLocation)#%d (2) {
+    ["name"]=>
+    string(6) "shared"
+    ["location"]=>
+    int(1)
+  }
+}
+NULL
+add, find, local sym4
+int(23)
+object(ion\Symbol)#%d (3) {
+  ["value"]=>
+  string(4) "sym4"
+  ["sid"]=>
+  int(23)
+  ["importLocation"]=>
+  NULL
+}
+object(ion\Symbol)#%d (3) {
+  ["value"]=>
+  string(4) "sym4"
+  ["sid"]=>
+  int(23)
+  ["importLocation"]=>
+  NULL
+}
+DONE