Consistently compare lseek() < 0 instead of == -1
[xapian.git] / xapian-bindings / php7 / generate-php-exceptions
blob40475e522a86c7736b56455f93b3c0cebbff74d0
1 # generate-php-exceptions: generate error handling code for PHP bindings
2 my $copyright = <<'END';
3  Copyright 2006,2007,2010,2011,2012,2016 Olly Betts
4  Copyright 2007 Lemur Consulting Ltd
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of the
9  License, or (at your option) any later version.
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19 END
21 use strict;
22 use exception_data;
24 open FD, ">except.i" or die $!;
26 $copyright =~ s/^/ */mg;
28 print FD <<"EOF";
30 /** \@file php/except.i
31  * \@brief Custom PHP exception handling.
32  */
33 /* Warning: This file is generated by $0
34  * - do not modify directly!
35  *
36 $copyright */
38 EOF
40 print FD <<'EOF';
41 #include <exception>
42 #include <zend_exceptions.h>
44 static void
45 XapianExceptionHandler()
47     try {
48         // Rethrow so we can look at the exception if it was a Xapian::Error.
49         throw;
50     } catch (const Xapian::Error &e) {
51         // FIXME: It would be nicer to make the exceptions PHP classes
52         // corresponding to the C++ Xapian::Error class hierarchy.
53         zend_throw_exception(NULL, e.get_description().c_str(),
54                              SWIG_UnknownError);
55     } catch (const std::exception &e) {
56         zend_throw_exception_ex(NULL, SWIG_UnknownError,
57                                 "std::exception %s", e.what());
58     } catch (...) {
59         zend_throw_exception(NULL, "unknown error in Xapian",
60                              SWIG_UnknownError);
61     }
65 /* Functions and methods which are marked as "nothrow": */
66 EOF
68 chdir($INC[0]);
69 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
71 print FD <<'EOF';
73 %exception {
74     try {
75         $function
76     } catch (...) {
77         XapianExceptionHandler();
78         return;
79     }
81 EOF
83 close FD or die $!;