texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/main/DocumentXS.xs, tp/Texinfo/XS


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/main/DocumentXS.xs, tp/Texinfo/XS/main/build_perl_info.c (document_tree): move document_tree code to a function in build_perl_info.c.
Date: Sun, 20 Oct 2024 09:05:09 -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 732d820715 * tp/Texinfo/XS/main/DocumentXS.xs, 
tp/Texinfo/XS/main/build_perl_info.c (document_tree): move document_tree code 
to a function in build_perl_info.c.
732d820715 is described below

commit 732d8207159e5d6e72bdc42d3771b229042f2c76
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Oct 20 15:05:01 2024 +0200

    * tp/Texinfo/XS/main/DocumentXS.xs,
    tp/Texinfo/XS/main/build_perl_info.c (document_tree): move
    document_tree code to a function in build_perl_info.c.
    
    * tp/Texinfo/XS/parsetexi/Parsetexi.pm,
    tp/Texinfo/XS/parsetexi/Parsetexi.xs (parse_texi_line): in
    Parsetexi.xs define directly parse_texi_line instead of parse_string
    by calling document_tree to get the tree.  Remove parse_texi_line from
    Parsetexi.pm.
---
 ChangeLog                            | 12 ++++++++++++
 tp/Texinfo/XS/main/DocumentXS.xs     | 30 ----------------------------
 tp/Texinfo/XS/main/build_perl_info.c | 38 ++++++++++++++++++++++++++++++++++++
 tp/Texinfo/XS/main/build_perl_info.h |  1 +
 tp/Texinfo/XS/parsetexi/Parsetexi.pm | 11 +++--------
 tp/Texinfo/XS/parsetexi/Parsetexi.xs |  8 +++++---
 6 files changed, 59 insertions(+), 41 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 72e0e4cdbd..4f5ec8ebc8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-10-20  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/DocumentXS.xs,
+       tp/Texinfo/XS/main/build_perl_info.c (document_tree): move
+       document_tree code to a function in build_perl_info.c.
+
+       * tp/Texinfo/XS/parsetexi/Parsetexi.pm,
+       tp/Texinfo/XS/parsetexi/Parsetexi.xs (parse_texi_line): in
+       Parsetexi.xs define directly parse_texi_line instead of parse_string
+       by calling document_tree to get the tree.  Remove parse_texi_line from
+       Parsetexi.pm.
+
 2024-10-20  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/parsetexi/Parsetexi.pm (parse_texi_line),
diff --git a/tp/Texinfo/XS/main/DocumentXS.xs b/tp/Texinfo/XS/main/DocumentXS.xs
index 550689a35c..e08379cb8e 100644
--- a/tp/Texinfo/XS/main/DocumentXS.xs
+++ b/tp/Texinfo/XS/main/DocumentXS.xs
@@ -223,36 +223,6 @@ set_document_global_info (SV *document_in, char *key, SV 
*value_sv)
 
 SV *
 document_tree (SV *document_in, int handler_only=0)
-    PREINIT:
-        HV *document_hv;
-        SV *result_sv = 0;
-        const char *key = "tree";
-     CODE:
-        document_hv = (HV *) SvRV (document_in);
-
-        if (!handler_only)
-          {
-            DOCUMENT *document = get_sv_document_document (document_in, 0);
-            if (document)
-              result_sv = store_document_texinfo_tree (document, document_hv);
-          }
-
-        if (!result_sv)
-          {
-            SV **sv_reference = hv_fetch (document_hv, key, strlen (key), 0);
-            if (sv_reference && SvOK (*sv_reference))
-              result_sv = *sv_reference;
-          }
-
-        if (result_sv)
-          {
-            RETVAL = result_sv;
-            SvREFCNT_inc (result_sv);
-          }
-        else
-          RETVAL = newSV (0);
-    OUTPUT:
-        RETVAL
 
 SV *
 document_global_information (SV *document_in)
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 5b2049961c..52f4f5047b 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1988,6 +1988,44 @@ store_document_texinfo_tree (DOCUMENT *document, HV 
*document_hv)
   return result_sv;
 }
 
+/* Get a reference to the document tree.  Either from C data if the
+   document could be found and if HANDLER_ONLY is not set, else from
+   the Perl DOCUMENT_IN.
+   If the C document data was not stored, the tree will be only be
+   in the Perl document. */
+SV *
+document_tree (SV *document_in, int handler_only)
+{
+  HV *document_hv;
+  SV *result_sv = 0;
+
+  dTHX;
+
+  document_hv = (HV *) SvRV (document_in);
+
+  if (!handler_only)
+    {
+      DOCUMENT *document = get_sv_document_document (document_in, 0);
+      if (document)
+        result_sv = store_document_texinfo_tree (document, document_hv);
+    }
+
+  if (!result_sv)
+    {
+      SV **sv_reference = hv_fetch (document_hv, "tree", strlen ("tree"), 0);
+      if (sv_reference && SvOK (*sv_reference))
+        result_sv = *sv_reference;
+    }
+
+  if (result_sv)
+    {
+      SvREFCNT_inc (result_sv);
+      return result_sv;
+    }
+  else
+    return newSV (0);
+}
+
 /* Build Texinfo Document registered data to Perl */
 
 /* there are 2 differences between BUILD_PERL_DOCUMENT_ITEM and
diff --git a/tp/Texinfo/XS/main/build_perl_info.h 
b/tp/Texinfo/XS/main/build_perl_info.h
index 8b15c3873b..872969c74c 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -49,6 +49,7 @@ SV *get_or_build_document (SV *parser_sv, size_t 
document_descriptor,
 
 SV *store_document_texinfo_tree (DOCUMENT *document, HV *document_hv);
 
+SV *document_tree (SV *document_in, int handler_only);
 SV *document_indices_information (SV *document_in);
 SV *document_global_commands_information (SV *document_in);
 SV *document_labels_information (SV *document_in);
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm 
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index 7b6e3751d4..c6a651dd72 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -41,6 +41,9 @@ use warnings;
 #no autovivification qw(fetch delete exists store strict);
 
 use Texinfo::Report;
+# Not directly used, but the returned variables are in this module, this
+# import makes sure that the functions associated to the objects are found.
+use Texinfo::Document;
 
 # Initialize the parser
 # The last argument, optional, is a hash provided by the user to change
@@ -134,14 +137,6 @@ sub parser (;$)
   return $parser;
 }
 
-sub parse_texi_line($$;$$)
-{
-  my ($self, $text, $line_nr, $no_store) = @_;
-  my $document = parse_string($self, $text, $line_nr, $no_store);
-  return undef if (!defined($document));
-  return $document->tree();
-}
-
 sub errors($)
 {
   my $self = shift;
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs 
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index 8ee0c3491e..4fec771f13 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -137,7 +137,7 @@ parse_texi_piece (SV *parser, SV *string_sv, ...)
         RETVAL
 
 SV *
-parse_string (SV *parser, SV *string_sv, ...)
+parse_texi_line (SV *parser, SV *string_sv, ...)
     PREINIT:
         size_t document_descriptor = 0;
         int no_store = 0;
@@ -148,14 +148,16 @@ parse_string (SV *parser, SV *string_sv, ...)
         else
           {
             char *string = (char *)SvPVutf8_nolen (string_sv);
+            SV *document_sv;
             if (items > 2 && SvOK(ST(2)))
               line_nr = SvIV (ST(2));
             if (items > 3 && SvOK(ST(3)))
               no_store = SvIV (ST(3));
             apply_sv_parser_conf (parser);
             document_descriptor = parse_string (string, line_nr);
-            RETVAL = get_or_build_document (parser, document_descriptor,
-                                            no_store);
+            document_sv = get_or_build_document (parser, document_descriptor,
+                                                 no_store);
+            RETVAL = document_tree (document_sv, 0);
           }
       OUTPUT:
         RETVAL



reply via email to

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