texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Tue, 20 Feb 2024 15:11:56 -0500 (EST)

branch: master
commit 6d369e2b5910d9d3d489990243f7824247cb8fbe
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Feb 20 16:13:04 2024 +0100

    * tp/Texinfo/Structuring.pm (rebuild_output_units),
    tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
    (rebuild_output_units): reuse the input reference instead of creating
    a new one.  Do that by calling rebuild_output_units_list in XS.
    Do not return anything.  Update callers.
    
    * tp/Texinfo/XS/convert/build_html_perl_state.c: make a function
    static, add const.
    
    * tp/Texinfo/XS/main/build_perl_info.c: move code around.
    
    * tp/Texinfo/Convert/Info.pm (output): move code around.  Rename
    variables as output_unit*.
    
    * tp/Texinfo/XS/parsetexi/end_line.c (parse_line_command_args): remove
    a useless TODO.
---
 ChangeLog                                          | 19 ++++++++
 tp/Texinfo/Convert/Converter.pm                    |  2 +-
 tp/Texinfo/Convert/HTML.pm                         |  3 +-
 tp/Texinfo/Convert/Info.pm                         | 13 +++---
 tp/Texinfo/Structuring.pm                          |  1 -
 tp/Texinfo/XS/convert/build_html_perl_state.c      | 16 ++++---
 tp/Texinfo/XS/convert/build_html_perl_state.h      |  2 +-
 tp/Texinfo/XS/main/build_perl_info.c               | 54 +++++++++++-----------
 tp/Texinfo/XS/main/get_perl_info.c                 |  1 +
 tp/Texinfo/XS/parsetexi/end_line.c                 |  3 +-
 .../XS/structuring_transfo/StructuringTransfoXS.xs | 13 ++----
 tp/t/test_utils.pl                                 |  9 ++--
 12 files changed, 75 insertions(+), 61 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ef33f48c2e..8139355afd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,25 @@
        $self->{'encoding_disabled'} if not outputting to a file, before
        any conversion is done.
 
+2024-02-20  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Structuring.pm (rebuild_output_units),
+       tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+       (rebuild_output_units): reuse the input reference instead of creating
+       a new one.  Do that by calling rebuild_output_units_list in XS.
+       Do not return anything.  Update callers.
+
+       * tp/Texinfo/XS/convert/build_html_perl_state.c: make a function
+       static, add const.
+
+       * tp/Texinfo/XS/main/build_perl_info.c: move code around.
+
+       * tp/Texinfo/Convert/Info.pm (output): move code around.  Rename
+       variables as output_unit*.
+
+       * tp/Texinfo/XS/parsetexi/end_line.c (parse_line_command_args): remove
+       a useless TODO.
+
 2024-02-20  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/build_perl_info.c
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index b523c506cc..93bfc72ad5 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -408,7 +408,7 @@ sub output($$)
 
   Texinfo::Structuring::split_pages($output_units, $self->get_conf('SPLIT'));
 
-  $output_units = Texinfo::Structuring::rebuild_output_units($output_units);
+  Texinfo::Structuring::rebuild_output_units($output_units);
 
   # determine file names associated with the different pages
   if ($output_file ne '') {
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 89010b1163..d7cb41ed20 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -12053,6 +12053,7 @@ sub convert($$)
   # are set and present in the buttons, as is the case in the default
   # buttons.  For example in converters_tests/ref_in_sectioning
   # or converters_tests/sections_and_printindex.
+  # Output units lists are rebuilt in the XS code.
   $self->_prepare_output_units_global_targets($output_units,
                                               $special_units,
                                               $associated_special_units);
@@ -12772,7 +12773,7 @@ sub output($$)
   # setup untranslated strings
   $self->_translate_names();
 
-  # The XS code override rebuilds output units, so there is no need to call
+  # Output units lists are rebuilt in the XS code so there is no need to call
   # rebuild_output_units.
   my $files_source_info
     = $self->_prepare_units_directions_files($output_units, $special_units,
diff --git a/tp/Texinfo/Convert/Info.pm b/tp/Texinfo/Convert/Info.pm
index d91dabbb1f..13c5f07908 100644
--- a/tp/Texinfo/Convert/Info.pm
+++ b/tp/Texinfo/Convert/Info.pm
@@ -98,7 +98,7 @@ sub output($$)
   }
 
   my $fh;
-  if (! $output_file eq '') {
+  if ($output_file ne '') {
     if ($self->get_conf('VERBOSE')) {
       print STDERR "Output file $output_file\n";
     }
@@ -117,13 +117,14 @@ sub output($$)
 
   my $header_bytes = length($header);
   my $complete_header_bytes = $header_bytes;
-  my $tree_units = Texinfo::Structuring::split_by_node($root);
+  my $output_units = Texinfo::Structuring::split_by_node($root);
 
   print STDERR "DOCUMENT\n" if ($self->get_conf('DEBUG'));
+
   my $out_file_nr = 0;
   my @indirect_files;
-  if (!defined($tree_units) or not defined($tree_units->[0])
-      or not defined($tree_units->[0]->{'unit_command'})) {
+  if (!defined($output_units) or not defined($output_units->[0])
+      or not defined($output_units->[0]->{'unit_command'})) {
     my $input_file_name;
     if ($self->{'document'}) {
       my $document_info = $self->{'document'}->global_information();
@@ -181,7 +182,7 @@ sub output($$)
     $out_file_nr = 1;
     my $first_node_seen = 0;
     $self->{'count_context'}->[-1]->{'bytes'} += $header_bytes;
-    foreach my $node_root_element (@$tree_units) {
+    foreach my $output_unit (@$output_units) {
       if ($first_node_seen
           and defined($self->get_conf('SPLIT_SIZE'))
           and $self->{'count_context'}->[-1]->{'bytes'} >
@@ -250,7 +251,7 @@ sub output($$)
         #print STDERR join(' --> ', @{$indirect_files[-1]}) ."\n";
       }
 
-      my $node_text = $self->convert_output_unit($node_root_element);
+      my $node_text = $self->convert_output_unit($output_unit);
       if ($node_text !~ /\n\n$/) {
         $node_text .= "\n";
         $self->{'count_context'}->[-1]->{'bytes'}++;
diff --git a/tp/Texinfo/Structuring.pm b/tp/Texinfo/Structuring.pm
index fb5ef1284f..a6e9e3c7ef 100644
--- a/tp/Texinfo/Structuring.pm
+++ b/tp/Texinfo/Structuring.pm
@@ -1805,7 +1805,6 @@ sub unsplit($)
 sub rebuild_output_units($)
 {
   my $output_units = shift;
-  return $output_units;
 }
 
 # Associate top-level units with pages according to the splitting
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.c 
b/tp/Texinfo/XS/convert/build_html_perl_state.c
index ed0799d068..bff7376059 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.c
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.c
@@ -137,9 +137,9 @@ build_html_files_source_info (FILE_SOURCE_INFO_LIST 
*files_source_info)
   return newRV_noinc ((SV *) hv);
 }
 
-HV *
+static HV *
 build_html_global_units_directions (const OUTPUT_UNIT 
**global_units_directions,
-                       SPECIAL_UNIT_DIRECTION *special_units_direction_name)
+                     const SPECIAL_UNIT_DIRECTION 
*special_units_direction_name)
 {
   int i;
   HV *hv;
@@ -161,13 +161,15 @@ build_html_global_units_directions (const OUTPUT_UNIT 
**global_units_directions,
         }
     }
 
-  /* html_prepare_units_directions_files is allocated because
-     html_prepare_units_directions_files was called before */
+  /* special_units_direction_name is allocated because
+     html_prepare_output_units_global_targets or
+     html_prepare_units_directions_files was called before
+     calling pass_html_global_units_directions */
   for (i = 0; special_units_direction_name[i].output_unit; i++)
     {
-      SPECIAL_UNIT_DIRECTION *special_unit_direction
+      const SPECIAL_UNIT_DIRECTION *special_unit_direction
        = &special_units_direction_name[i];
-      char *direction_name = special_unit_direction->direction;
+      const char *direction_name = special_unit_direction->direction;
       const OUTPUT_UNIT *output_unit = special_unit_direction->output_unit;
       hv_store (hv, direction_name, strlen (direction_name),
                   newRV_inc ((SV *) output_unit->hv), 0);
@@ -179,7 +181,7 @@ build_html_global_units_directions (const OUTPUT_UNIT 
**global_units_directions,
 void
 pass_html_global_units_directions (SV *converter_sv,
                        const OUTPUT_UNIT **global_units_directions,
-                       SPECIAL_UNIT_DIRECTION *special_units_direction_name)
+                   const SPECIAL_UNIT_DIRECTION *special_units_direction_name)
 {
   HV *global_units_directions_hv;
   SV *global_units_directions_sv;
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.h 
b/tp/Texinfo/XS/convert/build_html_perl_state.h
index c17b35f9c4..b8dc869eed 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.h
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.h
@@ -18,7 +18,7 @@ void build_html_translated_names (HV *hv, CONVERTER 
*converter);
 SV *build_html_files_source_info (FILE_SOURCE_INFO_LIST *files_source_info);
 void pass_html_global_units_directions (SV *converter_sv,
                        const OUTPUT_UNIT **global_units_directions,
-                       SPECIAL_UNIT_DIRECTION *special_units_direction_name);
+                   const SPECIAL_UNIT_DIRECTION *special_units_direction_name);
 void pass_html_elements_in_file_count (SV *converter_sv,
                    FILE_NAME_PATH_COUNTER_LIST *output_unit_files);
 
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 7b3aa3da35..dad45c4020 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1525,7 +1525,7 @@ build_output_units_list (size_t output_units_descriptor)
 
   if (!fill_output_units_descriptor_av (av_output_units,
                                         output_units_descriptor))
-    {
+    {/* no output unit */
       av_undef (av_output_units);
       return newSV(0);
     }
@@ -1533,6 +1533,32 @@ build_output_units_list (size_t output_units_descriptor)
     return newRV_noinc ((SV *) av_output_units);
 }
 
+void
+rebuild_output_units_list (SV *output_units_sv, size_t output_units_descriptor)
+{
+  AV *av_output_units;
+
+  dTHX;
+
+  if (!SvOK (output_units_sv))
+    {
+      OUTPUT_UNIT_LIST *output_units
+         = retrieve_output_units (output_units_descriptor);
+      if (output_units && output_units->number)
+        fprintf (stderr, "BUG: no input sv for %zu output units (%zu)",
+                 output_units->number, output_units_descriptor);
+      return;
+    }
+
+  av_output_units = (AV *) SvRV (output_units_sv);
+  av_clear (av_output_units);
+
+  if (!fill_output_units_descriptor_av (av_output_units,
+                                        output_units_descriptor))
+    /* TODO cannot associate output_units_descriptor. A problem? */
+    return;
+}
+
 SV *
 get_conf (CONVERTER *converter, const char *option_name)
 {
@@ -1606,32 +1632,6 @@ pass_converter_errors (ERROR_MESSAGE_LIST 
*error_messages,
   clear_error_message_list (error_messages);
 }
 
-void
-rebuild_output_units_list (SV *output_units_sv, size_t output_units_descriptor)
-{
-  AV *av_output_units;
-
-  dTHX;
-
-  if (!SvOK (output_units_sv))
-    {
-      OUTPUT_UNIT_LIST *output_units
-         = retrieve_output_units (output_units_descriptor);
-      if (output_units && output_units->number)
-        fprintf (stderr, "BUG: no input sv for %zu output units (%zu)",
-                 output_units->number, output_units_descriptor);
-      return;
-    }
-
-  av_output_units = (AV *) SvRV (output_units_sv);
-  av_clear (av_output_units);
-
-  if (!fill_output_units_descriptor_av (av_output_units,
-                                        output_units_descriptor))
-    /* TODO cannot associate output_units_descriptor. A problem? */
-    return;
-}
-
 AV *
 build_integer_stack (INTEGER_STACK *integer_stack)
 {
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index b780ef637f..9c1c126e92 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -154,6 +154,7 @@ get_sv_document_document (SV *document_in, char 
*warn_string)
                                warn_string);
 }
 
+/* caller should ensure that OUTPUT_UNIT_IN is defined */
 int
 get_sv_output_units_descriptor (SV *output_units_in, char *warn_string)
 {
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c 
b/tp/Texinfo/XS/parsetexi/end_line.c
index 151c4be261..5f8fb2b6b6 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -225,10 +225,9 @@ parse_line_command_args (ELEMENT *line_command)
         line += strspn (line, whitespace_chars);
         if (*line != ',')
           goto definfoenclose_invalid;
-        line++;
+        line++; /* Past ','. */
         line += strspn (line, whitespace_chars);
 
-        /* TODO: Can we have spaces in the delimiters? */
         len = strcspn (line, ",");
         start = strndup (line, len);
         line += len;
diff --git a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs 
b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
index 500fec3563..6af6a301e9 100644
--- a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+++ b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
@@ -400,24 +400,17 @@ unsplit (SV *tree_in)
     OUTPUT:
         RETVAL
 
-# return the input if XS information is missing
-SV *
+void
 rebuild_output_units (SV *output_units_in)
     PREINIT:
         int output_units_descriptor = 0;
      CODE:
-      /* This is called in Texinfo::Convert::Converter::output on
+      /* 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)
-          RETVAL = build_output_units_list (output_units_descriptor);
-        else
-         /* NOTE adding SvREFCNT_inc was done by trial and error
-            as without one gets "Useless assignment to a temporary" */
-          RETVAL = SvREFCNT_inc(output_units_in);
-    OUTPUT:
-        RETVAL
+          rebuild_output_units_list (output_units_in, output_units_descriptor);
 
 void
 split_pages (SV *output_units_in, char *split)
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index bfc5799c52..37d6db77fe 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -1383,12 +1383,12 @@ sub test($$)
     if ($self->{'DEBUG'} and $unsplit_needed);
 
   # There is no XS overriding for the following codes. rebuild_output_units
-  # returns the input output units if there is no XS structures, which allows
-  # to have tests passing when XS is used (in the default case).  If overriding
+  # does nothing if there is no XS structures, which allows to have tests
+  # passing when XS is used (in the default case).  If overriding
   # of XS is setup, most likely all the functions should have an XS override
   # (units_directions has not, though there is an implementation in C),
   # otherwise some information will be missing in the rebuild_output_units
-  # output.
+  # output units.
   my $output_units;
   if ($test_split eq 'node') {
     $output_units = Texinfo::Structuring::split_by_node($tree);
@@ -1411,8 +1411,7 @@ sub test($$)
   }
 
   if ($test_split or $split_pages) {
-    $output_units
-      = Texinfo::Structuring::rebuild_output_units($output_units);
+    Texinfo::Structuring::rebuild_output_units($output_units);
   }
 
   my $file = "t/results/$self->{'name'}/$test_name.pl";



reply via email to

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