texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/convert/convert_html.c (html_free


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/convert/convert_html.c (html_free_converter): rename html_destroy as html_free_converter.
Date: Sun, 19 Nov 2023 16:02:30 -0500

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 c3f32706f5 * tp/Texinfo/XS/convert/convert_html.c 
(html_free_converter): rename html_destroy as html_free_converter.
c3f32706f5 is described below

commit c3f32706f5ac847be48875a1f82d035999d5d2bd
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Nov 19 22:02:10 2023 +0100

    * tp/Texinfo/XS/convert/convert_html.c (html_free_converter): rename
    html_destroy as html_free_converter.
    
    * tp/Texinfo/XS/convert/ConvertXS.xs (destroy),
    tp/Texinfo/XS/convert/converter.c (converter_list, new_converter)
    (retrieve_converter, unregister_converter_descriptor),
    tp/Texinfo/XS/convert/get_html_perl_info.c
    (html_converter_initialize_sv): use a list of pointers to converters
    in converter_list.  Add new_converter to allocate a converter,
    replacing register_converter.  Add unregister_converter_descriptor
    that removes a converter from converter_list and frees it.
    
    * tp/Texinfo/XS/convert/converter.c (html_free_converter): free
    special_unit_info.  Free html_document_context.stack.
---
 ChangeLog                                  | 17 +++++++++++++++
 tp/Texinfo/XS/convert/ConvertXS.xs         |  7 +++++--
 tp/Texinfo/XS/convert/convert_html.c       | 14 ++++++++++++-
 tp/Texinfo/XS/convert/convert_html.h       |  2 +-
 tp/Texinfo/XS/convert/converter.c          | 33 ++++++++++++++++++++----------
 tp/Texinfo/XS/convert/converter.h          |  3 ++-
 tp/Texinfo/XS/convert/get_html_perl_info.c |  7 ++-----
 tp/Texinfo/XS/main/document.c              |  3 +++
 8 files changed, 65 insertions(+), 21 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 50d19c0765..85a49716c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2023-11-19  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/convert_html.c (html_free_converter): rename
+       html_destroy as html_free_converter.
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs (destroy),
+       tp/Texinfo/XS/convert/converter.c (converter_list, new_converter)
+       (retrieve_converter, unregister_converter_descriptor),
+       tp/Texinfo/XS/convert/get_html_perl_info.c
+       (html_converter_initialize_sv): use a list of pointers to converters
+       in converter_list.  Add new_converter to allocate a converter,
+       replacing register_converter.  Add unregister_converter_descriptor
+       that removes a converter from converter_list and frees it.
+
+       * tp/Texinfo/XS/convert/converter.c (html_free_converter): free
+       special_unit_info.  Free html_document_context.stack.
+
 2023-11-19  Patrice Dumas  <pertusus@free.fr>
 
        * tp/texi2any.supp: Add suppression specification for leaks associated
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 87ae6e88ad..6427f69bc7 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -41,6 +41,7 @@
 #include "builtin_commands.h"
 #include "indices_in_conversion.h"
 #include "command_stack.h"
+#include "converter.h"
 #include "convert_html.h"
 #include "get_html_perl_info.h"
 #include "document.h"
@@ -124,7 +125,7 @@ get_unclosed_stream (SV *converter_in, file_path)
 void
 destroy (SV *converter_in)
       PREINIT:
-         CONVERTER *self;
+         CONVERTER *self = 0;
          HV *stash;
          char *name;
       CODE:
@@ -133,7 +134,7 @@ destroy (SV *converter_in)
          if (!strcmp (name, "Texinfo::Convert::HTML"))
            {
              self = get_sv_converter (converter_in, "destroy html");
-             html_destroy (self);
+             html_free_converter (self);
            }
           /*
          else if (!strcmp (name, "Texinfo::Convert::Text"))
@@ -142,6 +143,8 @@ destroy (SV *converter_in)
              text_destroy (self);
            }
            */
+         if (self)
+           unregister_converter_descriptor (self->converter_descriptor);
 
 SV *
 plain_texinfo_convert_tree (SV *tree_in)
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 7db366d8a5..7ca7995cbd 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -3153,7 +3153,7 @@ html_check_transfer_state_finalization (CONVERTER *self)
 }
 
 void
-html_destroy (CONVERTER *self)
+html_free_converter (CONVERTER *self)
 {
   int i;
 
@@ -3200,12 +3200,24 @@ html_destroy (CONVERTER *self)
         }
     }
 
+  for (i = 0; i < SUI_type_heading+1; i++)
+    {
+      int k;
+      for (k = 0; k < self->special_unit_varieties.number; k++)
+        {
+          free (self->special_unit_info[i][k]);
+        }
+      free (self->special_unit_info[i]);
+    }
+
   free (self->no_arg_formatted_cmd.list);
 
   free (self->no_arg_formatted_cmd_translated.list);
   free (self->reset_target_commands.list);
   free (self->file_changed_counter.list);
 
+  free (self->html_document_context.stack);
+
   free_strings_list (&self->special_unit_varieties);
 }
 
diff --git a/tp/Texinfo/XS/convert/convert_html.h 
b/tp/Texinfo/XS/convert/convert_html.h
index 289fd3fbba..5ab0d9a3bf 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -68,6 +68,6 @@ char *html_convert_output (CONVERTER *self, const ELEMENT 
*root,
                            char *output_filename, char *document_name);
 
 void html_check_transfer_state_finalization (CONVERTER *self);
-void html_destroy (CONVERTER *self);
+void html_free_converter (CONVERTER *self);
 void html_destroy_files_source_info (FILE_SOURCE_INFO_LIST *files_source_info);
 #endif
diff --git a/tp/Texinfo/XS/convert/converter.c 
b/tp/Texinfo/XS/convert/converter.c
index fd56d9d0b4..2dbe1836e8 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -31,7 +31,7 @@
 #include "convert_utils.h"
 #include "converter.h"
 
-static CONVERTER *converter_list;
+static CONVERTER **converter_list;
 static size_t converter_number;
 static size_t converter_space;
 
@@ -39,14 +39,14 @@ CONVERTER *
 retrieve_converter (int converter_descriptor)
 {
   if (converter_descriptor <= converter_number
-      && converter_list[converter_descriptor -1].document != 0)
-    return &converter_list[converter_descriptor -1];
+      && converter_list[converter_descriptor -1] != 0)
+    return converter_list[converter_descriptor -1];
   return 0;
 }
 
 /* descriptor starts at 1, 0 is not found or an error */
 size_t
-register_converter (CONVERTER *converter)
+new_converter (void)
 {
   size_t converter_index;
   int slot_found = 0;
@@ -55,7 +55,7 @@ register_converter (CONVERTER *converter)
 
   for (i = 0; i < converter_number; i++)
     {
-      if (converter_list[i].document == 0)
+      if (converter_list[i] == 0)
         {
           slot_found = 1;
           converter_index = i;
@@ -66,26 +66,37 @@ register_converter (CONVERTER *converter)
       if (converter_number == converter_space)
         {
           converter_list = realloc (converter_list,
-                              (converter_space += 5) * sizeof (CONVERTER));
+                              (converter_space += 5) * sizeof (CONVERTER *));
           if (!converter_list)
             fatal ("realloc failed");
         }
       converter_index = converter_number;
       converter_number++;
     }
-  registered_converter = &converter_list[converter_index];
-  memcpy (registered_converter, converter, sizeof (CONVERTER));
+  registered_converter = (CONVERTER *) malloc (sizeof (CONVERTER));
+  memset (registered_converter, 0, sizeof (CONVERTER));
+
+  converter_list[converter_index] = registered_converter;
+  registered_converter->converter_descriptor = converter_index +1;
 
   /*
   fprintf(stderr, "REGISTER CONVERTER %zu %p %p %p\n", converter_index +1,
                        converter, registered_converter, converter->document);
    */
-
-  registered_converter->converter_descriptor = converter_index +1;
-
   return converter_index +1;
 }
 
+void
+unregister_converter_descriptor (int converter_descriptor)
+{
+  CONVERTER *converter = retrieve_converter (converter_descriptor);
+  if (converter)
+    {
+      converter_list[converter_descriptor-1] = 0;
+      free (converter);
+    }
+}
+
 /* freed by caller */
 static COMMAND_OPTION_VALUE *
 new_option_value (int type, int int_value, char *char_value)
diff --git a/tp/Texinfo/XS/convert/converter.h 
b/tp/Texinfo/XS/convert/converter.h
index b05ad6f7e2..8d0e405ab7 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -70,7 +70,8 @@
 
 
 CONVERTER *retrieve_converter (int converter_descriptor);
-size_t register_converter (CONVERTER *converter);
+size_t new_converter(void);
+void unregister_converter_descriptor (int converter_descriptor);
 
 void set_global_document_commands (CONVERTER *converter,
                                   const enum command_location location,
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c 
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index 91f82e1020..d980e95ca0 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -158,13 +158,12 @@ html_converter_initialize_sv (SV *converter_sv,
   HV *types_conversion_hv;
   HV *output_units_conversion_hv;
   int converter_descriptor = 0;
-  CONVERTER initial_converter;
   CONVERTER *converter;
 
   dTHX;
 
-  converter = &initial_converter;
-  memset (converter, 0, sizeof (CONVERTER));
+  converter_descriptor = new_converter ();
+  converter = retrieve_converter (converter_descriptor);
 
   converter_initialize (converter_sv, converter);
 
@@ -749,8 +748,6 @@ html_converter_initialize_sv (SV *converter_sv,
 
   converter->hv = converter_hv;
 
-  converter_descriptor = register_converter (converter);
-
   /* store converter_descriptor in perl converter */
   hv_store (converter_hv, "converter_descriptor",
             strlen("converter_descriptor"),
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index 029448e2d9..b85b536f54 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -32,6 +32,9 @@
 #include "utils.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 size_t document_number;
 static size_t document_space;



reply via email to

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