texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Wed, 6 Mar 2024 17:07:56 -0500 (EST)

branch: master
commit 5deb72cfaa79559d80bd9f2cc29795b9fd163921
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Mar 6 23:07:48 2024 +0100

    Get errors from XS independently of document build/rebuild
    
    * tp/Texinfo/XS/main/build_perl_info.c (pass_document_parser_errors),
    tp/Texinfo/XS/parsetexi/Parsetexi.pm (_get_parser_info),
    tp/Texinfo/XS/parsetexi/Parsetexi.xs (pass_document_parser_errors):
    pass XS parser errors through the pass_document_parser_errors XS
    interface and remove them from XS data.
    
    * tp/Texinfo/Document.pm (%XS_overrides, _XS_pass_document_errors)
    (errors), tp/Texinfo/XS/main/DocumentXS.xs (pass_document_errors),
    tp/Texinfo/XS/main/build_perl_info.c (pass_document_errors):
    pass directly XS errors to Perl through pass_document_errors
    independentely of document rebuild, and remove errors from XS data.
    
    * tp/Texinfo/XS/main/build_perl_info.c (get_document)
    (fill_document_hv): do not build parser nor document errors lists.
    
    * tp/Texinfo/Document.pm (%XS_overrides): remove XS interface for
    clear_document_errors.
    
    * tp/Texinfo/XS/parsetexi/Parsetexi.xs: remove clear_document_errors
    and clear_document_parser_errors XS interfaces.
    
    * tp/Texinfo/Document.pm (register): remove 'parser_registrar' field
    and $parser_registrar register function argument.  Update caller.
    
    * tp/t/test_utils.pl (test): do not call indices_sort_strings early
    anymore, and do not call $document->errors() right after rebuilding
    document, now that there are no link between retrieving errors and
    building document to Perl.
---
 ChangeLog                            | 33 +++++++++++++++++
 tp/Texinfo/Document.pm               | 61 ++++++++-----------------------
 tp/Texinfo/ParserNonXS.pm            |  3 +-
 tp/Texinfo/XS/main/DocumentXS.xs     | 16 ++++++++
 tp/Texinfo/XS/main/build_perl_info.c | 71 +++++++++++++++++++++++-------------
 tp/Texinfo/XS/main/build_perl_info.h |  3 ++
 tp/Texinfo/XS/parsetexi/Parsetexi.pm | 15 ++++----
 tp/Texinfo/XS/parsetexi/Parsetexi.xs |  7 +---
 tp/t/test_utils.pl                   | 11 ++----
 9 files changed, 126 insertions(+), 94 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bb325b8f6e..4d0457ec8c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2024-03-06  Patrice Dumas  <pertusus@free.fr>
+
+       Get errors from XS independently of document build/rebuild
+
+       * tp/Texinfo/XS/main/build_perl_info.c (pass_document_parser_errors),
+       tp/Texinfo/XS/parsetexi/Parsetexi.pm (_get_parser_info),
+       tp/Texinfo/XS/parsetexi/Parsetexi.xs (pass_document_parser_errors):
+       pass XS parser errors through the pass_document_parser_errors XS
+       interface and remove them from XS data.
+
+       * tp/Texinfo/Document.pm (%XS_overrides, _XS_pass_document_errors)
+       (errors), tp/Texinfo/XS/main/DocumentXS.xs (pass_document_errors),
+       tp/Texinfo/XS/main/build_perl_info.c (pass_document_errors):
+       pass directly XS errors to Perl through pass_document_errors
+       independentely of document rebuild, and remove errors from XS data.
+
+       * tp/Texinfo/XS/main/build_perl_info.c (get_document)
+       (fill_document_hv): do not build parser nor document errors lists.
+
+       * tp/Texinfo/Document.pm (%XS_overrides): remove XS interface for
+       clear_document_errors.
+
+       * tp/Texinfo/XS/parsetexi/Parsetexi.xs: remove clear_document_errors
+       and clear_document_parser_errors XS interfaces.
+
+       * tp/Texinfo/Document.pm (register): remove 'parser_registrar' field
+       and $parser_registrar register function argument.  Update caller.
+
+       * tp/t/test_utils.pl (test): do not call indices_sort_strings early
+       anymore, and do not call $document->errors() right after rebuilding
+       document, now that there are no link between retrieving errors and
+       building document to Perl.
+
 2024-03-05  Patrice Dumas  <pertusus@free.fr>
 
        * doc/texinfo.texi (Command List): @bullet is often associated with
diff --git a/tp/Texinfo/Document.pm b/tp/Texinfo/Document.pm
index 3949047b8c..dc0e4e3a51 100644
--- a/tp/Texinfo/Document.pm
+++ b/tp/Texinfo/Document.pm
@@ -50,8 +50,8 @@ my $XS_structuring = ($XS_parser
 our %XS_overrides = (
   "Texinfo::Document::remove_document"
     => "Texinfo::DocumentXS::remove_document",
-  "Texinfo::Document::clear_document_errors"
-    => "Texinfo::DocumentXS::clear_document_errors",
+  "Texinfo::Document::_XS_pass_document_errors"
+    => "Texinfo::DocumentXS::pass_document_errors",
   "Texinfo::Document::_XS_set_document_global_info",
     => "Texinfo::DocumentXS::set_document_global_info",
 );
@@ -95,7 +95,6 @@ sub register
   my $global_commands_information = shift;
   my $identifier_target = shift;
   my $labels_list = shift;
-  my $parser_registrar = shift;
 
   my $document = {
     'tree' => $tree,
@@ -106,8 +105,6 @@ sub register
     'global_info' => $global_information,
     'identifiers_target' => $identifier_target,
     'labels_list' => $labels_list,
-    # Parser errors registrar
-    'parser_registrar' => $parser_registrar,
     # New error registrar for the document
     'registrar' => Texinfo::Report::new(),
   };
@@ -436,17 +433,14 @@ sub rebuild_tree($;$)
   return $tree;
 }
 
-# this method does nothing, but the XS override clears the document errors
-sub clear_document_errors($)
+# this method does nothing, but the XS override pass the document errors
+sub _XS_pass_document_errors($)
 {
 }
 
-# In general, this method should be called after calling rebuild_document
-# on the document, such that the XS code builds the 'errors' list before
-# this method is called.  Also note that if XS code was not used, all
-# the errors should already be registered in the document registrar.
-# NOTE similar code is used in the perl code associated to the XS parser to
-# get the errors from parser_errors.
+
+# Note that if XS code was not used, all the errors should already be
+# registered in the document registrar.
 sub errors($)
 {
   my $document = shift;
@@ -454,12 +448,13 @@ sub errors($)
   my $registrar = $document->{'registrar'};
   return if !defined($registrar);
 
-  foreach my $error (@{$document->{'errors'}}) {
-    $registrar->add_formatted_message($error);
+  # get errors from XS data
+  my $XS_document_errors = _XS_pass_document_errors($document);
+  if ($XS_document_errors) {
+    foreach my $error (@{$XS_document_errors}) {
+      $registrar->add_formatted_message($error);
+    }
   }
-  @{$document->{'errors'}} = ();
-  Texinfo::Document::clear_document_errors(
-                                      $document->document_descriptor());
 
   return $registrar->errors();
 }
@@ -791,10 +786,6 @@ one for each error, warning or error line continuation.  
The format of
 these hash references is described
 in L<C<Texinfo::Report::errors>|Texinfo::Report/($error_warnings_list, 
$error_count) = errors($registrar)>.
 
-Note that, in general, C<error> should
-be called after L<C<rebuild_document>|/$rebuilt_document = 
rebuild_document($document, $no_store)>,
-such that errors registered in C are passed to Perl.
-
 =back
 
 
@@ -892,35 +883,13 @@ tree I<$tree> if C<rebuild_tree> is called.
 
 If the optional I<$no_store> argument is set, remove the C data.
 
-This method also sets the errors list in the Perl I<$rebuilt_document> based on
-errors and warnings associated to I<$document> stored in C, and should
-therefore be called before calling
-L<C<errors>|/($error warnings list, $error count) = errors($document)>.
-
-B<the document errors should be in C<< $document->{'errors'} >>, but this is 
not
-documented anywhere, and maybe do not need to be documented as
-L<C<errors>|/($error warnings list, $error count) = errors($document)> can be 
used to get the errors.>
-
 =back
 
-Some methods allow to release the memory or remove error messages held
-by C data associated to a Texinfo parsed document:
+Some methods allow to release the memory held by C data associated
+to a Texinfo parsed document:
 
 =over
 
-=item clear_document_errors($document)
-X<C<clear_document_errors>>
-
-Remove the document errors and warnings held in C data.
-
-Note that L<C<errors>|/($error warnings list, $error count) = 
errors($document)>
-already calls C<clear_document_errors>, so calling this function directly
-is usually not needed.
-
-The method can be called on pure Perl modules and does nothing in that case
-as the errors and warnings are already in the L<Texinfo::Report> object
-associated to a document.
-
 =item remove_document($document)
 X<C<remove_document>>
 
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 0f09fd44d4..8eb07e8f4f 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -7537,8 +7537,7 @@ 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->{'registrar'});
+     $self->{'identifiers_target'}, $self->{'labels_list'});
 
   return $document;
 }
diff --git a/tp/Texinfo/XS/main/DocumentXS.xs b/tp/Texinfo/XS/main/DocumentXS.xs
index 28c7694b58..2d62d4afc1 100644
--- a/tp/Texinfo/XS/main/DocumentXS.xs
+++ b/tp/Texinfo/XS/main/DocumentXS.xs
@@ -102,6 +102,22 @@ remove_document (SV *document_in)
         if (document)
           remove_document_descriptor (document->descriptor);
 
+SV *
+pass_document_errors (SV *document_in)
+    PREINIT:
+        HV *document_hv;
+        const char *key = "document_descriptor";
+        SV** document_descriptor_sv;
+     CODE:
+        document_hv = (HV *) SvRV (document_in);
+        document_descriptor_sv = hv_fetch (document_hv, key, strlen (key), 0);
+        if (document_descriptor_sv && SvOK (*document_descriptor_sv))
+          RETVAL = pass_document_errors (SvIV (*document_descriptor_sv));
+        else
+          RETVAL = newSV (0);
+    OUTPUT:
+        RETVAL
+
 void
 clear_document_errors (int document_descriptor)
 
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 1c5f039a06..2e270b2998 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1203,6 +1203,51 @@ build_errors (ERROR_MESSAGE* error_list, size_t 
error_number)
   return av;
 }
 
+/* build perl errors list and clear XS document parser errors */
+SV *
+pass_document_parser_errors (size_t document_descriptor)
+{
+  DOCUMENT *document;
+  AV *av_parser_errors_list;
+
+  dTHX;
+
+  document = retrieve_document (document_descriptor);
+
+  if (!document)
+    return newSV (0);
+
+  av_parser_errors_list
+    = build_errors (document->parser_error_messages->list,
+                    document->parser_error_messages->number);
+
+  clear_document_parser_errors (document_descriptor);
+
+  return newRV_inc ((SV *) av_parser_errors_list);
+}
+
+/* build perl errors list and clear XS document errors */
+SV *
+pass_document_errors (size_t document_descriptor)
+{
+  AV *av_document_errors_list;
+  DOCUMENT *document = 0;
+
+  dTHX;
+
+  document = retrieve_document (document_descriptor);
+
+  if (!document)
+    return newSV (0);
+
+  av_document_errors_list = build_errors (document->error_messages->list,
+                                          document->error_messages->number);
+
+  clear_document_errors (document->descriptor);
+
+  return newRV_inc ((SV *) av_document_errors_list);
+}
+
 
 
 /* build a minimal document, without tree/global commands/indices, only
@@ -1217,8 +1262,6 @@ get_document (size_t document_descriptor)
   SV *sv;
   HV *hv_tree;
   HV *hv_info;
-  AV *av_errors_list;
-  AV *av_parser_errors_list;
 
   dTHX;
 
@@ -1229,19 +1272,9 @@ get_document (size_t document_descriptor)
 
   hv_info = build_global_info (document->global_info, 
document->global_commands);
 
-  av_errors_list = build_errors (document->error_messages->list,
-                                 document->error_messages->number);
-
-  av_parser_errors_list
-    = build_errors (document->parser_error_messages->list,
-                    document->parser_error_messages->number);
-
-
 #define STORE(key, value) hv_store (hv, key, strlen (key), newRV_inc ((SV *) 
value), 0)
   STORE("tree", hv_tree);
   STORE("global_info", hv_info);
-  STORE("errors", av_errors_list);
-  STORE("parser_errors", av_parser_errors_list);
 #undef STORE
 
   hv_store (hv, "document_descriptor", strlen ("document_descriptor"),
@@ -1270,8 +1303,6 @@ fill_document_hv (HV *hv, size_t document_descriptor, int 
no_store)
   AV *av_internal_xref;
   HV *hv_identifiers_target;
   AV *av_labels_list;
-  AV *av_errors_list;
-  AV *av_parser_errors_list;
   AV *av_nodes_list = 0;
   AV *av_sections_list = 0;
 
@@ -1307,13 +1338,6 @@ fill_document_hv (HV *hv, size_t document_descriptor, 
int no_store)
   av_labels_list = build_target_elements_list (document->labels_list->list,
                                                document->labels_list->number);
 
-  av_errors_list = build_errors (document->error_messages->list,
-                                 document->error_messages->number);
-  av_parser_errors_list
-    = build_errors (document->parser_error_messages->list,
-                    document->parser_error_messages->number);
-
-
   if (document->nodes_list)
     av_nodes_list = build_elements_list (document->nodes_list);
 
@@ -1336,8 +1360,6 @@ fill_document_hv (HV *hv, size_t document_descriptor, int 
no_store)
   STORE("global_info", hv_info);
   STORE("identifiers_target", hv_identifiers_target);
   STORE("labels_list", av_labels_list);
-  STORE("errors", av_errors_list);
-  STORE("parser_errors", av_parser_errors_list);
 
   if (av_nodes_list)
     STORE("nodes_list", av_nodes_list);
@@ -1401,9 +1423,6 @@ rebuild_document (SV *document_in, int no_store)
   document_descriptor_sv = hv_fetch (hv, descriptor_key,
                                      strlen (descriptor_key), 0);
 
-  /* Note that we could also keep the parser_registrar, however at that
-     point it should not be useful anymore, so it is better to let it
-     be cleared */
   SV **registrar_svp, *registrar_sv = 0;
   registrar_svp = hv_fetch (hv, registrar_key, strlen (registrar_key), 0);
   if (registrar_svp)
diff --git a/tp/Texinfo/XS/main/build_perl_info.h 
b/tp/Texinfo/XS/main/build_perl_info.h
index 3901ef7bd1..6d654037ec 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -47,6 +47,9 @@ HV *build_global_info (GLOBAL_INFO *global_info_ref,
                        GLOBAL_COMMANDS *global_commands_ref);
 HV *build_global_commands (GLOBAL_COMMANDS *global_commands_ref);
 
+SV *pass_document_parser_errors (size_t document_descriptor);
+SV *pass_document_errors (size_t document_descriptor);
+
 SV *build_output_units_list (size_t output_units_descriptor);
 void rebuild_output_units_list (SV *output_units_sv,
                                 size_t output_units_descriptor);
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm 
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index 4ce69073e1..4ae7e191b4 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -203,6 +203,14 @@ sub _get_parser_info($$;$$) {
   my ($parser_registrar, $configuration_information)
      = _get_parser_error_registrar($self);
 
+  # get hold of errors before calling build_document, as if $no_store is set
+  # they will be destroyed.
+  my $parser_errors = pass_document_parser_errors($document_descriptor);
+  # Copy the errors into the parser Texinfo::Report error list.
+  foreach my $error (@$parser_errors) {
+    $parser_registrar->add_formatted_message($error);
+  }
+
   my $document;
   if ($no_build) {
     $document = get_document ($document_descriptor);
@@ -213,13 +221,6 @@ sub _get_parser_info($$;$$) {
   #Texinfo::Translations::complete_indices ($self,
   #                                 $document->indices_information());
 
-  # Copy the errors into the error list in parser Texinfo::Report.
-  foreach my $error (@{$document->{'parser_errors'}}) {
-    $parser_registrar->add_formatted_message($error);
-  }
-  @{$document->{'parser_errors'}} = ();
-  clear_document_parser_errors($document_descriptor);
-
   # additional info relevant in perl only.
   my $perl_encoding
     = Texinfo::Common::get_perl_encoding($document->{'commands_info'},
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs 
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index ae8d6f4dd3..c2f3864be6 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -102,11 +102,8 @@ build_document (int document_descriptor, ...)
 SV *
 get_document (int document_descriptor)
 
-void
-clear_document_errors (int document_descriptor)
-
-void
-clear_document_parser_errors (int document_descriptor)
+SV *
+pass_document_parser_errors (int document_descriptor)
 
 void
 parser_store_value (name, value)
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 3b4ba121bf..ad69ab2651 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -1132,20 +1132,12 @@ sub test($$)
     }
   }
 
-  # Here the sort strings are generated, both in Perl and XS.
-  # If $XS_structuring is set, the Perl structure cannot be
-  # built yet from XS as the document index information have not
-  # been rebuilt yet, but it is not needed at that point.
-  Texinfo::Document::indices_sort_strings($document, $main_configuration);
-
   # could be in a if !$XS_structuring, but the function should not be
   # overriden already in that case
   Texinfo::Document::rebuild_document($document);
   # should not actually be useful, as the same element should be reused.
   $tree = $document->tree();
 
-  my ($document_errors, $document_error_nrs) = $document->errors();
-  push @$errors, @$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();
@@ -1194,6 +1186,9 @@ sub test($$)
     }
   }
 
+  my ($document_errors, $document_error_nrs) = $document->errors();
+  push @$errors, @$document_errors;
+
   # use the parser expanded formats to be similar to the main program,
   # and also to avoid having @inline* and raw output format @-commands
   # with elided contents especially parsed because they are ignored



reply via email to

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