texinfo-commits
[Top][All Lists]
Advanced

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

[6718] move XS test module


From: Gavin D. Smith
Subject: [6718] move XS test module
Date: Wed, 21 Oct 2015 19:21:21 +0000

Revision: 6718
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6718
Author:   gavin
Date:     2015-10-21 19:21:20 +0000 (Wed, 21 Oct 2015)
Log Message:
-----------
move XS test module

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/configure.ac
    trunk/tp/Makefile.am
    trunk/tp/Texinfo/Convert/XSParagraph/Makefile.am

Added Paths:
-----------
    trunk/tp/Texinfo/Convert/XSParagraph/TestXS.pm
    trunk/tp/Texinfo/Convert/XSParagraph/TestXS.xs
    trunk/tp/Texinfo/Convert/XSParagraph/fail.pl

Removed Paths:
-------------
    trunk/tp/TestXS/

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2015-10-21 10:13:25 UTC (rev 6717)
+++ trunk/ChangeLog     2015-10-21 19:21:20 UTC (rev 6718)
@@ -1,5 +1,20 @@
 2015-10-21  Gavin Smith  <address@hidden>
 
+       * tp/TestXS: Move test extension into tp/Texinfo/Convert/XSParagraph
+       and remove directory.  This should make the test more reliable 
+       as the conditions of building are more similar to those of the 
+       real extension.  It should make the package a little smaller as 
+       we have one fewer configure script, Makefile and libtool program.
+
+       * tp/Texinfo/Convert/XSParagraph/TestXS.pm,
+       tp/Texinfo/Convert/XSParagraph/TestXS.xs
+       tp/Texinfo/Convert/XSParagraph/fail.pl: New locations of files.
+
+       * configure.ac, tp/Makefile.am, 
+       tp/Texinfo/Convert/XSParagraph/Makefile.am: Update.
+
+2015-10-21  Gavin Smith  <address@hidden>
+
        * doc/info-stnd.texi (Invoking Info): Change mention of 
        command-line variable to match synopsis.  Fix an ungrammatical 
        sentence.

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac  2015-10-21 10:13:25 UTC (rev 6717)
+++ trunk/configure.ac  2015-10-21 19:21:20 UTC (rev 6718)
@@ -358,13 +358,12 @@
     [ enable_xs=$enableval],
     [ enable_xs=check])
 
-# Configure in TestXS directory unconditionally so that "make dist"
-# works.
-AC_CONFIG_SUBDIRS([tp/TestXS])
+AC_CONFIG_SUBDIRS([tp/Texinfo/Convert/XSParagraph])
 if test $enable_xs = check; then
   AC_MSG_CHECKING([whether we can build Perl extension modules])
   enable_xs=no
-  (cd tp/TestXS && ./configure PERL=${PERL} && make \
+  (cd tp/Texinfo/Convert/XSParagraph \
+   && ./configure PERL=${PERL} && make TestXS.la \
     && ${PERL} -w fail.pl | grep 'message from XS module') >/dev/null \
   && enable_xs=yes
   AC_MSG_RESULT([$enable_xs])
@@ -378,9 +377,7 @@
 
 AM_CONDITIONAL([DISABLE_XS], [test "z$enable_xs" = zno])
 
-AC_CONFIG_SUBDIRS([tp/Texinfo/Convert/XSParagraph])
 
-
 # Tests.
 AC_CONFIG_FILES([install-info/tests/defs])
 dnl We cannot enable the TeX-related tests, so don't waste time

Modified: trunk/tp/Makefile.am
===================================================================
--- trunk/tp/Makefile.am        2015-10-21 10:13:25 UTC (rev 6717)
+++ trunk/tp/Makefile.am        2015-10-21 19:21:20 UTC (rev 6718)
@@ -34,7 +34,6 @@
 SUBDIRS += . tests
 
 DIST_SUBDIRS = Texinfo/Convert/XSParagraph tests
-DIST_SUBDIRS += TestXS
 
 
 bin_SCRIPTS = texi2any

Modified: trunk/tp/Texinfo/Convert/XSParagraph/Makefile.am
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/Makefile.am    2015-10-21 10:13:25 UTC 
(rev 6717)
+++ trunk/tp/Texinfo/Convert/XSParagraph/Makefile.am    2015-10-21 19:21:20 UTC 
(rev 6718)
@@ -39,6 +39,8 @@
 modulesdir = $(pkgdatadir)/Texinfo/Convert/XSParagraph
 xsdir = $(pkglibexecdir)
 
+dist_modules_DATA = TestXS.pm
+
 PERL_INC = $(PERL_CONF_archlibexp)/CORE
 
 XSUBPPARGS = -typemap $(PERL_CONF_privlibexp)/ExtUtils/typemap
@@ -48,11 +50,17 @@
 
 # -------------------------------------------------------
 
-xs_LTLIBRARIES = XSParagraph.la
+CLEANFILES =
+
+xs_LTLIBRARIES = XSParagraph.la TestXS.la
 XSParagraph_la_SOURCES = XSParagraph.c xspara.c xspara.h \
                         text.c text.h ppport.h
+TestXS_la_SOURCES = TestXS.c ppport.h
 
-CLEANFILES = XSParagraph.c
+CLEANFILES += TestXS.c
+EXTRA_DIST += TestXS.xs
+
+CLEANFILES += XSParagraph.c
 EXTRA_DIST += XSParagraph.xs
 
 # Override these variables set by configure at the top level, because 
@@ -71,6 +79,12 @@
 XSParagraph_la_LDFLAGS=-avoid-version -module $(PERL_CONF_cccdlflags)
 
 
+TestXS_la_CFLAGS = $(PERL_CONF_ccflags)
+
+TestXS_la_CFLAGS += -DVERSION=\"$(VERSION)\" -DXS_VERSION=\"$(VERSION)\"  
"-I$(PERL_INC)"
+
+TestXS_la_LDFLAGS=-module $(PERL_CONF_cccdlflags)
+
 # only used to regenerate a stand-alone perl module
 perl_specific_files = \
   Makefile.PL \

Added: trunk/tp/Texinfo/Convert/XSParagraph/TestXS.pm
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/TestXS.pm                              
(rev 0)
+++ trunk/tp/Texinfo/Convert/XSParagraph/TestXS.pm      2015-10-21 19:21:20 UTC 
(rev 6718)
@@ -0,0 +1,220 @@
+# Copyright 2014, 2015 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License,
+# or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package Texinfo::Convert::XSParagraph::XSParagraph;
+
+use DynaLoader;
+
+# same as texi2any.pl, although I don't know what the real requirement
+# is for this module.
+use 5.00405;
+use strict;
+use warnings;
+
+require Exporter;
+
+our @ISA = qw(Exporter DynaLoader);
+
+# Items to export into callers namespace by default. Note: do not export
+# names by default without a very good reason. Use EXPORT_OK instead.
+# Do not simply export all your public functions/methods/constants.
+
+# This allows declaration      use XSParagraph ':all';
+# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
+# will save memory.
+our %EXPORT_TAGS = ( 'all' => [ qw(
+    add_next
+    add_text
+       
+) ] );
+
+our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
+
+our @EXPORT = qw(
+       
+);
+
+BEGIN {
+# 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'.
+
+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) {
+    _debug "checking $dir/$file";
+    if (-f "$dir/$file") {
+      _debug "found $dir/$file";
+      return ($dir, "$dir/$file");
+    }
+  }
+  return undef;
+}
+
+our $disable_XS;
+if ($disable_XS) {
+  _fatal "use of XS modules was disabled when Texinfo was built";
+  goto FALLBACK;
+}
+
+my ($libtool_dir, $libtool_archive) = _find_file("TestXS.la");
+if (!$libtool_archive) {
+  _fatal "XSParagraph: couldn't find Libtool archive file";
+  goto FALLBACK;
+}
+
+my $fh;
+open $fh, $libtool_archive;
+if (!$fh) {
+  _fatal "XSParagraph: couldn't open Libtool archive file";
+  goto FALLBACK;
+}
+
+# Look for the line in XSParagraph.la giving the name of the loadable object.
+my $dlname = undef;
+while (my $line = <$fh>) {
+  if ($line =~ /^\s*dlname\s*=\s*'([^']+)'\s$/) {
+    $dlname = $1;
+    last;
+  }
+}
+if (!$dlname) {
+  _fatal "XSParagraph: couldn't find name of shared object";
+  goto FALLBACK;
+}
+
+# The *.so file is under .libs in the source directory.
+push @DynaLoader::dl_library_path, $libtool_dir;
+push @DynaLoader::dl_library_path, "$libtool_dir/.libs";
+
+my $dlpath = DynaLoader::dl_findfile($dlname);
+if (!$dlpath) {
+  _fatal "XSParagraph: couldn't find $dlname";
+  goto FALLBACK;
+}
+
+#print STDERR "loadable object is at $dlpath\n";
+
+my $module = "TestXS";
+our $VERSION = '6.0';
+
+# Following steps under "bootstrap" in "man DynaLoader".
+#bootstrap XSParagraph $VERSION;
+
+# TODO: Execute blib/arch/auto/XSParagraph/XSParagraph.bs ?
+# That file is empty.
+
+#my $flags = dl_load_flags $module; # This is 0 in DynaLoader
+my $flags = 0;
+my $libref = DynaLoader::dl_load_file($dlpath, $flags);
+if (!$libref) {
+  _fatal "XSParagraph: couldn't load file $dlpath";
+  goto FALLBACK;
+}
+my @undefined_symbols = DynaLoader::dl_undef_symbols();
+if ($#undefined_symbols+1 != 0) {
+  _fatal "XSParagraph: still have undefined symbols after dl_load_file";
+}
+my $bootname = "boot_$module";
+$bootname =~ s/:/_/g;
+my $symref = DynaLoader::dl_find_symbol($libref, $bootname);
+if (!$symref) {
+  _fatal "XSParagraph: couldn't find boot_$module symbol";
+  goto FALLBACK;
+}
+my $boot_fn = DynaLoader::dl_install_xsub("${module}::bootstrap",
+                                                $symref, $dlname);
+
+if (!$boot_fn) {
+  _fatal "XSParagraph: couldn't bootstrap";
+  goto FALLBACK;
+}
+
+push @DynaLoader::dl_shared_objects, $dlpath; # record files loaded
+
+# This is the module bootstrap function, which causes all the other
+# functions (XSUB's) provided by the module to become available to
+# be called from Perl code.
+&$boot_fn($module, $VERSION);
+
+if (!TestXS::init ()) {
+  _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;
+  *Texinfo::Convert::XSParagraph::XSParagraph::
+                                          = *Texinfo::Convert::Paragraph::;
+DONTFALLBACK: ;
+} # end BEGIN
+
+
+# Preloaded methods go here.
+
+#########################################################################
+
+# Used for debugging.  Not implemented.
+sub dump($)
+{
+  return "\n";
+}
+
+1;
+__END__

Added: trunk/tp/Texinfo/Convert/XSParagraph/TestXS.xs
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/TestXS.xs                              
(rev 0)
+++ trunk/tp/Texinfo/Convert/XSParagraph/TestXS.xs      2015-10-21 19:21:20 UTC 
(rev 6718)
@@ -0,0 +1,17 @@
+#include <config.h>
+
+#define PERL_NO_GET_CONTEXT
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#include "ppport.h"
+
+
+
+MODULE = TestXS PACKAGE = TestXS PREFIX = xspara_
+
+int
+xspara_init ()
+    CODE:
+        puts ("message from XS module\n");

Added: trunk/tp/Texinfo/Convert/XSParagraph/fail.pl
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/fail.pl                                
(rev 0)
+++ trunk/tp/Texinfo/Convert/XSParagraph/fail.pl        2015-10-21 19:21:20 UTC 
(rev 6718)
@@ -0,0 +1 @@
+require 'TestXS.pm';




reply via email to

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