[libcxxabi] r195502 - On Windows, typeids are different between DLLs and EXEs, so comparing

Yaron Keren yaron.keren at gmail.com
Fri Nov 22 13:43:23 PST 2013


Author: yrnkrn
Date: Fri Nov 22 15:43:23 2013
New Revision: 195502

URL: http://llvm.org/viewvc/llvm-project?rev=195502&view=rev
Log:
On Windows, typeids are different between DLLs and EXEs, so comparing
type_info* will work for typeids from the same compiled file but fail
for typeids from a DLL and an executable. Among other things, exceptions
are not caught by handlers since can_catch() returns false.

Defining _LIBCXX_DYNAMIC_FALLBACK does not help since can_catch() calls
is_equal() with use_strcmp=false so the string names are not compared.

This patch compares typeids first (cheap) and only they are different
calls strcmp.


Modified:
    libcxxabi/trunk/src/private_typeinfo.cpp

Modified: libcxxabi/trunk/src/private_typeinfo.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/private_typeinfo.cpp?rev=195502&r1=195501&r2=195502&view=diff
==============================================================================
--- libcxxabi/trunk/src/private_typeinfo.cpp (original)
+++ libcxxabi/trunk/src/private_typeinfo.cpp Fri Nov 22 15:43:23 2013
@@ -40,6 +40,18 @@
 #include <sys/syslog.h>
 #endif
 
+// On Windows, typeids are different between DLLs and EXEs, so comparing
+// type_info* will work for typeids from the same compiled file but fail
+// for typeids from a DLL and an executable. Among other things, exceptions
+// are not caught by handlers since can_catch() returns false.
+//
+// Defining _LIBCXX_DYNAMIC_FALLBACK does not help since can_catch() calls 
+// is_equal() with use_strcmp=false so the string names are not compared.
+
+#ifdef _WIN32
+#include <string.h>
+#endif
+
 namespace __cxxabiv1
 {
 
@@ -62,7 +74,11 @@ inline
 bool
 is_equal(const std::type_info* x, const std::type_info* y, bool)
 {
+#ifndef _WIN32
     return x == y;
+#else
+    return (x == y) || (strcmp(x->name(), y->name()) == 0);
+#endif    
 }
 
 #endif  // _LIBCXX_DYNAMIC_FALLBACK





More information about the cfe-commits mailing list