Added an unknown VxD error code.
[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/malloc.h"
9
10
11 DEFAULT_DEBUG_CHANNEL(msvcrt);
12
13
14 void _purecall(void);
15
16 typedef void (*v_table_ptr)();
17
18 static v_table_ptr exception_vtable[2];
19 static v_table_ptr bad_typeid_vtable[3];
20 static v_table_ptr __non_rtti_object_vtable[3];
21 static v_table_ptr bad_cast_vtable[3];
22 static v_table_ptr type_info_vtable[1];
23
24 typedef struct __exception
25 {
26   v_table_ptr *vtable;
27   const char *name;
28   int do_free; /* FIXME: take string copy with char* ctor? */
29 } exception;
30
31 typedef struct __bad_typeid
32 {
33   exception base;
34 } bad_typeid;
35
36 typedef struct ____non_rtti_object
37 {
38   bad_typeid base;
39 } __non_rtti_object;
40
41 typedef struct __bad_cast
42 {
43   exception base;
44 } bad_cast;
45
46 typedef struct __type_info
47 {
48   v_table_ptr *vtable;
49   void *data;
50   char name[1];
51 } type_info;
52
53 /******************************************************************
54  *              exception_ctor (MSVCRT.@)
55  */
56 void MSVCRT_exception_ctor(exception * _this, const char ** name)
57 {
58   TRACE("(%p %s)\n",_this,*name);
59   _this->vtable = exception_vtable;
60   _this->name = *name;
61   TRACE("name = %s\n",_this->name);
62   _this->do_free = 0; /* FIXME */
63 }
64
65 /******************************************************************
66  *              exception_copy_ctor (MSVCRT.@)
67  */
68 void MSVCRT_exception_copy_ctor(exception * _this, const exception * rhs)
69 {
70   TRACE("(%p %p)\n",_this,rhs);
71   if (_this != rhs)
72     memcpy (_this, rhs, sizeof (*_this));
73   TRACE("name = %s\n",_this->name);
74 }
75
76 /******************************************************************
77  *              exception_default_ctor (MSVCRT.@)
78  */
79 void MSVCRT_exception_default_ctor(exception * _this)
80 {
81   TRACE("(%p)\n",_this);
82   _this->vtable = exception_vtable;
83   _this->name = "";
84   _this->do_free = 0; /* FIXME */
85 }
86
87 /******************************************************************
88  *              exception_dtor (MSVCRT.@)
89  */
90 void MSVCRT_exception_dtor(exception * _this)
91 {
92   TRACE("(%p)\n",_this);
93 }
94
95 /******************************************************************
96  *              exception_opequals (MSVCRT.@)
97  */
98 exception * MSVCRT_exception_opequals(exception * _this, const exception * rhs)
99 {
100   TRACE("(%p %p)\n",_this,rhs);
101   memcpy (_this, rhs, sizeof (*_this));
102   TRACE("name = %s\n",_this->name);
103   return _this;
104 }
105
106 /******************************************************************
107  *              exception__unknown_E (MSVCRT.@)
108  */
109 void * MSVCRT_exception__unknown_E(exception * _this, unsigned int arg1)
110 {
111   TRACE("(%p %d)\n",_this,arg1);
112   _purecall();
113   return NULL;
114 }
115
116 /******************************************************************
117  *              exception__unknown_G (MSVCRT.@)
118  */
119 void * MSVCRT_exception__unknown_G(exception * _this, unsigned int arg1)
120 {
121   TRACE("(%p %d)\n",_this,arg1);
122   _purecall();
123   return NULL;
124 }
125
126 /******************************************************************
127  *              exception_what (MSVCRT.@)
128  */
129 const char * __stdcall MSVCRT_exception_what(exception * _this)
130 {
131   TRACE("(%p) returning %s\n",_this,_this->name);
132   return _this->name;
133 }
134
135
136 /******************************************************************
137  *              bad_typeid_copy_ctor (MSVCRT.@)
138  */
139 void MSVCRT_bad_typeid_copy_ctor(bad_typeid * _this, const bad_typeid * rhs)
140 {
141   TRACE("(%p %p)\n",_this,rhs);
142   MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
143 }
144
145 /******************************************************************
146  *              bad_typeid_ctor (MSVCRT.@)
147  */
148 void MSVCRT_bad_typeid_ctor(bad_typeid * _this, const char * name)
149 {
150   TRACE("(%p %s)\n",_this,name);
151   MSVCRT_exception_ctor(&_this->base, &name);
152   _this->base.vtable = bad_typeid_vtable;
153 }
154
155 /******************************************************************
156  *              bad_typeid_dtor (MSVCRT.@)
157  */
158 void MSVCRT_bad_typeid_dtor(bad_typeid * _this)
159 {
160   TRACE("(%p)\n",_this);
161   MSVCRT_exception_dtor(&_this->base);
162 }
163
164 /******************************************************************
165  *              bad_typeid_opequals (MSVCRT.@)
166  */
167 bad_typeid * MSVCRT_bad_typeid_opequals(bad_typeid * _this, const bad_typeid * rhs)
168 {
169   TRACE("(%p %p)\n",_this,rhs);
170   MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
171   return _this;
172 }
173
174 /******************************************************************
175  *              __non_rtti_object_copy_ctor (MSVCRT.@)
176  */
177 void MSVCRT___non_rtti_object_copy_ctor(__non_rtti_object * _this,
178                                                 const __non_rtti_object * rhs)
179 {
180   TRACE("(%p %p)\n",_this,rhs);
181   MSVCRT_bad_typeid_copy_ctor(&_this->base,&rhs->base);
182 }
183
184 /******************************************************************
185  *              __non_rtti_object_ctor (MSVCRT.@)
186  */
187 void MSVCRT___non_rtti_object_ctor(__non_rtti_object * _this,
188                                            const char * name)
189 {
190   TRACE("(%p %s)\n",_this,name);
191   MSVCRT_bad_typeid_ctor(&_this->base,name);
192   _this->base.base.vtable = __non_rtti_object_vtable;
193 }
194
195 /******************************************************************
196  *              __non_rtti_object_dtor (MSVCRT.@)
197  */
198 void MSVCRT___non_rtti_object_dtor(__non_rtti_object * _this)
199 {
200   TRACE("(%p)\n",_this);
201   MSVCRT_bad_typeid_dtor(&_this->base);
202 }
203
204 /******************************************************************
205  *              __non_rtti_object_opequals (MSVCRT.@)
206  */
207 __non_rtti_object * MSVCRT___non_rtti_object_opequals(__non_rtti_object * _this,
208                                                               const __non_rtti_object *rhs)
209 {
210   TRACE("(%p %p)\n",_this,rhs);
211   memcpy (_this, rhs, sizeof (*_this));
212   TRACE("name = %s\n",_this->base.base.name);
213   return _this;
214 }
215
216 /******************************************************************
217  *              __non_rtti_object__unknown_E (MSVCRT.@)
218  */
219 void * MSVCRT___non_rtti_object__unknown_E(__non_rtti_object * _this, unsigned int arg1)
220 {
221   TRACE("(%p %d)\n",_this,arg1);
222   _purecall();
223   return NULL;
224 }
225
226 /******************************************************************
227  *              __non_rtti_object__unknown_G (MSVCRT.@)
228  */
229 void * MSVCRT___non_rtti_object__unknown_G(__non_rtti_object * _this, unsigned int arg1)
230 {
231   TRACE("(%p %d)\n",_this,arg1);
232   _purecall();
233   return NULL;
234 }
235
236 /******************************************************************
237  *              bad_cast_ctor (MSVCRT.@)
238  */
239 void MSVCRT_bad_cast_ctor(bad_cast * _this, const char ** name)
240 {
241   TRACE("(%p %s)\n",_this,*name);
242   MSVCRT_exception_ctor(&_this->base, name);
243   _this->base.vtable = bad_cast_vtable;
244 }
245
246 /******************************************************************
247  *              bad_cast_copy_ctor (MSVCRT.@)
248  */
249 void MSVCRT_bad_cast_copy_ctor(bad_cast * _this, const bad_cast * rhs)
250 {
251   TRACE("(%p %p)\n",_this,rhs);
252   MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
253 }
254
255 /******************************************************************
256  *              bad_cast_dtor (MSVCRT.@)
257  */
258 void MSVCRT_bad_cast_dtor(bad_cast * _this)
259 {
260   TRACE("(%p)\n",_this);
261   MSVCRT_exception_dtor(&_this->base);
262 }
263
264 /******************************************************************
265  *              bad_cast_opequals (MSVCRT.@)
266  */
267 bad_cast * MSVCRT_bad_cast_opequals(bad_cast * _this, const bad_cast * rhs)
268 {
269   TRACE("(%p %p)\n",_this,rhs);
270   MSVCRT_exception_copy_ctor(&_this->base,&rhs->base);
271   return _this;
272 }
273
274 /******************************************************************
275  *              type_info_opequals_equals (MSVCRT.@)
276  */
277 int __stdcall MSVCRT_type_info_opequals_equals(type_info * _this, const type_info * rhs)
278 {
279   TRACE("(%p %p) returning %d\n",_this,rhs,_this->name == rhs->name);
280   return _this->name == rhs->name;
281 }
282
283 /******************************************************************
284  *              type_info_opnot_equals (MSVCRT.@)
285  */
286 int __stdcall MSVCRT_type_info_opnot_equals(type_info * _this, const type_info * rhs)
287 {
288   TRACE("(%p %p) returning %d\n",_this,rhs,_this->name == rhs->name);
289   return _this->name != rhs->name;
290 }
291
292 /******************************************************************
293  *              type_info_dtor (MSVCRT.@)
294  */
295 void MSVCRT_type_info_dtor(type_info * _this)
296 {
297   TRACE("(%p)\n",_this);
298   if (_this->data)
299     MSVCRT_free(_this->data);
300 }
301
302 /******************************************************************
303  *              type_info_name (MSVCRT.@)
304  */
305 const char * __stdcall MSVCRT_type_info_name(type_info * _this)
306 {
307   TRACE("(%p) returning %s\n",_this,_this->name);
308   return _this->name;
309 }
310
311 /******************************************************************
312  *              type_info_raw_name (MSVCRT.@)
313  */
314 const char * __stdcall MSVCRT_type_info_raw_name(type_info * _this)
315 {
316   TRACE("(%p) returning %s\n",_this,_this->name);
317   return _this->name;
318 }
319
320
321 /* INTERNAL: Set up vtables
322  * FIXME:should be static, cope with versions?
323  */
324 void msvcrt_init_vtables(void)
325 {
326   exception_vtable[0] = MSVCRT_exception_dtor;
327   exception_vtable[1] = (void*)MSVCRT_exception_what;
328
329   bad_typeid_vtable[0] = MSVCRT_bad_typeid_dtor;
330   bad_typeid_vtable[1] = exception_vtable[1];
331   bad_typeid_vtable[2] = _purecall; /* FIXME */
332
333   __non_rtti_object_vtable[0] = MSVCRT___non_rtti_object_dtor;
334   __non_rtti_object_vtable[1] = bad_typeid_vtable[1];
335   __non_rtti_object_vtable[2] = bad_typeid_vtable[2];
336
337   bad_cast_vtable[0] = MSVCRT_bad_cast_dtor;
338   bad_cast_vtable[1] = exception_vtable[1];
339   bad_cast_vtable[2] = _purecall; /* FIXME */
340
341   type_info_vtable[0] = MSVCRT_type_info_dtor;
342
343 }
344