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, 4 Oct 2024 06:44:23 -0400 (EDT)

branch: master
commit 3da5a90f8c79413739296621c51272b472780a8c
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Aug 13 21:12:40 2024 +0200

    * tp/Texinfo/XS/convert/converter.c (new_converter): rename
    registered_converter as converter.
    
    * tp/Texinfo/XS/convert/converter.c (set_converter_init_information):
    rename converter_defaults as format_converter_defaults and
    converter_initialize as format_converter_initialize.
    
    * tp/Texinfo/XS/convert/converter.c (reset_generic_converter): add
    a function to reset parser structures tied to a document to be ready
    for a new conversion.
    
    * tp/Texinfo/XS/convert/converter.c (converter_format_data)
    (reset_converter, free_converter, destroy_converter),
    tp/Texinfo/XS/convert/converter.h (CONVERTER_FORMAT_DATA),
    tp/Texinfo/XS/Makefile.am (libtexinfo_convert_la_SOURCES),
    tp/Texinfo/XS/convert/ConvertXS.xs (reset_converter, destroy),
    tp/Texinfo/XS/convert/convert_html.c (html_reset_converter):
    add references to specific format reset_converter and free_converter
    functions in CONVERTER_FORMAT_DATA.  Set them for HTML, with
    declarations in the new file convert/html_converter_finish.h.
    Add reset_converter and free_converter in converter.c that call both
    the generic converter functions and function references from
    converter_format_data.  Call those functions in ConvertXS.xs.  Do not
    call free_generic_converter anymore in html_reset_converter.
    Add destroy_converter function with code of
    unregister_converter_descriptor, and call to free_converter.
---
 ChangeLog                                     |  29 +++++++
 tp/Texinfo/XS/Makefile.am                     |   3 +-
 tp/Texinfo/XS/convert/ConvertXS.xs            |  12 +--
 tp/Texinfo/XS/convert/convert_html.c          |   3 +-
 tp/Texinfo/XS/convert/convert_html.h          |   2 -
 tp/Texinfo/XS/convert/converter.c             | 120 ++++++++++++++++++--------
 tp/Texinfo/XS/convert/converter.h             |   9 +-
 tp/Texinfo/XS/convert/html_converter_finish.h |  10 +++
 8 files changed, 135 insertions(+), 53 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5035e33678..edfc6af830 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2024-08-13  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/converter.c (new_converter): rename
+       registered_converter as converter.
+
+       * tp/Texinfo/XS/convert/converter.c (set_converter_init_information):
+       rename converter_defaults as format_converter_defaults and
+       converter_initialize as format_converter_initialize.
+
+       * tp/Texinfo/XS/convert/converter.c (reset_generic_converter): add
+       a function to reset parser structures tied to a document to be ready
+       for a new conversion.
+
+       * tp/Texinfo/XS/convert/converter.c (converter_format_data)
+       (reset_converter, free_converter, destroy_converter),
+       tp/Texinfo/XS/convert/converter.h (CONVERTER_FORMAT_DATA),
+       tp/Texinfo/XS/Makefile.am (libtexinfo_convert_la_SOURCES),
+       tp/Texinfo/XS/convert/ConvertXS.xs (reset_converter, destroy),
+       tp/Texinfo/XS/convert/convert_html.c (html_reset_converter):
+       add references to specific format reset_converter and free_converter
+       functions in CONVERTER_FORMAT_DATA.  Set them for HTML, with
+       declarations in the new file convert/html_converter_finish.h.
+       Add reset_converter and free_converter in converter.c that call both
+       the generic converter functions and function references from
+       converter_format_data.  Call those functions in ConvertXS.xs.  Do not
+       call free_generic_converter anymore in html_reset_converter.
+       Add destroy_converter function with code of
+       unregister_converter_descriptor, and call to free_converter.
+
 2024-08-13  Patrice Dumas  <pertusus@free.fr>
 
        * tp/t/test_utils.pl (test): destroy PlainTexinfo converter.
diff --git a/tp/Texinfo/XS/Makefile.am b/tp/Texinfo/XS/Makefile.am
index 4d45079a87..a5b51b8c28 100644
--- a/tp/Texinfo/XS/Makefile.am
+++ b/tp/Texinfo/XS/Makefile.am
@@ -390,6 +390,7 @@ C_libtexinfo_convert_sources = \
                        convert/create_buttons.h \
                        convert/html_converter_init_options.c \
                        convert/html_converter_init_options.h \
+                       convert/html_converter_finish.h \
                        convert/texinfo.c \
                        convert/texinfo.h
 
@@ -406,7 +407,7 @@ libtexinfo_convert_la_SOURCES = \
    $(XS_libtexinfo_convert_sources)
 
 # locate include files under out-of-source builds.
-# parsetexi will only be needed for texinfo.c
+# parsetexi is only needed for texinfo.c
 libtexinfo_convert_la_CPPFLAGS = -I$(srcdir)/main -I$(srcdir)/convert 
-I$(srcdir)/structuring_transfo -I$(srcdir)/parsetexi $(AM_CPPFLAGS) 
$(GNULIB_CPPFLAGS) $(XSLIBS_CPPFLAGS)
 libtexinfo_convert_la_CFLAGS = $(XSLIBS_CFLAGS)
 libtexinfo_convert_la_LIBADD = libtexinfo.la libtexinfoxs.la 
$(top_builddir)/gnulib/lib/libgnu.la
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 94f7f963b2..3e91d755e8 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -531,10 +531,7 @@ reset_converter (SV *converter_in)
       CODE:
         self = get_sv_converter (converter_in, 0);
         if (self)
-          {
-            if (self->format == COF_html)
-              html_reset_converter (self);
-          }
+          reset_converter (self);
 
 void
 destroy (SV *converter_in)
@@ -543,12 +540,7 @@ destroy (SV *converter_in)
       CODE:
         self = get_sv_converter (converter_in, 0);
         if (self)
-          {
-            if (self->format == COF_html)
-              html_free_converter (self);
-
-            unregister_converter_descriptor (self->converter_descriptor);
-          }
+          destroy_converter (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 c4382bc6ac..18112dccfc 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -19617,6 +19617,7 @@ html_reset_converter (CONVERTER *self)
     clear_registered_ids_hv (self);
   else
     clear_strings_list (self->registered_ids);
+
   for (i = 0; i < ST_footnote_location+1; i++)
     {
       reset_html_targets_list (self, &self->html_special_targets[i]);
@@ -19793,8 +19794,6 @@ html_free_converter (CONVERTER *self)
   EXPLAINED_COMMAND_TYPE_LIST *type_explanations
    = &self->shared_conversion_state.explained_commands;
 
-  free_generic_converter (self);
-
   /* useful only if html_reset_converter was not called previously */
   reset_translated_special_unit_info_tree (self);
 
diff --git a/tp/Texinfo/XS/convert/convert_html.h 
b/tp/Texinfo/XS/convert/convert_html.h
index ac1b3d5cfb..1650fa2213 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -267,8 +267,6 @@ int html_finish_output (CONVERTER *self, const char 
*output_file,
                         const char *destination_directory);
 
 void html_check_transfer_state_finalization (CONVERTER *self);
-void html_free_converter (CONVERTER *self);
-void html_reset_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 8222dd4a02..b823c7c136 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -60,11 +60,16 @@
 #include "manipulate_indices.h"
 #include "document.h"
 #include "html_converter_init_options.h"
+#include "html_converter_finish.h"
 #include "call_perl_function.h"
 #include "converter.h"
 
+/* table used to dispatch format specific functions.
+   Same purpose as inherited methods in Texinfo::Convert::Converter */
 CONVERTER_FORMAT_DATA converter_format_data[] = {
-  {"html", "Texinfo::Convert::HTML", &html_converter_defaults, 
&html_converter_initialize},
+  {"html", "Texinfo::Convert::HTML", &html_converter_defaults,
+   &html_converter_initialize, &html_reset_converter,
+   &html_free_converter},
 };
 
 /* associate lower case no brace accent command to the upper case
@@ -228,7 +233,7 @@ new_converter (enum converter_format format, unsigned long 
flags)
   size_t converter_index;
   int slot_found = 0;
   size_t i;
-  CONVERTER *registered_converter;
+  CONVERTER *converter;
 
   for (i = 0; i < converter_number; i++)
     {
@@ -250,29 +255,42 @@ new_converter (enum converter_format format, unsigned 
long flags)
       converter_index = converter_number;
       converter_number++;
     }
-  registered_converter = (CONVERTER *) malloc (sizeof (CONVERTER));
-  memset (registered_converter, 0, sizeof (CONVERTER));
+  converter = (CONVERTER *) malloc (sizeof (CONVERTER));
+  memset (converter, 0, sizeof (CONVERTER));
 
-  registered_converter->format = format;
+  converter->format = format;
 
   /* set low level data representations options */
   if (flags & CONVF_string_list)
-    registered_converter->ids_data_type = IDT_string_list;
+    converter->ids_data_type = IDT_string_list;
   else
-    registered_converter->ids_data_type = IDT_perl_hashmap;
+    converter->ids_data_type = IDT_perl_hashmap;
 
-  init_generic_converter (registered_converter);
+  init_generic_converter (converter);
 
-  converter_list[converter_index] = registered_converter;
-  registered_converter->converter_descriptor = converter_index +1;
+  converter_list[converter_index] = converter;
+  converter->converter_descriptor = converter_index +1;
 
   /*
-  fprintf (stderr, "REGISTER CONVERTER %zu %p %p %p\n", converter_index +1,
-                       converter, registered_converter, converter->document);
+  fprintf (stderr, "REGISTER CONVERTER %zu %d %p %p\n", converter_index +1,
+                                   format, converter, converter->document);
    */
   return converter_index +1;
 }
 
+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);
+}
+
 /* apply initialization information from one source */
 static void
 apply_converter_info (CONVERTER *converter,
@@ -301,7 +319,9 @@ apply_converter_info (CONVERTER *converter,
 }
 
 /* apply format_defaults and user_conf initialization information and call
-   format specific options setting and initialization functions */
+   format specific options setting and initialization functions.
+   Correspond to Perl _generic_converter_init and part of converter_initialize.
+ */
 void
 set_converter_init_information (CONVERTER *converter,
                             enum converter_format converter_format,
@@ -313,10 +333,10 @@ set_converter_init_information (CONVERTER *converter,
   if (converter_format != COF_none
       && converter_format_data[converter_format].converter_defaults)
     {
-      void (* converter_defaults) (CONVERTER *self,
+      void (* format_converter_defaults) (CONVERTER *self,
                  CONVERTER_INITIALIZATION_INFO *conf)
         = converter_format_data[converter_format].converter_defaults;
-      converter_defaults (converter, user_conf);
+      format_converter_defaults (converter, user_conf);
     }
 
   apply_converter_info (converter, user_conf, 1);
@@ -341,9 +361,11 @@ set_converter_init_information (CONVERTER *converter,
   if (converter_format != COF_none
       && converter_format_data[converter_format].converter_initialize)
     {
-      void (* converter_initialize) (CONVERTER *self)
+      /* beginning of Perl converter_initialize always done in C even when
+         called from Perl */
+      void (* format_converter_initialize) (CONVERTER *self)
         = converter_format_data[converter_format].converter_initialize;
-      converter_initialize (converter);
+      format_converter_initialize (converter);
     }
 }
 
@@ -371,17 +393,6 @@ destroy_converter_initialization_info 
(CONVERTER_INITIALIZATION_INFO *init_info)
   free (init_info);
 }
 
-void
-unregister_converter_descriptor (size_t converter_descriptor)
-{
-  CONVERTER *converter = retrieve_converter (converter_descriptor);
-  if (converter)
-    {
-      converter_list[converter_descriptor-1] = 0;
-      free (converter);
-    }
-}
-
 void
 converter_set_document (CONVERTER *converter, DOCUMENT *document)
 {
@@ -1586,17 +1597,29 @@ free_output_unit_files (FILE_NAME_PATH_COUNTER_LIST 
*output_unit_files)
 
 
 
+/* reset parser structures tied to a document to be ready for a
+   new conversion */
 void
-destroy_translated_commands (TRANSLATED_COMMAND *translated_commands)
+reset_generic_converter (CONVERTER *self)
 {
-  TRANSLATED_COMMAND *translated_command;
+  clear_output_files_information (&self->output_files_information);
+  clear_output_unit_files (&self->output_unit_files);
+}
 
-  for (translated_command = translated_commands;
-       translated_command->translation; translated_command++)
+void
+reset_converter (CONVERTER *self)
+{
+  enum converter_format converter_format = self->format;
+
+  if (converter_format != COF_none
+      && converter_format_data[converter_format].converter_reset)
     {
-      free (translated_command->translation);
+      void (* format_converter_reset) (CONVERTER *self)
+        = converter_format_data[converter_format].converter_reset;
+      format_converter_reset (self);
     }
-  free (translated_commands);
+
+  reset_generic_converter (self);
 }
 
 void
@@ -1655,6 +1678,35 @@ free_generic_converter (CONVERTER *self)
   free_strings_list (&self->small_strings);
 }
 
+void
+free_converter (CONVERTER *self)
+{
+  enum converter_format converter_format = self->format;
+
+  if (converter_format != COF_none
+      && converter_format_data[converter_format].converter_free)
+    {
+      void (* format_converter_free) (CONVERTER *self)
+        = converter_format_data[converter_format].converter_free;
+      format_converter_free (self);
+    }
+
+  free_generic_converter (self);
+}
+
+void
+destroy_converter (CONVERTER *converter)
+{
+  size_t converter_descriptor = converter->converter_descriptor;
+
+  free_converter (converter);
+
+  if (converter_descriptor)
+    converter_list[converter_descriptor-1] = 0;
+
+  free (converter);
+}
+
 
 
 /* XML conversion functions */
diff --git a/tp/Texinfo/XS/convert/converter.h 
b/tp/Texinfo/XS/convert/converter.h
index e64374bf93..e527baa615 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -96,6 +96,8 @@ typedef struct CONVERTER_FORMAT_DATA {
     void (* converter_defaults) (CONVERTER *self,
                                CONVERTER_INITIALIZATION_INFO *conf);
     void (* converter_initialize) (CONVERTER *self);
+    void (* converter_reset) (CONVERTER *self);
+    void (* converter_free) (CONVERTER *self);
 } CONVERTER_FORMAT_DATA;
 
 extern enum command_id no_brace_command_accent_upper_case[][2];
@@ -124,7 +126,6 @@ enum converter_format find_format_data_index (const char 
*format);
 
 CONVERTER *retrieve_converter (size_t converter_descriptor);
 size_t new_converter (enum converter_format format, unsigned long flags);
-void unregister_converter_descriptor (size_t converter_descriptor);
 
 void set_converter_init_information (CONVERTER *converter,
                             enum converter_format converter_format,
@@ -137,6 +138,9 @@ void destroy_converter_initialization_info (
 
 void converter_set_document (CONVERTER *converter, DOCUMENT *document);
 
+void reset_converter (CONVERTER *converter);
+void destroy_converter (CONVERTER *converter);
+
 void determine_files_and_directory (CONVERTER *self, const char *output_format,
                                     char **result);
 int create_destination_directory (CONVERTER *self,
@@ -200,9 +204,6 @@ void set_file_path (CONVERTER *self, const char *filename, 
const char *filepath,
 void clear_output_unit_files (FILE_NAME_PATH_COUNTER_LIST *output_unit_files);
 void free_output_unit_files (FILE_NAME_PATH_COUNTER_LIST *output_unit_files);
 
-void destroy_translated_commands (TRANSLATED_COMMAND *translated_commands);
-void free_generic_converter (CONVERTER *self);
-
 void xml_format_text_with_numeric_entities (const char *text, TEXT *result);
 char *xml_numeric_entity_accent (enum command_id cmd, const char *text);
 char *xml_comment (CONVERTER *converter, const char *text);
diff --git a/tp/Texinfo/XS/convert/html_converter_finish.h 
b/tp/Texinfo/XS/convert/html_converter_finish.h
new file mode 100644
index 0000000000..ef2c7cf924
--- /dev/null
+++ b/tp/Texinfo/XS/convert/html_converter_finish.h
@@ -0,0 +1,10 @@
+/* html_converter_finish.h - convert_html.c functions called in converter.c
+   finish */
+#ifndef HTML_CONVERTER_FINISH_H
+#define HTML_CONVERTER_FINISH_H
+
+void html_reset_converter (CONVERTER *self);
+
+void html_free_converter (CONVERTER *self);
+
+#endif



reply via email to

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