Back to index

enigmail  1.4.3
Types.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * vim: set ts=8 sw=4 et tw=99 ft=cpp:
00003  *
00004  * ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at:
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is Mozilla Code.
00018  *
00019  * The Initial Developer of the Original Code is
00020  *   The Mozilla Foundation
00021  * Portions created by the Initial Developer are Copyright (C) 2011
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 /* mfbt foundational types and macros. */
00041 
00042 #ifndef mozilla_Types_h_
00043 #define mozilla_Types_h_
00044 
00045 /*
00046  * This header must be valid C and C++, includable by code embedding either
00047  * SpiderMonkey or Gecko.
00048  */
00049 
00050 /*
00051  * Expose all the integer types defined in C99's <stdint.h> (and the integer
00052  * limit and constant macros, if compiling C code or if compiling C++ code and
00053  * the right __STDC_*_MACRO has been defined for each).  These are all usable
00054  * throughout mfbt code, and throughout Mozilla code more generally.
00055  */
00056 #include "mozilla/StandardInteger.h"
00057 
00058 /* Also expose size_t. */
00059 #include <stddef.h>
00060 
00061 /* Implement compiler and linker macros needed for APIs. */
00062 
00063 /*
00064  * MOZ_EXPORT_API is used to declare and define a method which is externally
00065  * visible to users of the current library.  It encapsulates various decorations
00066  * needed to properly export the method's symbol.  MOZ_EXPORT_DATA serves the
00067  * same purpose for data.
00068  *
00069  *   api.h:
00070  *     extern MOZ_EXPORT_API(int) MeaningOfLife(void);
00071  *     extern MOZ_EXPORT_DATA(int) LuggageCombination;
00072  *
00073  *   api.c:
00074  *     MOZ_EXPORT_API(int) MeaningOfLife(void) { return 42; }
00075  *     MOZ_EXPORT_DATA(int) LuggageCombination = 12345;
00076  *
00077  * If you are merely sharing a method across files, just use plain |extern|.
00078  * These macros are designed for use by library interfaces -- not for normal
00079  * methods or data used cross-file.
00080  */
00081 #if defined(WIN32) || defined(XP_OS2)
00082 #  define MOZ_EXPORT_API(type)    __declspec(dllexport) type
00083 #  define MOZ_EXPORT_DATA(type)   __declspec(dllexport) type
00084 #else /* Unix */
00085 #  ifdef HAVE_VISIBILITY_ATTRIBUTE
00086 #    define MOZ_EXTERNAL_VIS       __attribute__((visibility("default")))
00087 #  elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
00088 #    define MOZ_EXTERNAL_VIS      __global
00089 #  else
00090 #    define MOZ_EXTERNAL_VIS
00091 #  endif
00092 #  define MOZ_EXPORT_API(type)    MOZ_EXTERNAL_VIS type
00093 #  define MOZ_EXPORT_DATA(type)   MOZ_EXTERNAL_VIS type
00094 #endif
00095 
00096 /*
00097  * Whereas implementers use MOZ_EXPORT_API and MOZ_EXPORT_DATA to declare and
00098  * define library symbols, users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to
00099  * access them.  Most often the implementer of the library will expose an API
00100  * macro which expands to either the export or import version of the macro,
00101  * depending upon the compilation mode.
00102  */
00103 #ifdef _WIN32
00104 #  if defined(__MWERKS__)
00105 #    define MOZ_IMPORT_API(x)    x
00106 #  else
00107 #    define MOZ_IMPORT_API(x)    __declspec(dllimport) x
00108 #  endif
00109 #elif defined(XP_OS2)
00110 #  define MOZ_IMPORT_API(x)     __declspec(dllimport) x
00111 #else
00112 #  define MOZ_IMPORT_API(x)     MOZ_EXPORT_API(x)
00113 #endif
00114 
00115 #if defined(_WIN32) && !defined(__MWERKS__)
00116 #  define MOZ_IMPORT_DATA(x)     __declspec(dllimport) x
00117 #elif defined(XP_OS2)
00118 #  define MOZ_IMPORT_DATA(x)     __declspec(dllimport) x
00119 #else
00120 #  define MOZ_IMPORT_DATA(x)     MOZ_EXPORT_DATA(x)
00121 #endif
00122 
00123 /*
00124  * Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose
00125  * export mfbt declarations when building mfbt, and they expose import mfbt
00126  * declarations when using mfbt.
00127  */
00128 #if defined(IMPL_MFBT)
00129 #  define MFBT_API(type)        MOZ_EXPORT_API(type)
00130 #  define MFBT_DATA(type)       MOZ_EXPORT_DATA(type)
00131 #else
00132   /*
00133    * When mozglue is linked in the program, we need the MFBT API symbols
00134    * to be weak.
00135    */
00136 #  if defined(MOZ_GLUE_IN_PROGRAM)
00137 #    define MFBT_API(type)        __attribute__((weak)) MOZ_IMPORT_API(type)
00138 #    define MFBT_DATA(type)       __attribute__((weak)) MOZ_IMPORT_DATA(type)
00139 #  else
00140 #    define MFBT_API(type)        MOZ_IMPORT_API(type)
00141 #    define MFBT_DATA(type)       MOZ_IMPORT_DATA(type)
00142 #  endif
00143 #endif
00144 
00145 /*
00146  * C symbols in C++ code must be declared immediately within |extern "C"|
00147  * blocks.  However, in C code, they need not be declared specially.  This
00148  * difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C
00149  * macros, so that the user need not know whether he is being used in C or C++
00150  * code.
00151  *
00152  *   MOZ_BEGIN_EXTERN_C
00153  *
00154  *   extern MOZ_EXPORT_API(int) MostRandomNumber(void);
00155  *   ...other declarations...
00156  *
00157  *   MOZ_END_EXTERN_C
00158  *
00159  * This said, it is preferable to just use |extern "C"| in C++ header files for
00160  * its greater clarity.
00161  */
00162 #ifdef __cplusplus
00163 #  define MOZ_BEGIN_EXTERN_C    extern "C" {
00164 #  define MOZ_END_EXTERN_C      }
00165 #else
00166 #  define MOZ_BEGIN_EXTERN_C
00167 #  define MOZ_END_EXTERN_C
00168 #endif
00169 
00170 #endif  /* mozilla_Types_h_ */