2 * msvcrt.dll C++ objects
4 * Copyright 2000 Jon Griffiths
9 #include "msvcrt/malloc.h"
12 DEFAULT_DEBUG_CHANNEL(msvcrt);
17 typedef void (*v_table_ptr)();
19 static v_table_ptr exception_vtable[2];
20 static v_table_ptr bad_typeid_vtable[3];
21 static v_table_ptr __non_rtti_object_vtable[3];
22 static v_table_ptr bad_cast_vtable[3];
23 static v_table_ptr type_info_vtable[1];
25 typedef struct __exception
29 int do_free; /* FIXME: take string copy with char* ctor? */
32 typedef struct __bad_typeid
37 typedef struct ____non_rtti_object
42 typedef struct __bad_cast
47 typedef struct __type_info
54 /******************************************************************
55 * ??0exception@@QAE@ABQBD@Z (MSVCRT.@)
57 void MSVCRT_exception_ctor(exception * _this, const char ** name)
59 TRACE("(%p %s)\n",_this,*name);
60 _this->vtable = exception_vtable;
62 TRACE("name = %s\n",_this->name);
63 _this->do_free = 0; /* FIXME */
66 /******************************************************************
67 * ??0exception@@QAE@ABV0@@Z (MSVCRT.@)
69 void MSVCRT_exception_copy_ctor(exception * _this, const exception * rhs)
71 TRACE("(%p %p)\n",_this,rhs);
73 memcpy (_this, rhs, sizeof (*_this));
74 TRACE("name = %s\n",_this->name);
77 /******************************************************************
78 * ??0exception@@QAE@XZ (MSVCRT.@)
80 void MSVCRT_exception_default_ctor(exception * _this)
82 TRACE("(%p)\n",_this);
83 _this->vtable = exception_vtable;
85 _this->do_free = 0; /* FIXME */
88 /******************************************************************
89 * ??1exception@@UAE@XZ (MSVCRT.@)
91 void MSVCRT_exception_dtor(exception * _this)
93 TRACE("(%p)\n",_this);
96 /******************************************************************
97 * ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@)
99 exception * MSVCRT_exception_opequals(exception * _this, const exception * rhs)
101 TRACE("(%p %p)\n",_this,rhs);
102 memcpy (_this, rhs, sizeof (*_this));
103 TRACE("name = %s\n",_this->name);
107 /******************************************************************
108 * ??_Eexception@@UAEPAXI@Z (MSVCRT.@)
110 void * MSVCRT_exception__unknown_E(exception * _this, unsigned int arg1)
112 TRACE("(%p %d)\n",_this,arg1);
117 /******************************************************************
118 * ??_Gexception@@UAEPAXI@Z (MSVCRT.@)
120 void * MSVCRT_exception__unknown_G(exception * _this, unsigned int arg1)
122 TRACE("(%p %d)\n",_this,arg1);
127 /******************************************************************
128 * ?what@exception@@UBEPBDXZ (MSVCRT.@)
130 const char * __stdcall MSVCRT_exception_what(exception * _this)
132 TRACE("(%p) returning %s\n",_this,_this->name);
137 static terminate_function func_terminate=NULL;
138 static unexpected_function func_unexpected=NULL;
140 /******************************************************************
141 * ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
143 terminate_function MSVCRT_set_terminate(terminate_function func)
145 terminate_function previous=func_terminate;
146 TRACE("(%p) returning %p\n",func,previous);
151 /******************************************************************
152 * ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
154 unexpected_function MSVCRT_set_unexpected(unexpected_function func)
156 unexpected_function previous=func_unexpected;
157 TRACE("(%p) returning %p\n",func,previous);
158 func_unexpected=func;
162 /******************************************************************
163 * ?terminate@@YAXXZ (MSVCRT.@)
165 void MSVCRT_terminate()
170 /******************************************************************
171 * ?unexpected@@YAXXZ (MSVCRT.@)
173 void MSVCRT_unexpected()
175 (*func_unexpected)();
179 /******************************************************************
180 * ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@)
182 void MSVCRT_bad_typeid_copy_ctor(bad_typeid * _this, const bad_typeid * rhs)
184 TRACE("(%p %p)\n",_this,rhs);
185 MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
188 /******************************************************************
189 * ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@)
191 void MSVCRT_bad_typeid_ctor(bad_typeid * _this, const char * name)
193 TRACE("(%p %s)\n",_this,name);
194 MSVCRT_exception_ctor(&_this->base, &name);
195 _this->base.vtable = bad_typeid_vtable;
198 /******************************************************************
199 * ??1bad_typeid@@UAE@XZ (MSVCRT.@)
201 void MSVCRT_bad_typeid_dtor(bad_typeid * _this)
203 TRACE("(%p)\n",_this);
204 MSVCRT_exception_dtor(&_this->base);
207 /******************************************************************
208 * ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@)
210 bad_typeid * MSVCRT_bad_typeid_opequals(bad_typeid * _this, const bad_typeid * rhs)
212 TRACE("(%p %p)\n",_this,rhs);
213 MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
217 /******************************************************************
218 * ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@)
220 void MSVCRT___non_rtti_object_copy_ctor(__non_rtti_object * _this,
221 const __non_rtti_object * rhs)
223 TRACE("(%p %p)\n",_this,rhs);
224 MSVCRT_bad_typeid_copy_ctor(&_this->base,&rhs->base);
227 /******************************************************************
228 * ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@)
230 void MSVCRT___non_rtti_object_ctor(__non_rtti_object * _this,
233 TRACE("(%p %s)\n",_this,name);
234 MSVCRT_bad_typeid_ctor(&_this->base,name);
235 _this->base.base.vtable = __non_rtti_object_vtable;
238 /******************************************************************
239 * ??1__non_rtti_object@@UAE@XZ (MSVCRT.@)
241 void MSVCRT___non_rtti_object_dtor(__non_rtti_object * _this)
243 TRACE("(%p)\n",_this);
244 MSVCRT_bad_typeid_dtor(&_this->base);
247 /******************************************************************
248 * ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@)
250 __non_rtti_object * MSVCRT___non_rtti_object_opequals(__non_rtti_object * _this,
251 const __non_rtti_object *rhs)
253 TRACE("(%p %p)\n",_this,rhs);
254 memcpy (_this, rhs, sizeof (*_this));
255 TRACE("name = %s\n",_this->base.base.name);
259 /******************************************************************
260 * ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
262 void * MSVCRT___non_rtti_object__unknown_E(__non_rtti_object * _this, unsigned int arg1)
264 TRACE("(%p %d)\n",_this,arg1);
269 /******************************************************************
270 * ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
272 void * MSVCRT___non_rtti_object__unknown_G(__non_rtti_object * _this, unsigned int arg1)
274 TRACE("(%p %d)\n",_this,arg1);
279 /******************************************************************
280 * ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@)
282 void MSVCRT_bad_cast_ctor(bad_cast * _this, const char ** name)
284 TRACE("(%p %s)\n",_this,*name);
285 MSVCRT_exception_ctor(&_this->base, name);
286 _this->base.vtable = bad_cast_vtable;
289 /******************************************************************
290 * ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@)
292 void MSVCRT_bad_cast_copy_ctor(bad_cast * _this, const bad_cast * rhs)
294 TRACE("(%p %p)\n",_this,rhs);
295 MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
298 /******************************************************************
299 * ??1bad_cast@@UAE@XZ (MSVCRT.@)
301 void MSVCRT_bad_cast_dtor(bad_cast * _this)
303 TRACE("(%p)\n",_this);
304 MSVCRT_exception_dtor(&_this->base);
307 /******************************************************************
308 * ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@)
310 bad_cast * MSVCRT_bad_cast_opequals(bad_cast * _this, const bad_cast * rhs)
312 TRACE("(%p %p)\n",_this,rhs);
313 MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
317 /******************************************************************
318 * ??8type_info@@QBEHABV0@@Z (MSVCRT.@)
320 int __stdcall MSVCRT_type_info_opequals_equals(type_info * _this, const type_info * rhs)
322 TRACE("(%p %p) returning %d\n",_this,rhs,_this->name == rhs->name);
323 return _this->name == rhs->name;
326 /******************************************************************
327 * ??9type_info@@QBEHABV0@@Z (MSVCRT.@)
329 int __stdcall MSVCRT_type_info_opnot_equals(type_info * _this, const type_info * rhs)
331 TRACE("(%p %p) returning %d\n",_this,rhs,_this->name == rhs->name);
332 return _this->name != rhs->name;
335 /******************************************************************
336 * ??1type_info@@UAE@XZ (MSVCRT.@)
338 void MSVCRT_type_info_dtor(type_info * _this)
340 TRACE("(%p)\n",_this);
342 MSVCRT_free(_this->data);
345 /******************************************************************
346 * ?name@type_info@@QBEPBDXZ (MSVCRT.@)
348 const char * __stdcall MSVCRT_type_info_name(type_info * _this)
350 TRACE("(%p) returning %s\n",_this,_this->name);
354 /******************************************************************
355 * ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@)
357 const char * __stdcall MSVCRT_type_info_raw_name(type_info * _this)
359 TRACE("(%p) returning %s\n",_this,_this->name);
364 /* INTERNAL: Set up vtables
365 * FIXME:should be static, cope with versions?
367 void msvcrt_init_vtables(void)
369 exception_vtable[0] = MSVCRT_exception_dtor;
370 exception_vtable[1] = (void*)MSVCRT_exception_what;
372 bad_typeid_vtable[0] = MSVCRT_bad_typeid_dtor;
373 bad_typeid_vtable[1] = exception_vtable[1];
374 bad_typeid_vtable[2] = _purecall; /* FIXME */
376 __non_rtti_object_vtable[0] = MSVCRT___non_rtti_object_dtor;
377 __non_rtti_object_vtable[1] = bad_typeid_vtable[1];
378 __non_rtti_object_vtable[2] = bad_typeid_vtable[2];
380 bad_cast_vtable[0] = MSVCRT_bad_cast_dtor;
381 bad_cast_vtable[1] = exception_vtable[1];
382 bad_cast_vtable[2] = _purecall; /* FIXME */
384 type_info_vtable[0] = MSVCRT_type_info_dtor;