Bug 860222: use our own isascii() for sanitizing TURN passwords r=glandium
[gecko.git] / mfbt / Types.h
blob56e5cb82fb21edb1fc8c8a3a4066a4c503e22ad7
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* mfbt foundational types and macros. */
8 #ifndef mozilla_Types_h_
9 #define mozilla_Types_h_
12 * This header must be valid C and C++, includable by code embedding either
13 * SpiderMonkey or Gecko.
17 * Expose all the integer types defined in C99's <stdint.h> (and the integer
18 * limit and constant macros, if compiling C code or if compiling C++ code and
19 * the right __STDC_*_MACRO has been defined for each). These are all usable
20 * throughout mfbt code, and throughout Mozilla code more generally.
22 #include "mozilla/StandardInteger.h"
24 /* Also expose size_t. */
25 #include <stddef.h>
27 /* Implement compiler and linker macros needed for APIs. */
30 * MOZ_EXPORT is used to declare and define a symbol or type which is externally
31 * visible to users of the current library. It encapsulates various decorations
32 * needed to properly export the method's symbol.
34 * api.h:
35 * extern MOZ_EXPORT int MeaningOfLife(void);
36 * extern MOZ_EXPORT int LuggageCombination;
38 * api.c:
39 * int MeaningOfLife(void) { return 42; }
40 * int LuggageCombination = 12345;
42 * If you are merely sharing a method across files, just use plain |extern|.
43 * These macros are designed for use by library interfaces -- not for normal
44 * methods or data used cross-file.
46 #if defined(WIN32) || defined(XP_OS2)
47 # define MOZ_EXPORT __declspec(dllexport)
48 #else /* Unix */
49 # ifdef HAVE_VISIBILITY_ATTRIBUTE
50 # define MOZ_EXPORT __attribute__((visibility("default")))
51 # elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
52 # define MOZ_EXPORT __global
53 # else
54 # define MOZ_EXPORT /* nothing */
55 # endif
56 #endif
60 * Whereas implementers use MOZ_EXPORT to declare and define library symbols,
61 * users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to access them. Most often the
62 * implementer of the library will expose an API macro which expands to either
63 * the export or import version of the macro, depending upon the compilation
64 * mode.
66 #ifdef _WIN32
67 # if defined(__MWERKS__)
68 # define MOZ_IMPORT_API /* nothing */
69 # else
70 # define MOZ_IMPORT_API __declspec(dllimport)
71 # endif
72 #elif defined(XP_OS2)
73 # define MOZ_IMPORT_API __declspec(dllimport)
74 #else
75 # define MOZ_IMPORT_API MOZ_EXPORT
76 #endif
78 #if defined(_WIN32) && !defined(__MWERKS__)
79 # define MOZ_IMPORT_DATA __declspec(dllimport)
80 #elif defined(XP_OS2)
81 # define MOZ_IMPORT_DATA __declspec(dllimport)
82 #else
83 # define MOZ_IMPORT_DATA MOZ_EXPORT
84 #endif
87 * Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose
88 * export mfbt declarations when building mfbt, and they expose import mfbt
89 * declarations when using mfbt.
91 #if defined(IMPL_MFBT)
92 # define MFBT_API MOZ_EXPORT
93 # define MFBT_DATA MOZ_EXPORT
94 #else
96 * On linux mozglue is linked in the program and we link libxul.so with
97 * -z,defs. Normally that causes the linker to reject undefined references in
98 * libxul.so, but as a loophole it allows undefined references to weak
99 * symbols. We add the weak attribute to the import version of the MFBT API
100 * macros to exploit this.
102 # if defined(MOZ_GLUE_IN_PROGRAM)
103 # define MFBT_API __attribute__((weak)) MOZ_IMPORT_API
104 # define MFBT_DATA __attribute__((weak)) MOZ_IMPORT_DATA
105 # else
106 # define MFBT_API MOZ_IMPORT_API
107 # define MFBT_DATA MOZ_IMPORT_DATA
108 # endif
109 #endif
112 * C symbols in C++ code must be declared immediately within |extern "C"|
113 * blocks. However, in C code, they need not be declared specially. This
114 * difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C
115 * macros, so that the user need not know whether he is being used in C or C++
116 * code.
118 * MOZ_BEGIN_EXTERN_C
120 * extern MOZ_EXPORT int MostRandomNumber(void);
121 * ...other declarations...
123 * MOZ_END_EXTERN_C
125 * This said, it is preferable to just use |extern "C"| in C++ header files for
126 * its greater clarity.
128 #ifdef __cplusplus
129 # define MOZ_BEGIN_EXTERN_C extern "C" {
130 # define MOZ_END_EXTERN_C }
131 #else
132 # define MOZ_BEGIN_EXTERN_C
133 # define MOZ_END_EXTERN_C
134 #endif
136 #endif /* mozilla_Types_h_ */