Bumping manifests a=b2g-bump
[gecko.git] / mfbt / Types.h
blobe7e18abb27467feeca016dcd7f9cdcf64c903f9b
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* mfbt foundational types and macros. */
9 #ifndef mozilla_Types_h
10 #define mozilla_Types_h
13 * This header must be valid C and C++, includable by code embedding either
14 * SpiderMonkey or Gecko.
17 /* Expose all <stdint.h> types and size_t. */
18 #include <stddef.h>
19 #include <stdint.h>
21 /* Implement compiler and linker macros needed for APIs. */
24 * MOZ_EXPORT is used to declare and define a symbol or type which is externally
25 * visible to users of the current library. It encapsulates various decorations
26 * needed to properly export the method's symbol.
28 * api.h:
29 * extern MOZ_EXPORT int MeaningOfLife(void);
30 * extern MOZ_EXPORT int LuggageCombination;
32 * api.c:
33 * int MeaningOfLife(void) { return 42; }
34 * int LuggageCombination = 12345;
36 * If you are merely sharing a method across files, just use plain |extern|.
37 * These macros are designed for use by library interfaces -- not for normal
38 * methods or data used cross-file.
40 #if defined(WIN32)
41 # define MOZ_EXPORT __declspec(dllexport)
42 #else /* Unix */
43 # ifdef HAVE_VISIBILITY_ATTRIBUTE
44 # define MOZ_EXPORT __attribute__((visibility("default")))
45 # elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
46 # define MOZ_EXPORT __global
47 # else
48 # define MOZ_EXPORT /* nothing */
49 # endif
50 #endif
54 * Whereas implementers use MOZ_EXPORT to declare and define library symbols,
55 * users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to access them. Most often the
56 * implementer of the library will expose an API macro which expands to either
57 * the export or import version of the macro, depending upon the compilation
58 * mode.
60 #ifdef _WIN32
61 # if defined(__MWERKS__)
62 # define MOZ_IMPORT_API /* nothing */
63 # else
64 # define MOZ_IMPORT_API __declspec(dllimport)
65 # endif
66 #else
67 # define MOZ_IMPORT_API MOZ_EXPORT
68 #endif
70 #if defined(_WIN32) && !defined(__MWERKS__)
71 # define MOZ_IMPORT_DATA __declspec(dllimport)
72 #else
73 # define MOZ_IMPORT_DATA MOZ_EXPORT
74 #endif
77 * Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose
78 * export mfbt declarations when building mfbt, and they expose import mfbt
79 * declarations when using mfbt.
81 #if defined(IMPL_MFBT)
82 # define MFBT_API MOZ_EXPORT
83 # define MFBT_DATA MOZ_EXPORT
84 #else
86 * On linux mozglue is linked in the program and we link libxul.so with
87 * -z,defs. Normally that causes the linker to reject undefined references in
88 * libxul.so, but as a loophole it allows undefined references to weak
89 * symbols. We add the weak attribute to the import version of the MFBT API
90 * macros to exploit this.
92 # if defined(MOZ_GLUE_IN_PROGRAM)
93 # define MFBT_API __attribute__((weak)) MOZ_IMPORT_API
94 # define MFBT_DATA __attribute__((weak)) MOZ_IMPORT_DATA
95 # else
96 # define MFBT_API MOZ_IMPORT_API
97 # define MFBT_DATA MOZ_IMPORT_DATA
98 # endif
99 #endif
102 * C symbols in C++ code must be declared immediately within |extern "C"|
103 * blocks. However, in C code, they need not be declared specially. This
104 * difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C
105 * macros, so that the user need not know whether he is being used in C or C++
106 * code.
108 * MOZ_BEGIN_EXTERN_C
110 * extern MOZ_EXPORT int MostRandomNumber(void);
111 * ...other declarations...
113 * MOZ_END_EXTERN_C
115 * This said, it is preferable to just use |extern "C"| in C++ header files for
116 * its greater clarity.
118 #ifdef __cplusplus
119 # define MOZ_BEGIN_EXTERN_C extern "C" {
120 # define MOZ_END_EXTERN_C }
121 #else
122 # define MOZ_BEGIN_EXTERN_C
123 # define MOZ_END_EXTERN_C
124 #endif
127 * GCC's typeof is available when decltype is not.
129 #if defined(__GNUC__) && defined(__cplusplus) && \
130 !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L
131 # define decltype __typeof__
132 #endif
134 #endif /* mozilla_Types_h */