texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sun, 29 Sep 2024 06:16:29 -0400 (EDT)

branch: master
commit ce77965002aa569a0dba71c0539facf29569503b
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jun 16 23:25:28 2024 +0200

    Associate output units lists with document in XS
    
    * tp/Texinfo/Convert/Plaintext.pm (output), tp/Texinfo/OutputUnits.pm
    (rebuild_output_units), tp/Texinfo/XS/convert/ConvertXS.xs
    (html_prepare_conversion_units, html_prepare_units_directions_files)
    (html_prepare_output_units_global_targets),
    tp/Texinfo/XS/convert/convert_html.c (html_get_tree_root_element),
    tp/Texinfo/XS/convert/convert_html.c (prepare_special_units)
    (set_special_units_targets_files)
    (prepare_associated_special_units_targets)
    (html_internal_command_href, html_prepare_output_units_global_targets)
    (html_prepare_units_directions_files, html_convert_convert)
    (html_prepare_title_titlepage, html_convert_output),
    tp/Texinfo/XS/main/build_perl_info.c (fill_output_units_descriptor_av)
    (build_output_units_list, setup_output_units_handler)
    (rebuild_output_units_list), tp/Texinfo/XS/main/document_types.h
    (OUTPUT_UNIT_LISTS, DOCUMENT), tp/Texinfo/XS/main/get_perl_info.c
    (get_sv_output_units), tp/Texinfo/XS/main/output_unit.c
    (retrieve_output_units, new_output_units_descriptor, split_by_node)
    (split_by_section),
    tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
    (split_by_node, split_by_section, rebuild_output_units, split_pages),
    tp/t/test_utils.pl (test): add output_units_lists in DOCUMENT, and put
    and retrieve output units from there. Remove output_units_list,
    output_units_number and output_units_space in output_unit.c.
---
 ChangeLog                                          | 28 +++++++++++++
 tp/Texinfo/Convert/Plaintext.pm                    |  2 +-
 tp/Texinfo/OutputUnits.pm                          |  3 +-
 tp/Texinfo/XS/convert/ConvertXS.xs                 | 30 ++++++++------
 tp/Texinfo/XS/convert/convert_html.c               | 46 ++++++++++++----------
 tp/Texinfo/XS/main/build_perl_info.c               | 23 ++++++-----
 tp/Texinfo/XS/main/build_perl_info.h               |  8 ++--
 tp/Texinfo/XS/main/document_types.h                |  7 ++++
 tp/Texinfo/XS/main/get_perl_info.c                 |  7 ++--
 tp/Texinfo/XS/main/get_perl_info.h                 |  4 +-
 tp/Texinfo/XS/main/output_unit.c                   | 46 +++++++++++-----------
 tp/Texinfo/XS/main/output_unit.h                   |  6 ++-
 .../XS/structuring_transfo/StructuringTransfoXS.xs | 31 ++++++++++-----
 tp/t/test_utils.pl                                 |  2 +-
 14 files changed, 159 insertions(+), 84 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index dd07b798e9..bbb2681446 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,34 @@
        * tp/Texinfo/XS/convert/convert_html.c (html_command_description):
        update for move of cmd to CONTAINER.
 
+2024-06-16  Patrice Dumas  <pertusus@free.fr>
+
+       Associate output units lists with document in XS
+
+       * tp/Texinfo/Convert/Plaintext.pm (output), tp/Texinfo/OutputUnits.pm
+       (rebuild_output_units), tp/Texinfo/XS/convert/ConvertXS.xs
+       (html_prepare_conversion_units, html_prepare_units_directions_files)
+       (html_prepare_output_units_global_targets),
+       tp/Texinfo/XS/convert/convert_html.c (html_get_tree_root_element),
+       tp/Texinfo/XS/convert/convert_html.c (prepare_special_units)
+       (set_special_units_targets_files)
+       (prepare_associated_special_units_targets)
+       (html_internal_command_href, html_prepare_output_units_global_targets)
+       (html_prepare_units_directions_files, html_convert_convert)
+       (html_prepare_title_titlepage, html_convert_output),
+       tp/Texinfo/XS/main/build_perl_info.c (fill_output_units_descriptor_av)
+       (build_output_units_list, setup_output_units_handler)
+       (rebuild_output_units_list), tp/Texinfo/XS/main/document_types.h
+       (OUTPUT_UNIT_LISTS, DOCUMENT), tp/Texinfo/XS/main/get_perl_info.c
+       (get_sv_output_units), tp/Texinfo/XS/main/output_unit.c
+       (retrieve_output_units, new_output_units_descriptor, split_by_node)
+       (split_by_section),
+       tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+       (split_by_node, split_by_section, rebuild_output_units, split_pages),
+       tp/t/test_utils.pl (test): add output_units_lists in DOCUMENT, and put
+       and retrieve output units from there. Remove output_units_list,
+       output_units_number and output_units_space in output_unit.c.
+
 2024-06-16  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/manipulate_tree.c (copy_associated_info): use
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index 4e897237ae..191cb3755d 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -710,7 +710,7 @@ sub output($$)
 
   Texinfo::OutputUnits::split_pages($output_units, $self->get_conf('SPLIT'));
 
-  Texinfo::OutputUnits::rebuild_output_units($output_units);
+  Texinfo::OutputUnits::rebuild_output_units($document, $output_units);
 
   # determine file names associated with the different pages
   if ($output_file ne '') {
diff --git a/tp/Texinfo/OutputUnits.pm b/tp/Texinfo/OutputUnits.pm
index 5814ed8557..cd1f991015 100644
--- a/tp/Texinfo/OutputUnits.pm
+++ b/tp/Texinfo/OutputUnits.pm
@@ -237,8 +237,9 @@ sub unsplit($)
 }
 
 # does nothing in perl, the XS version reexports the output units
-sub rebuild_output_units($)
+sub rebuild_output_units($$)
 {
+  my $document = shift;
   my $output_units = shift;
 }
 
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index ff22a666cc..e896418be8 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -2007,20 +2007,24 @@ html_prepare_conversion_units (SV *converter_in, ...)
                }
 
              output_units_sv = build_output_units_list
-               (self->output_units_descriptors[OUDT_units]);
+               (self->document, self->output_units_descriptors[OUDT_units]);
              special_units_sv = build_output_units_list
-               (self->output_units_descriptors[OUDT_special_units]);
+               (self->document,
+                self->output_units_descriptors[OUDT_special_units]);
              associated_special_units_sv = build_output_units_list
-               (self->output_units_descriptors[OUDT_associated_special_units]);
+               (self->document,
+                self->output_units_descriptors[OUDT_associated_special_units]);
            }
          else
            {
              output_units_sv = setup_output_units_handler
-               (self->output_units_descriptors[OUDT_units]);
+               (self->document, self->output_units_descriptors[OUDT_units]);
              special_units_sv = setup_output_units_handler
-               (self->output_units_descriptors[OUDT_special_units]);
+               (self->document,
+                self->output_units_descriptors[OUDT_special_units]);
              associated_special_units_sv = setup_output_units_handler
-               (self->output_units_descriptors[OUDT_associated_special_units]);
+               (self->document,
+                self->output_units_descriptors[OUDT_associated_special_units]);
            }
 
          output_units_hv = (HV *) SvRV (output_units_sv);
@@ -2056,11 +2060,12 @@ html_prepare_units_directions_files (SV *converter_in, 
SV *output_units_in, SV *
 
          if (self->external_references_number > 0)
            {
-             rebuild_output_units_list (output_units_in,
+             rebuild_output_units_list (self->document, output_units_in,
                            self->output_units_descriptors[OUDT_units]);
-             rebuild_output_units_list (special_units_in,
+             rebuild_output_units_list (self->document, special_units_in,
                       self->output_units_descriptors[OUDT_special_units]);
-             rebuild_output_units_list (associated_special_units_in,
+             rebuild_output_units_list (self->document,
+                                        associated_special_units_in,
                 self->output_units_descriptors[OUDT_associated_special_units]);
 
              pass_html_global_units_directions (converter_in,
@@ -2088,11 +2093,12 @@ html_prepare_output_units_global_targets (SV 
*converter_in, SV *output_units_in,
 
          if (self->external_references_number > 0)
            {
-             rebuild_output_units_list (output_units_in,
+             rebuild_output_units_list (self->document, output_units_in,
                                 self->output_units_descriptors[OUDT_units]);
-             rebuild_output_units_list (special_units_in,
+             rebuild_output_units_list (self->document, special_units_in,
                         self->output_units_descriptors[OUDT_special_units]);
-             rebuild_output_units_list (associated_special_units_in,
+             rebuild_output_units_list (self->document,
+                                        associated_special_units_in,
                self->output_units_descriptors[OUDT_associated_special_units]);
 
              pass_html_global_units_directions (converter_in,
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 02b7b33ec1..f8e9f2161d 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -384,7 +384,8 @@ html_get_tree_root_element (CONVERTER *self, const ELEMENT 
*command,
                && builtin_command_data[data_cmd].data == BLOCK_region)
         {
           const OUTPUT_UNIT_LIST *output_units
-         = retrieve_output_units (self->output_units_descriptors[OUDT_units]);
+         = retrieve_output_units (self->document,
+                                  self->output_units_descriptors[OUDT_units]);
           if (data_cmd == CM_copying
               && self->document->global_commands.insertcopying.number > 0)
             {
@@ -1538,19 +1539,21 @@ prepare_special_units (CONVERTER *self, int 
output_units_descriptor)
   SPECIAL_UNIT_ORDER *special_units_order;
   OUTPUT_UNIT *previous_output_unit = 0;
 
-  int special_units_descriptor = new_output_units_descriptor ();
-  int associated_special_units_descriptor = new_output_units_descriptor ();
+  int special_units_descriptor = new_output_units_descriptor (self->document);
+  int associated_special_units_descriptor
+         = new_output_units_descriptor (self->document);
 
   /* retrieve after reallocating */
 
   OUTPUT_UNIT_LIST *special_units
-    = retrieve_output_units (special_units_descriptor);
+    = retrieve_output_units (self->document, special_units_descriptor);
 
   OUTPUT_UNIT_LIST *associated_special_units
-    = retrieve_output_units (associated_special_units_descriptor);
+    = retrieve_output_units (self->document,
+                             associated_special_units_descriptor);
 
   OUTPUT_UNIT_LIST *output_units
-    = retrieve_output_units (output_units_descriptor);
+    = retrieve_output_units (self->document, output_units_descriptor);
 
   /* for separate special output units */
   STRING_LIST *do_special = new_string_list ();
@@ -1828,7 +1831,7 @@ set_special_units_targets_files (CONVERTER *self, const 
char *document_name)
 {
   int i;
   OUTPUT_UNIT_LIST *special_units = retrieve_output_units
-    (self->output_units_descriptors[OUDT_special_units]);
+    (self->document, self->output_units_descriptors[OUDT_special_units]);
 
   char *extension = "";
   if (self->conf->EXTENSION.o.string)
@@ -1916,7 +1919,8 @@ static void
 prepare_associated_special_units_targets (CONVERTER *self)
 {
   OUTPUT_UNIT_LIST *associated_special_units = retrieve_output_units
-   (self->output_units_descriptors[OUDT_associated_special_units]);
+   (self->document,
+    self->output_units_descriptors[OUDT_associated_special_units]);
 
   if (associated_special_units && associated_special_units->number > 0)
     {
@@ -3597,7 +3601,8 @@ html_internal_command_href (CONVERTER *self, const 
ELEMENT *command,
       as in the test cases.  Also for things in @titlepage when
       titlepage is not output. */
       const OUTPUT_UNIT_LIST *output_units
-         = retrieve_output_units (self->output_units_descriptors[OUDT_units]);
+         = retrieve_output_units (self->document,
+                            self->output_units_descriptors[OUDT_units]);
       if (output_units->list[0]->unit_filename)
         { /* In that case use the first page. */
           set_target_filename = (FILE_NUMBER_NAME *)
@@ -5270,7 +5275,7 @@ html_prepare_output_units_global_targets (CONVERTER *self)
   int all_special_units_nr = 0;
   int s;
   const OUTPUT_UNIT_LIST *output_units = retrieve_output_units
-   (self->output_units_descriptors[OUDT_units]);
+   (self->document, self->output_units_descriptors[OUDT_units]);
 
   const OUTPUT_UNIT *top_output_unit = get_top_unit (self->document,
                                                      output_units);
@@ -5364,7 +5369,7 @@ html_prepare_output_units_global_targets (CONVERTER *self)
     {
       int special_units_descriptor = special_output_units_lists[i];
       const OUTPUT_UNIT_LIST *units_list
-       = retrieve_output_units (special_units_descriptor);
+       = retrieve_output_units (self->document, special_units_descriptor);
       if (units_list && units_list->number)
         all_special_units_nr += units_list->number;
     }
@@ -5379,7 +5384,7 @@ html_prepare_output_units_global_targets (CONVERTER *self)
     {
       int special_units_descriptor = special_output_units_lists[i];
       const OUTPUT_UNIT_LIST *units_list
-        = retrieve_output_units (special_units_descriptor);
+        = retrieve_output_units (self->document, special_units_descriptor);
       if (units_list && units_list->number)
         {
           int j;
@@ -6043,11 +6048,12 @@ html_prepare_units_directions_files (CONVERTER *self,
   int i;
   FILE_SOURCE_INFO_LIST *files_source_info = 0;
   OUTPUT_UNIT_LIST *output_units = retrieve_output_units
-    (self->output_units_descriptors[OUDT_units]);
+    (self->document, self->output_units_descriptors[OUDT_units]);
   OUTPUT_UNIT_LIST *special_units = retrieve_output_units
-    (self->output_units_descriptors[OUDT_special_units]);
+    (self->document, self->output_units_descriptors[OUDT_special_units]);
   OUTPUT_UNIT_LIST *associated_special_units = retrieve_output_units
-    (self->output_units_descriptors[OUDT_associated_special_units]);
+    (self->document,
+     self->output_units_descriptors[OUDT_associated_special_units]);
 
   html_prepare_output_units_global_targets (self);
 
@@ -19086,9 +19092,9 @@ html_convert_convert (CONVERTER *self, const ELEMENT 
*root)
   int i;
 
   const OUTPUT_UNIT_LIST *output_units = retrieve_output_units
-    (self->output_units_descriptors[OUDT_units]);
+    (self->document, self->output_units_descriptors[OUDT_units]);
   const OUTPUT_UNIT_LIST *special_units = retrieve_output_units
-    (self->output_units_descriptors[OUDT_special_units]);
+    (self->document, self->output_units_descriptors[OUDT_special_units]);
 
   text_init (&result);
 
@@ -19283,7 +19289,7 @@ html_prepare_title_titlepage (CONVERTER *self, const 
char *output_file,
                               const char *output_filename)
 {
   const OUTPUT_UNIT_LIST *output_units = retrieve_output_units
-    (self->output_units_descriptors[OUDT_units]);
+    (self->document, self->output_units_descriptors[OUDT_units]);
 
   if (strlen (output_file))
     {
@@ -19314,9 +19320,9 @@ html_convert_output (CONVERTER *self, const ELEMENT 
*root,
   TEXT text; /* reused for all the output units */
 
   const OUTPUT_UNIT_LIST *output_units = retrieve_output_units
-    (self->output_units_descriptors[OUDT_units]);
+    (self->document, self->output_units_descriptors[OUDT_units]);
   const OUTPUT_UNIT_LIST *special_units = retrieve_output_units
-    (self->output_units_descriptors[OUDT_special_units]);
+    (self->document, self->output_units_descriptors[OUDT_special_units]);
 
   text_init (&result);
   text_init (&text);
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 7eb6f08cc6..d7c384fdf3 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -2150,7 +2150,8 @@ output_unit_to_perl_hash (OUTPUT_UNIT *output_unit)
 }
 
 static int
-fill_output_units_descriptor_av (AV *av_output_units,
+fill_output_units_descriptor_av (const DOCUMENT *document,
+                                 AV *av_output_units,
                                  size_t output_units_descriptor)
 {
   const OUTPUT_UNIT_LIST *output_units;
@@ -2158,7 +2159,7 @@ fill_output_units_descriptor_av (AV *av_output_units,
 
   dTHX;
 
-  output_units = retrieve_output_units (output_units_descriptor);
+  output_units = retrieve_output_units (document, output_units_descriptor);
 
   if (!output_units || !output_units->number)
     return 0;
@@ -2183,7 +2184,8 @@ fill_output_units_descriptor_av (AV *av_output_units,
 }
 
 SV *
-build_output_units_list (size_t output_units_descriptor)
+build_output_units_list (const DOCUMENT *document,
+                         size_t output_units_descriptor)
 {
   AV *av_output_units;
 
@@ -2191,7 +2193,8 @@ build_output_units_list (size_t output_units_descriptor)
 
   av_output_units = newAV ();
 
-  if (!fill_output_units_descriptor_av (av_output_units,
+  if (!fill_output_units_descriptor_av (document,
+                                        av_output_units,
                                         output_units_descriptor))
     {/* no output unit */
       av_undef (av_output_units);
@@ -2204,7 +2207,8 @@ build_output_units_list (size_t output_units_descriptor)
 /* a fake output units list that only holds a descriptor allowing
    to retrieve the C data */
 SV *
-setup_output_units_handler (size_t output_units_descriptor)
+setup_output_units_handler (const DOCUMENT *document,
+                            size_t output_units_descriptor)
 {
   AV *av_output_units;
   HV *dummy_output_unit;
@@ -2213,7 +2217,7 @@ setup_output_units_handler (size_t 
output_units_descriptor)
 
   dTHX;
 
-  output_units = retrieve_output_units (output_units_descriptor);
+  output_units = retrieve_output_units (document, output_units_descriptor);
 
   if (!output_units || !output_units->number)
     return newSV (0);
@@ -2233,7 +2237,8 @@ setup_output_units_handler (size_t 
output_units_descriptor)
 }
 
 void
-rebuild_output_units_list (SV *output_units_sv, size_t output_units_descriptor)
+rebuild_output_units_list (const DOCUMENT *document, SV *output_units_sv,
+                           size_t output_units_descriptor)
 {
   AV *av_output_units;
 
@@ -2242,7 +2247,7 @@ rebuild_output_units_list (SV *output_units_sv, size_t 
output_units_descriptor)
   if (!SvOK (output_units_sv))
     {
       const OUTPUT_UNIT_LIST *output_units
-        = retrieve_output_units (output_units_descriptor);
+        = retrieve_output_units (document, output_units_descriptor);
       if (output_units && output_units->number)
         fprintf (stderr, "BUG: no input sv for %zu output units (%zu)\n",
                  output_units->number, output_units_descriptor);
@@ -2252,7 +2257,7 @@ rebuild_output_units_list (SV *output_units_sv, size_t 
output_units_descriptor)
   av_output_units = (AV *) SvRV (output_units_sv);
   av_clear (av_output_units);
 
-  if (!fill_output_units_descriptor_av (av_output_units,
+  if (!fill_output_units_descriptor_av (document, av_output_units,
                                         output_units_descriptor))
     {
  /* the output_units_descriptor is not found.  In the codes calling
diff --git a/tp/Texinfo/XS/main/build_perl_info.h 
b/tp/Texinfo/XS/main/build_perl_info.h
index 953db73c56..259e6d753c 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -61,10 +61,12 @@ SV *pass_errors_to_registrar (const ERROR_MESSAGE_LIST 
*error_messages,
                               SV *object_sv,
                               SV **errors_warnings_out, SV **error_nrs_out);
 
-SV *build_output_units_list (size_t output_units_descriptor);
-void rebuild_output_units_list (SV *output_units_sv,
+SV *build_output_units_list (const DOCUMENT *document,
+                             size_t output_units_descriptor);
+void rebuild_output_units_list (const DOCUMENT *document, SV *output_units_sv,
+                                size_t output_units_descriptor);
+SV *setup_output_units_handler (const DOCUMENT *document,
                                 size_t output_units_descriptor);
-SV *setup_output_units_handler (size_t output_units_descriptor);
 
 AV *build_integer_stack (const INTEGER_STACK *integer_stack);
 AV *build_string_list (const STRING_LIST *strings_list, enum sv_string_type);
diff --git a/tp/Texinfo/XS/main/document_types.h 
b/tp/Texinfo/XS/main/document_types.h
index cefaf4734e..db140442c3 100644
--- a/tp/Texinfo/XS/main/document_types.h
+++ b/tp/Texinfo/XS/main/document_types.h
@@ -185,6 +185,12 @@ typedef struct COLLATIONS_INDICES_SORTED_BY_LETTER {
     COLLATION_INDICES_SORTED_BY_LETTER *collation_sorted_indices;
 } COLLATIONS_INDICES_SORTED_BY_LETTER;
 
+typedef struct OUTPUT_UNIT_LISTS {
+    OUTPUT_UNIT_LIST *output_units_lists;
+    size_t number;
+    size_t space;
+} OUTPUT_UNIT_LISTS;
+
 typedef struct DOCUMENT {
     size_t descriptor;
     ELEMENT *tree;
@@ -212,6 +218,7 @@ typedef struct DOCUMENT {
     INDICES_SORT_STRINGS *indices_sort_strings;
     COLLATIONS_INDICES_SORTED_BY_INDEX *sorted_indices_by_index;
     COLLATIONS_INDICES_SORTED_BY_LETTER *sorted_indices_by_letter;
+    OUTPUT_UNIT_LISTS output_units_lists;
 
     /* flags for modified information not already passed to Perl */
     unsigned long modified_information;
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index 57d97ab04e..bbaf0f3ae7 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -216,14 +216,15 @@ get_sv_output_units_descriptor (SV *output_units_in, char 
*warn_string)
 
 
 OUTPUT_UNIT_LIST *
-get_sv_output_units (SV *output_units_in, char *warn_string)
+get_sv_output_units (const DOCUMENT *document, SV *output_units_in,
+                     char *warn_string)
 {
   OUTPUT_UNIT_LIST *output_units = 0;
   int output_units_descriptor
      = get_sv_output_units_descriptor (output_units_in, warn_string);
   if (output_units_descriptor)
     {
-      output_units = retrieve_output_units (output_units_descriptor);
+      output_units = retrieve_output_units (document, output_units_descriptor);
       if (!output_units && warn_string)
         fprintf (stderr, "ERROR: %s: no units %d\n", warn_string,
                                              output_units_descriptor);
@@ -1086,7 +1087,7 @@ find_root_command (const DOCUMENT *document, HV 
*element_hv,
             {
               int unit_index = SvIV (*unit_index_sv);
               const OUTPUT_UNIT_LIST *output_units
-               = retrieve_output_units (output_units_descriptor);
+               = retrieve_output_units (document, output_units_descriptor);
 
               if (output_units && unit_index < output_units->number)
                 {
diff --git a/tp/Texinfo/XS/main/get_perl_info.h 
b/tp/Texinfo/XS/main/get_perl_info.h
index f51c307253..dfb6e42fb5 100644
--- a/tp/Texinfo/XS/main/get_perl_info.h
+++ b/tp/Texinfo/XS/main/get_perl_info.h
@@ -23,8 +23,10 @@ void set_option_key_configured (OPTIONS *options, const char 
*key,
 DOCUMENT *get_sv_tree_document (SV *tree_in, char *warn_string);
 DOCUMENT *get_sv_document_document (SV *document_in, char *warn_string);
 
-OUTPUT_UNIT_LIST *get_sv_output_units (SV *output_units_in, char *warn_string);
 int get_sv_output_units_descriptor (SV *output_units_in, char *warn_string);
+OUTPUT_UNIT_LIST *get_sv_output_units (const DOCUMENT *document,
+                                       SV *output_units_in,
+                                       char *warn_string);
 
 void apply_sv_parser_conf (SV *parser_sv);
 
diff --git a/tp/Texinfo/XS/main/output_unit.c b/tp/Texinfo/XS/main/output_unit.c
index 258d1193b0..5597d0743b 100644
--- a/tp/Texinfo/XS/main/output_unit.c
+++ b/tp/Texinfo/XS/main/output_unit.c
@@ -48,17 +48,15 @@ const char *relative_unit_direction_name[] = {
 };
 
 
-static OUTPUT_UNIT_LIST *output_units_list;
-static size_t output_units_number;
-static size_t output_units_space;
-
 OUTPUT_UNIT_LIST *
-retrieve_output_units (int output_units_descriptor)
+retrieve_output_units (const DOCUMENT *document, int output_units_descriptor)
 {
+  const OUTPUT_UNIT_LISTS *output_units = &document->output_units_lists;
+
   /* the list can still be uninitialized and .list be 0 */
   if (output_units_descriptor > 0
-      && output_units_descriptor <= output_units_number)
-    return &output_units_list[output_units_descriptor -1];
+      && output_units_descriptor <= output_units->number)
+    return &output_units->output_units_lists[output_units_descriptor -1];
   return 0;
 }
 
@@ -76,15 +74,16 @@ reallocate_output_unit_list (OUTPUT_UNIT_LIST *list)
 
 /* descriptor starts at 1, 0 is an error */
 size_t
-new_output_units_descriptor (void)
+new_output_units_descriptor (DOCUMENT *document)
 {
   size_t output_units_index;
   int slot_found = 0;
   int i;
+  OUTPUT_UNIT_LISTS *output_units = &document->output_units_lists;
 
-  for (i = 0; i < output_units_number; i++)
+  for (i = 0; i < output_units->number; i++)
     {
-      if (output_units_list[i].list == 0)
+      if (output_units->output_units_lists[i].list == 0)
         {
           slot_found = 1;
           output_units_index = i;
@@ -92,22 +91,25 @@ new_output_units_descriptor (void)
     }
   if (!slot_found)
     {
-      if (output_units_number == output_units_space)
+      if (output_units->number == output_units->space)
         {
-          output_units_list = realloc (output_units_list,
-                      (output_units_space += 5) * sizeof (OUTPUT_UNIT_LIST));
-          if (!output_units_list)
+          output_units->output_units_lists
+              = realloc (output_units->output_units_lists,
+                      (output_units->space += 1) * sizeof (OUTPUT_UNIT_LIST));
+          if (!output_units->output_units_lists)
             fatal ("realloc failed");
         }
-      output_units_index = output_units_number;
-      output_units_number++;
+      output_units_index = output_units->number;
+      output_units->number++;
     }
 
-  memset (&output_units_list[output_units_index], 0, sizeof 
(OUTPUT_UNIT_LIST));
+  memset (&output_units->output_units_lists[output_units_index],
+          0, sizeof (OUTPUT_UNIT_LIST));
 
   /* immediately allocate, even if the list will remain empty, such
      that the slot is reserved */
-  reallocate_output_unit_list (&output_units_list[output_units_index]);
+  reallocate_output_unit_list
+       (&output_units->output_units_lists[output_units_index]);
 
   /*
   fprintf (stderr, "Register output units (%d): %d\n", slot_found,
@@ -140,9 +142,9 @@ int
 split_by_node (DOCUMENT *document)
 {
   const ELEMENT *root = document->tree;
-  int output_units_descriptor = new_output_units_descriptor ();
+  int output_units_descriptor = new_output_units_descriptor (document);
   OUTPUT_UNIT_LIST *output_units
-    = retrieve_output_units (output_units_descriptor);
+    = retrieve_output_units (document, output_units_descriptor);
   OUTPUT_UNIT *current = new_output_unit (OU_unit);
   ELEMENT_LIST *pending_parts = new_list ();
   int i;
@@ -213,9 +215,9 @@ int
 split_by_section (DOCUMENT *document)
 {
   const ELEMENT *root = document->tree;
-  int output_units_descriptor = new_output_units_descriptor ();
+  int output_units_descriptor = new_output_units_descriptor (document);
   OUTPUT_UNIT_LIST *output_units
-    = retrieve_output_units (output_units_descriptor);
+    = retrieve_output_units (document, output_units_descriptor);
   OUTPUT_UNIT *current = new_output_unit (OU_unit);
   int i;
 
diff --git a/tp/Texinfo/XS/main/output_unit.h b/tp/Texinfo/XS/main/output_unit.h
index cc5743bb92..a1de893d70 100644
--- a/tp/Texinfo/XS/main/output_unit.h
+++ b/tp/Texinfo/XS/main/output_unit.h
@@ -5,11 +5,13 @@
 #include <stddef.h>
 
 #include "tree_types.h"
+#include "document_types.h"
 
 extern const char *relative_unit_direction_name[];
 
-OUTPUT_UNIT_LIST *retrieve_output_units (int output_units_descriptor);
-size_t new_output_units_descriptor (void);
+OUTPUT_UNIT_LIST *retrieve_output_units (const DOCUMENT *document,
+                                         int output_units_descriptor);
+size_t new_output_units_descriptor (DOCUMENT *document);
 
 int split_by_node (DOCUMENT *document);
 int split_by_section (DOCUMENT *document);
diff --git a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs 
b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
index ad9f74d29f..18b8071964 100644
--- a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+++ b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
@@ -393,7 +393,8 @@ split_by_node (SV *document_in)
         if (document)
           {
             int output_units_descriptor = split_by_node (document);
-            RETVAL = build_output_units_list (output_units_descriptor);
+            RETVAL = build_output_units_list (document,
+                                              output_units_descriptor);
           }
         else
           RETVAL = newSV(0);
@@ -409,7 +410,8 @@ split_by_section (SV *document_in)
         if (document)
           {
             int output_units_descriptor = split_by_section (document);
-            RETVAL = build_output_units_list (output_units_descriptor);
+            RETVAL = build_output_units_list (document,
+                                              output_units_descriptor);
           }
         else
           RETVAL = newSV(0);
@@ -431,23 +433,34 @@ unsplit (SV *document_in)
         RETVAL
 
 void
-rebuild_output_units (SV *output_units_in)
+rebuild_output_units (SV *document_in, SV *output_units_in)
     PREINIT:
+        DOCUMENT *document = 0;
         int output_units_descriptor = 0;
      CODE:
+        document = get_sv_document_document (document_in,
+                                             "rebuild_output_units");
       /* This may be called in Texinfo::Convert::Converter::output on
          converters that may or may not have XS information, so no warning */
-        output_units_descriptor
-           = get_sv_output_units_descriptor (output_units_in, 0);
-        if (output_units_descriptor)
-          rebuild_output_units_list (output_units_in, output_units_descriptor);
+        if (document)
+          {
+            output_units_descriptor
+             = get_sv_output_units_descriptor (output_units_in, 0);
+            if (output_units_descriptor)
+              rebuild_output_units_list (document, output_units_in,
+                                         output_units_descriptor);
+          }
 
 void
-split_pages (SV *output_units_in, char *split)
+split_pages (SV *document_in, SV *output_units_in, char *split)
     PREINIT:
+        const DOCUMENT *document = 0;
         OUTPUT_UNIT_LIST *output_units = 0;
      CODE:
-        output_units = get_sv_output_units (output_units_in, "split_pages");
+        document = get_sv_document_document (document_in,
+                                             "split_pages");
+        output_units = get_sv_output_units (document,
+                                            output_units_in, "split_pages");
         if (output_units)
           split_pages (output_units, split);
 
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index ee370ae551..3b757e32d8 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -1395,7 +1395,7 @@ sub test($$)
   }
 
   if ($test_split or $split_pages) {
-    Texinfo::OutputUnits::rebuild_output_units($output_units);
+    Texinfo::OutputUnits::rebuild_output_units($document, $output_units);
   }
 
   my $file = "t/results/$self->{'name'}/$test_name.pl";



reply via email to

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