Bug 805416 - refactor macros to avoid the need for empty macro arguments. r=Waldo.
authorRafael Ávila de Espíndola <respindola@mozilla.com>
Tue, 30 Oct 2012 16:12:22 -0400
changeset 119760 b511cc69f71774e42589f1fd843006d230e3cd13
parent 119759 434c6bdec0bb8c1891fe909b2eaf59b4b46fd2f1
child 119761 e7d9b7fadd242e92f3c0a31a9ece2c83c61fee29
push id1997
push userakeybl@mozilla.com
push dateMon, 07 Jan 2013 21:25:26 +0000
treeherdermozilla-beta@4baf45cdcf21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs805416
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 805416 - refactor macros to avoid the need for empty macro arguments. r=Waldo.
mfbt/HashFunctions.cpp
mfbt/HashFunctions.h
mfbt/SHA1.h
mfbt/Types.h
mfbt/double-conversion/add-mfbt-api-markers.patch
mfbt/double-conversion/double-conversion.h
--- a/mfbt/HashFunctions.cpp
+++ b/mfbt/HashFunctions.cpp
@@ -7,17 +7,17 @@
 
 #include "mozilla/HashFunctions.h"
 #include "mozilla/Types.h"
 
 #include <string.h>
 
 namespace mozilla {
 
-MFBT_API(uint32_t)
+uint32_t
 HashBytes(const void* bytes, size_t length)
 {
   uint32_t hash = 0;
   const char* b = reinterpret_cast<const char*>(bytes);
 
   /* Walk word by word. */
   size_t i = 0;
   for (; i < length - (length % sizeof(size_t)); i += sizeof(size_t)) {
--- a/mfbt/HashFunctions.h
+++ b/mfbt/HashFunctions.h
@@ -346,14 +346,14 @@ HashString(const wchar_t* str, size_t le
 
 /**
  * Hash some number of bytes.
  *
  * This hash walks word-by-word, rather than byte-by-byte, so you won't get the
  * same result out of HashBytes as you would out of HashString.
  */
 MOZ_WARN_UNUSED_RESULT
-extern MFBT_API(uint32_t)
+extern MFBT_API uint32_t
 HashBytes(const void* bytes, size_t length);
 
 } /* namespace mozilla */
 #endif /* __cplusplus */
 #endif /* mozilla_HashFunctions_h_ */
--- a/mfbt/SHA1.h
+++ b/mfbt/SHA1.h
@@ -39,23 +39,23 @@ class SHA1Sum
         uint32_t w[16]; /* input buffer */
         uint8_t b[64];
     } u;
     uint64_t size; /* count of hashed bytes. */
     unsigned H[22]; /* 5 state variables, 16 tmp values, 1 extra */
     bool mDone;
 
   public:
-    MFBT_API() SHA1Sum();
+    MFBT_API SHA1Sum();
 
     static const size_t HashSize = 20;
     typedef uint8_t Hash[HashSize];
 
     /* Add len bytes of dataIn to the data sequence being hashed. */
-    MFBT_API(void) update(const void* dataIn, uint32_t len);
+    MFBT_API void update(const void* dataIn, uint32_t len);
 
     /* Compute the final hash of all data into hashOut. */
-    MFBT_API(void) finish(SHA1Sum::Hash& hashOut);
+    MFBT_API void finish(SHA1Sum::Hash& hashOut);
 };
 
 } /* namespace mozilla */
 
 #endif /* mozilla_SHA1_h_ */
--- a/mfbt/Types.h
+++ b/mfbt/Types.h
@@ -40,79 +40,84 @@
  *     MOZ_EXPORT_API(int) MeaningOfLife(void) { return 42; }
  *     MOZ_EXPORT_DATA(int) LuggageCombination = 12345;
  *
  * 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.
  */
 #if defined(WIN32) || defined(XP_OS2)
-#  define MOZ_EXPORT_API(type)    __declspec(dllexport) type
-#  define MOZ_EXPORT_DATA(type)   __declspec(dllexport) type
+#  define MOZ_EXPORT_DIRECTIVE  __declspec(dllexport)
 #else /* Unix */
 #  ifdef HAVE_VISIBILITY_ATTRIBUTE
 #    define MOZ_EXTERNAL_VIS       __attribute__((visibility("default")))
 #  elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
 #    define MOZ_EXTERNAL_VIS      __global
 #  else
 #    define MOZ_EXTERNAL_VIS
 #  endif
-#  define MOZ_EXPORT_API(type)    MOZ_EXTERNAL_VIS type
-#  define MOZ_EXPORT_DATA(type)   MOZ_EXTERNAL_VIS type
+#  define MOZ_EXPORT_DIRECTIVE   MOZ_EXTERNAL_VIS
 #endif
 
+#define MOZ_EXPORT_API(type)    MOZ_EXPORT_DIRECTIVE type
+#define MOZ_EXPORT_DATA(type)   MOZ_EXPORT_DIRECTIVE type
+
 /*
  * Whereas implementers use MOZ_EXPORT_API and MOZ_EXPORT_DATA 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.
  */
 #ifdef _WIN32
 #  if defined(__MWERKS__)
-#    define MOZ_IMPORT_API(x)    x
+#    define MOZ_IMPORT_API_DIRECTIVE /* nothing */
 #  else
-#    define MOZ_IMPORT_API(x)    __declspec(dllimport) x
+#    define MOZ_IMPORT_API_DIRECTIVE __declspec(dllimport)
 #  endif
 #elif defined(XP_OS2)
-#  define MOZ_IMPORT_API(x)     __declspec(dllimport) x
+#  define MOZ_IMPORT_API_DIRECTIVE  __declspec(dllimport)
 #else
-#  define MOZ_IMPORT_API(x)     MOZ_EXPORT_API(x)
+#  define MOZ_IMPORT_API_DIRECTIVE MOZ_EXPORT_DIRECTIVE
 #endif
 
+#define MOZ_IMPORT_API(x)    MOZ_IMPORT_API_DIRECTIVE x
+
 #if defined(_WIN32) && !defined(__MWERKS__)
-#  define MOZ_IMPORT_DATA(x)     __declspec(dllimport) x
+#  define MOZ_IMPORT_DATA_DIRECTIVE __declspec(dllimport)
 #elif defined(XP_OS2)
-#  define MOZ_IMPORT_DATA(x)     __declspec(dllimport) x
+#  define MOZ_IMPORT_DATA_DIRECTIVE __declspec(dllimport)
 #else
-#  define MOZ_IMPORT_DATA(x)     MOZ_EXPORT_DATA(x)
+#  define MOZ_IMPORT_DATA_DIRECTIVE MOZ_EXPORT_DIRECTIVE
 #endif
 
+#define MOZ_IMPORT_DATA(x)    MOZ_IMPORT_DATA_DIRECTIVE x
+
 /*
  * 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.
  */
 #if defined(IMPL_MFBT)
-#  define MFBT_API(type)        MOZ_EXPORT_API(type)
-#  define MFBT_DATA(type)       MOZ_EXPORT_DATA(type)
+#  define MFBT_API     MOZ_EXPORT_DIRECTIVE
+#  define MFBT_DATA    MOZ_EXPORT_DIRECTIVE
 #else
   /*
    * 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.
    */
 #  if defined(MOZ_GLUE_IN_PROGRAM)
-#    define MFBT_API(type)        __attribute__((weak)) MOZ_IMPORT_API(type)
-#    define MFBT_DATA(type)       __attribute__((weak)) MOZ_IMPORT_DATA(type)
+#    define MFBT_API   __attribute__((weak)) MOZ_IMPORT_API_DIRECTIVE
+#    define MFBT_DATA  __attribute__((weak)) MOZ_IMPORT_DATA_DIRECTIVE
 #  else
-#    define MFBT_API(type)        MOZ_IMPORT_API(type)
-#    define MFBT_DATA(type)       MOZ_IMPORT_DATA(type)
+#    define MFBT_API   MOZ_IMPORT_API_DIRECTIVE
+#    define MFBT_DATA  MOZ_IMPORT_DATA_DIRECTIVE
 #  endif
 #endif
 
 /*
  * 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++
--- a/mfbt/double-conversion/add-mfbt-api-markers.patch
+++ b/mfbt/double-conversion/add-mfbt-api-markers.patch
@@ -1,94 +1,94 @@
 diff --git a/mfbt/double-conversion/double-conversion.h b/mfbt/double-conversion/double-conversion.h
-index f98edae..e536a01 100644
+index f98edae..c62b16b 100644
 --- a/mfbt/double-conversion/double-conversion.h
 +++ b/mfbt/double-conversion/double-conversion.h
 @@ -28,6 +28,7 @@
  #ifndef DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
  #define DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
  
 +#include "mozilla/Types.h"
  #include "utils.h"
  
  namespace double_conversion {
 @@ -129,7 +130,7 @@ class DoubleToStringConverter {
    }
  
    // Returns a converter following the EcmaScript specification.
 -  static const DoubleToStringConverter& EcmaScriptConverter();
-+  static MFBT_API(const DoubleToStringConverter&) EcmaScriptConverter();
++  static MFBT_API const DoubleToStringConverter& EcmaScriptConverter();
  
    // Computes the shortest string of digits that correctly represent the input
    // number. Depending on decimal_in_shortest_low and decimal_in_shortest_high
 @@ -197,7 +198,7 @@ class DoubleToStringConverter {
    // The last two conditions imply that the result will never contain more than
    // 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint characters
    // (one additional character for the sign, and one for the decimal point).
 -  bool ToFixed(double value,
-+  MFBT_API(bool) ToFixed(double value,
++  MFBT_API bool ToFixed(double value,
                 int requested_digits,
                 StringBuilder* result_builder) const;
  
 @@ -229,7 +230,7 @@ class DoubleToStringConverter {
    // kMaxExponentialDigits + 8 characters (the sign, the digit before the
    // decimal point, the decimal point, the exponent character, the
    // exponent's sign, and at most 3 exponent digits).
 -  bool ToExponential(double value,
-+  MFBT_API(bool) ToExponential(double value,
++  MFBT_API bool ToExponential(double value,
                       int requested_digits,
                       StringBuilder* result_builder) const;
  
 @@ -267,7 +268,7 @@ class DoubleToStringConverter {
    // The last condition implies that the result will never contain more than
    // kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the
    // exponent character, the exponent's sign, and at most 3 exponent digits).
 -  bool ToPrecision(double value,
-+  MFBT_API(bool) ToPrecision(double value,
++  MFBT_API bool ToPrecision(double value,
                     int precision,
                     StringBuilder* result_builder) const;
  
 @@ -292,7 +293,7 @@ class DoubleToStringConverter {
    // kBase10MaximalLength.
    // Note that DoubleToAscii null-terminates its input. So the given buffer
    // should be at least kBase10MaximalLength + 1 characters long.
 -  static const int kBase10MaximalLength = 17;
-+  static const MFBT_DATA(int) kBase10MaximalLength = 17;
++  static const MFBT_DATA int kBase10MaximalLength = 17;
  
    // Converts the given double 'v' to ascii. 'v' must not be NaN, +Infinity, or
    // -Infinity. In SHORTEST_SINGLE-mode this restriction also applies to 'v'
 @@ -332,7 +333,7 @@ class DoubleToStringConverter {
    // terminating null-character when computing the maximal output size.
    // The given length is only used in debug mode to ensure the buffer is big
    // enough.
 -  static void DoubleToAscii(double v,
-+  static MFBT_API(void) DoubleToAscii(double v,
++  static MFBT_API void DoubleToAscii(double v,
                              DtoaMode mode,
                              int requested_digits,
                              char* buffer,
 @@ -343,7 +344,7 @@ class DoubleToStringConverter {
  
   private:
    // Implementation for ToShortest and ToShortestSingle.
 -  bool ToShortestIeeeNumber(double value,
-+  MFBT_API(bool) ToShortestIeeeNumber(double value,
++  MFBT_API bool ToShortestIeeeNumber(double value,
                              StringBuilder* result_builder,
                              DtoaMode mode) const;
  
 @@ -351,15 +352,15 @@ class DoubleToStringConverter {
    // corresponding string using the configured infinity/nan-symbol.
    // If either of them is NULL or the value is not special then the
    // function returns false.
 -  bool HandleSpecialValues(double value, StringBuilder* result_builder) const;
-+  MFBT_API(bool) HandleSpecialValues(double value, StringBuilder* result_builder) const;
++  MFBT_API bool HandleSpecialValues(double value, StringBuilder* result_builder) const;
    // Constructs an exponential representation (i.e. 1.234e56).
    // The given exponent assumes a decimal point after the first decimal digit.
 -  void CreateExponentialRepresentation(const char* decimal_digits,
-+  MFBT_API(void) CreateExponentialRepresentation(const char* decimal_digits,
++  MFBT_API void CreateExponentialRepresentation(const char* decimal_digits,
                                         int length,
                                         int exponent,
                                         StringBuilder* result_builder) const;
    // Creates a decimal representation (i.e 1234.5678).
 -  void CreateDecimalRepresentation(const char* decimal_digits,
-+  MFBT_API(void) CreateDecimalRepresentation(const char* decimal_digits,
++  MFBT_API void CreateDecimalRepresentation(const char* decimal_digits,
                                     int length,
                                     int decimal_point,
                                     int digits_after_point,
--- a/mfbt/double-conversion/double-conversion.h
+++ b/mfbt/double-conversion/double-conversion.h
@@ -125,17 +125,17 @@ class DoubleToStringConverter {
             max_trailing_padding_zeroes_in_precision_mode) {
     // When 'trailing zero after the point' is set, then 'trailing point'
     // must be set too.
     ASSERT(((flags & EMIT_TRAILING_DECIMAL_POINT) != 0) ||
         !((flags & EMIT_TRAILING_ZERO_AFTER_POINT) != 0));
   }
 
   // Returns a converter following the EcmaScript specification.
-  static MFBT_API(const DoubleToStringConverter&) EcmaScriptConverter();
+  static MFBT_API const DoubleToStringConverter& EcmaScriptConverter();
 
   // Computes the shortest string of digits that correctly represent the input
   // number. Depending on decimal_in_shortest_low and decimal_in_shortest_high
   // (see constructor) it then either returns a decimal representation, or an
   // exponential representation.
   // Example with decimal_in_shortest_low = -6,
   //              decimal_in_shortest_high = 21,
   //              EMIT_POSITIVE_EXPONENT_SIGN activated, and
@@ -193,17 +193,17 @@ class DoubleToStringConverter {
   // except for the following cases:
   //   - the input value is special and no infinity_symbol or nan_symbol has
   //     been provided to the constructor,
   //   - 'value' > 10^kMaxFixedDigitsBeforePoint, or
   //   - 'requested_digits' > kMaxFixedDigitsAfterPoint.
   // The last two conditions imply that the result will never contain more than
   // 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint characters
   // (one additional character for the sign, and one for the decimal point).
-  MFBT_API(bool) ToFixed(double value,
+  MFBT_API bool ToFixed(double value,
                int requested_digits,
                StringBuilder* result_builder) const;
 
   // Computes a representation in exponential format with requested_digits
   // after the decimal point. The last emitted digit is rounded.
   // If requested_digits equals -1, then the shortest exponential representation
   // is computed.
   //
@@ -225,17 +225,17 @@ class DoubleToStringConverter {
   // except for the following cases:
   //   - the input value is special and no infinity_symbol or nan_symbol has
   //     been provided to the constructor,
   //   - 'requested_digits' > kMaxExponentialDigits.
   // The last condition implies that the result will never contain more than
   // kMaxExponentialDigits + 8 characters (the sign, the digit before the
   // decimal point, the decimal point, the exponent character, the
   // exponent's sign, and at most 3 exponent digits).
-  MFBT_API(bool) ToExponential(double value,
+  MFBT_API bool ToExponential(double value,
                      int requested_digits,
                      StringBuilder* result_builder) const;
 
   // Computes 'precision' leading digits of the given 'value' and returns them
   // either in exponential or decimal format, depending on
   // max_{leading|trailing}_padding_zeroes_in_precision_mode (given to the
   // constructor).
   // The last computed digit is rounded.
@@ -263,17 +263,17 @@ class DoubleToStringConverter {
   // except for the following cases:
   //   - the input value is special and no infinity_symbol or nan_symbol has
   //     been provided to the constructor,
   //   - precision < kMinPericisionDigits
   //   - precision > kMaxPrecisionDigits
   // The last condition implies that the result will never contain more than
   // kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the
   // exponent character, the exponent's sign, and at most 3 exponent digits).
-  MFBT_API(bool) ToPrecision(double value,
+  MFBT_API bool ToPrecision(double value,
                    int precision,
                    StringBuilder* result_builder) const;
 
   enum DtoaMode {
     // Produce the shortest correct representation.
     // For example the output of 0.299999999999999988897 is (the less accurate
     // but correct) 0.3.
     SHORTEST,
@@ -288,17 +288,17 @@ class DoubleToStringConverter {
   };
 
   // The maximal number of digits that are needed to emit a double in base 10.
   // A higher precision can be achieved by using more digits, but the shortest
   // accurate representation of any double will never use more digits than
   // kBase10MaximalLength.
   // Note that DoubleToAscii null-terminates its input. So the given buffer
   // should be at least kBase10MaximalLength + 1 characters long.
-  static const MFBT_DATA(int) kBase10MaximalLength = 17;
+  static const MFBT_DATA int kBase10MaximalLength = 17;
 
   // Converts the given double 'v' to ascii. 'v' must not be NaN, +Infinity, or
   // -Infinity. In SHORTEST_SINGLE-mode this restriction also applies to 'v'
   // after it has been casted to a single-precision float. That is, in this
   // mode static_cast<float>(v) must not be NaN, +Infinity or -Infinity.
   //
   // The result should be interpreted as buffer * 10^(point-length).
   //
@@ -328,44 +328,44 @@ class DoubleToStringConverter {
   // DoubleToAscii expects the given buffer to be big enough to hold all
   // digits and a terminating null-character. In SHORTEST-mode it expects a
   // buffer of at least kBase10MaximalLength + 1. In all other modes the
   // requested_digits parameter and the padding-zeroes limit the size of the
   // output. Don't forget the decimal point, the exponent character and the
   // terminating null-character when computing the maximal output size.
   // The given length is only used in debug mode to ensure the buffer is big
   // enough.
-  static MFBT_API(void) DoubleToAscii(double v,
+  static MFBT_API void DoubleToAscii(double v,
                             DtoaMode mode,
                             int requested_digits,
                             char* buffer,
                             int buffer_length,
                             bool* sign,
                             int* length,
                             int* point);
 
  private:
   // Implementation for ToShortest and ToShortestSingle.
-  MFBT_API(bool) ToShortestIeeeNumber(double value,
+  MFBT_API bool ToShortestIeeeNumber(double value,
                             StringBuilder* result_builder,
                             DtoaMode mode) const;
 
   // If the value is a special value (NaN or Infinity) constructs the
   // corresponding string using the configured infinity/nan-symbol.
   // If either of them is NULL or the value is not special then the
   // function returns false.
-  MFBT_API(bool) HandleSpecialValues(double value, StringBuilder* result_builder) const;
+  MFBT_API bool HandleSpecialValues(double value, StringBuilder* result_builder) const;
   // Constructs an exponential representation (i.e. 1.234e56).
   // The given exponent assumes a decimal point after the first decimal digit.
-  MFBT_API(void) CreateExponentialRepresentation(const char* decimal_digits,
+  MFBT_API void CreateExponentialRepresentation(const char* decimal_digits,
                                        int length,
                                        int exponent,
                                        StringBuilder* result_builder) const;
   // Creates a decimal representation (i.e 1234.5678).
-  MFBT_API(void) CreateDecimalRepresentation(const char* decimal_digits,
+  MFBT_API void CreateDecimalRepresentation(const char* decimal_digits,
                                    int length,
                                    int decimal_point,
                                    int digits_after_point,
                                    StringBuilder* result_builder) const;
 
   const int flags_;
   const char* const infinity_symbol_;
   const char* const nan_symbol_;