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/ConvertXS.xs (destroy), t


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/convert/ConvertXS.xs (destroy), tp/Texinfo/Convert/Converter.pm (import, destroy), tp/Texinfo/Convert/Text.pm(import, destroy), tp/Texinfo/XS/convert/convert_html.c (html_destroy), tp/Texinfo/XS/convert/converter.c (free_generic_converter), tp/Texinfo/XS/main/convert_utils.c (destroy_translated_commands), tp/t/test_utils.pl (test), tp/texi2any.pl: add function, XS interface and C code to destroy a converter, to free its memory, called both in texi2any.pl and test_utils.pl.
Date: Sat, 11 Nov 2023 09:20:50 -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 2ea426031c * tp/Texinfo/XS/convert/ConvertXS.xs (destroy), 
tp/Texinfo/Convert/Converter.pm (import, destroy), 
tp/Texinfo/Convert/Text.pm(import, destroy), 
tp/Texinfo/XS/convert/convert_html.c (html_destroy), 
tp/Texinfo/XS/convert/converter.c (free_generic_converter), 
tp/Texinfo/XS/main/convert_utils.c (destroy_translated_commands), 
tp/t/test_utils.pl (test), tp/texi2any.pl: add function, XS interface and C 
code to destroy a converter, to free its memory, called both in texi2any.p [...]
2ea426031c is described below

commit 2ea426031c7ec37d3740d0d275ff96f1d0eeb2f4
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Nov 11 15:18:04 2023 +0100

    * tp/Texinfo/XS/convert/ConvertXS.xs (destroy),
    tp/Texinfo/Convert/Converter.pm (import, destroy),
    tp/Texinfo/Convert/Text.pm(import, destroy),
    tp/Texinfo/XS/convert/convert_html.c (html_destroy),
    tp/Texinfo/XS/convert/converter.c (free_generic_converter),
    tp/Texinfo/XS/main/convert_utils.c (destroy_translated_commands),
    tp/t/test_utils.pl (test), tp/texi2any.pl: add function, XS interface
    and C code to destroy a converter, to free its memory, called both in
    texi2any.pl and test_utils.pl.
---
 ChangeLog                            | 12 ++++++++++++
 tp/TODO                              | 30 +++++++++++++++---------------
 tp/Texinfo/Convert/Converter.pm      |  8 ++++++++
 tp/Texinfo/Convert/Text.pm           | 11 +++++++++--
 tp/Texinfo/XS/convert/ConvertXS.xs   | 21 +++++++++++++++++++++
 tp/Texinfo/XS/convert/convert_html.c | 32 ++++++++++++++++++++++++++++++++
 tp/Texinfo/XS/convert/convert_html.h |  1 +
 tp/Texinfo/XS/convert/converter.c    | 20 ++++++++++++++++++++
 tp/Texinfo/XS/convert/converter.h    |  2 ++
 tp/Texinfo/XS/main/convert_utils.c   | 13 +++++++++++++
 tp/Texinfo/XS/main/convert_utils.h   |  1 +
 tp/t/test_utils.pl                   |  1 +
 tp/texi2any.pl                       |  1 +
 13 files changed, 136 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f188902cef..b6d61e5cdd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,18 @@
        it complicates the script significantly anyway, integrated into
        many parts of the code for a very rare if non-existent use case.
 
+2023-11-11  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs (destroy),
+       tp/Texinfo/Convert/Converter.pm (import, destroy),
+       tp/Texinfo/Convert/Text.pm(import, destroy),
+       tp/Texinfo/XS/convert/convert_html.c (html_destroy),
+       tp/Texinfo/XS/convert/converter.c (free_generic_converter),
+       tp/Texinfo/XS/main/convert_utils.c (destroy_translated_commands),
+       tp/t/test_utils.pl (test), tp/texi2any.pl: add function, XS interface
+       and C code to destroy a converter, to free its memory, called both in
+       texi2any.pl and test_utils.pl.
+
 2023-11-11  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/ConvertXS.xs (html_finalize_output_state),
diff --git a/tp/TODO b/tp/TODO
index 485a3ac348..003d75bb08 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -56,24 +56,24 @@ converter free
 special_units_direction_name html_finalize_output_state
 output_unit_file_indices html_finalize_output_state
 special_unit_file_indices html_finalize_output_state
-global_units_directions
-html_targets
-seen_ids
-html_special_targets
-special_unit_info_tree
-translated_commands translated_command->translation:strdup
-expanded_formats
-error_messages: with a check that it is empty?
-conf
-init_conf
+global_units_directions html_destroy
+html_targets html_destroy
+seen_ids html_destroy
+html_special_targets html_destroy
+special_unit_info_tree html_destroy
+translated_commands translated_command->translation:strdup 
free_generic_converter
+expanded_formats free_generic_converter
+conf free_generic_converter
+init_conf free_generic_converter
 no_arg_formatted_cmd
-pre_class_types
-special_unit_varieties
+pre_class_types html_destroy
+special_unit_varieties html_destroy
 html_command_conversion
-no_arg_formatted_cmd_translated
-reset_target_commands
-file_changed_counter
+no_arg_formatted_cmd_translated html_destroy
+reset_target_commands html_destroy
+file_changed_counter html_destroy
 
+error_messages: with a check that it is empty?
 
 Bugs
 ====
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 9494792977..62098716ab 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -83,6 +83,9 @@ sub import {
       Texinfo::XSLoader::override(
        "Texinfo::Convert::Converter::_XS_get_unclosed_stream",
        "Texinfo::Convert::ConvertXS::get_unclosed_stream");
+      Texinfo::XSLoader::override(
+       "Texinfo::Convert::Converter::destroy",
+       "Texinfo::Convert::ConvertXS::destroy");
     }
 
     $module_loaded = 1;
@@ -458,6 +461,11 @@ sub output($$)
   return undef;
 }
 
+# Nothing to do in perl.  XS function frees memory
+sub destroy($)
+{
+}
+
 ###############################################################
 # Implementation of the customization API that is used in many
 # Texinfo modules
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index 8422b22e48..4ef9c3e978 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -69,8 +69,10 @@ sub import {
       # that the document tree was stored by the XS parser.
       Texinfo::XSLoader::override(
         "Texinfo::Convert::Text::_convert_tree_with_XS",
-        "Texinfo::Convert::ConvertXS::text_convert_tree"
-      );
+        "Texinfo::Convert::ConvertXS::text_convert_tree");
+      Texinfo::XSLoader::override(
+       "Texinfo::Convert::Text::destroy",
+       "Texinfo::Convert::ConvertXS::destroy");
     }
     $module_loaded = 1;
   }
@@ -1003,6 +1005,11 @@ sub output($$)
   return $result;
 }
 
+# Nothing to do in perl.  XS function frees memory
+sub destroy($)
+{
+}
+
 sub get_conf($$)
 {
   my $self = shift;
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 7f4fc77fe2..d3b6f3b844 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -108,6 +108,27 @@ get_unclosed_stream (SV *converter_in, file_path)
     OUTPUT:
          RETVAL
 
+void
+destroy (SV *converter_in)
+      PREINIT:
+         CONVERTER *self;
+         HV *stash;
+         char *name;
+      CODE:
+         stash = SvSTASH (SvRV (converter_in));
+         name = HvNAME (stash);
+         if (!strcmp (name, "Texinfo::Convert::HTML"))
+           {
+             self = get_sv_converter (converter_in, "destroy html");
+             html_destroy (self);
+           }
+          /*
+         else if (!strcmp (name, "Texinfo::Convert::Text"))
+           {
+             self = get_sv_converter (converter_in, "destroy text");
+             text_destroy (self);
+           }
+           */
 
 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 5b1c75b4b6..252a6a1289 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -2593,6 +2593,38 @@ html_check_transfer_state_finalization (CONVERTER *self)
     }
 }
 
+void
+html_destroy (CONVERTER *self)
+{
+  int i;
+
+  free_generic_converter (self);
+
+  free (self->global_units_directions);
+  free (self->html_targets.list);
+  free_strings_list (&self->seen_ids);
+  for (i = 0; i < ST_footnote_location+1; i++)
+    {
+      free (self->html_special_targets[i].list);
+    }
+  for (i = 0; i < SUIT_type_heading+1; i++)
+    {/* we assume that reset_translated_special_unit_info_tree
+        has already been called */
+      free (self->special_unit_info_tree[i]);
+    }
+
+  for (i = 1; i < ET_special_unit_element+1; i++)
+    {
+      free (self->pre_class_types[i]);
+    }
+
+  free (self->no_arg_formatted_cmd_translated.list);
+  free (self->reset_target_commands.list);
+  free (self->file_changed_counter.list);
+
+  free_strings_list (&self->special_unit_varieties);
+}
+
 char *
 html_convert_tree (CONVERTER *self, ELEMENT *tree, char *explanation)
 {
diff --git a/tp/Texinfo/XS/convert/convert_html.h 
b/tp/Texinfo/XS/convert/convert_html.h
index 75077c3cb0..db4f49e50d 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -56,4 +56,5 @@ char *html_convert_output (CONVERTER *self, ELEMENT *root,
                            char *output_file, char *destination_directory,
                            char *output_filename, char *document_name);
 void html_check_transfer_state_finalization (CONVERTER *self);
+void html_destroy (CONVERTER *self);
 #endif
diff --git a/tp/Texinfo/XS/convert/converter.c 
b/tp/Texinfo/XS/convert/converter.c
index ae45a554a9..d240380ea3 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -28,6 +28,7 @@
 #include "utils.h"
 #include "builtin_commands.h"
 #include "node_name_normalization.h"
+#include "convert_utils.h"
 #include "converter.h"
 
 static CONVERTER *converter_list;
@@ -508,3 +509,22 @@ set_file_path (CONVERTER *self, char *filename, char 
*filepath,
   if (free_filepath)
     free (filepath_str);
 }
+
+void
+free_generic_converter (CONVERTER *self)
+{
+  if (self->translated_commands)
+    {
+      destroy_translated_commands (self->translated_commands);
+    }
+
+  free (self->expanded_formats);
+
+  if (self->init_conf)
+    free_options (self->init_conf);
+  free (self->init_conf);
+
+  if (self->conf)
+    free_options (self->conf);
+  free (self->conf);
+}
diff --git a/tp/Texinfo/XS/convert/converter.h 
b/tp/Texinfo/XS/convert/converter.h
index 9fab969d77..22062f562d 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -35,4 +35,6 @@ size_t set_output_unit_file (CONVERTER *self, OUTPUT_UNIT 
*output_unit,
                                     char *filename, int set_counter);
 void set_file_path (CONVERTER *self, char *filename, char *filepath,
                     char *destination_directory);
+
+void free_generic_converter (CONVERTER *self);
 #endif
diff --git a/tp/Texinfo/XS/main/convert_utils.c 
b/tp/Texinfo/XS/main/convert_utils.c
index cd818b2209..1947b2b1f0 100644
--- a/tp/Texinfo/XS/main/convert_utils.c
+++ b/tp/Texinfo/XS/main/convert_utils.c
@@ -555,6 +555,19 @@ translated_command_tree (CONVERTER *self, enum command_id 
cmd)
   return 0;
 }
 
+void
+destroy_translated_commands (TRANSLATED_COMMAND *translated_commands)
+{
+  TRANSLATED_COMMAND *translated_command;
+
+  for (translated_command = translated_commands;
+       translated_command->translation; translated_command++)
+    {
+      free (translated_command->translation);
+    }
+  free (translated_commands);
+}
+
 /*
   API to open, set encoding and register files.
 */
diff --git a/tp/Texinfo/XS/main/convert_utils.h 
b/tp/Texinfo/XS/main/convert_utils.h
index 658764f17b..206011dc00 100644
--- a/tp/Texinfo/XS/main/convert_utils.h
+++ b/tp/Texinfo/XS/main/convert_utils.h
@@ -40,6 +40,7 @@ void destroy_parsed_def (PARSED_DEF *parsed_def);
 ELEMENT *definition_category_tree (OPTIONS *options, ELEMENT *current);
 
 ELEMENT *translated_command_tree (CONVERTER *self, enum command_id cmd);
+void destroy_translated_commands (TRANSLATED_COMMAND *translated_commands);
 
 char *encoded_output_file_name (OPTIONS *options,
                                 GLOBAL_INFO *global_information,
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 5ff668c424..f8b2ce2db4 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -1287,6 +1287,7 @@ sub test($$)
           }
         }
       }
+      $converter->destroy();
     }
   }
   my $directions_text;
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index c12e78a01d..b1d4d1cce0 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1828,6 +1828,7 @@ while(@input_files) {
   }
 
   Texinfo::Document::remove_document($document);
+  $converter->destroy();
 }
 
 foreach my $unclosed_file (keys(%main_unclosed_files)) {



reply via email to

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