2 * msvcrt.dll C++ objects
4 * Copyright 2000 Jon Griffiths
9 #include "msvcrt/malloc.h"
11 DEFAULT_DEBUG_CHANNEL(msvcrt);
14 typedef void (*v_table_ptr)();
16 static v_table_ptr exception_vtable[2];
17 static v_table_ptr bad_typeid_vtable[3];
18 static v_table_ptr __non_rtti_object_vtable[3];
19 static v_table_ptr bad_cast_vtable[3];
20 static v_table_ptr type_info_vtable[1];
22 typedef struct __exception
26 int do_free; /* FIXME: take string copy with char* ctor? */
29 typedef struct __bad_typeid
34 typedef struct ____non_rtti_object
39 typedef struct __bad_cast
44 typedef struct __type_info
51 /******************************************************************
52 * ??0exception@@QAE@ABQBD@Z (MSVCRT.@)
54 void MSVCRT_exception_ctor(exception * _this, const char ** name)
56 TRACE("(%p %s)\n",_this,*name);
57 _this->vtable = exception_vtable;
59 TRACE("name = %s\n",_this->name);
60 _this->do_free = 0; /* FIXME */
63 /******************************************************************
64 * ??0exception@@QAE@ABV0@@Z (MSVCRT.@)
66 void MSVCRT_exception_copy_ctor(exception * _this, const exception * rhs)
68 TRACE("(%p %p)\n",_this,rhs);
70 memcpy (_this, rhs, sizeof (*_this));
71 TRACE("name = %s\n",_this->name);
74 /******************************************************************
75 * ??0exception@@QAE@XZ (MSVCRT.@)
77 void MSVCRT_exception_default_ctor(exception * _this)
79 TRACE("(%p)\n",_this);
80 _this->vtable = exception_vtable;
82 _this->do_free = 0; /* FIXME */
85 /******************************************************************
86 * ??1exception@@UAE@XZ (MSVCRT.@)
88 void MSVCRT_exception_dtor(exception * _this)
90 TRACE("(%p)\n",_this);
93 /******************************************************************
94 * ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@)
96 exception * MSVCRT_exception_opequals(exception * _this, const exception * rhs)
98 TRACE("(%p %p)\n",_this,rhs);
99 memcpy (_this, rhs, sizeof (*_this));
100 TRACE("name = %s\n",_this->name);
104 /******************************************************************
105 * ??_Eexception@@UAEPAXI@Z (MSVCRT.@)
107 void * MSVCRT_exception__unknown_E(exception * _this, unsigned int arg1)
109 TRACE("(%p %d)\n",_this,arg1);
114 /******************************************************************
115 * ??_Gexception@@UAEPAXI@Z (MSVCRT.@)
117 void * MSVCRT_exception__unknown_G(exception * _this, unsigned int arg1)
119 TRACE("(%p %d)\n",_this,arg1);
124 /******************************************************************
125 * ?what@exception@@UBEPBDXZ (MSVCRT.@)
127 const char * __stdcall MSVCRT_exception_what(exception * _this)
129 TRACE("(%p) returning %s\n",_this,_this->name);
134 static terminate_function func_terminate=NULL;
135 static unexpected_function func_unexpected=NULL;
137 /******************************************************************
138 * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
140 terminate_function MSVCRT_set_terminate(terminate_function func)
142 terminate_function previous=func_terminate;
143 TRACE("(%p) returning %p\n",func,previous);
148 /******************************************************************
149 * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
151 unexpected_function MSVCRT_set_unexpected(unexpected_function func)
153 unexpected_function previous=func_unexpected;
154 TRACE("(%p) returning %p\n",func,previous);
155 func_unexpected=func;
159 /******************************************************************
160 * ?terminate@@YAXXZ (MSVCRT.@)
162 void MSVCRT_terminate()
167 /******************************************************************
168 * ?unexpected@@YAXXZ (MSVCRT.@)
170 void MSVCRT_unexpected()
172 (*func_unexpected)();
176 /******************************************************************
177 * ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@)
179 void MSVCRT_bad_typeid_copy_ctor(bad_typeid * _this, const bad_typeid * rhs)
181 TRACE("(%p %p)\n",_this,rhs);
182 MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
185 /******************************************************************
186 * ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@)
188 void MSVCRT_bad_typeid_ctor(bad_typeid * _this, const char * name)
190 TRACE("(%p %s)\n",_this,name);
191 MSVCRT_exception_ctor(&_this->base, &name);
192 _this->base.vtable = bad_typeid_vtable;
195 /******************************************************************
196 * ??1bad_typeid@@UAE@XZ (MSVCRT.@)
198 void MSVCRT_bad_typeid_dtor(bad_typeid * _this)
200 TRACE("(%p)\n",_this);
201 MSVCRT_exception_dtor(&_this->base);
204 /******************************************************************
205 * ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@)
207 bad_typeid * MSVCRT_bad_typeid_opequals(bad_typeid * _this, const bad_typeid * rhs)
209 TRACE("(%p %p)\n",_this,rhs);
210 MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
214 /******************************************************************
215 * ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@)
217 void MSVCRT___non_rtti_object_copy_ctor(__non_rtti_object * _this,
218 const __non_rtti_object * rhs)
220 TRACE("(%p %p)\n",_this,rhs);
221 MSVCRT_bad_typeid_copy_ctor(&_this->base,&rhs->base);
224 /******************************************************************
225 * ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@)
227 void MSVCRT___non_rtti_object_ctor(__non_rtti_object * _this,
230 TRACE("(%p %s)\n",_this,name);
231 MSVCRT_bad_typeid_ctor(&_this->base,name);
232 _this->base.base.vtable = __non_rtti_object_vtable;
235 /******************************************************************
236 * ??1__non_rtti_object@@UAE@XZ (MSVCRT.@)
238 void MSVCRT___non_rtti_object_dtor(__non_rtti_object * _this)
240 TRACE("(%p)\n",_this);
241 MSVCRT_bad_typeid_dtor(&_this->base);
244 /******************************************************************
245 * ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@)
247 __non_rtti_object * MSVCRT___non_rtti_object_opequals(__non_rtti_object * _this,
248 const __non_rtti_object *rhs)
250 TRACE("(%p %p)\n",_this,rhs);
251 memcpy (_this, rhs, sizeof (*_this));
252 TRACE("name = %s\n",_this->base.base.name);
256 /******************************************************************
257 * ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
259 void * MSVCRT___non_rtti_object__unknown_E(__non_rtti_object * _this, unsigned int arg1)
261 TRACE("(%p %d)\n",_this,arg1);
266 /******************************************************************
267 * ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
269 void * MSVCRT___non_rtti_object__unknown_G(__non_rtti_object * _this, unsigned int arg1)
271 TRACE("(%p %d)\n",_this,arg1);
276 /******************************************************************
277 * ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@)
279 void MSVCRT_bad_cast_ctor(bad_cast * _this, const char ** name)
281 TRACE("(%p %s)\n",_this,*name);
282 MSVCRT_exception_ctor(&_this->base, name);
283 _this->base.vtable = bad_cast_vtable;
286 /******************************************************************
287 * ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@)
289 void MSVCRT_bad_cast_copy_ctor(bad_cast * _this, const bad_cast * rhs)
291 TRACE("(%p %p)\n",_this,rhs);
292 MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
295 /******************************************************************
296 * ??1bad_cast@@UAE@XZ (MSVCRT.@)
298 void MSVCRT_bad_cast_dtor(bad_cast * _this)
300 TRACE("(%p)\n",_this);
301 MSVCRT_exception_dtor(&_this->base);
304 /******************************************************************
305 * ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@)
307 bad_cast * MSVCRT_bad_cast_opequals(bad_cast * _this, const bad_cast * rhs)
309 TRACE("(%p %p)\n",_this,rhs);
310 MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
314 /******************************************************************
315 * ??8type_info@@QBEHABV0@@Z (MSVCRT.@)
317 int __stdcall MSVCRT_type_info_opequals_equals(type_info * _this, const type_info * rhs)
319 TRACE("(%p %p) returning %d\n",_this,rhs,_this->name == rhs->name);
320 return _this->name == rhs->name;
323 /******************************************************************
324 * ??9type_info@@QBEHABV0@@Z (MSVCRT.@)
326 int __stdcall MSVCRT_type_info_opnot_equals(type_info * _this, const type_info * rhs)
328 TRACE("(%p %p) returning %d\n",_this,rhs,_this->name == rhs->name);
329 return _this->name != rhs->name;
332 /******************************************************************
333 * ??1type_info@@UAE@XZ (MSVCRT.@)
335 void MSVCRT_type_info_dtor(type_info * _this)
337 TRACE("(%p)\n",_this);
339 MSVCRT_free(_this->data);
342 /******************************************************************
343 * ?name@type_info@@QBEPBDXZ (MSVCRT.@)
345 const char * __stdcall MSVCRT_type_info_name(type_info * _this)
347 TRACE("(%p) returning %s\n",_this,_this->name);
351 /******************************************************************
352 * ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@)
354 const char * __stdcall MSVCRT_type_info_raw_name(type_info * _this)
356 TRACE("(%p) returning %s\n",_this,_this->name);
361 /* INTERNAL: Set up vtables
362 * FIXME:should be static, cope with versions?
364 void msvcrt_init_vtables(void)
366 exception_vtable[0] = MSVCRT_exception_dtor;
367 exception_vtable[1] = (void*)MSVCRT_exception_what;
369 bad_typeid_vtable[0] = MSVCRT_bad_typeid_dtor;
370 bad_typeid_vtable[1] = exception_vtable[1];
371 bad_typeid_vtable[2] = _purecall; /* FIXME */
373 __non_rtti_object_vtable[0] = MSVCRT___non_rtti_object_dtor;
374 __non_rtti_object_vtable[1] = bad_typeid_vtable[1];
375 __non_rtti_object_vtable[2] = bad_typeid_vtable[2];
377 bad_cast_vtable[0] = MSVCRT_bad_cast_dtor;
378 bad_cast_vtable[1] = exception_vtable[1];
379 bad_cast_vtable[2] = _purecall; /* FIXME */
381 type_info_vtable[0] = MSVCRT_type_info_dtor;