[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Tue, 28 May 2024 06:54:45 -0400 (EDT) |
branch: master
commit d70a8c9ecc56aed69d3e016dd2e2dcc48be311e4
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue May 28 12:54:31 2024 +0200
Fix error message of XS parser when the input file cannot be opened
* tp/Texinfo/XS/parsetexi/api.c (initialize_parsing, parse_file)
(parse_text, parse_string, parse_piece): have initialize_parsing
return the document_descriptor and get it from there in parse_*.
* tp/Texinfo/XS/parsetexi/Parsetexi.pm (parse_texi_file),
tp/Texinfo/XS/parsetexi/Parsetexi.xs (parse_file),
tp/Texinfo/XS/parsetexi/api.c (parse_file): add a status
argument to parse_file in api.c, set it to non-zero if the parsing
could not proceed. Set the open error message in api.c parse_file,
where the error can be converted to a string with strerror. Return a
document_descriptor even if there was an error. In Parsetexi.xs
parse_file, check the status, and if there was an error, get the
parsing error and destroy the document. Remove the error setting
in Parsetexi.pm parse_texi_file, where $! is unlikely to be correct.
* tp/Texinfo/ParserNonXS.pm (parse_texi_file): rename $input_file_name
as $decoded_input_file_path.
* tp/Texinfo/ParserNonXS.pm (parse_texi_file): do not pass the
PROGRAM configuration value to document_error, it is not in the parser
customization variables, and we do not want to add more.
---
ChangeLog | 26 ++++++++++++++++++
tp/Texinfo/ParserNonXS.pm | 7 ++---
tp/Texinfo/XS/parsetexi/Parsetexi.pm | 8 ------
tp/Texinfo/XS/parsetexi/Parsetexi.xs | 16 ++++++++++-
tp/Texinfo/XS/parsetexi/api.c | 53 +++++++++++++++++++-----------------
tp/Texinfo/XS/parsetexi/api.h | 2 +-
6 files changed, 73 insertions(+), 39 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fd711f0eb9..be241b8deb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2024-05-28 Patrice Dumas <pertusus@free.fr>
+
+ Fix error message of XS parser when the input file cannot be opened
+
+ * tp/Texinfo/XS/parsetexi/api.c (initialize_parsing, parse_file)
+ (parse_text, parse_string, parse_piece): have initialize_parsing
+ return the document_descriptor and get it from there in parse_*.
+
+ * tp/Texinfo/XS/parsetexi/Parsetexi.pm (parse_texi_file),
+ tp/Texinfo/XS/parsetexi/Parsetexi.xs (parse_file),
+ tp/Texinfo/XS/parsetexi/api.c (parse_file): add a status
+ argument to parse_file in api.c, set it to non-zero if the parsing
+ could not proceed. Set the open error message in api.c parse_file,
+ where the error can be converted to a string with strerror. Return a
+ document_descriptor even if there was an error. In Parsetexi.xs
+ parse_file, check the status, and if there was an error, get the
+ parsing error and destroy the document. Remove the error setting
+ in Parsetexi.pm parse_texi_file, where $! is unlikely to be correct.
+
+ * tp/Texinfo/ParserNonXS.pm (parse_texi_file): rename $input_file_name
+ as $decoded_input_file_path.
+
+ * tp/Texinfo/ParserNonXS.pm (parse_texi_file): do not pass the
+ PROGRAM configuration value to document_error, it is not in the parser
+ customization variables, and we do not want to add more.
+
2024-05-28 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/parsetexi/Parsetexi.pm (parse_texi_file): remove the
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index bc3baf2387..3ee28a0d74 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -931,15 +931,14 @@ sub parse_texi_file($$)
my ($status, $file_name, $directories, $error_message)
= _input_push_file($self, $input_file_path);
if (!$status) {
- my $input_file_name = $input_file_path;
+ my $decoded_input_file_path = $input_file_path;
my $encoding = $self->{'conf'}->{'COMMAND_LINE_ENCODING'};
if (defined($encoding)) {
- $input_file_name = decode($encoding, $input_file_path);
+ $decoded_input_file_path = decode($encoding, $input_file_path);
}
$self->{'registrar'}->document_error(
sprintf(__("could not open %s: %s"),
- $input_file_name, $error_message),
- $self->{'conf'}->{'PROGRAM'});
+ $decoded_input_file_path, $error_message));
return undef;
}
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index a6a5809a79..4164a6043f 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -217,14 +217,6 @@ sub parse_texi_file ($$)
# it is not useful for the XS parser.
my $document_descriptor = parse_file($self, $input_file_path);
if (!$document_descriptor) {
- my $parser_registrar = $self->{'registrar'};
- my $decoded_input_file_path = $input_file_path;
- my $encoding = $self->{'conf'}->{'COMMAND_LINE_ENCODING'};
- if (defined($encoding)) {
- $decoded_input_file_path = decode($encoding, $input_file_path);
- }
- $parser_registrar->document_error($self,
- sprintf(__("could not open %s: %s"), $decoded_input_file_path, $!));
return undef;
}
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index f3a331598a..62b086162c 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -34,6 +34,7 @@
#include "parser_conf.h"
#include "build_perl_info.h"
#include "get_perl_info.h"
+#include "document.h"
/* See the NOTE in build_perl_info.c on use of functions related to
memory allocation */
@@ -76,9 +77,22 @@ register_parser_conf (SV *parser)
int
parse_file (SV *parser, input_file_path)
char *input_file_path = (char *)SvPVbyte_nolen ($arg);
+ PREINIT:
+ int status;
+ int document_descriptor = 0;
CODE:
apply_sv_parser_conf (parser);
- RETVAL = parse_file (input_file_path);
+ document_descriptor = parse_file (input_file_path, &status);
+ if (status)
+ /* if the input file could not be opened */
+ {
+ pass_document_parser_errors_to_registrar (document_descriptor,
+ parser);
+ remove_document_descriptor (document_descriptor);
+ RETVAL = 0;
+ }
+ else
+ RETVAL = document_descriptor;
OUTPUT:
RETVAL
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index 50c0f55ff2..257e2193b4 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -49,7 +49,7 @@
#include "indices.h"
#include "api.h"
-static void
+static int
initialize_parsing (void)
{
parsed_document = new_document ();
@@ -101,6 +101,8 @@ initialize_parsing (void)
reset_parser_counters ();
reset_obstacks ();
+
+ return parsed_document->descriptor;
}
void
@@ -153,24 +155,30 @@ parse_file_path (const char *input_file_path, char
**result)
/* Determine directory path based on file name.
Return a DOCUMENT_DESCRIPTOR that can be used to retrieve the
- tree and document obtained by parsing FILENAME.
+ tree and document obtained by parsing INPUT_FILE_PATH.
+ STATUS is set to non zero if parsing could not proceed.
+ It is always the responsibility of the caller to get the error
+ messages and destroy the document.
+
Used for parse_texi_file. */
int
-parse_file (const char *input_file_path)
+parse_file (const char *input_file_path, int *status)
{
- int document_descriptor;
+ int document_descriptor = initialize_parsing ();
GLOBAL_INFO *global_info;
char *input_file_name_and_directory[2];
+ int input_error;
- int status;
-
- initialize_parsing ();
-
- status = input_push_file (input_file_path);
- if (status)
+ input_error = input_push_file (input_file_path);
+ if (input_error)
{
- remove_document_descriptor (parsed_document->descriptor);
- return 0;
+ char *decoded_file_path = convert_to_utf8 (strdup (input_file_path));
+ message_list_document_error (&parsed_document->parser_error_messages, 0,
+ 0, "could not open %s: %s",
+ decoded_file_path, strerror (input_error));
+ free (decoded_file_path);
+ *status = 1;
+ return document_descriptor;
}
parse_file_path (input_file_path, input_file_name_and_directory);
@@ -182,8 +190,9 @@ parse_file (const char *input_file_path)
global_info->input_file_name = input_file_name_and_directory[0];
global_info->input_directory = input_file_name_and_directory[1];
- document_descriptor = parse_texi_document ();
+ parse_texi_document ();
+ *status = 0;
return document_descriptor;
}
@@ -191,12 +200,10 @@ parse_file (const char *input_file_path)
int
parse_text (const char *string, int line_nr)
{
- int document_descriptor;
-
- initialize_parsing ();
+ int document_descriptor = initialize_parsing ();
input_push_text (strdup (string), line_nr, 0, 0);
- document_descriptor = parse_texi_document ();
+ parse_texi_document ();
return document_descriptor;
}
@@ -207,14 +214,12 @@ int
parse_string (const char *string, int line_nr)
{
ELEMENT *root_elt;
- int document_descriptor;
-
- initialize_parsing ();
+ int document_descriptor = initialize_parsing ();
root_elt = new_element (ET_root_line);
input_push_text (strdup (string), line_nr, 0, 0);
- document_descriptor = parse_texi (root_elt, root_elt);
+ parse_texi (root_elt, root_elt);
return document_descriptor;
}
@@ -222,16 +227,14 @@ parse_string (const char *string, int line_nr)
int
parse_piece (const char *string, int line_nr)
{
- int document_descriptor;
+ int document_descriptor = initialize_parsing ();
ELEMENT *before_node_section, *document_root;
- initialize_parsing ();
-
before_node_section = setup_document_root_and_before_node_section ();
document_root = before_node_section->parent;
input_push_text (strdup (string), line_nr, 0, 0);
- document_descriptor = parse_texi (document_root, before_node_section);
+ parse_texi (document_root, before_node_section);
return document_descriptor;
}
diff --git a/tp/Texinfo/XS/parsetexi/api.h b/tp/Texinfo/XS/parsetexi/api.h
index 3af555d9ae..7d1e834512 100644
--- a/tp/Texinfo/XS/parsetexi/api.h
+++ b/tp/Texinfo/XS/parsetexi/api.h
@@ -4,7 +4,7 @@
#include "tree_types.h"
-int parse_file (const char *input_file_path);
+int parse_file (const char *input_file_path, int *status);
int parse_piece (const char *, int line_nr);
int parse_string (const char *, int line_nr);
int parse_text (const char *, int line_nr);