Fix the gdb build with GCC 7
[deliverable/binutils-gdb.git] / libctf / ctf-create.c
index 16e7de85c157af3dc5f630cbdf185a67e2c6ffd9..fa40100c770114a0154ac7665bb6132ce6491cff 100644 (file)
@@ -479,7 +479,7 @@ ctf_serialize (ctf_file_t *fp)
 
   if (strtab.cts_strs == NULL)
     {
-      ctf_free (buf);
+      free (buf);
       return (ctf_set_errno (fp, EAGAIN));
     }
 
@@ -491,8 +491,8 @@ ctf_serialize (ctf_file_t *fp)
 
   if ((newbuf = ctf_realloc (fp, buf, buf_size + strtab.cts_len)) == NULL)
     {
-      ctf_free (buf);
-      ctf_free (strtab.cts_strs);
+      free (buf);
+      free (strtab.cts_strs);
       return (ctf_set_errno (fp, EAGAIN));
     }
   buf = newbuf;
@@ -500,7 +500,7 @@ ctf_serialize (ctf_file_t *fp)
   hdrp = (ctf_header_t *) buf;
   hdrp->cth_strlen = strtab.cts_len;
   buf_size += hdrp->cth_strlen;
-  ctf_free (strtab.cts_strs);
+  free (strtab.cts_strs);
 
   /* Finally, we are ready to ctf_simple_open() the new container.  If this
      is successful, we then switch nfp and fp and free the old container.  */
@@ -509,7 +509,7 @@ ctf_serialize (ctf_file_t *fp)
                                       0, NULL, 0, fp->ctf_syn_ext_strtab,
                                       1, &err)) == NULL)
     {
-      ctf_free (buf);
+      free (buf);
       return (ctf_set_errno (fp, err));
     }
 
@@ -525,6 +525,7 @@ ctf_serialize (ctf_file_t *fp)
   nfp->ctf_dvhash = fp->ctf_dvhash;
   nfp->ctf_dvdefs = fp->ctf_dvdefs;
   nfp->ctf_dtoldid = fp->ctf_dtoldid;
+  nfp->ctf_add_processing = fp->ctf_add_processing;
   nfp->ctf_snapshots = fp->ctf_snapshots + 1;
   nfp->ctf_specific = fp->ctf_specific;
   nfp->ctf_ptrtab = fp->ctf_ptrtab;
@@ -553,6 +554,7 @@ ctf_serialize (ctf_file_t *fp)
   fp->ctf_str_atoms = NULL;
   fp->ctf_prov_strtab = NULL;
   memset (&fp->ctf_dtdefs, 0, sizeof (ctf_list_t));
+  fp->ctf_add_processing = NULL;
   fp->ctf_ptrtab = NULL;
   fp->ctf_link_inputs = NULL;
   fp->ctf_link_outputs = NULL;
@@ -633,13 +635,13 @@ ctf_dtd_delete (ctf_file_t *fp, ctf_dtdef_t *dtd)
           dmd != NULL; dmd = nmd)
        {
          if (dmd->dmd_name != NULL)
-             ctf_free (dmd->dmd_name);
+             free (dmd->dmd_name);
          nmd = ctf_list_next (dmd);
-         ctf_free (dmd);
+         free (dmd);
        }
       break;
     case CTF_K_FUNCTION:
-      ctf_free (dtd->dtd_u.dtu_argv);
+      free (dtd->dtd_u.dtu_argv);
       break;
     }
 
@@ -652,7 +654,7 @@ ctf_dtd_delete (ctf_file_t *fp, ctf_dtdef_t *dtd)
     }
 
   ctf_list_delete (&fp->ctf_dtdefs, dtd);
-  ctf_free (dtd);
+  free (dtd);
 }
 
 ctf_dtdef_t *
@@ -692,10 +694,10 @@ void
 ctf_dvd_delete (ctf_file_t *fp, ctf_dvdef_t *dvd)
 {
   ctf_dynhash_remove (fp->ctf_dvhash, dvd->dvd_name);
-  ctf_free (dvd->dvd_name);
+  free (dvd->dvd_name);
 
   ctf_list_delete (&fp->ctf_dvdefs, dvd);
-  ctf_free (dvd);
+  free (dvd);
 }
 
 ctf_dvdef_t *
@@ -813,7 +815,7 @@ ctf_add_generic (ctf_file_t *fp, uint32_t flag, const char *name, int kind,
   if (ctf_grow_ptrtab (fp) < 0)
       return CTF_ERR;          /* errno is set for us. */
 
-  if ((dtd = ctf_alloc (sizeof (ctf_dtdef_t))) == NULL)
+  if ((dtd = malloc (sizeof (ctf_dtdef_t))) == NULL)
     return (ctf_set_errno (fp, EAGAIN));
 
   type = ++fp->ctf_typemax;
@@ -825,13 +827,13 @@ ctf_add_generic (ctf_file_t *fp, uint32_t flag, const char *name, int kind,
 
   if (dtd->dtd_data.ctt_name == 0 && name != NULL && name[0] != '\0')
     {
-      ctf_free (dtd);
+      free (dtd);
       return (ctf_set_errno (fp, EAGAIN));
     }
 
   if (ctf_dtd_insert (fp, dtd, kind) < 0)
     {
-      ctf_free (dtd);
+      free (dtd);
       return CTF_ERR;                  /* errno is set for us.  */
     }
   fp->ctf_flags |= LCTF_DIRTY;
@@ -1064,13 +1066,13 @@ ctf_add_function (ctf_file_t *fp, uint32_t flag,
   if (vlen > CTF_MAX_VLEN)
     return (ctf_set_errno (fp, EOVERFLOW));
 
-  if (vlen != 0 && (vdat = ctf_alloc (sizeof (ctf_id_t) * vlen)) == NULL)
+  if (vlen != 0 && (vdat = malloc (sizeof (ctf_id_t) * vlen)) == NULL)
     return (ctf_set_errno (fp, EAGAIN));
 
   if ((type = ctf_add_generic (fp, flag, NULL, CTF_K_FUNCTION,
                               &dtd)) == CTF_ERR)
     {
-      ctf_free (vdat);
+      free (vdat);
       return CTF_ERR;             /* errno is set for us.  */
     }
 
@@ -1313,12 +1315,12 @@ ctf_add_enumerator (ctf_file_t *fp, ctf_id_t enid, const char *name,
        return (ctf_set_errno (fp, ECTF_DUPLICATE));
     }
 
-  if ((dmd = ctf_alloc (sizeof (ctf_dmdef_t))) == NULL)
+  if ((dmd = malloc (sizeof (ctf_dmdef_t))) == NULL)
     return (ctf_set_errno (fp, EAGAIN));
 
-  if ((s = ctf_strdup (name)) == NULL)
+  if ((s = strdup (name)) == NULL)
     {
-      ctf_free (dmd);
+      free (dmd);
       return (ctf_set_errno (fp, EAGAIN));
     }
 
@@ -1376,12 +1378,12 @@ ctf_add_member_offset (ctf_file_t *fp, ctf_id_t souid, const char *name,
       (malign = ctf_type_align (fp, type)) < 0)
     return -1;                 /* errno is set for us.  */
 
-  if ((dmd = ctf_alloc (sizeof (ctf_dmdef_t))) == NULL)
+  if ((dmd = malloc (sizeof (ctf_dmdef_t))) == NULL)
     return (ctf_set_errno (fp, EAGAIN));
 
-  if (name != NULL && (s = ctf_strdup (name)) == NULL)
+  if (name != NULL && (s = strdup (name)) == NULL)
     {
-      ctf_free (dmd);
+      free (dmd);
       return (ctf_set_errno (fp, EAGAIN));
     }
 
@@ -1498,12 +1500,12 @@ ctf_add_variable (ctf_file_t *fp, const char *name, ctf_id_t ref)
       && (ctf_errno (fp) == ECTF_NONREPRESENTABLE))
     return -1;
 
-  if ((dvd = ctf_alloc (sizeof (ctf_dvdef_t))) == NULL)
+  if ((dvd = malloc (sizeof (ctf_dvdef_t))) == NULL)
     return (ctf_set_errno (fp, EAGAIN));
 
-  if (name != NULL && (dvd->dvd_name = ctf_strdup (name)) == NULL)
+  if (name != NULL && (dvd->dvd_name = strdup (name)) == NULL)
     {
-      ctf_free (dvd);
+      free (dvd);
       return (ctf_set_errno (fp, EAGAIN));
     }
   dvd->dvd_type = ref;
@@ -1511,7 +1513,8 @@ ctf_add_variable (ctf_file_t *fp, const char *name, ctf_id_t ref)
 
   if (ctf_dvd_insert (fp, dvd) < 0)
     {
-      ctf_free (dvd);
+      free (dvd->dvd_name);
+      free (dvd);
       return -1;                       /* errno is set for us.  */
     }
 
@@ -1527,7 +1530,8 @@ enumcmp (const char *name, int value, void *arg)
 
   if (ctf_enum_value (ctb->ctb_file, ctb->ctb_type, name, &bvalue) < 0)
     {
-      ctf_dprintf ("Conflict due to member %s iteration error.\n", name);
+      ctf_dprintf ("Conflict due to member %s iteration error: %s.\n", name,
+                  ctf_errmsg (ctf_errno (ctb->ctb_file)));
       return 1;
     }
   if (value != bvalue)
@@ -1557,7 +1561,8 @@ membcmp (const char *name, ctf_id_t type _libctf_unused_, unsigned long offset,
 
   if (ctf_member_info (ctb->ctb_file, ctb->ctb_type, name, &ctm) < 0)
     {
-      ctf_dprintf ("Conflict due to member %s iteration error.\n", name);
+      ctf_dprintf ("Conflict due to member %s iteration error: %s.\n", name,
+                  ctf_errmsg (ctf_errno (ctb->ctb_file)));
       return 1;
     }
   if (ctm.ctm_offset != offset)
@@ -1576,12 +1581,12 @@ membadd (const char *name, ctf_id_t type, unsigned long offset, void *arg)
   ctf_dmdef_t *dmd;
   char *s = NULL;
 
-  if ((dmd = ctf_alloc (sizeof (ctf_dmdef_t))) == NULL)
+  if ((dmd = malloc (sizeof (ctf_dmdef_t))) == NULL)
     return (ctf_set_errno (ctb->ctb_file, EAGAIN));
 
-  if (name != NULL && (s = ctf_strdup (name)) == NULL)
+  if (name != NULL && (s = strdup (name)) == NULL)
     {
-      ctf_free (dmd);
+      free (dmd);
       return (ctf_set_errno (ctb->ctb_file, EAGAIN));
     }
 
@@ -1603,11 +1608,13 @@ membadd (const char *name, ctf_id_t type, unsigned long offset, void *arg)
    following the source type's links and embedded member types.  If the
    destination container already contains a named type which has the same
    attributes, then we succeed and return this type but no changes occur.  */
-ctf_id_t
-ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
+static ctf_id_t
+ctf_add_type_internal (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type,
+                      ctf_file_t *proc_tracking_fp)
 {
   ctf_id_t dst_type = CTF_ERR;
   uint32_t dst_kind = CTF_K_UNKNOWN;
+  ctf_file_t *tmp_fp = dst_fp;
   ctf_id_t tmp;
 
   const char *name;
@@ -1618,7 +1625,6 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
   ctf_encoding_t src_en, dst_en;
   ctf_arinfo_t src_ar, dst_ar;
 
-  ctf_dtdef_t *dtd;
   ctf_funcinfo_t ctc;
 
   ctf_id_t orig_src_type = src_type;
@@ -1638,6 +1644,33 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
   flag = LCTF_INFO_ISROOT (src_fp, src_tp->ctt_info);
   vlen = LCTF_INFO_VLEN (src_fp, src_tp->ctt_info);
 
+  /* If this is a type we are currently in the middle of adding, hand it
+     straight back.  (This lets us handle self-referential structures without
+     considering forwards and empty structures the same as their completed
+     forms.)  */
+
+  tmp = ctf_type_mapping (src_fp, src_type, &tmp_fp);
+
+  if (tmp != 0)
+    {
+      if (ctf_dynhash_lookup (proc_tracking_fp->ctf_add_processing,
+                             (void *) (uintptr_t) src_type))
+       return tmp;
+
+      /* If this type has already been added from this container, and is the same
+        kind and (if a struct or union) has the same number of members, hand it
+        straight back.  */
+
+      if ((ctf_type_kind_unsliced (tmp_fp, tmp) == (int) kind)
+         && (kind == CTF_K_STRUCT || kind == CTF_K_UNION
+             || kind == CTF_K_ENUM))
+       {
+         if ((dst_tp = ctf_lookup_by_id (&tmp_fp, dst_type)) != NULL)
+           if (vlen == LCTF_INFO_VLEN (tmp_fp, dst_tp->ctt_info))
+             return tmp;
+       }
+    }
+
   forward_kind = kind;
   if (kind == CTF_K_FORWARD)
     forward_kind = src_tp->ctt_type;
@@ -1697,6 +1730,9 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
          if ((dst_tp = ctf_lookup_by_id (&fp, dst_type)) == NULL)
            return CTF_ERR;
 
+         if (ctf_type_encoding (dst_fp, dst_type, &dst_en) != 0)
+           return CTF_ERR;                     /* errno set for us.  */
+
          if (LCTF_INFO_ISROOT (fp, dst_tp->ctt_info) & CTF_ADD_ROOT)
            {
              /* The type that we found in the hash is also root-visible.  If
@@ -1705,9 +1741,6 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
                 even if there is no conflict: we must check the contained type
                 too.  */
 
-             if (ctf_type_encoding (dst_fp, dst_type, &dst_en) != 0)
-               return CTF_ERR;                 /* errno set for us.  */
-
              if (memcmp (&src_en, &dst_en, sizeof (ctf_encoding_t)) == 0)
                {
                  if (kind != CTF_K_SLICE)
@@ -1723,71 +1756,17 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
            }
          else
            {
-             /* We found a non-root-visible type in the hash.  We reset
-                dst_type to ensure that we continue to look for a possible
-                conflict in the pending list.  */
-
-             dst_type = CTF_ERR;
-           }
-       }
-    }
-
-  /* If the non-empty name was not found in the appropriate hash, search
-     the list of pending dynamic definitions that are not yet committed.
-     If a matching name and kind are found, assume this is the type that
-     we are looking for.  This is necessary to permit ctf_add_type() to
-     operate recursively on entities such as a struct that contains a
-     pointer member that refers to the same struct type.  */
-
-  if (dst_type == CTF_ERR && name[0] != '\0')
-    {
-      for (dtd = ctf_list_prev (&dst_fp->ctf_dtdefs); dtd != NULL
-            && LCTF_TYPE_TO_INDEX (src_fp, dtd->dtd_type) > dst_fp->ctf_dtoldid;
-          dtd = ctf_list_prev (dtd))
-       {
-         const char *ctt_name;
-
-         if (LCTF_INFO_KIND (src_fp, dtd->dtd_data.ctt_info) == kind
-             && dtd->dtd_data.ctt_name
-             && ((ctt_name = ctf_strraw (src_fp, dtd->dtd_data.ctt_name)) != NULL)
-             && strcmp (ctt_name, name) == 0)
-           {
-             int sroot;        /* Is the src root-visible?  */
-             int droot;        /* Is the dst root-visible?  */
-             int match;        /* Do the encodings match?  */
-
-             if (kind != CTF_K_INTEGER && kind != CTF_K_FLOAT && kind != CTF_K_SLICE)
-               {
-                 ctf_add_type_mapping (src_fp, src_type, dst_fp, dtd->dtd_type);
-                 return dtd->dtd_type;
-               }
-
-             sroot = (flag & CTF_ADD_ROOT);
-             droot = (LCTF_INFO_ISROOT (dst_fp,
-                                        dtd->dtd_data.
-                                        ctt_info) & CTF_ADD_ROOT);
-
-             match = (memcmp (&src_en, &dtd->dtd_u.dtu_enc,
-                              sizeof (ctf_encoding_t)) == 0);
-
-             /* If the types share the same encoding then return the id of the
-                first unless one type is root-visible and the other is not; in
-                that case the new type must get a new id if a match is never
-                found.  Note: slices are not certain to match even if there is
-                no conflict: we must check the contained type too. */
+             /* We found a non-root-visible type in the hash.  If its encoding
+                is the same, we can reuse it, unless it is a slice.  */
 
-             if (match && sroot == droot)
+             if (memcmp (&src_en, &dst_en, sizeof (ctf_encoding_t)) == 0)
                {
                  if (kind != CTF_K_SLICE)
                    {
-                     ctf_add_type_mapping (src_fp, src_type, dst_fp, dtd->dtd_type);
-                     return dtd->dtd_type;
+                     ctf_add_type_mapping (src_fp, src_type, dst_fp, dst_type);
+                     return dst_type;
                    }
                }
-             else if (!match && sroot && droot)
-               {
-                 return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
-               }
            }
        }
     }
@@ -1800,10 +1779,18 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
   dst.ctb_type = dst_type;
   dst.ctb_dtd = NULL;
 
-  /* Now perform kind-specific processing.  If dst_type is CTF_ERR, then
-     we add a new type with the same properties as src_type to dst_fp.
-     If dst_type is not CTF_ERR, then we verify that dst_type has the
-     same attributes as src_type.  We recurse for embedded references.  */
+  /* Now perform kind-specific processing.  If dst_type is CTF_ERR, then we add
+     a new type with the same properties as src_type to dst_fp.  If dst_type is
+     not CTF_ERR, then we verify that dst_type has the same attributes as
+     src_type.  We recurse for embedded references.  Before we start, we note
+     that we are processing this type, to prevent infinite recursion: we do not
+     re-process any type that appears in this list.  The list is emptied
+     wholesale at the end of processing everything in this recursive stack.  */
+
+  if (ctf_dynhash_insert (proc_tracking_fp->ctf_add_processing,
+                         (void *) (uintptr_t) src_type, (void *) 1) < 0)
+    return ctf_set_errno (dst_fp, ENOMEM);
+
   switch (kind)
     {
     case CTF_K_INTEGER:
@@ -1822,7 +1809,8 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
       /* We have checked for conflicting encodings: now try to add the
         contained type.  */
       src_type = ctf_type_reference (src_fp, src_type);
-      dst_type = ctf_add_type (dst_fp, src_fp, src_type);
+      src_type = ctf_add_type_internal (dst_fp, src_fp, src_type,
+                                       proc_tracking_fp);
 
       if (src_type == CTF_ERR)
        return CTF_ERR;                         /* errno is set for us.  */
@@ -1835,7 +1823,8 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
     case CTF_K_CONST:
     case CTF_K_RESTRICT:
       src_type = ctf_type_reference (src_fp, src_type);
-      src_type = ctf_add_type (dst_fp, src_fp, src_type);
+      src_type = ctf_add_type_internal (dst_fp, src_fp, src_type,
+                                       proc_tracking_fp);
 
       if (src_type == CTF_ERR)
        return CTF_ERR;                         /* errno is set for us.  */
@@ -1848,8 +1837,11 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
        return (ctf_set_errno (dst_fp, ctf_errno (src_fp)));
 
       src_ar.ctr_contents =
-       ctf_add_type (dst_fp, src_fp, src_ar.ctr_contents);
-      src_ar.ctr_index = ctf_add_type (dst_fp, src_fp, src_ar.ctr_index);
+       ctf_add_type_internal (dst_fp, src_fp, src_ar.ctr_contents,
+                              proc_tracking_fp);
+      src_ar.ctr_index = ctf_add_type_internal (dst_fp, src_fp,
+                                               src_ar.ctr_index,
+                                               proc_tracking_fp);
       src_ar.ctr_nelems = src_ar.ctr_nelems;
 
       if (src_ar.ctr_contents == CTF_ERR || src_ar.ctr_index == CTF_ERR)
@@ -1876,7 +1868,9 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
       break;
 
     case CTF_K_FUNCTION:
-      ctc.ctc_return = ctf_add_type (dst_fp, src_fp, src_tp->ctt_type);
+      ctc.ctc_return = ctf_add_type_internal (dst_fp, src_fp,
+                                             src_tp->ctt_type,
+                                             proc_tracking_fp);
       ctc.ctc_argc = 0;
       ctc.ctc_flags = 0;
 
@@ -1893,6 +1887,7 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
        int errs = 0;
        size_t size;
        ssize_t ssize;
+       ctf_dtdef_t *dtd;
 
        /* Technically to match a struct or union we need to check both
           ways (src members vs. dst, dst members vs. src) but we make
@@ -1902,7 +1897,8 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
           This optimization can be defeated for unions, but is so
           pathological as to render it irrelevant for our purposes.  */
 
-       if (dst_type != CTF_ERR && dst_kind != CTF_K_FORWARD)
+       if (dst_type != CTF_ERR && kind != CTF_K_FORWARD
+           && dst_kind != CTF_K_FORWARD)
          {
            if (ctf_type_size (src_fp, src_type) !=
                ctf_type_size (dst_fp, dst_type))
@@ -1936,6 +1932,10 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
        dst.ctb_type = dst_type;
        dst.ctb_dtd = dtd;
 
+       /* Pre-emptively add this struct to the type mapping so that
+          structures that refer to themselves work.  */
+       ctf_add_type_mapping (src_fp, src_type, dst_fp, dst_type);
+
        if (ctf_member_iter (src_fp, src_type, membadd, &dst) != 0)
          errs++;              /* Increment errs and fail at bottom of case.  */
 
@@ -1963,12 +1963,22 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
        for (dmd = ctf_list_next (&dtd->dtd_u.dtu_members);
             dmd != NULL; dmd = ctf_list_next (dmd))
          {
-           if ((dmd->dmd_type = ctf_add_type (dst_fp, src_fp,
-                                              dmd->dmd_type)) == CTF_ERR)
+           ctf_file_t *dst = dst_fp;
+           ctf_id_t memb_type;
+
+           memb_type = ctf_type_mapping (src_fp, dmd->dmd_type, &dst);
+           if (memb_type == 0)
              {
-               if (ctf_errno (dst_fp) != ECTF_NONREPRESENTABLE)
-                 errs++;
+               if ((dmd->dmd_type =
+                    ctf_add_type_internal (dst_fp, src_fp, dmd->dmd_type,
+                                           proc_tracking_fp)) == CTF_ERR)
+                 {
+                   if (ctf_errno (dst_fp) != ECTF_NONREPRESENTABLE)
+                     errs++;
+                 }
              }
+           else
+             dmd->dmd_type = memb_type;
          }
 
        if (errs)
@@ -1977,7 +1987,8 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
       }
 
     case CTF_K_ENUM:
-      if (dst_type != CTF_ERR && dst_kind != CTF_K_FORWARD)
+      if (dst_type != CTF_ERR && kind != CTF_K_FORWARD
+         && dst_kind != CTF_K_FORWARD)
        {
          if (ctf_enum_iter (src_fp, src_type, enumcmp, &dst)
              || ctf_enum_iter (dst_fp, dst_type, enumcmp, &src))
@@ -2003,7 +2014,8 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
 
     case CTF_K_TYPEDEF:
       src_type = ctf_type_reference (src_fp, src_type);
-      src_type = ctf_add_type (dst_fp, src_fp, src_type);
+      src_type = ctf_add_type_internal (dst_fp, src_fp, src_type,
+                                       proc_tracking_fp);
 
       if (src_type == CTF_ERR)
        return CTF_ERR;                         /* errno is set for us.  */
@@ -2017,9 +2029,8 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
         equivalent.  */
 
       if (dst_type == CTF_ERR)
-       {
          dst_type = ctf_add_typedef (dst_fp, flag, name, src_type);
-       }
+
       break;
 
     default:
@@ -2031,6 +2042,27 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
   return dst_type;
 }
 
+ctf_id_t
+ctf_add_type (ctf_file_t *dst_fp, ctf_file_t *src_fp, ctf_id_t src_type)
+{
+  ctf_id_t id;
+
+  if (!src_fp->ctf_add_processing)
+    src_fp->ctf_add_processing = ctf_dynhash_create (ctf_hash_integer,
+                                                    ctf_hash_eq_integer,
+                                                    NULL, NULL);
+
+  /* We store the hash on the source, because it contains only source type IDs:
+     but callers will invariably expect errors to appear on the dest.  */
+  if (!src_fp->ctf_add_processing)
+    return (ctf_set_errno (dst_fp, ENOMEM));
+
+  id = ctf_add_type_internal (dst_fp, src_fp, src_type, src_fp);
+  ctf_dynhash_empty (src_fp->ctf_add_processing);
+
+  return id;
+}
+
 /* Write the compressed CTF data stream to the specified gzFile descriptor.  */
 int
 ctf_gzwrite (ctf_file_t *fp, gzFile fd)
@@ -2084,7 +2116,7 @@ ctf_compress_write (ctf_file_t *fp, int fd)
   hp->cth_flags |= CTF_F_COMPRESS;
   compress_len = compressBound (fp->ctf_size);
 
-  if ((buf = ctf_alloc (compress_len)) == NULL)
+  if ((buf = malloc (compress_len)) == NULL)
     return (ctf_set_errno (fp, ECTF_ZALLOC));
 
   if ((rc = compress (buf, (uLongf *) &compress_len,
@@ -2119,7 +2151,7 @@ ctf_compress_write (ctf_file_t *fp, int fd)
     }
 
 ret:
-  ctf_free (buf);
+  free (buf);
   return err;
 }
 
@@ -2167,7 +2199,7 @@ ctf_write_mem (ctf_file_t *fp, size_t *size, size_t threshold)
        {
          ctf_dprintf ("zlib deflate err: %s\n", zError (rc));
          ctf_set_errno (fp, ECTF_COMPRESS);
-         ctf_free (buf);
+         free (buf);
          return NULL;
        }
       *size += compress_len;
This page took 0.03383 seconds and 4 git commands to generate.