From 33a752b0bda53fe304b3a08ae81a0561ba473a38 Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Thu, 29 Sep 2005 13:04:42 +0000 Subject: [PATCH] add %exceptionclass and %noexceptionclass directives and manage the feature:exceptionclass in a consistent way git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7548 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Lib/python/std_except.i | 32 ++++++++++++++++++++------------ SWIG/Lib/swig.swg | 4 ++++ SWIG/Source/Modules/allocate.cxx | 4 +++- SWIG/Source/Modules/python.cxx | 2 +- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/SWIG/Lib/python/std_except.i b/SWIG/Lib/python/std_except.i index 8f7ce4ebb..734f2ba93 100644 --- a/SWIG/Lib/python/std_except.i +++ b/SWIG/Lib/python/std_except.i @@ -5,21 +5,29 @@ #include %} + + namespace std { - /* Mark all of them as exception classes */ - %feature("exceptionclass") exception; - %feature("exceptionclass") bad_exception; - %feature("exceptionclass") logic_error; - %feature("exceptionclass") domain_error; - %feature("exceptionclass") invalid_argument; - %feature("exceptionclass") length_error; - %feature("exceptionclass") out_of_range; - %feature("exceptionclass") runtime_error; - %feature("exceptionclass") range_error; - %feature("exceptionclass") overflow_error; - %feature("exceptionclass") underflow_error; + /* + Mark all of std exception classes as "exception classes" via + the "exceptionclass" feature. + + If needed, you can disable it by using %noexceptionclass. + */ + %exceptionclass exception; + %exceptionclass bad_exception; + %exceptionclass logic_error; + %exceptionclass domain_error; + %exceptionclass invalid_argument; + %exceptionclass length_error; + %exceptionclass out_of_range; + %exceptionclass runtime_error; + %exceptionclass range_error; + %exceptionclass overflow_error; + %exceptionclass underflow_error; } + namespace std { struct exception { diff --git a/SWIG/Lib/swig.swg b/SWIG/Lib/swig.swg index 82fe0dfe0..e6e6109bf 100644 --- a/SWIG/Lib/swig.swg +++ b/SWIG/Lib/swig.swg @@ -66,6 +66,10 @@ #endif #define %noexception %feature("except","") +#define %exceptionclass %feature("exceptionclass","1") +#define %noexceptionclass %feature("exceptionclass","0") + + #define %newobject %feature("new") /* Warnings */ diff --git a/SWIG/Source/Modules/allocate.cxx b/SWIG/Source/Modules/allocate.cxx index 935920aa9..29ad7c14e 100644 --- a/SWIG/Source/Modules/allocate.cxx +++ b/SWIG/Source/Modules/allocate.cxx @@ -467,7 +467,9 @@ class Allocate : public Dispatcher { } Node *c = Swig_symbol_clookup(t,0); if (c) { - Setattr(c,"feature:exceptionclass","1"); + if (!Getattr(c,"feature:exceptionclass")) { + Setattr(c,"feature:exceptionclass","1"); + } } p = nextSibling(p); Delete(t); diff --git a/SWIG/Source/Modules/python.cxx b/SWIG/Source/Modules/python.cxx index 1df9fdb2d..bb589b466 100644 --- a/SWIG/Source/Modules/python.cxx +++ b/SWIG/Source/Modules/python.cxx @@ -1954,7 +1954,7 @@ public: have_constructor = 0; have_repr = 0; - if (Getattr(n,"feature:exceptionclass")) { + if (checkAttribute(n,"feature:exceptionclass","1")) { classic = 1; modern = 0; }