texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Setup an empty document early instead of storing


From: Patrice Dumas
Subject: branch master updated: Setup an empty document early instead of storing variables at the end
Date: Sat, 18 May 2024 03:19:02 -0400

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 6c83565e75 Setup an empty document early instead of storing variables 
at the end
6c83565e75 is described below

commit 6c83565e759c9cb4b92fa95daf4a4e8a807894ac
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat May 18 08:28:26 2024 +0200

    Setup an empty document early instead of storing variables at the end
    
    * tp/Texinfo/XS/main/document.c (new_document),
    tp/Texinfo/XS/parsetexi/api.c (reset_parser_except_conf, parse_file)
    (parse_text, parse_string, parse_piece),
    tp/Texinfo/XS/parsetexi/end_line.c (parse_line_command_args)
    (end_line_starting_block, end_line_misc_line),
    tp/Texinfo/XS/parsetexi/errors_parser.c (line_error_internal),
    tp/Texinfo/XS/parsetexi/handle_commands.c (handle_line_command),
    (handle_block_command), tp/Texinfo/XS/parsetexi/indices.c
    (add_index_internal, add_index, init_index_commands)
    (enter_index_entry, forget_indices, resolve_indices_merged_in),
    tp/Texinfo/XS/parsetexi/input.c (set_input_encoding, encode_file_name)
    (save_string), tp/Texinfo/XS/parsetexi/labels.c (register_label)
    (remember_internal_xref), tp/Texinfo/XS/parsetexi/macro.c
    (store_value, clear_value), tp/Texinfo/XS/parsetexi/parser.c
    (parsed_document, register_global_command)
    (wipe_parser_global_variables, rearrange_tree_beginning)
    (parse_texi_document, parse_texi), tp/Texinfo/XS/parsetexi/separator.c
    (handle_close_brace),
    tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs (copy_tree):
    setup a document global variable named parsed_document early on in
    parsing functions, parse_file, parse_text, parse_string and
    parse_piece and use the document structure for information that end up
    in the document instead of using global variables that are stored at
    the end of parsing.  Add new_document to create an empty document
    and remove store_document, now unused.  Add a document_descriptor
    argument to rearrange_tree_beginning.  Rename wipe_parser_global_info
    as wipe_parser_global_variables.  Remove register_document,
    wipe_errors, forget_errors, forget_small_strings, free_small_strings,
    reset_labels, forget_labels, wipe_identifiers_target,
    reset_internal_xrefs and forget_internal_xrefs functions and
    parser_float_list, error_messages_list, global_info, index_names,
    small_strings, labels_list, identifiers_target, internal_xref_list and
    global_commands global variables as parsed_document is directly used.
---
 ChangeLog                                          |  38 +++++
 tp/Texinfo/XS/main/document.c                      |  59 +++----
 tp/Texinfo/XS/main/document.h                      |  10 +-
 tp/Texinfo/XS/main/document_types.h                |   1 +
 tp/Texinfo/XS/main/utils.c                         |   1 -
 tp/Texinfo/XS/parsetexi/api.c                      |  52 +++---
 tp/Texinfo/XS/parsetexi/end_line.c                 |  27 +--
 tp/Texinfo/XS/parsetexi/errors_parser.c            |  18 +-
 tp/Texinfo/XS/parsetexi/errors_parser.h            |   3 -
 tp/Texinfo/XS/parsetexi/handle_commands.c          |  16 +-
 tp/Texinfo/XS/parsetexi/indices.c                  |  30 ++--
 tp/Texinfo/XS/parsetexi/indices.h                  |   2 -
 tp/Texinfo/XS/parsetexi/input.c                    |  54 +-----
 tp/Texinfo/XS/parsetexi/input.h                    |   5 -
 tp/Texinfo/XS/parsetexi/labels.c                   |  78 ++-------
 tp/Texinfo/XS/parsetexi/labels.h                   |   7 +-
 tp/Texinfo/XS/parsetexi/macro.c                    |  20 ++-
 tp/Texinfo/XS/parsetexi/parser.c                   | 181 ++++-----------------
 tp/Texinfo/XS/parsetexi/parser.h                   |  16 +-
 tp/Texinfo/XS/parsetexi/separator.c                |   5 +-
 .../XS/structuring_transfo/StructuringTransfoXS.xs |   6 +-
 21 files changed, 219 insertions(+), 410 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 94b4d81054..d7b2b3a4fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,41 @@
+2024-05-18  Patrice Dumas  <pertusus@free.fr>
+
+       Setup an empty document early instead of storing variables at the end
+
+       * tp/Texinfo/XS/main/document.c (new_document),
+       tp/Texinfo/XS/parsetexi/api.c (reset_parser_except_conf, parse_file)
+       (parse_text, parse_string, parse_piece),
+       tp/Texinfo/XS/parsetexi/end_line.c (parse_line_command_args)
+       (end_line_starting_block, end_line_misc_line),
+       tp/Texinfo/XS/parsetexi/errors_parser.c (line_error_internal),
+       tp/Texinfo/XS/parsetexi/handle_commands.c (handle_line_command),
+       (handle_block_command), tp/Texinfo/XS/parsetexi/indices.c
+       (add_index_internal, add_index, init_index_commands)
+       (enter_index_entry, forget_indices, resolve_indices_merged_in),
+       tp/Texinfo/XS/parsetexi/input.c (set_input_encoding, encode_file_name)
+       (save_string), tp/Texinfo/XS/parsetexi/labels.c (register_label)
+       (remember_internal_xref), tp/Texinfo/XS/parsetexi/macro.c
+       (store_value, clear_value), tp/Texinfo/XS/parsetexi/parser.c
+       (parsed_document, register_global_command)
+       (wipe_parser_global_variables, rearrange_tree_beginning)
+       (parse_texi_document, parse_texi), tp/Texinfo/XS/parsetexi/separator.c
+       (handle_close_brace),
+       tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs (copy_tree):
+       setup a document global variable named parsed_document early on in
+       parsing functions, parse_file, parse_text, parse_string and
+       parse_piece and use the document structure for information that end up
+       in the document instead of using global variables that are stored at
+       the end of parsing.  Add new_document to create an empty document
+       and remove store_document, now unused.  Add a document_descriptor
+       argument to rearrange_tree_beginning.  Rename wipe_parser_global_info
+       as wipe_parser_global_variables.  Remove register_document,
+       wipe_errors, forget_errors, forget_small_strings, free_small_strings,
+       reset_labels, forget_labels, wipe_identifiers_target,
+       reset_internal_xrefs and forget_internal_xrefs functions and
+       parser_float_list, error_messages_list, global_info, index_names,
+       small_strings, labels_list, identifiers_target, internal_xref_list and
+       global_commands global variables as parsed_document is directly used.
+
 2024-05-17  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/ParserNonXS.pm (_initialize_parsing, _enter_index_entry):
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index 94383e7c42..3a74b91ac3 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -50,27 +50,17 @@ retrieve_document (int document_descriptor)
   return 0;
 }
 
+/* note that the returned document will become invalid if there is a
+   realloc of the documents list */
 /* descriptor starts at 1, 0 is an error */
-size_t
-register_document (ELEMENT *root, INDEX **index_names,
-                   FLOAT_RECORD_LIST *floats_list,
-                   ELEMENT_LIST *internal_references,
-                   LABEL_LIST *labels_list,
-                   LABEL_LIST *identifiers_target,
-                   GLOBAL_INFO *global_info,
-                   GLOBAL_COMMANDS *global_commands,
-                   STRING_LIST *small_strings,
-                   ERROR_MESSAGE_LIST *parser_error_messages)
+DOCUMENT *
+new_document (void)
 {
   size_t document_index;
   int slot_found = 0;
   DOCUMENT *document = 0;
   int i;
 
-  /* error? */
-  if (root == 0)
-    return 0;
-
   for (i = 0; i < document_number; i++)
     {
       if (document_list[i].tree == 0)
@@ -92,34 +82,45 @@ register_document (ELEMENT *root, INDEX **index_names,
       document_number++;
     }
   document = &document_list[document_index];
-  /* this initializes the other fields */
   memset (document, 0, sizeof (DOCUMENT));
   document->descriptor = document_index +1;
-  document->tree = root;
-  document->index_names = index_names;
-  document->floats = floats_list;
-  document->internal_references = internal_references;
-  document->labels_list = labels_list;
-  document->identifiers_target = identifiers_target;
-  document->global_info = global_info;
-  document->global_commands = global_commands;
-  document->small_strings = small_strings;
-  document->parser_error_messages = parser_error_messages;
+
+  /* Information that is not local to where it is set in the Texinfo input,
+   for example document language and encoding. */
+  document->global_info = malloc (sizeof (GLOBAL_INFO));
+  memset (document->global_info, 0, sizeof (GLOBAL_INFO));
+
+  document->global_commands = malloc (sizeof (GLOBAL_COMMANDS));
+  memset (document->global_commands, 0, sizeof (GLOBAL_COMMANDS));
+  document->labels_list = malloc (sizeof (LABEL_LIST));
+  memset (document->labels_list, 0, sizeof (LABEL_LIST));
+  /* Array of recorded @float's. */
+  document->floats = malloc (sizeof (FLOAT_RECORD_LIST));
+  memset (document->floats, 0, sizeof (FLOAT_RECORD_LIST));
+  document->internal_references = malloc (sizeof (ELEMENT_LIST));
+  memset (document->internal_references, 0, sizeof (ELEMENT_LIST));
+  /* 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. */
+  document->small_strings = new_string_list ();
+
+  document->parser_error_messages = malloc (sizeof (ERROR_MESSAGE_LIST));
+  memset (document->parser_error_messages, 0, sizeof (ERROR_MESSAGE_LIST));
   document->error_messages = malloc (sizeof (ERROR_MESSAGE_LIST));
   memset (document->error_messages, 0, sizeof (ERROR_MESSAGE_LIST));
 
-  document->listoffloats = float_list_to_listoffloats_list (floats_list);
-
   document->modified_information |= F_DOCM_tree | F_DOCM_index_names
      | F_DOCM_floats | F_DOCM_internal_references | F_DOCM_labels_list
      | F_DOCM_identifiers_target | F_DOCM_global_info
      | F_DOCM_global_commands;
 
   /*
-  fprintf (stderr, "REGISTER %zu %p %p %p %p\n", document_index +1, document,
-                       document->tree, document->index_names, 
document->options);
+  fprintf (stderr, "DOCUMENT %zu %p\n", document_index +1, document);
    */
+  /*
   return document_index +1;
+   */
+  return document;
 }
 
 void
diff --git a/tp/Texinfo/XS/main/document.h b/tp/Texinfo/XS/main/document.h
index fa8f1fe8bd..3aa709928a 100644
--- a/tp/Texinfo/XS/main/document.h
+++ b/tp/Texinfo/XS/main/document.h
@@ -13,15 +13,7 @@ struct TEXT_OPTIONS;
 
 
 DOCUMENT *retrieve_document (int document_descriptor);
-size_t register_document (ELEMENT *root, INDEX **index_names,
-                          FLOAT_RECORD_LIST *floats_list,
-                          ELEMENT_LIST *internal_references,
-                          LABEL_LIST *labels_list,
-                          LABEL_LIST *identifiers_target,
-                          GLOBAL_INFO *global_info,
-                          GLOBAL_COMMANDS *global_commands,
-                          STRING_LIST *small_strings,
-                          ERROR_MESSAGE_LIST *parser_error_messages);
+DOCUMENT *new_document (void);
 void register_document_nodes_list (DOCUMENT *document,
                                    ELEMENT_LIST *nodes_list);
 void register_document_sections_list (DOCUMENT *document,
diff --git a/tp/Texinfo/XS/main/document_types.h 
b/tp/Texinfo/XS/main/document_types.h
index 0dfbe7f161..c74bbe100c 100644
--- a/tp/Texinfo/XS/main/document_types.h
+++ b/tp/Texinfo/XS/main/document_types.h
@@ -178,6 +178,7 @@ typedef struct DOCUMENT {
     LISTOFFLOATS_TYPE_LIST *listoffloats;
     ELEMENT_LIST *internal_references;
     LABEL_LIST *labels_list;
+  /* Array of target elements with unique identifiers, sorted by identifier */
     LABEL_LIST *identifiers_target;
     GLOBAL_INFO *global_info;
     GLOBAL_COMMANDS *global_commands;
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 03f777f455..7a99b8eaa3 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -1004,7 +1004,6 @@ clear_strings_list (STRING_LIST *strings)
   strings->number = 0;
 }
 
-/* very similar to parsetexi/input.c free_small_strings */
 void
 free_strings_list (STRING_LIST *strings)
 {
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index 334adf00b9..159017088f 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -28,15 +28,9 @@
 #include "debug_parser.h"
 /* reset_obstacks */
 #include "tree.h"
-/* wipe_index_names */
-#include "utils.h"
 /* for parser_add_include_directory, set_input_file_name_encoding ... */
 #include "input.h"
 #include "source_marks.h"
-/* wipe_identifiers_target */
-#include "labels.h"
-/* forget_indices init_index_commands */
-#include "indices.h"
 #include "errors.h"
 /* for wipe_user_commands */
 #include "commands.h"
@@ -46,6 +40,7 @@
 #include "handle_commands.h"
 /* for wipe_macros and store_value */
 #include "macro.h"
+#include "document.h"
 /* for reset_conf */
 #include "conf.h"
 #include "api.h"
@@ -60,21 +55,11 @@
 void
 reset_parser_except_conf (void)
 {
-  /* parser structures registered in document are reset by the
-     call to store_document, except for global info that is only
-     copied */
-  wipe_parser_global_info ();
+  wipe_parser_global_variables ();
 
   wipe_user_commands ();
   wipe_macros ();
-  /* index_names are forgotten in store_document, however, there
-     can be two calls of reset_parser_except_conf without a call to
-     store_document inbetween, for that case there need to be a call to
-     wipe_index_names and forget_indices before init_index_commands.
-  */
-  wipe_index_names (index_names);
-  forget_indices ();
-  wipe_identifiers_target ();
+
   reset_context_stack ();
   reset_command_stack (&nesting_context.basic_inline_stack);
   reset_command_stack (&nesting_context.basic_inline_stack_on_line);
@@ -86,7 +71,6 @@ reset_parser_except_conf (void)
      list to avoid memory leaks rather than reuse the iconv
      opened handlers */
   parser_reset_encoding_list ();
-  set_input_encoding ("utf-8");
   source_marks_reset_counters ();
 
   reset_obstacks ();
@@ -134,17 +118,26 @@ parse_file (const char *filename, const char 
*input_file_name,
 {
   int document_descriptor;
   char *p, *q;
+  GLOBAL_INFO *global_info;
 
   int status;
 
+  parsed_document = new_document ();
+  set_input_encoding ("utf-8");
+
   status = input_push_file (filename);
   if (status)
-    return 0;
+    {
+      remove_document_descriptor (parsed_document->descriptor);
+      return 0;
+    }
+
+  global_info = parsed_document->global_info;
 
-  free (global_info.input_file_name);
-  free (global_info.input_directory);
-  global_info.input_file_name = strdup (input_file_name);
-  global_info.input_directory = strdup (input_directory);
+  free (global_info->input_file_name);
+  free (global_info->input_directory);
+  global_info->input_file_name = strdup (input_file_name);
+  global_info->input_directory = strdup (input_directory);
 
   /* Strip off a leading directory path, by looking for the last
      '/' in filename. */
@@ -176,6 +169,10 @@ parse_text (const char *string, int line_nr)
   int document_descriptor;
 
   reset_parser_except_conf ();
+
+  parsed_document = new_document ();
+  set_input_encoding ("utf-8");
+
   input_push_text (strdup (string), line_nr, 0, 0);
   document_descriptor = parse_texi_document ();
   return document_descriptor;
@@ -192,6 +189,10 @@ parse_string (const char *string, int line_nr)
 
   reset_parser_except_conf ();
   root_elt = new_element (ET_root_line);
+
+  parsed_document = new_document ();
+  set_input_encoding ("utf-8");
+
   input_push_text (strdup (string), line_nr, 0, 0);
   document_descriptor = parse_texi (root_elt, root_elt);
   return document_descriptor;
@@ -208,6 +209,9 @@ parse_piece (const char *string, int line_nr)
   before_node_section = setup_document_root_and_before_node_section ();
   document_root = before_node_section->parent;
 
+  parsed_document = new_document ();
+  set_input_encoding ("utf-8");
+
   input_push_text (strdup (string), line_nr, 0, 0);
   document_descriptor = parse_texi (document_root, before_node_section);
   return document_descriptor;
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c 
b/tp/Texinfo/XS/parsetexi/end_line.c
index 19922d2dfb..9d29674807 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -408,8 +408,10 @@ parse_line_command_args (ELEMENT *line_command)
             break;
           }
 
-        from_index = indices_info_index_by_name (index_names, index_name_from);
-        to_index = indices_info_index_by_name (index_names, index_name_to);
+        from_index = indices_info_index_by_name (parsed_document->index_names,
+                                                 index_name_from);
+        to_index = indices_info_index_by_name (parsed_document->index_names,
+                                               index_name_to);
         if (!from_index)
           line_error ("unknown source index in @%s: %s",
                       command_name(cmd), index_name_from);
@@ -459,7 +461,8 @@ parse_line_command_args (ELEMENT *line_command)
           {}
         else
           {
-            INDEX *idx = indices_info_index_by_name (index_names,arg);
+            INDEX *idx
+             = indices_info_index_by_name (parsed_document->index_names, arg);
             if (!idx)
               line_error ("unknown index `%s' in @printindex", arg);
             else
@@ -662,10 +665,6 @@ parse_line_command_args (ELEMENT *line_command)
 #undef ADD_ARG
 }
 
-/* Array of recorded @float's. */
-FLOAT_RECORD_LIST parser_float_list = {0, 0, 0};
-
-
 ELEMENT *
 end_line_def_line (ELEMENT *current)
 {
@@ -877,7 +876,7 @@ end_line_starting_block (ELEMENT *current)
       float_type = parse_float_type (current);
 
       /* add to global 'floats' array */
-      add_to_float_record_list (&parser_float_list, float_type, current);
+      add_to_float_record_list (parsed_document->floats, float_type, current);
 
       if (current_section)
         add_extra_element (current, "float_section", current_section);
@@ -1306,6 +1305,7 @@ end_line_misc_line (ELEMENT *current)
             {
               int status;
               char *fullpath, *sys_filename;
+              GLOBAL_INFO *global_info = parsed_document->global_info;
 
               sys_filename = encode_file_name (text);
               fullpath = parser_locate_include_file (sys_filename);
@@ -1336,7 +1336,7 @@ end_line_misc_line (ELEMENT *current)
                       include_source_mark = new_source_mark (SM_type_include);
                       include_source_mark->status = SM_status_start;
                       set_input_source_mark (include_source_mark);
-                      add_string (fullpath, &global_info.included_files);
+                      add_string (fullpath, &global_info->included_files);
                     }
                   free (fullpath);
                 }
@@ -1344,16 +1344,17 @@ end_line_misc_line (ELEMENT *current)
           else if (current->cmd == CM_verbatiminclude)
             {
               char *fullpath, *sys_filename;
+              GLOBAL_INFO *global_info = parsed_document->global_info;
 
-              if (global_info.input_encoding_name)
+              if (global_info->input_encoding_name)
                 add_extra_string_dup (current, "input_encoding_name",
-                                      global_info.input_encoding_name);
+                                      global_info->input_encoding_name);
               /* gather included file for 'included_files'.  No errors, they
                  should be output by converters */
               sys_filename = encode_file_name (text);
               fullpath = parser_locate_include_file (sys_filename);
               if (fullpath && access (fullpath, R_OK) == 0)
-                add_string (fullpath, &global_info.included_files);
+                add_string (fullpath, &global_info->included_files);
               free (fullpath);
             }
           else if (current->cmd == CM_documentencoding)
@@ -1458,7 +1459,7 @@ end_line_misc_line (ELEMENT *current)
                     }
 
                   /* set_input_encoding also sets
-                     global_info.input_encoding_name */
+                     global_info->input_encoding_name */
                   encoding_set = set_input_encoding (input_encoding);
                   if (encoding_set)
                     {
diff --git a/tp/Texinfo/XS/parsetexi/errors_parser.c 
b/tp/Texinfo/XS/parsetexi/errors_parser.c
index 150fba5465..eca9932439 100644
--- a/tp/Texinfo/XS/parsetexi/errors_parser.c
+++ b/tp/Texinfo/XS/parsetexi/errors_parser.c
@@ -28,6 +28,7 @@
 
 #include "tree_types.h"
 #include "document_types.h"
+#include "parser.h"
 /* for debug_output */
 #include "debug_parser.h"
 #include "errors.h"
@@ -37,14 +38,12 @@
 /* Current filename and line number.  Used for reporting. */
 SOURCE_INFO current_source_info;
 
-ERROR_MESSAGE_LIST error_messages_list;
-
 static void
 line_error_internal (enum error_type type, int continuation,
                      const SOURCE_INFO *cmd_source_info,
                      const char *format, va_list v)
 {
-  vmessage_list_line_error (&error_messages_list,
+  vmessage_list_line_error (parsed_document->parser_error_messages,
                       type, continuation, debug_output, cmd_source_info,
                       0, format, v);
 }
@@ -96,19 +95,6 @@ command_error (const ELEMENT *e, const char *format, ...)
   line_error_internal (MSG_error, 0, &e->source_info, format, v);
 }
 
-/* not used */
-void
-wipe_errors (void)
-{
-  wipe_error_message_list (&error_messages_list);
-}
-
-void
-forget_errors (void)
-{
-  memset (&error_messages_list, 0, sizeof (ERROR_MESSAGE_LIST));
-}
-
 static void
 bug_message_internal (char *format, va_list v)
 {
diff --git a/tp/Texinfo/XS/parsetexi/errors_parser.h 
b/tp/Texinfo/XS/parsetexi/errors_parser.h
index 45477720b9..dc1c80a618 100644
--- a/tp/Texinfo/XS/parsetexi/errors_parser.h
+++ b/tp/Texinfo/XS/parsetexi/errors_parser.h
@@ -11,14 +11,11 @@ void line_error (const char *format, ...);
 void line_warn (const char *format, ...);
 void command_error (const ELEMENT *e, const char *format, ...);
 void command_warn (const ELEMENT *e, const char *format, ...);
-void wipe_errors (void);
-void forget_errors (void);
 void line_error_ext (enum error_type type, int continuation,
                      const SOURCE_INFO *cmd_source_info,
                      const char *format, ...);
 void bug_message (char *format, ...);
 
-extern ERROR_MESSAGE_LIST error_messages_list;
 extern SOURCE_INFO current_source_info;
 
 #endif
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.c 
b/tp/Texinfo/XS/parsetexi/handle_commands.c
index 8438445136..7de7f49003 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.c
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.c
@@ -698,11 +698,11 @@ handle_line_command (ELEMENT *current, char **line_inout,
 
       if (cmd == CM_raisesections)
         {
-          global_info.sections_level_modifier++;
+          parsed_document->global_info->sections_level_modifier++;
         }
       else if (cmd == CM_lowersections)
         {
-          global_info.sections_level_modifier--;
+          parsed_document->global_info->sections_level_modifier--;
         }
 
       if (command_e)
@@ -825,10 +825,11 @@ handle_line_command (ELEMENT *current, char **line_inout,
 
           if (command_data(data_cmd).flags & CF_sectioning_heading)
             {
-              if (global_info.sections_level_modifier)
+              GLOBAL_INFO *global_info = parsed_document->global_info;
+              if (global_info->sections_level_modifier)
                 {
                   add_extra_integer (command_e, "level_modifier",
-                                     global_info.sections_level_modifier);
+                                     global_info->sections_level_modifier);
                 }
             }
 
@@ -969,7 +970,9 @@ handle_line_command (ELEMENT *current, char **line_inout,
   if (command_e)
     register_global_command (command_e);
   if (cmd == CM_dircategory)
-    add_to_element_list (&global_commands.dircategory_direntry, command_e);
+    add_to_element_list (&parsed_document->global_commands
+                                             ->dircategory_direntry,
+                         command_e);
 
 funexit:
   *line_inout = line;
@@ -1104,7 +1107,8 @@ handle_block_command (ELEMENT *current, char **line_inout,
           push_context (ct_preformatted, cmd);
 
           if (cmd == CM_direntry)
-            add_to_element_list (&global_commands.dircategory_direntry,
+            add_to_element_list (&parsed_document->global_commands
+                                                     ->dircategory_direntry,
                                  block);
 
           if (current_node)
diff --git a/tp/Texinfo/XS/parsetexi/indices.c 
b/tp/Texinfo/XS/parsetexi/indices.c
index 9503830c53..b2275ea404 100644
--- a/tp/Texinfo/XS/parsetexi/indices.c
+++ b/tp/Texinfo/XS/parsetexi/indices.c
@@ -41,7 +41,6 @@
 #include "parser.h"
 #include "indices.h"
 
-INDEX **index_names = 0;
 int number_of_indices = 0;
 int space_for_indices = 0;
 
@@ -110,11 +109,12 @@ add_index_internal (char *name, int in_code)
   if (number_of_indices == space_for_indices)
     {
       space_for_indices += 5;
-      index_names = realloc (index_names, (space_for_indices + 1)
-                             * sizeof (INDEX *));
+      parsed_document->index_names
+        = realloc (parsed_document->index_names, (space_for_indices + 1)
+                                                 * sizeof (INDEX *));
     }
-  index_names[number_of_indices++] = idx;
-  index_names[number_of_indices] = 0;
+  parsed_document->index_names[number_of_indices++] = idx;
+  parsed_document->index_names[number_of_indices] = 0;
   return idx;
 }
 
@@ -124,7 +124,7 @@ add_index_internal (char *name, int in_code)
 void
 add_index (const char *name, int in_code)
 {
-  INDEX *idx = indices_info_index_by_name (index_names, name);
+  INDEX *idx = indices_info_index_by_name (parsed_document->index_names, name);
   char *cmdname;
 
   if (!idx)
@@ -140,6 +140,7 @@ void
 init_index_commands (void)
 {
   INDEX *idx;
+  INDEX **index_names;
 
   struct def { char *name; int in_code;
                enum command_id cmd2; enum command_id cmd1;}
@@ -215,6 +216,8 @@ init_index_commands (void)
       associate_command_to_index (p->cmd2, idx);
       associate_command_to_index (p->cmd1, idx);
     }
+  /* set the variable now that the realloc have been done */
+  index_names = parsed_document->index_names;
 
   associate_command_to_index (CM_vtable,
     indices_info_index_by_name (index_names, "vr"));
@@ -252,6 +255,7 @@ enter_index_entry (enum command_id index_type_cmd,
   INDEX *idx;
   INDEX_ENTRY *entry;
   TEXT ignored_chars;
+  GLOBAL_INFO *global_info = parsed_document->global_info;
 
   if (conf.no_index)
     return;
@@ -275,13 +279,13 @@ enter_index_entry (enum command_id index_type_cmd,
 
   /* Create ignored_chars string. */
   text_init (&ignored_chars);
-  if (global_info.ignored_chars.backslash)
+  if (global_info->ignored_chars.backslash)
     text_append (&ignored_chars, "\\");
-  if (global_info.ignored_chars.hyphen)
+  if (global_info->ignored_chars.hyphen)
     text_append (&ignored_chars, "-");
-  if (global_info.ignored_chars.lessthan)
+  if (global_info->ignored_chars.lessthan)
     text_append (&ignored_chars, "<");
-  if (global_info.ignored_chars.atsign)
+  if (global_info->ignored_chars.atsign)
     text_append (&ignored_chars, "@");
   if (ignored_chars.end > 0)
     {
@@ -350,11 +354,9 @@ set_non_ignored_space_in_index_before_command (ELEMENT 
*content)
 
 
 
-/* reset indices without unallocating them nor the list of indices */
 void
 forget_indices (void)
 {
-  index_names = 0;
   number_of_indices = 0;
   space_for_indices = 0;
   num_index_commands = 0;
@@ -365,9 +367,9 @@ resolve_indices_merged_in (void)
 {
   INDEX **i, *idx;
 
-  if (index_names)
+  if (parsed_document->index_names)
     {
-      for (i = index_names; (idx = *i); i++)
+      for (i = parsed_document->index_names; (idx = *i); i++)
         {
           if (idx->merged_in)
             {
diff --git a/tp/Texinfo/XS/parsetexi/indices.h 
b/tp/Texinfo/XS/parsetexi/indices.h
index ac7cd6d471..f557f2aeea 100644
--- a/tp/Texinfo/XS/parsetexi/indices.h
+++ b/tp/Texinfo/XS/parsetexi/indices.h
@@ -4,8 +4,6 @@
 
 #include "tree_types.h"
 
-extern INDEX **index_names;
-
 void init_index_commands (void);
 
 void add_index (const char *name, int in_code);
diff --git a/tp/Texinfo/XS/parsetexi/input.c b/tp/Texinfo/XS/parsetexi/input.c
index f562d0d7e9..492d988e75 100644
--- a/tp/Texinfo/XS/parsetexi/input.c
+++ b/tp/Texinfo/XS/parsetexi/input.c
@@ -79,8 +79,9 @@ set_input_encoding (const char *encoding)
   if (current_encoding_conversion)
     {
       encoding_set = 1;
-      free (global_info.input_encoding_name);
-      global_info.input_encoding_name = strdup (encoding);
+      GLOBAL_INFO *global_info = parsed_document->global_info;
+      free (global_info->input_encoding_name);
+      global_info->input_encoding_name = strdup (encoding);
     }
 
   return encoding_set;
@@ -196,7 +197,7 @@ set_doc_encoding_for_input_file_name (int value)
 
 /* Reverse the decoding of the filename to the input encoding, to retrieve
    the bytes that were present in the original Texinfo file.  Return
-   value is freed by free_small_strings. */
+   value is freed when freeing small_strings. */
 char *
 encode_file_name (char *filename)
 {
@@ -209,7 +210,8 @@ encode_file_name (char *filename)
       else if (doc_encoding_for_input_file_name)
         {
           if (current_encoding_conversion
-              && strcmp (global_info.input_encoding_name, "utf-8"))
+              && strcmp (parsed_document->global_info->input_encoding_name,
+                         "utf-8"))
             {
               char *conversion_encoding
                 = current_encoding_conversion->encoding_name;
@@ -532,51 +534,13 @@ set_input_source_mark (SOURCE_MARK *source_mark)
   input_stack[input_number - 1].input_source_mark = source_mark;
 }
 
-/* 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. */
-char **small_strings = 0;
-size_t small_strings_num = 0;
-static size_t small_strings_space;
-
 char *
 save_string (const 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)
-            fatal ("realloc failed");
-        }
-      small_strings[small_strings_num++] = ret;
-    }
-  return ret;
-}
-
-void
-forget_small_strings (void)
-{
-  small_strings = 0;
-  small_strings_num = 0;
-  small_strings_space = 0;
-}
+  if (!string)
+    return 0;
 
-/* not used */
-void
-free_small_strings (void)
-{
-  size_t i;
-  for (i = 0; i < small_strings_num; i++)
-    {
-      free (small_strings[i]);
-    }
-  small_strings_num = 0;
+  return add_string (string, parsed_document->small_strings);
 }
 
 void
diff --git a/tp/Texinfo/XS/parsetexi/input.h b/tp/Texinfo/XS/parsetexi/input.h
index 6a58f5cef0..7bfb54f8b1 100644
--- a/tp/Texinfo/XS/parsetexi/input.h
+++ b/tp/Texinfo/XS/parsetexi/input.h
@@ -27,12 +27,7 @@ int set_input_encoding (const char *encoding);
 void parser_add_include_directory (const char *filename);
 void parser_clear_include_directories (void);
 
-extern char **small_strings;
-extern size_t small_strings_num;
-
 char *save_string (const char *string);
-void free_small_strings (void);
-void forget_small_strings (void);
 
 extern int input_number;
 extern int macro_expansion_nr;
diff --git a/tp/Texinfo/XS/parsetexi/labels.c b/tp/Texinfo/XS/parsetexi/labels.c
index b88e634375..e580d9e5a7 100644
--- a/tp/Texinfo/XS/parsetexi/labels.c
+++ b/tp/Texinfo/XS/parsetexi/labels.c
@@ -18,8 +18,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-/* definitions of labels_list, labels_number and identifiers_target
-   as extern are in parser.h */
 #include "parser.h"
 #include "tree_types.h"
 #include "tree.h"
@@ -34,50 +32,30 @@
 #include "extra.h"
 #include "labels.h"
 
-/* Array of recorded elements with labels space. */
-LABEL *labels_list = 0;
-size_t labels_number = 0;
-static size_t labels_space = 0;
-
-/* Array of target elements with unique identifiers, sorted by identifier */
-LABEL_LIST *identifiers_target = 0;
-
 /* Register a target element associated to a label that may be the target of
    a reference and must be unique in the document.  Corresponds to @node,
    @anchor, and @float (float label corresponds to the second argument). */
 void
 register_label (ELEMENT *target_element, char *normalized)
 {
+  LABEL_LIST *labels_list = parsed_document->labels_list;
+  LABEL *label;
   /* register the element in the list. */
-  if (labels_number == labels_space)
+  if (labels_list->number == labels_list->space)
     {
-      labels_space += 1;
-      labels_space *= 1.5;
-      labels_list = realloc (labels_list,
-                             labels_space * sizeof (LABEL));
+      labels_list->space += 1;
+      labels_list->space *= 1.5;
+      labels_list->list = realloc (labels_list->list,
+                                   labels_list->space * sizeof (LABEL));
       if (!labels_list)
         fatal ("realloc failed");
     }
-  labels_list[labels_number].element = target_element;
-  labels_list[labels_number].label_number = labels_number;
-  labels_list[labels_number].identifier = normalized;
-  labels_list[labels_number].reference = 0;
-  labels_number++;
-}
-
-/* not used */
-void
-reset_labels (void)
-{
-  labels_number = 0;
-}
-
-void
-forget_labels (void)
-{
-  labels_number = 0;
-  labels_space = 0;
-  labels_list = 0;
+  label = &labels_list->list[labels_list->number];
+  label->element = target_element;
+  label->label_number = labels_list->number;
+  label->identifier = normalized;
+  label->reference = 0;
+  labels_list->number++;
 }
 
 void
@@ -119,39 +97,11 @@ check_register_target_element_label (ELEMENT 
*label_element,
   register_label (target_element, normalized);
 }
 
-void
-wipe_identifiers_target (void)
-{
-  if (identifiers_target != 0)
-    {
-      free (identifiers_target->list);
-      free (identifiers_target);
-      identifiers_target = 0;
-    }
-}
-
 
 
-ELEMENT_LIST internal_xref_list = {0, 0, 0};
-
 void
 remember_internal_xref (ELEMENT *element)
 {
-  add_to_element_list (&internal_xref_list, element);
-}
-
-/* not used */
-void
-reset_internal_xrefs (void)
-{
-  internal_xref_list.number = 0;
-}
-
-void
-forget_internal_xrefs (void)
-{
-  internal_xref_list.number = 0;
-  internal_xref_list.space = 0;
-  internal_xref_list.list = 0;
+  add_to_element_list (parsed_document->internal_references, element);
 }
 
diff --git a/tp/Texinfo/XS/parsetexi/labels.h b/tp/Texinfo/XS/parsetexi/labels.h
index 36c4375d93..8beb048b24 100644
--- a/tp/Texinfo/XS/parsetexi/labels.h
+++ b/tp/Texinfo/XS/parsetexi/labels.h
@@ -23,16 +23,11 @@
 /* declaration of extern data is in parser.h to avoid exposure
    to code including labels.h */
 
-void reset_labels (void);
-void forget_labels (void);
 void check_register_target_element_label (ELEMENT *label_element,
                                           ELEMENT *target_element);
-void wipe_identifiers_target (void);
 
 
-extern ELEMENT_LIST internal_xref_list;
 
 void remember_internal_xref (ELEMENT *element);
-void reset_internal_xrefs (void);
-void forget_internal_xrefs (void);
+
 #endif
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index bb58a1749d..81739fcf11 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -1059,17 +1059,18 @@ store_value (const char *name, const char *value)
   v->value = strdup (value);
 
   /* Internal Texinfo flag */
-  if (!strncmp (name, "txi", 3))
+  if (!strncmp (name, "txi", 3) && parsed_document)
     {
+      GLOBAL_INFO *global_info = parsed_document->global_info;
       int val = (strcmp (value, "0") != 0);
       if (!strcmp (name, "txiindexbackslashignore"))
-        global_info.ignored_chars.backslash = val;
+        global_info->ignored_chars.backslash = val;
       else if (!strcmp (name, "txiindexhyphenignore"))
-        global_info.ignored_chars.hyphen = val;
+        global_info->ignored_chars.hyphen = val;
       else if (!strcmp (name, "txiindexlessthanignore"))
-        global_info.ignored_chars.lessthan = val;
+        global_info->ignored_chars.lessthan = val;
       else if (!strcmp (name, "txiindexatsignignore"))
-        global_info.ignored_chars.atsign = val;
+        global_info->ignored_chars.atsign = val;
 
       /* also: txicodequotebacktick, txicodequoteundirected,
          txicommandconditionals.  Deal with them here? */
@@ -1091,14 +1092,15 @@ clear_value (char *name)
   /* Internal Texinfo flag */
   if (!strncmp (name, "txi", 3))
     {
+      GLOBAL_INFO *global_info = parsed_document->global_info;
       if (!strcmp (name, "txiindexbackslashignore"))
-        global_info.ignored_chars.backslash = 0;
+        global_info->ignored_chars.backslash = 0;
       else if (!strcmp (name, "txiindexhyphenignore"))
-        global_info.ignored_chars.hyphen = 0;
+        global_info->ignored_chars.hyphen = 0;
       else if (!strcmp (name, "txiindexlessthanignore"))
-        global_info.ignored_chars.lessthan = 0;
+        global_info->ignored_chars.lessthan = 0;
       else if (!strcmp (name, "txiindexatsignignore"))
-        global_info.ignored_chars.atsign = 0;
+        global_info->ignored_chars.atsign = 0;
 
       /* also: txicodequotebacktick, txicodequoteundirected,
          txicommandconditionals.  Deal with them here? */
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index a74d7e7af7..cece03ec68 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -29,13 +29,11 @@
 /* for relocate_source_marks */
 #include "manipulate_tree.h"
 #include "debug_parser.h"
-/* error_messages_list forget_errors ... */
 #include "errors_parser.h"
 #include "text.h"
 #include "counter.h"
 #include "builtin_commands.h"
 #include "macro.h"
-/* forget_small_strings small_strings ... */
 #include "input.h"
 #include "source_marks.h"
 #include "extra.h"
@@ -47,12 +45,14 @@
 #include "commands.h"
 /* for labels_list labels_number forget_labels forget_internal_xrefs */
 #include "labels.h"
-/* for register_document */
+/* for retrieve_document */
 #include "document.h"
 /* for set_labels_identifiers_target */
 #include "targets.h"
-/* for complete_indices forget_indices */
+/* for forget_indices complete_indices */
 #include "indices.h"
+/* for float_list_to_listoffloats_list */
+#include "floats.h"
 #include "parser.h"
 
 
@@ -66,6 +66,9 @@ const char *linecommand_expansion_delimiters = 
WHITESPACE_CHARS_EXCEPT_NEWLINE
                                                "{}@";
 #undef WHITESPACE_CHARS_EXCEPT_NEWLINE
 
+DOCUMENT *parsed_document = 0;
+
+
 /* Check if the contents of S2 appear at S1). */
 int
 looking_at (char *s1, char *s2)
@@ -311,10 +314,6 @@ reset_parser_counters (void)
 }
 
 
-/* Information that is not local to where it is set in the Texinfo input,
-   for example document language and encoding. */
-GLOBAL_INFO global_info;
-GLOBAL_COMMANDS global_commands;
 char *global_clickstyle = 0;
 char *global_documentlanguage = 0;
 int global_documentlanguage_fixed = 0;
@@ -352,6 +351,7 @@ set_accept_internalvalue (int value)
 int
 register_global_command (ELEMENT *current)
 {
+  GLOBAL_COMMANDS *global_commands = parsed_document->global_commands;
   enum command_id cmd = current->cmd;
   if (cmd == CM_summarycontents)
     cmd = CM_shortcontents;
@@ -364,21 +364,21 @@ register_global_command (ELEMENT *current)
         {
 #define GLOBAL_CASE(cmx) \
         case CM_##cmx:   \
-          add_to_element_list (&global_commands.cmx, current); \
+          add_to_element_list (&global_commands->cmx, current); \
           add_extra_integer (current, "global_command_number", \
-                             global_commands.cmx.number); \
+                             global_commands->cmx.number); \
           break
 
         case CM_footnote:
-          add_to_element_list (&global_commands.footnotes, current);
+          add_to_element_list (&global_commands->footnotes, current);
           add_extra_integer (current, "global_command_number",
-                             global_commands.footnotes.number);
+                             global_commands->footnotes.number);
           break;
 
         case CM_float:
-          add_to_element_list (&global_commands.floats, current);
+          add_to_element_list (&global_commands->floats, current);
           add_extra_integer (current, "global_command_number",
-                             global_commands.floats.number);
+                             global_commands->floats.number);
           break;
 
 #include "global_multi_commands_case.c"
@@ -402,12 +402,12 @@ register_global_command (ELEMENT *current)
           /* Check if we are inside an @include, and if so, do nothing. */
           if (top_file_index () > 0)
             break;
-          where = &global_commands.setfilename;
+          where = &global_commands->setfilename;
           break;
 
 #define GLOBAL_UNIQUE_CASE(cmd) \
         case CM_##cmd: \
-          where = &global_commands.cmd; \
+          where = &global_commands->cmd; \
           break
 
 #include "main/global_unique_commands_case.c"
@@ -432,7 +432,7 @@ register_global_command (ELEMENT *current)
 
 
 void
-wipe_parser_global_info (void)
+wipe_parser_global_variables (void)
 {
   free (global_clickstyle);
   global_clickstyle = strdup ("arrow");
@@ -442,13 +442,6 @@ wipe_parser_global_info (void)
       global_documentlanguage = 0;
     }
   global_kbdinputstyle = kbd_distinct;
-
-  delete_global_info (&global_info);
-  memset (&global_info, 0, sizeof (global_info));
-
-  delete_global_commands (&global_commands);
-  /* clear the fields and reset elements lists */
-  memset (&global_commands, 0, sizeof (global_commands));
 }
 
 /* setup a Texinfo tree with document_root as root and before_node_section
@@ -466,16 +459,18 @@ setup_document_root_and_before_node_section (void)
 /* Put everything before @setfilename in a special type and separate
    a preamble for informative commands */
 void
-rearrange_tree_beginning (ELEMENT *before_node_section)
+rearrange_tree_beginning (ELEMENT *before_node_section, int 
document_descriptor)
 {
+  DOCUMENT *document = retrieve_document (document_descriptor);
   ELEMENT *informational_preamble;
   /* temporary placeholder */
   ELEMENT_LIST *first_types = new_list ();
 
   /* Put everything before @setfilename in a special type.  This allows to
      ignore everything before @setfilename. */
-  if (global_commands.setfilename
-      && global_commands.setfilename->parent == before_node_section)
+  if (document->global_commands->setfilename
+      && document->global_commands->setfilename->parent
+                                          == before_node_section)
     {
       ELEMENT *before_setfilename
          = new_element (ET_preamble_before_setfilename);
@@ -575,7 +570,7 @@ parse_texi_document (void)
 
   document_descriptor = parse_texi (document_root, before_node_section);
 
-  rearrange_tree_beginning (before_node_section);
+  rearrange_tree_beginning (before_node_section, document_descriptor);
 
   return document_descriptor;
 }
@@ -2497,121 +2492,6 @@ check_line_directive (char *line)
   return 0;
 }
 
-/* store global parser information in a document calling register_document
-   and forgetting about the global information that got registered */
-int
-store_document (ELEMENT *root)
-{
-  int document_descriptor;
-  int i;
-  LABEL_LIST *labels;
-  FLOAT_RECORD_LIST *floats;
-  ELEMENT_LIST *internal_references;
-  STRING_LIST *small_strings_list;
-  ERROR_MESSAGE_LIST *error_messages;
-  GLOBAL_INFO *doc_global_info = malloc (sizeof (GLOBAL_INFO));
-  GLOBAL_COMMANDS *doc_global_commands = malloc (sizeof (GLOBAL_COMMANDS));
-
-  labels = malloc (sizeof (LABEL_LIST));
-
-  /* this is actually used to deallocate above labels_number */
-  labels_list = realloc (labels_list,
-                         labels_number * sizeof (LABEL));
-
-  labels->list = labels_list;
-  labels->number = labels_number;
-  labels->space = labels_number;
-
-  floats = malloc (sizeof (FLOAT_RECORD_LIST));
-  parser_float_list.list = realloc (parser_float_list.list,
-        parser_float_list.number * sizeof (FLOAT_RECORD));
-
-  floats->list = parser_float_list.list;
-  floats->number = parser_float_list.number;
-  floats->space = parser_float_list.number;
-
-  internal_references = malloc (sizeof (ELEMENT_LIST));
-
-  internal_xref_list.list = realloc (internal_xref_list.list,
-                             internal_xref_list.number * sizeof (ELEMENT));
-
-  internal_references->list = internal_xref_list.list;
-  internal_references->number = internal_xref_list.number;
-  internal_references->space = internal_xref_list.number;
-
-  memcpy (doc_global_info, &global_info, sizeof (GLOBAL_INFO));
-  if (global_info.input_encoding_name)
-    doc_global_info->input_encoding_name
-      = strdup (global_info.input_encoding_name);
-  if (global_info.input_file_name)
-    doc_global_info->input_file_name
-      = strdup (global_info.input_file_name);
-  if (global_info.input_directory)
-    doc_global_info->input_directory
-      = strdup (global_info.input_directory);
-
-  #define COPY_GLOBAL_ARRAY(type,cmd) \
-   doc_global_##type->cmd.list = 0;                            \
-   doc_global_##type->cmd.number = 0;                          \
-   doc_global_##type->cmd.space = 0;                           \
-   if (global_##type.cmd.number > 0)                           \
-    {                                                                   \
-      for (i = 0; i < global_##type.cmd.number; i++)           \
-        {                                                               \
-          ELEMENT *e = global_##type.cmd.list[i]; \
-          add_to_element_list (&doc_global_##type->cmd, e);        \
-        }                                                               \
-    }
-  memcpy (doc_global_commands, &global_commands, sizeof (GLOBAL_COMMANDS));
-
-  COPY_GLOBAL_ARRAY(commands,dircategory_direntry);
-
-  #define GLOBAL_CASE(cmd) \
-   COPY_GLOBAL_ARRAY(commands,cmd)
-
-  GLOBAL_CASE(footnotes);
-  GLOBAL_CASE(floats);
-
-#include "global_multi_commands_case.c"
-
-  #undef GLOBAL_CASE
-  #undef COPY_GLOBAL_ARRAY
-
-  small_strings = realloc (small_strings, small_strings_num * sizeof (char *));
-  small_strings_list = malloc (sizeof (STRING_LIST));
-  small_strings_list->list = small_strings;
-  small_strings_list->number = small_strings_num;
-  small_strings_list->space = small_strings_num;
-
-  error_messages_list.list = realloc (error_messages_list.list,
-                        error_messages_list.number * sizeof (ERROR_MESSAGE));
-  error_messages = malloc (sizeof (ERROR_MESSAGE_LIST));
-  error_messages->list = error_messages_list.list;
-  error_messages->number = error_messages_list.number;
-  error_messages->space = error_messages_list.number;
-
-  document_descriptor
-   = register_document (root, index_names, floats, internal_references,
-                        labels, identifiers_target, doc_global_info,
-                        doc_global_commands,
-                        small_strings_list, error_messages);
-  forget_indices ();
-  forget_labels ();
-
-  memset (&parser_float_list, 0, sizeof (FLOAT_RECORD_LIST));
-
-  forget_internal_xrefs ();
-
-  memset (&global_info.included_files, 0, sizeof (STRING_LIST));
-
-  forget_small_strings ();
-  forget_errors ();
-
-  identifiers_target = 0;
-
-  return document_descriptor;
-}
-
 /* Pass in a ROOT_ELT root of "Texinfo tree".  Starting point for adding
    to the tree is CURRENT_ELT.  Returns a stored DOCUMENT_DESCRIPTOR */
 int
@@ -2776,12 +2656,21 @@ parse_texi (ELEMENT *root_elt, ELEMENT *current_elt)
      index merge */
   resolve_indices_merged_in ();
 
-  identifiers_target
-    = set_labels_identifiers_target (labels_list, labels_number);
+  parsed_document->identifiers_target
+    = set_labels_identifiers_target (parsed_document->labels_list->list,
+                                     parsed_document->labels_list->number);
+
+  parsed_document->tree = current;
 
-  document_descriptor = store_document (current);
+  parsed_document->listoffloats
+    = float_list_to_listoffloats_list (parsed_document->floats);
+
+  document_descriptor = parsed_document->descriptor;
 
   complete_indices (document_descriptor, debug_output);
 
+  parsed_document = 0;
+  forget_indices ();
+
   return document_descriptor;
 }
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index a50b790d22..b3f4ee45eb 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -21,10 +21,7 @@
 
 #include <stddef.h>
 
-#include "global_commands_types.h"
 #include "tree_types.h"
-/* for GLOBAL_INFO */
-#include "document_types.h"
 #include "tree.h"
 #include "context_stack.h"
 #include "commands.h"
@@ -58,13 +55,6 @@ ELEMENT *end_line (ELEMENT *current);
 ELEMENT *end_line_misc_line (ELEMENT *current);
 ELEMENT *end_line_starting_block (ELEMENT *current);
 
-extern FLOAT_RECORD_LIST parser_float_list;
-
-/* In labels.c */
-extern LABEL *labels_list;
-extern LABEL_LIST *identifiers_target;
-extern size_t labels_number;
-
 /* In separator.c */
 ELEMENT * handle_open_brace (ELEMENT *current, char **line_inout);
 ELEMENT * handle_close_brace (ELEMENT *current, char **line_inout);
@@ -123,12 +113,12 @@ char *parse_command_name (char **ptr, int *single_char);
 extern const char *whitespace_chars_except_newline;
 extern const char *linecommand_expansion_delimiters;
 
+extern DOCUMENT *parsed_document;
+
 extern ELEMENT *current_node;
 extern ELEMENT *current_section;
 extern ELEMENT *current_part;
 
-extern GLOBAL_INFO global_info;
-extern GLOBAL_COMMANDS global_commands;
 extern char *global_clickstyle;
 extern char *global_documentlanguage;
 extern int global_documentlanguage_fixed;
@@ -138,7 +128,7 @@ enum kbd_enum {kbd_none, kbd_code, kbd_example, 
kbd_distinct };
 extern enum kbd_enum global_kbdinputstyle;
 
 int register_global_command (ELEMENT *current);
-void wipe_parser_global_info (void);
+void wipe_parser_global_variables (void);
 
 extern COUNTER count_remaining_args, count_items, count_cells;
 void reset_parser_counters (void);
diff --git a/tp/Texinfo/XS/parsetexi/separator.c 
b/tp/Texinfo/XS/parsetexi/separator.c
index 950d6104c1..428293fe02 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -430,15 +430,16 @@ handle_close_brace (ELEMENT *current, char **line_inout)
         }
       else if (closed_command == CM_image)
         {
+          GLOBAL_INFO *global_info = parsed_document->global_info;
           ELEMENT *image = current->parent;
           if (image->args.number == 0
               || image->args.list[0]->contents.number == 0)
             {
               line_error ("@image missing filename argument");
             }
-          if (global_info.input_encoding_name)
+          if (global_info->input_encoding_name)
             add_extra_string_dup (image, "input_encoding_name",
-                                  global_info.input_encoding_name);
+                                  global_info->input_encoding_name);
         }
       else if (closed_command == CM_dotless)
         {
diff --git a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs 
b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
index eb0a969e49..2f1f1dc2a3 100644
--- a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+++ b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
@@ -87,17 +87,17 @@ copy_tree (SV *tree_in)
         if (document)
           {
             ELEMENT *result = copy_tree (document->tree);
+            DOCUMENT *copy_document = new_document ();
           /* document additional information, global info, labels, indices...
              is not setup with copy_tree, so we only have the tree to store.
              This is not different from the Perl code and, in general,
              it is best that way.
            */
-            int copy_document_descriptor = register_document (result, 0, 0, 0,
-                                                      0, 0, 0, 0, 0, 0);
             HV *hv = build_texinfo_tree (result, 0);
+            copy_document->tree = result;
             hv_store (hv, "tree_document_descriptor",
                       strlen ("tree_document_descriptor"),
-                      newSViv ((IV) copy_document_descriptor), 0);
+                      newSViv ((IV) copy_document->descriptor), 0);
             RETVAL = newRV_inc ((SV *) hv);
           }
         else



reply via email to

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