CC: | David Leadbeater <dgl [...] dgl.cx> |
Subject: | [PATCH] Raise Perl level exception on error |
Date: | Sat, 1 Oct 2011 18:17:38 +0100 |
To: | bug-Tie-LevelDB [...] rt.cpan.org |
From: | David Leadbeater <dgl [...] dgl.cx> |
Avoids segfaulting on attempting to open a locked DB.
---
LevelDB.xs | 4 +++-
t/Tie-LevelDB.t | 11 ++++++++++-
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/LevelDB.xs b/LevelDB.xs
index 59e29aa..a7aa9bb 100644
--- a/LevelDB.xs
+++ b/LevelDB.xs
@@ -22,7 +22,9 @@ extern "C" {
#include<leveldb/write_batch.h>
void status_assert(leveldb::Status s) {
- if(!s.ok()) std::cerr << s.ToString() << std::endl;
+ if(!s.ok()) {
+ croak(s.ToString().c_str());
+ }
}
class Iterator {
diff --git a/t/Tie-LevelDB.t b/t/Tie-LevelDB.t
index f496946..887568f 100644
--- a/t/Tie-LevelDB.t
+++ b/t/Tie-LevelDB.t
@@ -5,7 +5,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
-use Test::More tests => 29;
+use Test::More tests => 30;
BEGIN { use_ok('Tie::LevelDB') };
#########################
@@ -87,6 +87,15 @@ delete $h{'goner2'};
is(scalar(keys %h), 2);
+open my $fh, "|-", $^X, "-Mblib" or die $!;
+print $fh <<EOF;
+use $LevelDB_Class;
+eval { tie my %h, "$LevelDB_Class", "$DBDIR" };
+die if \$@ !~ /LOCK/;
+EOF
+close $fh;
+ok +($? >> 8) == 0, "Unable to open locked DB";
+
untie %h;
is(scalar(keys %h), 0);
--
1.7.4.4