texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[8321] parsetexi keep references to file names


From: gavinsmith0123
Subject: [8321] parsetexi keep references to file names
Date: Thu, 18 Oct 2018 04:31:23 -0400 (EDT)

Revision: 8321
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=8321
Author:   gavin
Date:     2018-10-18 04:31:22 -0400 (Thu, 18 Oct 2018)
Log Message:
-----------
parsetexi keep references to file names

Modified Paths:
--------------
    trunk/tp/Texinfo/XS/parsetexi/api.c
    trunk/tp/Texinfo/XS/parsetexi/end_line.c
    trunk/tp/Texinfo/XS/parsetexi/input.c
    trunk/tp/Texinfo/XS/parsetexi/input.h
    trunk/tp/Texinfo/XS/parsetexi/parser.c
    trunk/tp/Texinfo/XS/parsetexi/tree.c

Modified: trunk/tp/Texinfo/XS/parsetexi/api.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/api.c 2018-10-17 21:48:14 UTC (rev 8320)
+++ trunk/tp/Texinfo/XS/parsetexi/api.c 2018-10-18 08:31:22 UTC (rev 8321)
@@ -65,6 +65,7 @@
   reset_internal_xrefs ();
   reset_labels ();
   input_reset_input_stack ();
+  free_small_strings ();
   reset_conf ();
 
   current_node = current_section = current_part = 0;

Modified: trunk/tp/Texinfo/XS/parsetexi/end_line.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/end_line.c    2018-10-17 21:48:14 UTC (rev 
8320)
+++ trunk/tp/Texinfo/XS/parsetexi/end_line.c    2018-10-18 08:31:22 UTC (rev 
8321)
@@ -794,48 +794,6 @@
 #undef ADD_ARG
 }
 
-/* Return a new element whose contents are the same as those of ORIGINAL,
-   but with some elements representing empty spaces removed. */
-ELEMENT *
-trim_spaces_comment_from_content (ELEMENT *original)
-{
-  ELEMENT *trimmed;
-  int i, j, k;
-  enum element_type t;
-
-  trimmed = new_element (ET_NONE);
-  trimmed->parent_type = route_not_in_tree;
-
-  if (original->contents.number == 0)
-    return trimmed;
-
-  i = 1;
-  t = original->contents.list[0]->type;
-  if (t != ET_empty_line_after_command
-      && t != ET_empty_spaces_after_command
-      && t != ET_empty_spaces_before_argument
-      && t != ET_empty_space_at_end_def_bracketed
-      && t != ET_empty_spaces_after_close_brace)
-    i = 0;
-
-  for (j = original->contents.number - 1; j >= 0; j--)
-    {
-      enum element_type t = original->contents.list[j]->type;
-      if (original->contents.list[j]->cmd != CM_c
-          && original->contents.list[j]->cmd != CM_comment
-          && t != ET_spaces_at_end
-          && t != ET_space_at_end_block_command)
-        break;
-    }
-  for (k = i; k <= j; k++)
-    {
-      add_to_contents_as_array (trimmed, original->contents.list[k]);
-    }
-
-  return trimmed;
-}
-
-// 2257
 /* NODE->contents is the Texinfo for the specification of a node.  This
    function sets three fields on the returned object:
 
@@ -861,7 +819,6 @@
   result = malloc (sizeof (NODE_SPEC_EXTRA));
   result->manual_content = result->node_content = 0;
 
-
   /* If the content starts with a '(', try to get a manual name. */
   if (node->contents.number > 0 && node->contents.list[0]->text.end > 0
       && node->contents.list[0]->text.text[0] == '(')

Modified: trunk/tp/Texinfo/XS/parsetexi/input.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/input.c       2018-10-17 21:48:14 UTC (rev 
8320)
+++ trunk/tp/Texinfo/XS/parsetexi/input.c       2018-10-18 08:31:22 UTC (rev 
8321)
@@ -401,9 +401,10 @@
           if (file != stdin)
             {
               if (fclose (input_stack[input_number - 1].file) == EOF)
-                abort (); // error
+                abort (); // FIXME: error
             }
         }
+
       input_number--;
     }
   return 0;
@@ -429,12 +430,51 @@
   if (!macro)
     line_number--;
   input_stack[input_number].line_nr.line_nr = line_number;
-  input_stack[input_number].line_nr.file_name
-                                       = filename ? strdup (filename) : 0;
-  input_stack[input_number].line_nr.macro = macro ? strdup (macro) : 0;
+  input_stack[input_number].line_nr.file_name = save_string (filename);
+  input_stack[input_number].line_nr.macro = save_string (macro);
   input_number++;
 }
 
+/* For filenames and macro names, it is possible that they won't be referenced 
+   in the line number of any element.  It would be too much work to keep 
track, 
+   so just keep them all here, and free them all together at the end. */
+static char **small_strings;
+static size_t small_strings_num;
+static size_t small_strings_space;
+
+char *
+save_string (char *string)
+{
+  char *ret = string ? strdup (string) : 0;
+  if (ret)
+    {
+      if (small_strings_num == small_strings_space)
+        {
+          small_strings_space++;
+          small_strings_space += (small_strings_space >> 2);
+          small_strings = realloc (small_strings, small_strings_space
+                                   * sizeof (char *));
+          if (!small_strings)
+            abort ();
+        }
+      small_strings[small_strings_num++] = ret;
+    }
+  return ret;
+}
+
+/* Called in reset_parser. */
+void
+free_small_strings (void)
+{
+  size_t i;
+  for (i = 0; i < small_strings_num; i++)
+    {
+      free (small_strings[i]);
+    }
+  small_strings_num = 0;
+}
+
+
 /* Store TEXT as a source for Texinfo content.  TEXT should be a UTF-8
    string.  TEXT will be later free'd and must be allocated on the heap.
    MACRO is the name of a macro that the text came from. */

Modified: trunk/tp/Texinfo/XS/parsetexi/input.h
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/input.h       2018-10-17 21:48:14 UTC (rev 
8320)
+++ trunk/tp/Texinfo/XS/parsetexi/input.h       2018-10-18 08:31:22 UTC (rev 
8321)
@@ -12,6 +12,9 @@
 int top_file_index (void);
 char *locate_include_file (char *filename);
 
+char *save_string (char *string);
+void free_small_strings (void);
+
 extern LINE_NR line_nr;
 
 extern int input_number;

Modified: trunk/tp/Texinfo/XS/parsetexi/parser.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/parser.c      2018-10-17 21:48:14 UTC (rev 
8320)
+++ trunk/tp/Texinfo/XS/parsetexi/parser.c      2018-10-18 08:31:22 UTC (rev 
8321)
@@ -249,6 +249,8 @@
   global_kbdinputstyle = kbd_distinct;
   global_documentlanguage = "";
 
+  free (global_info.footnotes.contents.list);
+
 #define GLOBAL_CASE(cmx) \
   free (global_info.cmx.contents.list)
 
@@ -1787,7 +1789,7 @@
 #if 0
       else
         {
-          /* error: unknown command */
+          /* TODO: error: unknown command */
         }
 #endif
     }
@@ -1864,7 +1866,8 @@
 parse_texi (ELEMENT *root_elt)
 {
   ELEMENT *current = root_elt;
-  char *allocated_line = 0, *line;
+  static char *allocated_line;
+  char *line;
 
   /* Read input file line-by-line. */
   while (1)
@@ -1942,7 +1945,7 @@
         current = current->parent;
     }
 
-  /* Check for "unclosed stacks". */
+  /* TODO: Check for "unclosed stacks". */
 
   return current;
 } /* 5372 */

Modified: trunk/tp/Texinfo/XS/parsetexi/tree.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/tree.c        2018-10-17 21:48:14 UTC (rev 
8320)
+++ trunk/tp/Texinfo/XS/parsetexi/tree.c        2018-10-18 08:31:22 UTC (rev 
8321)
@@ -91,11 +91,6 @@
                 destroy_element (nse->manual_content);
               if (nse->node_content)
                 destroy_element (nse->node_content);
-              /* Problem - some of the elements in 'node_content' may not
-                 have been in the main tree and need to be freed as well.
-                 We can't rely on checking whether the elements are 
-                 'route_not_in_tree' as the elements may have been freed 
-                 already. */
               free (nse);
               break;
             }
@@ -111,7 +106,6 @@
                   if ((*nse)->node_content)
                     destroy_element ((*nse)->node_content);
                   free (*nse);
-                  /* FIXME: same problem as above */
                 }
               free (array);
               break;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]