/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 943d369644718978b3b990f4345d51bed5f71366 */
+ * Stub hash: 8f4964120dccb00c053325183fda763f64f08b6e */
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_ion_Symbol_Table_PHP, 0, 0, ion\\Symbol\\Table, 0)
ZEND_END_ARG_INFO()
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_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, symbols, IS_ARRAY, 1, "null")
ZEND_END_ARG_INFO()
#define arginfo_class_ion_Symbol_Table_Shared_getMaxId arginfo_class_ion_Symbol_Enum_toSID
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_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);
+ 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;
}
#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}},
+#define PHP_ION_SYMBOL(c, s) { \
+ { \
+ 0, \
+ { sizeof(s)-1, (BYTE *) s }, \
+ { { 0, NULL }, 0 }, \
+ 0 \
+ }, \
+ { sizeof(c)-1, (BYTE *) c } \
+},
typedef struct php_ion_global_symbol {
- SID id;
+ ION_SYMBOL s;
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")
+#define PHP_ION_SYMBOL_PHP (g_sym_tab_php_sym[0]).s
+ PHP_ION_SYMBOL("PHP", "PHP")
+#define PHP_ION_SYMBOL_REFERENCE (g_sym_tab_php_sym[1]).s
+ PHP_ION_SYMBOL("Reference", "R")
+#define PHP_ION_SYMBOL_BACKREF (g_sym_tab_php_sym[2]).s
+ PHP_ION_SYMBOL("Backref", "r")
+#define PHP_ION_SYMBOL_PROPERTY (g_sym_tab_php_sym[3]).s
+ PHP_ION_SYMBOL("Property", "p")
+#define PHP_ION_SYMBOL_CLASS_OBJECT (g_sym_tab_php_sym[4]).s
+ PHP_ION_SYMBOL("ClassObject", "c")
+#define PHP_ION_SYMBOL_CUSTOM_OBJECT (g_sym_tab_php_sym[5]).s
+ PHP_ION_SYMBOL("CustomObject", "C")
+#define PHP_ION_SYMBOL_OBJECT (g_sym_tab_php_sym[6]).s
+ PHP_ION_SYMBOL("Object", "o")
+#define PHP_ION_SYMBOL_MAGIC_OBJECT (g_sym_tab_php_sym[7]).s
+ PHP_ION_SYMBOL("MagicObject", "O")
+#define PHP_ION_SYMBOL_SERIALIZEABLE (g_sym_tab_php_sym[8]).s
+ PHP_ION_SYMBOL("Serializable", "S")
+#define PHP_ION_SYMBOL_ENUM (g_sym_tab_php_sym[9]).s
PHP_ION_SYMBOL("Enum", "E")
- {0}
+ {{0}, {0}}
};
#undef PHP_ION_SYMBOL
}
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);
+ ion_symbol_table_set_name(g_sym_tab_php, &ptr->s.value);
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);
+ ion_symbol_table_add_symbol(g_sym_tab_php, &ptr->s.value, &ptr->s.sid);
+ g_sym_hash_add(sys_max_id + ptr->s.sid, (const char *) ptr->s.value.value, ptr->s.value.length);
+ g_sym_map_add(sys_max_id + ptr->s.sid, (const char *) ptr->e.value, ptr->e.length);
++ptr;
}
ion_symbol_table_lock(g_sym_tab_php);
} php_ion_serializer;
typedef struct php_ion_annotaions {
+ uint8_t shared_symtab:1;
uint8_t backref:1;
uint8_t makeref:1;
uint8_t object_prop:1;
}
}
+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;
+}
+
php_ion_decl(symbol, Symbol, php_ion_symbol_dtor(obj));
typedef struct php_ion_symbol_table {
if (ztab) {
zend_string_release(key);
RETURN_COPY(ztab);
- } else {
- fprintf(stderr, "FAIL\n");
}
}
php_ion_reader *obj = php_ion_obj(reader, context);
(void) obj;
}
+ fprintf(stderr, "%s\n", __FUNCTION__);
return IERR_OK;
}
static inline void php_ion_serialize_zval(php_ion_serializer *, zval *);
-static inline void php_ion_serialize_struct(php_ion_serializer *ser, zend_array *arr, bool props)
+static inline void php_ion_serialize_struct(php_ion_serializer *ser, zend_array *arr, bool unmangle_props, bool annotate_props)
{
ION_CHECK(ion_writer_start_container(ser->writer, tid_STRUCT));
zend_ulong h;
zend_string *k = NULL;
if (arr) ZEND_HASH_FOREACH_KEY_VAL_IND(arr, h, k, v)
+ char buf[MAX_LENGTH_OF_LONG + 1];
ION_STRING is;
if (k) {
size_t prop_len;
const char *class_name, *prop_name;
- if (props && (SUCCESS == zend_unmangle_property_name_ex(k, &class_name, &prop_name, &prop_len)) && class_name) {
- ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_assign_cstr(&is, ZEND_STRL("p"))));
- ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_assign_cstr(&is, (char *) class_name, prop_name - class_name - 1)));
+ if (unmangle_props && (SUCCESS == zend_unmangle_property_name_ex(k, &class_name, &prop_name, &prop_len)) && class_name) {
+ if (annotate_props) {
+ ION_CHECK(ion_writer_add_annotation_symbol(ser->writer, &PHP_ION_SYMBOL_PROPERTY));
+ ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_assign_cstr(&is, (char *) class_name, prop_name - class_name - 1)));
+ }
} else {
prop_name = k->val;
prop_len = k->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 *end = buf + sizeof(buf) - 1;
char *ptr = zend_print_long_to_buf(end, (zend_long) h);
ion_string_assign_cstr(&is, ptr, end - ptr);
}
if (zend_array_is_list(arr)) {
php_ion_serialize_list(ser, arr);
} else {
- php_ion_serialize_struct(ser, arr, false);
+ php_ion_serialize_struct(ser, arr, false, false);
}
}
ZVAL_OBJ(&tmp, zobject);
if (SUCCESS == zobject->ce->serialize(&tmp, &buf, &len, NULL)) {
ION_STRING is;
- ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_assign_cstr(&is, ZEND_STRL("S"))));
+ ION_CHECK(ion_writer_add_annotation_symbol(ser->writer, &PHP_ION_SYMBOL_SERIALIZEABLE));
ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_from_zend(&is, zobject->ce->name)));
ION_CHECK(ion_writer_write_string(ser->writer, ion_string_assign_cstr(&is, (char *) buf, len)));
efree(buf);
if (IS_ARRAY == Z_TYPE(rv)) {
ION_STRING is;
- ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_assign_cstr(&is, fn ? "C" : "O", 1)));
+ ION_CHECK(ion_writer_add_annotation_symbol(ser->writer, fn ? &PHP_ION_SYMBOL_CUSTOM_OBJECT : &PHP_ION_SYMBOL_MAGIC_OBJECT));
ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_from_zend(&is, zobject->ce->name)));
php_ion_serialize_zval(ser, &rv);
zval_ptr_dtor(&rv);
static inline void php_ion_serialize_object_enum(php_ion_serializer *ser, zend_object *zobject)
{
ION_STRING is;
- ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_assign_cstr(&is, ZEND_STRL("E"))));
+ ION_CHECK(ion_writer_add_annotation_symbol(ser->writer, &PHP_ION_SYMBOL_ENUM));
ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_from_zend(&is, zobject->ce->name)));
zval *z_cname = zend_enum_fetch_case_name(zobject);
ION_STRING is;
if (zobject->ce != zend_standard_class_def) {
- ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_assign_cstr(&is, ZEND_STRL("c"))));
+ ION_CHECK(ion_writer_add_annotation_symbol(ser->writer, &PHP_ION_SYMBOL_CLASS_OBJECT));
ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_from_zend(&is, zobject->ce->name)));
} else {
- ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_assign_cstr(&is, ZEND_STRL("o"))));
+ ION_CHECK(ion_writer_add_annotation_symbol(ser->writer, &PHP_ION_SYMBOL_OBJECT));
}
zval zobj;
ZVAL_OBJ(&zobj, zobject);
HashTable *props = zend_get_properties_for(&zobj, ZEND_PROP_PURPOSE_SERIALIZE);
if (props) {
- php_ion_serialize_struct(ser, props, true);
+ php_ion_serialize_struct(ser, props, true, true);
zend_release_properties(props);
} else {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, IERR_INTERNAL_ERROR,
}
}
+static inline bool php_ion_serialize_system_value(php_ion_serializer *ser, zval *zv)
+{
+ if (1 == php_ion_globals.serializer.level) {
+ if (Z_TYPE_P(zv) == IS_OBJECT) {
+ if (Z_OBJCE_P(zv) == ce_Symbol_Table_Shared) {
+ php_ion_symbol_table *obj = php_ion_obj(symbol_table, Z_OBJ_P(zv));
+ ION_CHECK_RETURN(true, ion_symbol_table_unload(obj->tab, ser->writer));
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
static inline void php_ion_serialize_refcounted(php_ion_serializer *ser, zval *zv)
{
+ if (php_ion_serialize_system_value(ser, zv)) {
+ return;
+ }
+
zend_ulong idx = (zend_ulong) (uintptr_t) Z_COUNTED_P(zv);
ION_STRING is;
if (zend_hash_index_exists(ser->ids, idx)) {
zval *num = zend_hash_index_find(ser->ids, idx);
- ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_assign_cstr(&is, ZEND_STRL("r"))));
+ ION_CHECK(ion_writer_add_annotation_symbol(ser->writer, &PHP_ION_SYMBOL_BACKREF));
ION_CHECK(ion_writer_write_int64(ser->writer, Z_LVAL_P(num)));
} else {
zval num;
break;
case IS_REFERENCE:
- ION_CHECK(ion_writer_add_annotation(ser->writer, ion_string_assign_cstr(&is, ZEND_STRL("R"))));
+ ION_CHECK(ion_writer_add_annotation_symbol(ser->writer, &PHP_ION_SYMBOL_REFERENCE));
php_ion_serialize_zval(ser, Z_REFVAL_P(zv));
break;
}
php_ion_unserialize_object(ser, return_value);
}
} else if (!ser->annotations.object_type) {
+ bool is_shared_symtab = ser->annotations.shared_symtab;
array_init(return_value);
php_ion_unserialize_hash(ser, return_value);
+ if (is_shared_symtab) {
+ zval zobj;
+ object_init_ex(&zobj, ce_Symbol_Table_Shared);
+ zend_call_known_function(Z_OBJCE(zobj)->constructor, Z_OBJ(zobj), Z_OBJCE(zobj), NULL, 0, NULL, Z_ARRVAL_P(return_value));
+ zval_ptr_dtor(return_value);
+ RETURN_COPY_VALUE(&zobj);
+ }
} else if (ser->annotations.object_type == 'o') {
object_init(return_value);
php_ion_unserialize_hash(ser, return_value);
ION_CHECK(ion_reader_get_an_annotation(ser->reader, i, &ann_str));
if (ann_str.length != 1) {
+ if (ann_str.length == ION_SYS_STRLEN_SHARED_SYMBOL_TABLE) {
+ if (!memcmp(ann_str.value, ION_SYMBOL_SHARED_SYMBOL_TABLE_BYTES, ION_SYS_STRLEN_SHARED_SYMBOL_TABLE)) {
+ ser->annotations.shared_symtab = true;
+ }
+ }
continue;
}
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;
-}