[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/XS/main/build_perl_info.c (new_texin
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/XS/main/build_perl_info.c (new_texinfo_report): add code doing the same as calling Texinfo::Report::new() in XS. |
Date: |
Sun, 20 Oct 2024 07:27:08 -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 1248f0d5a1 * tp/Texinfo/XS/main/build_perl_info.c
(new_texinfo_report): add code doing the same as calling Texinfo::Report::new()
in XS.
1248f0d5a1 is described below
commit 1248f0d5a13a833dd4fbe9b47c9bed9add02ae13
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Oct 20 13:27:01 2024 +0200
* tp/Texinfo/XS/main/build_perl_info.c (new_texinfo_report): add code
doing the same as calling Texinfo::Report::new() in XS.
* tp/Texinfo/XS/main/build_perl_info.c (get_document, build_document):
add a registrar key by calling new_texinfo_report.
* tp/Texinfo/XS/main/build_perl_info.c (get_or_build_document),
tp/Texinfo/XS/parsetexi/Parsetexi.pm (parse_texi_file)
(parse_texi_piece, parse_texi_text, parse_texi_line),
tp/Texinfo/XS/parsetexi/Parsetexi.xs (parse_file, parse_piece)
(parse_string, parse_text): build the document directly in parse_* by
calling the new function get_or_build_document or directly
get_document. Remove _get_parser_info.
---
ChangeLog | 16 +++++++++++
tp/Texinfo/XS/main/build_perl_info.c | 56 +++++++++++++++++++++++++++++++++++-
tp/Texinfo/XS/main/build_perl_info.h | 2 ++
tp/Texinfo/XS/parsetexi/Parsetexi.pm | 44 +++-------------------------
tp/Texinfo/XS/parsetexi/Parsetexi.xs | 56 +++++++++++++++++++++++-------------
5 files changed, 113 insertions(+), 61 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ecba20e306..f4ecd354d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2024-10-20 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/build_perl_info.c (new_texinfo_report): add code
+ doing the same as calling Texinfo::Report::new() in XS.
+
+ * tp/Texinfo/XS/main/build_perl_info.c (get_document, build_document):
+ add a registrar key by calling new_texinfo_report.
+
+ * tp/Texinfo/XS/main/build_perl_info.c (get_or_build_document),
+ tp/Texinfo/XS/parsetexi/Parsetexi.pm (parse_texi_file)
+ (parse_texi_piece, parse_texi_text, parse_texi_line),
+ tp/Texinfo/XS/parsetexi/Parsetexi.xs (parse_file, parse_piece)
+ (parse_string, parse_text): build the document directly in parse_* by
+ calling the new function get_or_build_document or directly
+ get_document. Remove _get_parser_info.
+
2024-10-19 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Convert/Utils.pm (encoded_output_file_name)
diff --git a/tp/Texinfo/XS/main/build_perl_info.c
b/tp/Texinfo/XS/main/build_perl_info.c
index 0d6769e0f0..5b2049961c 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1689,6 +1689,31 @@ build_global_commands (const GLOBAL_COMMANDS
*global_commands_ref)
return hv;
}
+/* same as calling Texinfo::Report::new() */
+static SV *
+new_texinfo_report (void)
+{
+ HV *hv_stash;
+ HV *hv;
+ SV *sv;
+ AV *errors_warnings;
+
+ dTHX;
+
+ hv = newHV ();
+
+ hv_store (hv, "errors_nrs", strlen ("errors_nrs"), newSViv (0), 0);
+
+ errors_warnings = newAV ();
+ hv_store (hv, "errors_warnings", strlen ("errors_warnings"),
+ newRV_noinc ((SV *) errors_warnings), 0);
+
+ hv_stash = gv_stashpv ("Texinfo::Report", GV_ADD);
+ sv = newRV_noinc ((SV *) hv);
+ sv_bless (sv, hv_stash);
+ return sv;
+}
+
/* build a minimal document, without tree/global commands/indices, only
with the document descriptor information, errors and information that do
not refer directly to tree elements */
@@ -1701,6 +1726,7 @@ get_document (size_t document_descriptor)
SV *sv;
HV *hv_tree;
HV *hv_info;
+ SV *registrar_sv;
dTHX;
@@ -1726,6 +1752,12 @@ get_document (size_t document_descriptor)
strlen ("tree_document_descriptor"),
newSViv (document_descriptor), 0);
+ /* New error registrar for document to be used after parsing, for
+ structuring and tree modifications */
+ registrar_sv = new_texinfo_report ();
+ SvREFCNT_inc (registrar_sv);
+ hv_store (hv, "registrar", strlen ("registrar"), registrar_sv, 0);
+
if (!document->hv)
{
document->hv = (void *) hv;
@@ -1875,6 +1907,7 @@ build_document (size_t document_descriptor, int no_store)
HV *hv;
SV *sv;
HV *hv_stash;
+ SV *registrar_sv;
dTHX;
@@ -1882,12 +1915,33 @@ build_document (size_t document_descriptor, int
no_store)
fill_document_hv (hv, document_descriptor, no_store);
+ /* New error registrar for document to be used after parsing, for
+ structuring and tree modifications */
+ registrar_sv = new_texinfo_report ();
+ SvREFCNT_inc (registrar_sv);
+ hv_store (hv, "registrar", strlen ("registrar"), registrar_sv, 0);
+
hv_stash = gv_stashpv ("Texinfo::Document", GV_ADD);
sv = newRV_noinc ((SV *) hv);
sv_bless (sv, hv_stash);
return sv;
}
+SV *
+get_or_build_document (SV *parser_sv, size_t document_descriptor, int no_store)
+{
+ dTHX;
+
+ /* get hold of errors before calling build_document, as if no_store is set
+ they will be destroyed. */
+ pass_document_parser_errors_to_registrar (document_descriptor, parser_sv);
+
+ if (!no_store)
+ return get_document (document_descriptor);
+ else
+ return build_document (document_descriptor, 1);
+}
+
/* Currently unused, but could be */
void
rebuild_document (SV *document_in, int no_store)
@@ -3124,7 +3178,7 @@ pass_generic_converter_to_converter_sv (SV *converter_sv,
-/* API to access output file names associated with output units */
+/* API to access output file names associated with output units */
static SV *
build_filenames (const FILE_NAME_PATH_COUNTER_LIST *output_unit_files)
diff --git a/tp/Texinfo/XS/main/build_perl_info.h
b/tp/Texinfo/XS/main/build_perl_info.h
index c4be69cce2..8b15c3873b 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -44,6 +44,8 @@ SV *pass_errors_to_registrar (const ERROR_MESSAGE_LIST
*error_messages,
SV *build_document (size_t document_descriptor, int no_store);
SV *get_document (size_t document_descriptor);
+SV *get_or_build_document (SV *parser_sv, size_t document_descriptor,
+ int no_store);
SV *store_document_texinfo_tree (DOCUMENT *document, HV *document_hv);
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index 477e3932dc..004cf12111 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -139,46 +139,16 @@ sub parser (;$)
return $parser;
}
-sub _get_parser_info($$;$) {
- my $self = shift;
- my $document_descriptor = shift;
- my $no_store = shift;
-
- # get hold of errors before calling build_document, as if $no_store is set
- # they will be destroyed.
- pass_document_parser_errors_to_registrar($document_descriptor, $self);
-
- my $document;
- if (!$no_store) {
- $document = get_document ($document_descriptor);
- } else {
- $document = build_document ($document_descriptor, 1);
- }
-
- # New error registrar for document to be used after parsing, for
- # structuring and tree modifications
- $document->{'registrar'} = Texinfo::Report::new();
-
- return $document;
-}
-
sub parse_texi_file ($$)
{
my $self = shift;
my $input_file_path = shift;
- my $tree_stream;
return undef if (!defined($self));
# the file is already a byte string, taken as is from the command
# line. The encoding was detected as COMMAND_LINE_ENCODING.
- my $document_descriptor = parse_file($self, $input_file_path);
- if (!$document_descriptor) {
- return undef;
- }
-
- my $document = _get_parser_info($self, $document_descriptor);
-
+ my $document = parse_file($self, $input_file_path);
return $document;
}
@@ -192,9 +162,7 @@ sub parse_texi_piece($$;$$)
$line_nr = 1 if (not defined($line_nr));
- my $document_descriptor = parse_piece($self, $text, $line_nr);
-
- my $document = _get_parser_info($self, $document_descriptor, $no_store);
+ my $document = parse_piece($self, $text, $line_nr, $no_store);
return $document;
}
@@ -208,9 +176,7 @@ sub parse_texi_text($$;$)
$line_nr = 1 if (not defined($line_nr));
- my $document_descriptor = parse_text($self, $text, $line_nr);
-
- my $document = _get_parser_info($self, $document_descriptor);
+ my $document = parse_text($self, $text, $line_nr);
return $document;
}
@@ -223,9 +189,7 @@ sub parse_texi_line($$;$$)
$line_nr = 1 if (not defined($line_nr));
- my $document_descriptor = parse_string($self, $text, $line_nr);
-
- my $document = _get_parser_info($self, $document_descriptor, $no_store);
+ my $document = parse_string($self, $text, $line_nr, $no_store);
return $document->tree();
}
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index 67f624768a..8e40bfe0be 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -83,7 +83,7 @@ register_parser_conf (SV *parser)
newSViv ((IV) parser_conf->descriptor), 0);
# file path, can be in any encoding
-size_t
+SV *
parse_file (SV *parser, input_file_path)
char *input_file_path = (char *)SvPVbyte_nolen ($arg);
PREINIT:
@@ -92,46 +92,63 @@ parse_file (SV *parser, input_file_path)
CODE:
apply_sv_parser_conf (parser);
document_descriptor = parse_file (input_file_path, &status);
+ pass_document_parser_errors_to_registrar (document_descriptor,
+ parser);
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;
+ RETVAL = newSV (0);
}
else
- RETVAL = document_descriptor;
+ {
+ RETVAL = get_document (document_descriptor);
+ }
OUTPUT:
RETVAL
-size_t
-parse_piece (SV *parser, string, line_nr)
+# note that giving optional arguments, like: int no_store=0
+# would have been nice, but in that case an undef value cannot be passed
+# and leads to a perl warning
+SV *
+parse_piece (SV *parser, string, int line_nr, ...)
char *string = (char *)SvPVutf8_nolen ($arg);
- int line_nr
+ PREINIT:
+ size_t document_descriptor = 0;
+ int no_store = 0;
CODE:
+ if (items > 3 && SvOK(ST(3)))
+ no_store = SvIV (ST(3));
apply_sv_parser_conf (parser);
- RETVAL = parse_piece (string, line_nr);
+ document_descriptor = parse_piece (string, line_nr);
+ RETVAL = get_or_build_document (parser, document_descriptor, no_store);
OUTPUT:
RETVAL
-size_t
-parse_string (SV *parser, string, line_nr)
+SV *
+parse_string (SV *parser, string, int line_nr, ...)
char *string = (char *)SvPVutf8_nolen ($arg);
- int line_nr
+ PREINIT:
+ size_t document_descriptor = 0;
+ int no_store = 0;
CODE:
+ if (items > 3 && SvOK(ST(3)))
+ no_store = SvIV (ST(3));
apply_sv_parser_conf (parser);
- RETVAL = parse_string (string, line_nr);
+ document_descriptor = parse_string (string, line_nr);
+ RETVAL = get_or_build_document (parser, document_descriptor, no_store);
OUTPUT:
RETVAL
-size_t
-parse_text (SV *parser, string, line_nr)
+SV *
+parse_text (SV *parser, string, int line_nr)
char *string = (char *)SvPVutf8_nolen ($arg);
- int line_nr
+ PREINIT:
+ size_t document_descriptor = 0;
CODE:
apply_sv_parser_conf (parser);
- RETVAL = parse_text (string, line_nr);
+ document_descriptor = parse_text (string, line_nr);
+ RETVAL = get_or_build_document (parser, document_descriptor, 0);
OUTPUT:
RETVAL
@@ -145,9 +162,8 @@ build_document (size_t document_descriptor, ...)
PREINIT:
int no_store = 0;
CODE:
- if (items > 1)
- if (SvOK(ST(1)))
- no_store = SvIV (ST(1));
+ if (items > 1 && SvOK(ST(1)))
+ no_store = SvIV (ST(1));
RETVAL = build_document (document_descriptor, no_store);
OUTPUT:
RETVAL
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/XS/main/build_perl_info.c (new_texinfo_report): add code doing the same as calling Texinfo::Report::new() in XS.,
Patrice Dumas <=