[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/XS/main/document.c (document_list, r
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/XS/main/document.c (document_list, retrieve_document) (new_document, remove_document_descriptor): store a document pointer in document_list, not a document, such that the document pointer remains valid upon reallocating. Then it becomes easier to have fields in the document being themselves structures instead of pointers on structures. |
Date: |
Sat, 18 May 2024 08:33:01 -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 5804416e8f * tp/Texinfo/XS/main/document.c (document_list,
retrieve_document) (new_document, remove_document_descriptor): store a document
pointer in document_list, not a document, such that the document pointer
remains valid upon reallocating. Then it becomes easier to have fields in the
document being themselves structures instead of pointers on structures.
5804416e8f is described below
commit 5804416e8fe4b2f66d13241cac33c1b305f63453
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat May 18 14:33:00 2024 +0200
* tp/Texinfo/XS/main/document.c (document_list, retrieve_document)
(new_document, remove_document_descriptor): store a document pointer
in document_list, not a document, such that the document pointer
remains valid upon reallocating. Then it becomes easier to have
fields in the document being themselves structures instead of pointers
on structures.
---
ChangeLog | 9 +++++++++
tp/Texinfo/XS/main/document.c | 28 +++++++++++-----------------
tp/Texinfo/XS/parsetexi/indices.c | 3 ---
3 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e5293dfb74..dc15ed1a0c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-05-18 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/document.c (document_list, retrieve_document)
+ (new_document, remove_document_descriptor): store a document pointer
+ in document_list, not a document, such that the document pointer
+ remains valid upon reallocating. Then it becomes easier to have
+ fields in the document being themselves structures instead of pointers
+ on structures.
+
2024-05-18 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/convert_html.c (prepare_index_entries_targets)
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index 7f3afe56ad..01e7240ba3 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -34,10 +34,7 @@
#include "manipulate_indices.h"
#include "document.h"
-/* note that each time the document list is reallocated, pointers
- to documents need to be reset, so in general the document should be
- retrieved with the index in the list */
-static DOCUMENT *document_list;
+static DOCUMENT **document_list;
static size_t document_number;
static size_t document_space;
@@ -45,25 +42,23 @@ DOCUMENT *
retrieve_document (int document_descriptor)
{
if (document_descriptor <= document_number
- && document_list[document_descriptor -1].tree != 0)
- return &document_list[document_descriptor -1];
+ && document_list[document_descriptor -1] != 0)
+ return document_list[document_descriptor -1];
return 0;
}
-/* note that the returned document will become invalid if there is a
- realloc of the documents list */
/* descriptor starts at 1, 0 is an error */
DOCUMENT *
new_document (void)
{
size_t document_index;
int slot_found = 0;
- DOCUMENT *document = 0;
int i;
+ DOCUMENT *document = (DOCUMENT *) malloc (sizeof (DOCUMENT));
for (i = 0; i < document_number; i++)
{
- if (document_list[i].tree == 0)
+ if (document_list[i] == 0)
{
slot_found = 1;
document_index = i;
@@ -74,14 +69,15 @@ new_document (void)
if (document_number == document_space)
{
document_list = realloc (document_list,
- (document_space += 5) * sizeof (DOCUMENT));
+ (document_space += 5) * sizeof (DOCUMENT *));
if (!document_list)
fatal ("realloc failed");
}
document_index = document_number;
document_number++;
}
- document = &document_list[document_index];
+ document_list[document_index] = document;
+
memset (document, 0, sizeof (DOCUMENT));
document->descriptor = document_index +1;
@@ -119,9 +115,6 @@ new_document (void)
/*
fprintf (stderr, "DOCUMENT %zu %p\n", document_index +1, document);
*/
- /*
- return document_index +1;
- */
return document;
}
@@ -498,7 +491,7 @@ remove_document_descriptor (int document_descriptor)
if (document_descriptor > document_number)
return;
- document = &document_list[document_descriptor -1];
+ document = document_list[document_descriptor -1];
destroy_document_information_except_tree (document);
@@ -507,7 +500,8 @@ remove_document_descriptor (int document_descriptor)
destroy_element_and_children (document->tree);
destroy_strings_list (document->small_strings);
}
- document->tree = 0;
+ free (document);
+ document_list[document_descriptor -1] = 0;
/*
fprintf (stderr, "REMOVE %d %p\n", document_descriptor, document);
*/
diff --git a/tp/Texinfo/XS/parsetexi/indices.c
b/tp/Texinfo/XS/parsetexi/indices.c
index 0d4899c68f..afc82ece90 100644
--- a/tp/Texinfo/XS/parsetexi/indices.c
+++ b/tp/Texinfo/XS/parsetexi/indices.c
@@ -375,9 +375,6 @@ complete_indices (int document_descriptor, int debug_level)
INDEX_LIST *indices;
size_t i;
- /* beware that document may have a change in adress if realloc on
- the documents list is called in gdt. So only use it here and
- not after gdt call */
document = retrieve_document (document_descriptor);
indices = document->indices_info;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/XS/main/document.c (document_list, retrieve_document) (new_document, remove_document_descriptor): store a document pointer in document_list, not a document, such that the document pointer remains valid upon reallocating. Then it becomes easier to have fields in the document being themselves structures instead of pointers on structures.,
Patrice Dumas <=
- Prev by Date:
branch master updated: * tp/Texinfo/XS/convert/convert_html.c (prepare_index_entries_targets) (convert_printindex_command, html_initialize_output_state) (html_reset_converter), tp/Texinfo/XS/convert/get_html_perl_info.c (find_index_entry_numbers_index_entry_sv), tp/Texinfo/XS/main/IndicesXS.xs (index_entry_element_sort_string), tp/Texinfo/XS/main/build_perl_info.c (build_index_data) (fill_document_hv), tp/Texinfo/XS/main/document.c (document_merged_indices, document_indices_sort_strings) (destroy_document_inform [...]
- Next by Date:
branch master updated: * tp/Texinfo/XS/main/build_perl_info.c (build_target_elements_list) (build_internal_xref_list, build_float_types_list) (BUILD_PERL_DOCUMENT_LIST): use a list as input argument. Update callers. Modify BUILD_PERL_DOCUMENT_LIST to use a list too, using the address of the fieldname.
- Previous by thread:
branch master updated: * tp/Texinfo/XS/convert/convert_html.c (prepare_index_entries_targets) (convert_printindex_command, html_initialize_output_state) (html_reset_converter), tp/Texinfo/XS/convert/get_html_perl_info.c (find_index_entry_numbers_index_entry_sv), tp/Texinfo/XS/main/IndicesXS.xs (index_entry_element_sort_string), tp/Texinfo/XS/main/build_perl_info.c (build_index_data) (fill_document_hv), tp/Texinfo/XS/main/document.c (document_merged_indices, document_indices_sort_strings) (destroy_document_inform [...]
- Next by thread:
branch master updated: * tp/Texinfo/XS/main/build_perl_info.c (build_target_elements_list) (build_internal_xref_list, build_float_types_list) (BUILD_PERL_DOCUMENT_LIST): use a list as input argument. Update callers. Modify BUILD_PERL_DOCUMENT_LIST to use a list too, using the address of the fieldname.
- Index(es):