oledb32: Add IDataInitialize interface support.
[wine.git] / dlls / msvcp60 / exception.c
blobdde066cbd54d2dcaea25f6e4319b0b7f89c0a607
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 "msvcp.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
30 /* dlls/msvcrt/cppexcept.h */
31 typedef void (*cxx_copy_ctor)(void);
33 /* complete information about a C++ type */
34 typedef struct __cxx_type_info
36 UINT flags; /* flags (see CLASS_* flags below) */
37 const type_info *type_info; /* C++ type info */
38 this_ptr_offsets offsets; /* offsets for computing the this pointer */
39 unsigned int size; /* object size */
40 cxx_copy_ctor copy_ctor; /* copy constructor */
41 } cxx_type_info;
42 #define CLASS_IS_SIMPLE_TYPE 1
43 #define CLASS_HAS_VIRTUAL_BASE_CLASS 4
45 /* table of C++ types that apply for a given object */
46 typedef struct __cxx_type_info_table
48 UINT count; /* number of types */
49 const cxx_type_info *info[3]; /* variable length, we declare it large enough for static RTTI */
50 } cxx_type_info_table;
52 /* type information for an exception object */
53 typedef struct __cxx_exception_type
55 UINT flags; /* TYPE_FLAG flags */
56 void (*destructor)(void);/* exception object destructor */
57 void* /*cxx_exc_custom_handler*/ custom_handler; /* custom handler for this exception */
58 const cxx_type_info_table *type_info_table; /* list of types for this exception object */
59 } cxx_exception_type;
61 void WINAPI _CxxThrowException(exception*,const cxx_exception_type*);
63 /* vtables */
64 extern const vtable_ptr MSVCP_type_info_vtable;
65 extern const vtable_ptr MSVCP_exception_vtable;
66 /* ??_7bad_alloc@std@@6B@ */
67 extern const vtable_ptr MSVCP_bad_alloc_vtable;
68 /* ??_7logic_error@std@@6B@ */
69 extern const vtable_ptr MSVCP_logic_error_vtable;
70 /* ??_7length_error@std@@6B@ */
71 extern const vtable_ptr MSVCP_length_error_vtable;
72 /* ??_7out_of_range@std@@6B@ */
73 extern const vtable_ptr MSVCP_out_of_range_vtable;
74 extern const vtable_ptr MSVCP_invalid_argument_vtable;
75 /* ??_7runtime_error@std@@6B@ */
76 extern const vtable_ptr MSVCP_runtime_error_vtable;
78 static void MSVCP_type_info_dtor(type_info * _this)
80 free(_this->name);
83 DEFINE_THISCALL_WRAPPER(MSVCP_type_info_vector_dtor,8)
84 void * __thiscall MSVCP_type_info_vector_dtor(type_info * _this, unsigned int flags)
86 TRACE("(%p %x)\n", _this, flags);
87 if (flags & 2)
89 /* we have an array, with the number of elements stored before the first object */
90 INT_PTR i, *ptr = (INT_PTR *)_this - 1;
92 for (i = *ptr - 1; i >= 0; i--) MSVCP_type_info_dtor(_this + i);
93 MSVCRT_operator_delete(ptr);
95 else
97 MSVCP_type_info_dtor(_this);
98 if (flags & 1) MSVCRT_operator_delete(_this);
100 return _this;
103 DEFINE_RTTI_DATA0( type_info, 0, ".?AVtype_info@@" );
105 DEFINE_THISCALL_WRAPPER(MSVCP_exception_ctor, 8)
106 exception* __thiscall MSVCP_exception_ctor(exception *this, const char *name)
108 TRACE("(%p %s)\n", this, name);
110 this->vtable = &MSVCP_exception_vtable;
111 if(name) {
112 unsigned int name_len = strlen(name) + 1;
113 this->name = malloc(name_len);
114 memcpy(this->name, name, name_len);
115 this->do_free = TRUE;
116 } else {
117 this->name = NULL;
118 this->do_free = FALSE;
120 return this;
123 DEFINE_THISCALL_WRAPPER(MSVCP_exception_copy_ctor,8)
124 exception* __thiscall MSVCP_exception_copy_ctor(exception *this, const exception *rhs)
126 TRACE("(%p,%p)\n", this, rhs);
128 if(!rhs->do_free) {
129 this->vtable = &MSVCP_exception_vtable;
130 this->name = rhs->name;
131 this->do_free = FALSE;
132 } else
133 MSVCP_exception_ctor(this, rhs->name);
134 TRACE("name = %s\n", this->name);
135 return this;
138 DEFINE_THISCALL_WRAPPER(MSVCP_exception_dtor,4)
139 void __thiscall MSVCP_exception_dtor(exception *this)
141 TRACE("(%p)\n", this);
142 this->vtable = &MSVCP_exception_vtable;
143 if(this->do_free)
144 free(this->name);
147 DEFINE_THISCALL_WRAPPER(MSVCP_exception_vector_dtor, 8)
148 void * __thiscall MSVCP_exception_vector_dtor(exception *this, unsigned int flags)
150 TRACE("%p %x\n", this, flags);
151 if(flags & 2) {
152 /* we have an array, with the number of elements stored before the first object */
153 INT_PTR i, *ptr = (INT_PTR *)this-1;
155 for(i=*ptr-1; i>=0; i--)
156 MSVCP_exception_dtor(this+i);
157 MSVCRT_operator_delete(ptr);
158 } else {
159 MSVCP_exception_dtor(this);
160 if(flags & 1)
161 MSVCRT_operator_delete(this);
164 return this;
167 DEFINE_RTTI_DATA0(exception, 0, ".?AVexception@std@@");
169 /* ?_Doraise@bad_alloc@std@@MBEXXZ */
170 /* ?_Doraise@bad_alloc@std@@MEBAXXZ */
171 /* ?_Doraise@logic_error@std@@MBEXXZ */
172 /* ?_Doraise@logic_error@std@@MEBAXXZ */
173 /* ?_Doraise@length_error@std@@MBEXXZ */
174 /* ?_Doraise@length_error@std@@MEBAXXZ */
175 /* ?_Doraise@out_of_range@std@@MBEXXZ */
176 /* ?_Doraise@out_of_range@std@@MEBAXXZ */
177 /* ?_Doraise@runtime_error@std@@MBEXXZ */
178 /* ?_Doraise@runtime_error@std@@MEBAXXZ */
179 DEFINE_THISCALL_WRAPPER(MSVCP_exception__Doraise, 4)
180 void __thiscall MSVCP_exception__Doraise(exception *this)
182 FIXME("(%p) stub\n", this);
185 DEFINE_THISCALL_WRAPPER(MSVCP_exception_what,4)
186 const char* __thiscall MSVCP_exception_what(exception * this)
188 TRACE("(%p) returning %s\n", this, this->name);
189 return this->name ? this->name : "Unknown exception";
192 static const cxx_type_info exception_cxx_type_info = {
194 &exception_type_info,
195 { 0, -1, 0 },
196 sizeof(exception),
197 (cxx_copy_ctor)THISCALL(MSVCP_exception_dtor)
200 static const cxx_type_info_table exception_cxx_type_table = {
203 &exception_cxx_type_info,
204 NULL,
205 NULL
209 static const cxx_exception_type exception_cxx_type = {
211 (cxx_copy_ctor)THISCALL(MSVCP_exception_copy_ctor),
212 NULL,
213 &exception_cxx_type_table
216 /* bad_alloc class data */
217 typedef exception bad_alloc;
219 /* ??0bad_alloc@std@@QAE@PBD@Z */
220 /* ??0bad_alloc@std@@QEAA@PEBD@Z */
221 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_ctor, 8)
222 bad_alloc* __thiscall MSVCP_bad_alloc_ctor(bad_alloc *this, const char *name)
224 TRACE("%p %s\n", this, name);
225 MSVCP_exception_ctor(this, name);
226 this->vtable = &MSVCP_bad_alloc_vtable;
227 return this;
230 /* ??0bad_alloc@std@@QAE@XZ */
231 /* ??0bad_alloc@std@@QEAA@XZ */
232 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_default_ctor, 4)
233 bad_alloc* __thiscall MSVCP_bad_alloc_default_ctor(bad_alloc *this)
235 return MSVCP_bad_alloc_ctor(this, "bad allocation");
238 /* ??0bad_alloc@std@@QAE@ABV01@@Z */
239 /* ??0bad_alloc@std@@QEAA@AEBV01@@Z */
240 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_copy_ctor, 8)
241 bad_alloc* __thiscall MSVCP_bad_alloc_copy_ctor(bad_alloc *this, const bad_alloc *rhs)
243 TRACE("%p %p\n", this, rhs);
244 MSVCP_exception_copy_ctor(this, rhs);
245 this->vtable = &MSVCP_bad_alloc_vtable;
246 return this;
249 /* ??1bad_alloc@std@@UAE@XZ */
250 /* ??1bad_alloc@std@@UEAA@XZ */
251 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_dtor, 4)
252 void __thiscall MSVCP_bad_alloc_dtor(bad_alloc *this)
254 TRACE("%p\n", this);
255 MSVCP_exception_dtor(this);
258 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_vector_dtor, 8)
259 void * __thiscall MSVCP_bad_alloc_vector_dtor(bad_alloc *this, unsigned int flags)
261 TRACE("%p %x\n", this, flags);
262 if(flags & 2) {
263 /* we have an array, with the number of elements stored before the first object */
264 INT_PTR i, *ptr = (INT_PTR *)this-1;
266 for(i=*ptr-1; i>=0; i--)
267 MSVCP_bad_alloc_dtor(this+i);
268 MSVCRT_operator_delete(ptr);
269 } else {
270 MSVCP_bad_alloc_dtor(this);
271 if(flags & 1)
272 MSVCRT_operator_delete(this);
275 return this;
278 /* ??4bad_alloc@std@@QAEAAV01@ABV01@@Z */
279 /* ??4bad_alloc@std@@QEAAAEAV01@AEBV01@@Z */
280 DEFINE_THISCALL_WRAPPER(MSVCP_bad_alloc_assign, 8)
281 bad_alloc* __thiscall MSVCP_bad_alloc_assign(bad_alloc *this, const bad_alloc *assign)
283 MSVCP_bad_alloc_dtor(this);
284 return MSVCP_bad_alloc_copy_ctor(this, assign);
287 DEFINE_RTTI_DATA1(bad_alloc, 0, &exception_rtti_base_descriptor, ".?AVbad_alloc@std@@");
289 static const cxx_type_info bad_alloc_cxx_type_info = {
291 &bad_alloc_type_info,
292 { 0, -1, 0 },
293 sizeof(bad_alloc),
294 (cxx_copy_ctor)THISCALL(MSVCP_bad_alloc_copy_ctor)
297 static const cxx_type_info_table bad_alloc_cxx_type_table = {
300 &bad_alloc_cxx_type_info,
301 &exception_cxx_type_info,
302 NULL
306 static const cxx_exception_type bad_alloc_cxx_type = {
308 (cxx_copy_ctor)THISCALL(MSVCP_bad_alloc_dtor),
309 NULL,
310 &bad_alloc_cxx_type_table
313 /* logic_error class data */
314 typedef struct {
315 exception e;
316 basic_string_char str;
317 } logic_error;
319 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_ctor, 8)
320 logic_error* __thiscall MSVCP_logic_error_ctor(
321 logic_error *this, const char *name)
323 TRACE("%p %s\n", this, name);
324 this->e.vtable = &MSVCP_logic_error_vtable;
325 this->e.name = NULL;
326 this->e.do_free = FALSE;
327 MSVCP_basic_string_char_ctor_cstr(&this->str, name);
328 return this;
331 /* ??0logic_error@std@@QAE@ABV01@@Z */
332 /* ??0logic_error@std@@QEAA@AEBV01@@Z */
333 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_copy_ctor, 8)
334 logic_error* __thiscall MSVCP_logic_error_copy_ctor(
335 logic_error *this, const logic_error *rhs)
337 TRACE("%p %p\n", this, rhs);
338 MSVCP_exception_copy_ctor(&this->e, &rhs->e);
339 MSVCP_basic_string_char_copy_ctor(&this->str, &rhs->str);
340 this->e.vtable = &MSVCP_logic_error_vtable;
341 return this;
344 /* ??0logic_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
345 /* ??0logic_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
346 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_ctor_bstr, 8)
347 logic_error* __thiscall MSVCP_logic_error_ctor_bstr(logic_error *this, const basic_string_char *str)
349 TRACE("(%p %p)\n", this, str);
350 return MSVCP_logic_error_ctor(this, MSVCP_basic_string_char_c_str(str));
353 /* ??1logic_error@std@@UAE@XZ */
354 /* ??1logic_error@std@@UEAA@XZ */
355 /* ??1length_error@std@@UAE@XZ */
356 /* ??1length_error@std@@UEAA@XZ */
357 /* ??1out_of_range@std@@UAE@XZ */
358 /* ??1out_of_range@std@@UEAA@XZ */
359 /* ??1runtime_error@std@@UAE@XZ */
360 /* ??1runtime_error@std@@UEAA@XZ */
361 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_dtor, 4)
362 void __thiscall MSVCP_logic_error_dtor(logic_error *this)
364 TRACE("%p\n", this);
365 MSVCP_exception_dtor(&this->e);
366 MSVCP_basic_string_char_dtor(&this->str);
369 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_vector_dtor, 8)
370 void* __thiscall MSVCP_logic_error_vector_dtor(
371 logic_error *this, unsigned int flags)
373 TRACE("%p %x\n", this, flags);
374 if(flags & 2) {
375 /* we have an array, with the number of elements stored before the first object */
376 INT_PTR i, *ptr = (INT_PTR *)this-1;
378 for(i=*ptr-1; i>=0; i--)
379 MSVCP_logic_error_dtor(this+i);
380 MSVCRT_operator_delete(ptr);
381 } else {
382 MSVCP_logic_error_dtor(this);
383 if(flags & 1)
384 MSVCRT_operator_delete(this);
387 return this;
390 /* ??4logic_error@std@@QAEAAV01@ABV01@@Z */
391 /* ??4logic_error@std@@QEAAAEAV01@AEBV01@@Z */
392 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_assign, 8)
393 logic_error* __thiscall MSVCP_logic_error_assign(logic_error *this, const logic_error *assign)
395 MSVCP_logic_error_dtor(this);
396 return MSVCP_logic_error_copy_ctor(this, assign);
399 /* ?what@logic_error@std@@UBEPBDXZ */
400 /* ?what@logic_error@std@@UEBAPEBDXZ */
401 DEFINE_THISCALL_WRAPPER(MSVCP_logic_error_what, 4)
402 const char* __thiscall MSVCP_logic_error_what(logic_error *this)
404 TRACE("%p\n", this);
405 return MSVCP_basic_string_char_c_str(&this->str);
408 DEFINE_RTTI_DATA1(logic_error, 0, &exception_rtti_base_descriptor, ".?AVlogic_error@std@@");
410 static const cxx_type_info logic_error_cxx_type_info = {
412 &logic_error_type_info,
413 { 0, -1, 0 },
414 sizeof(logic_error),
415 (cxx_copy_ctor)THISCALL(MSVCP_logic_error_copy_ctor)
418 static const cxx_type_info_table logic_error_cxx_type_table = {
421 &logic_error_cxx_type_info,
422 &exception_cxx_type_info,
423 NULL
427 static const cxx_exception_type logic_error_cxx_type = {
429 (cxx_copy_ctor)THISCALL(MSVCP_logic_error_dtor),
430 NULL,
431 &logic_error_cxx_type_table
434 /* length_error class data */
435 typedef logic_error length_error;
437 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_ctor, 8)
438 length_error* __thiscall MSVCP_length_error_ctor(
439 length_error *this, const char *name)
441 TRACE("%p %s\n", this, name);
442 MSVCP_logic_error_ctor(this, name);
443 this->e.vtable = &MSVCP_length_error_vtable;
444 return this;
447 /* ??0length_error@std@@QAE@ABV01@@Z */
448 /* ??0length_error@std@@QEAA@AEBV01@@Z */
449 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_copy_ctor, 8)
450 length_error* __thiscall MSVCP_length_error_copy_ctor(
451 length_error *this, const length_error *rhs)
453 TRACE("%p %p\n", this, rhs);
454 MSVCP_logic_error_copy_ctor(this, rhs);
455 this->e.vtable = &MSVCP_length_error_vtable;
456 return this;
459 /* ??0length_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
460 /* ??0length_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
461 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_ctor_bstr, 8)
462 length_error* __thiscall MSVCP_length_error_ctor_bstr(length_error *this, const basic_string_char *str)
464 TRACE("(%p %p)\n", this, str);
465 return MSVCP_length_error_ctor(this, MSVCP_basic_string_char_c_str(str));
468 /* ??4length_error@std@@QAEAAV01@ABV01@@Z */
469 /* ??4length_error@std@@QEAAAEAV01@AEBV01@@Z */
470 DEFINE_THISCALL_WRAPPER(MSVCP_length_error_assign, 8)
471 length_error* __thiscall MSVCP_length_error_assign(length_error *this, const length_error *assign)
473 MSVCP_logic_error_dtor(this);
474 return MSVCP_length_error_copy_ctor(this, assign);
477 DEFINE_RTTI_DATA2(length_error, 0, &logic_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVlength_error@std@@");
479 static const cxx_type_info length_error_cxx_type_info = {
481 &length_error_type_info,
482 { 0, -1, 0 },
483 sizeof(length_error),
484 (cxx_copy_ctor)THISCALL(MSVCP_length_error_copy_ctor)
487 static const cxx_type_info_table length_error_cxx_type_table = {
490 &length_error_cxx_type_info,
491 &logic_error_cxx_type_info,
492 &exception_cxx_type_info
496 static const cxx_exception_type length_error_cxx_type = {
498 (cxx_copy_ctor)THISCALL(MSVCP_logic_error_dtor),
499 NULL,
500 &length_error_cxx_type_table
503 /* out_of_range class data */
504 typedef logic_error out_of_range;
506 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_ctor, 8)
507 out_of_range* __thiscall MSVCP_out_of_range_ctor(
508 out_of_range *this, const char *name)
510 TRACE("%p %s\n", this, name);
511 MSVCP_logic_error_ctor(this, name);
512 this->e.vtable = &MSVCP_out_of_range_vtable;
513 return this;
516 /* ??0out_of_range@std@@QAE@ABV01@@Z */
517 /* ??0out_of_range@std@@QEAA@AEBV01@@Z */
518 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_copy_ctor, 8)
519 out_of_range* __thiscall MSVCP_out_of_range_copy_ctor(
520 out_of_range *this, const out_of_range *rhs)
522 TRACE("%p %p\n", this, rhs);
523 MSVCP_logic_error_copy_ctor(this, rhs);
524 this->e.vtable = &MSVCP_out_of_range_vtable;
525 return this;
528 /* ??0out_of_range@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
529 /* ??0out_of_range@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
530 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_ctor_bstr, 8)
531 out_of_range* __thiscall MSVCP_out_of_range_ctor_bstr(out_of_range *this, const basic_string_char *str)
533 TRACE("(%p %p)\n", this, str);
534 return MSVCP_out_of_range_ctor(this, MSVCP_basic_string_char_c_str(str));
537 /* ??4out_of_range@std@@QAEAAV01@ABV01@@Z */
538 /* ??4out_of_range@std@@QEAAAEAV01@AEBV01@@Z */
539 DEFINE_THISCALL_WRAPPER(MSVCP_out_of_range_assign, 8)
540 out_of_range* __thiscall MSVCP_out_of_range_assign(out_of_range *this, const out_of_range *assign)
542 MSVCP_logic_error_dtor(this);
543 return MSVCP_out_of_range_copy_ctor(this, assign);
546 DEFINE_RTTI_DATA2(out_of_range, 0, &logic_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVout_of_range@std@@");
548 static const cxx_type_info out_of_range_cxx_type_info = {
550 &out_of_range_type_info,
551 { 0, -1, 0 },
552 sizeof(out_of_range),
553 (cxx_copy_ctor)THISCALL(MSVCP_out_of_range_copy_ctor)
556 static const cxx_type_info_table out_of_range_cxx_type_table = {
559 &out_of_range_cxx_type_info,
560 &logic_error_cxx_type_info,
561 &exception_cxx_type_info
565 static const cxx_exception_type out_of_range_cxx_type = {
567 (cxx_copy_ctor)THISCALL(MSVCP_logic_error_dtor),
568 NULL,
569 &out_of_range_cxx_type_table
572 /* invalid_argument class data */
573 typedef logic_error invalid_argument;
575 DEFINE_THISCALL_WRAPPER(MSVCP_invalid_argument_ctor, 8)
576 invalid_argument* __thiscall MSVCP_invalid_argument_ctor(
577 invalid_argument *this, const char *name)
579 TRACE("%p %s\n", this, name);
580 MSVCP_logic_error_ctor(this, name);
581 this->e.vtable = &MSVCP_invalid_argument_vtable;
582 return this;
585 DEFINE_THISCALL_WRAPPER(MSVCP_invalid_argument_copy_ctor, 8)
586 invalid_argument* __thiscall MSVCP_invalid_argument_copy_ctor(
587 invalid_argument *this, invalid_argument *rhs)
589 TRACE("%p %p\n", this, rhs);
590 MSVCP_logic_error_copy_ctor(this, rhs);
591 this->e.vtable = &MSVCP_invalid_argument_vtable;
592 return this;
595 DEFINE_RTTI_DATA2(invalid_argument, 0, &logic_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVinvalid_argument@std@@");
597 static const cxx_type_info invalid_argument_cxx_type_info = {
599 &invalid_argument_type_info,
600 { 0, -1, 0 },
601 sizeof(invalid_argument),
602 (cxx_copy_ctor)THISCALL(MSVCP_invalid_argument_copy_ctor)
605 static const cxx_type_info_table invalid_argument_cxx_type_table = {
608 &invalid_argument_cxx_type_info,
609 &logic_error_cxx_type_info,
610 &exception_cxx_type_info
614 static const cxx_exception_type invalid_argument_cxx_type = {
616 (cxx_copy_ctor)THISCALL(MSVCP_logic_error_dtor),
617 NULL,
618 &invalid_argument_cxx_type_table
621 /* runtime_error class data */
622 typedef logic_error runtime_error;
624 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_ctor, 8)
625 runtime_error* __thiscall MSVCP_runtime_error_ctor(
626 runtime_error *this, const char *name)
628 TRACE("%p %s\n", this, name);
629 MSVCP_logic_error_ctor(this, name);
630 this->e.vtable = &MSVCP_runtime_error_vtable;
631 return this;
634 /* ??0runtime_error@std@@QAE@ABV01@@Z */
635 /* ??0runtime_error@std@@QEAA@AEBV01@@Z */
636 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_copy_ctor, 8)
637 runtime_error* __thiscall MSVCP_runtime_error_copy_ctor(
638 runtime_error *this, const runtime_error *rhs)
640 TRACE("%p %p\n", this, rhs);
641 MSVCP_logic_error_copy_ctor(this, rhs);
642 this->e.vtable = &MSVCP_runtime_error_vtable;
643 return this;
646 /* ??0runtime_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
647 /* ??0runtime_error@std@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z */
648 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_ctor_bstr, 8)
649 runtime_error* __thiscall MSVCP_runtime_error_ctor_bstr(runtime_error *this, const basic_string_char *str)
651 TRACE("(%p %p)\n", this, str);
652 return MSVCP_runtime_error_ctor(this, MSVCP_basic_string_char_c_str(str));
655 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_vector_dtor, 8)
656 void* __thiscall MSVCP_runtime_error_vector_dtor(
657 runtime_error *this, unsigned int flags)
659 TRACE("%p %x\n", this, flags);
660 return MSVCP_logic_error_vector_dtor(this, flags);
663 /* ??4runtime_error@std@@QAEAAV01@ABV01@@Z */
664 /* ??4runtime_error@std@@QEAAAEAV01@AEBV01@@Z */
665 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_assign, 8)
666 runtime_error* __thiscall MSVCP_runtime_error_assign(runtime_error *this, const runtime_error *assign)
668 MSVCP_logic_error_dtor(this);
669 return MSVCP_runtime_error_copy_ctor(this, assign);
672 DEFINE_RTTI_DATA1(runtime_error, 0, &exception_rtti_base_descriptor, ".?AVruntime_error@std@@");
674 static const cxx_type_info runtime_error_cxx_type_info = {
676 &runtime_error_type_info,
677 { 0, -1, 0 },
678 sizeof(runtime_error),
679 (cxx_copy_ctor)THISCALL(MSVCP_runtime_error_copy_ctor)
682 static const cxx_type_info_table runtime_error_cxx_type_table = {
685 &runtime_error_cxx_type_info,
686 &exception_cxx_type_info,
687 NULL
691 static const cxx_exception_type runtime_error_cxx_type = {
693 (cxx_copy_ctor)THISCALL(MSVCP_logic_error_dtor),
694 NULL,
695 &runtime_error_cxx_type_table
698 /* ?what@runtime_error@std@@UBEPBDXZ */
699 /* ?what@runtime_error@std@@UEBAPEBDXZ */
700 DEFINE_THISCALL_WRAPPER(MSVCP_runtime_error_what, 4)
701 const char* __thiscall MSVCP_runtime_error_what(runtime_error *this)
703 TRACE("%p\n", this);
704 return MSVCP_basic_string_char_c_str(&this->str);
707 #ifndef __GNUC__
708 void __asm_dummy_vtables(void) {
709 #endif
710 __ASM_VTABLE(type_info,
711 VTABLE_ADD_FUNC(MSVCP_type_info_vector_dtor));
712 __ASM_VTABLE(exception,
713 VTABLE_ADD_FUNC(MSVCP_exception_vector_dtor)
714 VTABLE_ADD_FUNC(MSVCP_exception_what)
715 VTABLE_ADD_FUNC(MSVCP_exception__Doraise));
716 __ASM_VTABLE(bad_alloc,
717 VTABLE_ADD_FUNC(MSVCP_bad_alloc_vector_dtor)
718 VTABLE_ADD_FUNC(MSVCP_exception_what)
719 VTABLE_ADD_FUNC(MSVCP_exception__Doraise));
720 __ASM_VTABLE(logic_error,
721 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
722 VTABLE_ADD_FUNC(MSVCP_logic_error_what)
723 VTABLE_ADD_FUNC(MSVCP_exception__Doraise));
724 __ASM_VTABLE(length_error,
725 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
726 VTABLE_ADD_FUNC(MSVCP_logic_error_what)
727 VTABLE_ADD_FUNC(MSVCP_exception__Doraise));
728 __ASM_VTABLE(out_of_range,
729 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
730 VTABLE_ADD_FUNC(MSVCP_logic_error_what)
731 VTABLE_ADD_FUNC(MSVCP_exception__Doraise));
732 __ASM_VTABLE(invalid_argument,
733 VTABLE_ADD_FUNC(MSVCP_logic_error_vector_dtor)
734 VTABLE_ADD_FUNC(MSVCP_logic_error_what)
735 VTABLE_ADD_FUNC(MSVCP_exception__Doraise));
736 __ASM_VTABLE(runtime_error,
737 VTABLE_ADD_FUNC(MSVCP_runtime_error_vector_dtor)
738 VTABLE_ADD_FUNC(MSVCP_runtime_error_what)
739 VTABLE_ADD_FUNC(MSVCP_exception__Doraise));
740 #ifndef __GNUC__
742 #endif
744 /* Internal: throws selected exception */
745 void throw_exception(exception_type et, const char *str)
747 switch(et) {
748 case EXCEPTION: {
749 exception e;
750 MSVCP_exception_ctor(&e, str);
751 _CxxThrowException(&e, &exception_cxx_type);
753 case EXCEPTION_BAD_ALLOC: {
754 bad_alloc e;
755 MSVCP_bad_alloc_ctor(&e, str);
756 _CxxThrowException(&e, &bad_alloc_cxx_type);
758 case EXCEPTION_LOGIC_ERROR: {
759 logic_error e;
760 MSVCP_logic_error_ctor(&e, str);
761 _CxxThrowException((exception*)&e, &logic_error_cxx_type);
763 case EXCEPTION_LENGTH_ERROR: {
764 length_error e;
765 MSVCP_length_error_ctor(&e, str);
766 _CxxThrowException((exception*)&e, &length_error_cxx_type);
768 case EXCEPTION_OUT_OF_RANGE: {
769 out_of_range e;
770 MSVCP_out_of_range_ctor(&e, str);
771 _CxxThrowException((exception*)&e, &out_of_range_cxx_type);
773 case EXCEPTION_INVALID_ARGUMENT: {
774 invalid_argument e;
775 MSVCP_invalid_argument_ctor(&e, str);
776 _CxxThrowException((exception*)&e, &invalid_argument_cxx_type);
778 case EXCEPTION_RUNTIME_ERROR: {
779 runtime_error e;
780 MSVCP_runtime_error_ctor(&e, str);
781 _CxxThrowException((exception*)&e, &runtime_error_cxx_type);
783 default:
784 ERR("exception type not handled: %d\n", et);
788 void init_exception(void *base)
790 #ifdef __x86_64__
791 init_type_info_rtti(base);
792 init_exception_rtti(base);
793 init_bad_alloc_rtti(base);
794 init_logic_error_rtti(base);
795 init_length_error_rtti(base);
796 init_out_of_range_rtti(base);
797 init_invalid_argument_rtti(base);
798 init_runtime_error_rtti(base);
799 #endif