VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/public/xptcall.h@ 86297

Last change on this file since 86297 was 86297, checked in by vboxsync, 4 years ago

xpcom/python/xptcall: shut up warning about memsetting objects.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 KB
Line 
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1999
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/* Public declarations for xptcall. */
39
40#ifndef xptcall_h___
41#define xptcall_h___
42
43#include "prtypes.h"
44#include "nscore.h"
45#include "nsISupports.h"
46#include "xpt_struct.h"
47#include "xptinfo.h"
48#include "nsIInterfaceInfo.h"
49
50#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
51#define XPTC_InvokeByIndex VBoxNsxpXPTC_InvokeByIndex
52#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
53
54/***************************************************************************/
55/*
56 * The linkage of XPTC API functions differs depending on whether the file is
57 * used within the XPTC library or not. Any source file within the XPTC
58 * library should define EXPORT_XPTC_API whereas any client of the library
59 * should not.
60 */
61#ifdef EXPORT_XPTC_API
62#define XPTC_PUBLIC_API(t) PR_IMPLEMENT(t)
63#define XPTC_PUBLIC_DATA(t) PR_IMPLEMENT_DATA(t)
64#if defined(_WIN32)
65# define XPTC_EXPORT __declspec(dllexport)
66#elif defined(XP_OS2) && defined(__declspec)
67# define XPTC_EXPORT __declspec(dllexport)
68#elif defined(XP_OS2_VACPP)
69# define XPTC_EXPORT extern
70#else
71# ifdef VBOX_HAVE_VISIBILITY_HIDDEN
72# define XPTC_EXPORT __attribute__((visibility("default")))
73# else
74# define XPTC_EXPORT
75# endif
76#endif
77#else
78#if defined(_WIN32)
79# define XPTC_PUBLIC_API(t) __declspec(dllimport) t
80# define XPTC_PUBLIC_DATA(t) __declspec(dllimport) t
81# define XPTC_EXPORT __declspec(dllimport)
82#elif defined(XP_OS2) && defined(__declspec)
83# define XPTC_PUBLIC_API(t) __declspec(dllimport) t
84# define XPTC_PUBLIC_DATA(t) __declspec(dllimport) t
85# define XPTC_EXPORT __declspec(dllimport)
86#elif defined(XP_OS2_VACPP)
87# define XPTC_PUBLIC_API(t) extern t
88# define XPTC_PUBLIC_DATA(t) extern t
89# define XPTC_EXPORT extern
90#else
91# define XPTC_PUBLIC_API(t) PR_IMPLEMENT(t)
92# define XPTC_PUBLIC_DATA(t) t
93# define XPTC_EXPORT
94#endif
95#endif
96#define XPTC_FRIEND_API(t) XPTC_PUBLIC_API(t)
97#define XPTC_FRIEND_DATA(t) XPTC_PUBLIC_DATA(t)
98/***************************************************************************/
99
100struct nsXPTCMiniVariant
101{
102// No ctors or dtors so that we can use arrays of these on the stack
103// with no penalty.
104 union
105 {
106 PRInt8 i8;
107 PRInt16 i16;
108 PRInt32 i32;
109 PRInt64 i64;
110 PRUint8 u8;
111 PRUint16 u16;
112 PRUint32 u32;
113 PRUint64 u64;
114 float f;
115 double d;
116 PRBool b;
117 char c;
118 PRUnichar wc;
119 void* p;
120 } val;
121};
122
123struct nsXPTCVariant : public nsXPTCMiniVariant
124{
125// No ctors or dtors so that we can use arrays of these on the stack
126// with no penalty.
127
128 // inherits 'val' here
129 void* ptr;
130 nsXPTType type;
131 PRUint8 flags;
132
133 enum
134 {
135 // these are bitflags!
136 PTR_IS_DATA = 0x1, // ptr points to 'real' data in val
137 VAL_IS_ALLOCD = 0x2, // val.p holds alloc'd ptr that must be freed
138 VAL_IS_IFACE = 0x4, // val.p holds interface ptr that must be released
139 VAL_IS_ARRAY = 0x8, // val.p holds a pointer to an array needing cleanup
140 VAL_IS_DOMSTR = 0x10, // val.p holds a pointer to domstring needing cleanup
141 VAL_IS_UTF8STR = 0x20, // val.p holds a pointer to utf8string needing cleanup
142 VAL_IS_CSTR = 0x40 // val.p holds a pointer to cstring needing cleanup
143 };
144
145 /* VBox: Added to prevent -Wclass-memaccess warnings (nsXPTType has a constructor) in python/src/VariantUtils.cpp */
146 nsXPTCVariant() : ptr(NULL), flags(0)
147 {
148 val.p = NULL;
149 type.flags = 0; /* stupid nsXPTType constructor only do random bytes (documented) */
150 }
151
152 void ClearFlags() {flags = 0;}
153 void SetPtrIsData() {flags |= PTR_IS_DATA;}
154 void SetValIsAllocated() {flags |= VAL_IS_ALLOCD;}
155 void SetValIsInterface() {flags |= VAL_IS_IFACE;}
156 void SetValIsArray() {flags |= VAL_IS_ARRAY;}
157 void SetValIsDOMString() {flags |= VAL_IS_DOMSTR;}
158 void SetValIsUTF8String() {flags |= VAL_IS_UTF8STR;}
159 void SetValIsCString() {flags |= VAL_IS_CSTR;}
160
161 PRBool IsPtrData() const {return 0 != (flags & PTR_IS_DATA);}
162 PRBool IsValAllocated() const {return 0 != (flags & VAL_IS_ALLOCD);}
163 PRBool IsValInterface() const {return 0 != (flags & VAL_IS_IFACE);}
164 PRBool IsValArray() const {return 0 != (flags & VAL_IS_ARRAY);}
165 PRBool IsValDOMString() const {return 0 != (flags & VAL_IS_DOMSTR);}
166 PRBool IsValUTF8String() const {return 0 != (flags & VAL_IS_UTF8STR);}
167 PRBool IsValCString() const {return 0 != (flags & VAL_IS_CSTR);}
168#ifdef VBOX
169 PRBool MustFreeVal() const {return 0 != (flags & ( VAL_IS_ALLOCD
170 | VAL_IS_IFACE
171 | VAL_IS_DOMSTR
172 | VAL_IS_UTF8STR
173 | VAL_IS_CSTR)); }
174#endif
175
176 void Init(const nsXPTCMiniVariant& mv, const nsXPTType& t, PRUint8 f)
177 {
178 type = t;
179 flags = f;
180
181 if(f & PTR_IS_DATA)
182 {
183 ptr = mv.val.p;
184 val.p = nsnull;
185 }
186 else
187 {
188 ptr = nsnull;
189 switch(t.TagPart()) {
190 case nsXPTType::T_I8: val.i8 = mv.val.i8; break;
191 case nsXPTType::T_I16: val.i16 = mv.val.i16; break;
192 case nsXPTType::T_I32: val.i32 = mv.val.i32; break;
193 case nsXPTType::T_I64: val.i64 = mv.val.i64; break;
194 case nsXPTType::T_U8: val.u8 = mv.val.u8; break;
195 case nsXPTType::T_U16: val.u16 = mv.val.u16; break;
196 case nsXPTType::T_U32: val.u32 = mv.val.u32; break;
197 case nsXPTType::T_U64: val.u64 = mv.val.u64; break;
198 case nsXPTType::T_FLOAT: val.f = mv.val.f; break;
199 case nsXPTType::T_DOUBLE: val.d = mv.val.d; break;
200 case nsXPTType::T_BOOL: val.b = mv.val.b; break;
201 case nsXPTType::T_CHAR: val.c = mv.val.c; break;
202 case nsXPTType::T_WCHAR: val.wc = mv.val.wc; break;
203 case nsXPTType::T_VOID: /* fall through */
204 case nsXPTType::T_IID: /* fall through */
205 case nsXPTType::T_DOMSTRING: /* fall through */
206 case nsXPTType::T_CHAR_STR: /* fall through */
207 case nsXPTType::T_WCHAR_STR: /* fall through */
208 case nsXPTType::T_INTERFACE: /* fall through */
209 case nsXPTType::T_INTERFACE_IS: /* fall through */
210 case nsXPTType::T_ARRAY: /* fall through */
211 case nsXPTType::T_PSTRING_SIZE_IS: /* fall through */
212 case nsXPTType::T_PWSTRING_SIZE_IS: /* fall through */
213 case nsXPTType::T_UTF8STRING: /* fall through */
214 case nsXPTType::T_CSTRING: /* fall through */
215 default: val.p = mv.val.p; break;
216 }
217 }
218 }
219};
220
221/***************************************************************************/
222
223#undef IMETHOD_VISIBILITY
224#define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
225
226class XPTC_EXPORT nsXPTCStubBase : public nsISupports
227{
228public:
229 // We are going to implement this to force the compiler to generate a
230 // vtbl for this class. Since this is overridden in the inheriting class
231 // we expect it to never be called.
232 // *This is needed by the Irix implementation.*
233 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
234
235 // Implement dummy constructor, destructor to workaround Solaris gcc 4.8.2
236 // linking issue (see @bugref{5838}).
237 nsXPTCStubBase() {}
238 ~nsXPTCStubBase() {}
239
240 // Include generated vtbl stub declarations.
241 // These are virtual and *also* implemented by this class..
242#include "xptcstubsdecl.inc"
243
244 // The following methods must be provided by inheritor of this class.
245
246 // return a refcounted pointer to the InterfaceInfo for this object
247 // NOTE: on some platforms this MUST not fail or we crash!
248 NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
249
250 // call this method and return result
251 NS_IMETHOD CallMethod(PRUint16 methodIndex,
252 const nsXPTMethodInfo* info,
253 nsXPTCMiniVariant* params) = 0;
254};
255
256#undef IMETHOD_VISIBILITY
257#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
258
259PR_BEGIN_EXTERN_C
260
261XPTC_PUBLIC_API(nsresult)
262XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
263 PRUint32 paramCount, nsXPTCVariant* params);
264
265// Used to force linking of these obj for the static library into the dll
266extern void xptc_dummy();
267extern void xptc_dummy2();
268
269PR_END_EXTERN_C
270
271#endif /* xptcall_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette