texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/main/get_perl_info.c (copy_sv_opt


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/main/get_perl_info.c (copy_sv_options_for_convert_text): use a FETCH macro to simplify code.
Date: Sun, 07 Jan 2024 04:17:08 -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 e84ca8345a * tp/Texinfo/XS/main/get_perl_info.c 
(copy_sv_options_for_convert_text): use a FETCH macro to simplify code.
e84ca8345a is described below

commit e84ca8345afb87b7d8f59e5fdb1e2e4bd611eeb3
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jan 7 10:17:07 2024 +0100

    * tp/Texinfo/XS/main/get_perl_info.c
    (copy_sv_options_for_convert_text): use a FETCH macro to simplify
    code.
    
    * tp/Texinfo/Convert/Text.pm (convert_to_text, output),
    tp/Texinfo/XS/convert/ConvertXS.xs (text_convert_tree),
    tp/Texinfo/XS/main/get_perl_info.c (copy_sv_options_for_convert_text):
    pass text options directly to XS.  Remove select_text_options.  Remove
    code that cannot be reached.
---
 ChangeLog                          | 12 ++++++++
 tp/Texinfo/Convert/Text.pm         | 52 +++-------------------------------
 tp/Texinfo/XS/convert/ConvertXS.xs |  9 +++---
 tp/Texinfo/XS/main/get_perl_info.c | 57 +++++++++++++++++---------------------
 4 files changed, 45 insertions(+), 85 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9ccad3c6a0..1b6411793f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-01-07  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/get_perl_info.c
+       (copy_sv_options_for_convert_text): use a FETCH macro to simplify
+       code.
+
+       * tp/Texinfo/Convert/Text.pm (convert_to_text, output),
+       tp/Texinfo/XS/convert/ConvertXS.xs (text_convert_tree),
+       tp/Texinfo/XS/main/get_perl_info.c (copy_sv_options_for_convert_text):
+       pass text options directly to XS.  Remove select_text_options.  Remove
+       code that cannot be reached.
+
 2024-01-06  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/convert_html.c (html_converter_initialize),
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index 1e20caf4c6..d36e1f06b9 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -422,37 +422,8 @@ sub copy_options_for_convert_text($;$)
   return %options;
 }
 
-# select converter options passed.
-sub select_text_options($)
-{
-  my $options = shift;
-  my $selected_options = {};
-
-  foreach my $option (@text_indicator_converter_options,
-                      'INCLUDE_DIRECTORIES',
-                      'expanded_formats',
-                      # non-converter indicator options
-       'enabled_encoding', 'sc', 'code', 'sort_string') {
-    if (defined($options->{$option})) {
-      $selected_options->{$option} = $options->{$option};
-    }
-  }
-
-  # called through convert_to_text with a converter in text options
-  if ($options->{'converter'}
-      and $options->{'converter'}->{'conf'}) {
-    $selected_options->{'other_converter_options'}
-       = $options->{'converter'}->{'conf'};
-  }
-
-  $selected_options->{'self_converter_options'} = $options;
-
-  return $selected_options;
-}
-
-# This is used if the document is available for XS, but XS is not
-# used (most likely $TEXINFO_XS_CONVERT is 0).
-sub _convert_tree_with_XS($$;$)
+# Will never be called, used for the overrride.
+sub _convert_tree_with_XS($$)
 {
 }
 
@@ -482,15 +453,7 @@ sub convert_to_text($;$)
 
   # Interface with XS converter.
   if ($XS_convert and defined($root->{'tree_document_descriptor'})) {
-    my $selected_options = select_text_options($options);
-    my $XS_result = _convert_tree_with_XS($selected_options, $root, $options);
-    if (defined ($XS_result)) {
-      return $XS_result;
-    } else {
-      my $result = _convert($root, $options);
-      print STDERR "NO XS Text: $root->{'tree_document_descriptor'}\n";
-      cluck();
-    }
+    return _convert_tree_with_XS($options, $root);
   }
 
   return _convert($root, $options);
@@ -990,14 +953,7 @@ sub output($$)
   my $result;
   # Interface with XS converter.
   if ($XS_convert and defined($root->{'tree_document_descriptor'})) {
-    my $selected_options = select_text_options($self);
-    my $XS_result = _convert_tree_with_XS($selected_options, $root, $self);
-    if (defined ($XS_result)) {
-      $result = $XS_result;
-    } else {
-      print STDERR "NO XS Text: $root->{'tree_document_descriptor'}\n";
-      cluck();
-    }
+    $result = _convert_tree_with_XS($self, $root);
   } else {
     $result = _convert($root, $self);
   }
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index b0b59660d2..41d46b935a 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -303,16 +303,15 @@ plain_texinfo_convert_tree (SV *tree_in)
     OUTPUT:
         RETVAL
 
-# unused argument is used in the overriden function if XS is not used
 SV *
-text_convert_tree (SV *text_options_in, SV *tree_in, unused=0)
+text_convert_tree (SV *options_in, SV *tree_in)
     PREINIT:
         DOCUMENT *document = 0;
         TEXT_OPTIONS *text_options = 0;
     CODE:
-        /* FIXME warning/error if not found? */
-        document = get_sv_tree_document (tree_in, 0);
-        text_options = copy_sv_options_for_convert_text (text_options_in);
+        /* The caller checks that there is a descriptor */
+        document = get_sv_tree_document (tree_in, "text_convert_tree");
+        text_options = copy_sv_options_for_convert_text (options_in);
         if (document)
           {
             /* text_options is destroyed in text_convert */
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index f49f87fd63..ce7c3641e1 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -824,65 +824,58 @@ force_conf (CONVERTER *converter, const char *conf, SV 
*value)
 
 /* map hash reference of Convert::Text options to TEXT_OPTIONS */
 /* TODO more to do */
+#define FETCH(key) key##_sv = hv_fetch (hv_in, #key, strlen(#key), 0);
 TEXT_OPTIONS *
 copy_sv_options_for_convert_text (SV *sv_in)
 {
   HV *hv_in;
-  SV **test_option_sv;
-  SV **include_directories_sv;
-  SV **other_converter_options_sv;
-  SV **self_converter_options_sv;
+  SV **TEST_sv;
+  SV **INCLUDE_DIRECTORIES_sv;
+  SV **converter_sv;
   SV **enabled_encoding_sv;
-  SV **sort_string_option_sv;
+  SV **sort_string_sv;
   TEXT_OPTIONS *text_options = new_text_options ();
 
   dTHX;
 
   hv_in = (HV *)SvRV (sv_in);
 
-  test_option_sv = hv_fetch (hv_in, "TEST", strlen ("TEST"), 0);
-  if (test_option_sv)
-    text_options->TEST = SvIV (*test_option_sv);
+  FETCH(TEST)
+  if (TEST_sv)
+    text_options->TEST = SvIV (*TEST_sv);
 
-  sort_string_option_sv = hv_fetch (hv_in, "sort_string",
-                                    strlen ("sort_string"), 0);
-  if (sort_string_option_sv)
-    text_options->sort_string = SvIV (*sort_string_option_sv);
+  FETCH(sort_string)
+  if (sort_string_sv)
+    text_options->sort_string = SvIV (*sort_string_sv);
 
-  enabled_encoding_sv = hv_fetch (hv_in, "enabled_encoding",
-                                  strlen ("enabled_encoding"), 0);
+  FETCH(enabled_encoding)
   if (enabled_encoding_sv)
     text_options->encoding = strdup (SvPVutf8_nolen (*enabled_encoding_sv));
 
-  include_directories_sv = hv_fetch (hv_in, "INCLUDE_DIRECTORIES",
-                                     strlen ("INCLUDE_DIRECTORIES"), 0);
+  FETCH(INCLUDE_DIRECTORIES)
 
-  if (include_directories_sv)
-    add_svav_to_string_list (*include_directories_sv,
+  if (INCLUDE_DIRECTORIES_sv)
+    add_svav_to_string_list (*INCLUDE_DIRECTORIES_sv,
                              &text_options->include_directories, svt_dir);
 
   get_expanded_formats (hv_in, &text_options->expanded_formats);
 
-  other_converter_options_sv = hv_fetch (hv_in, "other_converter_options",
-                                         strlen ("other_converter_options"), 
0);
-
-  if (other_converter_options_sv)
+  FETCH(converter)
+  if (converter_sv)
     {
-      text_options->other_converter_options
-         = init_copy_sv_options (*other_converter_options_sv, 0, 1);
+      HV *converter_hv = (HV *) SvRV (*converter_sv);
+      SV **conf_sv = hv_fetch (converter_hv, "conf", strlen ("conf"), 0);
+      if (conf_sv)
+        text_options->other_converter_options
+          = init_copy_sv_options (*conf_sv, 0, 1);
     }
 
-  self_converter_options_sv = hv_fetch (hv_in, "self_converter_options",
-                                         strlen ("self_converter_options"), 0);
-
-  if (self_converter_options_sv)
-    {
-      text_options->self_converter_options
-         = init_copy_sv_options (*self_converter_options_sv, 0, 1);
-    }
+  text_options->self_converter_options
+     = init_copy_sv_options (sv_in, 0, 1);
 
   return text_options;
 }
+#undef FETCH
 
 int
 html_get_direction_index (CONVERTER *converter, const char *direction)



reply via email to

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