riched20: Initial support for changing font properties.
[wine/multimedia.git] / dlls / msvcp90 / exception.c
blobfaeadda8f6e9d0450bfaac2f47902c53d4e1783f
1 /*
2 * Copyright 2010 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
23 #include "msvcp90.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
30 #define CLASS_IS_SIMPLE_TYPE 1
31 #define CLASS_HAS_VIRTUAL_BASE_CLASS 4
33 void WINAPI _CxxThrowException(exception*,const cxx_exception_type*);
35 #if _MSVCP_VER >= 70
36 typedef const char **exception_name;
37 #define EXCEPTION_STR(name) (*name)
38 #define EXCEPTION_NAME(str) ((exception_name)&str)
39 #else
40 typedef const char *exception_name;
41 #define EXCEPTION_STR(name) (name)
42 #define EXCEPTION_NAME(str) (str)
43 #endif
45 /* vtables */
46 extern const vtable_ptr MSVCP_exception_vtable;
47 /* ??_7bad_alloc@std@@6B@ */
48 extern const vtable_ptr MSVCP_bad_alloc_vtable;
49 /* ??_7logic_error@std@@6B@ */
50 extern const vtable_ptr MSVCP_logic_error_vtable;
51 /* ??_7length_error@std@@6B@ */
52 extern const vtable_ptr MSVCP_length_error_vtable;
53 /* ??_7out_of_range@std@@6B@ */
54 extern const vtable_ptr MSVCP_out_of_range_vtable;
55 extern const vtable_ptr MSVCP_invalid_argument_vtable;
56 /* ??_7runtime_error@std@@6B@ */
57 extern const vtable_ptr MSVCP_runtime_error_vtable;
58 extern const vtable_ptr MSVCP_failure_vtable;
59 /* ??_7bad_cast@std@@6B@ */
60 extern const vtable_ptr MSVCP_bad_cast_vtable;
62 static void MSVCP_type_info_dtor(type_info * _this)
64 free(_this->name);
67 /* Unexported */
68 DEFINE_THISCALL_WRAPPER(MSVCP_type_info_vector_dtor,8)
69 void * __thiscall MSVCP_type_info_vector_dtor(type_info * _this, unsigned int flags)
71 TRACE("(%p %x)\n", _this, flags);
72 if (flags & 2)
74 /* we have an array, with the number of elements stored before the first object */
75 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
77 for (i = *ptr - 1; i >= 0; i--) MSVCP_type_info_dtor(_this + i);
78 MSVCRT_operator_delete(ptr);
80 else
82 MSVCP_type_info_dtor(_this);
83 if (flags & 1) MSVCRT_operator_delete(_this);
85 return _this;
88 DEFINE_RTTI_DATA0( type_info, 0, ".?AVtype_info@@" )
90 static exception* MSVCP_exception_ctor(exception *this, exception_name name)
92 TRACE("(%p %s)\n", this, EXCEPTION_STR(name));
94 this->vtable = &MSVCP_exception_vtable;
95 if(EXCEPTION_STR(name)) {
96 unsigned int name_len = strlen(EXCEPTION_STR(name)) + 1;
97 this->name = malloc(name_len);
98 memcpy(this->name, EXCEPTION_STR(name), name_len);
99 this->do_free = TRUE;
100 } else {
101 this->name = NULL;
102 this->do_free = FALSE;
104 return this;
107 DEFINE_THISCALL_WRAPPER(MSVCP_exception_copy_ctor,8)
108 exception* __thiscall MSVCP_exception_copy_ctor(exception *this, const exception *rhs)
110 TRACE("(%p,%p)\n", this, rhs);
112 if(!rhs->do_free) {
113 this->vtable = &MSVCP_exception_vtable;
114 this->name = rhs->name;
115 this->do_free = FALSE;
116 } else
117 MSVCP_exception_ctor(this, EXCEPTION_NAME(rhs->name));
118 TRACE("name = %s\n", this->name);
119 return this;
122 DEFINE_THISCALL_WRAPPER(MSVCP_exception_dtor,4)
123 void __thiscall MSVCP_exception_dtor(exception *this)
125 TRACE("(%p)\n", this);
126 this->vtable = &MSVCP_exception_vtable;
127 if(this->do_free)
128 free(this->name);
131 DEFINE_THISCALL_WRAPPER(MSVCP_exception_vector_dtor, 8)
132 void * __thiscall MSVCP_exception_vector_dtor(exception *this, unsigned int flags)
134 TRACE("%p %x\n", this, flags);
135 if(flags & 2) {
136 /* we have an array, with the number of elements stored before the first object */
137 INT_PTR i, *ptr = (INT_PTR *)this-1;
139 for(i=*ptr-1; i>=0; i--)
140 MSVCP_exception_dtor(this+i);
141 MSVCRT_operator_delete(ptr);
142 } else {
143 MSVCP_exception_dtor(this);
144 if(flags & 1)
145 MSVCRT_operator_delete(this);
148 return this;
151 DEFINE_RTTI_DATA0(exception, 0, ".?AVexception@std@@")
152 DEFINE_CXX_DATA0(exception, MSVCP_exception_dtor)
154 /* ?_Doraise@bad_alloc@std@@MBEXXZ */
155 /* ?_Doraise@bad_alloc@std@@MEBAXXZ */
156 /* ?_Doraise@logic_error@std@@MBEXXZ */
157 /* ?_Doraise@logic_error@std@@MEBAXXZ */
158 /* ?_Doraise@length_error@std@@MBEXXZ */
159 /* ?_Doraise@length_error@std@@MEBAXXZ */
160 /* ?_Doraise@out_of_range@std@@MBEXXZ */
161 /* ?_Doraise@out_of_range@std@@MEBAXXZ */
162 /* ?_Doraise@runtime_error@std@@MBEXXZ */
163 /* ?_Doraise@runtime_error@std@@MEBAXXZ */
164 /* ?_Doraise@bad_cast@std@@MBEXXZ */
165 /* ?_Doraise@bad_cast@std@@MEBAXXZ */
166 DEFINE_THISCALL_WRAPPER(MSVCP_exception__Doraise, 4)
167 void __thiscall MSVCP_exception__Doraise(exception *this)
169 FIXME("(%p) stub\n", this);
172 DEFINE_THISCALL_WRAPPER(MSVCP_exception_what,4)
173 const char* __thiscall MSVCP_exception_what(exception * this)
175 TRACE("(%p) returning %s\n", this, this->name);
176 return this->name ? this->name : "Unknown exception";
179 /* bad_alloc class data */
180 typedef exception bad_alloc;
182 /* ??0bad_alloc@std@@QAE@PBD@Z */
183 /* ??0bad_alloc@std@@QEAA@PEBD@Z */
184 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_ctor, 8)
185 bad_alloc* __thiscall MSVCP_bad_alloc_ctor(bad_alloc *this, exception_name name)
187 TRACE("%p %s\n", this, EXCEPTION_STR(name));
188 MSVCP_exception_ctor(this, name);
189 this->vtable = &MSVCP_bad_alloc_vtable;
190 return this;
193 /* ??0bad_alloc@std@@QAE@XZ */
194 /* ??0bad_alloc@std@@QEAA@XZ */
195 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_default_ctor, 4)
196 bad_alloc* __thiscall MSVCP_bad_alloc_default_ctor(bad_alloc *this)
198 static const char name[] = "bad allocation";
199 return MSVCP_bad_alloc_ctor(this, EXCEPTION_NAME(name));
202 /* ??0bad_alloc@std@@QAE@ABV01@@Z */
203 /* ??0bad_alloc@std@@QEAA@AEBV01@@Z */
204 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_copy_ctor, 8)
205 bad_alloc* __thiscall MSVCP_bad_alloc_copy_ctor(bad_alloc *this, const bad_alloc *rhs)
207 TRACE("%p %p\n", this, rhs);
208 MSVCP_exception_copy_ctor(this, rhs);
209 this->vtable = &MSVCP_bad_alloc_vtable;
210 return this;
213 /* ??1bad_alloc@std@@UAE@XZ */
214 /* ??1bad_alloc@std@@UEAA@XZ */
215 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_dtor, 4)
216 void __thiscall MSVCP_bad_alloc_dtor(bad_alloc *this)
218 TRACE("%p\n", this);
219 MSVCP_exception_dtor(this);
222 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_vector_dtor, 8)
223 void * __thiscall MSVCP_bad_alloc_vector_dtor(bad_alloc *this, unsigned int flags)
225 TRACE("%p %x\n", this, flags);
226 if(flags & 2) {
227 /* we have an array, with the number of elements stored before the first object */
228 INT_PTR i, *ptr = (INT_PTR *)this-1;
230 for(i=*ptr-1; i>=0; i--)
231 MSVCP_bad_alloc_dtor(this+i);
232 MSVCRT_operator_delete(ptr);
233 } else {
234 MSVCP_bad_alloc_dtor(this);
235 if(flags & 1)
236 MSVCRT_operator_delete(this);
239 return this;
242 /* ??4bad_alloc@std@@QAEAAV01@ABV01@@Z */
243 /* ??4bad_alloc@std@@QEAAAEAV01@AEBV01@@Z */
244 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_assign, 8)
245 bad_alloc* __thiscall MSVCP_bad_alloc_assign(bad_alloc *this, const bad_alloc *assign)
247 MSVCP_bad_alloc_dtor(this);
248 return MSVCP_bad_alloc_copy_ctor(this, assign);
251 DEFINE_RTTI_DATA1(bad_alloc, 0, &exception_rtti_base_descriptor, ".?AVbad_alloc@std@@")
252 DEFINE_CXX_DATA1(bad_alloc, &exception_cxx_type_info, MSVCP_bad_alloc_dtor)
254 /* logic_error class data */
255 typedef struct {
256 exception e;
257 basic_string_char str;
258 } logic_error;
260 static logic_error* MSVCP_logic_error_ctor( logic_error *this, exception_name name )
262 TRACE("%p %s\n", this, EXCEPTION_STR(name));
263 this->e.vtable = &MSVCP_logic_error_vtable;
264 this->e.name = NULL;
265 this->e.do_free = FALSE;
266 MSVCP_basic_string_char_ctor_cstr(&this->str, EXCEPTION_STR(name));
267 return this;
270 /* ??0logic_error@std@@QAE@ABV01@@Z */
271 /* ??0logic_error@std@@QEAA@AEBV01@@Z */
272 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_copy_ctor, 8)
273 logic_error* __thiscall MSVCP_logic_error_copy_ctor(
274 logic_error *this, const logic_error *rhs)
276 TRACE("%p %p\n", this, rhs);
277 MSVCP_exception_copy_ctor(&this->e, &rhs->e);
278 MSVCP_basic_string_char_copy_ctor(&this->str, &rhs->str);
279 this->e.vtable = &MSVCP_logic_error_vtable;
280 return this;
283 /* ??0logic_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
284 /* ??0logic_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
285 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_ctor_bstr, 8)
286 logic_error* __thiscall MSVCP_logic_error_ctor_bstr(logic_error *this, const basic_string_char *str)
288 const char *name = MSVCP_basic_string_char_c_str(str);
289 TRACE("(%p %p %s)\n", this, str, name);
290 return MSVCP_logic_error_ctor(this, EXCEPTION_NAME(name));
293 /* ??1logic_error@std@@UAE@XZ */
294 /* ??1logic_error@std@@UEAA@XZ */
295 /* ??1length_error@std@@UAE@XZ */
296 /* ??1length_error@std@@UEAA@XZ */
297 /* ??1out_of_range@std@@UAE@XZ */
298 /* ??1out_of_range@std@@UEAA@XZ */
299 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_dtor, 4)
300 void __thiscall MSVCP_logic_error_dtor(logic_error *this)
302 TRACE("%p\n", this);
303 MSVCP_exception_dtor(&this->e);
304 MSVCP_basic_string_char_dtor(&this->str);
307 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_vector_dtor, 8)
308 void* __thiscall MSVCP_logic_error_vector_dtor(
309 logic_error *this, unsigned int flags)
311 TRACE("%p %x\n", this, flags);
312 if(flags & 2) {
313 /* we have an array, with the number of elements stored before the first object */
314 INT_PTR i, *ptr = (INT_PTR *)this-1;
316 for(i=*ptr-1; i>=0; i--)
317 MSVCP_logic_error_dtor(this+i);
318 MSVCRT_operator_delete(ptr);
319 } else {
320 MSVCP_logic_error_dtor(this);
321 if(flags & 1)
322 MSVCRT_operator_delete(this);
325 return this;
328 /* ??4logic_error@std@@QAEAAV01@ABV01@@Z */
329 /* ??4logic_error@std@@QEAAAEAV01@AEBV01@@Z */
330 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_assign, 8)
331 logic_error* __thiscall MSVCP_logic_error_assign(logic_error *this, const logic_error *assign)
333 MSVCP_logic_error_dtor(this);
334 return MSVCP_logic_error_copy_ctor(this, assign);
337 /* ?what@logic_error@std@@UBEPBDXZ */
338 /* ?what@logic_error@std@@UEBAPEBDXZ */
339 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_what, 4)
340 const char* __thiscall MSVCP_logic_error_what(logic_error *this)
342 TRACE("%p\n", this);
343 return MSVCP_basic_string_char_c_str(&this->str);
346 DEFINE_RTTI_DATA1(logic_error, 0, &exception_rtti_base_descriptor, ".?AVlogic_error@std@@")
347 DEFINE_CXX_DATA1(logic_error, &exception_cxx_type_info, MSVCP_logic_error_dtor)
349 /* length_error class data */
350 typedef logic_error length_error;
352 static length_error* MSVCP_length_error_ctor( length_error *this, exception_name name )
354 TRACE("%p %s\n", this, EXCEPTION_STR(name));
355 MSVCP_logic_error_ctor(this, name);
356 this->e.vtable = &MSVCP_length_error_vtable;
357 return this;
360 /* ??0length_error@std@@QAE@ABV01@@Z */
361 /* ??0length_error@std@@QEAA@AEBV01@@Z */
362 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_copy_ctor, 8)
363 length_error* __thiscall MSVCP_length_error_copy_ctor(
364 length_error *this, const length_error *rhs)
366 TRACE("%p %p\n", this, rhs);
367 MSVCP_logic_error_copy_ctor(this, rhs);
368 this->e.vtable = &MSVCP_length_error_vtable;
369 return this;
372 /* ??0length_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
373 /* ??0length_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
374 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_ctor_bstr, 8)
375 length_error* __thiscall MSVCP_length_error_ctor_bstr(length_error *this, const basic_string_char *str)
377 const char *name = MSVCP_basic_string_char_c_str(str);
378 TRACE("(%p %p %s)\n", this, str, name);
379 return MSVCP_length_error_ctor(this, EXCEPTION_NAME(name));
382 /* ??4length_error@std@@QAEAAV01@ABV01@@Z */
383 /* ??4length_error@std@@QEAAAEAV01@AEBV01@@Z */
384 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_assign, 8)
385 length_error* __thiscall MSVCP_length_error_assign(length_error *this, const length_error *assign)
387 MSVCP_logic_error_dtor(this);
388 return MSVCP_length_error_copy_ctor(this, assign);
391 DEFINE_RTTI_DATA2(length_error, 0, &logic_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVlength_error@std@@")
392 DEFINE_CXX_DATA2(length_error, &logic_error_cxx_type_info, &exception_cxx_type_info, MSVCP_logic_error_dtor)
394 /* out_of_range class data */
395 typedef logic_error out_of_range;
397 static out_of_range* MSVCP_out_of_range_ctor( out_of_range *this, exception_name name )
399 TRACE("%p %s\n", this, EXCEPTION_STR(name));
400 MSVCP_logic_error_ctor(this, name);
401 this->e.vtable = &MSVCP_out_of_range_vtable;
402 return this;
405 /* ??0out_of_range@std@@QAE@ABV01@@Z */
406 /* ??0out_of_range@std@@QEAA@AEBV01@@Z */
407 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_copy_ctor, 8)
408 out_of_range* __thiscall MSVCP_out_of_range_copy_ctor(
409 out_of_range *this, const out_of_range *rhs)
411 TRACE("%p %p\n", this, rhs);
412 MSVCP_logic_error_copy_ctor(this, rhs);
413 this->e.vtable = &MSVCP_out_of_range_vtable;
414 return this;
417 /* ??0out_of_range@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
418 /* ??0out_of_range@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
419 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_ctor_bstr, 8)
420 out_of_range* __thiscall MSVCP_out_of_range_ctor_bstr(out_of_range *this, const basic_string_char *str)
422 const char *name = MSVCP_basic_string_char_c_str(str);
423 TRACE("(%p %p %s)\n", this, str, name);
424 return MSVCP_out_of_range_ctor(this, EXCEPTION_NAME(name));
427 /* ??4out_of_range@std@@QAEAAV01@ABV01@@Z */
428 /* ??4out_of_range@std@@QEAAAEAV01@AEBV01@@Z */
429 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_assign, 8)
430 out_of_range* __thiscall MSVCP_out_of_range_assign(out_of_range *this, const out_of_range *assign)
432 MSVCP_logic_error_dtor(this);
433 return MSVCP_out_of_range_copy_ctor(this, assign);
436 DEFINE_RTTI_DATA2(out_of_range, 0, &logic_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVout_of_range@std@@")
437 DEFINE_CXX_DATA2(out_of_range, &logic_error_cxx_type_info, &exception_cxx_type_info, MSVCP_logic_error_dtor)
439 /* invalid_argument class data */
440 typedef logic_error invalid_argument;
442 static invalid_argument* MSVCP_invalid_argument_ctor( invalid_argument *this, exception_name name )
444 TRACE("%p %s\n", this, EXCEPTION_STR(name));
445 MSVCP_logic_error_ctor(this, name);
446 this->e.vtable = &MSVCP_invalid_argument_vtable;
447 return this;
450 DEFINE_THISCALL_WRAPPER(MSVCP_invalid_argument_copy_ctor, 8)
451 invalid_argument* __thiscall MSVCP_invalid_argument_copy_ctor(
452 invalid_argument *this, invalid_argument *rhs)
454 TRACE("%p %p\n", this, rhs);
455 MSVCP_logic_error_copy_ctor(this, rhs);
456 this->e.vtable = &MSVCP_invalid_argument_vtable;
457 return this;
460 DEFINE_RTTI_DATA2(invalid_argument, 0, &logic_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVinvalid_argument@std@@")
461 DEFINE_CXX_DATA2(invalid_argument, &logic_error_cxx_type_info, &exception_cxx_type_info, MSVCP_logic_error_dtor)
463 /* runtime_error class data */
464 typedef struct {
465 exception e;
466 basic_string_char str;
467 } runtime_error;
469 static runtime_error* MSVCP_runtime_error_ctor( runtime_error *this, exception_name name )
471 TRACE("%p %s\n", this, EXCEPTION_STR(name));
472 this->e.vtable = &MSVCP_runtime_error_vtable;
473 this->e.name = NULL;
474 this->e.do_free = FALSE;
475 MSVCP_basic_string_char_ctor_cstr(&this->str, EXCEPTION_STR(name));
476 return this;
479 /* ??0runtime_error@std@@QAE@ABV01@@Z */
480 /* ??0runtime_error@std@@QEAA@AEBV01@@Z */
481 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_copy_ctor, 8)
482 runtime_error* __thiscall MSVCP_runtime_error_copy_ctor(
483 runtime_error *this, const runtime_error *rhs)
485 TRACE("%p %p\n", this, rhs);
486 MSVCP_exception_copy_ctor(&this->e, &rhs->e);
487 MSVCP_basic_string_char_copy_ctor(&this->str, &rhs->str);
488 this->e.vtable = &MSVCP_runtime_error_vtable;
489 return this;
492 /* ??0runtime_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
493 /* ??0runtime_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
494 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_ctor_bstr, 8)
495 runtime_error* __thiscall MSVCP_runtime_error_ctor_bstr(runtime_error *this, const basic_string_char *str)
497 const char *name = MSVCP_basic_string_char_c_str(str);
498 TRACE("(%p %p %s)\n", this, str, name);
499 return MSVCP_runtime_error_ctor(this, EXCEPTION_NAME(name));
502 /* ??1runtime_error@std@@UAE@XZ */
503 /* ??1runtime_error@std@@UEAA@XZ */
504 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_dtor, 4)
505 void __thiscall MSVCP_runtime_error_dtor(runtime_error *this)
507 TRACE("%p\n", this);
508 MSVCP_exception_dtor(&this->e);
509 MSVCP_basic_string_char_dtor(&this->str);
512 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_vector_dtor, 8)
513 void* __thiscall MSVCP_runtime_error_vector_dtor(
514 runtime_error *this, unsigned int flags)
516 TRACE("%p %x\n", this, flags);
517 if(flags & 2) {
518 /* we have an array, with the number of elements stored before the first object */
519 INT_PTR i, *ptr = (INT_PTR *)this-1;
521 for(i=*ptr-1; i>=0; i--)
522 MSVCP_runtime_error_dtor(this+i);
523 MSVCRT_operator_delete(ptr);
524 } else {
525 MSVCP_runtime_error_dtor(this);
526 if(flags & 1)
527 MSVCRT_operator_delete(this);
530 return this;
533 /* ??4runtime_error@std@@QAEAAV01@ABV01@@Z */
534 /* ??4runtime_error@std@@QEAAAEAV01@AEBV01@@Z */
535 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_assign, 8)
536 runtime_error* __thiscall MSVCP_runtime_error_assign(runtime_error *this, const runtime_error *assign)
538 MSVCP_runtime_error_dtor(this);
539 return MSVCP_runtime_error_copy_ctor(this, assign);
542 /* ?what@runtime_error@std@@UBEPBDXZ */
543 /* ?what@runtime_error@std@@UEBAPEBDXZ */
544 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_what, 4)
545 const char* __thiscall MSVCP_runtime_error_what(runtime_error *this)
547 TRACE("%p\n", this);
548 return MSVCP_basic_string_char_c_str(&this->str);
551 DEFINE_RTTI_DATA1(runtime_error, 0, &exception_rtti_base_descriptor, ".?AVruntime_error@std@@")
552 DEFINE_CXX_DATA1(runtime_error, &exception_cxx_type_info, MSVCP_runtime_error_dtor)
554 /* failure class data */
555 typedef runtime_error failure;
557 static failure* MSVCP_failure_ctor( failure *this, exception_name name )
559 TRACE("%p %s\n", this, EXCEPTION_STR(name));
560 MSVCP_runtime_error_ctor(this, name);
561 this->e.vtable = &MSVCP_failure_vtable;
562 return this;
565 DEFINE_THISCALL_WRAPPER(MSVCP_failure_copy_ctor, 8)
566 failure* __thiscall MSVCP_failure_copy_ctor(
567 failure *this, failure *rhs)
569 TRACE("%p %p\n", this, rhs);
570 MSVCP_runtime_error_copy_ctor(this, rhs);
571 this->e.vtable = &MSVCP_failure_vtable;
572 return this;
575 DEFINE_THISCALL_WRAPPER(MSVCP_failure_dtor, 4)
576 void __thiscall MSVCP_failure_dtor(failure *this)
578 TRACE("%p\n", this);
579 MSVCP_runtime_error_dtor(this);
582 DEFINE_THISCALL_WRAPPER(MSVCP_failure_vector_dtor, 8)
583 void* __thiscall MSVCP_failure_vector_dtor(
584 failure *this, unsigned int flags)
586 TRACE("%p %x\n", this, flags);
587 return MSVCP_runtime_error_vector_dtor(this, flags);
590 DEFINE_THISCALL_WRAPPER(MSVCP_failure_what, 4)
591 const char* __thiscall MSVCP_failure_what(failure *this)
593 TRACE("%p\n", this);
594 return MSVCP_runtime_error_what(this);
597 DEFINE_RTTI_DATA2(failure, 0, &runtime_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVfailure@std@@")
598 DEFINE_CXX_DATA2(failure, &runtime_error_cxx_type_info, &exception_cxx_type_info, MSVCP_runtime_error_dtor)
600 /* bad_cast class data */
601 typedef exception bad_cast;
603 /* ??0bad_cast@std@@QAE@PBD@Z */
604 /* ??0bad_cast@std@@QEAA@PEBD@Z */
605 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_ctor, 8)
606 bad_cast* __thiscall MSVCP_bad_cast_ctor(bad_cast *this, const char *name)
608 TRACE("%p %s\n", this, name);
609 MSVCP_exception_ctor(this, EXCEPTION_NAME(name));
610 this->vtable = &MSVCP_bad_cast_vtable;
611 return this;
614 /* ??_Fbad_cast@@QAEXXZ */
615 /* ??_Fbad_cast@std@@QEAAXXZ */
616 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_default_ctor,4)
617 bad_cast* __thiscall MSVCP_bad_cast_default_ctor(bad_cast *this)
619 return MSVCP_bad_cast_ctor(this, "bad cast");
622 /* ??0bad_cast@std@@QAE@ABV01@@Z */
623 /* ??0bad_cast@std@@QEAA@AEBV01@@Z */
624 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_copy_ctor, 8)
625 bad_cast* __thiscall MSVCP_bad_cast_copy_ctor(bad_cast *this, const bad_cast *rhs)
627 TRACE("%p %p\n", this, rhs);
628 MSVCP_exception_copy_ctor(this, rhs);
629 this->vtable = &MSVCP_bad_cast_vtable;
630 return this;
633 /* ??1bad_cast@@UAE@XZ */
634 /* ??1bad_cast@std@@UEAA@XZ */
635 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_dtor, 4)
636 void __thiscall MSVCP_bad_cast_dtor(bad_cast *this)
638 TRACE("%p\n", this);
639 MSVCP_exception_dtor(this);
642 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_vector_dtor, 8)
643 void * __thiscall MSVCP_bad_cast_vector_dtor(bad_cast *this, unsigned int flags)
645 TRACE("%p %x\n", this, flags);
646 if(flags & 2) {
647 /* we have an array, with the number of elements stored before the first object */
648 INT_PTR i, *ptr = (INT_PTR *)this-1;
650 for(i=*ptr-1; i>=0; i--)
651 MSVCP_bad_cast_dtor(this+i);
652 MSVCRT_operator_delete(ptr);
653 } else {
654 MSVCP_bad_cast_dtor(this);
655 if(flags & 1)
656 MSVCRT_operator_delete(this);
659 return this;
662 /* ??4bad_cast@std@@QAEAAV01@ABV01@@Z */
663 /* ??4bad_cast@std@@QEAAAEAV01@AEBV01@@Z */
664 DEFINE_THISCALL_WRAPPER(MSVCP_bad_cast_opequals, 8)
665 bad_cast* __thiscall MSVCP_bad_cast_opequals(bad_cast *this, const bad_cast *rhs)
667 TRACE("(%p %p)\n", this, rhs);
669 if(this != rhs) {
670 MSVCP_exception_dtor(this);
671 MSVCP_exception_copy_ctor(this, rhs);
673 return this;
676 DEFINE_RTTI_DATA1(bad_cast, 0, &exception_rtti_base_descriptor, ".?AVbad_cast@std@@")
677 DEFINE_CXX_DATA1(bad_cast, &exception_cxx_type_info, MSVCP_bad_cast_dtor)
679 /* ?_Nomemory@std@@YAXXZ */
680 void __cdecl _Nomemory(void)
682 TRACE("()\n");
683 throw_exception(EXCEPTION_BAD_ALLOC, NULL);
686 /* ?_Xmem@tr1@std@@YAXXZ */
687 void __cdecl _Xmem(void)
689 TRACE("()\n");
690 throw_exception(EXCEPTION_BAD_ALLOC, NULL);
693 /* ?_Xinvalid_argument@std@@YAXPBD@Z */
694 /* ?_Xinvalid_argument@std@@YAXPEBD@Z */
695 void __cdecl _Xinvalid_argument(const char *str)
697 TRACE("(%s)\n", debugstr_a(str));
698 throw_exception(EXCEPTION_INVALID_ARGUMENT, str);
701 /* ?_Xlength_error@std@@YAXPBD@Z */
702 /* ?_Xlength_error@std@@YAXPEBD@Z */
703 void __cdecl _Xlength_error(const char *str)
705 TRACE("(%s)\n", debugstr_a(str));
706 throw_exception(EXCEPTION_LENGTH_ERROR, str);
709 /* ?_Xout_of_range@std@@YAXPBD@Z */
710 /* ?_Xout_of_range@std@@YAXPEBD@Z */
711 void __cdecl _Xout_of_range(const char *str)
713 TRACE("(%s)\n", debugstr_a(str));
714 throw_exception(EXCEPTION_OUT_OF_RANGE, str);
717 /* ?_Xruntime_error@std@@YAXPBD@Z */
718 /* ?_Xruntime_error@std@@YAXPEBD@Z */
719 void __cdecl _Xruntime_error(const char *str)
721 TRACE("(%s)\n", debugstr_a(str));
722 throw_exception(EXCEPTION_RUNTIME_ERROR, str);
725 /* ?uncaught_exception@std@@YA_NXZ */
726 MSVCP_bool __cdecl MSVCP__uncaught_exception(void)
728 return __uncaught_exception();
731 #if _MSVCP_VER >= 70
732 #define EXCEPTION_VTABLE(name,funcs) __ASM_VTABLE(name,funcs)
733 #else
734 #define EXCEPTION_VTABLE(name,funcs) __ASM_VTABLE(name,funcs VTABLE_ADD_FUNC(MSVCP_exception__Doraise))
735 #endif
737 #ifndef __GNUC__
738 void __asm_dummy_vtables(void) {
739 #endif
740 __ASM_VTABLE(type_info,
741 VTABLE_ADD_FUNC(MSVCP_type_info_vector_dtor));
742 EXCEPTION_VTABLE(exception,
743 VTABLE_ADD_FUNC(MSVCP_exception_vector_dtor)
744 VTABLE_ADD_FUNC(MSVCP_exception_what));
745 EXCEPTION_VTABLE(bad_alloc,
746 VTABLE_ADD_FUNC(MSVCP_bad_alloc_vector_dtor)
747 VTABLE_ADD_FUNC(MSVCP_exception_what));
748 EXCEPTION_VTABLE(logic_error,
749 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
750 VTABLE_ADD_FUNC(MSVCP_logic_error_what));
751 EXCEPTION_VTABLE(length_error,
752 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
753 VTABLE_ADD_FUNC(MSVCP_logic_error_what));
754 EXCEPTION_VTABLE(out_of_range,
755 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
756 VTABLE_ADD_FUNC(MSVCP_logic_error_what));
757 EXCEPTION_VTABLE(invalid_argument,
758 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
759 VTABLE_ADD_FUNC(MSVCP_logic_error_what));
760 EXCEPTION_VTABLE(runtime_error,
761 VTABLE_ADD_FUNC(MSVCP_runtime_error_vector_dtor)
762 VTABLE_ADD_FUNC(MSVCP_runtime_error_what));
763 EXCEPTION_VTABLE(failure,
764 VTABLE_ADD_FUNC(MSVCP_failure_vector_dtor)
765 VTABLE_ADD_FUNC(MSVCP_failure_what));
766 EXCEPTION_VTABLE(bad_cast,
767 VTABLE_ADD_FUNC(MSVCP_bad_cast_vector_dtor)
768 VTABLE_ADD_FUNC(MSVCP_exception_what));
769 #ifndef __GNUC__
771 #endif
773 /* Internal: throws selected exception */
774 void throw_exception(exception_type et, const char *str)
776 exception_name name = EXCEPTION_NAME(str);
778 switch(et) {
779 case EXCEPTION_RERAISE:
780 _CxxThrowException(NULL, NULL);
781 case EXCEPTION: {
782 exception e;
783 MSVCP_exception_ctor(&e, name);
784 _CxxThrowException(&e, &exception_cxx_type);
786 case EXCEPTION_BAD_ALLOC: {
787 bad_alloc e;
788 MSVCP_bad_alloc_ctor(&e, name);
789 _CxxThrowException(&e, &bad_alloc_cxx_type);
791 case EXCEPTION_BAD_CAST: {
792 bad_cast e;
793 MSVCP_bad_cast_ctor(&e, str);
794 _CxxThrowException(&e, &bad_cast_cxx_type);
796 case EXCEPTION_LOGIC_ERROR: {
797 logic_error e;
798 MSVCP_logic_error_ctor(&e, name);
799 _CxxThrowException((exception*)&e, &logic_error_cxx_type);
801 case EXCEPTION_LENGTH_ERROR: {
802 length_error e;
803 MSVCP_length_error_ctor(&e, name);
804 _CxxThrowException((exception*)&e, &length_error_cxx_type);
806 case EXCEPTION_OUT_OF_RANGE: {
807 out_of_range e;
808 MSVCP_out_of_range_ctor(&e, name);
809 _CxxThrowException((exception*)&e, &out_of_range_cxx_type);
811 case EXCEPTION_INVALID_ARGUMENT: {
812 invalid_argument e;
813 MSVCP_invalid_argument_ctor(&e, name);
814 _CxxThrowException((exception*)&e, &invalid_argument_cxx_type);
816 case EXCEPTION_RUNTIME_ERROR: {
817 runtime_error e;
818 MSVCP_runtime_error_ctor(&e, name);
819 _CxxThrowException((exception*)&e, &runtime_error_cxx_type);
821 case EXCEPTION_FAILURE: {
822 failure e;
823 MSVCP_failure_ctor(&e, name);
824 _CxxThrowException((exception*)&e, &failure_cxx_type);
829 void init_exception(void *base)
831 #ifdef __x86_64__
832 init_type_info_rtti(base);
833 init_exception_rtti(base);
834 init_bad_alloc_rtti(base);
835 init_logic_error_rtti(base);
836 init_length_error_rtti(base);
837 init_out_of_range_rtti(base);
838 init_invalid_argument_rtti(base);
839 init_runtime_error_rtti(base);
840 init_failure_rtti(base);
841 init_bad_cast_rtti(base);
843 init_exception_cxx(base);
844 init_bad_alloc_cxx(base);
845 init_logic_error_cxx(base);
846 init_length_error_cxx(base);
847 init_out_of_range_cxx(base);
848 init_invalid_argument_cxx(base);
849 init_runtime_error_cxx(base);
850 init_failure_cxx(base);
851 init_bad_cast_cxx(base);
852 #endif