tree schema UPDATE store typedef name in the compiled type
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index 2bb7af3..d0b3431 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -1675,29 +1675,35 @@
/**
* @brief Allocate a new specific type structure according to the basetype.
*
+ * @param[in] ctx Context to use.
* @param[in] basetype Base type of the new type.
- * @return Specific type structure.
+ * @param[in] tpdf_name Optional referenced typedef name, NULL for built-in types.
+ * @param[out] type Specific type structure.
+ * @return LY_ERR value.
*/
-static struct lysc_type *
-lys_new_type(LY_DATA_TYPE basetype)
+static LY_ERR
+lys_new_type(const struct ly_ctx *ctx, LY_DATA_TYPE basetype, const char *tpdf_name, struct lysc_type **type)
{
- struct lysc_type *type = NULL;
+ LY_ERR rc = LY_SUCCESS;
+ struct lysc_type *t = NULL;
+
+ *type = NULL;
switch (basetype) {
case LY_TYPE_BINARY:
- type = calloc(1, sizeof(struct lysc_type_bin));
+ t = calloc(1, sizeof(struct lysc_type_bin));
break;
case LY_TYPE_BITS:
- type = calloc(1, sizeof(struct lysc_type_bits));
+ t = calloc(1, sizeof(struct lysc_type_bits));
break;
case LY_TYPE_DEC64:
- type = calloc(1, sizeof(struct lysc_type_dec));
+ t = calloc(1, sizeof(struct lysc_type_dec));
break;
case LY_TYPE_STRING:
- type = calloc(1, sizeof(struct lysc_type_str));
+ t = calloc(1, sizeof(struct lysc_type_str));
break;
case LY_TYPE_ENUM:
- type = calloc(1, sizeof(struct lysc_type_enum));
+ t = calloc(1, sizeof(struct lysc_type_enum));
break;
case LY_TYPE_INT8:
case LY_TYPE_UINT8:
@@ -1707,29 +1713,41 @@
case LY_TYPE_UINT32:
case LY_TYPE_INT64:
case LY_TYPE_UINT64:
- type = calloc(1, sizeof(struct lysc_type_num));
+ t = calloc(1, sizeof(struct lysc_type_num));
break;
case LY_TYPE_IDENT:
- type = calloc(1, sizeof(struct lysc_type_identityref));
+ t = calloc(1, sizeof(struct lysc_type_identityref));
break;
case LY_TYPE_LEAFREF:
- type = calloc(1, sizeof(struct lysc_type_leafref));
+ t = calloc(1, sizeof(struct lysc_type_leafref));
break;
case LY_TYPE_INST:
- type = calloc(1, sizeof(struct lysc_type_instanceid));
+ t = calloc(1, sizeof(struct lysc_type_instanceid));
break;
case LY_TYPE_UNION:
- type = calloc(1, sizeof(struct lysc_type_union));
+ t = calloc(1, sizeof(struct lysc_type_union));
break;
case LY_TYPE_BOOL:
case LY_TYPE_EMPTY:
- type = calloc(1, sizeof(struct lysc_type));
+ t = calloc(1, sizeof(struct lysc_type));
break;
case LY_TYPE_UNKNOWN:
break;
}
+ LY_CHECK_ERR_GOTO(!t, LOGMEM(ctx); rc = LY_EMEM, cleanup);
- return type;
+ if (tpdf_name) {
+ rc = lydict_insert(ctx, tpdf_name, 0, &t->name);
+ LY_CHECK_GOTO(rc, cleanup);
+ }
+
+cleanup:
+ if (rc) {
+ free(t);
+ } else {
+ *type = t;
+ }
+ return rc;
}
/**
@@ -1737,7 +1755,8 @@
*
* @param[in] ctx Compile context.
* @param[in] context_pnode Schema node where the type/typedef is placed to correctly find the base types.
- * @param[in] context_flags Flags of the context node or the referencing typedef to correctly check status of referencing and referenced objects.
+ * @param[in] context_flags Flags of the context node or the referencing typedef to correctly check status of
+ * referencing and referenced objects.
* @param[in] context_name Name of the context node or referencing typedef for logging.
* @param[in] type_p Parsed type to compile.
* @param[in] basetype Base YANG built-in type of the type to compile.
@@ -1769,8 +1788,8 @@
uint32_t i;
/* alloc and init */
- *type = lys_new_type(basetype);
- LY_CHECK_ERR_GOTO(!(*type), LOGMEM(ctx->ctx), cleanup);
+ rc = lys_new_type(ctx->ctx, basetype, tpdfname, type);
+ LY_CHECK_GOTO(rc, cleanup);
(*type)->basetype = basetype;
(*type)->plugin = plugin;
diff --git a/src/tree_schema.h b/src/tree_schema.h
index ffb1b2f..c24e7da 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -1277,37 +1277,44 @@
};
struct lysc_type {
+ const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
- struct lyplg_type *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
- LY_DATA_TYPE basetype; /**< Base type of the type */
+ struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */
+ LY_DATA_TYPE basetype; /**< base type of the type */
uint32_t refcount; /**< reference counter for type sharing, it may be accessed concurrently when
creating/freeing data node values that reference it (instance-identifier) */
};
struct lysc_type_num {
+ const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
- struct lyplg_type *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
- LY_DATA_TYPE basetype; /**< Base type of the type */
+ struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */
+ LY_DATA_TYPE basetype; /**< base type of the type */
uint32_t refcount; /**< reference counter for type sharing */
+
struct lysc_range *range; /**< Optional range limitation */
};
struct lysc_type_dec {
+ const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
- struct lyplg_type *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
- LY_DATA_TYPE basetype; /**< Base type of the type */
+ struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */
+ LY_DATA_TYPE basetype; /**< base type of the type */
uint32_t refcount; /**< reference counter for type sharing */
+
uint8_t fraction_digits; /**< fraction digits specification */
struct lysc_range *range; /**< Optional range limitation */
};
struct lysc_type_str {
+ const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
- struct lyplg_type *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
- LY_DATA_TYPE basetype; /**< Base type of the type */
+ struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */
+ LY_DATA_TYPE basetype; /**< base type of the type */
uint32_t refcount; /**< reference counter for type sharing */
- struct lysc_range *length; /**< Optional length limitation */
- struct lysc_pattern **patterns; /**< Optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
+
+ struct lysc_range *length; /**< optional length limitation */
+ struct lysc_pattern **patterns; /**< optional list of pointers to pattern limitations ([sized array](@ref sizedarrays)) */
};
struct lysc_type_bitenum_item {
@@ -1325,27 +1332,33 @@
};
struct lysc_type_enum {
+ const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
- struct lyplg_type *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
- LY_DATA_TYPE basetype; /**< Base type of the type */
+ struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */
+ LY_DATA_TYPE basetype; /**< base type of the type */
uint32_t refcount; /**< reference counter for type sharing */
+
struct lysc_type_bitenum_item *enums; /**< enumerations list ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
};
struct lysc_type_bits {
+ const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
- struct lyplg_type *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
- LY_DATA_TYPE basetype; /**< Base type of the type */
+ struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */
+ LY_DATA_TYPE basetype; /**< base type of the type */
uint32_t refcount; /**< reference counter for type sharing */
+
struct lysc_type_bitenum_item *bits; /**< bits list ([sized array](@ref sizedarrays)), mandatory (at least 1 item),
the items are ordered by their position value. */
};
struct lysc_type_leafref {
+ const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
- struct lyplg_type *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
- LY_DATA_TYPE basetype; /**< Base type of the type */
+ struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */
+ LY_DATA_TYPE basetype; /**< base type of the type */
uint32_t refcount; /**< reference counter for type sharing */
+
struct lyxp_expr *path; /**< parsed target path, compiled path cannot be stored because of type sharing */
struct lysc_prefix *prefixes; /**< resolved prefixes used in the path */
struct lysc_type *realtype; /**< pointer to the real (first non-leafref in possible leafrefs chain) type. */
@@ -1353,36 +1366,44 @@
};
struct lysc_type_identityref {
+ const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
- struct lyplg_type *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
- LY_DATA_TYPE basetype; /**< Base type of the type */
+ struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */
+ LY_DATA_TYPE basetype; /**< base type of the type */
uint32_t refcount; /**< reference counter for type sharing */
+
struct lysc_ident **bases; /**< list of pointers to the base identities ([sized array](@ref sizedarrays)),
mandatory (at least 1 item) */
};
struct lysc_type_instanceid {
+ const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
- struct lyplg_type *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
- LY_DATA_TYPE basetype; /**< Base type of the type */
+ struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */
+ LY_DATA_TYPE basetype; /**< base type of the type */
uint32_t refcount; /**< reference counter for type sharing */
+
uint8_t require_instance; /**< require-instance flag */
};
struct lysc_type_union {
+ const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
- struct lyplg_type *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
- LY_DATA_TYPE basetype; /**< Base type of the type */
+ struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */
+ LY_DATA_TYPE basetype; /**< base type of the type */
uint32_t refcount; /**< reference counter for type sharing */
+
struct lysc_type **types; /**< list of types in the union ([sized array](@ref sizedarrays)), mandatory (at least 1 item) */
};
struct lysc_type_bin {
+ const char *name; /**< referenced typedef name (without prefix, if any), NULL for built-in types */
struct lysc_ext_instance *exts; /**< list of the extension instances ([sized array](@ref sizedarrays)) */
- struct lyplg_type *plugin; /**< type's plugin with built-in as well as user functions to canonize or validate the value of the type */
- LY_DATA_TYPE basetype; /**< Base type of the type */
+ struct lyplg_type *plugin; /**< type's manipulation callbacks plugin */
+ LY_DATA_TYPE basetype; /**< base type of the type */
uint32_t refcount; /**< reference counter for type sharing */
- struct lysc_range *length; /**< Optional length limitation */
+
+ struct lysc_range *length; /**< optional length limitation */
};
/**
diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c
index 3af495f..10b1c6c 100644
--- a/src/tree_schema_free.c
+++ b/src/tree_schema_free.c
@@ -932,6 +932,7 @@
break;
}
+ lydict_remove(ctx->ctx, type->name);
FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free);
free(type);
}