#include "ext/date/php_date.h"
#include "ext/spl/spl_exceptions.h"
-#include "ext/spl/spl_iterators.h"
#include "php_ion.h"
#include "ion_private.h"
Z_PARAM_LONG(location)
ZEND_PARSE_PARAMETERS_END();
- obj->loc.location = location;
+ obj->loc.location = (SID) location;
php_ion_symbol_iloc_ctor(obj);
}
static ZEND_METHOD(ion_Symbol, __construct)
Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->iloc, ce_Symbol_ImportLocation)
ZEND_PARSE_PARAMETERS_END();
- obj->sym.sid = sid;
+ obj->sym.sid = (SID) sid;
php_ion_symbol_ctor(obj);
}
static ZEND_METHOD(ion_Symbol, equals)
zend_string *zname;
zend_long version = 1;
- ZEND_PARSE_PARAMETERS_START(1, 2)
+ HashTable *ht_sym = NULL;
+ ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_STR(zname)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(version)
+ Z_PARAM_ARRAY_HT_OR_NULL(ht_sym)
ZEND_PARSE_PARAMETERS_END();
ION_CHECK(ion_symbol_table_open_with_type(&obj->tab, NULL, ist_SHARED));
ION_CHECK(ion_symbol_table_set_version(obj->tab, version));
php_ion_symbol_table_ctor(obj);
+
+ zval *zsym;
+ if (ht_sym) ZEND_HASH_FOREACH_VAL(ht_sym, zsym)
+ {
+ zend_string *str = zval_get_string(zsym);
+ if (EG(exception)) {
+ break;
+ }
+
+ ION_STRING istr;
+ ION_CHECK(ion_symbol_table_add_symbol(obj->tab, ion_string_from_zend(&istr, str), NULL), zend_string_release(str));
+ zend_string_release(str);
+ }
+ ZEND_HASH_FOREACH_END();
}
static ZEND_METHOD(ion_Symbol_Table, getMaxId)
{
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));
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));
+ RETVAL_BOOL(SUCCESS == zend_hash_index_del(Z_ARRVAL_P(ztabs), idx));
+ ION_CHECK(ion_catalog_release_symbol_table(obj->cat, php_ion_obj(symbol_table, zo_symtab)->tab));
} 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);
+ bool deleted = false;
+ ION_SYMBOL_TABLE *tab;
+ ION_STRING is;
+ ion_string_from_zend(&is, zs_symtab);
+ do {
+ tab = NULL;
+ ION_CHECK(ion_catalog_find_best_match(obj->cat, &is, 0, &tab));
+ if (tab) {
+ ION_CHECK(ion_catalog_release_symbol_table(obj->cat, tab));
+ deleted = true;
+ }
+ } while(tab);
+ RETVAL_BOOL(deleted);
}
}
}
if (o_round) {
round = Z_LVAL_P(zend_enum_fetch_case_value(o_round));
}
- php_ion_decimal_ctx_init(&obj->ctx, digits, emax, emin, round, clamp);
+ php_ion_decimal_ctx_init(&obj->ctx, digits, emax, emin, round, clamp); // NOLINT(cppcoreguidelines-narrowing-conversions)
php_ion_decimal_ctx_ctor(obj, o_round);
}
static inline void make_decimal_ctx(INTERNAL_FUNCTION_PARAMETERS, int kind)
{
php_ion_reader_options *opt = php_ion_obj(reader_options, Z_OBJ_P(ZEND_THIS));
zend_bool ret_sys_val = false, skip_validation = false;
- zend_long ch_nl = 0xa, max_depth = 10, max_ann, max_ann_buf = 512,
- sym_thr = 0x1000, uval_thr = 0x1000, chunk_thr = 0x1000, alloc_pgsz = 0x1000;
+ zend_long ch_nl = 0xa, max_depth = 10, max_ann = 10, max_ann_buf = 512,
+ sym_thr = 0x4000, uval_thr = 0x4000, chunk_thr = 0x4000, alloc_pgsz = 0x10000;
PTR_CHECK(opt);
Z_PARAM_LONG(max_ann)
// public readonly int $maxAnnotationBuffered = 512,
Z_PARAM_LONG(max_ann_buf)
- // public readonly int $symbolThreshold = 4096,
+ // public readonly int $symbolThreshold = 0x4000,
Z_PARAM_LONG(sym_thr)
- // public readonly int $userValueThreshold = 4096,
+ // public readonly int $userValueThreshold = 0x4000,
Z_PARAM_LONG(uval_thr)
- // public readonly int $chunkThreshold = 4096,
+ // public readonly int $chunkThreshold = 0x4000,
Z_PARAM_LONG(chunk_thr)
- // public readonly int $allocationPageSize = 4096,
+ // public readonly int $allocationPageSize = 0x10000,
Z_PARAM_LONG(alloc_pgsz)
// public readonly bool $skipCharacterValidation = false,
Z_PARAM_BOOL(skip_validation)
ZEND_PARSE_PARAMETERS_END();
- opt->opt.context_change_notifier = EMPTY_READER_CHANGE_NOTIFIER;
if (opt->cb) {
+ zval zcb;
+ ZVAL_OBJ(&zcb, opt->cb);
+ zend_fcall_info_init(&zcb, 0, &opt->ccn.fci, &opt->ccn.fcc, NULL, NULL);
+ opt->opt.context_change_notifier.context = &opt->ccn;
update_property_obj(&opt->std, ZEND_STRL("onContextChange"), opt->cb);
+ } else {
+ zend_update_property_null(NULL, &opt->std, ZEND_STRL("onContextChange"));
}
if (opt->cat) {
update_property_obj(&opt->std, ZEND_STRL("catalog"), opt->cat);
opt->opt.pcatalog = php_ion_obj(catalog, opt->cat)->cat;
+ } else {
+ zend_update_property_null(NULL, &opt->std, ZEND_STRL("catalog"));
}
if (opt->dec_ctx) {
update_property_obj(&opt->std, ZEND_STRL("decimalContext"), opt->dec_ctx);
opt->opt.decimal_context = &php_ion_obj(decimal_ctx, opt->dec_ctx)->ctx;
+ } else {
+ zend_update_property_null(NULL, &opt->std, ZEND_STRL("decimalContext"));
}
zend_update_property_bool(opt->std.ce, &opt->std, ZEND_STRL("returnSystemValues"),
opt->opt.return_system_values = ret_sys_val);
zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("newLine"),
- opt->opt.new_line_char = ch_nl);
+ opt->opt.new_line_char = (int) ch_nl);
zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("maxContainerDepth"),
- opt->opt.max_container_depth = max_depth);
- zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("maxAnnotationCount"),
- opt->opt.max_annotation_count = max_ann);
+ opt->opt.max_container_depth = (SIZE) max_depth);
+ zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("maxAnnotations"),
+ opt->opt.max_annotation_count = (SIZE) max_ann);
zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("maxAnnotationBuffered"),
- opt->opt.max_annotation_buffered = max_ann_buf);
+ opt->opt.max_annotation_buffered = (SIZE) max_ann_buf);
zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("symbolThreshold"),
- opt->opt.symbol_threshold = sym_thr);
+ opt->opt.symbol_threshold = (SIZE) sym_thr);
zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("userValueThreshold"),
- opt->opt.user_value_threshold = uval_thr);
+ opt->opt.user_value_threshold = (SIZE) uval_thr);
zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("chunkThreshold"),
- opt->opt.chunk_threshold = chunk_thr);
+ opt->opt.chunk_threshold = (SIZE) chunk_thr);
zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("allocationPageSize"),
- opt->opt.allocation_page_size = alloc_pgsz);
+ opt->opt.allocation_page_size = (SIZE) alloc_pgsz);
zend_update_property_long(opt->std.ce, &opt->std, ZEND_STRL("skipCharacterValidation"),
- opt->opt.skip_character_validation = skip_validation);
+ opt->opt.skip_character_validation = (SIZE) skip_validation);
}
static ZEND_METHOD(ion_Reader_Reader, hasChildren)
{
ION_TYPE typ;
ION_CHECK(ion_reader_read_null(obj->reader, &typ));
- RETURN_OBJ_COPY(php_ion_type_fetch(typ));
+ RETURN_IONTYPE(typ);
}
static ZEND_METHOD(ion_Reader_Reader, readBool)
{
zend_bool binary = false, compact_floats = false, escape = false, pretty = false,
tabs = true, small_cntr_inl = true, suppress_sys = false, flush = false;
- zend_long indent = 2, max_depth = 10, max_ann = 10, temp = 0x400, alloc = 0x1000;
+ zend_long indent = 2, max_depth = 10, max_ann = 10, temp = 0x4000, alloc = 0x10000;
ZEND_PARSE_PARAMETERS_START(0, 16)
Z_PARAM_OPTIONAL
//public readonly ?\ion\Catalog $catalog = null,
Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->cat, ce_Catalog)
- //public readonly ?\ion\Collection $encodingSymbolTable = null,
- Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->col, ce_Collection)
//public readonly ?\ion\Decimal\Context $decimalContext = null,
Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->dec_ctx, ce_Decimal_Context)
//public readonly bool $outputBinary = false,
Z_PARAM_LONG(max_depth)
//public readonly int $maxAnnotations = 10,
Z_PARAM_LONG(max_ann)
- //public readonly int $tempBufferSize = 0x400,
+ //public readonly int $tempBufferSize = 0x4000,
Z_PARAM_LONG(temp)
- //public readonly int $allocationPageSize = 0x1000,
+ //public readonly int $allocationPageSize = 0x10000,
Z_PARAM_LONG(alloc)
ZEND_PARSE_PARAMETERS_END();
if (obj->cat) {
update_property_obj(&obj->std, ZEND_STRL("catalog"), obj->cat);
obj->opt.pcatalog = php_ion_obj(catalog, obj->cat)->cat;
- }
- if (obj->col) {
- // TODO
+ } else {
+ zend_update_property_null(NULL, &obj->std, ZEND_STRL("catalog"));
}
if (obj->dec_ctx) {
update_property_obj(&obj->std, ZEND_STRL("decimalContext"), obj->dec_ctx);
obj->opt.decimal_context = &php_ion_obj(decimal_ctx, obj->dec_ctx)->ctx;
+ } else {
+ zend_update_property_null(NULL, &obj->std, ZEND_STRL("decimalContext"));
}
zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("outputBinary"),
obj->opt.output_as_binary = binary);
- zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("comactFloats"),
+ zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("compactFloats"),
obj->opt.compact_floats = compact_floats);
- zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("excapeNonAscii"),
+ zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("escapeNonAscii"),
obj->opt.escape_all_non_ascii = escape);
zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("prettyPrint"),
obj->opt.pretty_print = pretty);
zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("indentTabs"),
obj->opt.indent_with_tabs = tabs);
zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("indentSize"),
- obj->opt.indent_size = indent);
+ obj->opt.indent_size = (SIZE) indent);
zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("smallContainersInline"),
obj->opt.small_containers_in_line = small_cntr_inl);
zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("suppressSystemValues"),
zend_update_property_bool(obj->std.ce, &obj->std, ZEND_STRL("flushEveryValue"),
obj->opt.flush_every_value = flush);
zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("maxContainerDepth"),
- obj->opt.max_container_depth = max_depth);
+ obj->opt.max_container_depth = (SIZE) max_depth);
zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("maxAnnotations"),
- obj->opt.max_annotation_count = max_ann);
+ obj->opt.max_annotation_count = (SIZE) max_ann);
zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("tempBufferSize"),
- obj->opt.temp_buffer_size = temp);
+ obj->opt.temp_buffer_size = (SIZE) temp);
zend_update_property_long(obj->std.ce, &obj->std, ZEND_STRL("allocationPageSize"),
- obj->opt.allocation_page_size = alloc);
+ obj->opt.allocation_page_size = (SIZE) alloc);
}
static ZEND_METHOD(ion_Writer_Writer, writeNull)
{
Z_PARAM_OBJ_OF_CLASS(typ_obj, ce_Type)
ZEND_PARSE_PARAMETERS_END();
- php_ion_type *typ = php_ion_obj(type, typ_obj);
- OBJ_CHECK(typ);
- ION_CHECK(ion_writer_write_typed_null(obj->writer, php_ion_obj(type, typ)->typ));
+ ION_CHECK(ion_writer_write_typed_null(obj->writer, ion_type_from_enum(typ_obj)));
}
static ZEND_METHOD(ion_Writer_Writer, writeBool)
{
Z_PARAM_OBJ_OF_CLASS(typ_obj, ce_Type)
ZEND_PARSE_PARAMETERS_END();
- php_ion_type *typ = php_ion_obj(type, typ_obj);
- OBJ_CHECK(typ);
- ION_CHECK(ion_writer_start_lob(obj->writer, php_ion_obj(type, typ)->typ));
+ ION_CHECK(ion_writer_start_lob(obj->writer, ion_type_from_enum(typ_obj)));
}
static ZEND_METHOD(ion_Writer_Writer, appendLob)
{
Z_PARAM_OBJ_OF_CLASS(typ_obj, ce_Type)
ZEND_PARSE_PARAMETERS_END();
- php_ion_type *typ = php_ion_obj(type, typ_obj);
- OBJ_CHECK(typ);
- ION_CHECK(ion_writer_start_container(obj->writer, php_ion_obj(type, typ)->typ));
+ ION_CHECK(ion_writer_start_container(obj->writer, ion_type_from_enum(typ_obj)));
}
static ZEND_METHOD(ion_Writer_Writer, finishContainer)
{
for (unsigned i = 0; i < argc; ++i) {
switch (Z_TYPE(args[i])) {
- case IS_STRING:
+ case IS_STRING: ;
ION_STRING is;
ION_CHECK(ion_writer_add_annotation(obj->writer, ion_string_from_zend(&is, Z_STR(args[i]))));
break;
obj->serializer.call_magic = true;
- ZEND_PARSE_PARAMETERS_START(0, 3)
+ ZEND_PARSE_PARAMETERS_START(0, 4)
Z_PARAM_OPTIONAL
Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->opt, ce_Writer_Options)
Z_PARAM_BOOL(obj->serializer.multi_seq)
php_ion_serializer_php_ctor(obj);
}
-static ZEND_METHOD(ion_Serializer_PHP, __invoke)
+static ZEND_METHOD(ion_Serializer_PHP, serialize)
{
zend_object *obj = Z_OBJ_P(ZEND_THIS);
Z_PARAM_ZVAL(data)
ZEND_PARSE_PARAMETERS_END();
- if (obj->ce == ce_Serializer_PHP) {
- // default, fast path
- php_ion_serialize(&php_ion_obj(serializer_php, obj)->serializer, data, return_value);
- } else {
- zend_call_method_with_1_params(obj, obj->ce, NULL /* TODO */, "serialize", return_value, data);
- }
+ php_ion_serialize(&php_ion_obj(serializer_php, obj)->serializer, data, return_value);
}
static ZEND_FUNCTION(ion_serialize)
{
php_ion_serializer *ser = zo_ser ? &php_ion_obj(serializer_php, zo_ser)->serializer : NULL;
php_ion_serialize(ser, data, return_value);
} else {
- zend_call_method_with_1_params(zo_ser, NULL, NULL, "__invoke", return_value, data);
+ zend_call_method_with_1_params(zo_ser, NULL, NULL, "serialize", return_value, data);
}
}
-static ZEND_METHOD(ion_Serializer_PHP, serialize)
-{
- //zend_object *obj = Z_OBJ_P(ZEND_THIS);
-
- zval *data;
- ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_ZVAL(data)
- ZEND_PARSE_PARAMETERS_END();
-
- // TODO
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Not implemented");
-}
static ZEND_METHOD(ion_Unserializer_PHP, __construct)
{
obj->unserializer.call_magic = true;
- ZEND_PARSE_PARAMETERS_START(0, 3)
+ ZEND_PARSE_PARAMETERS_START(0, 4)
Z_PARAM_OPTIONAL
Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj->opt, ce_Reader_Options)
Z_PARAM_BOOL(obj->unserializer.multi_seq)
php_ion_unserializer_php_ctor(obj);
}
-static ZEND_METHOD(ion_Unserializer_PHP, __invoke)
+static ZEND_METHOD(ion_Unserializer_PHP, unserialize)
{
zend_object *obj = Z_OBJ_P(ZEND_THIS);
Z_PARAM_ZVAL(data)
ZEND_PARSE_PARAMETERS_END();
- if (obj->ce == ce_Unserializer_PHP) {
- php_ion_unserialize(&php_ion_obj(unserializer_php, obj)->unserializer, data, return_value);
- } else {
- zend_call_method_with_1_params(obj, obj->ce, NULL /* TODO */, "unserialize", return_value, data);
- }
+ php_ion_unserialize(&php_ion_obj(unserializer_php, obj)->unserializer, data, return_value);
}
static ZEND_FUNCTION(ion_unserialize)
{
zend_call_method_with_1_params(zo_ser, NULL, NULL, "__invoke", return_value, data);
}
}
-static ZEND_METHOD(ion_Unserializer_PHP, unserialize)
-{
- //zend_object *obj = Z_OBJ_P(ZEND_THIS);
-
- zval *data;
- ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_ZVAL(data)
- ZEND_PARSE_PARAMETERS_END();
-
- // TODO
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Not implemented");
-}
PHP_RINIT_FUNCTION(ion)
{
}
#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 },
+ { #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"
+// spl_iterators.h includes ext/pcre/php_pcre.h which might not find pcre2.h
+extern PHPAPI zend_class_entry *spl_ce_RecursiveIterator;
+
PHP_MINIT_FUNCTION(ion)
{
// true globals
ce_Timestamp_Precision = register_class_ion_Timestamp_Precision();
// Type
- php_ion_register(type, Type);
+ ce_Type = register_class_ion_Type();
// Writer
ce_Writer = register_class_ion_Writer();