Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: gecko-sdk/include/nscore.h

Issue 20346: Version 1.8 of gecko-sdk. Downloaded from here:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gecko-sdk/include/nsXPCOMGlue.h ('k') | gecko-sdk/include/nspr.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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) 1998
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 #ifndef nscore_h___
38 #define nscore_h___
39
40 /**
41 * Make sure that we have the proper platform specific
42 * c++ definitions needed by nscore.h
43 */
44 #ifndef _XPCOM_CONFIG_H_
45 #include "xpcom-config.h"
46 #endif
47
48 /**
49 * Incorporate the core NSPR data types which XPCOM uses.
50 */
51 #include "prtypes.h"
52
53 /* Core XPCOM declarations. */
54
55 /**
56 * Macros defining the target platform...
57 */
58 #ifdef _WIN32
59 #define NS_WIN32 1
60
61 #elif defined(__unix)
62 #define NS_UNIX 1
63
64 #elif defined(XP_OS2)
65 #define NS_OS2 1
66 #endif
67 /*----------------------------------------------------------------------*/
68 /* Import/export defines */
69
70 /**
71 * Using the visibility("hidden") attribute allows the compiler to use
72 * PC-relative addressing to call this function. If a function does not
73 * access any global data, and does not call any methods which are not either
74 * file-local or hidden, then on ELF systems we avoid loading the address of
75 * the PLT into a register at the start of the function, which reduces code
76 * size and frees up a register for general use.
77 *
78 * As a general rule, this should be used for any non-exported symbol
79 * (including virtual method implementations). NS_IMETHOD uses this by
80 * default; if you need to have your NS_IMETHOD functions exported, you can
81 * wrap your class as follows:
82 *
83 * #undef IMETHOD_VISIBILITY
84 * #define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
85 *
86 * class Foo {
87 * ...
88 * };
89 *
90 * #undef IMETHOD_VISIBILITY
91 * #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
92 *
93 * Don't forget to change the visibility back to hidden before the end
94 * of a header!
95 *
96 * Other examples:
97 *
98 * NS_HIDDEN_(int) someMethod();
99 * SomeCtor() NS_HIDDEN;
100 */
101
102 #ifdef HAVE_VISIBILITY_HIDDEN_ATTRIBUTE
103 #define NS_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden")))
104 #else
105 #define NS_VISIBILITY_HIDDEN
106 #endif
107
108 #if defined(HAVE_VISIBILITY_HIDDEN_ATTRIBUTE) && defined(HAVE_VISIBILITY_PRAGMA)
109 #define NS_VISIBILITY_DEFAULT __attribute__ ((visibility ("default")))
110 #else
111 #define NS_VISIBILITY_DEFAULT
112 #endif
113
114 #define NS_HIDDEN_(type) NS_VISIBILITY_HIDDEN type
115 #define NS_EXTERNAL_VIS_(type) NS_VISIBILITY_DEFAULT type
116
117 #define NS_HIDDEN NS_VISIBILITY_HIDDEN
118 #define NS_EXTERNAL_VIS NS_VISIBILITY_DEFAULT
119
120 #undef IMETHOD_VISIBILITY
121 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
122
123 /**
124 * Mark a function as using a potentially non-standard function calling
125 * convention. This can be used on functions that are called very
126 * frequently, to reduce the overhead of the function call. It is still worth
127 * using the macro for C++ functions which take no parameters since it allows
128 * passing |this| in a register.
129 *
130 * - Do not use this on any scriptable interface method since xptcall won't be
131 * aware of the different calling convention.
132 * - This must appear on the declaration, not the definition.
133 * - Adding this to a public function _will_ break binary compatibility.
134 * - This may be used on virtual functions but you must ensure it is applied
135 * to all implementations - the compiler will _not_ warn but it will crash.
136 * - This has no effect for inline functions or functions which take a
137 * variable number of arguments.
138 *
139 * Examples: int NS_FASTCALL func1(char *foo);
140 * NS_HIDDEN_(int) NS_FASTCALL func2(char *foo);
141 */
142
143 #if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 3) && !defined(XP_OS2 )
144 #define NS_FASTCALL __attribute__ ((regparm (3), stdcall))
145 #else
146 #define NS_FASTCALL
147 #endif
148
149 /*
150 * NS_DEFCALL undoes the effect of a global regparm/stdcall setting
151 * so that xptcall works correctly.
152 */
153 #if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 3) && !defined(XP_OS2 )
154 #define NS_DEFCALL __attribute__ ((regparm (0), cdecl))
155 #else
156 #define NS_DEFCALL
157 #endif
158
159 #ifdef NS_WIN32
160
161 #define NS_IMPORT __declspec(dllimport)
162 #define NS_IMPORT_(type) type __declspec(dllimport) __stdcall
163 #define NS_EXPORT __declspec(dllexport)
164 #define NS_EXPORT_(type) type __declspec(dllexport) __stdcall
165 #define NS_IMETHOD_(type) virtual type __stdcall
166 #define NS_IMETHODIMP_(type) type __stdcall
167 #define NS_METHOD_(type) type __stdcall
168 #define NS_CALLBACK_(_type, _name) _type (__stdcall * _name)
169 #define NS_STDCALL __stdcall
170
171 /*
172 These are needed to mark static members in exported classes, due to
173 gcc bug XXX insert bug# here.
174 */
175
176 #define NS_EXPORT_STATIC_MEMBER_(type) type
177 #define NS_IMPORT_STATIC_MEMBER_(type) type
178
179 #else
180
181 #define NS_IMPORT NS_EXTERNAL_VIS
182 #define NS_IMPORT_(type) NS_EXTERNAL_VIS_(type)
183 #define NS_EXPORT NS_EXTERNAL_VIS
184 #define NS_EXPORT_(type) NS_EXTERNAL_VIS_(type)
185 #define NS_IMETHOD_(type) virtual IMETHOD_VISIBILITY type NS_DEFCALL
186 #define NS_IMETHODIMP_(type) type
187 #define NS_METHOD_(type) type
188 #define NS_CALLBACK_(_type, _name) _type (* _name)
189 #define NS_STDCALL
190 #define NS_EXPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type)
191 #define NS_IMPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type)
192
193 #endif
194
195 /**
196 * Macro for creating typedefs for pointer-to-member types which are
197 * declared with stdcall. It is important to use this for any type which is
198 * declared as stdcall (i.e. NS_IMETHOD). For example, instead of writing:
199 *
200 * typedef nsresult (nsIFoo::*someType)(nsISupports* arg);
201 *
202 * you should write:
203 *
204 * typedef
205 * NS_STDCALL_FUNCPROTO(nsresult, someType, nsIFoo, typeFunc, (nsISupports*));
206 *
207 * where nsIFoo::typeFunc is any method declared as
208 * NS_IMETHOD typeFunc(nsISupports*);
209 *
210 * XXX this can be simplified to always use the non-typeof implementation
211 * when http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11893 is fixed.
212 */
213
214 #ifdef __GNUC__
215 #define NS_STDCALL_FUNCPROTO(ret, name, class, func, args) \
216 typeof(&class::func) name
217 #else
218 #define NS_STDCALL_FUNCPROTO(ret, name, class, func, args) \
219 ret (NS_STDCALL class::*name) args
220 #endif
221
222 /**
223 * Generic API modifiers which return the standard XPCOM nsresult type
224 */
225 #define NS_IMETHOD NS_IMETHOD_(nsresult)
226 #define NS_IMETHODIMP NS_IMETHODIMP_(nsresult)
227 #define NS_METHOD NS_METHOD_(nsresult)
228 #define NS_CALLBACK(_name) NS_CALLBACK_(nsresult, _name)
229
230 /**
231 * Import/Export macros for XPCOM APIs
232 */
233
234 #ifdef _IMPL_NS_COM
235 #define NS_COM NS_EXPORT
236 #elif _IMPL_NS_COM_OFF
237 #define NS_COM
238 #elif XPCOM_GLUE
239 #define NS_COM
240 #else
241 #define NS_COM NS_IMPORT
242 #endif
243
244 #ifdef MOZILLA_INTERNAL_API
245 # define NS_COM_GLUE NS_COM
246 /*
247 The frozen string API has different definitions of nsAC?String
248 classes than the internal API. On systems that explicitly declare
249 dllexport symbols this is not a problem, but on ELF systems
250 internal symbols can accidentally "shine through"; we rename the
251 internal classes to avoid symbol conflicts.
252 */
253 # define nsAString nsAString_internal
254 # define nsACString nsACString_internal
255 #else
256 # define NS_COM_GLUE
257 #endif
258
259
260 /**
261 * NS_NO_VTABLE is emitted by xpidl in interface declarations whenever
262 * xpidl can determine that the interface can't contain a constructor.
263 * This results in some space savings and possible runtime savings -
264 * see bug 49416. We undefine it first, as xpidl-generated headers
265 * define it for IDL uses that don't include this file.
266 */
267 #ifdef NS_NO_VTABLE
268 #undef NS_NO_VTABLE
269 #endif
270 #if defined(_MSC_VER) && _MSC_VER >= 1100
271 #define NS_NO_VTABLE __declspec(novtable)
272 #else
273 #define NS_NO_VTABLE
274 #endif
275
276
277 /**
278 * Generic XPCOM result data type
279 */
280 typedef PRUint32 nsresult;
281
282 /**
283 * The preferred symbol for null.
284 */
285 #define nsnull 0
286
287 #include "nsError.h"
288
289 /* ------------------------------------------------------------------------ */
290 /* Casting macros for hiding C++ features from older compilers */
291
292 /*
293 All our compiler support template specialization, but not all support the
294 |template <>| notation. The compiler that don't understand this notation
295 just omit it for specialization.
296
297 Need to add an autoconf test for this.
298 */
299
300 /* under Metrowerks (Mac), we don't have autoconf yet */
301 #ifdef __MWERKS__
302 #define HAVE_CPP_PARTIAL_SPECIALIZATION
303 #define HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
304
305 #define HAVE_CPP_ACCESS_CHANGING_USING
306 #define HAVE_CPP_AMBIGUITY_RESOLVING_USING
307 #define HAVE_CPP_EXPLICIT
308 #define HAVE_CPP_TYPENAME
309 #define HAVE_CPP_BOOL
310 #define HAVE_CPP_NAMESPACE_STD
311 #define HAVE_CPP_UNAMBIGUOUS_STD_NOTEQUAL
312 #define HAVE_CPP_2BYTE_WCHAR_T
313 #endif
314
315 /* under VC++ (Windows), we don't have autoconf yet */
316 #if defined(_MSC_VER) && (_MSC_VER>=1100)
317 /* VC++ 5.0 and greater implement template specialization, 4.2 is unknown */
318 #define HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
319
320 #define HAVE_CPP_EXPLICIT
321 #define HAVE_CPP_TYPENAME
322 #define HAVE_CPP_ACCESS_CHANGING_USING
323
324 #if (_MSC_VER==1100)
325 /* VC++5.0 has an internal compiler error (sometimes) without this */
326 #undef HAVE_CPP_ACCESS_CHANGING_USING
327 #endif
328
329 #define HAVE_CPP_NAMESPACE_STD
330 #define HAVE_CPP_UNAMBIGUOUS_STD_NOTEQUAL
331 #define HAVE_CPP_2BYTE_WCHAR_T
332 #endif
333
334 #ifndef __PRUNICHAR__
335 #define __PRUNICHAR__
336 /* For now, don't use wchar_t on Unix because it breaks the Netscape
337 * commercial build. When this is fixed there will be no need for the
338 * |NS_REINTERPRET_CAST| in nsLiteralString.h either.
339 */
340 #if defined(HAVE_CPP_2BYTE_WCHAR_T) && defined(NS_WIN32)
341 typedef wchar_t PRUnichar;
342 #else
343 typedef PRUint16 PRUnichar;
344 #endif
345 #endif
346
347 /*
348 If the compiler doesn't support |explicit|, we'll just make it go away, trus ting
349 that the builds under compilers that do have it will keep us on the straight and narrow.
350 */
351 #ifndef HAVE_CPP_EXPLICIT
352 #define explicit
353 #endif
354
355 #ifndef HAVE_CPP_TYPENAME
356 #define typename
357 #endif
358
359 #ifdef HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
360 #define NS_SPECIALIZE_TEMPLATE template <>
361 #else
362 #define NS_SPECIALIZE_TEMPLATE
363 #endif
364
365 /* unix and beos now determine this automatically */
366 #if ! defined XP_UNIX && ! defined XP_BEOS && !defined(XP_OS2)
367 #ifndef HAVE_CPP_NEW_CASTS
368 #define HAVE_CPP_NEW_CASTS 1 /* we'll be optimistic. */
369 #endif
370 #endif
371
372 #if defined(HAVE_CPP_NEW_CASTS)
373 #define NS_STATIC_CAST(__type, __ptr) static_cast< __type >(__ptr)
374 #define NS_CONST_CAST(__type, __ptr) const_cast< __type >(__ptr)
375
376 #define NS_REINTERPRET_POINTER_CAST(__type, __ptr) reinterpret_cast< __type > (__ptr)
377 #define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) reinterpret_cast< __type > (__obj)
378 #define NS_REINTERPRET_CAST(__type, __expr) reinterpret_cast< __type > (__expr)
379
380 #else
381 #define NS_STATIC_CAST(__type, __ptr) ((__type)(__ptr))
382 #define NS_CONST_CAST(__type, __ptr) ((__type)(__ptr))
383
384 #define NS_REINTERPRET_POINTER_CAST(__type, __ptr) ((__type)((void*)(__ptr)) )
385 #define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) ((__type)(__obj))
386
387 /* Note: the following is only appropriate for pointers. */
388 #define NS_REINTERPRET_CAST(__type, __expr) NS_REINTERPRET_POINTER_CA ST(__type, __expr)
389 /*
390 Why cast to a |void*| first? Well, when old-style casting from
391 a pointer to a base to a pointer to a derived class, the cast will be
392 ambiguous if the source pointer type appears multiple times in the
393 destination, e.g.,
394
395 class Base {};
396 class Derived : public Base, public Base {};
397
398 void foo( Base* b )
399 {
400 ((Derived*)b)->some_derived_member ... // Error: Ambiguous, expand fro m which |Base|?
401 }
402
403 an old-style cast (like |static_cast|) will change the pointer, but
404 here, doesn't know how. The cast to |void*| prevents it from thinking
405 it needs to expand the original pointer.
406
407 The cost is, |NS_REINTERPRET_CAST| is no longer appropriate for non-pointer
408 conversions. Also, mis-applying |NS_REINTERPRET_CAST| to cast |this| to som ething
409 will still expand the pointer to the outer object in standards complying com pilers.
410 */
411
412 /*
413 No sense in making an NS_DYNAMIC_CAST() macro: you can't duplicate
414 the semantics. So if you want to dynamic_cast, then just use it
415 "straight", no macro.
416 */
417 #endif
418
419 /*
420 * Use these macros to do 64bit safe pointer conversions.
421 */
422
423 #define NS_PTR_TO_INT32(x) ((PRInt32) (PRWord) (x))
424 #define NS_PTR_TO_UINT32(x) ((PRUint32) (PRWord) (x))
425 #define NS_INT32_TO_PTR(x) ((void *) (PRWord) (x))
426
427 /*
428 * Use NS_STRINGIFY to form a string literal from the value of a macro.
429 */
430 #define NS_STRINGIFY_HELPER(x_) #x_
431 #define NS_STRINGIFY(x_) NS_STRINGIFY_HELPER(x_)
432
433 /*
434 * These macros allow you to give a hint to the compiler about branch
435 * probability so that it can better optimize. Use them like this:
436 *
437 * if (NS_LIKELY(v == 1)) {
438 * ... expected code path ...
439 * }
440 *
441 * if (NS_UNLIKELY(v == 0)) {
442 * ... non-expected code path ...
443 * }
444 *
445 */
446
447 #if defined(__GNUC__) && (__GNUC__ > 2)
448 #define NS_LIKELY(x) (__builtin_expect((x), 1))
449 #define NS_UNLIKELY(x) (__builtin_expect((x), 0))
450 #else
451 #define NS_LIKELY(x) (x)
452 #define NS_UNLIKELY(x) (x)
453 #endif
454
455 #endif /* nscore_h___ */
OLDNEW
« no previous file with comments | « gecko-sdk/include/nsXPCOMGlue.h ('k') | gecko-sdk/include/nspr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698