perl-Sereal-Encoder/Sereal-3.002_001-Prefer-external-csnappy-library-in-Sereal-Encoder.patch
Petr Písař d8a37ec1aa Import
2014-10-30 07:42:57 +01:00

94 lines
3.0 KiB
Diff

From 9b0bc16ced731228eb7e2e07b4287020c39d8025 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Mon, 13 Oct 2014 16:35:04 +0200
Subject: [PATCH 1/2] Prefer external csnappy library in Sereal::Encoder
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This patch checks for presence of csnappy library and header file and
if they are available, they will be used to link to the
Sereal::Encoder XS module. Otherwise the bundled csnappy code will be
used.
<https://github.com/Sereal/Sereal/issues/72>
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
Perl/Encoder/Makefile.PL | 26 +++++++++++++++++++-------
Perl/Encoder/srl_encoder.c | 5 +++++
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/Perl/Encoder/Makefile.PL b/Perl/Encoder/Makefile.PL
index 65d9292..ce0e8d7 100644
--- a/Perl/Encoder/Makefile.PL
+++ b/Perl/Encoder/Makefile.PL
@@ -25,6 +25,7 @@ inc::Sereal::BuildTools::generate_constant_includes($module) if $in_source_repo;
our $OPTIMIZE;
+my $libs = '';
my $defines = join " ", map "-D$_", grep exists $ENV{$_},
qw(NOINLINE DEBUG MEMDEBUG NDEBUG ENABLE_DANGEROUS_HACKS);
@@ -56,13 +57,24 @@ if ($Config{osname} eq 'hpux' && not $Config{gccversion}) {
$defines .= " -Dinline= ";
}
-# from Compress::Snappy
+# Prefer external csnappy library over the bundled one.
require Devel::CheckLib;
-my $ctz = Devel::CheckLib::check_lib(
- lib => 'c',
- function => 'return (__builtin_ctzll(0x100000000LL) != 32);'
-) ? '-DHAVE_BUILTIN_CTZ' : '';
-$defines .= " $ctz" if $ctz;
+my $have_csnappy = Devel::CheckLib::check_lib(
+ lib => 'csnappy',
+ header => 'csnappy.h'
+);
+
+if ($have_csnappy) {
+ $libs .= ' -lcsnappy';
+ $defines .= ' -DHAVE_CSNAPPY';
+} else {
+ # from Compress::Snappy
+ my $ctz = Devel::CheckLib::check_lib(
+ lib => 'c',
+ function => 'return (__builtin_ctzll(0x100000000LL) != 32);'
+ ) ? '-DHAVE_BUILTIN_CTZ' : '';
+ $defines .= " $ctz" if $ctz;
+}
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
@@ -101,7 +113,7 @@ WriteMakefile1(
LICENSE => 'perl',
ABSTRACT_FROM => 'lib/Sereal/Encoder.pm',
AUTHOR => 'Steffen Mueller <smueller@cpan.org>, Yves Orton <yves@cpan.org>',
- LIBS => [''], # e.g., '-lm'
+ LIBS => [$libs], # e.g., '-lm'
DEFINE => $defines,
INC => '-I.', # e.g., '-I. -I/usr/include/other'
OPTIMIZE => $OPTIMIZE,
diff --git a/Perl/Encoder/srl_encoder.c b/Perl/Encoder/srl_encoder.c
index 780748f..cc87623 100644
--- a/Perl/Encoder/srl_encoder.c
+++ b/Perl/Encoder/srl_encoder.c
@@ -52,7 +52,12 @@ extern "C" {
#include "ptable.h"
#include "srl_buffer.h"
+#if defined(HAVE_CSNAPPY)
+#include <csnappy.h>
+#else
#include "snappy/csnappy_compress.c"
+#endif
+
#include "miniz.h"
/* The ENABLE_DANGEROUS_HACKS (passed through from ENV via Makefile.PL) enables
--
1.9.3