texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Common.pm (import, copy_treeNonXS, c


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Common.pm (import, copy_treeNonXS, copy_contentsNonXS), tp/Texinfo/Structuring.pm (import), tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs (copy_tree), tp/t/test_tree_copy.t: remove copy_tree from Structuring.pm. Override copy_tree in Common.pm. Let XS copy_tree build the tree and return the perl tree. Add NonXS variants for copy_tree and copy_contents for situations where the XS tree cannot be found or where we want to modify perl trees only. Update callers of co [...]
Date: Wed, 25 Oct 2023 06:01:54 -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 0e2205552f * tp/Texinfo/Common.pm (import, copy_treeNonXS, 
copy_contentsNonXS), tp/Texinfo/Structuring.pm (import), 
tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs (copy_tree), 
tp/t/test_tree_copy.t: remove copy_tree from Structuring.pm.  Override 
copy_tree in Common.pm.  Let XS copy_tree build the tree and return the perl 
tree.  Add NonXS variants for copy_tree and copy_contents for situations where 
the XS tree cannot be found or where we want to modify perl trees only.  [...]
0e2205552f is described below

commit 0e2205552fef7729437395347e4524483f066de1
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Oct 25 12:01:55 2023 +0200

    * tp/Texinfo/Common.pm (import, copy_treeNonXS, copy_contentsNonXS),
    tp/Texinfo/Structuring.pm (import),
    tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs (copy_tree),
    tp/t/test_tree_copy.t: remove copy_tree from Structuring.pm.  Override
    copy_tree in Common.pm.  Let XS copy_tree build the tree and return the
    perl tree.  Add NonXS variants for copy_tree and copy_contents for
    situations where the XS tree cannot be found or where we want to
    modify perl trees only.  Update callers of copy_tree and
    copy_contents, using the NonXS or the overriden function.
    
    * tp/t/automatic_nodes.t, tp/t/test_fill_gaps_in_sectioning.t: fix
    skip call.
---
 ChangeLog                                          | 15 +++++++++
 tp/Texinfo/Common.pm                               | 32 +++++++++++++++---
 tp/Texinfo/Structuring.pm                          | 38 +++++-----------------
 tp/Texinfo/Transformations.pm                      |  2 +-
 tp/Texinfo/TranslationsNonXS.pm                    | 10 +++---
 .../XS/structuring_transfo/StructuringTransfo.xs   | 22 ++++---------
 tp/t/automatic_nodes.t                             |  4 +--
 tp/t/test_fill_gaps_in_sectioning.t                |  2 +-
 tp/t/test_tree_copy.t                              | 22 +++++++++----
 9 files changed, 82 insertions(+), 65 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f6fb769d3c..c02057f6cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2023-10-26  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Common.pm (import, copy_treeNonXS, copy_contentsNonXS),
+       tp/Texinfo/Structuring.pm (import),
+       tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs (copy_tree),
+       tp/t/test_tree_copy.t: remove copy_tree from Structuring.pm.  Override
+       copy_tree in Common.pm.  Let XS copy_tree build the tree and return the
+       perl tree.  Add NonXS variants for copy_tree and copy_contents for
+       situations where the XS tree cannot be found or where we want to
+       modify perl trees only.  Update callers of copy_tree and
+       copy_contents, using the NonXS or the overriden function.
+
+       * tp/t/automatic_nodes.t, tp/t/test_fill_gaps_in_sectioning.t: fix
+       skip call.
+
 2023-10-25  Patrice Dumas  <pertusus@free.fr>
 
        * util/texi-elements-by-size: pass a document in argument of
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 12f3d0277c..fc696fad7a 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -83,6 +83,12 @@ sub import {
   if (!$module_loaded) {
     if (!defined $ENV{TEXINFO_XS_PARSER}
         or $ENV{TEXINFO_XS_PARSER} eq '1') {
+      Texinfo::XSLoader::override(
+        "Texinfo::Common::_XS_set_document_options",
+        "Texinfo::StructTransf::set_document_options");
+      Texinfo::XSLoader::override(
+        "Texinfo::Common::copy_tree",
+        "Texinfo::StructTransf::copy_tree");
       Texinfo::XSLoader::override(
         "Texinfo::Common::relate_index_entries_to_table_items_in_tree",
         "Texinfo::StructTransf::relate_index_entries_to_table_items_in_tree"
@@ -103,10 +109,6 @@ sub import {
         "Texinfo::Common::protect_node_after_label_in_tree",
         "Texinfo::StructTransf::protect_node_after_label_in_tree"
       );
-      Texinfo::XSLoader::override(
-        "Texinfo::Common::_XS_set_document_options",
-        "Texinfo::StructTransf::set_document_options"
-      );
     }
     $module_loaded = 1;
   }
@@ -2047,6 +2049,16 @@ sub copy_tree($;$)
   return $copy;
 }
 
+# Never overriden by XS version
+sub copy_treeNonXS($;$)
+{
+  my $current = shift;
+  my $parent = shift;
+  my $copy = _copy_tree($current, $parent);
+  _copy_extra_info($current, $copy);
+  return $copy;
+}
+
 sub copy_contents($;$)
 {
   my $element = shift;
@@ -2059,6 +2071,18 @@ sub copy_contents($;$)
   return $copy;
 }
 
+sub copy_contentsNonXS($;$)
+{
+  my $element = shift;
+  my $type = shift;
+  my $tmp = {'contents' => $element->{'contents'}};
+  my $copy = copy_treeNonXS($tmp);
+  if (defined($type)) {
+    $copy->{'type'} = $type;
+  }
+  return $copy;
+}
+
 sub modify_tree($$;$);
 sub modify_tree($$;$)
 {
diff --git a/tp/Texinfo/Structuring.pm b/tp/Texinfo/Structuring.pm
index c610958eb4..c9ce634a2a 100644
--- a/tp/Texinfo/Structuring.pm
+++ b/tp/Texinfo/Structuring.pm
@@ -95,12 +95,7 @@ sub import {
         "Texinfo::StructTransf::rebuild_tree");
       Texinfo::XSLoader::override(
         "Texinfo::Structuring::clear_document_errors",
-        "Texinfo::StructTransf::clear_document_errors",
-      );
-      Texinfo::XSLoader::override(
-        "Texinfo::Structuring::_XS_copy_tree",
-        "Texinfo::StructTransf::copy_tree"
-      );
+        "Texinfo::StructTransf::clear_document_errors");
       Texinfo::XSLoader::override(
         "Texinfo::Structuring::associate_internal_references",
         "Texinfo::StructTransf::associate_internal_references"
@@ -146,7 +141,7 @@ sub import {
       #  "Texinfo::Structuring::split_by_node",
       #  "Texinfo::StructTransf::split_by_node");
       #Texinfo::XSLoader::override(
-      #  "Texinfo::Structuring::_XS_split_by_section",
+      #  "Texinfo::Structuring::split_by_section",
       #  "Texinfo::StructTransf::split_by_section");
       #Texinfo::XSLoader::override(
       #  "Texinfo::Structuring::split_pages",
@@ -196,23 +191,6 @@ sub clear_document_errors($)
 {
 }
 
-sub _XS_copy_tree($$)
-{
-  return 0;
-}
-
-sub copy_tree($;$)
-{
-  my $tree = shift;
-  my $parent = shift;
-  my $descriptor = _XS_copy_tree($tree, $parent);
-  my $result = Texinfo::Common::copy_tree($tree, $parent);
-  if ($descriptor != 0 and $result) {
-    $result->{'tree_document_descriptor'} = $descriptor;
-  }
-  return $result;
-}
-
 # Go through the sectioning commands (e.g. @chapter, not @node), and
 # set:
 # 'section_level'
@@ -1364,7 +1342,7 @@ sub new_node_menu_entry
     }
 
     $menu_entry_name
-        = Texinfo::Common::copy_contents($name_element, 'menu_entry_name');
+     = Texinfo::Common::copy_contentsNonXS($name_element, 'menu_entry_name');
     foreach my $content (@{$menu_entry_name->{'contents'}}) {
       $content->{'parent'} = $menu_entry_name;
     }
@@ -1376,7 +1354,7 @@ sub new_node_menu_entry
   my $entry = {'type' => 'menu_entry'};
 
   my $menu_entry_node
-    = Texinfo::Common::copy_contents($node_name_element, 'menu_entry_node');
+   = Texinfo::Common::copy_contentsNonXS($node_name_element, 
'menu_entry_node');
   foreach my $content (@{$menu_entry_node->{'contents'}}) {
     $content->{'parent'} = $menu_entry_node;
   }
@@ -1599,9 +1577,7 @@ sub _print_down_menus($$;$)
   foreach my $menu (@menus) {
     foreach my $entry (@{$menu->{'contents'}}) {
       if ($entry->{'type'} and $entry->{'type'} eq 'menu_entry') {
-        # Should use copy_tree from Structuring to use XS code, but
-        # the tree would have to be registered first.
-        push @master_menu_contents, Texinfo::Common::copy_tree($entry);
+        push @master_menu_contents, Texinfo::Common::copy_treeNonXS($entry);
         # gather node children to recursively print their menus
         my $node
              = _normalized_entry_associated_internal_node($entry,
@@ -1621,7 +1597,9 @@ sub _print_down_menus($$;$)
     } else {
       $node_name_element = $node->{'args'}->[0];
     }
-    my $node_title_copy = Texinfo::Common::copy_contents($node_name_element);
+
+    my $node_title_copy
+      = Texinfo::Common::copy_contentsNonXS($node_name_element);
     my $menu_comment = {'type' => 'menu_comment', 'contents' => []};
     my $preformatted = {'type' => 'preformatted', 'parent' => $menu_comment};
     $menu_comment->{'contents'}->[0] = $preformatted;
diff --git a/tp/Texinfo/Transformations.pm b/tp/Texinfo/Transformations.pm
index d512032ce4..836e1b4aae 100644
--- a/tp/Texinfo/Transformations.pm
+++ b/tp/Texinfo/Transformations.pm
@@ -442,7 +442,7 @@ sub insert_nodes_for_sectioning_commands($;$$)
         $new_node_tree = {'contents' => [{'text' => 'Top'}]};
       } else {
         $new_node_tree
-           = Texinfo::Common::copy_contents($content->{'args'}->[0]);
+           = Texinfo::Common::copy_contentsNonXS($content->{'args'}->[0]);
       }
       my $new_node = _new_node($new_node_tree, $document, $registrar,
                                $customization_information);
diff --git a/tp/Texinfo/TranslationsNonXS.pm b/tp/Texinfo/TranslationsNonXS.pm
index 2563097f9d..5e9af44afe 100644
--- a/tp/Texinfo/TranslationsNonXS.pm
+++ b/tp/Texinfo/TranslationsNonXS.pm
@@ -451,7 +451,7 @@ if (0) {
 
 # In a handful of cases, we delay storing the contents of the
 # index entry until now to avoid needing Texinfo::Translations::gdt
-# in the main code of Parser.pm.
+# in the main code of ParserNonXS.pm.
 sub complete_indices($$)
 {
   my $customization_information = shift;
@@ -484,10 +484,10 @@ sub complete_indices($$)
 
           my $def_command = $main_entry_element->{'extra'}->{'def_command'};
 
-          my $class_copy = Texinfo::Common::copy_tree($class, undef);
-          my $name_copy = Texinfo::Common::copy_tree($name, undef);
-          my $ref_class_copy = Texinfo::Common::copy_tree($class, undef);
-          my $ref_name_copy = Texinfo::Common::copy_tree($name, undef);
+          my $class_copy = Texinfo::Common::copy_treeNonXS($class, undef);
+          my $name_copy = Texinfo::Common::copy_treeNonXS($name, undef);
+          my $ref_class_copy = Texinfo::Common::copy_treeNonXS($class, undef);
+          my $ref_name_copy = Texinfo::Common::copy_treeNonXS($name, undef);
 
           # Use the document language that was current when the command was
           # used for getting the translation.
diff --git a/tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs 
b/tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs
index 463970fb11..cdbc86f8e0 100644
--- a/tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs
+++ b/tp/Texinfo/XS/structuring_transfo/StructuringTransfo.xs
@@ -190,36 +190,26 @@ fill_gaps_in_sectioning (SV *tree_in)
           }
 
 # FIXME what to do with the parent argument?
-# FIXME add another way to call that returns a fake tree?
-int
-copy_tree (SV *tree_in, SV *parent_in)
+SV *
+copy_tree (SV *tree_in, SV *parent_in=0)
     PREINIT:
-        ELEMENT *result;
         DOCUMENT *document;
-        int copy_document_descriptor;
      CODE:
-        /* FIXME warning/error if not found? */
-        document = get_sv_tree_document (tree_in, 0);
+        document = get_sv_tree_document (tree_in, "copy_tree");
         if (document)
           {
-            result = copy_tree (document->tree, 0);
+            ELEMENT *result = copy_tree (document->tree, 0);
             /* FIXME have a similar system but for trees only? */
-            copy_document_descriptor = register_document (result, 0, 0, 0,
+            int copy_document_descriptor = register_document (result, 0, 0, 0,
                                                       0, 0, 0, 0, 0, 0);
-            /* to return a fake element
-            HV *hv = newHV ();
+            HV *hv = build_texinfo_tree (result);
             hv_store (hv, "tree_document_descriptor",
                       strlen ("tree_document_descriptor"),
                       newSViv ((IV) copy_document_descriptor), 0);
             RETVAL = newRV_inc ((SV *) hv);
-            */
-            RETVAL = copy_document_descriptor;
           }
         else
-          /*
           RETVAL = newSV(0);
-           */
-          RETVAL = 0;
     OUTPUT:
         RETVAL
 
diff --git a/tp/t/automatic_nodes.t b/tp/t/automatic_nodes.t
index 7d3ba2d3ce..5f426988d3 100644
--- a/tp/t/automatic_nodes.t
+++ b/tp/t/automatic_nodes.t
@@ -60,7 +60,7 @@ sub test_new_node($$$$)
 }
 SKIP:
 {
-  skip "test perl not XS", 7 * 3, $with_XS;
+  skip "test perl not XS", 7 * 3 if ($with_XS);
 
 test_new_node ('a node', 'a-node', '@node a node
 ', 'simple');
@@ -94,7 +94,7 @@ my $line_tree = Texinfo::Parser::parse_texi_line (undef, 'a 
node');
 
 SKIP:
 {
-  skip "test perl not XS", 1, $with_XS;
+  skip "test perl not XS", 1 if ($with_XS);
 
 my $new_node = Texinfo::Transformations::_new_node($line_tree, $document);
 is ('@node a node 1
diff --git a/tp/t/test_fill_gaps_in_sectioning.t 
b/tp/t/test_fill_gaps_in_sectioning.t
index 52480787c7..d89537e670 100644
--- a/tp/t/test_fill_gaps_in_sectioning.t
+++ b/tp/t/test_fill_gaps_in_sectioning.t
@@ -68,7 +68,7 @@ my $with_XS = ((not defined($ENV{TEXINFO_XS})
 
 SKIP:
 {
-  skip "test perl not XS", 2, $with_XS;
+  skip "test perl not XS", 2 if ($with_XS);
 
 test_correction('@raisesections
 
diff --git a/tp/t/test_tree_copy.t b/tp/t/test_tree_copy.t
index 8f7491bc4b..ed6c5b9ae3 100644
--- a/tp/t/test_tree_copy.t
+++ b/tp/t/test_tree_copy.t
@@ -12,10 +12,10 @@ use Data::Dumper;
 use File::Spec;
 #use Text::Diff;
 
+use Texinfo::Common;
 use Texinfo::Parser;
-use Texinfo::Convert::Texinfo;
-# use copy_tree from Texinfo::Structuring to use the XS version.
 use Texinfo::Structuring;
+use Texinfo::Convert::Texinfo;
 
 my $srcdir = $ENV{'srcdir'};
 if (defined($srcdir)) {
@@ -26,6 +26,11 @@ if (defined($srcdir)) {
 
 my $debug = 0;
 
+my $with_XS = ((not defined($ENV{TEXINFO_XS})
+                or $ENV{TEXINFO_XS} ne 'omit')
+               and (!defined $ENV{TEXINFO_XS_PARSER}
+                    or $ENV{TEXINFO_XS_PARSER} eq '1'));
+
 ok(1, "modules loading");
 
 # FIXME not tested in XS
@@ -51,14 +56,19 @@ 
$tref->{'contents'}->[1]->{'extra'}->{'thing'}->{'contents'}->[0]->{'extra'}->{'
 
 my $tref_texi = Texinfo::Convert::Texinfo::convert_to_texinfo($tref);
 
-my $tref_copy = Texinfo::Structuring::copy_tree($tref, undef);
+my $tref_copy = Texinfo::Common::copy_tree($tref, undef);
 
 my $tref_copy_texi = Texinfo::Convert::Texinfo::convert_to_texinfo($tref_copy);
 
 # Does not test much as the reference in extra does not appear in the
 # output.  Not a big deal, what is important it so see if there are error
 # messages.
+
+SKIP:
+{
+  skip "test perl not XS", 1 if ($with_XS);
 is ($tref_texi, $tref_copy_texi, "ref within extra tree");
+}
 
 my $text = '@setfilename some@@file.ext
 
@@ -131,7 +141,7 @@ my $test_parser = Texinfo::Parser::parser();
 my $document = Texinfo::Parser::parse_texi_piece($test_parser, $text);
 my $tree = $document->tree();
 my $test_registrar = $test_parser->registered_errors();
-my $copy = Texinfo::Structuring::copy_tree($tree, undef);
+my $copy = Texinfo::Common::copy_tree($tree, undef);
 
 my $texi_tree = Texinfo::Convert::Texinfo::convert_to_texinfo($tree);
 
@@ -146,7 +156,7 @@ Texinfo::Structuring::sectioning_structure($tree, 
$test_registrar,
 
 $tree = Texinfo::Structuring::rebuild_tree($tree);
 
-my $copy_with_sec = Texinfo::Structuring::copy_tree($tree, undef);
+my $copy_with_sec = Texinfo::Common::copy_tree($tree, undef);
 
 my $texi_tree_with_sec = Texinfo::Convert::Texinfo::convert_to_texinfo($tree);
 my $texi_copy_with_sec
@@ -178,7 +188,7 @@ foreach my $file_include (['Texinfo', $manual_file, 
$manual_include_dir],
     warn "$label: ".$error_message->{'error_line'}
       if ($debug);
   }
-  my $test_tree_copy = Texinfo::Structuring::copy_tree($texinfo_test_tree, 
undef);
+  my $test_tree_copy = Texinfo::Common::copy_tree($texinfo_test_tree, undef);
 
   my $test_texi
      = Texinfo::Convert::Texinfo::convert_to_texinfo($texinfo_test_tree);



reply via email to

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