[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sun, 29 Sep 2024 05:38:55 -0400 (EDT) |
branch: master
commit ce68d788ccb5f928e2eb9697b213759ff38dd7de
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Jun 12 23:23:58 2024 +0200
* tp/Texinfo/XS/main/DocumentXS.xs (set_document_global_info),
tp/Texinfo/XS/main/build_perl_info.c (build_global_info),
tp/Texinfo/XS/main/document.c (add_other_global_info_string),
tp/Texinfo/XS/main/document_types.h (KEY_STRING_PAIR)
(OTHER_GLOBAL_INFO, GLOBAL_INFO): do not use ASSOCIATED_INFO for
global_info.other_info, use specific structures and
add_other_global_info_string to add a key, string pair.
* tp/Texinfo/XS/main/extra.c: remove get_associated_info_skey and
add_associated_info_string_dup.
* tp/Makefile.tres, t/test_document.t: add test of Texinfo::Document
set_document_global_info.
---
ChangeLog | 16 +++++++++++++++
tp/Makefile.tres | 1 +
tp/Texinfo/XS/main/DocumentXS.xs | 2 +-
tp/Texinfo/XS/main/build_perl_info.c | 8 ++++++--
tp/Texinfo/XS/main/document.c | 27 +++++++++++++++++++++++++
tp/Texinfo/XS/main/document.h | 4 ++++
tp/Texinfo/XS/main/document_types.h | 13 +++++++++++-
tp/Texinfo/XS/main/extra.c | 38 -----------------------------------
tp/Texinfo/XS/main/extra.h | 4 ----
tp/Texinfo/XS/main/utils.c | 9 ++++++++-
tp/t/test_document.t | 39 ++++++++++++++++++++++++++++++++++++
11 files changed, 114 insertions(+), 47 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 47d8138114..3e95f86931 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,22 @@
* tp/Texinfo/XS/convert/convert_html.c (html_command_description):
use integer key lookup_extra_element.
+2024-06-12 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/DocumentXS.xs (set_document_global_info),
+ tp/Texinfo/XS/main/build_perl_info.c (build_global_info),
+ tp/Texinfo/XS/main/document.c (add_other_global_info_string),
+ tp/Texinfo/XS/main/document_types.h (KEY_STRING_PAIR)
+ (OTHER_GLOBAL_INFO, GLOBAL_INFO): do not use ASSOCIATED_INFO for
+ global_info.other_info, use specific structures and
+ add_other_global_info_string to add a key, string pair.
+
+ * tp/Texinfo/XS/main/extra.c: remove get_associated_info_skey and
+ add_associated_info_string_dup.
+
+ * tp/Makefile.tres, t/test_document.t: add test of Texinfo::Document
+ set_document_global_info.
+
2024-06-12 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/main/build_perl_info.c (build_additional_info),
diff --git a/tp/Makefile.tres b/tp/Makefile.tres
index 42502ba7cb..3d4fe8c96a 100644
--- a/tp/Makefile.tres
+++ b/tp/Makefile.tres
@@ -56,6 +56,7 @@ test_tap_files_generated_list = \
t/reference_to_text_in_tree.t \
t/same_parser_multiple_files.t \
t/test_brace_count.t \
+ t/test_document.t \
t/test_fill_gaps_in_sectioning.t \
t/test_is_content_empty.t \
t/test_parse_texi_line.t \
diff --git a/tp/Texinfo/XS/main/DocumentXS.xs b/tp/Texinfo/XS/main/DocumentXS.xs
index 7bbe14a33c..56fd76985c 100644
--- a/tp/Texinfo/XS/main/DocumentXS.xs
+++ b/tp/Texinfo/XS/main/DocumentXS.xs
@@ -209,7 +209,7 @@ set_document_global_info (SV *document_in, char *key, SV
*value_sv)
}
else
{
- add_associated_info_string_dup (
+ add_other_global_info_string (
&document->global_info.other_info,
key, (char *)SvPVutf8_nolen(value_sv));
}
diff --git a/tp/Texinfo/XS/main/build_perl_info.c
b/tp/Texinfo/XS/main/build_perl_info.c
index a4f6f32644..c7b058e093 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1210,7 +1210,7 @@ build_global_info (const GLOBAL_INFO *global_info_ref,
const GLOBAL_INFO global_info = *global_info_ref;
const GLOBAL_COMMANDS global_commands = *global_commands_ref;
const ELEMENT *document_language;
- int nr_info;
+ int i;
dTHX;
@@ -1235,7 +1235,11 @@ build_global_info (const GLOBAL_INFO *global_info_ref,
newRV_noinc ((SV *) av), 0);
}
- build_additional_info (hv, &global_info.other_info, 0, &nr_info);
+ for (i = 0; i < global_info.other_info.info_number; i++)
+ {
+ const KEY_STRING_PAIR *k = &global_info.other_info.info[i];
+ hv_store (hv, k->key, strlen (k->key), newSVpv_utf8 (k->string, 0), 0);
+ }
/* duplicate information with global_commands to avoid needing to use
global_commands and build tree elements in other codes, for
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index 75e96c21cb..69f1c04f28 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -516,6 +516,33 @@ unregister_document_merge_with_document (int
document_descriptor,
return tree;
}
+void
+add_other_global_info_string (OTHER_GLOBAL_INFO *other_global_info,
+ const char *key, const char *value)
+{
+ int i;
+ for (i = 0; i < other_global_info->info_number; i++)
+ {
+ if (!strcmp (other_global_info->info[i].key, key))
+ break;
+ }
+ if (i == other_global_info->info_number)
+ {
+ if (other_global_info->info_number == other_global_info->info_space)
+ {
+ other_global_info->info = realloc (other_global_info->info,
+ (other_global_info->info_space += 5) * sizeof (KEY_STRING_PAIR));
+ if (!other_global_info->info)
+ fatal ("realloc failed");
+ }
+ other_global_info->info_number++;
+
+ other_global_info->info[i].key = strdup (key);
+ }
+
+ other_global_info->info[i].string = strdup (value);
+}
+
/* does not seems to be used */
void
wipe_document_errors (int document_descriptor)
diff --git a/tp/Texinfo/XS/main/document.h b/tp/Texinfo/XS/main/document.h
index 26af97db18..07ba1b1f95 100644
--- a/tp/Texinfo/XS/main/document.h
+++ b/tp/Texinfo/XS/main/document.h
@@ -44,6 +44,10 @@ COLLATION_INDICES_SORTED_BY_LETTER *sorted_indices_by_letter
(
void remove_document_descriptor (int document_descriptor);
ELEMENT *unregister_document_merge_with_document (int document_descriptor,
DOCUMENT *document);
+
+void add_other_global_info_string (OTHER_GLOBAL_INFO *other_global_info,
+ const char *key, const char *value);
+
void wipe_document_parser_errors (int document_descriptor);
void wipe_document_errors (int document_descriptor);
diff --git a/tp/Texinfo/XS/main/document_types.h
b/tp/Texinfo/XS/main/document_types.h
index d779b8d1b3..cefaf4734e 100644
--- a/tp/Texinfo/XS/main/document_types.h
+++ b/tp/Texinfo/XS/main/document_types.h
@@ -62,6 +62,17 @@ typedef struct ERROR_MESSAGE_LIST {
size_t space;
} ERROR_MESSAGE_LIST;
+typedef struct KEY_STRING_PAIR {
+ char *key;
+ char *string;
+} KEY_STRING_PAIR;
+
+typedef struct OTHER_GLOBAL_INFO {
+ KEY_STRING_PAIR *info;
+ size_t info_number;
+ size_t info_space;
+} OTHER_GLOBAL_INFO;
+
typedef struct GLOBAL_INFO {
char *input_file_name;
char *input_directory;
@@ -72,7 +83,7 @@ typedef struct GLOBAL_INFO {
STRING_LIST included_files;
/* remaining, in general passed to/from perl but not used in C */
- ASSOCIATED_INFO other_info;
+ OTHER_GLOBAL_INFO other_info;
/* perl specific */
char *input_perl_encoding;
diff --git a/tp/Texinfo/XS/main/extra.c b/tp/Texinfo/XS/main/extra.c
index 8afe2c493e..4a12cb005e 100644
--- a/tp/Texinfo/XS/main/extra.c
+++ b/tp/Texinfo/XS/main/extra.c
@@ -26,36 +26,6 @@
#include "debug.h"
#include "extra.h"
-/* directly used in tree copy, but should not be directly used in general */
-KEY_PAIR *
-get_associated_info_skey (ASSOCIATED_INFO *a, const char *key,
- const enum extra_type type)
-{
- int i;
- for (i = 0; i < a->info_number; i++)
- {
- if (a->info[i].skey && !strcmp (a->info[i].skey, key))
- break;
- }
- if (i == a->info_number)
- {
- if (a->info_number == a->info_space)
- {
- a->info = realloc (a->info,
- (a->info_space += 5) * sizeof (KEY_PAIR));
- if (!a->info)
- fatal ("realloc failed");
- }
- a->info_number++;
- }
-
- a->info[i].skey = key;
- a->info[i].key = AI_key_none;
- a->info[i].type = type;
-
- return &a->info[i];
-}
-
KEY_PAIR *
get_associated_info_key (ASSOCIATED_INFO *a, enum ai_key_name key,
const enum extra_type type)
@@ -203,14 +173,6 @@ add_extra_string_dup (ELEMENT *e, enum ai_key_name key,
const char *value)
k->k.string = strdup (value);
}
-void
-add_associated_info_string_dup (ASSOCIATED_INFO *a, const char *key,
- const char *value)
-{
- KEY_PAIR *k = get_associated_info_skey (a, key, extra_string);
- k->k.string = strdup (value);
-}
-
void
add_extra_integer (ELEMENT *e, enum ai_key_name key, int value)
{
diff --git a/tp/Texinfo/XS/main/extra.h b/tp/Texinfo/XS/main/extra.h
index 4a0dcde118..e1fadcbf40 100644
--- a/tp/Texinfo/XS/main/extra.h
+++ b/tp/Texinfo/XS/main/extra.h
@@ -31,8 +31,6 @@ void add_extra_index_entry (ELEMENT *e, enum ai_key_name key,
void add_extra_string (ELEMENT *e, enum ai_key_name key, char *value);
void add_extra_string_dup (ELEMENT *e, enum ai_key_name key, const char
*value);
void add_extra_integer (ELEMENT *e, enum ai_key_name key, int value);
-void add_associated_info_string_dup (ASSOCIATED_INFO *a, const char *key,
- const char *value);
KEY_PAIR *lookup_extra (const ELEMENT *e, enum ai_key_name key);
ELEMENT *lookup_extra_element (const ELEMENT *e, enum ai_key_name key);
ELEMENT_LIST *lookup_extra_contents (const ELEMENT *e, enum ai_key_name key);
@@ -52,8 +50,6 @@ KEY_PAIR *lookup_associated_info (const ASSOCIATED_INFO *a,
as a temporary holder of information, for speed */
KEY_PAIR *get_associated_info_key (ASSOCIATED_INFO *a, enum ai_key_name key,
const enum extra_type type);
-KEY_PAIR *get_associated_info_skey (ASSOCIATED_INFO *a, const char *key,
- const enum extra_type type);
KEY_PAIR *lookup_extra_by_index (const ELEMENT *e, enum ai_key_name key,
int index);
#endif
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index b42ae6b063..e1811d5546 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -1077,13 +1077,20 @@ wipe_values (VALUE_LIST *values)
void
delete_global_info (GLOBAL_INFO *global_info)
{
+ int i;
free_strings_list (&global_info->included_files);
free (global_info->input_encoding_name);
free (global_info->input_file_name);
free (global_info->input_directory);
- destroy_associated_info (&global_info->other_info);
+ for (i = 0; i < global_info->other_info.info_number; i++)
+ {
+ const KEY_STRING_PAIR *k = &global_info->other_info.info[i];
+ free (k->key);
+ free (k->string);
+ }
+ free (global_info->other_info.info);
/* perl specific information */
free (global_info->input_perl_encoding);
diff --git a/tp/t/test_document.t b/tp/t/test_document.t
new file mode 100644
index 0000000000..a2e9f146c8
--- /dev/null
+++ b/tp/t/test_document.t
@@ -0,0 +1,39 @@
+use strict;
+
+use lib '.';
+use Texinfo::ModulePath (undef, undef, undef, 'updirs' => 2);
+
+use Test::More;
+
+BEGIN { plan tests => 4; }
+
+use Texinfo::Parser;
+use Texinfo::Document;
+
+# For consistent error messages, use the C locale
+$ENV{LC_ALL} = 'C';
+$ENV{LANGUAGE} = 'en';
+
+
+ok(1, "modules loading");
+
+my $parser = Texinfo::Parser::parser();
+
+my $document = $parser->parse_texi_text('@top top
+@node Top
+
+T
+');
+
+my $global_info = $document->global_information();
+
+is ('input_encoding_name|input_perl_encoding',
+ join('|', sort(keys(%$global_info))), 'initial global info keys');
+
+$document->set_document_global_info('toto', 'la tete a');
+
+is ('input_encoding_name|input_perl_encoding|toto',
+ join('|', sort(keys(%$global_info))), 'with set global info keys');
+
+is ('la tete a', $global_info->{'toto'}, 'check global info set value');
+