[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Fri, 24 Nov 2023 11:52:19 -0500 (EST) |
branch: master
commit 20ad84474f4415b724d5d1b847afd54991e3a91d
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Nov 24 17:35:10 2023 +0100
Use an union for KEY_PAIR value.
* tp/Texinfo/XS/main/tree_types.h (KEY_PAIR),
tp/Texinfo/XS/main/build_perl_info.c (store_additional_info),
tp/Texinfo/XS/main/debug.c (print_associate_info_debug),
tp/Texinfo/XS/main/extra.c (get_associated_info_key, add_*, lookup_*),
tp/Texinfo/XS/main/manipulate_tree.c (copy_associated_info)
(associate_info_references), tp/Texinfo/XS/main/tree.c
(destroy_associated_info): use a union for the KEY_PAIR value instead
of casting. Replace add_associated_info_key by
get_associated_info_key which does not set the value.
Update other codes to use the union instead of value.
---
ChangeLog | 15 ++++
tp/Texinfo/XS/main/build_perl_info.c | 15 ++--
tp/Texinfo/XS/main/builtin_commands.c | 4 +-
tp/Texinfo/XS/main/convert_to_texinfo.c | 11 ++-
tp/Texinfo/XS/main/debug.c | 18 ++---
tp/Texinfo/XS/main/extra.c | 82 ++++++++++------------
tp/Texinfo/XS/main/extra.h | 4 +-
tp/Texinfo/XS/main/manipulate_tree.c | 66 +++++++++--------
tp/Texinfo/XS/main/node_name_normalization.c | 5 +-
tp/Texinfo/XS/main/targets.c | 6 +-
tp/Texinfo/XS/main/tree.c | 10 +--
tp/Texinfo/XS/main/tree_types.h | 6 +-
tp/Texinfo/XS/main/utils.c | 2 +-
tp/Texinfo/XS/parsetexi/close.c | 4 +-
tp/Texinfo/XS/parsetexi/end_line.c | 28 ++++----
tp/Texinfo/XS/parsetexi/handle_commands.c | 10 +--
tp/Texinfo/XS/parsetexi/indices.c | 28 +++-----
tp/Texinfo/XS/parsetexi/macro.c | 2 +-
tp/Texinfo/XS/parsetexi/parser.c | 2 +-
.../XS/structuring_transfo/transformations.c | 19 ++---
20 files changed, 177 insertions(+), 160 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 318e84f2e5..7db3ff50bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2023-11-24 Patrice Dumas <pertusus@free.fr>
+
+ Use an union for KEY_PAIR value.
+
+ * tp/Texinfo/XS/main/tree_types.h (KEY_PAIR),
+ tp/Texinfo/XS/main/build_perl_info.c (store_additional_info),
+ tp/Texinfo/XS/main/debug.c (print_associate_info_debug),
+ tp/Texinfo/XS/main/extra.c (get_associated_info_key, add_*, lookup_*),
+ tp/Texinfo/XS/main/manipulate_tree.c (copy_associated_info)
+ (associate_info_references), tp/Texinfo/XS/main/tree.c
+ (destroy_associated_info): use a union for the KEY_PAIR value instead
+ of casting. Replace add_associated_info_key by
+ get_associated_info_key which does not set the value.
+ Update other codes to use the union instead of value.
+
2023-11-24 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Common.pm (parse_node_manual), tp/Texinfo/Convert/HTML.pm
diff --git a/tp/Texinfo/XS/main/build_perl_info.c
b/tp/Texinfo/XS/main/build_perl_info.c
index 34ca4ec2df..735c8cb3b7 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -255,15 +255,16 @@ store_additional_info (const ELEMENT *e, ASSOCIATED_INFO*
a, char *key)
for (i = 0; i < a->info_number; i++)
{
+ KEY_PAIR *k = &a->info[i];
#define STORE(sv) hv_store (extra, key, strlen (key), sv, 0)
- char *key = a->info[i].key;
- ELEMENT *f = (ELEMENT *) a->info[i].value;
+ char *key = k->key;
+ ELEMENT *f = k->element;
- if (a->info[i].type == extra_deleted)
+ if (k->type == extra_deleted)
continue;
nr_info++;
- switch (a->info[i].type)
+ switch (k->type)
{
case extra_element:
/* For references to other parts of the tree, create the hash so
@@ -322,7 +323,7 @@ store_additional_info (const ELEMENT *e, ASSOCIATED_INFO*
a, char *key)
}
case extra_string:
{ /* A simple string. */
- char *value = (char *) f;
+ char *value = k->string;
STORE(newSVpv_utf8 (value, 0));
break;
}
@@ -330,7 +331,7 @@ store_additional_info (const ELEMENT *e, ASSOCIATED_INFO*
a, char *key)
{ /* A simple integer. The intptr_t cast here prevents
a warning on MinGW ("cast from pointer to integer of
different size"). */
- IV value = (IV) (intptr_t) f;
+ IV value = (IV) k->integer;
STORE(newSViv (value));
break;
}
@@ -349,7 +350,7 @@ store_additional_info (const ELEMENT *e, ASSOCIATED_INFO*
a, char *key)
k_integer = lookup_extra (f->contents.list[j], "integer");
if (k_integer)
{
- IV value = (IV) (intptr_t) k_integer->value;
+ IV value = (IV) k_integer->integer;
av_store (av, j, newSViv (value));
}
else if (f->contents.list[j]->text.end > 0)
diff --git a/tp/Texinfo/XS/main/builtin_commands.c
b/tp/Texinfo/XS/main/builtin_commands.c
index fa6556df6b..5661c25530 100644
--- a/tp/Texinfo/XS/main/builtin_commands.c
+++ b/tp/Texinfo/XS/main/builtin_commands.c
@@ -72,8 +72,8 @@ element_command_name (const ELEMENT *e)
{
KEY_PAIR *k_cmdname;
k_cmdname = lookup_info (e, "command_name");
- if (k_cmdname && k_cmdname->value)
- return (char *)k_cmdname->value;
+ if (k_cmdname && k_cmdname->string)
+ return k_cmdname->string;
}
return 0;
diff --git a/tp/Texinfo/XS/main/convert_to_texinfo.c
b/tp/Texinfo/XS/main/convert_to_texinfo.c
index fd0b6ff43b..e2419e8a23 100644
--- a/tp/Texinfo/XS/main/convert_to_texinfo.c
+++ b/tp/Texinfo/XS/main/convert_to_texinfo.c
@@ -67,7 +67,7 @@ expand_cmd_args_to_texi (const ELEMENT *e, TEXT *result)
if (spc_before_arg)
ADD((char *)spc_before_arg->text.text);
- s = (char *)arg_line->value;
+ s = arg_line->string;
if (s)
{
ADD(s);
@@ -86,7 +86,7 @@ expand_cmd_args_to_texi (const ELEMENT *e, TEXT *result)
if (cmd == CM_verb)
{
KEY_PAIR *k_delimiter = lookup_info (e, "delimiter");
- ADD((char *)k_delimiter->value);
+ ADD(k_delimiter->string);
}
if (spc_before_arg)
@@ -121,7 +121,7 @@ expand_cmd_args_to_texi (const ELEMENT *e, TEXT *result)
if (cmd == CM_verb)
{
KEY_PAIR *k_delimiter = lookup_info (e, "delimiter");
- ADD((char *)k_delimiter->value);
+ ADD(k_delimiter->string);
}
if (braces)
@@ -263,10 +263,9 @@ check_node_same_texinfo_code (const ELEMENT
*reference_node,
char *reference_node_texi;
char *node_texi;
int equal_texi;
- const KEY_PAIR *k_normalized
- = lookup_extra (reference_node, "normalized");
+ const char *normalized = lookup_extra_string (reference_node, "normalized");
- if (k_normalized && k_normalized->value)
+ if (normalized)
{
char *tmp_texi;
const ELEMENT *label_element = get_label_element (reference_node);
diff --git a/tp/Texinfo/XS/main/debug.c b/tp/Texinfo/XS/main/debug.c
index 18cc98fcb7..31ab8dc362 100644
--- a/tp/Texinfo/XS/main/debug.c
+++ b/tp/Texinfo/XS/main/debug.c
@@ -136,8 +136,8 @@ char *print_associate_info_debug (const ASSOCIATED_INFO
*info)
for (i = 0; i < info->info_number; i++)
{
- char *key = info->info[i].key;
- const ELEMENT *f = (ELEMENT *) info->info[i].value;
+ KEY_PAIR *k = &info->info[i];
+ char *key = k->key;
text_printf (&text, " %s|", key);
switch (info->info[i].type)
{
@@ -145,30 +145,31 @@ char *print_associate_info_debug (const ASSOCIATED_INFO
*info)
text_printf (&text, "deleted");
break;
case extra_integer:
- text_printf (&text, "integer: %d", (intptr_t)f);
+ text_printf (&text, "integer: %d", (int)k->integer);
break;
case extra_string:
- text_printf (&text, "string: %s", (char *) f);
+ text_printf (&text, "string: %s", k->string);
break;
case extra_element:
case extra_element_oot:
{
- char *element_str = print_element_debug (f, 0);
- if (info->info[i].type == extra_element_oot)
+ char *element_str = print_element_debug (k->element, 0);
+ if (k->type == extra_element_oot)
text_append (&text, "oot ");
- text_printf (&text, "element %p: %s", f, element_str);
+ text_printf (&text, "element %p: %s", k->element, element_str);
free (element_str);
break;
}
case extra_misc_args:
{
int j;
+ ELEMENT *f = k->element;
text_append (&text, "array: ");
for (j = 0; j < f->contents.number; j++)
{
KEY_PAIR *k_integer = lookup_extra (f->contents.list[j],
"integer");
if (k_integer)
- text_printf (&text, "%d|", (intptr_t) k_integer->value);
+ text_printf (&text, "%d|", (int)k_integer->integer);
else
text_printf (&text, "%s|", f->contents.list[j]->text.text);
}
@@ -178,6 +179,7 @@ char *print_associate_info_debug (const ASSOCIATED_INFO
*info)
case extra_container:
{
int j;
+ ELEMENT *f = k->element;
text_append (&text, "contents: ");
for (j = 0; j < f->contents.number; j++)
{
diff --git a/tp/Texinfo/XS/main/extra.c b/tp/Texinfo/XS/main/extra.c
index 5c7621a4ce..b850e096da 100644
--- a/tp/Texinfo/XS/main/extra.c
+++ b/tp/Texinfo/XS/main/extra.c
@@ -27,9 +27,8 @@
#include "extra.h"
/* directly used in tree copy, but should not be directly used in general */
-void
-add_associated_info_key (ASSOCIATED_INFO *a, char *key, intptr_t value,
- enum extra_type type)
+KEY_PAIR *
+get_associated_info_key (ASSOCIATED_INFO *a, char *key, enum extra_type type)
{
int i;
for (i = 0; i < a->info_number; i++)
@@ -50,8 +49,9 @@ add_associated_info_key (ASSOCIATED_INFO *a, char *key,
intptr_t value,
}
a->info[i].key = key;
- a->info[i].value = value;
a->info[i].type = type;
+
+ return &a->info[i];
}
/* Add an extra key that is a reference to another element (for example,
@@ -59,8 +59,9 @@ add_associated_info_key (ASSOCIATED_INFO *a, char *key,
intptr_t value,
void
add_extra_element (ELEMENT *e, char *key, ELEMENT *value)
{
- add_associated_info_key (&e->extra_info, key,
- (intptr_t) value, extra_element);
+ KEY_PAIR *k = get_associated_info_key (&e->extra_info, key,
+ extra_element);
+ k->element = value;
}
/* Add an extra key that is a reference to another element that is
@@ -70,8 +71,9 @@ add_extra_element (ELEMENT *e, char *key, ELEMENT *value)
void
add_extra_element_oot (ELEMENT *e, char *key, ELEMENT *value)
{
- add_associated_info_key (&e->extra_info,
- key, (intptr_t) value, extra_element_oot);
+ KEY_PAIR *k = get_associated_info_key (&e->extra_info, key,
+ extra_element_oot);
+ k->element = value;
}
/* Add an extra key that is a reference to elements elsewhere in the tree,
@@ -83,15 +85,17 @@ add_extra_element_oot (ELEMENT *e, char *key, ELEMENT
*value)
void
add_extra_container (ELEMENT *e, char *key, ELEMENT *value)
{
- add_associated_info_key (&e->extra_info,
- key, (intptr_t) value, extra_container);
+ KEY_PAIR *k = get_associated_info_key (&e->extra_info, key,
+ extra_container);
+ k->element = value;
}
void
add_info_element_oot (ELEMENT *e, char *key, ELEMENT *value)
{
- add_associated_info_key (&e->info_info,
- key, (intptr_t) value, extra_element_oot);
+ KEY_PAIR *k = get_associated_info_key (&e->info_info, key,
+ extra_element_oot);
+ k->element = value;
}
/* Add an extra key that is a reference to an array of other
@@ -99,8 +103,9 @@ add_info_element_oot (ELEMENT *e, char *key, ELEMENT *value)
void
add_extra_contents (ELEMENT *e, char *key, ELEMENT *value)
{
- add_associated_info_key (&e->extra_info,
- key, (intptr_t) value, extra_contents);
+ KEY_PAIR *k = get_associated_info_key (&e->extra_info, key,
+ extra_contents);
+ k->element = value;
}
/* similar to extra_contents, but holds 3 elements corresponding to
@@ -114,61 +119,52 @@ void
add_extra_directions (ELEMENT *e, char *key, ELEMENT *value)
{
element_set_empty_contents (value, directions_length);
- add_associated_info_key (&e->extra_info,
- key, (intptr_t) value, extra_directions);
-}
-
-/* Add an extra key that is a reference to the text field of another
- element. */
-/*
- Unused in 2023.
-*/
-void
-add_extra_text (ELEMENT *e, char *key, ELEMENT *value)
-{
- add_associated_info_key (&e->extra_info, key, (intptr_t) value, extra_text);
+ KEY_PAIR *k = get_associated_info_key (&e->extra_info, key,
+ extra_directions);
+ k->element = value;
}
void
add_extra_misc_args (ELEMENT *e, char *key, ELEMENT *value)
{
if (!value) return;
- add_associated_info_key (&e->extra_info,
- key, (intptr_t) value, extra_misc_args);
+ KEY_PAIR *k = get_associated_info_key (&e->extra_info, key, extra_misc_args);
+ k->element = value;
}
void
add_extra_string (ELEMENT *e, char *key, char *value)
{
- add_associated_info_key (&e->extra_info, key,
- (intptr_t) value, extra_string);
+ KEY_PAIR *k = get_associated_info_key (&e->extra_info, key, extra_string);
+ k->string = value;
}
void
add_info_string (ELEMENT *e, char *key, char *value)
{
- add_associated_info_key (&e->info_info, key, (intptr_t) value, extra_string);
+ KEY_PAIR *k = get_associated_info_key (&e->info_info, key, extra_string);
+ k->string = value;
}
void
add_extra_string_dup (ELEMENT *e, char *key, char *value)
{
- add_associated_info_key (&e->extra_info,
- key, (intptr_t) strdup (value), extra_string);
+ KEY_PAIR *k = get_associated_info_key (&e->extra_info, key, extra_string);
+ k->string = strdup (value);
}
void
add_info_string_dup (ELEMENT *e, char *key, char *value)
{
- add_associated_info_key (&e->info_info,
- key, (intptr_t) strdup (value), extra_string);
+ KEY_PAIR *k = get_associated_info_key (&e->info_info, key, extra_string);
+ k->string = strdup (value);
}
void
add_extra_integer (ELEMENT *e, char *key, long value)
{
- add_associated_info_key (&e->extra_info,
- key, (intptr_t) value, extra_integer);
+ KEY_PAIR *k = get_associated_info_key (&e->extra_info, key, extra_integer);
+ k->integer = value;
}
KEY_PAIR *
@@ -193,7 +189,7 @@ lookup_extra_element (const ELEMENT *e, char *key)
k = lookup_associated_info (&e->extra_info, key);
if (!k)
return 0;
- return (ELEMENT *) k->value;
+ return k->element;
}
char *
@@ -201,9 +197,9 @@ lookup_extra_string (const ELEMENT *e, char *key)
{
const KEY_PAIR *k;
k = lookup_associated_info (&e->extra_info, key);
- if (!k || !k->value)
+ if (!k || !k->string)
return 0;
- return (char *) k->value;
+ return k->string;
}
KEY_PAIR *
@@ -229,7 +225,7 @@ lookup_extra_integer (const ELEMENT *e, char *key, int *ret)
return 0;
}
*ret = 0;
- return (int)k->value;
+ return (int)k->integer;
}
/* if CREATE is true, create an extra contents element if there is none */
@@ -267,7 +263,7 @@ lookup_info_element (const ELEMENT *e, char *key)
k = lookup_associated_info (&e->info_info, key);
if (!k)
return 0;
- return (ELEMENT *) k->value;
+ return k->element;
}
diff --git a/tp/Texinfo/XS/main/extra.h b/tp/Texinfo/XS/main/extra.h
index ec46cd40d4..9ed63e14e9 100644
--- a/tp/Texinfo/XS/main/extra.h
+++ b/tp/Texinfo/XS/main/extra.h
@@ -45,7 +45,7 @@ KEY_PAIR *lookup_associated_info (const ASSOCIATED_INFO *a,
char *key);
/* not to be used in general, only when using associated info
as a temporary holder of information, for speed */
-void add_associated_info_key (ASSOCIATED_INFO *a, char *key, intptr_t value,
- enum extra_type type);
+KEY_PAIR *get_associated_info_key (ASSOCIATED_INFO *a, char *key,
+ enum extra_type type);
KEY_PAIR *lookup_extra_by_index (const ELEMENT *e, char *key, int index);
#endif
diff --git a/tp/Texinfo/XS/main/manipulate_tree.c
b/tp/Texinfo/XS/main/manipulate_tree.c
index 27f7bd88f7..f762ca3a87 100644
--- a/tp/Texinfo/XS/main/manipulate_tree.c
+++ b/tp/Texinfo/XS/main/manipulate_tree.c
@@ -45,7 +45,7 @@ increase_ref_counter (ELEMENT *element)
if (!k_counter)
add_extra_integer (element, "_counter", 0);
k_counter = lookup_extra_by_index (element, "_counter", -1);
- counter_ptr = (intptr_t *) &k_counter->value;
+ counter_ptr = (intptr_t *) &k_counter->integer;
(*counter_ptr) ++;
}
@@ -56,16 +56,17 @@ copy_associated_info (ASSOCIATED_INFO *info,
ASSOCIATED_INFO* new_info)
for (i = 0; i < info->info_number; i++)
{
- char *key = info->info[i].key;
- ELEMENT *f = (ELEMENT *) info->info[i].value;
+ KEY_PAIR *k_ref = &info->info[i];
+ char *key = k_ref->key;
+ ELEMENT *f = k_ref->element;
ELEMENT *new_extra_contents;
KEY_PAIR *k_copy = 0;
int j;
- if (info->info[i].type == extra_deleted)
+ if (k_ref->type == extra_deleted)
continue;
- switch (info->info[i].type)
+ switch (k_ref->type)
{
case extra_element:
case extra_element_oot:
@@ -73,8 +74,11 @@ copy_associated_info (ASSOCIATED_INFO *info,
ASSOCIATED_INFO* new_info)
break;
k_copy = lookup_extra_by_index (f, "_copy", -1);
if (k_copy)
- add_associated_info_key (new_info, key, (intptr_t)k_copy->value,
- info->info[i].type);
+ {
+ KEY_PAIR *k
+ = get_associated_info_key (new_info, key, k_ref->type);
+ k->element = k_copy->element;
+ }
else
{
increase_ref_counter (f);
@@ -84,9 +88,9 @@ copy_associated_info (ASSOCIATED_INFO *info, ASSOCIATED_INFO*
new_info)
case extra_contents:
case extra_directions:
case extra_container:
+ KEY_PAIR *k = get_associated_info_key (new_info, key, k_ref->type);
new_extra_contents = new_element (ET_NONE);
- add_associated_info_key (new_info, key, (intptr_t)new_extra_contents,
- info->info[i].type);
+ k->element = new_extra_contents;
for (j = 0; j < f->contents.number; j++)
{
ELEMENT *e = f->contents.list[j];
@@ -99,7 +103,7 @@ copy_associated_info (ASSOCIATED_INFO *info,
ASSOCIATED_INFO* new_info)
k_copy = lookup_extra_by_index (e, "_copy", -1);
if (k_copy)
add_to_contents_as_array (new_extra_contents,
- (ELEMENT *)k_copy->value);
+ k_copy->element);
else
{
increase_ref_counter (e);
@@ -124,7 +128,7 @@ copy_tree_internal (ELEMENT* current, ELEMENT *parent)
k_copy = lookup_extra_by_index (current, "_copy", -1);
if (k_copy)
{
- new = (ELEMENT *)k_copy->value;
+ new = k_copy->element;
if (parent && !new->parent)
new->parent = parent;
return new;
@@ -165,10 +169,10 @@ get_copy_ref (ELEMENT *element)
ELEMENT *result;
k_copy = lookup_extra_by_index (element, "_copy", -1);
- result = (ELEMENT *)k_copy->value;
+ result = k_copy->element;
k_counter = lookup_extra_by_index (element, "_counter", -2);
- counter_ptr = (intptr_t *) &k_counter->value;
+ counter_ptr = (intptr_t *) &k_counter->integer;
(*counter_ptr) --;
if (*counter_ptr == 0)
@@ -189,15 +193,16 @@ associate_info_references (ASSOCIATED_INFO *info,
ASSOCIATED_INFO *new_info)
for (i = 0; i < info->info_number; i++)
{
- char *key = info->info[i].key;
- ELEMENT *f = (ELEMENT *) info->info[i].value;
+ KEY_PAIR *k_ref = &info->info[i];
+ char *key = k_ref->key;
+ ELEMENT *f = k_ref->element;
ELEMENT *new_extra_contents;
int j;
- if (info->info[i].type == extra_deleted)
+ if (k_ref->type == extra_deleted)
continue;
- switch (info->info[i].type)
+ switch (k_ref->type)
{
case extra_element:
case extra_element_oot:
@@ -210,12 +215,13 @@ associate_info_references (ASSOCIATED_INFO *info,
ASSOCIATED_INFO *new_info)
if (!k)
{
ELEMENT *e = get_copy_ref (f);
- add_associated_info_key (new_info, key, (intptr_t)e,
- info->info[i].type);
+ k = get_associated_info_key (new_info, key,
+ info->info[i].type);
+ k->element = e;
}
k_copy = lookup_extra_by_index (f, "_copy", -1);
if (k_copy)
- copy_extra_info (f, (ELEMENT *) k_copy->value);
+ copy_extra_info (f, k_copy->element);
break;
}
case extra_contents:
@@ -223,7 +229,7 @@ associate_info_references (ASSOCIATED_INFO *info,
ASSOCIATED_INFO *new_info)
case extra_directions:
{
KEY_PAIR *k = lookup_associated_info (new_info, key);
- new_extra_contents = (ELEMENT *)k->value;
+ new_extra_contents = k->element;
for (j = 0; j < f->contents.number; j++)
{
KEY_PAIR *k_copy;
@@ -242,39 +248,39 @@ associate_info_references (ASSOCIATED_INFO *info,
ASSOCIATED_INFO *new_info)
k_copy = lookup_extra_by_index (e, "_copy", -1);
if (k_copy)
- copy_extra_info (e, (ELEMENT *) k_copy->value);
+ copy_extra_info (e, k_copy->element);
}
}
break;
}
case extra_string:
{ /* A simple string. */
- char *value = (char *) f;
- add_associated_info_key (new_info, key, (intptr_t) strdup (value),
- info->info[i].type);
+ char *value = k_ref->string;
+ KEY_PAIR *k = get_associated_info_key (new_info, key, k_ref->type);
+ k->string = strdup (value);
break;
}
case extra_integer:
if (!strcmp(key, "_counter"))
break;
{ /* A simple integer. */
- add_associated_info_key (new_info, key, (intptr_t)f,
- info->info[i].type);
+ KEY_PAIR *k = get_associated_info_key (new_info, key, k_ref->type);
+ k->integer = k_ref->integer;
break;
}
case extra_misc_args:
{
int j;
new_extra_contents = new_element (ET_NONE);
- add_associated_info_key (new_info, key, (intptr_t)new_extra_contents,
- info->info[i].type);
+ KEY_PAIR *k = get_associated_info_key (new_info, key, k_ref->type);
+ k->element = new_extra_contents;
for (j = 0; j < f->contents.number; j++)
{
ELEMENT *e = new_element (ET_NONE);
KEY_PAIR *k_integer = lookup_extra (f->contents.list[j],
"integer");
if (k_integer)
{
- add_extra_integer (e, "integer", (intptr_t)
k_integer->value);
+ add_extra_integer (e, "integer", k_integer->integer);
}
else
{
diff --git a/tp/Texinfo/XS/main/node_name_normalization.c
b/tp/Texinfo/XS/main/node_name_normalization.c
index 5108a909f7..341d31f2de 100644
--- a/tp/Texinfo/XS/main/node_name_normalization.c
+++ b/tp/Texinfo/XS/main/node_name_normalization.c
@@ -85,10 +85,9 @@ convert_to_normalized_internal (const ELEMENT *e, TEXT
*result)
else if (e->cmd == CM_click)
{
enum command_id cmd;
- KEY_PAIR *k_clickstyle = lookup_extra (e, "clickstyle");
- if (k_clickstyle && k_clickstyle->value)
+ char *command_name = lookup_extra_string (e, "clickstyle");
+ if (command_name)
{
- char *command_name = (char *) k_clickstyle->value;
cmd = lookup_builtin_command (command_name);
if (command_normalization_text[cmd])
ADD(command_normalization_text[cmd]);
diff --git a/tp/Texinfo/XS/main/targets.c b/tp/Texinfo/XS/main/targets.c
index 341b69e9e0..3d3ccfa584 100644
--- a/tp/Texinfo/XS/main/targets.c
+++ b/tp/Texinfo/XS/main/targets.c
@@ -212,12 +212,10 @@ char *
add_element_to_identifiers_target (DOCUMENT *document, ELEMENT *element,
int *status)
{
- KEY_PAIR *k_normalized = lookup_extra (element, "normalized");
- char *normalized = 0;
+ char *normalized = lookup_extra_string (element, "normalized");
*status = 2;
- if (k_normalized && k_normalized->value)
+ if (normalized)
{
- normalized = (char *)k_normalized->value;
LABEL_LIST *identifiers_target = document->identifiers_target;
ELEMENT *target = find_identifier_target (identifiers_target,
normalized);
diff --git a/tp/Texinfo/XS/main/tree.c b/tp/Texinfo/XS/main/tree.c
index 1f115e5def..cb1468fabe 100644
--- a/tp/Texinfo/XS/main/tree.c
+++ b/tp/Texinfo/XS/main/tree.c
@@ -142,19 +142,19 @@ destroy_associated_info (ASSOCIATED_INFO *a)
switch (a->info[i].type)
{
case extra_string:
- free ((char *) a->info[i].value);
+ free (a->info[i].string);
break;
case extra_element_oot:
- destroy_element_and_children ((ELEMENT *) a->info[i].value);
+ destroy_element_and_children (a->info[i].element);
break;
case extra_contents:
case extra_container:
case extra_directions:
- if (a->info[i].value)
- destroy_element ((ELEMENT *) a->info[i].value);
+ if (a->info[i].element)
+ destroy_element (a->info[i].element);
break;
case extra_misc_args:
- destroy_element_and_children ((ELEMENT *) a->info[i].value);
+ destroy_element_and_children (a->info[i].element);
break;
default:
diff --git a/tp/Texinfo/XS/main/tree_types.h b/tp/Texinfo/XS/main/tree_types.h
index 7dd718c126..3bc6573d0b 100644
--- a/tp/Texinfo/XS/main/tree_types.h
+++ b/tp/Texinfo/XS/main/tree_types.h
@@ -116,7 +116,11 @@ extern char *relative_unit_direction_name[];
typedef struct KEY_PAIR {
char *key;
enum extra_type type;
- intptr_t value;
+ union {
+ struct ELEMENT *element;
+ char *string;
+ long integer;
+ };
} KEY_PAIR;
typedef struct ELEMENT_LIST {
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 0376ed1ae1..27960f015d 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -1126,7 +1126,7 @@ section_level (const ELEMENT *section)
KEY_PAIR *k_level_modifier = lookup_extra (section, "level_modifier");
if (k_level_modifier && level >= 0)
{
- int section_modifier = (intptr_t) k_level_modifier->value;
+ int section_modifier = (int) k_level_modifier->integer;
level -= section_modifier;
if (level < min_level)
if (command_structuring_level[section->cmd] < min_level)
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index 83fd160e28..5667780564 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -68,7 +68,7 @@ close_brace_command (ELEMENT *current,
if (current->cmd != CM_verb)
goto yes;
k_delimiter = lookup_info (current, "delimiter");
- if (!k_delimiter || !*(char *)k_delimiter->value)
+ if (!k_delimiter || !*k_delimiter->string)
goto yes;
if (0)
{
@@ -93,7 +93,7 @@ close_brace_command (ELEMENT *current,
command_error (current,
"@%s missing closing delimiter sequence: %s}",
command_name(current->cmd),
- (char *)k_delimiter->value);
+ k_delimiter->string);
}
current = current->parent;
return current;
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c
b/tp/Texinfo/XS/parsetexi/end_line.c
index 6e86bd4270..380355a058 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -640,7 +640,7 @@ end_line_def_line (ELEMENT *current)
{
enum command_id def_command;
DEF_ARG **def_info = 0;
- KEY_PAIR *k_pair;
+ char *def_cmdname;
ELEMENT *index_entry = 0; /* Index entry text. */
ELEMENT *def_info_name = 0;
ELEMENT *def_info_class = 0;
@@ -651,8 +651,8 @@ end_line_def_line (ELEMENT *current)
if (top_context != ct_def)
fatal ("def context expected");
- k_pair = lookup_extra (current->parent, "def_command");
- def_command = lookup_command ((char *) k_pair->value);
+ def_cmdname = lookup_extra_string (current->parent, "def_command");
+ def_command = lookup_command (def_cmdname);
debug_nonl ("END DEF LINE %s; current ",
command_name(def_command));
@@ -724,14 +724,14 @@ end_line_def_line (ELEMENT *current)
}
else
{
- k_pair = lookup_extra (current, "original_def_cmdname");
- command_warn (current, "missing name for @%s", (char *)
k_pair->value);
+ def_cmdname = lookup_extra_string (current, "original_def_cmdname");
+ command_warn (current, "missing name for @%s", def_cmdname);
}
}
else
{
- k_pair = lookup_extra (current, "original_def_cmdname");
- command_warn (current, "missing category for @%s", (char *)
k_pair->value);
+ def_cmdname = lookup_extra_string (current, "original_def_cmdname");
+ command_warn (current, "missing category for @%s", def_cmdname);
}
@@ -772,7 +772,7 @@ end_line_starting_block (ELEMENT *current)
if (command == CM_multitable
&& (k = lookup_extra (current->parent, "columnfractions")))
{
- ELEMENT *misc_cmd = (ELEMENT *) k->value;
+ ELEMENT *misc_cmd = k->element;
ELEMENT *misc_args;
if ((misc_args = lookup_extra_element (misc_cmd, "misc_args")))
@@ -908,7 +908,7 @@ end_line_starting_block (ELEMENT *current)
}
else
{
- ELEMENT *e = (ELEMENT *) k_command_as_argument->value;
+ ELEMENT *e = k_command_as_argument->element;
if (!(command_flags(e) & CF_brace)
|| (command_data(e->cmd).data == BRACE_noarg))
{
@@ -937,7 +937,7 @@ end_line_starting_block (ELEMENT *current)
for (i = 0; i < e->contents.number; i++)
{
if (contents_child_by_index (e, i)
- == (ELEMENT *) k_command_as_argument->value)
+ == k_command_as_argument->element)
{
i++;
break;
@@ -952,7 +952,7 @@ end_line_starting_block (ELEMENT *current)
&& !*(f->text.text
+ strspn (f->text.text, whitespace_chars))))
{
- ((ELEMENT *) k_command_as_argument->value)->type =
ET_NONE;
+ k_command_as_argument->element->type = ET_NONE;
k_command_as_argument->key = "";
k_command_as_argument->type = extra_deleted;
break;
@@ -963,9 +963,9 @@ end_line_starting_block (ELEMENT *current)
/* Check if command_as_argument isn't an accent command */
k = lookup_extra (current, "command_as_argument");
- if (k && k->value)
+ if (k && k->element)
{
- enum command_id as_argument_cmd = ((ELEMENT *) k->value)->cmd;
+ enum command_id as_argument_cmd = k->element->cmd;
if (as_argument_cmd
&& (command_data(as_argument_cmd).flags & CF_accent))
{
@@ -974,7 +974,7 @@ end_line_starting_block (ELEMENT *current)
command_name(as_argument_cmd),
command_name(command));
k->key = "";
- k->value = 0;
+ k->element = 0;
k->type = extra_deleted;
}
}
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.c
b/tp/Texinfo/XS/parsetexi/handle_commands.c
index 40c83ba8d8..89b6b0f225 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.c
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.c
@@ -421,7 +421,7 @@ handle_other_command (ELEMENT *current, char **line_inout,
k_max_columns = lookup_extra (parent, "max_columns");
if (k_max_columns)
- max_columns = (long) k_max_columns->value;
+ max_columns = k_max_columns->integer;
if (max_columns == 0)
{
@@ -798,9 +798,11 @@ handle_line_command (ELEMENT *current, char **line_inout,
if (parent->cmd == CM_subentry)
{
- KEY_PAIR *k_parent_level = lookup_extra (parent, "level");
- if (k_parent_level && k_parent_level->value)
- level = (long) k_parent_level->value + 1;
+ int status;
+ int parent_level
+ = lookup_extra_integer (parent, "level", &status);
+ if (status >= 0 && parent_level)
+ level = parent_level + 1;
else
fatal ("No subentry parent level or level 0");
}
diff --git a/tp/Texinfo/XS/parsetexi/indices.c
b/tp/Texinfo/XS/parsetexi/indices.c
index c08a4b6cf1..db664887ee 100644
--- a/tp/Texinfo/XS/parsetexi/indices.c
+++ b/tp/Texinfo/XS/parsetexi/indices.c
@@ -397,18 +397,18 @@ complete_indices (int document_descriptor)
{
INDEX_ENTRY *entry;
ELEMENT *main_entry_element;
- KEY_PAIR *k_def_command;
- KEY_PAIR *k_idx_element;
+ ELEMENT *idx_element;
+ char *def_cmdname;
entry = &idx->index_entries[j];
main_entry_element = entry->entry_element;
- k_def_command = lookup_extra (main_entry_element, "def_command");
+ def_cmdname = lookup_extra_string (main_entry_element,
+ "def_command");
- k_idx_element = lookup_extra (main_entry_element,
- "def_index_element");
- if (k_def_command && k_def_command->value
- && !(k_idx_element && k_idx_element->value))
+ idx_element = lookup_extra_element (main_entry_element,
+ "def_index_element");
+ if (def_cmdname && !idx_element)
{
ELEMENT *name = 0;
ELEMENT *class = 0;
@@ -419,8 +419,7 @@ complete_indices (int document_descriptor)
for (ic = 0; ic < def_l_e->contents.number; ic++)
{
ELEMENT *arg = def_l_e->contents.list[ic];
- KEY_PAIR *k_role = lookup_extra (arg, "def_role");
- char *role = (char *) k_role->value;
+ char *role = lookup_extra_string (arg, "def_role");
if (!strcmp (role, "name"))
name = arg;
else if (!strcmp (role, "class"))
@@ -438,14 +437,13 @@ complete_indices (int document_descriptor)
*/
if (name && class)
{
- char *lang = 0;
+ char *lang = lookup_extra_string (main_entry_element,
+ "documentlanguage");
ELEMENT *index_entry;
ELEMENT *index_entry_normalized = new_element (ET_NONE);
ELEMENT *text_element = new_element (ET_NONE);
enum command_id def_command
- = lookup_command ((char *) k_def_command->value);
- KEY_PAIR *k_lang = lookup_extra (main_entry_element,
- "documentlanguage");
+ = lookup_command (def_cmdname);
NAMED_STRING_ELEMENT_LIST *substrings
= new_named_string_element_list ();
ELEMENT *name_copy = copy_tree (name);
@@ -457,10 +455,6 @@ complete_indices (int document_descriptor)
"name", name_copy);
add_element_to_named_string_element_list (substrings,
"class",
class_copy);
- if (k_lang && k_lang->value)
- {
- lang = (char *) k_lang->value;
- }
if (def_command == CM_defop
|| def_command == CM_deftypeop
|| def_command == CM_defmethod
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index b1d06132fb..7fd73c1257 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -638,7 +638,7 @@ expand_linemacro_arguments (ELEMENT *macro, char
**line_inout,
= lookup_extra (argument_content, "toplevel_braces_nr");
if (k_toplevel_braces_nr)
{
- if ((intptr_t) k_toplevel_braces_nr->value == 1)
+ if (k_toplevel_braces_nr->integer == 1)
{
int text_len = strlen(argument_content->text.text);
if (argument_content->text.text[0] == '{'
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index a652698d2b..02256872ee 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1605,7 +1605,7 @@ process_remaining_on_line (ELEMENT **current_inout, char
**line_inout)
char *q;
KEY_PAIR *k_delimiter = lookup_info (current->parent, "delimiter");
- char *delimiter = (char *)k_delimiter->value;
+ char *delimiter = k_delimiter->string;
if (strcmp (delimiter, ""))
{
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.c
b/tp/Texinfo/XS/structuring_transfo/transformations.c
index 60da42170b..5ba7913cdf 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.c
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.c
@@ -51,10 +51,11 @@ INDEX_ENTRY_AND_INDEX *
lookup_index_entry (ELEMENT *index_entry_info, INDEX **indices_information)
{
INDEX_ENTRY_AND_INDEX *result = 0;
- KEY_PAIR *k_integer
- = lookup_extra (index_entry_info->contents.list[1], "integer");
+ int status;
+ int entry_number
+ = lookup_extra_integer (index_entry_info->contents.list[1], "integer",
+ &status);
char *entry_index_name = index_entry_info->contents.list[0]->text.text;
- int entry_number = (intptr_t) k_integer->value;
INDEX *index_info;
index_info = indices_info_index_by_name (indices_information,
@@ -250,11 +251,12 @@ modify_tree (ELEMENT *tree,
void
correct_level (ELEMENT *section, ELEMENT *parent, int modifier)
{
- KEY_PAIR *k_level_modifier = lookup_extra (section, "level_modifier");
- if (k_level_modifier)
+ int status;
+ int section_modifier = lookup_extra_integer (section, "level_modifier",
+ &status);
+ if (status >= 0)
{
int level_to_remove;
- int section_modifier = (intptr_t) k_level_modifier->value;
enum command_id cmd;
int remaining_level;
@@ -1020,10 +1022,9 @@ complete_node_menu (ELEMENT *node, int use_sections)
for (i = 0; i < node_childs->number; i++)
{
ELEMENT *node_entry = node_childs->list[i];
- KEY_PAIR *k_normalized = lookup_extra (node_entry, "normalized");
- if (k_normalized && k_normalized->value)
+ char *normalized = lookup_extra_string (node_entry, "normalized");
+ if (normalized)
{
- char *normalized = (char *)k_normalized->value;
int j;
ELEMENT *entry = 0;