Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# v1.7.7-alpha1
# v1.8.0-alpha2

* Added `TI_PROTO_CLIENT_REQ_EMIT_PEER` protocol, pr #414.
* Changed `copy()` behavior of wrapped type, pr #415.
* Changed `copy()` behavior for wrapped type, pr #415.
* Fixed missing wrap-prefix flags after renaming type, issue #416.
* Allow defining nested structure in wrap type, pr #417.

# v1.7.6

Expand Down
1 change: 1 addition & 0 deletions inc/ti/condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int ti_condition_field_rel_init(
ti_field_t * ofield,
ex_t * e);
int ti_condition_init_enum(ti_field_t * field, ti_member_t * member, ex_t * e);
int ti_condition_init_type(ti_field_t * field, ex_t * e);

void ti_condition_destroy(ti_condition_via_t condition, uint16_t spec);

Expand Down
18 changes: 10 additions & 8 deletions inc/ti/condition.t.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ typedef struct ti_condition_irange_s ti_condition_irange_t;
typedef struct ti_condition_drange_s ti_condition_drange_t;
typedef struct ti_condition_rel_s ti_condition_rel_t;

#include <stdint.h>
#include <stdlib.h>
#include <ti/field.t.h>
#include <ti/raw.t.h>
#include <ti/regex.h>
#include <ti/thing.t.h>
#include <ti/type.t.h>
#include <ti/val.t.h>

union ti_condition_via_u
{
ti_type_t * type; /* nested type (wrap-only) */
ti_condition_re_t * re; /* str, utf8 */
ti_condition_srange_t * srange; /* str, utf8 */
ti_condition_irange_t * irange; /* int, float */
Expand All @@ -22,14 +32,6 @@ union ti_condition_via_u
ti_condition_t * none; /* NULL */
};

#include <stdint.h>
#include <stdlib.h>
#include <ti/raw.t.h>
#include <ti/regex.h>
#include <ti/val.t.h>
#include <ti/field.t.h>
#include <ti/thing.t.h>

typedef void (*ti_condition_rel_cb) (ti_field_t *, ti_thing_t *, ti_thing_t *);

struct ti_condition_s
Expand Down
28 changes: 18 additions & 10 deletions inc/ti/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int ti_field_make_assignable(
ex_t * e);
_Bool ti_field_maps_to_val(ti_field_t * field, ti_val_t * val);
_Bool ti_field_maps_to_field(ti_field_t * t_field, ti_field_t * f_field);
ti_raw_t * ti_field_nested_to_mpdata(ti_field_t * field);
ti_field_t * ti_field_by_strn_e(
ti_type_t * type,
const char * str,
Expand Down Expand Up @@ -83,24 +84,31 @@ static inline _Bool ti_field_has_relation(ti_field_t * field)
* is a non-nillable set or a nillable type.
*/
return field->condition.none && (
field->spec == TI_SPEC_SET ||
(field->spec & TI_SPEC_MASK_NILLABLE) < TI_SPEC_ANY);
field->spec == TI_SPEC_SET ||
(field->spec & TI_SPEC_MASK_NILLABLE) < TI_SPEC_ANY);
}

static inline uint8_t ti_field_deep(ti_field_t * field, uint8_t deep)
{
return (
(field->flags & TI_FIELD_FLAG_DEEP)
? deep
: (field->flags & TI_FIELD_FLAG_MAX_DEEP)
? TI_MAX_DEEP-1
: 0
) + (field->flags & TI_FIELD_FLAG_SAME_DEEP);
return (
(field->flags & TI_FIELD_FLAG_DEEP)
? deep
: (field->flags & TI_FIELD_FLAG_MAX_DEEP)
? TI_MAX_DEEP-1
: 0
) + (field->flags & TI_FIELD_FLAG_SAME_DEEP);
}

static inline int ti_field_ret_flags(ti_field_t * field)
{
return field->flags & TI_FIELD_FLAG_NO_IDS;
return field->flags & TI_FIELD_FLAG_NO_IDS;
}

static inline _Bool ti_field_is_nested(ti_field_t * field)
{
return (
(field->spec & TI_SPEC_MASK_NILLABLE) == TI_SPEC_TYPE ||
(field->spec & TI_SPEC_MASK_NILLABLE) == TI_SPEC_ARR_TYPE);
}


Expand Down
2 changes: 1 addition & 1 deletion inc/ti/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef struct ti_fmt_s ti_fmt_t;
#include <ti/raw.t.h>

/* When 0, use TAB, else the number of spaces */
#define TI_FMT_SPACES 0
#define TI_FMT_TAB 0

struct ti_fmt_s
{
Expand Down
1 change: 1 addition & 0 deletions inc/ti/fn/fnjsondump.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static int do__f_json_dump(ti_query_t * query, cleri_node_t * nd, ex_t * e)
size_t total_n;
ti_vp_t vp = {
.query=query,
.size_limit=ti.cfg->result_size_limit,
};
json_dumps__options_t options = {
.deep = query->qbind.deep,
Expand Down
99 changes: 57 additions & 42 deletions inc/ti/fn/fnmodtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,56 +409,66 @@ static void type__add(

return;
}
else if (!ti_val_is_str(query->rval))
{
ex_set(e, EX_TYPE_ERROR,
"function `%s` expects argument 4 to be of "
"type `"TI_VAL_STR_S"` or type `"TI_VAL_CLOSURE_S"` "
"but got type `%s` instead"DOC_MOD_TYPE_ADD,
fnname, ti_val_str(query->rval));

spec_raw = ti_type_nested_from_val(type, query->rval, e);
if (e->nr)
return;
}

spec_raw = (ti_raw_t *) query->rval;
if (spec_raw->n == 1 && spec_raw->data[0] == '#')
if (spec_raw)
ti_val_unsafe_gc_drop(query->rval);
else
{
if (nargs == 5)
if (!ti_val_is_str(query->rval))
{
ex_set(e, EX_NUM_ARGUMENTS,
"function `%s` takes at most 4 arguments when adding "
"an Id ('#') definition"DOC_MOD_TYPE_ADD,
fnname);
ex_set(e, EX_TYPE_ERROR,
"function `%s` expects argument 4 to be of "
"type `"TI_VAL_STR_S"` or type `"TI_VAL_CLOSURE_S"` "
"but got type `%s` instead"DOC_MOD_TYPE_ADD,
fnname, ti_val_str(query->rval));
return;
}
spec_raw = (ti_raw_t *) query->rval;

if (type->idname)
if (spec_raw->n == 1 && spec_raw->data[0] == '#')
{
ex_set(e, EX_LOOKUP_ERROR,
"multiple Id ('#') definitions on type `%s`",
type->name);
return;
}
if (nargs == 5)
{
ex_set(e, EX_NUM_ARGUMENTS,
"function `%s` takes at most 4 arguments when adding "
"an Id ('#') definition"DOC_MOD_TYPE_ADD,
fnname);
return;
}

task = ti_task_get_task(query->change, query->collection->root);
if (!task)
{
ex_set_mem(e);
return;
}
if (type->idname)
{
ex_set(e, EX_LOOKUP_ERROR,
"multiple Id ('#') definitions on type `%s`",
type->name);
return;
}

task = ti_task_get_task(query->change, query->collection->root);
if (!task)
{
ex_set_mem(e);
return;
}

/* update modified time-stamp */
type->modified_at = util_now_usec();
type->idname = name;
ti_incref(name);
/* update modified time-stamp */
type->modified_at = util_now_usec();
type->idname = name;
ti_incref(name);

if (ti_task_add_mod_type_add_idname(task, type))
{
/* modified is wrong; the rest we can revert */
type->idname = NULL;
ti_decref(name);
ex_set_mem(e);
if (ti_task_add_mod_type_add_idname(task, type))
{
/* modified is wrong; the rest we can revert */
type->idname = NULL;
ti_decref(name);
ex_set_mem(e);
}
return;
}
return;
}

query->rval = NULL;
Expand Down Expand Up @@ -857,7 +867,7 @@ static void type__mod(
const int nargs = fn_get_nargs(nd);
ti_field_t * field = ti_field_by_name(type, name);
ti_method_t * method = field ? NULL : ti_type_get_method(type, name);

ti_raw_t * spec_raw = NULL;
cleri_node_t * child;

if (fn_nargs_range(fnname, DOC_MOD_TYPE_MOD, 4, 5, nargs, e))
Expand Down Expand Up @@ -935,10 +945,12 @@ static void type__mod(
return;
}

spec_raw = ti_type_nested_from_val(type, query->rval, e);
if (e->nr)
return;

if (ti_val_is_str(query->rval))
{
ti_raw_t * spec_raw;

if (!field)
{
ex_set(e, EX_TYPE_ERROR,
Expand All @@ -956,7 +968,10 @@ static void type__mod(
}

query->rval = NULL;
}

if (spec_raw)
{
if (nargs == 4)
{
ti_task_t * task;
Expand Down Expand Up @@ -1453,7 +1468,7 @@ static void type__wpo(
if (wrap_only && ti_type_required_by_non_wpo(type, e))
return;

if (!wrap_only && ti_type_uses_wpo(type, e))
if (!wrap_only && ti_type_requires_wpo(type, e))
return;

task = ti_task_get_task(query->change, query->collection->root);
Expand Down
2 changes: 1 addition & 1 deletion inc/ti/fn/fnsettype.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int do__f_set_type(ti_query_t * query, cleri_node_t * nd, ex_t * e)
type = ti_type_create(
query->collection->types,
type_id,
TI_TYPE_FLAG_WRAP_ONLY, /* prevents looking for instances */
TI_TYPE_FLAG_WRAP_ONLY,
(const char *) rname->data,
rname->n,
ts_now,
Expand Down
5 changes: 5 additions & 0 deletions inc/ti/raw.inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ static inline _Bool ti_raw_is_name(ti_raw_t * raw)
return raw->tp == TI_VAL_NAME;
}

static inline _Bool ti_raw_is_mpdata(ti_raw_t * raw)
{
return raw->tp == TI_VAL_MPDATA;
}

static inline _Bool ti_raw_is_reserved_key(ti_raw_t * raw)
{
return raw->n == 1 && (*raw->data >> 4 == 2);
Expand Down
2 changes: 2 additions & 0 deletions inc/ti/spec.t.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ typedef enum
TI_SPEC_FLOAT_RANGE, /* `float<:> */
TI_SPEC_STR_RANGE, /* `str<:> */
TI_SPEC_UTF8_RANGE, /* `utf8<:> */
TI_SPEC_TYPE, /* `{...} */
TI_SPEC_ARR_TYPE, /* `[{...}] */
} ti_spec_enum_t;

typedef enum
Expand Down
49 changes: 9 additions & 40 deletions inc/ti/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#include <inttypes.h>
#include <ti/change.t.h>
#include <ti/closure.t.h>
#include <ti/map.h>
#include <ti/method.t.h>
#include <ti/name.t.h>
#include <ti/map.h>
#include <ti/raw.t.h>
#include <ti/thing.t.h>
#include <ti/type.t.h>
#include <ti/types.t.h>
Expand All @@ -26,7 +27,12 @@ ti_type_t * ti_type_create(
size_t name_n,
uint64_t created_at,
uint64_t modified_at);
ti_type_t * ti_type_create_unnamed(
ti_types_t * types,
ti_raw_t * name,
uint8_t flags);
void ti_type_drop(ti_type_t * type);
void ti_type_drop_unnamed(ti_type_t * type);
void ti_type_del(ti_type_t * type, vec_t * vars);
void ti_type_destroy(ti_type_t * type);
void ti_type_map_cleanup(ti_type_t * type);
Expand Down Expand Up @@ -67,8 +73,9 @@ int ti_type_methods_info_to_pk(
msgpack_packer * pk,
_Bool with_definition);
int ti_type_required_by_non_wpo(ti_type_t * type, ex_t * e);
int ti_type_uses_wpo(ti_type_t * type, ex_t * e);
int ti_type_requires_wpo(ti_type_t * type, ex_t * e);
int ti_type_rename(ti_type_t * type, ti_raw_t * nname);
ti_raw_t * ti__type_nested_from_val(ti_type_t * type, ti_val_t * val, ex_t * e);

static inline int ti_type_use(ti_type_t * type, ex_t * e)
{
Expand Down Expand Up @@ -120,44 +127,6 @@ static inline _Bool ti_type_hide_id(ti_type_t * type)
return type->flags & TI_TYPE_FLAG_HIDE_ID;
}

static inline int ti_type_to_pk(
ti_type_t * type,
msgpack_packer * pk,
_Bool with_definition)
{
return (
msgpack_pack_map(pk, 9) ||
mp_pack_str(pk, "type_id") ||
msgpack_pack_uint16(pk, type->type_id) ||

mp_pack_str(pk, "name") ||
mp_pack_strn(pk, type->rname->data, type->rname->n) ||

mp_pack_str(pk, "wrap_only") ||
mp_pack_bool(pk, ti_type_is_wrap_only(type)) ||

mp_pack_str(pk, "hide_id") ||
mp_pack_bool(pk, ti_type_hide_id(type)) ||

mp_pack_str(pk, "created_at") ||
msgpack_pack_uint64(pk, type->created_at) ||

mp_pack_str(pk, "modified_at") ||
(type->modified_at
? msgpack_pack_uint64(pk, type->modified_at)
: msgpack_pack_nil(pk)) ||

mp_pack_str(pk, "fields") ||
ti_type_fields_to_pk(type, pk) ||

mp_pack_str(pk, "methods") ||
ti_type_methods_info_to_pk(type, pk, with_definition) ||

mp_pack_str(pk, "relations") ||
ti_type_relations_to_pk(type, pk)
);
}

static inline void ti_type_set_wrap_only_mode(ti_type_t * type, _Bool wpo)
{
if (wpo)
Expand Down
10 changes: 10 additions & 0 deletions inc/ti/types.inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@
#include <ti/type.h>
#include <ti/types.h>
#include <ti/raw.h>
#include <ti/val.inline.h>

static inline ti_raw_t * ti_type_nested_from_val(
ti_type_t * type,
ti_val_t * val,
ex_t * e)
{
return (ti_val_is_thing(val) || ti_val_is_array(val))
? ti__type_nested_from_val(type, val, e)
: NULL;
}

static inline ti_type_t * ti_types_by_strn(ti_types_t * types, const char * str, size_t n)
{
Expand Down
Loading