[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: Wrappers around functions to avoid mixing Perl an
From: |
Patrice Dumas |
Subject: |
branch master updated: Wrappers around functions to avoid mixing Perl and non-Perl |
Date: |
Mon, 26 Feb 2024 08:24:55 -0500 |
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 d7ba5543f3 Wrappers around functions to avoid mixing Perl and non-Perl
d7ba5543f3 is described below
commit d7ba5543f3845606eaa03ab98473daafce43e1d2
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Feb 26 14:24:50 2024 +0100
Wrappers around functions to avoid mixing Perl and non-Perl
* tp/Texinfo/XS/convert/convert_html.c (initialize_cmd_list)
(new_htmlxref_manual_list, initialize_js_categories_list)
(initialize_jslicense_files, initialize_css_selector_style_list)
(new_directions_strings_translated_type, new_directions_strings_type)
(new_special_unit_formatting_references)
(initialize_special_unit_info_type),
tp/Texinfo/XS/convert/get_html_perl_info.c: add and use initialization
functions, and use more wrappers.
---
ChangeLog | 13 +++
tp/Texinfo/XS/convert/convert_html.c | 111 +++++++++++++++++++++++
tp/Texinfo/XS/convert/convert_html.h | 20 +++++
tp/Texinfo/XS/convert/get_html_perl_info.c | 136 +++++++++++++----------------
4 files changed, 206 insertions(+), 74 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 226185baac..3459013f09 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-02-26 Patrice Dumas <pertusus@free.fr>
+
+ Wrappers around functions to avoid mixing Perl and non-Perl
+
+ * tp/Texinfo/XS/convert/convert_html.c (initialize_cmd_list)
+ (new_htmlxref_manual_list, initialize_js_categories_list)
+ (initialize_jslicense_files, initialize_css_selector_style_list)
+ (new_directions_strings_translated_type, new_directions_strings_type)
+ (new_special_unit_formatting_references)
+ (initialize_special_unit_info_type),
+ tp/Texinfo/XS/convert/get_html_perl_info.c: add and use initialization
+ functions, and use more wrappers.
+
2024-02-25 Patrice Dumas <pertusus@free.fr>
Homogenize the reference to the NOTE in build_perl_info.c
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 475359e467..6d06462b99 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -16150,6 +16150,117 @@ register_special_unit_body_formatting_function
}
}
+/* these constructors/initialization allow to use malloc from this
+ file and not from a file including Perl headers */
+
+/* NOTE relatively generic */
+void
+initialize_cmd_list (COMMAND_ID_LIST *cmd_list, size_t size, size_t number)
+{
+ cmd_list->list = (enum command_id *) malloc
+ (size * sizeof (enum command_id));
+ cmd_list->number = number;
+ if (number)
+ {
+ memset (cmd_list->list, 0, number * sizeof (enum command_id));
+ }
+}
+
+HTMLXREF_MANUAL *
+new_htmlxref_manual_list (size_t size)
+{
+ HTMLXREF_MANUAL *result = (HTMLXREF_MANUAL *)
+ malloc (size * sizeof (HTMLXREF_MANUAL));
+ memset (result, 0, size * sizeof (HTMLXREF_MANUAL));
+
+ return result;
+}
+
+void
+initialize_js_categories_list (JSLICENSE_CATEGORY_LIST *js_files_info,
+ size_t size)
+{
+ js_files_info->list = (JSLICENSE_FILE_INFO_LIST *)
+ malloc (size * sizeof (JSLICENSE_FILE_INFO_LIST));
+ memset (js_files_info->list, 0,
+ size * sizeof (JSLICENSE_FILE_INFO_LIST));
+ js_files_info->number = size;
+}
+
+void
+initialize_jslicense_files (JSLICENSE_FILE_INFO_LIST *jslicences_files_info,
+ const char *category, size_t size)
+{
+ jslicences_files_info->category = strdup (category);
+ jslicences_files_info->list = (JSLICENSE_FILE_INFO *)
+ malloc (size * sizeof (JSLICENSE_FILE_INFO));
+ memset (jslicences_files_info->list, 0,
+ size * sizeof (JSLICENSE_FILE_INFO));
+ jslicences_files_info->number = size;
+}
+
+void
+initialize_css_selector_style_list (CSS_SELECTOR_STYLE_LIST *selector_styles,
+ size_t size)
+{
+ selector_styles->list = (CSS_SELECTOR_STYLE *)
+ malloc (size * sizeof (CSS_SELECTOR_STYLE));
+ selector_styles->space = size;
+ selector_styles->number = size;
+}
+
+HTML_DIRECTION_STRING_TRANSLATED *
+new_directions_strings_translated_type (int nr_string_directions)
+{
+ HTML_DIRECTION_STRING_TRANSLATED *result
+ = (HTML_DIRECTION_STRING_TRANSLATED *) malloc
+ (nr_string_directions * sizeof (HTML_DIRECTION_STRING_TRANSLATED));
+ memset (result, 0,
+ nr_string_directions * sizeof (HTML_DIRECTION_STRING_TRANSLATED));
+ return result;
+}
+
+char ***
+new_directions_strings_type (int nr_string_directions,
+ int nr_dir_str_contexts)
+{
+ int i;
+ char ***result = (char ***)
+ malloc (nr_string_directions * sizeof (char **));
+ memset (result, 0,
+ nr_string_directions * sizeof (char **));
+
+ for (i = 0; i < nr_string_directions; i++)
+ {
+ result[i] = (char **)
+ malloc (nr_dir_str_contexts * sizeof (char *));
+ memset (result[i], 0,
+ nr_dir_str_contexts * sizeof (char *));
+ }
+
+ return result;
+}
+
+FORMATTING_REFERENCE *
+new_special_unit_formatting_references (int special_units_varieties_nr)
+{
+ FORMATTING_REFERENCE *formatting_references = (FORMATTING_REFERENCE *)
+ malloc (special_units_varieties_nr * sizeof (FORMATTING_REFERENCE));
+ memset (formatting_references, 0,
+ special_units_varieties_nr * sizeof (FORMATTING_REFERENCE));
+ return formatting_references;
+}
+
+void
+initialize_special_unit_info_type (char **special_unit_info,
+ int special_units_varieties_nr)
+{
+ special_unit_info = (char **)
+ malloc ((special_units_varieties_nr +1) * sizeof (char *));
+ memset (special_unit_info, 0,
+ (special_units_varieties_nr +1) * sizeof (char *));
+}
+
/* most of the initialization is done by html_converter_initialize_sv
in get_perl_info, the initialization that do not require information
directly from perl data is done here. This is called after information
diff --git a/tp/Texinfo/XS/convert/convert_html.h
b/tp/Texinfo/XS/convert/convert_html.h
index b9f6bf00e3..e1fe390704 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -45,6 +45,26 @@ void html_conversion_finalization (CONVERTER *self);
void html_converter_prepare_output (CONVERTER* self);
+void initialize_cmd_list (COMMAND_ID_LIST *cmd_list, size_t size);
+
+HTMLXREF_MANUAL *new_htmlxref_manual_list (size_t size);
+void initialize_js_categories_list (JSLICENSE_CATEGORY_LIST *js_files_info,
+ size_t size);
+void initialize_jslicense_files
+ (JSLICENSE_FILE_INFO_LIST *jslicences_files_info,
+ const char *category, size_t size);
+void initialize_css_selector_style_list
+ (CSS_SELECTOR_STYLE_LIST *selector_styles,
+ size_t size);
+HTML_DIRECTION_STRING_TRANSLATED *new_directions_strings_translated_type
+ (int nr_string_directions);
+char ***new_directions_strings_type (int nr_string_directions,
+ int nr_dir_str_contexts);
+FORMATTING_REFERENCE *new_special_unit_formatting_references
+ (int special_units_varieties_nr);
+void initialize_special_unit_info_type (char **special_unit_info,
+ int special_units_varieties_nr);
+
int html_open_command_update_context (CONVERTER *self,
enum command_id data_cmd);
void html_convert_command_update_context (CONVERTER *self,
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index 74a8d0a2ae..e3dc266bb2 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -194,10 +194,7 @@ html_converter_initialize_sv (SV *converter_sv,
if (hv_number > 0)
{
- converter->htmlxref.list = (HTMLXREF_MANUAL *)
- malloc (hv_number * sizeof (HTMLXREF_MANUAL));
- memset (converter->htmlxref.list, 0,
- hv_number * sizeof (HTMLXREF_MANUAL));
+ converter->htmlxref.list = new_htmlxref_manual_list (hv_number);
for (i = 0; i < hv_number; i++)
{
@@ -325,9 +322,7 @@ html_converter_initialize_sv (SV *converter_sv,
nr_accent_cmd++;
}
- converter->accent_cmd.list = (enum command_id *)
- malloc (nr_accent_cmd * sizeof (enum command_id));
- converter->accent_cmd.number = 0;
+ initialize_cmd_list (&converter->accent_cmd, nr_accent_cmd, 0);
default_css_string_commands_conversion_hv
= (HV *)SvRV (default_css_string_commands_conversion);
@@ -441,9 +436,7 @@ html_converter_initialize_sv (SV *converter_sv,
= (HV*) SvRV (default_no_arg_commands_formatting);
hv_number = hv_iterinit (default_no_arg_commands_formatting_hv);
- converter->no_arg_formatted_cmd.list = (enum command_id *)
- malloc (hv_number * sizeof (enum command_id));
- converter->no_arg_formatted_cmd.number = 0;
+ initialize_cmd_list (&converter->no_arg_formatted_cmd, hv_number, 0);
for (i = 0; i < hv_number; i++)
{
@@ -506,11 +499,9 @@ html_converter_initialize_sv (SV *converter_sv,
special_unit_info_type_hv
= (HV *) SvRV(*special_unit_info_type_sv);
- converter->special_unit_info[j]
- = (char **)
- malloc ((special_unit_varieties->number +1) * sizeof (char
*));
- memset (converter->special_unit_info[j], 0,
- (special_unit_varieties->number +1) * sizeof (char *));
+ initialize_special_unit_info_type
+ (converter->special_unit_info[j],
+ special_unit_varieties->number);
for (k = 0; k < special_unit_varieties->number; k++)
{
@@ -523,9 +514,10 @@ html_converter_initialize_sv (SV *converter_sv,
/* can be undef if set undef in user init file */
if (SvOK (*info_type_variety_sv))
{
- char *value
+ const char *value
= (char *) SvPVutf8_nolen (*info_type_variety_sv);
- converter->special_unit_info[j][k] = non_perl_strdup
(value);
+ converter->special_unit_info[j][k]
+ = non_perl_strdup (value);
}
else
converter->special_unit_info[j][k] = 0;
@@ -538,10 +530,9 @@ html_converter_initialize_sv (SV *converter_sv,
}
}
- converter->special_unit_body = (FORMATTING_REFERENCE *)
- malloc (special_unit_varieties->number * sizeof (FORMATTING_REFERENCE));
- memset (converter->special_unit_body, 0,
- special_unit_varieties->number * sizeof (FORMATTING_REFERENCE));
+ converter->special_unit_body
+ = new_special_unit_formatting_references
+ (special_unit_varieties->number);
FETCH(special_unit_body)
special_unit_body_hv = (HV *)SvRV (*special_unit_body_sv);
@@ -728,9 +719,7 @@ html_converter_initialize_sv (SV *converter_sv,
= (HV *)SvRV (*style_commands_formatting_sv);
hv_number = hv_iterinit (style_commands_formatting_hv);
- converter->style_formatted_cmd.list = (enum command_id *)
- malloc (hv_number * sizeof (enum command_id));
- converter->style_formatted_cmd.number = 0;
+ initialize_cmd_list (&converter->style_formatted_cmd, hv_number, 0);
for (i = 0; i < hv_number; i++)
{
@@ -922,31 +911,33 @@ html_conversion_initialization_sv (SV *converter_sv,
CONVERTER *converter)
&key, &retlen);
if (!strcmp (key, "element"))
{
- char *tmp_spec
+ const char *tmp_spec
= (char *) SvPVutf8_nolen (spec_sv);
- format_spec->element = strdup (tmp_spec);
+ format_spec->element
+ = non_perl_strdup (tmp_spec);
}
else if (!strcmp (key, "unset"))
format_spec->unset = SvIV (spec_sv);
else if (!strcmp (key, "text"))
{
- char *tmp_spec
+ const char *tmp_spec
= (char *) SvPVutf8_nolen (spec_sv);
- format_spec->text = strdup (tmp_spec);
+ format_spec->text
+ = non_perl_strdup (tmp_spec);
}
else if (!strcmp (key, "translated_converted"))
{
- char *tmp_spec
+ const char *tmp_spec
= (char *) SvPVutf8_nolen (spec_sv);
format_spec->translated_converted
- = strdup (tmp_spec);
+ = non_perl_strdup (tmp_spec);
}
else if (!strcmp (key, "translated_to_convert"))
{
- char *tmp_spec
+ const char *tmp_spec
= (char *) SvPVutf8_nolen (spec_sv);
format_spec->translated_to_convert
- = strdup (tmp_spec);
+ = non_perl_strdup (tmp_spec);
}
}
}
@@ -973,10 +964,9 @@ html_conversion_initialization_sv (SV *converter_sv,
CONVERTER *converter)
HV *direction_hv = 0;
const char *type_name = direction_string_type_names[DS_type];
- converter->directions_strings[DS_type] = (char ***)
- malloc (nr_string_directions * sizeof (char **));
- memset (converter->directions_strings[DS_type], 0,
- nr_string_directions * sizeof (char **));
+ converter->directions_strings[DS_type]
+ = new_directions_strings_type (nr_string_directions,
+ nr_dir_str_contexts);
if (directions_strings_sv)
{
@@ -988,11 +978,6 @@ html_conversion_initialization_sv (SV *converter_sv,
CONVERTER *converter)
for (i = 0; i < nr_string_directions; i++)
{
- converter->directions_strings[DS_type][i] = (char **)
- malloc (nr_dir_str_contexts * sizeof (char *));
- memset (converter->directions_strings[DS_type][i], 0,
- nr_dir_str_contexts * sizeof (char *));
-
if (direction_sv)
{
const char *direction_name;
@@ -1023,8 +1008,10 @@ html_conversion_initialization_sv (SV *converter_sv,
CONVERTER *converter)
if (value_sv && SvOK (*value_sv))
{
+ const char *value
+ = (char *) SvPVutf8_nolen (*value_sv);
converter->directions_strings[DS_type][i][j]
- = strdup ((char *) SvPVutf8_nolen (*value_sv));
+ = non_perl_strdup (value);
}
}
}
@@ -1041,10 +1028,7 @@ html_conversion_initialization_sv (SV *converter_sv,
CONVERTER *converter)
for (DS_type = 0; DS_type < TDS_TRANSLATED_MAX_NR; DS_type++)
{
converter->translated_direction_strings[DS_type]
- = (HTML_DIRECTION_STRING_TRANSLATED *) malloc
- (nr_string_directions * sizeof (HTML_DIRECTION_STRING_TRANSLATED));
- memset (converter->translated_direction_strings[DS_type], 0,
- nr_string_directions * sizeof (HTML_DIRECTION_STRING_TRANSLATED));
+ = new_directions_strings_translated_type (nr_string_directions);
if (translated_direction_strings_sv)
{
@@ -1081,9 +1065,11 @@ html_conversion_initialization_sv (SV *converter_sv,
CONVERTER *converter)
/* can be undef if set through Config */
if (to_convert_sv && SvOK (*to_convert_sv))
{
+ const char *to_convert
+ = (char *) SvPVutf8_nolen (*to_convert_sv);
converter
->translated_direction_strings[DS_type][i].to_convert
- = strdup ((char *) SvPVutf8_nolen
(*to_convert_sv));
+ = non_perl_strdup (to_convert);
}
else
{
@@ -1105,9 +1091,11 @@ html_conversion_initialization_sv (SV *converter_sv,
CONVERTER *converter)
if (value_sv)
{
+ const char *value
+ = (char *) SvPVutf8_nolen (*value_sv);
converter
->translated_direction_strings[DS_type][i].converted[j]
- = strdup ((char *) SvPVutf8_nolen (*value_sv));
+ = non_perl_strdup (value);
}
}
}
@@ -1130,10 +1118,8 @@ html_conversion_initialization_sv (SV *converter_sv,
CONVERTER *converter)
hv_number = hv_iterinit (css_element_class_styles_hv);
- converter->css_element_class_styles.space = hv_number;
- converter->css_element_class_styles.list = (CSS_SELECTOR_STYLE *)
- malloc (hv_number * sizeof (CSS_SELECTOR_STYLE));
- converter->css_element_class_styles.number = hv_number;
+ initialize_css_selector_style_list (&converter->css_element_class_styles,
+ hv_number);
for (i = 0; i < hv_number; i++)
{
@@ -1145,8 +1131,8 @@ html_conversion_initialization_sv (SV *converter_sv,
CONVERTER *converter)
CSS_SELECTOR_STYLE *selector_style
= &converter->css_element_class_styles.list[i];
- selector_style->selector = strdup (selector);
- selector_style->style = strdup (style);
+ selector_style->selector = non_perl_strdup (selector);
+ selector_style->style = non_perl_strdup (style);
}
}
}
@@ -1174,11 +1160,7 @@ html_converter_prepare_output_sv (SV *converter_sv,
CONVERTER *converter)
if (hv_number > 0)
{
- converter->jslicenses.number = hv_number;
- converter->jslicenses.list = (JSLICENSE_FILE_INFO_LIST *)
- malloc (hv_number * sizeof (JSLICENSE_FILE_INFO_LIST));
- memset (converter->jslicenses.list, 0,
- hv_number * sizeof (JSLICENSE_FILE_INFO_LIST));
+ initialize_js_categories_list (&converter->jslicenses, hv_number);
for (i = 0; i < hv_number; i++)
{
@@ -1186,21 +1168,17 @@ html_converter_prepare_output_sv (SV *converter_sv,
CONVERTER *converter)
I32 j;
HE *next = hv_iternext (jslicenses_hv);
SV *category_sv = hv_iterkeysv (next);
- char *category = (char *) SvPVutf8_nolen (category_sv);
+ const char *category = (char *) SvPVutf8_nolen (category_sv);
SV *files_info_sv = HeVAL(next);
HV *files_info_hv = (HV *)SvRV (files_info_sv);
JSLICENSE_FILE_INFO_LIST *jslicences_files_info
= &converter->jslicenses.list[i];
- jslicences_files_info->category = strdup (category);
-
hv_files_number = hv_iterinit (files_info_hv);
- jslicences_files_info->number = hv_files_number;
- jslicences_files_info->list = (JSLICENSE_FILE_INFO *)
- malloc (hv_files_number * sizeof (JSLICENSE_FILE_INFO));
- memset (jslicences_files_info->list, 0,
- hv_files_number * sizeof (JSLICENSE_FILE_INFO));
+
+ initialize_jslicense_files (jslicences_files_info, category,
+ hv_files_number);
for (j = 0; j < hv_files_number; j++)
{
@@ -1216,7 +1194,7 @@ html_converter_prepare_output_sv (SV *converter_sv,
CONVERTER *converter)
JSLICENSE_FILE_INFO *jslicense_file_info
= &jslicences_files_info->list[j];
- jslicense_file_info->filename = strdup (filename);
+ jslicense_file_info->filename = non_perl_strdup (filename);
file_info_nr = av_top_index (file_info_av) +1;
if (file_info_nr != 3)
@@ -1228,16 +1206,26 @@ html_converter_prepare_output_sv (SV *converter_sv,
CONVERTER *converter)
}
license_sv = av_fetch (file_info_av, 0, 0);
if (license_sv && SvOK (*license_sv))
- jslicense_file_info->license
- = strdup ((char *) SvPVutf8_nolen (*license_sv));
+ {
+ const char *license
+ = (char *) SvPVutf8_nolen (*license_sv);
+ jslicense_file_info->license
+ = non_perl_strdup (license);
+ }
url_sv = av_fetch (file_info_av, 0, 0);
if (url_sv && SvOK (*url_sv))
- jslicense_file_info->url
- = strdup ((char *) SvPVutf8_nolen (*url_sv));
+ {
+ const char *url = (char *) SvPVutf8_nolen (*url_sv);
+ jslicense_file_info->url = non_perl_strdup (url);
+ }
source_sv = av_fetch (file_info_av, 0, 0);
if (source_sv && SvOK (*source_sv))
- jslicense_file_info->source
- = strdup ((char *) SvPVutf8_nolen (*source_sv));
+ {
+ const char *source
+ = (char *) SvPVutf8_nolen (*source_sv);
+ jslicense_file_info->source
+ = non_perl_strdup (source);
+ }
}
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Wrappers around functions to avoid mixing Perl and non-Perl,
Patrice Dumas <=