[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Mon, 30 Sep 2024 15:05:22 -0400 (EDT) |
branch: master
commit 4b187d55b580ce6e2a84585ffb8427df3c8e9fa1
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Jul 22 13:47:46 2024 +0200
XS override for HTML::conversion_initialization
* tp/Texinfo/Convert/HTML.pm (conversion_initialization, convert)
(output), tp/t/accents.t: pass context as second argument of
conversion_initialization.
* tp/Texinfo/XS/convert/ConvertXS.xs (converter_set_document),
tp/Texinfo/XS/main/build_perl_info.c (pass_document_to_converter_sv):
move setting Perl data code out of converter_set_document to a new
function pass_document_to_converter_sv in build_perl_info.c.
* tp/Texinfo/XS/main/get_perl_info.c (converter_set_document_from_sv):
allow a NULL document_in argument.
* tp/Texinfo/XS/convert/ConvertXS.xs (html_initialize_output_state),
tp/Texinfo/XS/convert/build_html_perl_state.c
(html_pass_converter_output_state): set use_unicode_text in
build_html_perl_state.c.
* tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides, convert)
(output), tp/Texinfo/XS/convert/ConvertXS.xs
(html_conversion_initialization, html_init_output)
(html_prepare_simpletitle),
tp/Texinfo/XS/convert/build_html_perl_state.c
(html_pass_converter_output_state): add an XS override for
conversion_initialization. Update html_pass_converter_output_state
with a document_in argument to set converter_info and other Perl data.
Call Texinfo::Common::set_output_perl_encoding in Perl convert and
output as there is no corresponding code in C/XS. Export to Perl only
if self->external_references_number > 0, except for jslicenses that
are always passed, as they are always used in Perl.
* tp/Texinfo/XS/convert/get_html_perl_info.c: add const.
---
ChangeLog | 36 ++++++++
tp/Texinfo/Convert/HTML.pm | 17 +++-
tp/Texinfo/XS/convert/ConvertXS.xs | 105 ++++++++++++++++++------
tp/Texinfo/XS/convert/build_html_perl_state.c | 23 +++++-
tp/Texinfo/XS/convert/build_html_perl_state.h | 4 +-
tp/Texinfo/XS/convert/get_converter_perl_info.c | 5 +-
tp/Texinfo/XS/convert/get_html_perl_info.c | 4 +-
tp/Texinfo/XS/main/build_perl_info.c | 26 ++++++
tp/Texinfo/XS/main/build_perl_info.h | 4 +
tp/t/accents.t | 2 +-
10 files changed, 187 insertions(+), 39 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ad1bd370da..a6aca6ff30 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,42 @@
Update test results
+2024-07-22 Patrice Dumas <pertusus@free.fr>
+
+ XS override for HTML::conversion_initialization
+
+ * tp/Texinfo/Convert/HTML.pm (conversion_initialization, convert)
+ (output), tp/t/accents.t: pass context as second argument of
+ conversion_initialization.
+
+ * tp/Texinfo/XS/convert/ConvertXS.xs (converter_set_document),
+ tp/Texinfo/XS/main/build_perl_info.c (pass_document_to_converter_sv):
+ move setting Perl data code out of converter_set_document to a new
+ function pass_document_to_converter_sv in build_perl_info.c.
+
+ * tp/Texinfo/XS/main/get_perl_info.c (converter_set_document_from_sv):
+ allow a NULL document_in argument.
+
+ * tp/Texinfo/XS/convert/ConvertXS.xs (html_initialize_output_state),
+ tp/Texinfo/XS/convert/build_html_perl_state.c
+ (html_pass_converter_output_state): set use_unicode_text in
+ build_html_perl_state.c.
+
+ * tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides, convert)
+ (output), tp/Texinfo/XS/convert/ConvertXS.xs
+ (html_conversion_initialization, html_init_output)
+ (html_prepare_simpletitle),
+ tp/Texinfo/XS/convert/build_html_perl_state.c
+ (html_pass_converter_output_state): add an XS override for
+ conversion_initialization. Update html_pass_converter_output_state
+ with a document_in argument to set converter_info and other Perl data.
+ Call Texinfo::Common::set_output_perl_encoding in Perl convert and
+ output as there is no corresponding code in C/XS. Export to Perl only
+ if self->external_references_number > 0, except for jslicenses that
+ are always passed, as they are always used in Perl.
+
+ * tp/Texinfo/XS/convert/get_html_perl_info.c: add const.
+
2024-07-22 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/main/api_to_perl.c (get_perl_scalar_reference_value):
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 10d3e344d0..d0bfb4b185 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -105,6 +105,8 @@ my %XS_conversion_overrides = (
=> "Texinfo::Convert::ConvertXS::html_format_setup",
"Texinfo::Convert::HTML::_XS_html_converter_initialize"
=> "Texinfo::Convert::ConvertXS::html_converter_initialize_sv",
+ "Texinfo::Convert::HTML::conversion_initialization"
+ => "Texinfo::Convert::ConvertXS::html_conversion_initialization",
"Texinfo::Convert::HTML::_initialize_output_state"
=> "Texinfo::Convert::ConvertXS::html_initialize_output_state",
"Texinfo::Convert::HTML::_init_output"
@@ -12480,9 +12482,10 @@ sub _initialize_output_state($$)
# This function initializes states that are initialized both in XS and
# in perl. Called as early as possible in the conversion functions.
# $DOCUMENT is the converted Texinfo parsed document.
-sub conversion_initialization($;$)
+sub conversion_initialization($$;$)
{
my $self = shift;
+ my $context = shift;
my $document = shift;
$self->{'converter_info'} = {};
@@ -12494,7 +12497,7 @@ sub conversion_initialization($;$)
$self->{'shared_conversion_state'} = {};
- $self->_initialize_output_state('_convert');
+ $self->_initialize_output_state($context);
}
sub conversion_finalization($)
@@ -12601,7 +12604,8 @@ sub convert($$)
my $self = shift;
my $document = shift;
- $self->conversion_initialization($document);
+ $self->conversion_initialization('_convert', $document);
+ Texinfo::Common::set_output_perl_encoding($self);
_init_conversion_after_setup_handler($self);
@@ -13458,7 +13462,12 @@ sub output($$)
my $self = shift;
my $document = shift;
- $self->conversion_initialization($document);
+ $self->conversion_initialization('_output', $document);
+ Texinfo::Common::set_output_perl_encoding($self);
+
+ # TODO workaround for simpler code in XS needed while _do_js_files
+ # is not overriden. Remove when _do_js_files is overriden
+ $self->{'converter_info'} = {} if (!$self->{'converter_info'});
my $paths = _init_output($self);
if (!defined($paths)) {
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index b5aa95c458..8e33313ba7 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -98,23 +98,11 @@ void
converter_set_document (SV *converter_in, SV *document_in)
PREINIT:
CONVERTER *self;
- HV *converter_hv;
CODE:
/* if a converter is properly initialized, the XS converter should
always be found when XS is used */
self = converter_set_document_from_sv (converter_in, document_in);
- converter_hv = (HV *)SvRV (converter_in);
- SvREFCNT_inc (document_in);
- hv_store (converter_hv, "document", strlen ("document"),
- document_in, 0);
- if (self && self->convert_text_options)
- {
- SV *text_options_sv
- = build_convert_text_options (self->convert_text_options);
- hv_store (converter_hv,
- "convert_text_options", strlen("convert_text_options"),
- text_options_sv, 0);
- }
+ pass_document_to_converter_sv (self, converter_in, document_in);
void
set_conf (SV *converter_in, conf, SV *value)
@@ -578,6 +566,49 @@ html_format_setup ()
void
html_converter_initialize_sv (SV *converter_in, SV
*default_formatting_references, SV *default_css_string_formatting_references,
SV *default_commands_open, SV *default_commands_conversion, SV
*default_css_string_commands_conversion, SV *default_types_open, SV
*default_types_conversion, SV *default_css_string_types_conversion, SV
*default_output_units_conversion, SV *default_special_unit_body, SV
*default_css_element_class_styles, SV *default_converted_directions_strings)
+void
+html_conversion_initialization (SV *converter_in, const char *context, SV
*document_in=0)
+ PREINIT:
+ CONVERTER *self;
+ CODE:
+ /* if a converter is properly initialized, the XS converter should
+ always be found when XS is used */
+ self = converter_set_document_from_sv (converter_in, document_in);
+ if (self)
+ {
+ HV *converter_hv = (HV *) SvRV (converter_in);
+
+ html_initialize_output_state (self, context);
+ /* could be useful if something from Perl is needed
+ html_conversion_initialization_sv (converter_in, self);
+ */
+
+ /* internal links code is in Perl */
+ if (self->conf->INTERNAL_LINKS.o.string)
+ self->external_references_number++;
+ /* Conversion to LaTeX is in Perl */
+ if (self->conf->CONVERT_TO_LATEX_IN_MATH.o.integer > 0)
+ self->external_references_number++;
+
+ if (self->conf->CONVERT_TO_LATEX_IN_MATH.o.integer > 0)
+ {
+ HV *options_latex_math_hv =
+ latex_build_options_for_convert_to_latex_math (self);
+ hv_store (converter_hv, "options_latex_math",
+ strlen ("options_latex_math"),
+ newRV_noinc ((SV *)options_latex_math_hv), 0);
+ }
+
+ if (self->external_references_number > 0)
+ {
+ pass_document_to_converter_sv (self, converter_in,
+ document_in);
+ html_pass_converter_output_state (self, converter_in,
+ document_in);
+ }
+ }
+
+
void
html_initialize_output_state (SV *converter_in, const char *context)
PREINIT:
@@ -609,12 +640,9 @@ html_initialize_output_state (SV *converter_in, const char
*context)
newRV_noinc ((SV *)options_latex_math_hv), 0);
}
- if (self->external_references_number)
+ if (self->external_references_number > 0)
{
- html_pass_converter_output_state (converter_in, self);
- if (self->use_unicode_text)
- hv_store (converter_hv, "use_unicode_text",
- strlen ("use_unicode_text"), newSViv (1), 0);
+ html_pass_converter_output_state (self, converter_in, 0);
}
}
@@ -629,6 +657,7 @@ html_init_output (SV *converter_in)
if (self)
{
char *paths[5];
+ /* TODO remove the next 5 lines when _do_js_files is overriden */
HV *converter_hv = (HV *) SvRV (converter_in);
SV **converter_info_sv
= hv_fetch (converter_hv, "converter_info",
@@ -645,20 +674,42 @@ html_init_output (SV *converter_in)
{
SV *sv = newSVpv_utf8 (paths[i], 0);
av_push (result_av, sv);
- free (paths[i]);
}
- free (paths[4]);
RETVAL = newRV_noinc ((SV *) result_av);
- hv_store (converter_info_hv, "document_name",
- strlen ("document_name"),
- newSVpv_utf8 (self->document_name, 0), 0);
- hv_store (converter_info_hv, "destination_directory",
- strlen ("destination_directory"),
- newSVpv_utf8 (self->destination_directory, 0), 0);
+
+ for (i = 0; i < 5; i++)
+ {
+ free (paths[i]);
+ }
}
+ if (self->external_references_number > 0)
+ {
+ HV *converter_hv = (HV *) SvRV (converter_in);
+ SV **converter_info_sv
+ = hv_fetch (converter_hv, "converter_info",
+ strlen ("converter_info"), 0);
+ HV *converter_info_hv = (HV *) SvRV (*converter_info_sv);
+
+ if (status)
+ {
+ hv_store (converter_info_hv, "document_name",
+ strlen ("document_name"),
+ newSVpv_utf8 (self->document_name, 0), 0);
+ hv_store (converter_info_hv, "destination_directory",
+ strlen ("destination_directory"),
+ newSVpv_utf8 (self->destination_directory, 0),
0);
+ }
+
+ /*
+ pass_jslicenses (&self->jslicenses, converter_info_hv);
+ */
+ }
+ /* TODO when _do_js_files is overriden, remove and uncomment
+ above */
pass_jslicenses (&self->jslicenses, converter_info_hv);
+
}
OUTPUT:
RETVAL
@@ -2308,7 +2359,7 @@ html_prepare_simpletitle (SV *converter_in)
if (self)
{
html_prepare_simpletitle (self);
- if (self->simpletitle_tree)
+ if (self->simpletitle_tree && self->external_references_number >
0)
{
HV *converter_hv = (HV *) SvRV (converter_in);
SV **converter_info_sv
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.c
b/tp/Texinfo/XS/convert/build_html_perl_state.c
index 1171d778e8..7504ea1149 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.c
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.c
@@ -205,10 +205,13 @@ build_directions_strings (const CONVERTER *converter)
#define STORE(key, sv) hv_store (converter_hv, key, strlen (key), sv, 0)
#define STORE_INFO(key, sv) hv_store (converter_info_hv, key, strlen (key),
sv, 0)
void
-html_pass_converter_output_state (SV *converter_sv, const CONVERTER *converter)
+html_pass_converter_output_state (const CONVERTER *converter,
+ SV *converter_sv, SV *document_in)
{
HV *converter_hv;
+ /*
SV **converter_info_sv;
+ */
HV *converter_info_hv;
const char *non_breaking_space;
const char *paragraph_symbol;
@@ -219,13 +222,18 @@ html_pass_converter_output_state (SV *converter_sv, const
CONVERTER *converter)
SV **expanded_formats_sv;
SV *no_arg_commands_formatting_sv;
SV *directions_strings_sv;
+ HV *shared_conversion_state_hv;
dTHX;
converter_hv = (HV *) SvRV (converter_sv);
+ /*
converter_info_sv = hv_fetch (converter_hv, "converter_info",
strlen ("converter_info"), 0);
converter_info_hv = (HV *) SvRV (*converter_info_sv);
+ */
+ converter_info_hv = newHV ();
+ STORE("converter_info", newRV_noinc ((SV *)converter_info_hv));
non_breaking_space
= converter->special_character[SC_non_breaking_space].string;
@@ -262,6 +270,19 @@ html_pass_converter_output_state (SV *converter_sv, const
CONVERTER *converter)
directions_strings_sv = build_directions_strings (converter);
STORE("directions_strings", directions_strings_sv);
+ if (converter->use_unicode_text)
+ STORE("use_unicode_text", newSViv (1));
+
+ shared_conversion_state_hv = newHV ();
+ STORE("shared_conversion_state",
+ newRV_noinc ((SV *)shared_conversion_state_hv));
+
+ if (document_in && SvOK (document_in))
+ {
+ SvREFCNT_inc (document_in);
+ STORE_INFO("document", document_in);
+ }
+
#undef STORE
#undef STORE_INFO
}
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.h
b/tp/Texinfo/XS/convert/build_html_perl_state.h
index 6f3e45c174..af1184155f 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.h
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.h
@@ -13,8 +13,8 @@
HV *build_html_target (const HTML_TARGET *html_target);
void build_html_translated_names (HV *hv, CONVERTER *converter);
-void html_pass_converter_output_state (SV *converter_sv,
- const CONVERTER *converter);
+void html_pass_converter_output_state (const CONVERTER *converter,
+ SV *converter_sv, SV *document_in);
SV *build_html_files_source_info
(const FILE_SOURCE_INFO_LIST *files_source_info);
diff --git a/tp/Texinfo/XS/convert/get_converter_perl_info.c
b/tp/Texinfo/XS/convert/get_converter_perl_info.c
index 6dd913d473..00dacef589 100644
--- a/tp/Texinfo/XS/convert/get_converter_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_converter_perl_info.c
@@ -72,12 +72,13 @@ CONVERTER *
converter_set_document_from_sv (SV *converter_in, SV *document_in)
{
CONVERTER *converter;
- DOCUMENT *document;
+ DOCUMENT *document = 0;
dTHX;
converter = get_sv_converter (converter_in, "converter_set_document");
- document = get_sv_document_document (document_in, 0);
+ if (document_in)
+ document = get_sv_document_document (document_in, 0);
converter_set_document (converter, document);
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index 9e0a20fc2b..911fb90474 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -53,7 +53,7 @@
/* Following is HTML specific */
static SV **
-register_formatting_reference_default (char *type_string,
+register_formatting_reference_default (const char *type_string,
FORMATTING_REFERENCE *formatting_reference,
const char *ref_name, HV *default_hv)
{
@@ -80,7 +80,7 @@ register_formatting_reference_default (char *type_string,
}
static void
-register_formatting_reference_with_default (char *type_string,
+register_formatting_reference_with_default (const char *type_string,
FORMATTING_REFERENCE *formatting_reference,
const char *ref_name, HV *default_hv, HV *customized_hv)
{
diff --git a/tp/Texinfo/XS/main/build_perl_info.c
b/tp/Texinfo/XS/main/build_perl_info.c
index bf37fba98f..c51dd837c9 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -2362,6 +2362,32 @@ output_units_list_to_perl_hash (const DOCUMENT *document,
+void
+pass_document_to_converter_sv (const CONVERTER *converter,
+ SV *converter_sv, SV *document_in)
+{
+ HV *converter_hv;
+
+ dTHX;
+
+ converter_hv = (HV *)SvRV (converter_sv);
+
+ if (document_in && SvOK (document_in))
+ {
+ SvREFCNT_inc (document_in);
+ hv_store (converter_hv, "document", strlen ("document"),
+ document_in, 0);
+ }
+ if (converter && converter->convert_text_options)
+ {
+ SV *text_options_sv
+ = build_convert_text_options (converter->convert_text_options);
+ hv_store (converter_hv,
+ "convert_text_options", strlen("convert_text_options"),
+ text_options_sv, 0);
+ }
+}
+
SV *
get_conf (const CONVERTER *converter, const char *option_name)
{
diff --git a/tp/Texinfo/XS/main/build_perl_info.h
b/tp/Texinfo/XS/main/build_perl_info.h
index 7aa1642700..affaba7fdd 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -94,6 +94,10 @@ HV *build_sorted_indices_by_index (
SV *html_build_direction_icons (const CONVERTER *converter,
const DIRECTION_ICON_LIST *direction_icons);
+
+void pass_document_to_converter_sv (const CONVERTER *converter,
+ SV *converter_sv, SV *document_in);
+
SV *get_conf (const CONVERTER *converter, const char *option_name);
HV *build_expanded_formats (const EXPANDED_FORMAT *expanded_formats);
diff --git a/tp/t/accents.t b/tp/t/accents.t
index c00c8b5800..3d49d572b5 100644
--- a/tp/t/accents.t
+++ b/tp/t/accents.t
@@ -111,7 +111,7 @@ sub test_enable_encoding ($)
my $options = {};
my $html_converter = Texinfo::Convert::HTML->converter($options);
# NOTE we use a converter outside of output/convert
- $html_converter->conversion_initialization();
+ $html_converter->conversion_initialization('_accents_ctx');
my $result_xml = Texinfo::Convert::Converter::xml_accents($html_converter,
$accent_tree);
$html_converter->set_conf('USE_NUMERIC_ENTITY', 1);