read.c s_include: use notes obstack for path
[binutils-gdb.git] / gas / read.c
index 8524d0bffb96c3389954b7a91cf61c79d4741d48..71bb30e4e70f5a928d6d8ff52b86c39be99a30d3 100644 (file)
@@ -295,53 +295,7 @@ address_bytes (void)
 
 /* Set up pseudo-op tables.  */
 
-struct po_entry
-{
-  const char *poc_name;
-
-  const pseudo_typeS *pop;
-};
-
-typedef struct po_entry po_entry_t;
-
-/* Hash function for a po_entry.  */
-
-static hashval_t
-hash_po_entry (const void *e)
-{
-  const po_entry_t *entry = (const po_entry_t *) e;
-  return htab_hash_string (entry->poc_name);
-}
-
-/* Equality function for a po_entry.  */
-
-static int
-eq_po_entry (const void *a, const void *b)
-{
-  const po_entry_t *ea = (const po_entry_t *) a;
-  const po_entry_t *eb = (const po_entry_t *) b;
-
-  return strcmp (ea->poc_name, eb->poc_name) == 0;
-}
-
-static po_entry_t *
-po_entry_alloc (const char *poc_name, const pseudo_typeS *pop)
-{
-  po_entry_t *entry = XNEW (po_entry_t);
-  entry->poc_name = poc_name;
-  entry->pop = pop;
-  return entry;
-}
-
-static const pseudo_typeS *
-po_entry_find (htab_t table, const char *poc_name)
-{
-  po_entry_t needle = { poc_name, NULL };
-  po_entry_t *entry = htab_find (table, &needle);
-  return entry != NULL ? entry->pop : NULL;
-}
-
-static struct htab *po_hash;
+static htab_t po_hash;
 
 static const pseudo_typeS potable[] = {
   {"abort", s_abort, 0},
@@ -563,10 +517,8 @@ pop_insert (const pseudo_typeS *table)
   const pseudo_typeS *pop;
   for (pop = table; pop->poc_name; pop++)
     {
-      po_entry_t *elt = po_entry_alloc (pop->poc_name, pop);
-      if (htab_insert (po_hash, elt, 0) != NULL)
+      if (str_hash_insert (po_hash, pop->poc_name, pop, 0) != NULL)
        {
-         free (elt);
          if (!pop_override_ok)
            as_fatal (_("error constructing %s pseudo-op table"),
                      pop_table_name);
@@ -589,8 +541,7 @@ pop_insert (const pseudo_typeS *table)
 static void
 pobegin (void)
 {
-  po_hash = htab_create_alloc (16, hash_po_entry, eq_po_entry, NULL,
-                              xcalloc, xfree);
+  po_hash = str_htab_create ();
 
   /* Do the target-specific pseudo ops.  */
   pop_table_name = "md";
@@ -623,25 +574,6 @@ pobegin (void)
       continue;                                                                \
     }
 
-/* This function is used when scrubbing the characters between #APP
-   and #NO_APP.  */
-
-static char *scrub_string;
-static char *scrub_string_end;
-
-static size_t
-scrub_from_string (char *buf, size_t buflen)
-{
-  size_t copy;
-
-  copy = scrub_string_end - scrub_string;
-  if (copy > buflen)
-    copy = buflen;
-  memcpy (buf, scrub_string, copy);
-  scrub_string += copy;
-  return copy;
-}
-
 /* Helper function of read_a_source_file, which tries to expand a macro.  */
 static int
 try_macro (char term, const char *line)
@@ -927,7 +859,7 @@ read_a_source_file (const char *name)
                  if (s != last_eol)
                    {
                      char *copy;
-                     int len;
+                     size_t len;
 
                      last_eol = s;
                      /* Copy it for safe keeping.  Also give an indication of
@@ -1118,7 +1050,7 @@ read_a_source_file (const char *name)
                    {
                      /* The MRI assembler uses pseudo-ops without
                         a period.  */
-                     pop = po_entry_find (po_hash, s);
+                     pop = str_hash_find (po_hash, s);
                      if (pop != NULL && pop->poc_handler == NULL)
                        pop = NULL;
                    }
@@ -1133,7 +1065,7 @@ read_a_source_file (const char *name)
                         already know that the pseudo-op begins with a '.'.  */
 
                      if (pop == NULL)
-                       pop = po_entry_find (po_hash, s + 1);
+                       pop = str_hash_find (po_hash, s + 1);
                      if (pop && !pop->poc_handler)
                        pop = NULL;
 
@@ -1312,10 +1244,7 @@ read_a_source_file (const char *name)
            {                   /* Its a comment.  Better say APP or NO_APP.  */
              sb sbuf;
              char *ends;
-             char *new_buf;
-             char *new_tmp;
-             unsigned int new_length;
-             char *tmp_buf = 0;
+             size_t len;
 
              s = input_line_pointer;
              if (!startswith (s, "APP\n"))
@@ -1328,91 +1257,32 @@ read_a_source_file (const char *name)
              s += 4;
 
              ends = strstr (s, "#NO_APP\n");
+             len = ends ? ends - s : buffer_limit - s;
 
+             sb_build (&sbuf, len + 100);
+             sb_add_buffer (&sbuf, s, len);
              if (!ends)
                {
-                 unsigned int tmp_len;
-                 unsigned int num;
-
                  /* The end of the #APP wasn't in this buffer.  We
                     keep reading in buffers until we find the #NO_APP
                     that goes with this #APP  There is one.  The specs
                     guarantee it...  */
-                 tmp_len = buffer_limit - s;
-                 tmp_buf = XNEWVEC (char, tmp_len + 1);
-                 memcpy (tmp_buf, s, tmp_len);
                  do
                    {
-                     new_tmp = input_scrub_next_buffer (&buffer);
-                     if (!new_tmp)
+                     buffer_limit = input_scrub_next_buffer (&buffer);
+                     if (!buffer_limit)
                        break;
-                     else
-                       buffer_limit = new_tmp;
-                     input_line_pointer = buffer;
                      ends = strstr (buffer, "#NO_APP\n");
-                     if (ends)
-                       num = ends - buffer;
-                     else
-                       num = buffer_limit - buffer;
-
-                     tmp_buf = XRESIZEVEC (char, tmp_buf, tmp_len + num);
-                     memcpy (tmp_buf + tmp_len, buffer, num);
-                     tmp_len += num;
+                     len = ends ? ends - buffer : buffer_limit - buffer;
+                     sb_add_buffer (&sbuf, buffer, len);
                    }
                  while (!ends);
-
-                 input_line_pointer = ends ? ends + 8 : NULL;
-
-                 s = tmp_buf;
-                 ends = s + tmp_len;
-
-               }
-             else
-               {
-                 input_line_pointer = ends + 8;
-               }
-
-             scrub_string = s;
-             scrub_string_end = ends;
-
-             new_length = ends - s;
-             new_buf = XNEWVEC (char, new_length);
-             new_tmp = new_buf;
-             for (;;)
-               {
-                 size_t space;
-                 size_t size;
-
-                 space = (new_buf + new_length) - new_tmp;
-                 size = do_scrub_chars (scrub_from_string, new_tmp, space);
-
-                 if (size < space)
-                   {
-                     new_tmp[size] = 0;
-                     new_length = new_tmp + size - new_buf;
-                     break;
-                   }
-
-                 new_buf = XRESIZEVEC (char, new_buf, new_length + 100);
-                 new_tmp = new_buf + new_length;
-                 new_length += 100;
                }
 
-             free (tmp_buf);
-
-             /* We've "scrubbed" input to the preferred format.  In the
-                process we may have consumed the whole of the remaining
-                file (and included files).  We handle this formatted
-                input similar to that of macro expansion, letting
-                actual macro expansion (possibly nested) and other
-                input expansion work.  Beware that in messages, line
-                numbers and possibly file names will be incorrect.  */
-             sb_build (&sbuf, new_length);
-             sb_add_buffer (&sbuf, new_buf, new_length);
+             input_line_pointer = ends ? ends + 8 : NULL;
              input_scrub_include_sb (&sbuf, input_line_pointer, expanding_none);
              sb_kill (&sbuf);
              buffer_limit = input_scrub_next_buffer (&input_line_pointer);
-             free (new_buf);
              continue;
            }
 
@@ -1780,6 +1650,7 @@ read_symbol_name (void)
     {
       as_bad (_("expected symbol name"));
       ignore_rest_of_line ();
+      free (start);
       return NULL;
     }
 
@@ -2047,6 +1918,14 @@ get_linefile_number (int *flag)
   if (*input_line_pointer < '0' || *input_line_pointer > '9')
     return false;
 
+  /* Don't mistakenly interpret octal numbers as line numbers.  */
+  if (*input_line_pointer == '0')
+    {
+      *flag = 0;
+      ++input_line_pointer;
+      return true;
+    }
+
   expression_and_evaluate (&exp);
   if (exp.X_op != O_constant)
     return false;
@@ -2789,10 +2668,10 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
        }
 
       if (((NO_PSEUDO_DOT || flag_m68k_mri)
-          && po_entry_find (po_hash, name) != NULL)
+          && str_hash_find (po_hash, name) != NULL)
          || (!flag_m68k_mri
              && *name == '.'
-             && po_entry_find (po_hash, name + 1) != NULL))
+             && str_hash_find (po_hash, name + 1) != NULL))
        as_warn_where (file,
                 line,
                 _("attempt to redefine pseudo-op `%s' ignored"),
@@ -6000,8 +5879,7 @@ s_include (int arg ATTRIBUTE_UNUSED)
     }
 
   demand_empty_rest_of_line ();
-  path = XNEWVEC (char, (unsigned long) i
-                 + include_dir_maxlen + 5 /* slop */ );
+  path = notes_alloc ((size_t) i + include_dir_maxlen + 5);
 
   for (i = 0; i < include_dir_count; i++)
     {
@@ -6015,10 +5893,9 @@ s_include (int arg ATTRIBUTE_UNUSED)
        }
     }
 
-  free (path);
+  notes_free (path);
   path = filename;
  gotit:
-  /* malloc Storage leak when file is found on path.  FIXME-SOMEDAY.  */
   register_dependency (path);
   input_scrub_insert_file (path);
 }