texinfo-commits
[Top][All Lists]
Advanced

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

[6482] TEXINFO_XS env variable


From: Gavin D. Smith
Subject: [6482] TEXINFO_XS env variable
Date: Wed, 29 Jul 2015 11:34:48 +0000

Revision: 6482
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6482
Author:   gavin
Date:     2015-07-29 11:34:46 +0000 (Wed, 29 Jul 2015)
Log Message:
-----------
TEXINFO_XS env variable

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2015-07-28 20:20:05 UTC (rev 6481)
+++ trunk/ChangeLog     2015-07-29 11:34:46 UTC (rev 6482)
@@ -1,3 +1,8 @@
+2015-07-29  Gavin Smith  <address@hidden>
+
+       * tp/Texinfo/Convert/XSParagraph/XSParagraph.pm: Heed TEXINFO_XS
+       environmental variable.  Idea by Karl Berry.
+
 2015-07-28  Gavin Smith  <address@hidden>
 
        * tp/Texinfo/Convert/XSParagraph/xspara.c (add_text): Check for

Modified: trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm 2015-07-28 20:20:05 UTC 
(rev 6481)
+++ trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm 2015-07-29 11:34:46 UTC 
(rev 6482)
@@ -47,21 +47,52 @@
 );
 
 BEGIN {
-# We get this from XSParagraph.la
-# my $dlpath = "Texinfo/Convert/XSParagraph/.libs/XSParagraph.so.0";
+# Possible values for TEXINFO_XS environmental variable:
+#
+# TEXINFO_XS=omit     # don't try loading xs at all
+# TEXINFO_XS=default  # try xs, silent fallback
+# TEXINFO_XS=warn     # try xs, warn on failure
+# TEXINFO_XS=required # abort if not loadable, no fallback
+# TEXINFO_XS=debug    # voluminuous debugging
+#
+# Other values are treated at the moment as 'default'.
 
-# The following uses the module built by the ExtUtils::MakeMaker makefile.
-# my $dlname = 
"Texinfo/Convert/XSParagraph/blib/arch/auto/XSParagraph/XSParagraph.so";
+my $TEXINFO_XS = $ENV{'TEXINFO_XS'};
+if (!defined($TEXINFO_XS)) {
+  $TEXINFO_XS = '';
+}
 
+if ($TEXINFO_XS eq 'omit') {
+  # Don't try to use the XS module
+  goto FALLBACK;
+}
 
+# For verbose information about what's being done
+sub _debug($) {
+  if ($TEXINFO_XS eq 'debug') {
+    my $msg = shift;
+    warn $msg . "\n";
+  }
+}
+
+# For messages to say that XS module couldn't be loaded
+sub _fatal($) {
+  if ($TEXINFO_XS eq 'debug'
+      or $TEXINFO_XS eq 'required'
+      or $TEXINFO_XS eq 'warn') {
+    my $msg = shift;
+    warn $msg . "\n";
+  }
+}
+
 # We look for the .la and .so files in @INC because this allows us to override
 # which modules are used using -I flags to "perl".
 sub _find_file($) {
   my $file = shift;
   for my $dir (@INC) {
-    #print "checking $dir/$file\n";
+    _debug "checking $dir/$file";
     if (-f "$dir/$file") {
-      #print "found $dir/$file\n";
+      _debug "found $dir/$file";
       return ($dir, "$dir/$file");
     }
   }
@@ -70,14 +101,14 @@
 
 my ($libtool_dir, $libtool_archive) = _find_file("XSParagraph.la");
 if (!$libtool_archive) {
-  warn "XSParagraph: couldn't find Libtool archive file\n";
+  _fatal "XSParagraph: couldn't find Libtool archive file";
   goto FALLBACK;
 }
 
 my $fh;
 open $fh, $libtool_archive;
 if (!$fh) {
-  warn "XSParagraph: couldn't open Libtool archive file\n";
+  _fatal "XSParagraph: couldn't open Libtool archive file";
   goto FALLBACK;
 }
 
@@ -90,7 +121,7 @@
   }
 }
 if (!$dlname) {
-  warn "XSParagraph: couldn't find name of shared object\n";
+  _fatal "XSParagraph: couldn't find name of shared object";
   goto FALLBACK;
 }
 
@@ -100,7 +131,7 @@
 
 my $dlpath = DynaLoader::dl_findfile($dlname);
 if (!$dlpath) {
-  warn "XSParagraph: couldn't find $dlname\n";
+  _fatal "XSParagraph: couldn't find $dlname";
   goto FALLBACK;
 }
 
@@ -119,23 +150,23 @@
 my $flags = 0;
 my $libref = DynaLoader::dl_load_file($dlpath, $flags);
 if (!$libref) {
-  warn "XSParagraph: couldn't load file $dlpath\n";
+  _fatal "XSParagraph: couldn't load file $dlpath";
   goto FALLBACK;
 }
 my @undefined_symbols = DynaLoader::dl_undef_symbols();
 if ($#undefined_symbols+1 != 0) {
-  warn "XSParagraph: still have undefined symbols after dl_load_file\n";
+  _fatal "XSParagraph: still have undefined symbols after dl_load_file";
 }
 my $symref = DynaLoader::dl_find_symbol($libref, "boot_$module");
 if (!$symref) {
-  warn "XSParagraph: couldn't find boot_$module symbol\n";
+  _fatal "XSParagraph: couldn't find boot_$module symbol";
   goto FALLBACK;
 }
 my $boot_fn = DynaLoader::dl_install_xsub("${module}::bootstrap",
                                                 $symref, $dlname);
 
 if (!$boot_fn) {
-  warn "XSParagraph: couldn't bootstrap\n";
+  _fatal "XSParagraph: couldn't bootstrap";
   goto FALLBACK;
 }
 
@@ -147,12 +178,18 @@
 &$boot_fn($module, $VERSION);
 
 if (!XSParagraph::init ()) {
-  warn "XSParagraph: error initializing\n";
+  _fatal "XSParagraph: error initializing";
   goto FALLBACK;
 }
 goto DONTFALLBACK;
 
 FALLBACK:
+  if ($TEXINFO_XS eq 'required') {
+    die "unset the TEXINFO_XS environmental variable to use the "
+       ."pure Perl modules\n";
+  } elsif ($TEXINFO_XS eq 'warn' or $TEXINFO_XS eq 'debug') {
+    warn "falling back to pure Perl modules\n";
+  }
   # Fall back to using the Perl code.
   require Texinfo::Convert::Paragraph;
   *XSParagraph:: = *Texinfo::Convert::Paragraph::;




reply via email to

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