texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/configure.ac (usable_getenv_in_XS


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/configure.ac (usable_getenv_in_XS) (HAVE_USABLE_GETENV_IN_XS): add a define set if getenv can safely be used in Perl, based on Perl version >= 5.38.
Date: Mon, 14 Oct 2024 13:49:34 -0400

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 23b421d11e * tp/Texinfo/XS/configure.ac (usable_getenv_in_XS) 
(HAVE_USABLE_GETENV_IN_XS): add a define set if getenv can safely be used in 
Perl, based on Perl version >= 5.38.
23b421d11e is described below

commit 23b421d11eeccb30345f9691046424a4a957bd25
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Oct 14 19:49:08 2024 +0200

    * tp/Texinfo/XS/configure.ac (usable_getenv_in_XS)
    (HAVE_USABLE_GETENV_IN_XS): add a define set if getenv can safely be
    used in Perl, based on Perl version >= 5.38.
    
    * tp/Texinfo/XS/main/call_perl_function.c
    (call_translations_translate_string),
    tp/Texinfo/XS/main/replace_perl_api_call.c
    (call_translations_translate_string): add call to
    Texinfo::Translation::translate_string.
    
    * tp/Texinfo/Translations.pm (_XS_configure),
    tp/Texinfo/XS/convert/texinfo.c (txi_setup),
    tp/Texinfo/XS/main/DocumentXS.xs
    (configure_output_strings_translations),
    tp/Texinfo/XS/main/translations.c (use_external_translate_string)
    (configure_output_strings_translations, translate_string): add an
    argument to configure_output_strings_translations to specify whether
    to call Perl translate_string or not.  Set the variable
    use_external_translate_string variable based on the argument, or on
    HAVE_USABLE_GETENV_IN_XS if the argument is 0.  Use
    use_external_translate_string in translate_string to determine if
    call_translations_translate_string should be called.
    
    Report from Gavin.
---
 ChangeLog                                  | 27 ++++++++++++++++++
 tp/Texinfo/Translations.pm                 |  2 +-
 tp/Texinfo/XS/configure.ac                 | 17 +++++++++--
 tp/Texinfo/XS/convert/texinfo.c            |  2 +-
 tp/Texinfo/XS/main/DocumentXS.xs           |  6 ++--
 tp/Texinfo/XS/main/call_perl_function.c    | 46 ++++++++++++++++++++++++++++++
 tp/Texinfo/XS/main/call_perl_function.h    |  4 +++
 tp/Texinfo/XS/main/replace_perl_api_call.c |  7 +++++
 tp/Texinfo/XS/main/translations.c          | 37 +++++++++++++++++++++---
 tp/Texinfo/XS/main/translations.h          |  3 +-
 10 files changed, 140 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 390280fc74..d9b0d7dd8f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,33 @@
        (Node anchors are broken as this is from an old version of
        texi2html (1.52), but better than nothing.)
 
+2024-10-13  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/configure.ac (usable_getenv_in_XS)
+       (HAVE_USABLE_GETENV_IN_XS): add a define set if getenv can safely be
+       used in Perl, based on Perl version >= 5.38.
+
+       * tp/Texinfo/XS/main/call_perl_function.c
+       (call_translations_translate_string),
+       tp/Texinfo/XS/main/replace_perl_api_call.c
+       (call_translations_translate_string): add call to
+       Texinfo::Translation::translate_string.
+
+       * tp/Texinfo/Translations.pm (_XS_configure),
+       tp/Texinfo/XS/convert/texinfo.c (txi_setup),
+       tp/Texinfo/XS/main/DocumentXS.xs
+       (configure_output_strings_translations),
+       tp/Texinfo/XS/main/translations.c (use_external_translate_string)
+       (configure_output_strings_translations, translate_string): add an
+       argument to configure_output_strings_translations to specify whether
+       to call Perl translate_string or not.  Set the variable
+       use_external_translate_string variable based on the argument, or on
+       HAVE_USABLE_GETENV_IN_XS if the argument is 0.  Use
+       use_external_translate_string in translate_string to determine if
+       call_translations_translate_string should be called.
+
+       Report from Gavin.
+
 2024-10-13  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Makefile.tres, tp/t/html_tests.t (inline_in_node): test showing
diff --git a/tp/Texinfo/Translations.pm b/tp/Texinfo/Translations.pm
index 2d4ac68cf7..95efbab038 100644
--- a/tp/Texinfo/Translations.pm
+++ b/tp/Texinfo/Translations.pm
@@ -81,7 +81,7 @@ my $DEFAULT_LANGUAGE = 'en';
 my $messages_textdomain = 'texinfo';
 my $strings_textdomain = 'texinfo_document';
 
-sub _XS_configure($;$)
+sub _XS_configure($;$$)
 {
   # do nothing if there is no XS code loaded
 }
diff --git a/tp/Texinfo/XS/configure.ac b/tp/Texinfo/XS/configure.ac
index 6623abfc06..1dc5c1aa9b 100644
--- a/tp/Texinfo/XS/configure.ac
+++ b/tp/Texinfo/XS/configure.ac
@@ -18,6 +18,21 @@ AC_CONFIG_MACRO_DIR([gnulib/m4])
 CONVERTER=texi2any
 AC_SUBST([CONVERTER])
 
+AC_PATH_PROG([PERL], [perl])
+
+usable_getenv_in_XS=no
+AC_MSG_CHECKING([Perl XS with usable getenv])
+if $PERL -e "use 5.038" >/dev/null ; then
+  usable_getenv_in_XS=yes
+fi
+AC_MSG_RESULT($usable_getenv_in_XS)
+
+AC_DEFINE([HAVE_USABLE_GETENV_IN_XS], [], [whether getenv can be used in XS])
+
+if test $usable_getenv_in_XS = yes ; then
+  AC_DEFINE([HAVE_USABLE_GETENV_IN_XS], [1])
+fi
+
 b='\'
 d='$'
 o='@<:@' dnl quadrigraph for [ - see autoconf documentation
@@ -99,8 +114,6 @@ PACKAGE_XS_VERSION=0
 # is given, we still need to configure this directory minimally, so that
 # "make dist" will work.
 if test x$disable_xs != xyes; then
-  AC_PATH_PROG([PERL], [perl])
-
   #PACKAGE_XS_VERSION=`${PERL} -e 'use version; print 
version->declare('"$PACKAGE_VERSION"')->numify;'`
   PACKAGE_XS_VERSION=`echo $PACKAGE_VERSION | sed 's/-/./g'`
 
diff --git a/tp/Texinfo/XS/convert/texinfo.c b/tp/Texinfo/XS/convert/texinfo.c
index cfac5145fd..72ad411f97 100644
--- a/tp/Texinfo/XS/convert/texinfo.c
+++ b/tp/Texinfo/XS/convert/texinfo.c
@@ -51,7 +51,7 @@ txi_setup (const char *localesdir, int texinfo_uninstalled,
                  const char *converterdatadir, const char *top_srcdir)
 {
   if (localesdir)
-    configure_output_strings_translations (localesdir, 0);
+    configure_output_strings_translations (localesdir, 0, -1);
 
   converter_setup (texinfo_uninstalled, tp_builddir,
                    converterdatadir, top_srcdir);
diff --git a/tp/Texinfo/XS/main/DocumentXS.xs b/tp/Texinfo/XS/main/DocumentXS.xs
index e726720827..d23715f303 100644
--- a/tp/Texinfo/XS/main/DocumentXS.xs
+++ b/tp/Texinfo/XS/main/DocumentXS.xs
@@ -52,11 +52,13 @@ PROTOTYPES: ENABLE
 # More related to translations than to the Texinfo Document, but we do not
 # to add another XS file for only one function.
 void
-configure_output_strings_translations (localesdir, 
strings_textdomain="texinfo_document")
+configure_output_strings_translations (localesdir, 
strings_textdomain="texinfo_document", int use_external_translate_string=0)
        char *localesdir = (char *)SvPVbyte_nolen($arg);
        char *strings_textdomain;
       CODE:
-       configure_output_strings_translations (localesdir, strings_textdomain);
+       configure_output_strings_translations (localesdir,
+                                              strings_textdomain,
+                                              use_external_translate_string);
 
 # Since build_document is called, the underlying document HV is destroyed
 # instead of being reused, which is somewhat inefficient.  Doing something
diff --git a/tp/Texinfo/XS/main/call_perl_function.c 
b/tp/Texinfo/XS/main/call_perl_function.c
index 6f7c9fe55e..53bfaa2fd6 100644
--- a/tp/Texinfo/XS/main/call_perl_function.c
+++ b/tp/Texinfo/XS/main/call_perl_function.c
@@ -122,6 +122,52 @@ call_nodenamenormalization_unicode_to_transliterate (const 
char *text)
   return result;
 }
 
+char *
+call_translations_translate_string (const char *string, const char *in_lang,
+                                    const char *translation_context)
+{
+  int count;
+  char *result;
+  char *result_ret;
+  STRLEN len;
+  SV *result_sv;
+
+  dTHX;
+
+  dSP;
+
+  ENTER;
+  SAVETMPS;
+
+  PUSHMARK(SP);
+  EXTEND(SP, 3);
+
+  PUSHs(sv_2mortal (newSVpv_utf8 (string, 0)));
+  PUSHs(sv_2mortal (newSVpv_utf8 (in_lang, 0)));
+  PUSHs(sv_2mortal (newSVpv_utf8 (translation_context, 0)));
+  PUTBACK;
+
+  count = call_pv (
+    "Texinfo::Translation::translate_string",
+    G_SCALAR);
+
+  SPAGAIN;
+
+  if (count != 1)
+    croak ("translate_string should return 1 item\n");
+
+  result_sv = POPs;
+  result_ret = SvPVutf8 (result_sv, len);
+  result = non_perl_strndup (result_ret, len);
+
+  PUTBACK;
+
+  FREETMPS;
+  LEAVE;
+
+  return result;
+}
+
 const void *
 call_setup_collator (int use_unicode_collation, const char *locale_lang)
 {
diff --git a/tp/Texinfo/XS/main/call_perl_function.h 
b/tp/Texinfo/XS/main/call_perl_function.h
index 7fc450a4fd..845aaf0f70 100644
--- a/tp/Texinfo/XS/main/call_perl_function.h
+++ b/tp/Texinfo/XS/main/call_perl_function.h
@@ -10,6 +10,10 @@ void call_common_set_output_perl_encoding (const CONVERTER 
*self);
 
 char *call_nodenamenormalization_unicode_to_transliterate (const char *text);
 
+char *call_translations_translate_string (const char *string,
+                                          const char *in_lang,
+                                          const char *translation_context);
+
 const void *call_setup_collator (int use_unicode_collation,
                                  const char *locale_lang);
 
diff --git a/tp/Texinfo/XS/main/replace_perl_api_call.c 
b/tp/Texinfo/XS/main/replace_perl_api_call.c
index fa28d4371b..063d7738d0 100644
--- a/tp/Texinfo/XS/main/replace_perl_api_call.c
+++ b/tp/Texinfo/XS/main/replace_perl_api_call.c
@@ -62,6 +62,13 @@ call_nodenamenormalization_unicode_to_transliterate (const 
char *text)
   return result;
 }
 
+char *
+call_translations_translate_string (const char *string, const char *in_lang,
+                                    const char *translation_context)
+{
+  return strdup (string);
+}
+
 /* happens if not linked against Perl and a collation locale was specified
    but not found */
 const void *
diff --git a/tp/Texinfo/XS/main/translations.c 
b/tp/Texinfo/XS/main/translations.c
index 2bda5c835f..d39aedaa67 100644
--- a/tp/Texinfo/XS/main/translations.c
+++ b/tp/Texinfo/XS/main/translations.c
@@ -41,6 +41,7 @@
 #include "document.h"
 #include "conf.h"
 #include "api.h"
+#include "call_perl_function.h"
 /* for debugging */
 #include "convert_to_texinfo.h"
 #include "translations.h"
@@ -54,14 +55,33 @@ static char *locale_command = 0;
 
 static const char *strings_textdomain = "texinfo_document";
 
+static int use_external_translate_string;
+
+/* USE_EXTERNAL_TRANSLATE_STRING_IN:
+    -1: never call external (Perl) translate string
+    0: default, use HAVE_USABLE_GETENV_IN_XS value
+    1: always call external (Perl) translate string
+ */
 void
 configure_output_strings_translations (const char *localesdir,
-                                       const char *strings_textdomain_in)
+                                       const char *strings_textdomain_in,
+                                       int use_external_translate_string_in)
 {
   const char *textdomain_directory;
   if (strings_textdomain_in)
     strings_textdomain = strings_textdomain_in;
 
+  if (use_external_translate_string_in != 0)
+    use_external_translate_string = use_external_translate_string_in;
+  else
+    {
+  #ifndef HAVE_USABLE_GETENV_IN_XS
+      use_external_translate_string = 1;
+  #else
+      use_external_translate_string = 0;
+  #endif
+    }
+
   #ifdef ENABLE_NLS
   textdomain_directory = bindtextdomain (strings_textdomain, localesdir);
 
@@ -152,7 +172,7 @@ switch_messages_locale (void)
 }
 
 char *
-translate_string (const char * string, const char *in_lang,
+translate_string (const char *string, const char *in_lang,
                   const char *translation_context)
 {
   const char *lang = in_lang;
@@ -177,9 +197,18 @@ translate_string (const char * string, const char *in_lang,
     }
 
 #ifndef ENABLE_NLS
-  translated_string = strdup (string);
-  return translated_string;
+  if (use_external_translate_string < 0)
+    {
+      translated_string = strdup (string);
+      return translated_string;
+    }
+  else
+    return call_translations_translate_string (string, in_lang,
+                                               translation_context);
 #endif
+  if (use_external_translate_string > 0)
+    return call_translations_translate_string (string, in_lang,
+                                               translation_context);
 
   /* with the following code valgrind reports issues in perl memory */
 
diff --git a/tp/Texinfo/XS/main/translations.h 
b/tp/Texinfo/XS/main/translations.h
index e01ed529ac..f5a76b3d86 100644
--- a/tp/Texinfo/XS/main/translations.h
+++ b/tp/Texinfo/XS/main/translations.h
@@ -22,7 +22,8 @@ typedef struct NAMED_STRING_ELEMENT_LIST {
 } NAMED_STRING_ELEMENT_LIST;
 
 void configure_output_strings_translations (const char *localesdir,
-                                            const char *strings_textdomain_in);
+                                            const char *strings_textdomain_in,
+                                         int use_external_translate_string_in);
 
 char *translate_string (const char * string, const char *lang,
                         const char *translation_context);



reply via email to

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