texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Mon, 30 Sep 2024 12:46:56 -0400 (EDT)

branch: master
commit db6a2571db903c78cc6f232dc21294aabc778b77
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jul 21 14:29:17 2024 +0200

    * tp/Texinfo/Convert/Converter.pm (set_document): remove a redundant
    condition on $XS_convert.
    
    * tp/Texinfo/XS/convert/ConvertXS.xs (converter_initialize):
    converter_descriptor is necessarily set.
    
    * tp/Texinfo/XS/main/get_perl_info.c (converter_set_document_from_sv):
    return the converter.
    
    * tp/Texinfo/Convert/Converter.pm (set_document),
    tp/Texinfo/XS/convert/ConvertXS.xs (converter_set_document),
    tp/Texinfo/XS/main/build_perl_info.c (build_convert_text_options): add
    build_convert_text_options.  Setup more Perl structures in
    converter_set_document in ConvertXS.xs, renaming
    converter_set_document_from_sv to converter_set_document.
---
 ChangeLog                                       | 18 +++++++++
 tp/Texinfo/Convert/Converter.pm                 | 18 ++++-----
 tp/Texinfo/XS/convert/ConvertXS.xs              | 42 ++++++++++++++------
 tp/Texinfo/XS/convert/get_converter_perl_info.c |  4 +-
 tp/Texinfo/XS/main/build_perl_info.c            | 53 +++++++++++++++++++++++++
 tp/Texinfo/XS/main/build_perl_info.h            |  5 +++
 tp/Texinfo/XS/main/get_perl_info.h              |  2 +-
 tp/Texinfo/XS/main/utils.c                      |  2 +-
 8 files changed, 120 insertions(+), 24 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0ec12dfb01..a9db8e2e76 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2024-07-21  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/Converter.pm (set_document): remove a redundant
+       condition on $XS_convert.
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs (converter_initialize):
+       converter_descriptor is necessarily set.
+
+       * tp/Texinfo/XS/main/get_perl_info.c (converter_set_document_from_sv):
+       return the converter.
+
+       * tp/Texinfo/Convert/Converter.pm (set_document),
+       tp/Texinfo/XS/convert/ConvertXS.xs (converter_set_document),
+       tp/Texinfo/XS/main/build_perl_info.c (build_convert_text_options): add
+       build_convert_text_options.  Setup more Perl structures in
+       converter_set_document in ConvertXS.xs, renaming
+       converter_set_document_from_sv to converter_set_document.
+
 2024-07-21  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/ConvertXS.xs (converter_set_document_from_sv),
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 306c398ae3..e97d10f5e7 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -71,8 +71,6 @@ our $module_loaded = 0;
 
 my %XS_overrides = (
   # XS only called if there is an associated XS converter
-  "Texinfo::Convert::Converter::_internal_converter_initialize",
-   => "Texinfo::Convert::ConvertXS::converter_initialize",
   "Texinfo::Convert::Converter::_XS_set_conf"
    => "Texinfo::Convert::ConvertXS::set_conf",
   "Texinfo::Convert::Converter::_XS_force_conf"
@@ -83,6 +81,8 @@ my %XS_overrides = (
    => "Texinfo::Convert::ConvertXS::converter_set_document",
 
   # fully overriden for all the converters
+  "Texinfo::Convert::Converter::_internal_converter_initialize",
+   => "Texinfo::Convert::ConvertXS::converter_initialize",
   "Texinfo::Convert::Converter::get_converter_errors"
    => "Texinfo::Convert::ConvertXS::get_converter_errors",
   "Texinfo::Convert::Converter::converter_line_error"
@@ -244,16 +244,16 @@ sub set_document($$)
   my $converter = shift;
   my $document = shift;
 
-  if ($converter->{'converter_descriptor'} and $XS_convert) {
+  if ($converter->{'converter_descriptor'}) {
     _XS_set_document($converter, $document);
-  }
-
-  $converter->{'document'} = $document;
+  } else {
+    $converter->{'document'} = $document;
 
-  Texinfo::Common::set_output_encoding($converter, $document);
+    Texinfo::Common::set_output_encoding($converter, $document);
 
-  $converter->{'convert_text_options'}
-   = Texinfo::Convert::Text::copy_options_for_convert_text($converter);
+    $converter->{'convert_text_options'}
+     = Texinfo::Convert::Text::copy_options_for_convert_text($converter);
+  }
 
   # In general, OUTPUT_PERL_ENCODING set below is needed for the output()
   # entry point through Texinfo::Common::output_files_open_out.  It is
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 880668ffd9..9be03d4ad1 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -81,22 +81,40 @@ void
 converter_initialize (SV *converter_in)
       PREINIT:
          size_t converter_descriptor;
+         const CONVERTER *self;
+         HV *converter_hv;
+         HV *expanded_formats_hv;
       CODE:
          converter_descriptor = converter_initialize (converter_in);
-         if (converter_descriptor)
-           {
-             const CONVERTER *self = retrieve_converter (converter_descriptor);
-             HV *converter_hv = (HV *)SvRV (converter_in);
-             HV *expanded_formats_hv
-               = build_expanded_formats (self->expanded_formats);
-             hv_store (converter_hv, "expanded_formats",
-                       strlen ("expanded_formats"),
-                       newRV_inc ((SV *) expanded_formats_hv), 0);
-           }
+         self = retrieve_converter (converter_descriptor);
+         converter_hv = (HV *)SvRV (converter_in);
+         expanded_formats_hv
+           = build_expanded_formats (self->expanded_formats);
+         hv_store (converter_hv, "expanded_formats",
+                   strlen ("expanded_formats"),
+                   newRV_inc ((SV *) expanded_formats_hv), 0);
 
 void
-converter_set_document_from_sv (SV *converter_in, SV *document_in)
-
+converter_set_document (SV *converter_in, SV *document_in)
+      PREINIT:
+        CONVERTER *self;
+        HV *converter_hv;
+      CODE:
+        /* if a converter is properly initialized, the XS converter should
+           always be found when XS is used */
+        self = converter_set_document_from_sv (converter_in, document_in);
+        converter_hv = (HV *)SvRV (converter_in);
+        SvREFCNT_inc (document_in);
+        hv_store (converter_hv, "document", strlen ("document"),
+                  document_in, 0);
+        if (self && self->convert_text_options)
+          {
+            SV *text_options_sv
+             = build_convert_text_options (self->convert_text_options);
+            hv_store (converter_hv,
+                      "convert_text_options", strlen("convert_text_options"),
+                      text_options_sv, 0);
+          }
 
 void
 set_conf (SV *converter_in, conf, SV *value)
diff --git a/tp/Texinfo/XS/convert/get_converter_perl_info.c 
b/tp/Texinfo/XS/convert/get_converter_perl_info.c
index f37122c2fa..481b8086c0 100644
--- a/tp/Texinfo/XS/convert/get_converter_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_converter_perl_info.c
@@ -68,7 +68,7 @@ get_sv_converter (SV *sv_in, const char *warn_string)
   return converter;
 }
 
-void
+CONVERTER *
 converter_set_document_from_sv (SV *converter_in, SV *document_in)
 {
   CONVERTER *converter;
@@ -80,6 +80,8 @@ converter_set_document_from_sv (SV *converter_in, SV 
*document_in)
   document = get_sv_document_document (document_in, 0);
 
   converter_set_document (converter, document);
+
+  return converter;
 }
 
 void
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 344def5ffa..bf37fba98f 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -58,6 +58,8 @@
 #include "convert_to_texinfo.h"
 #include "document.h"
 #include "output_unit.h"
+/* for TEXT_OPTIONS */
+#include "convert_to_text.h"
 #include "get_perl_info.h"
 #include "build_perl_info.h"
 
@@ -2648,6 +2650,57 @@ build_expanded_formats (const EXPANDED_FORMAT 
*expanded_formats)
   return expanded_hv;
 }
 
+SV *
+build_convert_text_options (TEXT_OPTIONS *text_options)
+{
+  HV *text_options_hv;
+  HV *expanded_formats_hv;
+
+  dTHX;
+
+  text_options_hv = newHV ();
+
+#define STORE(key, sv) hv_store (text_options_hv, key, strlen (key), sv, 0)
+
+  if (text_options->ASCII_GLYPH)
+    STORE("ASCII_GLYPH", newSViv (1));
+
+  if (text_options->NUMBER_SECTIONS)
+    STORE("NUMBER_SECTIONS", newSViv (1));
+
+  if (text_options->TEST)
+    STORE("TEST", newSViv (1));
+
+  if (text_options->sort_string)
+    STORE("sort_string", newSViv (1));
+
+  if (text_options->encoding)
+    STORE("enabled_encoding", newSVpv_utf8 (text_options->encoding, 0));
+
+  if (text_options->set_case)
+    STORE("set_case", newSViv (text_options->set_case));
+
+  if (text_options->code_state)
+    STORE("_code_state", newSViv (text_options->code_state));
+
+  expanded_formats_hv = build_expanded_formats 
(text_options->expanded_formats);
+  STORE("expanded_formats", newRV_noinc ((SV *)expanded_formats_hv));
+
+  if (text_options->include_directories.number > 0)
+    {
+      AV *av = build_string_list (&text_options->include_directories, 
svt_byte);
+      STORE("INCLUDE_DIRECTORIES", newRV_noinc ((SV *) av));
+    }
+
+  if (text_options->converter && text_options->converter->hv)
+    {
+      STORE("converter", newRV_inc ((SV *) text_options->converter->hv));
+    }
+#undef STORE
+
+  return newRV_noinc ((SV *)text_options_hv);
+}
+
 SV *
 find_idx_name_entry_number_sv (HV *indices_information_hv,
                                const char* index_name, int entry_number,
diff --git a/tp/Texinfo/XS/main/build_perl_info.h 
b/tp/Texinfo/XS/main/build_perl_info.h
index 0856a067ec..7aa1642700 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -12,6 +12,9 @@
 #include "document_types.h"
 #include "converter_types.h"
 
+/* to avoid a dependency on "convert_to_text.h" */
+struct TEXT_OPTIONS;
+
 void perl_only_free (void *ptr);
 void *perl_only_malloc (size_t size);
 char *perl_only_strdup (const char *s);
@@ -95,6 +98,8 @@ SV *get_conf (const CONVERTER *converter, const char 
*option_name);
 
 HV *build_expanded_formats (const EXPANDED_FORMAT *expanded_formats);
 
+SV *build_convert_text_options (struct TEXT_OPTIONS *text_options);
+
 HV *latex_build_options_for_convert_to_latex_math (const CONVERTER *converter);
 
 void build_tree_to_build (ELEMENT_LIST *tree_to_build);
diff --git a/tp/Texinfo/XS/main/get_perl_info.h 
b/tp/Texinfo/XS/main/get_perl_info.h
index f7e846bda5..d092480400 100644
--- a/tp/Texinfo/XS/main/get_perl_info.h
+++ b/tp/Texinfo/XS/main/get_perl_info.h
@@ -46,7 +46,7 @@ void force_sv_conf (CONVERTER *converter, const char *conf, 
SV *value);
 CONVERTER *get_sv_converter (SV *sv_in, const char *warn_string);
 int converter_initialize (SV *converter_sv);
 void reset_output_init_conf (SV *sv_in);
-void converter_set_document_from_sv (SV *converter_in, SV *document_in);
+CONVERTER *converter_set_document_from_sv (SV *converter_in, SV *document_in);
 
 INDEX_ENTRY *find_index_entry_sv (const SV *index_entry_sv,
                      INDEX_LIST *indices_info,
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 7e53f6c59b..c6b3dce6f2 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -1096,7 +1096,7 @@ set_conf_string (OPTION *option, const char *value)
 }
 
 /* In perl, OUTPUT_PERL_ENCODING is set too.  Note that if the perl
-   version is called later on, the OUTPUT_PERL_ENCODING value will be re-set */
+   version is called later on, the OUTPUT_ENCODING_NAME value will be re-set */
 void
 set_output_encoding (OPTIONS *customization_information, DOCUMENT *document)
 {



reply via email to

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