texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Fri, 10 Nov 2023 17:30:42 -0500 (EST)

branch: master
commit 42249fe8adbefc42c3202cf9e694c4145e6ce459
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Nov 10 23:30:21 2023 +0100

    * tp/Texinfo/XS/convert/ConvertXS.xs
    (get_index_entries_sorted_by_letter),
    tp/Texinfo/XS/main/converter_types.h (CONVERTER),
    tp/Texinfo/XS/main/get_perl_info.c
    (get_sv_index_entries_sorted_by_letter): set index_entries_by_letter
    as a pointer on INDEX_SORTED_BY_LETTER, not a pointer on pointer.
    
    * tp/Texinfo/XS/main/get_perl_info.c
    (get_sv_index_entries_sorted_by_letter): add a zeroed entry to mark
    the end of the array. strdup letter string. Check that index entry
    index name is set in perl. When finding the index entry in C index
    data, verify that the index number from perl leads to an index
    consistent with index size. Debug message if the index entry is not
    found.
---
 ChangeLog                            | 17 ++++++++++++
 tp/TODO                              |  2 ++
 tp/Texinfo/XS/convert/ConvertXS.xs   |  2 +-
 tp/Texinfo/XS/main/converter_types.h |  2 +-
 tp/Texinfo/XS/main/get_perl_info.c   | 53 +++++++++++++++++++++++-------------
 tp/Texinfo/XS/main/get_perl_info.h   |  2 +-
 6 files changed, 56 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 80ada889c0..e11a4247fb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2023-11-10  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs
+       (get_index_entries_sorted_by_letter),
+       tp/Texinfo/XS/main/converter_types.h (CONVERTER),
+       tp/Texinfo/XS/main/get_perl_info.c
+       (get_sv_index_entries_sorted_by_letter): set index_entries_by_letter
+       as a pointer on INDEX_SORTED_BY_LETTER, not a pointer on pointer.
+
+       * tp/Texinfo/XS/main/get_perl_info.c
+       (get_sv_index_entries_sorted_by_letter): add a zeroed entry to mark
+       the end of the array. strdup letter string. Check that index entry
+       index name is set in perl. When finding the index entry in C index
+       data, verify that the index number from perl leads to an index
+       consistent with index size. Debug message if the index entry is not
+       found.
+
 2023-11-10  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/indices_in_conversion.c (merge_indices): add a
diff --git a/tp/TODO b/tp/TODO
index fea0597fb0..adbd53fccf 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -65,6 +65,8 @@ expanded_formats
 error_messages: with a check that it is empty?
 conf
 init_conf
+index_entries
+index_entries_by_letter (letter string, letter entries...)
 
 
 Bugs
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 4cb28a3594..76ae03ee07 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -65,7 +65,7 @@ void
 get_index_entries_sorted_by_letter (SV *converter_in, SV 
*index_entries_sorted_by_letter)
       PREINIT:
          CONVERTER *self;
-         INDEX_SORTED_BY_LETTER **index_entries_by_letter;
+         INDEX_SORTED_BY_LETTER *index_entries_by_letter;
       CODE:
          self = get_sv_converter (converter_in,
                                   "get_index_entries_sorted_by_letter");
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index bdcddfd259..c83cda284e 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -377,7 +377,7 @@ typedef struct CONVERTER {
 
     ERROR_MESSAGE_LIST error_messages;
     MERGED_INDEX *index_entries;
-    INDEX_SORTED_BY_LETTER **index_entries_by_letter;
+    INDEX_SORTED_BY_LETTER *index_entries_by_letter;
     TRANSLATED_COMMAND *translated_commands;
     EXPANDED_FORMAT *expanded_formats;
 
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index 33fcef8d02..92b5dda206 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -412,11 +412,11 @@ set_output_converter_sv (SV *sv_in, char *warn_string)
    in the data structure.  Not clear that it is useful or not, not enabled
    for now */
 /* return value to be freed by caller */
-INDEX_SORTED_BY_LETTER **
+INDEX_SORTED_BY_LETTER *
 get_sv_index_entries_sorted_by_letter (INDEX **index_names,
                                        SV *index_entries_sorted_by_letter)
 {
-  INDEX_SORTED_BY_LETTER **index_entries_by_letter;
+  INDEX_SORTED_BY_LETTER *indices_entries_by_letter;
 
   HV *hv_in;
   /* for sorted index names
@@ -462,12 +462,16 @@ get_sv_index_entries_sorted_by_letter (INDEX 
**index_names,
   sortsv (sorted_index_names_av_array, index_names_nr, Perl_sv_cmp);
    */
 
-  index_entries_by_letter = (INDEX_SORTED_BY_LETTER **)
-    malloc (index_names_nr * sizeof (INDEX_SORTED_BY_LETTER *));
+  indices_entries_by_letter = (INDEX_SORTED_BY_LETTER *)
+    malloc ((index_names_nr +1) * sizeof (INDEX_SORTED_BY_LETTER));
+  /* zeroed entry to mark the end of the array */
+  memset (&indices_entries_by_letter[index_names_nr], 0,
+          sizeof (INDEX_SORTED_BY_LETTER));
 
   for (j = 0; j < index_names_nr; j++)
     {
       int i;
+      INDEX_SORTED_BY_LETTER *index_index_letters;
       char *idx_name = 0;
       SSize_t letter_entries_nr;
       HE *sorted_by_letter_he;
@@ -522,26 +526,24 @@ get_sv_index_entries_sorted_by_letter (INDEX 
**index_names,
                      j, idx_name);
           fatal (msg);
         }
-
-      index_entries_by_letter[j] = (INDEX_SORTED_BY_LETTER *)
-                                 malloc (sizeof (INDEX_SORTED_BY_LETTER));
-      index_entries_by_letter[j]->name = strdup (idx_name);
-
       av = (AV *)SvRV (sorted_by_letter_sv);
-
       letter_entries_nr = av_top_index (av) +1;
-      index_entries_by_letter[j]->number = letter_entries_nr;
-      index_entries_by_letter[j]->letter_entries
+
+      index_index_letters = &indices_entries_by_letter[j];
+      index_index_letters->name = strdup (idx_name);
+      index_index_letters->number = letter_entries_nr;
+      index_index_letters->letter_entries
         = (LETTER_INDEX_ENTRIES *)
          malloc (letter_entries_nr * sizeof (LETTER_INDEX_ENTRIES));
       for (i = 0; i < letter_entries_nr; i++)
         {
           SV** letter_entries_sv = av_fetch (av, i, 0);
           LETTER_INDEX_ENTRIES *letter_entries
-            = &index_entries_by_letter[j]->letter_entries[i];
+            = &index_index_letters->letter_entries[i];
           if (letter_entries_sv)
             {
               int k;
+              char *letter_string;
               SSize_t entries_nr;
               AV *entries_av;
 
@@ -558,8 +560,8 @@ get_sv_index_entries_sorted_by_letter (INDEX **index_names,
                              idx_name, i);
                   fatal (msg);
                 }
-              letter_entries->letter
-                = (char *) SvPVutf8_nolen (*letter_sv);
+              letter_string = (char *) SvPVutf8_nolen (*letter_sv);
+              letter_entries->letter = strdup (letter_string);
 
               entries_av = (AV *) SvRV (*entries_sv);
               entries_nr = av_top_index (entries_av) +1;
@@ -576,6 +578,9 @@ get_sv_index_entries_sorted_by_letter (INDEX **index_names,
                   INDEX **n;
                   char *entry_index_name;
                   int entry_number;
+                  int entry_idx_in_index;
+
+                  letter_entries->entries[k] = 0;
 
                   if (!index_entry_sv)
                     {
@@ -590,7 +595,7 @@ get_sv_index_entries_sorted_by_letter (INDEX **index_names,
                                             strlen ("index_name"), 0);
                   entry_number_sv = hv_fetch (index_entry_hv, "entry_number",
                                               strlen ("entry_number"), 0);
-                  if (!index_entry_hv || !entry_number_sv)
+                  if (!index_name_sv || !entry_number_sv)
                     {
                       char *msg;
                       xasprintf (&msg,
@@ -600,16 +605,26 @@ get_sv_index_entries_sorted_by_letter (INDEX 
**index_names,
                     }
                   entry_index_name = (char *) SvPVutf8_nolen (*index_name_sv);
                   entry_number = SvIV (*entry_number_sv);
+                  entry_idx_in_index = entry_number - 1;
 
                   for (n = index_names; (idx = *n); n++)
                     {
                       if (!strcmp (idx->name, entry_index_name))
                         {
-                          letter_entries->entries[k]
-                            = &idx->index_entries[entry_number];
+                          if (entry_idx_in_index < idx->index_number)
+                            letter_entries->entries[k]
+                              = &idx->index_entries[entry_number];
                           break;
                         }
                     }
+                  if (!letter_entries->entries[k])
+                    {
+                      char *msg;
+                      xasprintf (&msg,
+          "BUG: index %s letter %s position %d: %s entry %d not found\n",
+                                 idx_name, letter_string, k,
+                                 entry_index_name, entry_number);
+                    }
                 }
             }
           else
@@ -622,7 +637,7 @@ get_sv_index_entries_sorted_by_letter (INDEX **index_names,
             }
         }
     }
-  return index_entries_by_letter;
+  return indices_entries_by_letter;
 }
 
 void
diff --git a/tp/Texinfo/XS/main/get_perl_info.h 
b/tp/Texinfo/XS/main/get_perl_info.h
index 7cb39c2aa5..f34f5b5355 100644
--- a/tp/Texinfo/XS/main/get_perl_info.h
+++ b/tp/Texinfo/XS/main/get_perl_info.h
@@ -27,7 +27,7 @@ CONVERTER *get_sv_converter (SV *sv_in, char *warn_string);
 
 CONVERTER *converter_initialize (SV *converter_sv);
 
-INDEX_SORTED_BY_LETTER **get_sv_index_entries_sorted_by_letter
+INDEX_SORTED_BY_LETTER *get_sv_index_entries_sorted_by_letter
                  (INDEX **index_names, SV *index_entries_sorted_by_letter);
 
 TEXT_OPTIONS *copy_sv_options_for_convert_text (SV *sv_in);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]