Fix testcase unsupportedcheck1 for --disable-backend-remote
[xapian.git] / xapian-bindings / perl / generate-perl-exceptions
blobe5fb6452e991427f54b86ddea37a1d8009325196
1 # generate-perl-exceptions: generate error handling code for Perl bindings
2 my $copyright = <<'END';
3  Copyright (C) 2003,2004,2006,2007,2008,2011,2012,2013 Olly Betts
4  Copyright (C) 2007 Lemur Consulting Ltd
5  Copyright (C) 2007 Richard Boulton
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of the
10  License, or (at your option) any later version.
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  GNU General Public License for more details.
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20 END
22 use strict;
23 use exception_data;
25 my @allclasses = (@baseclasses, @classes);
27 open FD, ">except.i" or die $!;
29 $copyright =~ s/^/ */mg;
31 print FD <<"EOF";
32 /** \@file
33  * \@brief Custom Perl exception handling.
34  */
35 /* Warning: This file is generated by $0
36  * - do not modify directly!
37  *
38 $copyright */
40 EOF
42 print FD <<'EOF';
43 namespace Xapian {
45 %exceptionclass Error;
46 EOF
48 for (@allclasses) {
49     my ($class) = @{$_};
50     print FD "%exceptionclass $class;\n";
53 print FD <<'EOF';
55 %ignore Xapian::Error::Error(const Error&);
56 %include "xapian/error.h"
59 namespace Xapian {
60 void handle_exception() {
61     try {
62         throw;
63 EOF
65 for (reverse @allclasses) {
66     my ($class) = @{$_};
67     print FD <<"EOF";
68     } catch (const Xapian::$class &e) {
69         void * p = (void *) new Xapian::$class(e);
70 #ifdef croak_sv
71         SV * sv = sv_newmortal();
72         sv_setref_pv(sv, "Xapian::$class", p);
73         croak_sv(sv);
74 #elif defined ERRSV
75         sv_setref_pv(ERRSV, "Xapian::$class", p);
76         croak(Nullch);
77 #else
78         sv_setref_pv(get_sv("@", TRUE), "Xapian::$class", p);
79         croak(Nullch);
80 #endif
81 EOF
84 print FD <<'EOF';
85     } catch (const std::exception& e) {
86         croak("std::exception: %s", e.what());
87     } catch (...) {
88         croak("something terrible happened");
89     }
94 /* Functions and methods which are marked as "nothrow": */
95 EOF
97 chdir($INC[0]);
98 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
100 print FD <<'EOF';
102 %exception {
103     try {
104         $action
105     } catch (...) {
106         Xapian::handle_exception();
107         SWIG_fail;
108     }
112 close FD or die $!;