From a22df2eca9d1726fa7af02cebc459eb373ed7fc7 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sat, 27 Nov 2010 00:13:44 +0000 Subject: [PATCH] [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 --- Examples/test-suite/d/Makefile.in | 1 + Examples/test-suite/d_exception_name.i | 15 +++++++++++++++ Lib/d/dhead.swg | 24 ++++++++++++------------ Source/Modules/d.cxx | 2 +- 4 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 Examples/test-suite/d_exception_name.i diff --git a/Examples/test-suite/d/Makefile.in b/Examples/test-suite/d/Makefile.in index 2e9eb827f..ec13fede3 100644 --- a/Examples/test-suite/d/Makefile.in +++ b/Examples/test-suite/d/Makefile.in @@ -16,6 +16,7 @@ endif TESTSUFFIX = _runme$(VERSIONSUFFIX).d CPP_TEST_CASES = \ + d_exception_name \ d_nativepointers \ exception_partial_info diff --git a/Examples/test-suite/d_exception_name.i b/Examples/test-suite/d_exception_name.i new file mode 100644 index 000000000..23f338a73 --- /dev/null +++ b/Examples/test-suite/d_exception_name.i @@ -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) {} + }; +%} diff --git a/Lib/d/dhead.swg b/Lib/d/dhead.swg index e4dca36e8..cb2b41079 100644 --- a/Lib/d/dhead.swg +++ b/Lib/d/dhead.swg @@ -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; %} diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index ce33b5252..c726ac022 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -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)) {