Piotr Caban : msvcrt: Add helper for exception throwing.
Alexandre Julliard
julliard at winehq.org
Mon Mar 27 15:26:08 CDT 2017
Module: wine
Branch: master
Commit: 90307e067f985f5963b62829993b320537578333
URL: http://source.winehq.org/git/wine.git/?a=commit;h=90307e067f985f5963b62829993b320537578333
Author: Piotr Caban <piotr at codeweavers.com>
Date: Mon Mar 27 10:26:54 2017 +0200
msvcrt: Add helper for exception throwing.
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/msvcrt/cpp.c | 38 +++++++++++++++++++-------------------
dlls/msvcrt/heap.c | 2 +-
dlls/msvcrt/lock.c | 8 ++++----
dlls/msvcrt/msvcrt.h | 11 +++++++----
dlls/msvcrt/scheduler.c | 4 ++--
5 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/dlls/msvcrt/cpp.c b/dlls/msvcrt/cpp.c
index 70f5cb5..b69ff9a 100644
--- a/dlls/msvcrt/cpp.c
+++ b/dlls/msvcrt/cpp.c
@@ -880,27 +880,27 @@ void msvcrt_init_exception(void *base)
}
#if _MSVCR_VER >= 80
-void throw_bad_alloc(const char *str)
+void throw_exception(exception_type et, HRESULT hr, const char *str)
{
- bad_alloc e;
- bad_alloc_ctor(&e, &str);
- _CxxThrowException(&e, &bad_alloc_exception_type);
-}
-#endif
-
+ switch(et) {
+ case EXCEPTION_BAD_ALLOC: {
+ bad_alloc e;
+ bad_alloc_ctor(&e, &str);
+ _CxxThrowException(&e, &bad_alloc_exception_type);
+ }
#if _MSVCR_VER >= 100
-void throw_scheduler_resource_allocation_error(const char *str, HRESULT hr)
-{
- scheduler_resource_allocation_error e;
- scheduler_resource_allocation_error_ctor_name(&e, str, hr);
- _CxxThrowException(&e.e, &scheduler_resource_allocation_error_exception_type);
-}
-
-void throw_improper_lock(const char *str)
-{
- improper_lock e;
- improper_lock_ctor_str(&e, str);
- _CxxThrowException(&e, &improper_lock_exception_type);
+ case EXCEPTION_SCHEDULER_RESOURCE_ALLOCATION_ERROR: {
+ scheduler_resource_allocation_error e;
+ scheduler_resource_allocation_error_ctor_name(&e, str, hr);
+ _CxxThrowException(&e.e, &scheduler_resource_allocation_error_exception_type);
+ }
+ case EXCEPTION_IMPROPER_LOCK: {
+ improper_lock e;
+ improper_lock_ctor_str(&e, str);
+ _CxxThrowException(&e, &improper_lock_exception_type);
+ }
+#endif
+ }
}
#endif
diff --git a/dlls/msvcrt/heap.c b/dlls/msvcrt/heap.c
index 3ae2599..ed41253 100644
--- a/dlls/msvcrt/heap.c
+++ b/dlls/msvcrt/heap.c
@@ -151,7 +151,7 @@ void* CDECL MSVCRT_operator_new(MSVCRT_size_t size)
TRACE("(%ld) out of memory\n", size);
#if _MSVCR_VER >= 80
- throw_bad_alloc("bad allocation");
+ throw_exception(EXCEPTION_BAD_ALLOC, 0, "bad allocation");
#endif
return NULL;
}
diff --git a/dlls/msvcrt/lock.c b/dlls/msvcrt/lock.c
index c2efae1..f4cf558 100644
--- a/dlls/msvcrt/lock.c
+++ b/dlls/msvcrt/lock.c
@@ -763,7 +763,7 @@ int __cdecl event_wait_for_multiple(event **events, MSVCRT_size_t count, MSVCRT_
wait = heap_alloc(FIELD_OFFSET(thread_wait, entries[count]));
if(!wait)
- throw_bad_alloc("bad allocation");
+ throw_exception(EXCEPTION_BAD_ALLOC, 0, "bad allocation");
ret = evt_wait(wait, events, count, wait_all, timeout);
heap_free(wait);
@@ -846,7 +846,7 @@ MSVCRT_bool __thiscall _Condition_variable_wait_for(_Condition_variable *this,
TRACE("(%p %p %d)\n", this, cs, timeout);
if(!(q = HeapAlloc(GetProcessHeap(), 0, sizeof(cv_queue)))) {
- throw_bad_alloc("bad allocation");
+ throw_exception(EXCEPTION_BAD_ALLOC, 0, "bad allocation");
}
critical_section_lock(&this->lock);
@@ -1026,7 +1026,7 @@ void __thiscall reader_writer_lock_lock(reader_writer_lock *this)
TRACE("(%p)\n", this);
if (this->thread_id == GetCurrentThreadId())
- throw_improper_lock("Already locked");
+ throw_exception(EXCEPTION_IMPROPER_LOCK, 0, "Already locked");
last = InterlockedExchangePointer((void**)&this->writer_tail, &q);
if (last) {
@@ -1057,7 +1057,7 @@ void __thiscall reader_writer_lock_lock_read(reader_writer_lock *this)
TRACE("(%p)\n", this);
if (this->thread_id == GetCurrentThreadId())
- throw_improper_lock("Already locked as writer");
+ throw_exception(EXCEPTION_IMPROPER_LOCK, 0, "Already locked as writer");
do {
q.next = this->reader_head;
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index 775ee0c..2b9d229 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -283,11 +283,14 @@ extern WORD MSVCRT__ctype [257];
void msvcrt_set_errno(int) DECLSPEC_HIDDEN;
#if _MSVCR_VER >= 80
-void throw_bad_alloc(const char*) DECLSPEC_HIDDEN;
-#endif
+typedef enum {
+ EXCEPTION_BAD_ALLOC,
#if _MSVCR_VER >= 100
-void throw_scheduler_resource_allocation_error(const char*, HRESULT) DECLSPEC_HIDDEN;
-void throw_improper_lock(const char*) DECLSPEC_HIDDEN;
+ EXCEPTION_SCHEDULER_RESOURCE_ALLOCATION_ERROR,
+ EXCEPTION_IMPROPER_LOCK,
+#endif
+} exception_type;
+void throw_exception(exception_type, HRESULT, const char*) DECLSPEC_HIDDEN;
#endif
void __cdecl _purecall(void);
diff --git a/dlls/msvcrt/scheduler.c b/dlls/msvcrt/scheduler.c
index 5d31d58..9551810 100644
--- a/dlls/msvcrt/scheduler.c
+++ b/dlls/msvcrt/scheduler.c
@@ -99,8 +99,8 @@ static Context* get_current_context(void)
if (context_tls_index == TLS_OUT_OF_INDEXES) {
int tls_index = TlsAlloc();
if (tls_index == TLS_OUT_OF_INDEXES) {
- throw_scheduler_resource_allocation_error(NULL,
- HRESULT_FROM_WIN32(GetLastError()));
+ throw_exception(EXCEPTION_SCHEDULER_RESOURCE_ALLOCATION_ERROR,
+ HRESULT_FROM_WIN32(GetLastError()), NULL);
return NULL;
}
More information about the wine-cvs
mailing list