2012-06-03 20:36:43 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 04:12:37 -07:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-04-28 15:48:52 -07:00
|
|
|
|
2011-12-13 11:26:58 -08:00
|
|
|
/* mfbt foundational types and macros. */
|
2011-04-28 15:48:52 -07:00
|
|
|
|
|
|
|
#ifndef mozilla_Types_h_
|
|
|
|
#define mozilla_Types_h_
|
|
|
|
|
2011-11-22 17:42:57 -08:00
|
|
|
/*
|
2011-12-13 11:26:58 -08:00
|
|
|
* This header must be valid C and C++, includable by code embedding either
|
|
|
|
* SpiderMonkey or Gecko.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Expose all the integer types defined in C99's <stdint.h> (and the integer
|
|
|
|
* limit and constant macros, if compiling C code or if compiling C++ code and
|
|
|
|
* the right __STDC_*_MACRO has been defined for each). These are all usable
|
|
|
|
* throughout mfbt code, and throughout Mozilla code more generally.
|
2011-11-22 17:42:57 -08:00
|
|
|
*/
|
2012-02-29 19:56:43 -08:00
|
|
|
#include "mozilla/StandardInteger.h"
|
2011-11-22 17:42:57 -08:00
|
|
|
|
2011-12-13 11:26:58 -08:00
|
|
|
/* Also expose size_t. */
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
/* Implement compiler and linker macros needed for APIs. */
|
|
|
|
|
|
|
|
/*
|
2012-10-31 15:18:12 -07:00
|
|
|
* MOZ_EXPORT is used to declare and define a symbol or type which is externally
|
2011-12-13 11:26:58 -08:00
|
|
|
* visible to users of the current library. It encapsulates various decorations
|
2012-10-31 15:18:12 -07:00
|
|
|
* needed to properly export the method's symbol.
|
2011-12-13 11:26:58 -08:00
|
|
|
*
|
|
|
|
* api.h:
|
2012-10-31 15:18:12 -07:00
|
|
|
* extern MOZ_EXPORT int MeaningOfLife(void);
|
|
|
|
* extern MOZ_EXPORT int LuggageCombination;
|
2011-04-28 15:48:52 -07:00
|
|
|
*
|
2011-12-13 11:26:58 -08:00
|
|
|
* api.c:
|
2012-10-31 15:18:12 -07:00
|
|
|
* int MeaningOfLife(void) { return 42; }
|
|
|
|
* int LuggageCombination = 12345;
|
2011-12-13 11:26:58 -08:00
|
|
|
*
|
|
|
|
* If you are merely sharing a method across files, just use plain |extern|.
|
|
|
|
* These macros are designed for use by library interfaces -- not for normal
|
|
|
|
* methods or data used cross-file.
|
2011-04-28 15:48:52 -07:00
|
|
|
*/
|
2011-12-13 11:26:58 -08:00
|
|
|
#if defined(WIN32) || defined(XP_OS2)
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MOZ_EXPORT __declspec(dllexport)
|
2011-12-13 11:26:58 -08:00
|
|
|
#else /* Unix */
|
|
|
|
# ifdef HAVE_VISIBILITY_ATTRIBUTE
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MOZ_EXPORT __attribute__((visibility("default")))
|
2011-12-13 11:26:58 -08:00
|
|
|
# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MOZ_EXPORT __global
|
2011-12-13 11:26:58 -08:00
|
|
|
# else
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MOZ_EXPORT /* nothing */
|
2011-12-13 11:26:58 -08:00
|
|
|
# endif
|
|
|
|
#endif
|
2011-04-28 15:48:52 -07:00
|
|
|
|
2012-10-30 13:12:22 -07:00
|
|
|
|
2011-12-13 11:26:58 -08:00
|
|
|
/*
|
2012-10-31 15:18:12 -07:00
|
|
|
* Whereas implementers use MOZ_EXPORT to declare and define library symbols,
|
|
|
|
* users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to access them. Most often the
|
|
|
|
* implementer of the library will expose an API macro which expands to either
|
|
|
|
* the export or import version of the macro, depending upon the compilation
|
|
|
|
* mode.
|
2011-12-13 11:26:58 -08:00
|
|
|
*/
|
|
|
|
#ifdef _WIN32
|
2012-03-02 02:27:29 -08:00
|
|
|
# if defined(__MWERKS__)
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MOZ_IMPORT_API /* nothing */
|
2011-12-13 11:26:58 -08:00
|
|
|
# else
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MOZ_IMPORT_API __declspec(dllimport)
|
2011-12-13 11:26:58 -08:00
|
|
|
# endif
|
|
|
|
#elif defined(XP_OS2)
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MOZ_IMPORT_API __declspec(dllimport)
|
2011-12-13 11:26:58 -08:00
|
|
|
#else
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MOZ_IMPORT_API MOZ_EXPORT
|
2011-12-13 11:26:58 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__MWERKS__)
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MOZ_IMPORT_DATA __declspec(dllimport)
|
2011-12-13 11:26:58 -08:00
|
|
|
#elif defined(XP_OS2)
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MOZ_IMPORT_DATA __declspec(dllimport)
|
2011-12-13 11:26:58 -08:00
|
|
|
#else
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MOZ_IMPORT_DATA MOZ_EXPORT
|
2011-12-13 11:26:58 -08:00
|
|
|
#endif
|
2011-04-28 15:48:52 -07:00
|
|
|
|
|
|
|
/*
|
2011-12-13 11:26:58 -08:00
|
|
|
* Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose
|
|
|
|
* export mfbt declarations when building mfbt, and they expose import mfbt
|
|
|
|
* declarations when using mfbt.
|
2011-04-28 15:48:52 -07:00
|
|
|
*/
|
|
|
|
#if defined(IMPL_MFBT)
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MFBT_API MOZ_EXPORT
|
|
|
|
# define MFBT_DATA MOZ_EXPORT
|
2011-04-28 15:48:52 -07:00
|
|
|
#else
|
2012-02-13 06:48:23 -08:00
|
|
|
/*
|
2012-10-24 11:33:45 -07:00
|
|
|
* On linux mozglue is linked in the program and we link libxul.so with
|
|
|
|
* -z,defs. Normally that causes the linker to reject undefined references in
|
|
|
|
* libxul.so, but as a loophole it allows undefined references to weak
|
|
|
|
* symbols. We add the weak attribute to the import version of the MFBT API
|
|
|
|
* macros to exploit this.
|
2012-02-13 06:48:23 -08:00
|
|
|
*/
|
|
|
|
# if defined(MOZ_GLUE_IN_PROGRAM)
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MFBT_API __attribute__((weak)) MOZ_IMPORT_API
|
|
|
|
# define MFBT_DATA __attribute__((weak)) MOZ_IMPORT_DATA
|
2012-02-13 06:48:23 -08:00
|
|
|
# else
|
2012-10-31 15:18:12 -07:00
|
|
|
# define MFBT_API MOZ_IMPORT_API
|
|
|
|
# define MFBT_DATA MOZ_IMPORT_DATA
|
2012-02-13 06:48:23 -08:00
|
|
|
# endif
|
2011-04-28 15:48:52 -07:00
|
|
|
#endif
|
|
|
|
|
2011-12-13 11:26:58 -08:00
|
|
|
/*
|
|
|
|
* C symbols in C++ code must be declared immediately within |extern "C"|
|
|
|
|
* blocks. However, in C code, they need not be declared specially. This
|
|
|
|
* difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C
|
|
|
|
* macros, so that the user need not know whether he is being used in C or C++
|
|
|
|
* code.
|
|
|
|
*
|
|
|
|
* MOZ_BEGIN_EXTERN_C
|
|
|
|
*
|
2012-10-31 15:18:12 -07:00
|
|
|
* extern MOZ_EXPORT int MostRandomNumber(void);
|
2011-12-13 11:26:58 -08:00
|
|
|
* ...other declarations...
|
|
|
|
*
|
|
|
|
* MOZ_END_EXTERN_C
|
|
|
|
*
|
|
|
|
* This said, it is preferable to just use |extern "C"| in C++ header files for
|
|
|
|
* its greater clarity.
|
|
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
|
|
|
# define MOZ_BEGIN_EXTERN_C extern "C" {
|
|
|
|
# define MOZ_END_EXTERN_C }
|
|
|
|
#else
|
|
|
|
# define MOZ_BEGIN_EXTERN_C
|
|
|
|
# define MOZ_END_EXTERN_C
|
|
|
|
#endif
|
2011-04-28 15:48:52 -07:00
|
|
|
|
2011-05-03 10:24:01 -07:00
|
|
|
#endif /* mozilla_Types_h_ */
|