"Fossies" - the Fresh Open Source Software Archive

Member "xapian-bindings-1.4.14/perl/generate-perl-exceptions" (23 Nov 2019, 2471 Bytes) of package /linux/www/xapian-bindings-1.4.14.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "generate-perl-exceptions": 1.4.12_vs_1.4.13.

    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
    6 
    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.
   11 
   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.
   16 
   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
   21 
   22 use strict;
   23 use exception_data;
   24 
   25 my @allclasses = (@baseclasses, @classes);
   26 
   27 open FD, ">except.i" or die $!;
   28 
   29 $copyright =~ s/^/ */mg;
   30 
   31 print FD <<"EOF";
   32 /** \@file perl/except.i
   33  * \@brief Custom Perl exception handling.
   34  */
   35 /* Warning: This file is generated by $0
   36  * - do not modify directly!
   37  *
   38 $copyright */
   39 
   40 EOF
   41 
   42 print FD <<'EOF';
   43 namespace Xapian {
   44 
   45 %exceptionclass Error;
   46 EOF
   47 
   48 for (@allclasses) {
   49     my ($class) = @{$_};
   50     print FD "%exceptionclass $class;\n";
   51 }
   52 
   53 print FD <<'EOF';
   54 }
   55 %ignore Xapian::Error::Error(const Error&);
   56 %include "xapian/error.h"
   57 
   58 %{
   59 namespace Xapian {
   60 void handle_exception() {
   61     try {
   62 	throw;
   63 EOF
   64 
   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
   82 }
   83 
   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     }
   90 }
   91 }
   92 %}
   93 
   94 /* Functions and methods which are marked as "nothrow": */
   95 EOF
   96 
   97 chdir($INC[0]);
   98 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
   99 
  100 print FD <<'EOF';
  101 
  102 %exception {
  103     try {
  104 	$action
  105     } catch (...) {
  106 	Xapian::handle_exception();
  107 	SWIG_fail;
  108     }
  109 }
  110 EOF
  111 
  112 close FD or die $!;