extern const char *ctf_cuname (ctf_dict_t *);
extern ctf_dict_t *ctf_parent_dict (ctf_dict_t *);
extern const char *ctf_parent_name (ctf_dict_t *);
-extern int ctf_type_isparent (ctf_dict_t *, ctf_id_t);
-extern int ctf_type_ischild (ctf_dict_t *, ctf_id_t);
+extern int ctf_type_isparent (const ctf_dict_t *, ctf_id_t);
+extern int ctf_type_ischild (const ctf_dict_t *, ctf_id_t);
extern int ctf_import (ctf_dict_t *, ctf_dict_t *);
/* Set these names (used when creating dicts). */
ctf_dtdef_t *
ctf_dtd_lookup (const ctf_dict_t *fp, ctf_id_t type)
{
- if ((fp->ctf_flags & LCTF_CHILD) && LCTF_TYPE_ISPARENT (fp, type))
- fp = fp->ctf_parent;
+ fp = ctf_get_dict (fp, type);
return (ctf_dtdef_t *)
ctf_dynhash_lookup (fp->ctf_dthash, (void *) (uintptr_t) type);
}
ctf_dtdef_t *
-ctf_dynamic_type (const ctf_dict_t *fp, ctf_id_t id)
+ctf_dynamic_type (const ctf_dict_t *fp, ctf_id_t type)
{
ctf_id_t idx;
- if ((fp->ctf_flags & LCTF_CHILD) && LCTF_TYPE_ISPARENT (fp, id))
- fp = fp->ctf_parent;
+ fp = ctf_get_dict (fp, type);
- idx = LCTF_TYPE_TO_INDEX(fp, id);
+ idx = LCTF_TYPE_TO_INDEX(fp, type);
if ((unsigned long) idx <= fp->ctf_typemax)
return ctf_dtd_lookup (fp, id);
}
static int
-ctf_static_type (const ctf_dict_t *fp, ctf_id_t id)
+ctf_static_type (const ctf_dict_t *fp, ctf_id_t type)
{
ctf_id_t idx;
- if ((fp->ctf_flags & LCTF_CHILD) && LCTF_TYPE_ISPARENT (fp, id))
- fp = fp->ctf_parent;
+ fp = ctf_get_dict (fp, type);
- idx = LCTF_TYPE_TO_INDEX(fp, id);
+ idx = LCTF_TYPE_TO_INDEX(fp, type);
return ((unsigned long) idx <= fp->ctf_stypes);
}
uint32_t type_idx = LCTF_TYPE_TO_INDEX (fp, type);
uint32_t ref_idx = LCTF_TYPE_TO_INDEX (fp, ref);
- if (LCTF_TYPE_ISCHILD (fp, ref) == child
+ if (ctf_type_ischild (fp, ref) == child
&& ref_idx < fp->ctf_typemax)
fp->ctf_ptrtab[ref_idx] = type_idx;
ctf_dtdef_t *dtd = ctf_dtd_lookup (fp, type);
ctf_array_t *vlen;
- if ((fp->ctf_flags & LCTF_CHILD) && LCTF_TYPE_ISPARENT (fp, type))
- fp = fp->ctf_parent;
+ fp = ctf_get_dict (fp, type);
/* You can only call ctf_set_array on a type you have added, not a
type that was read in via ctf_open(). */
if (name == NULL)
return (ctf_set_errno (fp, EINVAL));
- if ((fp->ctf_flags & LCTF_CHILD) && LCTF_TYPE_ISPARENT (fp, enid))
- fp = fp->ctf_parent;
+ fp = ctf_get_dict (fp, enid);
if (enid < fp->ctf_stypes)
return (ctf_set_errno (ofp, ECTF_RDONLY));
if (fp->ctf_flags & LCTF_NO_STR)
return (ctf_set_errno (fp, ECTF_NOPARENT));
- if ((fp->ctf_flags & LCTF_CHILD) && LCTF_TYPE_ISPARENT (fp, souid))
+ if ((fp->ctf_flags & LCTF_CHILD) && ctf_type_isparent (fp, souid))
{
/* Adding a child type to a parent, even via the child, is prohibited.
Otherwise, climb to the parent and do all work there. */
- if (LCTF_TYPE_ISCHILD (fp, type))
+ if (ctf_type_ischild (fp, type))
return (ctf_set_errno (ofp, ECTF_BADID));
fp = fp->ctf_parent;
ctf_add_type_mapping (ctf_dict_t *src_fp, ctf_id_t src_type,
ctf_dict_t *dst_fp, ctf_id_t dst_type)
{
- if (LCTF_TYPE_ISPARENT (src_fp, src_type) && src_fp->ctf_parent)
- src_fp = src_fp->ctf_parent;
+ src_fp = ctf_get_dict (src_fp, src_type);
+ dst_fp = ctf_get_dict (dst_fp, dst_type);
- src_type = LCTF_TYPE_TO_INDEX(src_fp, src_type);
+ /* Not imported? No mapping is meaningful. */
+ if (src_fp == NULL || dst_fp == NULL)
+ return;
- if (LCTF_TYPE_ISPARENT (dst_fp, dst_type) && dst_fp->ctf_parent)
- dst_fp = dst_fp->ctf_parent;
+ src_type = LCTF_TYPE_TO_INDEX(src_fp, src_type);
dst_type = LCTF_TYPE_TO_INDEX(dst_fp, dst_type);
ctf_dict_t *target_fp = *dst_fp;
ctf_id_t dst_type = 0;
- if (LCTF_TYPE_ISPARENT (src_fp, src_type) && src_fp->ctf_parent)
- src_fp = src_fp->ctf_parent;
+ src_fp = ctf_get_dict (src_fp, src_type);
+
+ /* No mapping is possible if the parent is not imported. */
+ if (src_fp == NULL)
+ return 0;
src_type = LCTF_TYPE_TO_INDEX(src_fp, src_type);
key.cltk_fp = src_fp;
{
ctf_id_t id;
- if ((src_fp->ctf_flags & LCTF_NO_STR) || (dst_fp->ctf_flags & LCTF_NO_STR))
+ if ((src_fp->ctf_flags & LCTF_NO_STR) || (dst_fp->ctf_flags & LCTF_NO_STR)
+ || ((src_fp->ctf_flags & LCTF_CHILD) && (src_fp->ctf_parent == NULL))
+ || ((dst_fp->ctf_flags & LCTF_CHILD) && (dst_fp->ctf_parent == NULL)))
return (ctf_set_errno (dst_fp, ECTF_NOPARENT));
if (!src_fp->ctf_add_processing)
const char *hashval; \
int cited_type_input_num = input_num; \
\
- if ((fp->ctf_flags & LCTF_CHILD) && (LCTF_TYPE_ISPARENT (fp, type))) \
+ if ((fp->ctf_flags & LCTF_CHILD) && (ctf_type_isparent (fp, type))) \
cited_type_input_num = parents[input_num]; \
\
type_id = CTF_DEDUP_GID (output, cited_type_input_num, type); \
/* If the input type is in the parent type space, and this is a child, reset
the input to the parent (which must already have been emitted, since
emission of parent dicts happens before children). */
- if ((input->ctf_flags & LCTF_CHILD) && (LCTF_TYPE_ISPARENT (input, id)))
+ if ((input->ctf_flags & LCTF_CHILD) && (ctf_type_isparent (input, id)))
{
if (!ctf_assert (output, parents[input_num] <= ninputs))
return CTF_ERR;
/* * If an offs is not aligned already then round it up and align it. */
#define LCTF_ALIGN_OFFS(offs, align) ((offs + (align - 1)) & ~(align - 1))
-#define LCTF_TYPE_ISPARENT(fp, id) ((id) <= fp->ctf_parmax)
-#define LCTF_TYPE_ISCHILD(fp, id) ((id) > fp->ctf_parmax)
#define LCTF_TYPE_TO_INDEX(fp, id) ((id) & (fp->ctf_parmax))
#define LCTF_INDEX_TO_TYPE(fp, id, child) (child ? ((id) | (fp->ctf_parmax+1)) : \
(id))
extern int ctf_add_funcobjt_sym (ctf_dict_t *, int is_function,
const char *, ctf_id_t);
-extern ctf_dict_t *ctf_get_dict (ctf_dict_t *fp, ctf_id_t type);
+extern ctf_dict_t *ctf_get_dict (const ctf_dict_t *fp, ctf_id_t type);
typedef unsigned int (*ctf_hash_fun) (const void *ptr);
extern unsigned int ctf_hash_integer (const void *ptr);
reffed_type = ctf_type_reference (fp, type);
- if (LCTF_TYPE_ISPARENT (fp, reffed_type))
+ if (ctf_type_isparent (fp, reffed_type))
{
uint32_t idx = LCTF_TYPE_TO_INDEX (fp, reffed_type);
store the index of the pointer type in fp->ctf_ptrtab[ index of
referenced type ]. */
- if (LCTF_TYPE_ISCHILD (fp, tp->ctt_type) == child
+ if (ctf_type_ischild (fp, tp->ctt_type) == child
&& LCTF_TYPE_TO_INDEX (fp, tp->ctt_type) <= fp->ctf_typemax)
fp->ctf_ptrtab[LCTF_TYPE_TO_INDEX (fp, tp->ctt_type)] = id;
/*FALLTHRU*/
/* Determine whether a type is a parent or a child. */
int
-ctf_type_isparent (ctf_dict_t *fp, ctf_id_t id)
+ctf_type_isparent (const ctf_dict_t *fp, ctf_id_t id)
{
- return (LCTF_TYPE_ISPARENT (fp, id));
+ return (id <= fp->ctf_parmax);
}
int
-ctf_type_ischild (ctf_dict_t * fp, ctf_id_t id)
+ctf_type_ischild (const ctf_dict_t *fp, ctf_id_t id)
{
- return (LCTF_TYPE_ISCHILD (fp, id));
+ return (!ctf_type_isparent (fp, id));
}
/* Expand a structure element into the passed-in ctf_lmember_t. */
type is in the parent, return the parent. Needed if you plan to access
the type directly, without using the API. */
ctf_dict_t *
-ctf_get_dict (ctf_dict_t *fp, ctf_id_t type)
+ctf_get_dict (const ctf_dict_t *fp, ctf_id_t type)
{
- if ((fp->ctf_flags & LCTF_CHILD) && LCTF_TYPE_ISPARENT (fp, type))
- return fp->ctf_parent;
+ if ((fp->ctf_flags & LCTF_CHILD) && ctf_type_isparent (fp, type))
+ return fp->ctf_parent;
- return fp;
+ return (ctf_dict_t *) fp;
}
/* Look up a name in the given name table, in the appropriate hash given the
if (lfp == rfp)
return rval;
- if (LCTF_TYPE_ISPARENT (lfp, ltype) && lfp->ctf_parent != NULL)
- lfp = lfp->ctf_parent;
+ if (lfp->ctf_parent != NULL)
+ lfp = ctf_get_dict (lfp, ltype);
- if (LCTF_TYPE_ISPARENT (rfp, rtype) && rfp->ctf_parent != NULL)
- rfp = rfp->ctf_parent;
+ if (rfp->ctf_parent != NULL)
+ rfp = ctf_get_dict (rfp, rtype);
if (lfp < rfp)
return -1;
if (rfp->ctf_flags & LCTF_NO_STR)
return (ctf_set_errno (rfp, ECTF_NOPARENT));
+ if (ctf_type_isparent (lfp, ltype) && !lfp->ctf_parent)
+ return (ctf_set_errno (rfp, ECTF_NOPARENT));
+
+ if (ctf_type_isparent (rfp, rtype) && !rfp->ctf_parent)
+ return (ctf_set_errno (rfp, ECTF_NOPARENT));
+
if (ctf_type_cmp (lfp, ltype, rfp, rtype) == 0)
return 1;