[D] Refer to the built-in Exception class using its fully-qualified name.

A C++ class called "Exception" could shadow the built-in one before, leading to compilation errors in the exception handling code.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12318 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
David Nadlinger 2010-11-27 00:13:44 +00:00
commit a22df2eca9
4 changed files with 29 additions and 13 deletions

View file

@ -16,6 +16,7 @@ endif
TESTSUFFIX = _runme$(VERSIONSUFFIX).d
CPP_TEST_CASES = \
d_exception_name \
d_nativepointers \
exception_partial_info

View file

@ -0,0 +1,15 @@
// Tests if exception handling still works in the presence of a wrapped C++
// class called »Exception«, which could shadow the built-in Exception class.
%module d_exception_name
%inline %{
class Exception {
Exception(int i) {}
};
class Foo {
~Foo() {}
public:
void bar(Exception *e) {}
};
%}

View file

@ -84,7 +84,7 @@ private class SwigExceptionHelper {
}
static void setException(char* message) {
auto exception = new Exception(tango.stdc.stringz.fromStringz(message).dup);
auto exception = new object.Exception(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
@ -131,9 +131,9 @@ public:
return pending;
}
static void set(Exception e) {
static void set(object.Exception e) {
if (m_sPendingException.val !is null) {
throw new Exception("FATAL: An earlier pending exception from C/C++ code " ~
throw new object.Exception("FATAL: An earlier pending exception from C/C++ code " ~
"was missed and thus not thrown (" ~ m_sPendingException.val.classinfo.name ~
": " ~ m_sPendingException.val.msg ~ ")!", e);
}
@ -144,8 +144,8 @@ public:
}
}
static Exception retrieve() {
Exception e = null;
static object.Exception retrieve() {
object.Exception e = null;
if (m_sPendingCount > 0) {
if (m_sPendingException.val !is null) {
e = m_sPendingException.val;
@ -163,7 +163,7 @@ private:
static int m_sPendingCount;
// The reference to the pending exception (if any) is stored thread-local.
alias tango.core.Thread.ThreadLocal!(Exception) ThreadLocalData;
alias tango.core.Thread.ThreadLocal!(object.Exception) ThreadLocalData;
static ThreadLocalData m_sPendingException;
}
alias void function(char* message) SwigExceptionCallback;
@ -187,7 +187,7 @@ private class SwigExceptionHelper {
}
static void setException(char* message) {
auto exception = new Exception(std.conv.to!string(message).idup);
auto exception = new object.Exception(std.conv.to!string(message).idup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
@ -210,9 +210,9 @@ public:
return pending;
}
static void set(Exception e) {
static void set(object.Exception e) {
if (m_sPendingException !is null) {
throw new Exception("FATAL: An earlier pending exception from C/C++ code " ~
throw new object.Exception("FATAL: An earlier pending exception from C/C++ code " ~
"was missed and thus not thrown (" ~ m_sPendingException.classinfo.name ~
": " ~ m_sPendingException.msg ~ ")!", e);
}
@ -223,8 +223,8 @@ public:
}
}
static Exception retrieve() {
Exception e = null;
static object.Exception retrieve() {
object.Exception e = null;
if (m_sPendingCount > 0) {
if (m_sPendingException !is null) {
e = m_sPendingException;
@ -242,7 +242,7 @@ private:
static shared int m_sPendingCount;
// The reference to the pending exception (if any) is stored thread-local.
static Exception m_sPendingException;
static object.Exception m_sPendingException;
}
alias void function(const char* message) SwigExceptionCallback;
%}

View file

@ -3216,7 +3216,7 @@ private:
if (*Char(destructor_call)) {
Replaceall(dispose_code, "$wcall", destructor_call);
} else {
Replaceall(dispose_code, "$wcall", "throw new Exception(\"C++ destructor does not have public access\")");
Replaceall(dispose_code, "$wcall", "throw new object.Exception(\"C++ destructor does not have public access\")");
}
if (*Char(dispose_code)) {