Merge branch 'yag00-master'
* yag00-master: Add raise methods for throwing c++ exceptions in C#, Java, D php5: propagate c++11 noexcept to director classes Revert "java : noexcept method can't raise Swig::DirectorException" Revert "csharp : noexcept method can't raise Swig::DirectorPureVirtualException" csharp : noexcept method can't raise Swig::DirectorPureVirtualException java : noexcept method can't raise Swig::DirectorException #526 : propagate c++11 noexcept to director classes #526 : propagate c++11 noexcept to director classes test case
This commit is contained in:
commit
f6d10278f8
15 changed files with 102 additions and 10 deletions
|
|
@ -3923,12 +3923,24 @@ is used in the feature code. Consider the following, which also happens to be th
|
|||
if ($error) {
|
||||
jenv->ExceptionClear();
|
||||
$directorthrowshandlers
|
||||
throw Swig::DirectorException(jenv, $error);
|
||||
Swig::DirectorException::raise(jenv, $error);
|
||||
}
|
||||
%}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
where <tt>Swig::DirectorException::raise</tt> is a helper method in the DirectorException class to throw a C++ exception (implemented in director.swg):
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
static void raise(JNIEnv *jenv, jthrowable throwable) {
|
||||
throw DirectorException(jenv, throwable);
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>The code generated using the <code>director:except</code> feature
|
||||
replaces the <code>$directorthrowshandlers</code> special variable with the code in
|
||||
the "directorthrows" typemaps, for each and every exception defined for the method.
|
||||
|
|
@ -3963,7 +3975,7 @@ if (swigerror) {
|
|||
throw std::out_of_range(Swig::JavaExceptionMessage(jenv, swigerror).message());
|
||||
}
|
||||
|
||||
throw Swig::DirectorException(jenv, swigerror);
|
||||
Swig::DirectorException::raise(jenv, swigerror);
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -543,6 +543,7 @@ CPP11_TEST_CASES += \
|
|||
cpp11_default_delete \
|
||||
cpp11_delegating_constructors \
|
||||
cpp11_director_enums \
|
||||
cpp11_directors \
|
||||
cpp11_explicit_conversion_operators \
|
||||
cpp11_final_override \
|
||||
cpp11_function_objects \
|
||||
|
|
|
|||
20
Examples/test-suite/cpp11_directors.i
Normal file
20
Examples/test-suite/cpp11_directors.i
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
%module(directors="1") cpp11_directors
|
||||
%feature("director");
|
||||
|
||||
%{
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() noexcept {}
|
||||
virtual int ping() noexcept = 0;
|
||||
virtual int pong() noexcept = 0;
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() noexcept {}
|
||||
virtual int ping() noexcept = 0;
|
||||
virtual int pong() noexcept = 0;
|
||||
};
|
||||
|
|
@ -41,6 +41,10 @@ namespace Swig {
|
|||
public:
|
||||
DirectorPureVirtualException(const char *msg) : DirectorException(std::string("Attempt to invoke pure virtual method ") + msg) {
|
||||
}
|
||||
|
||||
static void raise(const char *msg) {
|
||||
throw DirectorPureVirtualException(msg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ namespace Swig {
|
|||
public:
|
||||
DirectorPureVirtualException(const char *msg) : DirectorException(std::string("Attempted to invoke pure virtual method ") + msg) {
|
||||
}
|
||||
|
||||
static void raise(const char *msg) {
|
||||
throw DirectorPureVirtualException(msg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -356,6 +356,10 @@ namespace Swig {
|
|||
}
|
||||
}
|
||||
|
||||
static void raise(JNIEnv *jenv, jthrowable throwable) {
|
||||
throw DirectorException(jenv, throwable);
|
||||
}
|
||||
|
||||
private:
|
||||
static char *copypath(const char *srcmsg) {
|
||||
char *target = copystr(srcmsg);
|
||||
|
|
|
|||
|
|
@ -3935,7 +3935,7 @@ public:
|
|||
}
|
||||
Delete(super_call);
|
||||
} else {
|
||||
Printf(w->code, " throw Swig::DirectorPureVirtualException(\"%s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name));
|
||||
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"%s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name));
|
||||
}
|
||||
|
||||
if (!ignored_method)
|
||||
|
|
@ -4102,6 +4102,10 @@ public:
|
|||
Delete(target);
|
||||
|
||||
// Add any exception specifications to the methods in the director class
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Append(w->def, " noexcept");
|
||||
Append(declaration, " noexcept");
|
||||
}
|
||||
ParmList *throw_parm_list = NULL;
|
||||
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
|
||||
int gencomma = 0;
|
||||
|
|
@ -4419,7 +4423,10 @@ public:
|
|||
String *dirclassname = directorClassName(current_class);
|
||||
Wrapper *w = NewWrapper();
|
||||
|
||||
if (Getattr(n, "throw")) {
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Printf(f_directors_h, " virtual ~%s() noexcept;\n", dirclassname);
|
||||
Printf(w->def, "%s::~%s() noexcept {\n", dirclassname, dirclassname);
|
||||
} else if (Getattr(n, "throw")) {
|
||||
Printf(f_directors_h, " virtual ~%s() throw ();\n", dirclassname);
|
||||
Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2077,7 +2077,7 @@ public:
|
|||
}
|
||||
Delete(super_call);
|
||||
} else {
|
||||
Printf(w->code, " throw Swig::DirectorPureVirtualException(\"%s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name));
|
||||
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"%s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name));
|
||||
}
|
||||
|
||||
if (!ignored_method)
|
||||
|
|
@ -2217,6 +2217,10 @@ public:
|
|||
Delete(target);
|
||||
|
||||
// Add any exception specifications to the methods in the director class
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Append(w->def, " noexcept");
|
||||
Append(declaration, " noexcept");
|
||||
}
|
||||
ParmList *throw_parm_list = NULL;
|
||||
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
|
||||
int gencomma = 0;
|
||||
|
|
@ -2483,7 +2487,10 @@ public:
|
|||
String *dirclassname = directorClassName(current_class);
|
||||
Wrapper *w = NewWrapper();
|
||||
|
||||
if (Getattr(n, "throw")) {
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Printf(f_directors_h, " virtual ~%s() noexcept;\n", dirclassname);
|
||||
Printf(w->def, "%s::~%s() noexcept {\n", dirclassname, dirclassname);
|
||||
} else if (Getattr(n, "throw")) {
|
||||
Printf(f_directors_h, " virtual ~%s() throw ();\n", dirclassname);
|
||||
Printf(w->def, "%s::~%s() throw () {\n", dirclassname, dirclassname);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -4293,6 +4293,10 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Append(w->def, " noexcept");
|
||||
Append(declaration, " noexcept");
|
||||
}
|
||||
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
|
||||
int gencomma = 0;
|
||||
|
||||
|
|
@ -4486,7 +4490,7 @@ public:
|
|||
Printf(directorexcept, "jthrowable $error = jenv->ExceptionOccurred();\n");
|
||||
Printf(directorexcept, "if ($error) {\n");
|
||||
Printf(directorexcept, " jenv->ExceptionClear();$directorthrowshandlers\n");
|
||||
Printf(directorexcept, " throw Swig::DirectorException(jenv, $error);\n");
|
||||
Printf(directorexcept, " Swig::DirectorException::raise(jenv, $error);\n");
|
||||
Printf(directorexcept, "}\n");
|
||||
} else {
|
||||
directorexcept = Copy(directorexcept);
|
||||
|
|
@ -4671,7 +4675,10 @@ public:
|
|||
String *dirClassName = directorClassName(current_class);
|
||||
Wrapper *w = NewWrapper();
|
||||
|
||||
if (Getattr(n, "throw")) {
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Printf(f_directors_h, " virtual ~%s() noexcept;\n", dirClassName);
|
||||
Printf(w->def, "%s::~%s() noexcept {\n", dirClassName, dirClassName);
|
||||
} else if (Getattr(n, "throw")) {
|
||||
Printf(f_directors_h, " virtual ~%s() throw ();\n", dirClassName);
|
||||
Printf(w->def, "%s::~%s() throw () {\n", dirClassName, dirClassName);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1321,6 +1321,10 @@ public:
|
|||
Delete(target);
|
||||
|
||||
// Get any exception classes in the throws typemap
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Append(w->def, " noexcept");
|
||||
Append(declaration, " noexcept");
|
||||
}
|
||||
ParmList *throw_parm_list = 0;
|
||||
|
||||
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
|
||||
|
|
|
|||
|
|
@ -2090,6 +2090,10 @@ public:
|
|||
Delete(target);
|
||||
|
||||
// Get any exception classes in the throws typemap
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Append(w->def, " noexcept");
|
||||
Append(declaration, " noexcept");
|
||||
}
|
||||
ParmList *throw_parm_list = 0;
|
||||
|
||||
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
|
||||
|
|
@ -2486,7 +2490,10 @@ public:
|
|||
Delete(mangle);
|
||||
Delete(ptype);
|
||||
|
||||
if (Getattr(n, "throw")) {
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Printf(f_directors_h, " virtual ~%s() noexcept;\n", DirectorClassName);
|
||||
Printf(f_directors, "%s::~%s() noexcept {%s}\n\n", DirectorClassName, DirectorClassName, body);
|
||||
} else if (Getattr(n, "throw")) {
|
||||
Printf(f_directors_h, " virtual ~%s() throw ();\n", DirectorClassName);
|
||||
Printf(f_directors, "%s::~%s() throw () {%s}\n\n", DirectorClassName, DirectorClassName, body);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2530,6 +2530,10 @@ done:
|
|||
Delete(target);
|
||||
|
||||
// Get any exception classes in the throws typemap
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Append(w->def, " noexcept");
|
||||
Append(declaration, " noexcept");
|
||||
}
|
||||
ParmList *throw_parm_list = 0;
|
||||
|
||||
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
|
||||
|
|
|
|||
|
|
@ -2525,6 +2525,10 @@ done:
|
|||
Delete(target);
|
||||
|
||||
// Get any exception classes in the throws typemap
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Append(w->def, " noexcept");
|
||||
Append(declaration, " noexcept");
|
||||
}
|
||||
ParmList *throw_parm_list = 0;
|
||||
|
||||
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
|
||||
|
|
|
|||
|
|
@ -5366,8 +5366,11 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
Delete(target);
|
||||
|
||||
// Get any exception classes in the throws typemap
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Append(w->def, " noexcept");
|
||||
Append(declaration, " noexcept");
|
||||
}
|
||||
ParmList *throw_parm_list = 0;
|
||||
|
||||
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
|
||||
Parm *p;
|
||||
int gencomma = 0;
|
||||
|
|
|
|||
|
|
@ -3112,6 +3112,10 @@ public:
|
|||
Delete(target);
|
||||
|
||||
// Get any exception classes in the throws typemap
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Append(w->def, " noexcept");
|
||||
Append(declaration, " noexcept");
|
||||
}
|
||||
ParmList *throw_parm_list = 0;
|
||||
|
||||
if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue