michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* mfbt foundational types and macros. */ michael@0: michael@0: #ifndef mozilla_Types_h michael@0: #define mozilla_Types_h michael@0: michael@0: /* michael@0: * This header must be valid C and C++, includable by code embedding either michael@0: * SpiderMonkey or Gecko. michael@0: */ michael@0: michael@0: /* Expose all types and size_t. */ michael@0: #include michael@0: #include michael@0: michael@0: /* Implement compiler and linker macros needed for APIs. */ michael@0: michael@0: /* michael@0: * MOZ_EXPORT is used to declare and define a symbol or type which is externally michael@0: * visible to users of the current library. It encapsulates various decorations michael@0: * needed to properly export the method's symbol. michael@0: * michael@0: * api.h: michael@0: * extern MOZ_EXPORT int MeaningOfLife(void); michael@0: * extern MOZ_EXPORT int LuggageCombination; michael@0: * michael@0: * api.c: michael@0: * int MeaningOfLife(void) { return 42; } michael@0: * int LuggageCombination = 12345; michael@0: * michael@0: * If you are merely sharing a method across files, just use plain |extern|. michael@0: * These macros are designed for use by library interfaces -- not for normal michael@0: * methods or data used cross-file. michael@0: */ michael@0: #if defined(WIN32) michael@0: # define MOZ_EXPORT __declspec(dllexport) michael@0: #else /* Unix */ michael@0: # ifdef HAVE_VISIBILITY_ATTRIBUTE michael@0: # define MOZ_EXPORT __attribute__((visibility("default"))) michael@0: # elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) michael@0: # define MOZ_EXPORT __global michael@0: # else michael@0: # define MOZ_EXPORT /* nothing */ michael@0: # endif michael@0: #endif michael@0: michael@0: michael@0: /* michael@0: * Whereas implementers use MOZ_EXPORT to declare and define library symbols, michael@0: * users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to access them. Most often the michael@0: * implementer of the library will expose an API macro which expands to either michael@0: * the export or import version of the macro, depending upon the compilation michael@0: * mode. michael@0: */ michael@0: #ifdef _WIN32 michael@0: # if defined(__MWERKS__) michael@0: # define MOZ_IMPORT_API /* nothing */ michael@0: # else michael@0: # define MOZ_IMPORT_API __declspec(dllimport) michael@0: # endif michael@0: #else michael@0: # define MOZ_IMPORT_API MOZ_EXPORT michael@0: #endif michael@0: michael@0: #if defined(_WIN32) && !defined(__MWERKS__) michael@0: # define MOZ_IMPORT_DATA __declspec(dllimport) michael@0: #else michael@0: # define MOZ_IMPORT_DATA MOZ_EXPORT michael@0: #endif michael@0: michael@0: /* michael@0: * Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose michael@0: * export mfbt declarations when building mfbt, and they expose import mfbt michael@0: * declarations when using mfbt. michael@0: */ michael@0: #if defined(IMPL_MFBT) michael@0: # define MFBT_API MOZ_EXPORT michael@0: # define MFBT_DATA MOZ_EXPORT michael@0: #else michael@0: /* michael@0: * On linux mozglue is linked in the program and we link libxul.so with michael@0: * -z,defs. Normally that causes the linker to reject undefined references in michael@0: * libxul.so, but as a loophole it allows undefined references to weak michael@0: * symbols. We add the weak attribute to the import version of the MFBT API michael@0: * macros to exploit this. michael@0: */ michael@0: # if defined(MOZ_GLUE_IN_PROGRAM) michael@0: # define MFBT_API __attribute__((weak)) MOZ_IMPORT_API michael@0: # define MFBT_DATA __attribute__((weak)) MOZ_IMPORT_DATA michael@0: # else michael@0: # define MFBT_API MOZ_IMPORT_API michael@0: # define MFBT_DATA MOZ_IMPORT_DATA michael@0: # endif michael@0: #endif michael@0: michael@0: /* michael@0: * C symbols in C++ code must be declared immediately within |extern "C"| michael@0: * blocks. However, in C code, they need not be declared specially. This michael@0: * difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C michael@0: * macros, so that the user need not know whether he is being used in C or C++ michael@0: * code. michael@0: * michael@0: * MOZ_BEGIN_EXTERN_C michael@0: * michael@0: * extern MOZ_EXPORT int MostRandomNumber(void); michael@0: * ...other declarations... michael@0: * michael@0: * MOZ_END_EXTERN_C michael@0: * michael@0: * This said, it is preferable to just use |extern "C"| in C++ header files for michael@0: * its greater clarity. michael@0: */ michael@0: #ifdef __cplusplus michael@0: # define MOZ_BEGIN_EXTERN_C extern "C" { michael@0: # define MOZ_END_EXTERN_C } michael@0: #else michael@0: # define MOZ_BEGIN_EXTERN_C michael@0: # define MOZ_END_EXTERN_C michael@0: #endif michael@0: michael@0: /* michael@0: * GCC's typeof is available when decltype is not. michael@0: */ michael@0: #if defined(__GNUC__) && defined(__cplusplus) && \ michael@0: !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L michael@0: # define decltype __typeof__ michael@0: #endif michael@0: michael@0: #endif /* mozilla_Types_h */