On Sun Feb 20 21:46:02 2011, KENTNL wrote:
Show quoted text
I have attached a patch to Term-ReadLine-Gnu Makefile.PL.
With this patch I was able to compile and test Term::ReadLine::Gnu successfully on Gentoo Linux.
Could this be included in version 1.21?
diff -ru Term-ReadLine-Gnu-1.20/Makefile.PL Term-ReadLine-Gnu-1.20-hax/Makefile.PL
--- Term-ReadLine-Gnu-1.20/Makefile.PL 2010-05-02 12:37:55.000000000 +0200
+++ Term-ReadLine-Gnu-1.20-hax/Makefile.PL 2013-10-29 09:55:08.000000000 +0100
@@ -90,6 +90,11 @@
}
}
+# Check whether xmalloc has been renamed to _rl_malloc (Gentoo Linux)
+if (my $extra_defs = guess_malloc_names($RLINC, $RLLIB, $defs, $lddflags, $libs)) {
+ $defs .= " $extra_defs";
+}
+
# generate a Makefile
WriteMakefile
(
@@ -105,7 +110,7 @@
) : () ),
INC => $RLINC,
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz' },
- clean => { FILES => "rlver.c rlver$Config{_exe}" },
+ clean => { FILES => "rlver.c rlver$Config{_exe} rlmalloc.c rlmalloc$Config{_exe}" },
);
if ($Config{usesfio} eq 'true') {
@@ -214,4 +219,76 @@
# $rlver may be '8.21-beta3' or '4.2a'
return $rlver =~ /(\d+)\.(\d+)/;
}
+
+########################################################################
+# Check whether the xmalloc exported by readline is indeed called
+# 'xmalloc' or whether it has been renamed to '_rl_malloc'.
+sub guess_malloc_names {
+ my ($RLINC, $RLLIB, $defs, $lddflags, $libs) = @_;
+ my $frlmalloc = 'rlmalloc.c';
+
+ my @symbol_sets = (
+ {
+ # try defaults first
+ # xmalloc => 'xmalloc',
+ # xrealloc => 'xrealloc',
+ # xfree => 'xfree',
+ },
+ {
+ xmalloc => '_rl_malloc',
+ xrealloc => '_rl_realloc',
+ xfree => '_rl_free',
+ },
+ );
+
+ # make temp file
+ open(my $F, ">", $frlmalloc) || die "Cannot open $frlmalloc: $!\n";
+ print {$F} <<'EOF';
+/* used by Makefile.pl to check the names of xmalloc etc. of the GNU Readline Library */
+#include <stdio.h>
+#include <readline/readline.h>
+
+/* we assume support for ANSI C */
+extern void *xmalloc(int);
+extern void *xrealloc(void *, int);
+extern void xfree(void *);
+
+int main() {
+ char *p;
+ p = xmalloc(1);
+ p[0] = 'o';
+ p = xrealloc(p, 3);
+ p[1] = 'k';
+ p[2] = '\0';
+ puts(p);
+ xfree(p);
+ return 0;
+}
+EOF
+ close($F);
+
+ my $extra_defs;
+ for my $symbol_set (@symbol_sets) {
+ my $xdef = join " ", map "-D$_=$symbol_set->{$_}", sort keys %$symbol_set;
+ # compile it
+ my $comp_cmd = "$Config{cc} $RLINC $Config{ccflags} $defs $xdef $frlmalloc -o rlmalloc $RLLIB $lddflags $Config{ldflags} $libs";
+ print $comp_cmd, "\n";
+ system($comp_cmd);
+ unless (system($comp_cmd) || `./rlmalloc` !~ /^ok$/ || $?) {
+ $extra_defs = $xdef;
+ last;
+ }
+ }
+
+ unless (defined $extra_defs) {
+ warn <<EOM;
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+I was unable to find a working xmalloc in your readline library.
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+EOM
+ exit $err;
+ }
+
+ return $extra_defs;
+}
# End of Makefile.PL