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_ATTRIBUTE
|
---|
103 | #define NS_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden")))
|
---|
104 | # ifdef VBOX_HAVE_VISIBILITY_HIDDEN
|
---|
105 | # define NS_VISIBILITY_DEFAULT __attribute__ ((visibility ("default")))
|
---|
106 | # else
|
---|
107 | # define NS_VISIBILITY_DEFAULT
|
---|
108 | # endif
|
---|
109 |
|
---|
110 | #define NS_HIDDEN_(type) NS_VISIBILITY_HIDDEN type
|
---|
111 | #else
|
---|
112 | #define NS_VISIBILITY_HIDDEN
|
---|
113 | #define NS_VISIBILITY_DEFAULT
|
---|
114 |
|
---|
115 | #define NS_HIDDEN_(type) type
|
---|
116 | #endif
|
---|
117 |
|
---|
118 | #define NS_HIDDEN NS_VISIBILITY_HIDDEN
|
---|
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 | /* XXX: nike, maybe fix */
|
---|
150 | #define NS_EXPORT_STATIC_MEMBER_(type) type
|
---|
151 | #define NS_IMPORT_STATIC_MEMBER_(type) type
|
---|
152 |
|
---|
153 | #ifdef NS_WIN32
|
---|
154 |
|
---|
155 | #define NS_IMPORT __declspec(dllimport)
|
---|
156 | #define NS_IMPORT_(type) type __declspec(dllimport) __stdcall
|
---|
157 | #define NS_EXPORT __declspec(dllexport)
|
---|
158 | #define NS_EXPORT_(type) type __declspec(dllexport) __stdcall
|
---|
159 | #define NS_IMETHOD_(type) virtual type __stdcall
|
---|
160 | #define NS_IMETHODIMP_(type) type __stdcall
|
---|
161 | #define NS_METHOD_(type) type __stdcall
|
---|
162 | #define NS_CALLBACK_(_type, _name) _type (__stdcall * _name)
|
---|
163 | #define NS_STDCALL __stdcall
|
---|
164 |
|
---|
165 | #elif defined(XP_MAC)
|
---|
166 |
|
---|
167 | #define NS_IMPORT
|
---|
168 | #define NS_IMPORT_(type) type
|
---|
169 | #define NS_EXPORT __declspec(export)
|
---|
170 | #define NS_EXPORT_(type) __declspec(export) type
|
---|
171 | #define NS_IMETHOD_(type) virtual type
|
---|
172 | #define NS_IMETHODIMP_(type) type
|
---|
173 | #define NS_METHOD_(type) type
|
---|
174 | #define NS_CALLBACK_(_type, _name) _type (* _name)
|
---|
175 | #define NS_STDCALL
|
---|
176 |
|
---|
177 | #elif defined(XP_OS2) && defined(__declspec)
|
---|
178 |
|
---|
179 | #define NS_IMPORT __declspec(dllimport)
|
---|
180 | #define NS_IMPORT_(type) type __declspec(dllimport) __stdcall
|
---|
181 | #define NS_EXPORT __declspec(dllexport)
|
---|
182 | #define NS_EXPORT_(type) type __declspec(dllexport) __stdcall
|
---|
183 | #define NS_IMETHOD_(type) virtual IMETHOD_VISIBILITY type
|
---|
184 | #define NS_IMETHODIMP_(type) type
|
---|
185 | #define NS_METHOD_(type) type
|
---|
186 | #define NS_CALLBACK_(_type, _name) _type (* _name)
|
---|
187 | #define NS_STDCALL
|
---|
188 |
|
---|
189 | #else
|
---|
190 |
|
---|
191 | # ifdef VBOX_HAVE_VISIBILITY_HIDDEN
|
---|
192 | # define NS_IMPORT
|
---|
193 | # define NS_IMPORT_(type) type
|
---|
194 | # define NS_EXPORT __attribute__((visibility("default")))
|
---|
195 | # define NS_EXPORT_(type) __attribute__((visibility("default"))) type
|
---|
196 | # define NS_IMETHOD_(type) virtual IMETHOD_VISIBILITY type
|
---|
197 | # define NS_IMETHODIMP_(type) type
|
---|
198 | # define NS_METHOD_(type) type
|
---|
199 | # define NS_CALLBACK_(_type, _name) _type (* _name)
|
---|
200 | # define NS_STDCALL
|
---|
201 | # else
|
---|
202 | # define NS_IMPORT
|
---|
203 | # define NS_IMPORT_(type) type
|
---|
204 | # define NS_EXPORT
|
---|
205 | # define NS_EXPORT_(type) type
|
---|
206 | # define NS_IMETHOD_(type) virtual IMETHOD_VISIBILITY type
|
---|
207 | # define NS_IMETHODIMP_(type) type
|
---|
208 | # define NS_METHOD_(type) type
|
---|
209 | # define NS_CALLBACK_(_type, _name) _type (* _name)
|
---|
210 | # define NS_STDCALL
|
---|
211 | # endif
|
---|
212 | #endif
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Macro for creating typedefs for pointer-to-member types which are
|
---|
216 | * declared with stdcall. It is important to use this for any type which is
|
---|
217 | * declared as stdcall (i.e. NS_IMETHOD). For example, instead of writing:
|
---|
218 | *
|
---|
219 | * typedef nsresult (nsIFoo::*someType)(nsISupports* arg);
|
---|
220 | *
|
---|
221 | * you should write:
|
---|
222 | *
|
---|
223 | * typedef
|
---|
224 | * NS_STDCALL_FUNCPROTO(nsresult, someType, nsIFoo, typeFunc, (nsISupports*));
|
---|
225 | *
|
---|
226 | * where nsIFoo::typeFunc is any method declared as
|
---|
227 | * NS_IMETHOD typeFunc(nsISupports*);
|
---|
228 | *
|
---|
229 | * XXX this can be simplified to always use the non-typeof implementation
|
---|
230 | * when http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11893 is fixed.
|
---|
231 | */
|
---|
232 |
|
---|
233 | #ifdef __GNUC__
|
---|
234 | #define NS_STDCALL_FUNCPROTO(ret, name, class, func, args) \
|
---|
235 | typeof(&class::func) name
|
---|
236 | #else
|
---|
237 | #define NS_STDCALL_FUNCPROTO(ret, name, class, func, args) \
|
---|
238 | ret (NS_STDCALL class::*name) args
|
---|
239 | #endif
|
---|
240 |
|
---|
241 | /**
|
---|
242 | * Generic API modifiers which return the standard XPCOM nsresult type
|
---|
243 | */
|
---|
244 | #define NS_IMETHOD NS_IMETHOD_(nsresult)
|
---|
245 | #define NS_IMETHODIMP NS_IMETHODIMP_(nsresult)
|
---|
246 | #define NS_METHOD NS_METHOD_(nsresult)
|
---|
247 | #define NS_CALLBACK(_name) NS_CALLBACK_(nsresult, _name)
|
---|
248 |
|
---|
249 | /**
|
---|
250 | * Import/Export macros for XPCOM APIs
|
---|
251 | */
|
---|
252 |
|
---|
253 | #ifdef _IMPL_NS_COM
|
---|
254 | #define NS_COM NS_EXPORT
|
---|
255 | #elif _IMPL_NS_COM_OFF
|
---|
256 | #define NS_COM
|
---|
257 | #elif XPCOM_GLUE
|
---|
258 | #define NS_COM
|
---|
259 | #else
|
---|
260 | #define NS_COM NS_IMPORT
|
---|
261 | #endif
|
---|
262 |
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * NS_NO_VTABLE is emitted by xpidl in interface declarations whenever
|
---|
266 | * xpidl can determine that the interface can't contain a constructor.
|
---|
267 | * This results in some space savings and possible runtime savings -
|
---|
268 | * see bug 49416. We undefine it first, as xpidl-generated headers
|
---|
269 | * define it for IDL uses that don't include this file.
|
---|
270 | */
|
---|
271 | #ifdef NS_NO_VTABLE
|
---|
272 | #undef NS_NO_VTABLE
|
---|
273 | #endif
|
---|
274 | #if defined(_MSC_VER) && _MSC_VER >= 1100
|
---|
275 | #define NS_NO_VTABLE __declspec(novtable)
|
---|
276 | #else
|
---|
277 | #define NS_NO_VTABLE
|
---|
278 | #endif
|
---|
279 |
|
---|
280 |
|
---|
281 | /**
|
---|
282 | * Generic XPCOM result data type
|
---|
283 | */
|
---|
284 | typedef PRUint32 nsresult;
|
---|
285 |
|
---|
286 | /**
|
---|
287 | * The preferred symbol for null.
|
---|
288 | */
|
---|
289 | #define nsnull 0
|
---|
290 |
|
---|
291 | #include "nsError.h"
|
---|
292 |
|
---|
293 | /* ------------------------------------------------------------------------ */
|
---|
294 | /* Casting macros for hiding C++ features from older compilers */
|
---|
295 |
|
---|
296 | /*
|
---|
297 | All our compiler support template specialization, but not all support the
|
---|
298 | |template <>| notation. The compiler that don't understand this notation
|
---|
299 | just omit it for specialization.
|
---|
300 |
|
---|
301 | Need to add an autoconf test for this.
|
---|
302 | */
|
---|
303 |
|
---|
304 | /* under Metrowerks (Mac), we don't have autoconf yet */
|
---|
305 | #ifdef __MWERKS__
|
---|
306 | #define HAVE_CPP_PARTIAL_SPECIALIZATION
|
---|
307 | #define HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
|
---|
308 |
|
---|
309 | #define HAVE_CPP_ACCESS_CHANGING_USING
|
---|
310 | #define HAVE_CPP_AMBIGUITY_RESOLVING_USING
|
---|
311 | #define HAVE_CPP_EXPLICIT
|
---|
312 | #define HAVE_CPP_TYPENAME
|
---|
313 | #define HAVE_CPP_BOOL
|
---|
314 | #define HAVE_CPP_NAMESPACE_STD
|
---|
315 | #define HAVE_CPP_UNAMBIGUOUS_STD_NOTEQUAL
|
---|
316 | #define HAVE_CPP_2BYTE_WCHAR_T
|
---|
317 | #endif
|
---|
318 |
|
---|
319 | /* under VC++ (Windows), we don't have autoconf yet */
|
---|
320 | #if defined(_MSC_VER) && (_MSC_VER>=1100)
|
---|
321 | /* VC++ 5.0 and greater implement template specialization, 4.2 is unknown */
|
---|
322 | #define HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
|
---|
323 |
|
---|
324 | #define HAVE_CPP_EXPLICIT
|
---|
325 | #define HAVE_CPP_TYPENAME
|
---|
326 | #define HAVE_CPP_ACCESS_CHANGING_USING
|
---|
327 |
|
---|
328 | #if (_MSC_VER==1100)
|
---|
329 | /* VC++5.0 has an internal compiler error (sometimes) without this */
|
---|
330 | #undef HAVE_CPP_ACCESS_CHANGING_USING
|
---|
331 | #endif
|
---|
332 |
|
---|
333 | #define HAVE_CPP_NAMESPACE_STD
|
---|
334 | #define HAVE_CPP_UNAMBIGUOUS_STD_NOTEQUAL
|
---|
335 | #define HAVE_CPP_2BYTE_WCHAR_T
|
---|
336 | #endif
|
---|
337 |
|
---|
338 | #ifndef __PRUNICHAR__
|
---|
339 | #define __PRUNICHAR__
|
---|
340 | /* For now, don't use wchar_t on Unix because it breaks the Netscape
|
---|
341 | * commercial build. When this is fixed there will be no need for the
|
---|
342 | * |NS_REINTERPRET_CAST| in nsLiteralString.h either.
|
---|
343 | */
|
---|
344 | #if defined(HAVE_CPP_2BYTE_WCHAR_T) && (defined(NS_WIN32) || defined(XP_MAC))
|
---|
345 | typedef wchar_t PRUnichar;
|
---|
346 | #else
|
---|
347 | typedef PRUint16 PRUnichar;
|
---|
348 | #endif
|
---|
349 | #endif
|
---|
350 |
|
---|
351 | /*
|
---|
352 | If the compiler doesn't support |explicit|, we'll just make it go away, trusting
|
---|
353 | that the builds under compilers that do have it will keep us on the straight and narrow.
|
---|
354 | */
|
---|
355 | #ifndef HAVE_CPP_EXPLICIT
|
---|
356 | #define explicit
|
---|
357 | #endif
|
---|
358 |
|
---|
359 | #ifndef HAVE_CPP_TYPENAME
|
---|
360 | #define typename
|
---|
361 | #endif
|
---|
362 |
|
---|
363 | #ifdef HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
|
---|
364 | #define NS_SPECIALIZE_TEMPLATE template <>
|
---|
365 | #else
|
---|
366 | #define NS_SPECIALIZE_TEMPLATE
|
---|
367 | #endif
|
---|
368 |
|
---|
369 | /* unix and beos now determine this automatically */
|
---|
370 | #if ! defined XP_UNIX && ! defined XP_BEOS && !defined(XP_OS2)
|
---|
371 | #ifndef HAVE_CPP_NEW_CASTS
|
---|
372 | #define HAVE_CPP_NEW_CASTS 1 /* we'll be optimistic. */
|
---|
373 | #endif
|
---|
374 | #endif
|
---|
375 |
|
---|
376 | #if defined(HAVE_CPP_NEW_CASTS)
|
---|
377 | #define NS_STATIC_CAST(__type, __ptr) static_cast< __type >(__ptr)
|
---|
378 | #define NS_CONST_CAST(__type, __ptr) const_cast< __type >(__ptr)
|
---|
379 |
|
---|
380 | #define NS_REINTERPRET_POINTER_CAST(__type, __ptr) reinterpret_cast< __type >(__ptr)
|
---|
381 | #define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) reinterpret_cast< __type >(__obj)
|
---|
382 | #define NS_REINTERPRET_CAST(__type, __expr) reinterpret_cast< __type >(__expr)
|
---|
383 |
|
---|
384 | #else
|
---|
385 | #define NS_STATIC_CAST(__type, __ptr) ((__type)(__ptr))
|
---|
386 | #define NS_CONST_CAST(__type, __ptr) ((__type)(__ptr))
|
---|
387 |
|
---|
388 | #define NS_REINTERPRET_POINTER_CAST(__type, __ptr) ((__type)((void*)(__ptr)))
|
---|
389 | #define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) ((__type)(__obj))
|
---|
390 |
|
---|
391 | /* Note: the following is only appropriate for pointers. */
|
---|
392 | #define NS_REINTERPRET_CAST(__type, __expr) NS_REINTERPRET_POINTER_CAST(__type, __expr)
|
---|
393 | /*
|
---|
394 | Why cast to a |void*| first? Well, when old-style casting from
|
---|
395 | a pointer to a base to a pointer to a derived class, the cast will be
|
---|
396 | ambiguous if the source pointer type appears multiple times in the
|
---|
397 | destination, e.g.,
|
---|
398 |
|
---|
399 | class Base {};
|
---|
400 | class Derived : public Base, public Base {};
|
---|
401 |
|
---|
402 | void foo( Base* b )
|
---|
403 | {
|
---|
404 | ((Derived*)b)->some_derived_member ... // Error: Ambiguous, expand from which |Base|?
|
---|
405 | }
|
---|
406 |
|
---|
407 | an old-style cast (like |static_cast|) will change the pointer, but
|
---|
408 | here, doesn't know how. The cast to |void*| prevents it from thinking
|
---|
409 | it needs to expand the original pointer.
|
---|
410 |
|
---|
411 | The cost is, |NS_REINTERPRET_CAST| is no longer appropriate for non-pointer
|
---|
412 | conversions. Also, mis-applying |NS_REINTERPRET_CAST| to cast |this| to something
|
---|
413 | will still expand the pointer to the outer object in standards complying compilers.
|
---|
414 | */
|
---|
415 |
|
---|
416 | /*
|
---|
417 | No sense in making an NS_DYNAMIC_CAST() macro: you can't duplicate
|
---|
418 | the semantics. So if you want to dynamic_cast, then just use it
|
---|
419 | "straight", no macro.
|
---|
420 | */
|
---|
421 | #endif
|
---|
422 |
|
---|
423 | #if __cplusplus+0 > 201100L
|
---|
424 | #define NS_DEFAULT = default
|
---|
425 | #define NS_DELETE = delete
|
---|
426 | #define NS_OVERRIDE override
|
---|
427 | #else
|
---|
428 | #define NS_DEFAULT
|
---|
429 | #define NS_DELETE
|
---|
430 | #define NS_OVERRIDE
|
---|
431 | #endif
|
---|
432 |
|
---|
433 |
|
---|
434 | #ifndef VBOX
|
---|
435 | /*
|
---|
436 | * Use these macros to do 64bit safe pointer conversions.
|
---|
437 | */
|
---|
438 |
|
---|
439 | #define NS_PTR_TO_INT32(x) ((char *)(x) - (char *)0)
|
---|
440 | #define NS_INT32_TO_PTR(x) ((void *)((char *)0 + (x)))
|
---|
441 | #else /* VBOX */
|
---|
442 | // This stuff is (contrary to the comment) totally 64bit unsafe, so strip
|
---|
443 | // it down to only do one direction, which is used by the hashing code.
|
---|
444 | #define NS_PTR_TO_INT32(x) ((PRInt32)((char *)(x) - (char *)0))
|
---|
445 | #endif /* VBOX */
|
---|
446 |
|
---|
447 | /*
|
---|
448 | * These macros allow you to give a hint to the compiler about branch
|
---|
449 | * probability so that it can better optimize. Use them like this:
|
---|
450 | *
|
---|
451 | * if (NS_LIKELY(v == 1)) {
|
---|
452 | * ... expected code path ...
|
---|
453 | * }
|
---|
454 | *
|
---|
455 | * if (NS_UNLIKELY(v == 0)) {
|
---|
456 | * ... non-expected code path ...
|
---|
457 | * }
|
---|
458 | *
|
---|
459 | */
|
---|
460 |
|
---|
461 | #if defined(__GNUC__) && (__GNUC__ > 2) && !defined(FORTIFY_RUNNING)
|
---|
462 | #define NS_LIKELY(x) (__builtin_expect(!!(x), 1))
|
---|
463 | #define NS_UNLIKELY(x) (__builtin_expect(!!(x), 0))
|
---|
464 | #else
|
---|
465 | #define NS_LIKELY(x) (x)
|
---|
466 | #define NS_UNLIKELY(x) (x)
|
---|
467 | #endif
|
---|
468 |
|
---|
469 | #endif /* nscore_h___ */
|
---|
470 |
|
---|