texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Reference Texinfo::Report in Texinfo::Document ob


From: Gavin D. Smith
Subject: branch master updated: Reference Texinfo::Report in Texinfo::Document object.
Date: Sat, 24 Feb 2024 14:27:22 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 9cccf0a650 Reference Texinfo::Report in Texinfo::Document object.
9cccf0a650 is described below

commit 9cccf0a650522443b4cb23700086b3bcd6f59553
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sat Feb 24 19:26:59 2024 +0000

    Reference Texinfo::Report in Texinfo::Document object.
    
    * tp/Texinfo/Document.pm (register): Take an extra argument, a
    Texinfo::Report reference, and keep it in the 'registrar' value.
    * tp/Texinfo/XS/parsetexi/Parsetexi.pm: (_get_parser_info):
    Save reference to Texinfo::Document object in 'registrar' .
    * tp/Texinfo/ParserNonXS.pm (_parse_texi): Update call to "register".
    * tp/Texinfo/XS/main/build_perl_info.c (rebuild_document):
    Do not clear 'registrar' key on hash.
    
    * tp/Texinfo/Document.pm (errors):
    New function.  Return errors, including any errors in
    the 'errors' array.  Wipe 'errors' array after adding the errors
    to the Texinfo::Report object to allow calling multiple times.
    * tp/Texinfo/XS/parsetexi/Parsetexi.pm: (_get_parser_info):
    Wipe 'errors' array after propagating to Texinfo::Report.
    
    * tp/texi2any.pl (handle_document_errors, handle_errors)
    (_handle_errors): Add new function handle_document_errors to
    get errors from Texinfo::Document.
    * tp/t/test_parser_registrar.t,
    * tp/t/test_utils.pl: Call Texinfo::Document::errors instead
    of Texinfo::Report::errors.
    
    * tp/texi2any.pl, tp/t/test_utils.pl [XS structuring]:
    Eliminate loop copying errors with
    Texinfo::Report::add_formatted_message, as this is dealt with in
    Texinfo::Document::errors instead.
---
 ChangeLog                            | 31 ++++++++++++++++++++++++++++
 tp/Texinfo/Document.pm               | 21 ++++++++++++++++++-
 tp/Texinfo/ParserNonXS.pm            |  3 ++-
 tp/Texinfo/XS/main/build_perl_info.c | 11 ++++++++++
 tp/Texinfo/XS/parsetexi/Parsetexi.pm |  5 ++++-
 tp/t/test_parser_registrar.t         |  2 +-
 tp/t/test_utils.pl                   | 10 +--------
 tp/texi2any.pl                       | 40 ++++++++++++++++++++++++------------
 8 files changed, 97 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0773efa28c..bde3634617 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,34 @@
+2024-02-24  Gavin Smith <gavinsmith0123@gmail.com>
+
+       Reference Texinfo::Report in Texinfo::Document object.
+
+       * tp/Texinfo/Document.pm (register): Take an extra argument, a
+       Texinfo::Report reference, and keep it in the 'registrar' value.
+       * tp/Texinfo/XS/parsetexi/Parsetexi.pm: (_get_parser_info):
+       Save reference to Texinfo::Document object in 'registrar' .
+       * tp/Texinfo/ParserNonXS.pm (_parse_texi): Update call to "register".
+       * tp/Texinfo/XS/main/build_perl_info.c (rebuild_document):
+       Do not clear 'registrar' key on hash.
+
+       * tp/Texinfo/Document.pm (errors):
+       New function.  Return errors, including any errors in
+       the 'errors' array.  Wipe 'errors' array after adding the errors
+       to the Texinfo::Report object to allow calling multiple times.
+       * tp/Texinfo/XS/parsetexi/Parsetexi.pm: (_get_parser_info):
+       Wipe 'errors' array after propagating to Texinfo::Report.
+
+       * tp/texi2any.pl (handle_document_errors, handle_errors)
+       (_handle_errors): Add new function handle_document_errors to
+       get errors from Texinfo::Document.
+       * tp/t/test_parser_registrar.t,
+       * tp/t/test_utils.pl: Call Texinfo::Document::errors instead
+       of Texinfo::Report::errors.
+
+       * tp/texi2any.pl, tp/t/test_utils.pl [XS structuring]:
+       Eliminate loop copying errors with
+       Texinfo::Report::add_formatted_message, as this is dealt with in
+       Texinfo::Document::errors instead.
+
 2024-02-24  Gavin Smith <gavinsmith0123@gmail.com>
 
        * tp/Texinfo/XSLoader.pm (init): Remove $warning_message and
diff --git a/tp/Texinfo/Document.pm b/tp/Texinfo/Document.pm
index 62d729d369..fe2e7ce91a 100644
--- a/tp/Texinfo/Document.pm
+++ b/tp/Texinfo/Document.pm
@@ -93,6 +93,7 @@ sub register
   my $global_commands_information = shift;
   my $identifier_target = shift;
   my $labels_list = shift;
+  my $registrar = shift;
 
   my $document = {
     'tree' => $tree,
@@ -103,6 +104,7 @@ sub register
     'global_info' => $global_information,
     'identifiers_target' => $identifier_target,
     'labels_list' => $labels_list,
+    'registrar' => $registrar,
   };
 
   bless $document;
@@ -433,6 +435,23 @@ sub clear_document_errors($)
 {
 }
 
+sub errors($)
+{
+  my $document = shift;
+
+  my $registrar = $document->{'registrar'};
+  return if !defined($registrar);
+
+  foreach my $error (@{$document->{'errors'}}) {
+    $registrar->add_formatted_message($error);
+  }
+  @{$document->{'errors'}} = ();
+  Texinfo::Document::clear_document_errors(
+                                      $document->document_descriptor());
+
+  return $registrar->errors();
+}
+
 1;
 __END__
 =head1 NAME
@@ -739,7 +758,7 @@ parsers codes.
 
 =over
 
-=item $document = Texinfo::Document::register($tree, $global_information, 
$indices_information, $floats_information, $internal_references_information, 
$global_commands_information, $identifier_target, $labels_list)
+=item $document = Texinfo::Document::register($tree, $global_information, 
$indices_information, $floats_information, $internal_references_information, 
$global_commands_information, $identifier_target, $labels_list, $registrar)
 
 Setup a document. There is no reason to call this method out of parsers, as
 it is already done by the Texinfo parsers.  The arguments are gathered
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index fb0dcc8ca6..57ee86cb3b 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -7519,7 +7519,8 @@ sub _parse_texi($$$)
   my $document = Texinfo::Document::register($root,
      $self->{'global_info'}, $self->{'index_names'}, $self->{'floats'},
      $self->{'internal_references'}, $self->{'commands_info'},
-     $self->{'identifiers_target'}, $self->{'labels_list'});
+     $self->{'identifiers_target'}, $self->{'labels_list'},
+     $self->{'registrar'});
 
   return $document;
 }
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 5a81179dfa..681bd43955 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1329,6 +1329,7 @@ rebuild_document (SV *document_in, int no_store)
   HV *hv;
   SV **document_descriptor_sv;
   char *descriptor_key = "document_descriptor";
+  char *registrar_key = "registrar";
 
   dTHX;
 
@@ -1337,11 +1338,21 @@ rebuild_document (SV *document_in, int no_store)
   document_descriptor_sv = hv_fetch (hv, descriptor_key,
                                      strlen (descriptor_key), 0);
 
+  SV **registrar_svp, *registrar_sv = 0;
+  registrar_svp = hv_fetch (hv, registrar_key, strlen (registrar_key), 0);
+  if (registrar_svp)
+    {
+      registrar_sv = *registrar_svp;
+      SvREFCNT_inc(registrar_sv); /* prevent destruction at hv_clear below */
+    }
+
   if (document_descriptor_sv)
     {
       int document_descriptor = SvIV (*document_descriptor_sv);
       hv_clear (hv);
       fill_document_hv (hv, document_descriptor, no_store);
+      if (registrar_sv)
+        hv_store (hv, registrar_key, strlen (registrar_key), registrar_sv, 0);
     }
   else
     {
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm 
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index af00bf301c..3640d14e6b 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -217,9 +217,12 @@ sub _get_parser_info($$;$$) {
   foreach my $error (@{$document->{'errors'}}) {
     $registrar->add_formatted_message($error);
   }
-
+  @{$document->{'errors'}} = ();
   clear_document_errors($document_descriptor);
 
+  # Reference the same Texinfo::Report object
+  $document->{'registrar'} = $registrar;
+
   # additional info relevant in perl only.
   my $perl_encoding
     = Texinfo::Common::get_perl_encoding($document->{'commands_info'},
diff --git a/tp/t/test_parser_registrar.t b/tp/t/test_parser_registrar.t
index f605c8cc98..f43867e8e0 100644
--- a/tp/t/test_parser_registrar.t
+++ b/tp/t/test_parser_registrar.t
@@ -30,7 +30,7 @@ my $document = $parser->parse_texi_piece("\@end format\n");
 my $parser_registrar = $parser->registered_errors();
 ok ($parser_registrar eq $registrar, 'reused registrar');
 
-my ($error_warnings_list, $error_count) = $parser_registrar->errors();
+my ($error_warnings_list, $error_count) = $document->errors();
 
 ok ($error_count == 2, 'error count');
 
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index cc55aaa0fc..2d3cd6bfb4 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -1146,15 +1146,7 @@ sub test($$)
   # should not actually be useful, as the same element should be reused.
   $tree = $document->tree();
 
-  if ($XS_structuring) {
-    foreach my $error (@{$document->{'errors'}}) {
-      $registrar->add_formatted_message($error);
-    }
-    Texinfo::Document::clear_document_errors(
-                                           $document->document_descriptor());
-  }
-
-  my ($errors, $error_nrs) = $registrar->errors();
+  my ($errors, $error_nrs) = $document->errors();
   my $indices_information = $document->indices_information();
   # FIXME maybe it would be good to compare $merged_index_entries?
   my $merged_index_entries = $document->merged_indices();
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index a2d9ea3803..13682e0fca 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1229,6 +1229,22 @@ sub _exit($$)
      or $error_count > get_conf('ERROR_LIMIT')));
 }
 
+sub handle_document_errors($$$)
+{
+  my $document = shift;
+  my $error_count = shift;
+  my $opened_files = shift;
+
+  die if ref($document) ne 'Texinfo::Document';
+
+  my ($errors, $new_error_count) = $document->errors();
+  $error_count += $new_error_count if ($new_error_count);
+  _handle_errors($errors);
+
+  _exit($error_count, $opened_files);
+  return $error_count;
+}
+
 sub handle_errors($$$)
 {
   my $self = shift;
@@ -1237,6 +1253,15 @@ sub handle_errors($$$)
 
   my ($errors, $new_error_count) = $self->errors();
   $error_count += $new_error_count if ($new_error_count);
+  _handle_errors($errors);
+
+  _exit($error_count, $opened_files);
+  return $error_count;
+}
+
+sub _handle_errors($)
+{
+  my $errors = shift;
   foreach my $error_message (@$errors) {
     if ($error_message->{'type'} eq 'error' or !get_conf('NO_WARN')) {
       my $s = '';
@@ -1260,9 +1285,6 @@ sub handle_errors($$$)
       warn $s;
     }
   }
-
-  _exit($error_count, $opened_files);
-  return $error_count;
 }
 
 # Avoid loading these modules until down here to speed up the case
@@ -1682,16 +1704,8 @@ while(@input_files) {
   }
 
   Texinfo::Document::rebuild_document($document);
-
-  if ($XS_structuring) {
-    foreach my $error (@{$document->{'errors'}}) {
-      $registrar->add_formatted_message($error);
-    }
-    Texinfo::Document::clear_document_errors(
-                                        $document->document_descriptor());
-  }
-
-  $error_count = handle_errors($registrar, $error_count, \@opened_files);
+  $error_count = handle_document_errors($document,
+                                        $error_count, \@opened_files);
 
   if ($format eq 'structure') {
     goto NEXT;



reply via email to

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