msvcrt: Add helper for exception throwing.
Signed-off-by: Piotr Caban <piotr@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
895928860d
commit
90307e067f
|
@ -880,27 +880,27 @@ void msvcrt_init_exception(void *base)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if _MSVCR_VER >= 80
|
#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;
|
switch(et) {
|
||||||
bad_alloc_ctor(&e, &str);
|
case EXCEPTION_BAD_ALLOC: {
|
||||||
_CxxThrowException(&e, &bad_alloc_exception_type);
|
bad_alloc e;
|
||||||
}
|
bad_alloc_ctor(&e, &str);
|
||||||
#endif
|
_CxxThrowException(&e, &bad_alloc_exception_type);
|
||||||
|
}
|
||||||
#if _MSVCR_VER >= 100
|
#if _MSVCR_VER >= 100
|
||||||
void throw_scheduler_resource_allocation_error(const char *str, HRESULT hr)
|
case EXCEPTION_SCHEDULER_RESOURCE_ALLOCATION_ERROR: {
|
||||||
{
|
scheduler_resource_allocation_error e;
|
||||||
scheduler_resource_allocation_error e;
|
scheduler_resource_allocation_error_ctor_name(&e, str, hr);
|
||||||
scheduler_resource_allocation_error_ctor_name(&e, str, hr);
|
_CxxThrowException(&e.e, &scheduler_resource_allocation_error_exception_type);
|
||||||
_CxxThrowException(&e.e, &scheduler_resource_allocation_error_exception_type);
|
}
|
||||||
}
|
case EXCEPTION_IMPROPER_LOCK: {
|
||||||
|
improper_lock e;
|
||||||
void throw_improper_lock(const char *str)
|
improper_lock_ctor_str(&e, str);
|
||||||
{
|
_CxxThrowException(&e, &improper_lock_exception_type);
|
||||||
improper_lock e;
|
}
|
||||||
improper_lock_ctor_str(&e, str);
|
#endif
|
||||||
_CxxThrowException(&e, &improper_lock_exception_type);
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ void* CDECL MSVCRT_operator_new(MSVCRT_size_t size)
|
||||||
|
|
||||||
TRACE("(%ld) out of memory\n", size);
|
TRACE("(%ld) out of memory\n", size);
|
||||||
#if _MSVCR_VER >= 80
|
#if _MSVCR_VER >= 80
|
||||||
throw_bad_alloc("bad allocation");
|
throw_exception(EXCEPTION_BAD_ALLOC, 0, "bad allocation");
|
||||||
#endif
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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]));
|
wait = heap_alloc(FIELD_OFFSET(thread_wait, entries[count]));
|
||||||
if(!wait)
|
if(!wait)
|
||||||
throw_bad_alloc("bad allocation");
|
throw_exception(EXCEPTION_BAD_ALLOC, 0, "bad allocation");
|
||||||
ret = evt_wait(wait, events, count, wait_all, timeout);
|
ret = evt_wait(wait, events, count, wait_all, timeout);
|
||||||
heap_free(wait);
|
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);
|
TRACE("(%p %p %d)\n", this, cs, timeout);
|
||||||
|
|
||||||
if(!(q = HeapAlloc(GetProcessHeap(), 0, sizeof(cv_queue)))) {
|
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);
|
critical_section_lock(&this->lock);
|
||||||
|
@ -1026,7 +1026,7 @@ void __thiscall reader_writer_lock_lock(reader_writer_lock *this)
|
||||||
TRACE("(%p)\n", this);
|
TRACE("(%p)\n", this);
|
||||||
|
|
||||||
if (this->thread_id == GetCurrentThreadId())
|
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);
|
last = InterlockedExchangePointer((void**)&this->writer_tail, &q);
|
||||||
if (last) {
|
if (last) {
|
||||||
|
@ -1057,7 +1057,7 @@ void __thiscall reader_writer_lock_lock_read(reader_writer_lock *this)
|
||||||
TRACE("(%p)\n", this);
|
TRACE("(%p)\n", this);
|
||||||
|
|
||||||
if (this->thread_id == GetCurrentThreadId())
|
if (this->thread_id == GetCurrentThreadId())
|
||||||
throw_improper_lock("Already locked as writer");
|
throw_exception(EXCEPTION_IMPROPER_LOCK, 0, "Already locked as writer");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
q.next = this->reader_head;
|
q.next = this->reader_head;
|
||||||
|
|
|
@ -283,11 +283,14 @@ extern WORD MSVCRT__ctype [257];
|
||||||
|
|
||||||
void msvcrt_set_errno(int) DECLSPEC_HIDDEN;
|
void msvcrt_set_errno(int) DECLSPEC_HIDDEN;
|
||||||
#if _MSVCR_VER >= 80
|
#if _MSVCR_VER >= 80
|
||||||
void throw_bad_alloc(const char*) DECLSPEC_HIDDEN;
|
typedef enum {
|
||||||
#endif
|
EXCEPTION_BAD_ALLOC,
|
||||||
#if _MSVCR_VER >= 100
|
#if _MSVCR_VER >= 100
|
||||||
void throw_scheduler_resource_allocation_error(const char*, HRESULT) DECLSPEC_HIDDEN;
|
EXCEPTION_SCHEDULER_RESOURCE_ALLOCATION_ERROR,
|
||||||
void throw_improper_lock(const char*) DECLSPEC_HIDDEN;
|
EXCEPTION_IMPROPER_LOCK,
|
||||||
|
#endif
|
||||||
|
} exception_type;
|
||||||
|
void throw_exception(exception_type, HRESULT, const char*) DECLSPEC_HIDDEN;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void __cdecl _purecall(void);
|
void __cdecl _purecall(void);
|
||||||
|
|
|
@ -99,8 +99,8 @@ static Context* get_current_context(void)
|
||||||
if (context_tls_index == TLS_OUT_OF_INDEXES) {
|
if (context_tls_index == TLS_OUT_OF_INDEXES) {
|
||||||
int tls_index = TlsAlloc();
|
int tls_index = TlsAlloc();
|
||||||
if (tls_index == TLS_OUT_OF_INDEXES) {
|
if (tls_index == TLS_OUT_OF_INDEXES) {
|
||||||
throw_scheduler_resource_allocation_error(NULL,
|
throw_exception(EXCEPTION_SCHEDULER_RESOURCE_ALLOCATION_ERROR,
|
||||||
HRESULT_FROM_WIN32(GetLastError()));
|
HRESULT_FROM_WIN32(GetLastError()), NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue