Skip to content

Commit

Permalink
Bug 805416 - refactor macros to avoid the need for empty macro argume…
Browse files Browse the repository at this point in the history
…nts. r=Waldo.
  • Loading branch information
cixtor committed Oct 30, 2012
1 parent 6404f08 commit fe6bff1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 43 deletions.
2 changes: 1 addition & 1 deletion mfbt/HashFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace mozilla {

MFBT_API(uint32_t)
uint32_t
HashBytes(const void* bytes, size_t length)
{
uint32_t hash = 0;
Expand Down
2 changes: 1 addition & 1 deletion mfbt/HashFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ HashString(const wchar_t* str, size_t length)
* 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 */
Expand Down
6 changes: 3 additions & 3 deletions mfbt/SHA1.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ class SHA1Sum
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 */
Expand Down
39 changes: 22 additions & 17 deletions mfbt/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
* 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")))
Expand All @@ -55,10 +54,12 @@
# 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
Expand All @@ -68,32 +69,36 @@
*/
#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
Expand All @@ -103,11 +108,11 @@
* 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

Expand Down
22 changes: 11 additions & 11 deletions mfbt/double-conversion/add-mfbt-api-markers.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 @@
Expand All @@ -15,7 +15,7 @@ index f98edae..e536a01 100644

// 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
Expand All @@ -24,7 +24,7 @@ index f98edae..e536a01 100644
// 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;

Expand All @@ -33,7 +33,7 @@ index f98edae..e536a01 100644
// 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;

Expand All @@ -42,7 +42,7 @@ index f98edae..e536a01 100644
// 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;

Expand All @@ -51,7 +51,7 @@ index f98edae..e536a01 100644
// 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'
Expand All @@ -60,7 +60,7 @@ index f98edae..e536a01 100644
// 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,
Expand All @@ -69,7 +69,7 @@ index f98edae..e536a01 100644
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;

Expand All @@ -78,17 +78,17 @@ index f98edae..e536a01 100644
// 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,
20 changes: 10 additions & 10 deletions mfbt/double-conversion/double-conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class DoubleToStringConverter {
}

// 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
Expand Down Expand Up @@ -198,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).
MFBT_API(bool) ToFixed(double value,
MFBT_API bool ToFixed(double value,
int requested_digits,
StringBuilder* result_builder) const;

Expand Down Expand Up @@ -230,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).
MFBT_API(bool) ToExponential(double value,
MFBT_API bool ToExponential(double value,
int requested_digits,
StringBuilder* result_builder) const;

Expand Down Expand Up @@ -268,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).
MFBT_API(bool) ToPrecision(double value,
MFBT_API bool ToPrecision(double value,
int precision,
StringBuilder* result_builder) const;

Expand All @@ -293,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 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'
Expand Down Expand Up @@ -333,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 MFBT_API(void) DoubleToAscii(double v,
static MFBT_API void DoubleToAscii(double v,
DtoaMode mode,
int requested_digits,
char* buffer,
Expand All @@ -344,23 +344,23 @@ class DoubleToStringConverter {

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,
Expand Down

0 comments on commit fe6bff1

Please sign in to comment.