[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sat, 17 Feb 2024 18:12:40 -0500 (EST) |
branch: master
commit 979b30ca4cd8a476b6cdfcf0a1e49afd049cd9e0
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Feb 18 00:12:36 2024 +0100
Add some const for *find_element_from_sv and similar functions.
---
ChangeLog | 4 +++
tp/Texinfo/XS/convert/ConvertXS.xs | 39 ++++++++++----------
tp/Texinfo/XS/convert/get_html_perl_info.c | 14 ++++----
tp/Texinfo/XS/convert/get_html_perl_info.h | 6 ++--
tp/Texinfo/XS/main/IndicesXS.xs | 4 +--
tp/Texinfo/XS/main/get_perl_info.c | 57 +++++++++++++++---------------
tp/Texinfo/XS/main/get_perl_info.h | 5 +--
7 files changed, 70 insertions(+), 59 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1c6eb17997..bf7852a14a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2024-02-17 Patrice Dumas <pertusus@free.fr>
+
+ Add some const for *find_element_from_sv and similar functions.
+
2024-02-17 Patrice Dumas <pertusus@free.fr>
* main/utils.c (html_command_text_type_name): remove target.
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 740dc3d02f..3a860d8b15 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -939,7 +939,7 @@ html_get_target (SV *converter_in, SV *element_sv)
{
int output_units_descriptor
= get_output_units_descriptor_converter_sv (converter_in);
- ELEMENT *element;
+ const ELEMENT *element;
element = html_find_element_from_sv (self, element_sv,
output_units_descriptor);
if (element)
@@ -1053,7 +1053,7 @@ html_command_root_element_command (SV *converter_in, SV
*element_sv)
PREINIT:
CONVERTER *self;
const ELEMENT *root_element_command = 0;
- ELEMENT *element;
+ const ELEMENT *element;
CODE:
element = element_converter_from_sv (converter_in, element_sv,
"html_command_root_element_command",
@@ -1076,7 +1076,7 @@ html_command_node (SV *converter_in, SV *element_sv)
PREINIT:
CONVERTER *self;
const ELEMENT *node_element = 0;
- ELEMENT *element;
+ const ELEMENT *element;
CODE:
element = element_converter_from_sv (converter_in, element_sv,
"html_command_node", &self);
@@ -1102,12 +1102,12 @@ html_internal_command_href (SV *converter_in, SV
*element_sv, SV *source_filenam
if (element)
{
- char *source_filename = 0;
- char *specified_target = 0;
+ const char *source_filename = 0;
+ const char *specified_target = 0;
if (source_filename_sv && SvOK (source_filename_sv))
- source_filename = SvPVutf8_nolen(source_filename_sv);
+ source_filename = SvPVutf8_nolen (source_filename_sv);
if (specified_target_sv && SvOK (specified_target_sv))
- specified_target = SvPVutf8_nolen(specified_target_sv);
+ specified_target = SvPVutf8_nolen (specified_target_sv);
href = html_internal_command_href (self, element, source_filename,
specified_target);
}
@@ -1136,7 +1136,7 @@ html_command_contents_href (SV *converter_in, SV
*element_sv, cmdname, SV *sourc
if (element)
{
enum command_id cmd = lookup_builtin_command (cmdname);
- char *source_filename = 0;
+ const char *source_filename = 0;
if (source_filename_sv && SvOK (source_filename_sv))
source_filename = SvPVutf8_nolen(source_filename_sv);
href = html_command_contents_href (self, element, cmd,
@@ -1164,9 +1164,9 @@ html_footnote_location_href (SV *converter_in, SV
*element_sv, SV *source_filena
"html_footnote_location_href", &self);
if (element)
{
- char *source_filename = 0;
- char *specified_target = 0;
- char *target_filename_in = 0;
+ const char *source_filename = 0;
+ const char *specified_target = 0;
+ const char *target_filename_in = 0;
if (source_filename_sv && SvOK(source_filename_sv))
source_filename = SvPVutf8_nolen (source_filename_sv);
if (specified_target_sv && SvOK(specified_target_sv))
@@ -1175,11 +1175,14 @@ html_footnote_location_href (SV *converter_in, SV
*element_sv, SV *source_filena
target_filename_in = SvPVutf8_nolen (target_filename_sv);
href = html_footnote_location_href (self, element,
source_filename,
- specified_target,
target_filename_in);
+ specified_target,
target_filename_in);
}
if (href)
- RETVAL = newSVpv_utf8 (href, 0);
+ {
+ RETVAL = newSVpv_utf8 (href, 0);
+ free (href);
+ }
else
RETVAL = newSV (0);
OUTPUT:
@@ -1258,8 +1261,8 @@ html_internal_command_text (SV *converter_in, SV
*element_sv, char *type)
void
html_set_shared_conversion_state (SV *converter_in, cmdname, state_name, ...)
- char *cmdname = (char *)SvPVutf8_nolen($arg);
- char *state_name = (char *)SvPVutf8_nolen($arg);
+ const char *cmdname = (char *)SvPVutf8_nolen($arg);
+ const char *state_name = (char *)SvPVutf8_nolen($arg);
PREINIT:
CONVERTER *self;
SV **args_sv = 0;
@@ -1283,8 +1286,8 @@ html_set_shared_conversion_state (SV *converter_in,
cmdname, state_name, ...)
SV *
html_get_shared_conversion_state (SV *converter_in, cmdname, state_name, ...)
- char *cmdname = (char *)SvPVutf8_nolen($arg);
- char *state_name = (char *)SvPVutf8_nolen($arg);
+ const char *cmdname = (char *)SvPVutf8_nolen($arg);
+ const char *state_name = (char *)SvPVutf8_nolen($arg);
PREINIT:
CONVERTER *self;
SV **args_sv = 0;
@@ -1310,7 +1313,7 @@ html_get_shared_conversion_state (SV *converter_in,
cmdname, state_name, ...)
void
html_register_opened_section_level (SV *converter_in, int level, close_string)
- char *close_string = (char *)SvPVutf8_nolen($arg);
+ const char *close_string = (char *)SvPVutf8_nolen($arg);
PREINIT:
CONVERTER *self;
CODE:
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index b627d80180..e81ecd873a 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -1246,13 +1246,13 @@ html_converter_prepare_output_sv (SV *converter_sv,
CONVERTER *converter)
/* find C Texinfo tree element based on element_sv perl tree element.
Only for elements that can be targets of links. */
-ELEMENT *
-html_find_element_from_sv (CONVERTER *converter, SV *element_sv,
- int output_units_descriptor)
+const ELEMENT *
+html_find_element_from_sv (CONVERTER *converter, const SV *element_sv,
+ int output_units_descriptor)
{
HV *element_hv;
SV **type_sv;
- ELEMENT *element;
+ const ELEMENT *element;
dTHX;
@@ -1323,8 +1323,8 @@ get_output_units_descriptor_converter_sv (SV
*converter_in)
}
/* find converter and element */
-ELEMENT *
-element_converter_from_sv (SV *converter_in, SV *element_sv,
+const ELEMENT *
+element_converter_from_sv (SV *converter_in, const SV *element_sv,
const char *warn_string, CONVERTER **converter_out)
{
int output_units_descriptor;
@@ -1400,7 +1400,7 @@ find_node_target_info_nodedescription_sv (CONVERTER
*converter,
strlen ("element_node"), 0);
if (element_node_sv)
{
- ELEMENT *node = html_find_element_from_sv (converter,
+ const ELEMENT *node = html_find_element_from_sv (converter,
*element_node_sv, 0);
if (node)
{
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.h
b/tp/Texinfo/XS/convert/get_html_perl_info.h
index 4d09ed8168..a2e9531786 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.h
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.h
@@ -27,10 +27,12 @@ void html_conversion_initialization_sv (SV *converter_sv,
void html_converter_prepare_output_sv (SV *converter_sv, CONVERTER *converter);
-ELEMENT *html_find_element_from_sv (CONVERTER *converter, SV *element_sv,
+const ELEMENT *html_find_element_from_sv (CONVERTER *converter,
+ const SV *element_sv,
int output_units_descriptor);
-ELEMENT *element_converter_from_sv (SV *converter_in, SV *element_sv,
+const ELEMENT *element_converter_from_sv (SV *converter_in,
+ const SV *element_sv,
const char *warn_string, CONVERTER **converter_out);
void html_set_shared_conversion_state (CONVERTER *converter, SV *converter_in,
diff --git a/tp/Texinfo/XS/main/IndicesXS.xs b/tp/Texinfo/XS/main/IndicesXS.xs
index 17c117e3bc..12cc71399b 100644
--- a/tp/Texinfo/XS/main/IndicesXS.xs
+++ b/tp/Texinfo/XS/main/IndicesXS.xs
@@ -119,8 +119,8 @@ index_entry_element_sort_string (SV *customization_info_sv,
SV *main_entry_sv, S
int prefer_reference_element = 0;
int in_code;
int allocated_text_options = 0;
- ELEMENT *element = find_element_from_sv (0, document,
- element_sv, 0);
+ const ELEMENT *element = find_element_from_sv (0, document,
+ element_sv, 0);
INDEX_ENTRY *main_entry = find_index_entry_sv (main_entry_sv,
document->index_names, 0,
&entry_idx, &entry_number);
diff --git a/tp/Texinfo/XS/main/get_perl_info.c
b/tp/Texinfo/XS/main/get_perl_info.c
index 6d722e38e0..b780ef637f 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -1223,7 +1223,7 @@ html_get_direction_icons_sv (CONVERTER *converter,
INDEX_ENTRY *
find_sorted_index_names_index_entry_extra_index_entry_sv (
SORTED_INDEX_NAMES *sorted_index_names,
- SV *extra_index_entry_sv)
+ const SV *extra_index_entry_sv)
{
AV *extra_index_entry_av;
SV **index_name_sv;
@@ -1260,8 +1260,8 @@ find_sorted_index_names_index_entry_extra_index_entry_sv (
}
INDEX_ENTRY *
-find_document_index_entry_extra_index_entry_sv (DOCUMENT *document,
- SV *extra_index_entry_sv)
+find_document_index_entry_extra_index_entry_sv (const DOCUMENT *document,
+ const SV *extra_index_entry_sv)
{
AV *extra_index_entry_av;
SV **index_name_sv;
@@ -1300,9 +1300,9 @@ find_document_index_entry_extra_index_entry_sv (DOCUMENT
*document,
sorted index names, otherwise use the index information from
a document */
static INDEX_ENTRY *
-find_element_extra_index_entry_sv (DOCUMENT *document,
+find_element_extra_index_entry_sv (const DOCUMENT *document,
CONVERTER *converter,
- SV *extra_index_entry_sv)
+ const SV *extra_index_entry_sv)
{
INDEX_ENTRY *index_entry;
if (!converter || !converter->document || !converter->document->index_names)
@@ -1323,11 +1323,12 @@ find_element_extra_index_entry_sv (DOCUMENT *document,
#define FETCH(key) key##_sv = hv_fetch (element_hv, #key, strlen(#key), 0);
/* find C tree root element corresponding to perl tree element element_hv */
-ELEMENT *find_root_command (DOCUMENT *document, HV *element_hv,
- int output_units_descriptor)
+const ELEMENT *
+find_root_command (const DOCUMENT *document, HV *element_hv,
+ int output_units_descriptor)
{
SV **associated_unit_sv;
- ELEMENT *root;
+ const ELEMENT *root;
size_t i;
dTHX;
@@ -1377,15 +1378,15 @@ ELEMENT *find_root_command (DOCUMENT *document, HV
*element_hv,
}
/* find the subentry matching ELEMENT_HV */
-static ELEMENT *
-find_index_entry_subentry (ELEMENT *index_element, HV *element_hv)
+static const ELEMENT *
+find_index_entry_subentry (const ELEMENT *index_element, HV *element_hv)
{
- ELEMENT *current_element = index_element;
+ const ELEMENT *current_element = index_element;
while (1)
{
- ELEMENT *subentry = lookup_extra_element (current_element,
- "subentry");
+ const ELEMENT *subentry = lookup_extra_element (current_element,
+ "subentry");
if (subentry)
{
if (subentry->hv == element_hv)
@@ -1425,8 +1426,8 @@ subentry_hv_parent (HV *element_hv)
/* Find the index entry parent of a subentry going through
"subentry_parent" until finding the index element hash */
-ELEMENT *
-find_subentry_index_command_sv (DOCUMENT *document, HV *element_hv)
+const ELEMENT *
+find_subentry_index_command_sv (const DOCUMENT *document, HV *element_hv)
{
HV *current_parent = element_hv;
SV *current_sv = 0;
@@ -1466,8 +1467,8 @@ find_subentry_index_command_sv (DOCUMENT *document, HV
*element_hv)
when going through the elements associated to indices to setup
index entries sort strings.
*/
-ELEMENT *find_index_entry_associated_hv (INDEX_ENTRY *index_entry,
- HV *element_hv)
+const ELEMENT *find_index_entry_associated_hv (INDEX_ENTRY *index_entry,
+ HV *element_hv)
{
if (index_entry->entry_associated_element
&& index_entry->entry_associated_element->hv == element_hv)
@@ -1494,15 +1495,15 @@ ELEMENT *find_index_entry_associated_hv (INDEX_ENTRY
*index_entry,
commands faster.
Only for global commands, commands with indices, and sectioning root
commands */
-ELEMENT *
-find_element_from_sv (CONVERTER *converter, DOCUMENT *document_in,
- SV *element_sv, int output_units_descriptor)
+const ELEMENT *
+find_element_from_sv (CONVERTER *converter, const DOCUMENT *document_in,
+ const SV *element_sv, int output_units_descriptor)
{
enum command_id cmd = 0;
HV *element_hv;
SV **cmdname_sv;
SV **extra_sv;
- DOCUMENT *document = document_in;
+ const DOCUMENT *document = document_in;
dTHX;
@@ -1521,7 +1522,7 @@ find_element_from_sv (CONVERTER *converter, DOCUMENT
*document_in,
if (builtin_command_data[cmd].flags & CF_root
&& cmd != CM_node)
{
- ELEMENT *element = find_root_command (document,
+ const ELEMENT *element = find_root_command (document,
element_hv,
output_units_descriptor);
if (element)
@@ -1529,12 +1530,12 @@ find_element_from_sv (CONVERTER *converter, DOCUMENT
*document_in,
}
else if (cmd == CM_subentry)
{
- ELEMENT *index_element = find_subentry_index_command_sv (document,
- element_hv);
+ const ELEMENT *index_element
+ = find_subentry_index_command_sv (document, element_hv);
if (index_element)
{
- ELEMENT *element = find_index_entry_subentry (index_element,
- element_hv);
+ const ELEMENT *element
+ = find_index_entry_subentry (index_element, element_hv);
if (element)
return element;
}
@@ -1591,7 +1592,7 @@ find_element_from_sv (CONVERTER *converter, DOCUMENT
*document_in,
*associated_index_entry_sv);
if (index_entry)
{
- ELEMENT *index_element
+ const ELEMENT *index_element
= find_index_entry_associated_hv (index_entry, element_hv);
if (index_element)
return (index_element);
@@ -1607,7 +1608,7 @@ find_element_from_sv (CONVERTER *converter, DOCUMENT
*document_in,
*index_entry_sv);
if (index_entry)
{
- ELEMENT *index_element
+ const ELEMENT *index_element
= find_index_entry_associated_hv (index_entry, element_hv);
if (index_element)
return (index_element);
diff --git a/tp/Texinfo/XS/main/get_perl_info.h
b/tp/Texinfo/XS/main/get_perl_info.h
index e4a2fe4c90..7c9068b23c 100644
--- a/tp/Texinfo/XS/main/get_perl_info.h
+++ b/tp/Texinfo/XS/main/get_perl_info.h
@@ -59,6 +59,7 @@ void html_get_direction_icons_sv (CONVERTER *converter,
DIRECTION_ICON_LIST *direction_icons,
SV *icons_sv);
-ELEMENT *find_element_from_sv (CONVERTER *converter, DOCUMENT *document_in,
- SV *element_sv, int output_units_descriptor);
+const ELEMENT *find_element_from_sv (CONVERTER *converter,
+ const DOCUMENT *document_in,
+ const SV *element_sv, int output_units_descriptor);
#endif