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/build_perl_info.c (build_glo


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/main/build_perl_info.c (build_global_info): add a converter argument to try to reuse the "global_info" value of the Perl document hash instead of systematically creating a new HV. Update callers.
Date: Fri, 17 Jan 2025 13:17:50 -0500

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 3d592bc86f * tp/Texinfo/XS/main/build_perl_info.c (build_global_info): 
add a converter argument to try to reuse the "global_info" value of the Perl 
document hash instead of systematically creating a new HV.  Update callers.
3d592bc86f is described below

commit 3d592bc86f0cfe5f6829f97e559f87dae9c8c013
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Jan 17 19:17:51 2025 +0100

    * tp/Texinfo/XS/main/build_perl_info.c (build_global_info): add a
    converter argument to try to reuse the "global_info" value of the Perl
    document hash instead of systematically creating a new HV.  Update
    callers.
    
    * tp/Texinfo/Document.pm (%XS_overrides, set_document_global_info):
    override directly set_document_global_info.  Remove
    _XS_set_document_global_info.
    
    * tp/t/z_misc/test_document.t: call global_information() after
    set_document_global_info before accessing the hash.
    
    * tp/Texinfo/XS/main/DocumentXS.xs (set_document_global_info): add a
    string to get a warning if the document is not found in
    set_document_global_info.
    
    * tp/t/z_misc/test_document.t: update Texinfo::ModulePath updirs.
---
 ChangeLog                                        | 20 +++++++++++++++
 doc/tp_api/api_includes/Texinfo-Document.texi    | 30 ++++++-----------------
 doc/tp_api/api_includes/Texinfo-Parser.texi      |  2 +-
 doc/tp_api/api_includes/Texinfo-Structuring.texi | 27 +++++++++++----------
 tp/Texinfo/Document.pm                           | 12 +++------
 tp/Texinfo/ParserNonXS.pm                        |  2 +-
 tp/Texinfo/XS/main/DocumentXS.xs                 |  3 ++-
 tp/Texinfo/XS/main/build_perl_info.c             | 31 ++++++++++++++++++------
 tp/t/z_misc/test_document.t                      |  5 +++-
 9 files changed, 76 insertions(+), 56 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ffdd9240dc..e19b3f0c12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2025-01-17  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/build_perl_info.c (build_global_info): add a
+       converter argument to try to reuse the "global_info" value of the Perl
+       document hash instead of systematically creating a new HV.  Update
+       callers.
+
+       * tp/Texinfo/Document.pm (%XS_overrides, set_document_global_info):
+       override directly set_document_global_info.  Remove
+       _XS_set_document_global_info.
+
+       * tp/t/z_misc/test_document.t: call global_information() after
+       set_document_global_info before accessing the hash.
+
+       * tp/Texinfo/XS/main/DocumentXS.xs (set_document_global_info): add a
+       string to get a warning if the document is not found in
+       set_document_global_info.
+
+       * tp/t/z_misc/test_document.t: update Texinfo::ModulePath updirs.
+
 2025-01-17  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Structuring.pm (construct_nodes_tree),
diff --git a/doc/tp_api/api_includes/Texinfo-Document.texi 
b/doc/tp_api/api_includes/Texinfo-Document.texi
index 544c1b067a..7cb27f629f 100644
--- a/doc/tp_api/api_includes/Texinfo-Document.texi
+++ b/doc/tp_api/api_includes/Texinfo-Document.texi
@@ -111,6 +111,9 @@ Binary strings.  In @code{texi2any}, they should come from 
the command line
 
 @end table
 
+If the global information changed, @code{global_information} should be called
+to update the hash returned by previous calls before accessing the hash again.
+
 @end table
 
 Some command lists are available, such that it is possible to go through
@@ -192,17 +195,14 @@ to the same document with @@-commands that refer to node, 
anchors or floats.
 @anchor{Texinfo@asis{::}Document $nodes_list = nodes_list($document)}
 
 Returns an array reference containing the document nodes.  In general set to
-the nodes list returned by @ref{Texinfo@asis{::}Structuring $nodes_list = 
nodes_tree($document),, Texinfo::Structuring
-nodes_tree}, by a call
-to @ref{Texinfo@asis{::}Document register_document_nodes_list 
($document@comma{}
-$nodes_list),, register_document_nodes_list}.
+the nodes list constructed by @ref{Texinfo@asis{::}Structuring $nodes_list = 
construct_nodes_tree($document),, Texinfo::Structuring
+construct_nodes_tree}.
 
 @item $sections_list = sections_list($document)
 @anchor{Texinfo@asis{::}Document $sections_list = sections_list($document)}
 
-Returns an array reference containing the document sections.  In general set 
to the sections list returned by
-@ref{Texinfo@asis{::}Structuring $sections_list = 
sectioning_structure($document),, Texinfo::Structuring sectioning_structure},
-by a call to @ref{Texinfo@asis{::}Document register_document_sections_list 
($document@comma{} $sections_list),, register_document_sections_list}.
+Returns an array reference containing the document sections.  In general set 
to the sections list determined by
+@ref{Texinfo@asis{::}Structuring $sections_list = 
sectioning_structure($document),, Texinfo::Structuring sectioning_structure}.
 
 @end table
 
@@ -438,14 +438,6 @@ during parsing and correspond to information returned by 
the other methods.
 Further information can be registered in the document.
 
 @table @asis
-@item register_document_nodes_list ($document, $nodes_list)
-@anchor{Texinfo@asis{::}Document register_document_nodes_list 
($document@comma{} $nodes_list)}
-@cindex @code{register_document_nodes_list}
-
-Register the @emph{$nodes_list} array reference as @emph{$document} nodes
-list.  This method should be called after the processing of document
-structure.
-
 @item register_document_options ($document, $options)
 @anchor{Texinfo@asis{::}Document register_document_options ($document@comma{} 
$options)}
 @cindex @code{register_document_options}
@@ -458,14 +450,6 @@ Indeed, document customization options are mainly accessed 
by structuring and
 tree transformation methods (by calling @ref{Texinfo@asis{::}Document $value = 
$document->get_conf($variable_name),, @code{get_conf}}). The options should in 
general be registered before
 the calls to @code{get_conf}.
 
-@item register_document_sections_list ($document, $sections_list)
-@anchor{Texinfo@asis{::}Document register_document_sections_list 
($document@comma{} $sections_list)}
-@cindex @code{register_document_sections_list}
-
-Register the @emph{$sections_list} array reference as @emph{$document} sections
-list.  This method should be called after the processing of document
-structure.
-
 @item set_document_global_info($document, $key, $value)
 @anchor{Texinfo@asis{::}Document set_document_global_info($document@comma{} 
$key@comma{} $value)}
 @cindex @code{set_document_global_info}
diff --git a/doc/tp_api/api_includes/Texinfo-Parser.texi 
b/doc/tp_api/api_includes/Texinfo-Parser.texi
index 811d6c2dd8..16fe8b729e 100644
--- a/doc/tp_api/api_includes/Texinfo-Parser.texi
+++ b/doc/tp_api/api_includes/Texinfo-Parser.texi
@@ -1350,7 +1350,7 @@ if there is an associated external manual name, and a 
@emph{normalized} key for
 normalized label, built as specified in the @emph{HTML Xref} Texinfo 
documentation
 node.
 
-If you called @ref{Texinfo@asis{::}Structuring $nodes_list = 
nodes_tree($document),, Texinfo::Structuring::nodes_tree},
+If you called @ref{Texinfo@asis{::}Structuring $nodes_list = 
construct_nodes_tree($document),, Texinfo::Structuring::construct_nodes_tree},
 the @emph{node_directions} hash in the @code{@@node} element @code{extra} 
associates
 @emph{up}, @emph{next} and @emph{prev} keys to the elements corresponding to 
the node
 line directions.
diff --git a/doc/tp_api/api_includes/Texinfo-Structuring.texi 
b/doc/tp_api/api_includes/Texinfo-Structuring.texi
index 116873b412..7cbacec7ee 100644
--- a/doc/tp_api/api_includes/Texinfo-Structuring.texi
+++ b/doc/tp_api/api_includes/Texinfo-Structuring.texi
@@ -10,14 +10,14 @@ Texinfo::Structuring - information on Texinfo::Document 
document structure
 @section Texinfo::Structuring SYNOPSIS
 
 @verbatim
-  use Texinfo::Structuring qw(sectioning_structure nodes_tree number_floats
-    associate_internal_references);
+  use Texinfo::Structuring qw(sectioning_structure construct_nodes_tree
+    number_floats associate_internal_references);
 
   # $document is a parsed Texinfo::Document document.
   # When customization variables information is needed, it is obtained
   # from the $document by calling the get_conf() method.
-  my $sections_list = sectioning_structure($document);
-  my $nodes_list = nodes_tree($document);
+  sectioning_structure($document);
+  construct_nodes_tree($document);
   set_menus_node_directions($document);
   complete_node_tree_with_menus($document);
   check_nodes_are_referenced($document);
@@ -38,9 +38,9 @@ Texinfo to other formats.  There is no promise of API 
stability.
 document structure.  Thanks to @code{sectioning_structure} the hierarchy of
 sectioning commands is determined.  The directions implied by menus are
 determined with @code{set_menus_node_directions}.  The node tree is analysed
-with @code{nodes_tree}.  Nodes directions are completed with menu directions
-with @code{complete_node_tree_with_menus}.  Floats get their standard
-numbering with @code{number_floats} and internal references are matched up
+with @code{construct_nodes_tree}.  Nodes directions are completed with
+menu directions with @code{complete_node_tree_with_menus}.  Floats get their
+standard numbering with @code{number_floats} and internal references are 
matched up
 with nodes, floats or anchors with @code{associate_internal_references}.
 
 @node Texinfo@asis{::}Structuring METHODS
@@ -132,12 +132,12 @@ Returns the Texinfo tree corresponding to a single menu 
entry pointing to
 @emph{$node}.  If @emph{$use_sections} is set, use the section name for the 
menu
 entry name.  Returns @code{undef} if the node argument is missing.
 
-@item $nodes_list = nodes_tree($document)
-@anchor{Texinfo@asis{::}Structuring $nodes_list = nodes_tree($document)}
-@cindex @code{nodes_tree}
+@item $nodes_list = construct_nodes_tree($document)
+@anchor{Texinfo@asis{::}Structuring $nodes_list = 
construct_nodes_tree($document)}
+@cindex @code{construct_nodes_tree}
 
-Goes through nodes in @emph{$document} tree and set directions.  Returns the
-list of nodes.
+Goes through nodes in @emph{$document} tree and set directions.  Set the list 
of
+nodes in the @emph{$document}.  Returns the list of nodes.
 
 This functions sets, in the @code{extra} node element hash:
 
@@ -171,7 +171,8 @@ and lowered sections, when needed.
 @cindex @code{sectioning_structure}
 
 This function goes through the parsed document tree and gather information
-on the document structure for sectioning commands.  It returns a reference
+on the document structure for sectioning commands.  It sets the sections
+elements list in the document and returns a reference
 on the sections elements list.
 
 It sets section elements @code{extra} hash values:
diff --git a/tp/Texinfo/Document.pm b/tp/Texinfo/Document.pm
index ba16d5dff9..70be06558e 100644
--- a/tp/Texinfo/Document.pm
+++ b/tp/Texinfo/Document.pm
@@ -46,7 +46,7 @@ my $XS_parser = Texinfo::XSLoader::XS_parser_enabled();
 our %XS_overrides = (
   "Texinfo::Document::remove_document"
     => "Texinfo::DocumentXS::remove_document",
-  "Texinfo::Document::_XS_set_document_global_info",
+  "Texinfo::Document::set_document_global_info",
     => "Texinfo::DocumentXS::set_document_global_info",
   "Texinfo::Document::errors"
     => "Texinfo::DocumentXS::document_errors",
@@ -129,18 +129,11 @@ sub register_tree($$)
   $document->{'tree'} = $tree;
 }
 
-sub _XS_set_document_global_info($$$)
-{
-}
-
 sub set_document_global_info($$$)
 {
   my $document = shift;
   my $key = shift;
   my $value = shift;
-  if ($XS_parser) {
-    _XS_set_document_global_info($document, $key, $value);
-  }
   $document->{'global_info'}->{$key} = $value;
 }
 
@@ -614,6 +607,9 @@ C<COMMAND_LINE_ENCODING>).
 
 =back
 
+If the global information changed, C<global_information> should be called
+to update the hash returned by previous calls before accessing the hash again.
+
 =back
 
 Some command lists are available, such that it is possible to go through
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 1ce403fca0..38cdcb5b68 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -9501,7 +9501,7 @@ if there is an associated external manual name, and a 
I<normalized> key for the
 normalized label, built as specified in the I<HTML Xref> Texinfo documentation
 node.
 
-If you called 
L<Texinfo::Structuring::nodes_tree|Texinfo::Structuring/$nodes_list = 
nodes_tree($document)>,
+If you called 
L<Texinfo::Structuring::construct_nodes_tree|Texinfo::Structuring/$nodes_list = 
construct_nodes_tree($document)>,
 the I<node_directions> hash in the C<@node> element C<extra> associates
 I<up>, I<next> and I<prev> keys to the elements corresponding to the node
 line directions.
diff --git a/tp/Texinfo/XS/main/DocumentXS.xs b/tp/Texinfo/XS/main/DocumentXS.xs
index bbcca0ba95..93c5100cae 100644
--- a/tp/Texinfo/XS/main/DocumentXS.xs
+++ b/tp/Texinfo/XS/main/DocumentXS.xs
@@ -226,7 +226,8 @@ set_document_global_info (SV *document_in, char *key, SV 
*value_sv)
       PREINIT:
         DOCUMENT *document = 0;
       CODE:
-        document = get_sv_document_document (document_in, 0);
+        document = get_sv_document_document (document_in,
+                                             "set_document_global_info");
         if (document)
           {
             document->modified_information |= F_DOCM_global_info;
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 28af86ad40..f88ec90915 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1472,13 +1472,15 @@ build_index_data (const INDEX_LIST *indices_info)
   return hv;
 }
 
-/* Return object to be used as 'info', retrievable with the
-   'global_information' function. */
+/* Return object to be used as global info, retrievable with the
+   'global_information' function.  Reuse the Perl hash associated to
+   the DOCUMENT if it is passed and found */
 static HV *
-build_global_info (const GLOBAL_INFO *global_info_ref,
+build_global_info (DOCUMENT *document,
+                   const GLOBAL_INFO *global_info_ref,
                    const GLOBAL_COMMANDS *global_commands_ref)
 {
-  HV *hv;
+  HV *hv = 0;
   const GLOBAL_INFO global_info = *global_info_ref;
   const GLOBAL_COMMANDS global_commands = *global_commands_ref;
   const ELEMENT *document_language;
@@ -1486,7 +1488,19 @@ build_global_info (const GLOBAL_INFO *global_info_ref,
 
   dTHX;
 
-  hv = newHV ();
+  if (document && document->hv)
+    {
+      const char *key = "global_info";
+      SV **global_info_sv = hv_fetch (document->hv, key, strlen (key), 0);
+      if (global_info_sv && SvOK (*global_info_sv))
+        {
+          hv = (HV *) SvRV (*global_info_sv);
+          SvREFCNT_inc ((SV *) hv);
+        }
+    }
+
+  if (!hv)
+    hv = newHV ();
   if (global_info.input_encoding_name)
     hv_store (hv, "input_encoding_name", strlen ("input_encoding_name"),
               newSVpv (global_info.input_encoding_name, 0), 0);
@@ -1651,7 +1665,7 @@ get_document (size_t document_descriptor)
 
   hv = newHV ();
 
-  hv_info = build_global_info (&document->global_info,
+  hv_info = build_global_info (0, &document->global_info,
                                &document->global_commands);
 
 #define STORE(key, value) hv_store (hv, key, strlen (key), newRV_inc ((SV *) 
value), 0)
@@ -1720,7 +1734,7 @@ fill_document_hv (HV *hv, size_t document_descriptor, int 
no_store)
   if (document->tree)
     hv_tree = build_texinfo_tree (document->tree, 0);
 
-  hv_info = build_global_info (&document->global_info,
+  hv_info = build_global_info (0, &document->global_info,
                                &document->global_commands);
 
   hv_commands_info = build_global_commands (&document->global_commands);
@@ -2071,7 +2085,8 @@ document_global_information (SV *document_in)
     {
       if (document->modified_information & F_DOCM_global_info)
         {
-          HV *result_hv = build_global_info (&document->global_info,
+          HV *result_hv = build_global_info (document,
+                                             &document->global_info,
                                              &document->global_commands);
           result_sv = newRV_inc ((SV *) result_hv);
           hv_store (document->hv, key, strlen (key), result_sv, 0);
diff --git a/tp/t/z_misc/test_document.t b/tp/t/z_misc/test_document.t
index d474182c02..c55648bea9 100644
--- a/tp/t/z_misc/test_document.t
+++ b/tp/t/z_misc/test_document.t
@@ -1,7 +1,7 @@
 use strict;
 
 use lib '.';
-use Texinfo::ModulePath (undef, undef, undef, 'updirs' => 2);
+use Texinfo::ModulePath (undef, undef, undef, 'updirs' => 3);
 
 use Test::More;
 
@@ -33,6 +33,9 @@ is (join('|', sort(keys(%$global_info))),
 
 $document->set_document_global_info('toto', 'la tete a');
 
+# rebuild $global_info
+$document->global_information();
+
 is (join('|', sort(keys(%$global_info))),
     'input_encoding_name|toto',
     'with set global info keys');



reply via email to

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