[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Wed, 22 May 2024 15:43:26 -0400 (EDT) |
branch: master
commit 7ceaab760a41a3c14d7ee7be33d4bf28a59ed45e
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed May 22 21:43:07 2024 +0200
* tp/Texinfo/XS/main/get_perl_info.c (apply_sv_parser_conf),
tp/Texinfo/XS/main/parser_conf.c (apply_conf),
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), tp/Texinfo/XS/parsetexi/conf.c
(reset_parser_conf): pass parser to parser_* functions in Parsetexi.xs
to retrieve the parser_conf_descriptor kept in the parser with
apply_sv_parser_conf. Replace the current global_parser_conf with the
parser_conf associated with the parser by calling apply_conf.
Do not clear global_parser_conf structures in reset_parser_conf if the
global_parser_conf is registered. Inline clear_global_parser_conf.
---
ChangeLog | 15 ++++++++++++
tp/Texinfo/XS/main/get_perl_info.c | 45 ++++++++++++++++++++++++++++++++++++
tp/Texinfo/XS/main/get_perl_info.h | 2 ++
tp/Texinfo/XS/main/parser_conf.c | 7 ++++--
tp/Texinfo/XS/main/parser_conf.h | 4 +++-
tp/Texinfo/XS/parsetexi/Parsetexi.pm | 8 +++----
tp/Texinfo/XS/parsetexi/Parsetexi.xs | 30 ++++++++++++++++++++----
tp/Texinfo/XS/parsetexi/conf.c | 9 +++++++-
8 files changed, 108 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 71eecdad07..13873c75ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2024-05-22 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/get_perl_info.c (apply_sv_parser_conf),
+ tp/Texinfo/XS/main/parser_conf.c (apply_conf),
+ 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), tp/Texinfo/XS/parsetexi/conf.c
+ (reset_parser_conf): pass parser to parser_* functions in Parsetexi.xs
+ to retrieve the parser_conf_descriptor kept in the parser with
+ apply_sv_parser_conf. Replace the current global_parser_conf with the
+ parser_conf associated with the parser by calling apply_conf.
+ Do not clear global_parser_conf structures in reset_parser_conf if the
+ global_parser_conf is registered. Inline clear_global_parser_conf.
+
2024-05-22 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/parsetexi/input.c (parser_include_directories)
diff --git a/tp/Texinfo/XS/main/get_perl_info.c
b/tp/Texinfo/XS/main/get_perl_info.c
index 848f7fff9b..bcb4839e0b 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -37,6 +37,7 @@
#include "builtin_commands.h"
#include "errors.h"
#include "targets.h"
+#include "parser_conf.h"
#include "document.h"
#include "output_unit.h"
#include "convert_to_text.h"
@@ -226,6 +227,50 @@ get_sv_output_units (SV *output_units_in, char
*warn_string)
return output_units;
}
+void
+apply_sv_parser_conf (SV *parser_sv)
+{
+ HV *hv_in;
+ const char *key = "parser_conf_descriptor";
+ SV **parser_conf_descriptor_sv;
+
+ dTHX;
+
+ hv_in = (HV *)SvRV (parser_sv);
+
+ parser_conf_descriptor_sv = hv_fetch (hv_in, key, strlen (key), 0);
+ if (parser_conf_descriptor_sv && SvOK (*parser_conf_descriptor_sv))
+ {
+ int parser_conf_descriptor = SvIV (*parser_conf_descriptor_sv);
+
+ if (parser_conf_descriptor == global_parser_conf.descriptor)
+ {
+ /*
+ fprintf (stderr, "Reuse conf %d\n", parser_conf_descriptor);
+ */
+ return;
+ }
+ /*
+ else
+ fprintf (stderr, "APPLY %d\n", parser_conf_descriptor);
+ */
+
+ PARSER_CONF *parser_conf
+ = retrieve_parser_conf (parser_conf_descriptor);
+
+ if (!parser_conf)
+ {
+ fprintf (stderr, "ERROR: get_sv_parser_conf: descriptor %d not
found\n",
+ parser_conf_descriptor);
+ return;
+ }
+ else
+ {
+ apply_conf (parser_conf);
+ }
+ }
+}
+
void
add_svav_to_string_list (const SV *sv, STRING_LIST *string_list,
enum sv_string_type type)
diff --git a/tp/Texinfo/XS/main/get_perl_info.h
b/tp/Texinfo/XS/main/get_perl_info.h
index d71bb119e1..0215f6d6ef 100644
--- a/tp/Texinfo/XS/main/get_perl_info.h
+++ b/tp/Texinfo/XS/main/get_perl_info.h
@@ -26,6 +26,8 @@ DOCUMENT *get_sv_document_document (SV *document_in, char
*warn_string);
OUTPUT_UNIT_LIST *get_sv_output_units (SV *output_units_in, char *warn_string);
int get_sv_output_units_descriptor (SV *output_units_in, char *warn_string);
+void apply_sv_parser_conf (SV *parser_sv);
+
void add_svav_to_string_list (const SV *sv, STRING_LIST *string_list,
enum sv_string_type type);
diff --git a/tp/Texinfo/XS/main/parser_conf.c b/tp/Texinfo/XS/main/parser_conf.c
index 32aed5dce6..5924df6893 100644
--- a/tp/Texinfo/XS/main/parser_conf.c
+++ b/tp/Texinfo/XS/main/parser_conf.c
@@ -13,6 +13,9 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+/* This file is in main and not in parsetexi because get_perl_info.c depends
+ on it */
+
#include <config.h>
#include <stdlib.h>
#include <string.h>
@@ -90,9 +93,9 @@ clear_parser_conf (PARSER_CONF *parser_conf)
}
void
-clear_global_parser_conf (void)
+apply_conf (PARSER_CONF *parser_conf)
{
if (!global_parser_conf.descriptor)
clear_parser_conf (&global_parser_conf);
+ global_parser_conf = *parser_conf;
}
-
diff --git a/tp/Texinfo/XS/main/parser_conf.h b/tp/Texinfo/XS/main/parser_conf.h
index 89101f3637..cbc54a39d7 100644
--- a/tp/Texinfo/XS/main/parser_conf.h
+++ b/tp/Texinfo/XS/main/parser_conf.h
@@ -47,6 +47,8 @@ extern PARSER_CONF global_parser_conf;
PARSER_CONF *register_conf ();
PARSER_CONF *retrieve_parser_conf (int parser_conf_descriptor);
-void clear_global_parser_conf (void);
+void clear_parser_conf (PARSER_CONF *parser_conf);
+
+void apply_conf (PARSER_CONF *parser_conf);
#endif
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index 0cf9b10270..a3124de21f 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -222,7 +222,7 @@ sub parse_texi_file ($$)
# TODO instead of using fileparse here, reimplement fileparse
# in XS, or use a file name parsing code from somewhere else?
my ($basename, $directories, $suffix) = fileparse($input_file_path);
- my $document_descriptor = parse_file($input_file_path,
+ my $document_descriptor = parse_file($self, $input_file_path,
$basename, $directories);
if (!$document_descriptor) {
my $parser_registrar = $self->{'registrar'};
@@ -251,7 +251,7 @@ sub parse_texi_piece($$;$$)
$line_nr = 1 if (not defined($line_nr));
- my $document_descriptor = parse_piece($text, $line_nr);
+ my $document_descriptor = parse_piece($self, $text, $line_nr);
my $document = _get_parser_info($self, $document_descriptor, $no_store);
@@ -267,7 +267,7 @@ sub parse_texi_text($$;$)
$line_nr = 1 if (not defined($line_nr));
- my $document_descriptor = parse_text($text, $line_nr);
+ my $document_descriptor = parse_text($self, $text, $line_nr);
my $document = _get_parser_info($self, $document_descriptor);
@@ -282,7 +282,7 @@ sub parse_texi_line($$;$$)
$line_nr = 1 if (not defined($line_nr));
- my $document_descriptor = parse_string($text, $line_nr);
+ my $document_descriptor = parse_string($self, $text, $line_nr);
my $document = _get_parser_info($self, $document_descriptor, $no_store);
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index af631320d8..24cb70390f 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -33,6 +33,7 @@
#include "conf.h"
#include "parser_conf.h"
#include "build_perl_info.h"
+#include "get_perl_info.h"
/* See the NOTE in build_perl_info.c on use of functions related to
memory allocation */
@@ -73,25 +74,46 @@ register_parser_conf (SV *parser)
# file path, can be in any encoding
int
-parse_file (filename, input_file_name, input_directory)
+parse_file (SV *parser, filename, input_file_name, input_directory)
char *filename = (char *)SvPVbyte_nolen ($arg);
char *input_file_name = (char *)SvPVbyte_nolen ($arg);
char *input_directory = (char *)SvPVbyte_nolen ($arg);
+ CODE:
+ apply_sv_parser_conf (parser);
+ RETVAL = parse_file (filename, input_file_name, input_directory);
+ OUTPUT:
+ RETVAL
int
-parse_piece (string, line_nr)
+parse_piece (SV *parser, string, line_nr)
char *string = (char *)SvPVutf8_nolen ($arg);
int line_nr
+ CODE:
+ apply_sv_parser_conf (parser);
+ RETVAL = parse_piece (string, line_nr);
+ OUTPUT:
+ RETVAL
int
-parse_string (string, line_nr)
+parse_string (SV *parser, string, line_nr)
char *string = (char *)SvPVutf8_nolen ($arg);
int line_nr
+ CODE:
+ apply_sv_parser_conf (parser);
+ RETVAL = parse_string (string, line_nr);
+ OUTPUT:
+ RETVAL
int
-parse_text (string, line_nr)
+parse_text (SV *parser, string, line_nr)
char *string = (char *)SvPVutf8_nolen ($arg);
int line_nr
+ CODE:
+ apply_sv_parser_conf (parser);
+ RETVAL = parse_text (string, line_nr);
+ OUTPUT:
+ RETVAL
+
# note that giving optional arguments, like: int no_store=0
# would have been nice, but in that case an undef value cannot be passed
diff --git a/tp/Texinfo/XS/parsetexi/conf.c b/tp/Texinfo/XS/parsetexi/conf.c
index 3a74432487..914b4ee6eb 100644
--- a/tp/Texinfo/XS/parsetexi/conf.c
+++ b/tp/Texinfo/XS/parsetexi/conf.c
@@ -130,7 +130,14 @@ parser_conf_set_accept_internalvalue (int value)
void
reset_parser_conf (void)
{
- clear_global_parser_conf ();
+ /* FIXME except for the very first call to reset_parser_conf, there
+ should always be a descriptor set, so only the first case may happen */
+ if (global_parser_conf.descriptor)
+ /* it is important to set to 0 for list structures such that the list
+ pointer is set to 0 and not reused. */
+ memset (&global_parser_conf, 0, sizeof (PARSER_CONF));
+ else
+ clear_parser_conf (&global_parser_conf);
global_parser_conf.descriptor = 0;