[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: XS override for HTML::global_direction_unit
From: |
Patrice Dumas |
Subject: |
branch master updated: XS override for HTML::global_direction_unit |
Date: |
Mon, 30 Sep 2024 13:19:37 -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 62fccef21c XS override for HTML::global_direction_unit
62fccef21c is described below
commit 62fccef21c33328ecb5ca22d64240c4edbd11be2
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jul 21 17:19:08 2024 +0200
XS override for HTML::global_direction_unit
* tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides),
tp/Texinfo/XS/convert/ConvertXS.xs (html_global_direction_unit)
(html_prepare_units_directions_files)
(html_prepare_output_units_global_targets),
tp/Texinfo/XS/convert/convert_html.c
(compare_global_units_direction_name)
(html_setup_global_units_direction_names)
(html_find_direction_name_global_unit, html_reset_converter),
tp/Texinfo/XS/main/converter_types.h (SPECIAL_UNIT_DIRECTION_LIST)
(CONVERTER): setup a sorted list of SPECIAL_UNIT_DIRECTION with
direction name and output unit for global directions, including
of special output units with html_setup_global_units_direction_names,
called from html_prepare_units_directions_files and
html_prepare_output_units_global_targets. Add an XS override for
global_direction_unit that uses a bsearch to find the output unit
and the associated Perl object.
---
ChangeLog | 21 +++++++++
tp/TODO | 5 +++
tp/Texinfo/Convert/HTML.pm | 2 +
tp/Texinfo/XS/convert/ConvertXS.xs | 26 +++++++++++
tp/Texinfo/XS/convert/convert_html.c | 85 ++++++++++++++++++++++++++++++++++++
tp/Texinfo/XS/convert/convert_html.h | 3 ++
tp/Texinfo/XS/main/converter_types.h | 8 ++++
7 files changed, 150 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 6b01776d7a..47458bc062 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,27 @@
get_converter_perl_info.c functions declarations to
get_converter_perl_info.h.
+2024-07-21 Patrice Dumas <pertusus@free.fr>
+
+ XS override for HTML::global_direction_unit
+
+ * tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides),
+ tp/Texinfo/XS/convert/ConvertXS.xs (html_global_direction_unit)
+ (html_prepare_units_directions_files)
+ (html_prepare_output_units_global_targets),
+ tp/Texinfo/XS/convert/convert_html.c
+ (compare_global_units_direction_name)
+ (html_setup_global_units_direction_names)
+ (html_find_direction_name_global_unit, html_reset_converter),
+ tp/Texinfo/XS/main/converter_types.h (SPECIAL_UNIT_DIRECTION_LIST)
+ (CONVERTER): setup a sorted list of SPECIAL_UNIT_DIRECTION with
+ direction name and output unit for global directions, including
+ of special output units with html_setup_global_units_direction_names,
+ called from html_prepare_units_directions_files and
+ html_prepare_output_units_global_targets. Add an XS override for
+ global_direction_unit that uses a bsearch to find the output unit
+ and the associated Perl object.
+
2024-07-21 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Convert/Converter.pm (set_document): remove a redundant
diff --git a/tp/TODO b/tp/TODO
index 66d9c1854e..cd38c38136 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -806,6 +806,11 @@ PERL_DESTRUCT_LEVEL=2
export PERL_DESTRUCT_LEVEL
for file in t/*.t ; do bfile=`basename $file .t`; valgrind -q
--leak-check=full --keep-debuginfo=yes perl -w $file -d 1
2>t/check_debug_differences/XS_$bfile.err ; done
+Check of XS interface to Perl
+export TEXINFO_XS_CONVERT=1
+export TEXINFO_XS_EXTERNAL_FORMATTING=1
+export TEXINFO_XS_EXTERNAL_CONVERSION=1
+
Analysing memory use:
valgrinf massif useful-heap approximate distribution in 2024 (obsolete)
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 19fc12d527..eeccf8015c 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -149,6 +149,8 @@ my %XS_conversion_overrides = (
=> "Texinfo::Convert::ConvertXS::html_internal_command_text",
"Texinfo::Convert::HTML::command_description"
=> "Texinfo::Convert::ConvertXS::html_command_description",
+ "Texinfo::Convert::HTML::global_direction_unit"
+ => "Texinfo::Convert::ConvertXS::html_global_direction_unit",
"Texinfo::Convert::HTML::_XS_set_shared_conversion_state"
=> "Texinfo::Convert::ConvertXS::html_set_shared_conversion_state",
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 9be03d4ad1..324c5d3c3e 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -1580,6 +1580,28 @@ html_command_description (SV *converter_in, SV
*element_sv, const char *type=0)
OUTPUT:
RETVAL
+SV *
+html_global_direction_unit (SV *converter_in, direction_name)
+ const char *direction_name = (char *)SvPVutf8_nolen($arg);
+ PREINIT:
+ CONVERTER *self;
+ const OUTPUT_UNIT *output_unit = 0;
+ CODE:
+ self = get_sv_converter (converter_in,
+ "html_global_direction_unit");
+ if (self)
+ {
+ output_unit
+ = html_find_direction_name_global_unit (self, direction_name);
+ }
+ if (output_unit && output_unit->hv)
+ RETVAL = newRV_inc ((SV *) output_unit->hv);
+ /* should not happen */
+ else
+ RETVAL = newSV (0);
+ OUTPUT:
+ RETVAL
+
void
html_set_shared_conversion_state (SV *converter_in, cmdname, state_name, ...)
const char *cmdname = (char *)SvPVutf8_nolen($arg);
@@ -2187,6 +2209,8 @@ html_prepare_units_directions_files (SV *converter_in, SV
*output_units_in, SV *
pass_html_global_units_directions (converter_in,
self->global_units_directions,
self->special_units_direction_name);
+ html_setup_global_units_direction_names (self);
+
pass_html_elements_in_file_count (converter_in,
&self->output_unit_files);
@@ -2220,6 +2244,8 @@ html_prepare_output_units_global_targets (SV
*converter_in, SV *output_units_in,
pass_html_global_units_directions (converter_in,
self->global_units_directions,
self->special_units_direction_name);
+
+ html_setup_global_units_direction_names (self);
}
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 69748d78de..6c8401de2b 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -5491,6 +5491,87 @@ html_prepare_output_units_global_targets (CONVERTER
*self)
}
}
+static int
+compare_global_units_direction_name (const void *a, const void *b)
+{
+ const SPECIAL_UNIT_DIRECTION *gudn_a = (const SPECIAL_UNIT_DIRECTION *) a;
+ const SPECIAL_UNIT_DIRECTION *gudn_b = (const SPECIAL_UNIT_DIRECTION *) b;
+
+ return strcmp (gudn_a->direction, gudn_b->direction);
+}
+
+/* To find more easily a global output unit based on a direction name, for an
+ XS interface, associate global output units to names and sort according
+ to names */
+void
+html_setup_global_units_direction_names (CONVERTER *self)
+{
+ SPECIAL_UNIT_DIRECTION *global_units_direction_names;
+ int i;
+ int global_directions_nr = 0;
+ int global_units_direction_idx = 0;
+ const SPECIAL_UNIT_DIRECTION *special_units_direction_name
+ = self->special_units_direction_name;
+
+ for (i = 0; i < D_Last+1; i++)
+ if (self->global_units_directions[i])
+ global_directions_nr++;
+
+ for (i = 0; special_units_direction_name[i].output_unit; i++)
+ global_directions_nr++;
+
+ global_units_direction_names = (SPECIAL_UNIT_DIRECTION *)
+ malloc (sizeof (SPECIAL_UNIT_DIRECTION) * (global_directions_nr));
+
+ for (i = 0; i < D_Last+1; i++)
+ {
+ if (self->global_units_directions[i])
+ {
+ global_units_direction_names[global_units_direction_idx].direction
+ = html_global_unit_direction_names[i];
+ global_units_direction_names[global_units_direction_idx].output_unit
+ = self->global_units_directions[i];
+ global_units_direction_idx++;
+ }
+ }
+
+ for (i = 0; special_units_direction_name[i].output_unit; i++)
+ {
+ global_units_direction_names[global_units_direction_idx].direction
+ = special_units_direction_name[i].direction;
+ global_units_direction_names[global_units_direction_idx].output_unit
+ = special_units_direction_name[i].output_unit;
+ global_units_direction_idx++;
+ }
+
+ qsort (global_units_direction_names,
+ global_directions_nr,
+ sizeof (SPECIAL_UNIT_DIRECTION), compare_global_units_direction_name);
+
+ self->global_units_direction_name.list = global_units_direction_names;
+ self->global_units_direction_name.number = global_directions_nr;
+}
+
+/* Used from Perl through an XS override, in similar C codes the
+ direction indices are used instead of the direction names */
+const OUTPUT_UNIT *
+html_find_direction_name_global_unit (const CONVERTER *self,
+ const char *direction_name)
+{
+ SPECIAL_UNIT_DIRECTION *result = 0;
+ static SPECIAL_UNIT_DIRECTION searched_direction;
+
+ searched_direction.direction = direction_name;
+ result = (SPECIAL_UNIT_DIRECTION *) bsearch (&searched_direction,
+ self->global_units_direction_name.list,
+ self->global_units_direction_name.number,
+ sizeof (SPECIAL_UNIT_DIRECTION),
+ compare_global_units_direction_name);
+ if (!result)
+ return 0;
+ return result->output_unit;
+}
+
static void
set_file_source_info (FILE_SOURCE_INFO *file_source_info,
const char *file_info_type, const char
*file_info_name,
@@ -18811,6 +18892,10 @@ html_reset_converter (CONVERTER *self)
free (self->sorted_index_names.list);
memset (&self->sorted_index_names, 0, sizeof (INDEX_LIST));
+ free (self->global_units_direction_name.list);
+ self->global_units_direction_name.list = 0;
+ self->global_units_direction_name.number = 0;
+
free (self->special_units_direction_name);
self->special_units_direction_name = 0;
free (self->output_unit_file_indices);
diff --git a/tp/Texinfo/XS/convert/convert_html.h
b/tp/Texinfo/XS/convert/convert_html.h
index 54a236a860..0892ff7976 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -221,6 +221,9 @@ FILE_SOURCE_INFO_LIST * html_prepare_units_directions_files
(CONVERTER *self,
const char *output_filename, const char *document_name);
void html_prepare_output_units_global_targets (CONVERTER *self);
+void html_setup_global_units_direction_names (CONVERTER *self);
+const OUTPUT_UNIT *html_find_direction_name_global_unit (const CONVERTER *self,
+ const char *direction_name);
void html_translate_names (CONVERTER *self);
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index bad5bd99c3..a52260299f 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -470,6 +470,11 @@ typedef struct SPECIAL_UNIT_DIRECTION {
const char *direction;
} SPECIAL_UNIT_DIRECTION;
+typedef struct SPECIAL_UNIT_DIRECTION_LIST {
+ size_t number;
+ SPECIAL_UNIT_DIRECTION *list;
+} SPECIAL_UNIT_DIRECTION_LIST;
+
typedef struct FORMATTING_REFERENCE {
/* perl references. This should be SV *sv_*,
but we don't want to include the Perl headers everywhere; */
@@ -827,6 +832,9 @@ typedef struct CONVERTER {
enum htmlxref_split_type document_htmlxref_split_type;
const OUTPUT_UNIT **global_units_directions;
SPECIAL_UNIT_DIRECTION *special_units_direction_name;
+ /* both for global units associated to normal output units and
+ for special output units, sorted according to direction name */
+ SPECIAL_UNIT_DIRECTION_LIST global_units_direction_name;
ELEMENT **special_unit_info_tree[SUIT_type_heading+1];
SORTED_INDEX_NAMES sorted_index_names;
union {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: XS override for HTML::global_direction_unit,
Patrice Dumas <=