[PATCH] D28442: [libc++] Implement terminate(), unexpected() and uncaught_exceptions() on Windows

2017-01-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked an inline comment as done.
EricWF added a comment.

In https://reviews.llvm.org/D28442#638862, @smeenai wrote:

> Hooray for Microsoft for putting all these in msvcrt (their **C** runtime 
> library) instead of msvcprt (their C++ runtime library), I guess :p


Although Boo to `eh.h` for being in the same directory as the MSVC STL headers. 
If possible I would like to be able to compile libc++ without
adding that directory to the include paths.




Comment at: src/exception.cpp:53
+#if defined(_LIBCPP_ABI_MICROSOFT)
+  return ::set_unexpected(func);
+#else

smeenai wrote:
> MSDN says "unexpected is not used in the current C++ exception-handling 
> implementation", which is maybe not the most desirable thing in the world, 
> but I guess this is going away in C++17 anyway :D
Actually `unexpected()` has gone away in C++17 since C++17 removes "dynamic 
exception specifications" (ie `void foo() throw(int, ...)`). Therefore I 
suspect the doc is referring to that.

However I suspect are still used when `clang-cl` targets C++14 or newer.



Comment at: src/exception.cpp:139
+#elif defined(_LIBCPP_ABI_MICROSOFT)
+return __uncaught_exceptions();
+#else

smeenai wrote:
> Yay undocumented APIs (at least as far as I can see).
Undocumented API for sure. Unfortunately libc++ is going to have to rely on a 
number of undocumented API's because Microsoft doesn't provide documentation 
for porting an STL to Windows.


https://reviews.llvm.org/D28442



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28442: [libc++] Implement terminate(), unexpected() and uncaught_exceptions() on Windows

2017-01-06 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai accepted this revision.
smeenai added a comment.
This revision is now accepted and ready to land.

Hooray for Microsoft for putting all these in msvcrt (their **C** runtime 
library) instead of msvcprt (their C++ runtime library), I guess :p




Comment at: src/exception.cpp:53
+#if defined(_LIBCPP_ABI_MICROSOFT)
+  return ::set_unexpected(func);
+#else

MSDN says "unexpected is not used in the current C++ exception-handling 
implementation", which is maybe not the most desirable thing in the world, but 
I guess this is going away in C++17 anyway :D



Comment at: src/exception.cpp:139
+#elif defined(_LIBCPP_ABI_MICROSOFT)
+return __uncaught_exceptions();
+#else

Yay undocumented APIs (at least as far as I can see).


https://reviews.llvm.org/D28442



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28442: [libc++] Implement terminate(), unexpected() and uncaught_exceptions() on Windows

2017-01-06 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.
EricWF added reviewers: compnerd, smeenai, rnk, majnemer.
EricWF added a subscriber: cfe-commits.

This patch implements the following functions on Windows by forwarding to the 
MSVCRT:

- `get_terminate()`
- `set_terminate()`
- `terminate()`
- `set_unexpected()`
- `get_unexpected()`
- `unexpected()`
- `uncaught_exception()`

- `uncaught_exceptions()`


https://reviews.llvm.org/D28442

Files:
  src/exception.cpp


Index: src/exception.cpp
===
--- src/exception.cpp
+++ src/exception.cpp
@@ -12,7 +12,10 @@
 #include "exception"
 #include "new"
 
-#if defined(__APPLE__) && !defined(LIBCXXRT) && \
+#if defined(_LIBCPP_ABI_MICROSOFT)
+#include 
+#include 
+#elif defined(__APPLE__) && !defined(LIBCXXRT) && \
 !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY)
   #include 
 
@@ -46,13 +49,21 @@
 unexpected_handler
 set_unexpected(unexpected_handler func) _NOEXCEPT
 {
-return __sync_lock_test_and_set(&__unexpected_handler, func);
+#if defined(_LIBCPP_ABI_MICROSOFT)
+  return ::set_unexpected(func);
+#else
+  return __sync_lock_test_and_set(&__unexpected_handler, func);
+#endif
 }
 
 unexpected_handler
 get_unexpected() _NOEXCEPT
 {
-return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0);
+#if defined(_LIBCPP_ABI_MICROSOFT)
+  return ::_get_unexpected();
+#else
+  return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0);
+#endif
 }
 
 _LIBCPP_NORETURN
@@ -67,13 +78,21 @@
 terminate_handler
 set_terminate(terminate_handler func) _NOEXCEPT
 {
-return __sync_lock_test_and_set(&__terminate_handler, func);
+#if defined(_LIBCPP_ABI_MICROSOFT)
+  return ::set_terminate(func);
+#else
+  return __sync_lock_test_and_set(&__terminate_handler, func);
+#endif
 }
 
 terminate_handler
 get_terminate() _NOEXCEPT
 {
-return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0);
+#if defined(_LIBCPP_ABI_MICROSOFT)
+  return ::_get_terminate();
+#else
+  return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0);
+#endif
 }
 
 #ifndef __EMSCRIPTEN__ // We provide this in JS
@@ -103,6 +122,7 @@
 #endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION)
 
 #if !defined(LIBCXXRT) && !defined(__GLIBCXX__) && !defined(__EMSCRIPTEN__)
+
 bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; }
 
 int uncaught_exceptions() _NOEXCEPT
@@ -115,7 +135,9 @@
 # else
 return __cxa_uncaught_exception() ? 1 : 0;
 # endif
-#else  // __APPLE__
+#elif defined(_LIBCPP_ABI_MICROSOFT)
+return __uncaught_exceptions();
+#else
 #   if defined(_MSC_VER) && ! defined(__clang__)
 _LIBCPP_WARNING("uncaught_exceptions not yet implemented")
 #   else


Index: src/exception.cpp
===
--- src/exception.cpp
+++ src/exception.cpp
@@ -12,7 +12,10 @@
 #include "exception"
 #include "new"
 
-#if defined(__APPLE__) && !defined(LIBCXXRT) && \
+#if defined(_LIBCPP_ABI_MICROSOFT)
+#include 
+#include 
+#elif defined(__APPLE__) && !defined(LIBCXXRT) && \
 !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY)
   #include 
 
@@ -46,13 +49,21 @@
 unexpected_handler
 set_unexpected(unexpected_handler func) _NOEXCEPT
 {
-return __sync_lock_test_and_set(&__unexpected_handler, func);
+#if defined(_LIBCPP_ABI_MICROSOFT)
+  return ::set_unexpected(func);
+#else
+  return __sync_lock_test_and_set(&__unexpected_handler, func);
+#endif
 }
 
 unexpected_handler
 get_unexpected() _NOEXCEPT
 {
-return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0);
+#if defined(_LIBCPP_ABI_MICROSOFT)
+  return ::_get_unexpected();
+#else
+  return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0);
+#endif
 }
 
 _LIBCPP_NORETURN
@@ -67,13 +78,21 @@
 terminate_handler
 set_terminate(terminate_handler func) _NOEXCEPT
 {
-return __sync_lock_test_and_set(&__terminate_handler, func);
+#if defined(_LIBCPP_ABI_MICROSOFT)
+  return ::set_terminate(func);
+#else
+  return __sync_lock_test_and_set(&__terminate_handler, func);
+#endif
 }
 
 terminate_handler
 get_terminate() _NOEXCEPT
 {
-return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0);
+#if defined(_LIBCPP_ABI_MICROSOFT)
+  return ::_get_terminate();
+#else
+  return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0);
+#endif
 }
 
 #ifndef __EMSCRIPTEN__ // We provide this in JS
@@ -103,6 +122,7 @@
 #endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION)
 
 #if !defined(LIBCXXRT) && !defined(__GLIBCXX__) && !defined(__EMSCRIPTEN__)
+
 bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; }
 
 int uncaught_exceptions() _NOEXCEPT
@@ -115,7 +135,9 @@
 # else
 return __cxa_uncaught_exception() ? 1 : 0;
 # endif
-#else  // __APPLE__
+#elif defined(_LIBCPP_ABI_MICROSOFT)
+return __uncaught_exceptions();
+#else
 #   if defined(_MSC_VER) && ! defined(__clang__)