Added mappings for a few messages.
[wine] / dlls / msvcrt / cpp.c
1 /*
2  * msvcrt.dll C++ objects
3  *
4  * Copyright 2000 Jon Griffiths
5  */
6
7 #include "msvcrt.h"
8 #include "msvcrt/eh.h"
9 #include "msvcrt/malloc.h"
10
11 DEFAULT_DEBUG_CHANNEL(msvcrt);
12
13
14 typedef void (*v_table_ptr)();
15
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];
21
22 typedef struct __exception
23 {
24   v_table_ptr *vtable;
25   const char *name;
26   int do_free; /* FIXME: take string copy with char* ctor? */
27 } exception;
28
29 typedef struct __bad_typeid
30 {
31   exception base;
32 } bad_typeid;
33
34 typedef struct ____non_rtti_object
35 {
36   bad_typeid base;
37 } __non_rtti_object;
38
39 typedef struct __bad_cast
40 {
41   exception base;
42 } bad_cast;
43
44 typedef struct __type_info
45 {
46   v_table_ptr *vtable;
47   void *data;
48   char name[1];
49 } type_info;
50
51 /******************************************************************
52  *              ??0exception@@QAE@ABQBD@Z (MSVCRT.@)
53  */
54 void MSVCRT_exception_ctor(exception * _this, const char ** name)
55 {
56   TRACE("(%p %s)\n",_this,*name);
57   _this->vtable = exception_vtable;
58   _this->name = *name;
59   TRACE("name = %s\n",_this->name);
60   _this->do_free = 0; /* FIXME */
61 }
62
63 /******************************************************************
64  *              ??0exception@@QAE@ABV0@@Z (MSVCRT.@)
65  */
66 void MSVCRT_exception_copy_ctor(exception * _this, const exception * rhs)
67 {
68   TRACE("(%p %p)\n",_this,rhs);
69   if (_this != rhs)
70     memcpy (_this, rhs, sizeof (*_this));
71   TRACE("name = %s\n",_this->name);
72 }
73
74 /******************************************************************
75  *              ??0exception@@QAE@XZ (MSVCRT.@)
76  */
77 void MSVCRT_exception_default_ctor(exception * _this)
78 {
79   TRACE("(%p)\n",_this);
80   _this->vtable = exception_vtable;
81   _this->name = "";
82   _this->do_free = 0; /* FIXME */
83 }
84
85 /******************************************************************
86  *              ??1exception@@UAE@XZ (MSVCRT.@)
87  */
88 void MSVCRT_exception_dtor(exception * _this)
89 {
90   TRACE("(%p)\n",_this);
91 }
92
93 /******************************************************************
94  *              ??4exception@@QAEAAV0@ABV0@@Z (MSVCRT.@)
95  */
96 exception * MSVCRT_exception_opequals(exception * _this, const exception * rhs)
97 {
98   TRACE("(%p %p)\n",_this,rhs);
99   memcpy (_this, rhs, sizeof (*_this));
100   TRACE("name = %s\n",_this->name);
101   return _this;
102 }
103
104 /******************************************************************
105  *              ??_Eexception@@UAEPAXI@Z (MSVCRT.@)
106  */
107 void * MSVCRT_exception__unknown_E(exception * _this, unsigned int arg1)
108 {
109   TRACE("(%p %d)\n",_this,arg1);
110   _purecall();
111   return NULL;
112 }
113
114 /******************************************************************
115  *              ??_Gexception@@UAEPAXI@Z (MSVCRT.@)
116  */
117 void * MSVCRT_exception__unknown_G(exception * _this, unsigned int arg1)
118 {
119   TRACE("(%p %d)\n",_this,arg1);
120   _purecall();
121   return NULL;
122 }
123
124 /******************************************************************
125  *              ?what@exception@@UBEPBDXZ (MSVCRT.@)
126  */
127 const char * __stdcall MSVCRT_exception_what(exception * _this)
128 {
129   TRACE("(%p) returning %s\n",_this,_this->name);
130   return _this->name;
131 }
132
133
134 static terminate_function func_terminate=NULL;
135 static unexpected_function func_unexpected=NULL;
136
137 /******************************************************************
138  *              ?set_terminate@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
139  */
140 terminate_function MSVCRT_set_terminate(terminate_function func)
141 {
142   terminate_function previous=func_terminate;
143   TRACE("(%p) returning %p\n",func,previous);
144   func_terminate=func;
145   return previous;
146 }
147
148 /******************************************************************
149  *              ?set_unexpected@@YAP6AXXZP6AXXZ@Z (MSVCRT.@)
150  */
151 unexpected_function MSVCRT_set_unexpected(unexpected_function func)
152 {
153   unexpected_function previous=func_unexpected;
154   TRACE("(%p) returning %p\n",func,previous);
155   func_unexpected=func;
156   return previous;
157 }
158
159 /******************************************************************
160  *              ?terminate@@YAXXZ (MSVCRT.@)
161  */
162 void MSVCRT_terminate()
163 {
164   (*func_terminate)();
165 }
166
167 /******************************************************************
168  *              ?unexpected@@YAXXZ (MSVCRT.@)
169  */
170 void MSVCRT_unexpected()
171 {
172   (*func_unexpected)();
173 }
174
175
176 /******************************************************************
177  *              ??0bad_typeid@@QAE@ABV0@@Z (MSVCRT.@)
178  */
179 void MSVCRT_bad_typeid_copy_ctor(bad_typeid * _this, const bad_typeid * rhs)
180 {
181   TRACE("(%p %p)\n",_this,rhs);
182   MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
183 }
184
185 /******************************************************************
186  *              ??0bad_typeid@@QAE@PBD@Z (MSVCRT.@)
187  */
188 void MSVCRT_bad_typeid_ctor(bad_typeid * _this, const char * name)
189 {
190   TRACE("(%p %s)\n",_this,name);
191   MSVCRT_exception_ctor(&_this->base, &name);
192   _this->base.vtable = bad_typeid_vtable;
193 }
194
195 /******************************************************************
196  *              ??1bad_typeid@@UAE@XZ (MSVCRT.@)
197  */
198 void MSVCRT_bad_typeid_dtor(bad_typeid * _this)
199 {
200   TRACE("(%p)\n",_this);
201   MSVCRT_exception_dtor(&_this->base);
202 }
203
204 /******************************************************************
205  *              ??4bad_typeid@@QAEAAV0@ABV0@@Z (MSVCRT.@)
206  */
207 bad_typeid * MSVCRT_bad_typeid_opequals(bad_typeid * _this, const bad_typeid * rhs)
208 {
209   TRACE("(%p %p)\n",_this,rhs);
210   MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
211   return _this;
212 }
213
214 /******************************************************************
215  *              ??0__non_rtti_object@@QAE@ABV0@@Z (MSVCRT.@)
216  */
217 void MSVCRT___non_rtti_object_copy_ctor(__non_rtti_object * _this,
218                                                 const __non_rtti_object * rhs)
219 {
220   TRACE("(%p %p)\n",_this,rhs);
221   MSVCRT_bad_typeid_copy_ctor(&_this->base,&rhs->base);
222 }
223
224 /******************************************************************
225  *              ??0__non_rtti_object@@QAE@PBD@Z (MSVCRT.@)
226  */
227 void MSVCRT___non_rtti_object_ctor(__non_rtti_object * _this,
228                                            const char * name)
229 {
230   TRACE("(%p %s)\n",_this,name);
231   MSVCRT_bad_typeid_ctor(&_this->base,name);
232   _this->base.base.vtable = __non_rtti_object_vtable;
233 }
234
235 /******************************************************************
236  *              ??1__non_rtti_object@@UAE@XZ (MSVCRT.@)
237  */
238 void MSVCRT___non_rtti_object_dtor(__non_rtti_object * _this)
239 {
240   TRACE("(%p)\n",_this);
241   MSVCRT_bad_typeid_dtor(&_this->base);
242 }
243
244 /******************************************************************
245  *              ??4__non_rtti_object@@QAEAAV0@ABV0@@Z (MSVCRT.@)
246  */
247 __non_rtti_object * MSVCRT___non_rtti_object_opequals(__non_rtti_object * _this,
248                                                               const __non_rtti_object *rhs)
249 {
250   TRACE("(%p %p)\n",_this,rhs);
251   memcpy (_this, rhs, sizeof (*_this));
252   TRACE("name = %s\n",_this->base.base.name);
253   return _this;
254 }
255
256 /******************************************************************
257  *              ??_E__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
258  */
259 void * MSVCRT___non_rtti_object__unknown_E(__non_rtti_object * _this, unsigned int arg1)
260 {
261   TRACE("(%p %d)\n",_this,arg1);
262   _purecall();
263   return NULL;
264 }
265
266 /******************************************************************
267  *              ??_G__non_rtti_object@@UAEPAXI@Z (MSVCRT.@)
268  */
269 void * MSVCRT___non_rtti_object__unknown_G(__non_rtti_object * _this, unsigned int arg1)
270 {
271   TRACE("(%p %d)\n",_this,arg1);
272   _purecall();
273   return NULL;
274 }
275
276 /******************************************************************
277  *              ??0bad_cast@@QAE@ABQBD@Z (MSVCRT.@)
278  */
279 void MSVCRT_bad_cast_ctor(bad_cast * _this, const char ** name)
280 {
281   TRACE("(%p %s)\n",_this,*name);
282   MSVCRT_exception_ctor(&_this->base, name);
283   _this->base.vtable = bad_cast_vtable;
284 }
285
286 /******************************************************************
287  *              ??0bad_cast@@QAE@ABV0@@Z (MSVCRT.@)
288  */
289 void MSVCRT_bad_cast_copy_ctor(bad_cast * _this, const bad_cast * rhs)
290 {
291   TRACE("(%p %p)\n",_this,rhs);
292   MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
293 }
294
295 /******************************************************************
296  *              ??1bad_cast@@UAE@XZ (MSVCRT.@)
297  */
298 void MSVCRT_bad_cast_dtor(bad_cast * _this)
299 {
300   TRACE("(%p)\n",_this);
301   MSVCRT_exception_dtor(&_this->base);
302 }
303
304 /******************************************************************
305  *              ??4bad_cast@@QAEAAV0@ABV0@@Z (MSVCRT.@)
306  */
307 bad_cast * MSVCRT_bad_cast_opequals(bad_cast * _this, const bad_cast * rhs)
308 {
309   TRACE("(%p %p)\n",_this,rhs);
310   MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
311   return _this;
312 }
313
314 /******************************************************************
315  *              ??8type_info@@QBEHABV0@@Z (MSVCRT.@)
316  */
317 int __stdcall MSVCRT_type_info_opequals_equals(type_info * _this, const type_info * rhs)
318 {
319   TRACE("(%p %p) returning %d\n",_this,rhs,_this->name == rhs->name);
320   return _this->name == rhs->name;
321 }
322
323 /******************************************************************
324  *              ??9type_info@@QBEHABV0@@Z (MSVCRT.@)
325  */
326 int __stdcall MSVCRT_type_info_opnot_equals(type_info * _this, const type_info * rhs)
327 {
328   TRACE("(%p %p) returning %d\n",_this,rhs,_this->name == rhs->name);
329   return _this->name != rhs->name;
330 }
331
332 /******************************************************************
333  *              ??1type_info@@UAE@XZ (MSVCRT.@)
334  */
335 void MSVCRT_type_info_dtor(type_info * _this)
336 {
337   TRACE("(%p)\n",_this);
338   if (_this->data)
339     MSVCRT_free(_this->data);
340 }
341
342 /******************************************************************
343  *              ?name@type_info@@QBEPBDXZ (MSVCRT.@)
344  */
345 const char * __stdcall MSVCRT_type_info_name(type_info * _this)
346 {
347   TRACE("(%p) returning %s\n",_this,_this->name);
348   return _this->name;
349 }
350
351 /******************************************************************
352  *              ?raw_name@type_info@@QBEPBDXZ (MSVCRT.@)
353  */
354 const char * __stdcall MSVCRT_type_info_raw_name(type_info * _this)
355 {
356   TRACE("(%p) returning %s\n",_this,_this->name);
357   return _this->name;
358 }
359
360
361 /* INTERNAL: Set up vtables
362  * FIXME:should be static, cope with versions?
363  */
364 void msvcrt_init_vtables(void)
365 {
366   exception_vtable[0] = MSVCRT_exception_dtor;
367   exception_vtable[1] = (void*)MSVCRT_exception_what;
368
369   bad_typeid_vtable[0] = MSVCRT_bad_typeid_dtor;
370   bad_typeid_vtable[1] = exception_vtable[1];
371   bad_typeid_vtable[2] = _purecall; /* FIXME */
372
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];
376
377   bad_cast_vtable[0] = MSVCRT_bad_cast_dtor;
378   bad_cast_vtable[1] = exception_vtable[1];
379   bad_cast_vtable[2] = _purecall; /* FIXME */
380
381   type_info_vtable[0] = MSVCRT_type_info_dtor;
382
383 }
384