Commit bfe2b889 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

define FOLLY_ATTR_WEAK in CPortability.h

Summary:
Define a FOLLY_ATTR_WEAK helper macro in CPortability.h, and update existing
code in folly that declares functions as weak to use this new macro.  This will
make it easier to declare weak functions in other files in the future.

Reviewed By: yfeldblum

Differential Revision: D7164834

fbshipit-source-id: 87e03401400f2912fcd5e719af0d667251cd642b
parent bf255392
......@@ -19,6 +19,8 @@
/* These definitions are in a separate file so that they
* may be included from C- as well as C++-based projects. */
#include <folly/portability/Config.h>
/**
* Portable version check.
*/
......@@ -154,3 +156,10 @@
#else
#define FOLLY_ATTR_VISIBILITY_HIDDEN
#endif
// An attribute for marking symbols as weak, if supported
#if FOLLY_HAVE_WEAK_SYMBOLS
#define FOLLY_ATTR_WEAK __attribute__((__weak__))
#else
#define FOLLY_ATTR_WEAK
#endif
......@@ -15,16 +15,10 @@
*/
#include <folly/compression/Counters.h>
#include <folly/portability/Config.h>
#include <folly/Portability.h>
namespace folly {
#if FOLLY_HAVE_WEAK_SYMBOLS
#define FOLLY_WEAK_SYMBOL __attribute__((__weak__))
#else
#define FOLLY_WEAK_SYMBOL
#endif
folly::Function<void(double)> FOLLY_WEAK_SYMBOL makeCompressionCounterHandler(
FOLLY_ATTR_WEAK folly::Function<void(double)> makeCompressionCounterHandler(
folly::io::CodecType,
folly::StringPiece,
folly::Optional<int>,
......
......@@ -17,6 +17,7 @@
#include <set>
#include <folly/CPortability.h>
#include <folly/Conv.h>
#include <folly/FileUtil.h>
#include <folly/String.h>
......@@ -28,7 +29,6 @@
#include <folly/experimental/logging/Logger.h>
#include <folly/experimental/logging/RateLimiter.h>
#include <folly/experimental/logging/StreamHandlerFactory.h>
#include <folly/portability/Config.h>
using std::string;
......@@ -40,10 +40,7 @@ namespace folly {
* This is defined as a weak symbol to allow programs to provide their own
* alternative definition if desired.
*/
#if FOLLY_HAVE_WEAK_SYMBOLS
void initializeLoggerDB(LoggerDB& db) __attribute__((weak));
#endif
void initializeLoggerDB(LoggerDB& db) {
FOLLY_ATTR_WEAK void initializeLoggerDB(LoggerDB& db) {
// Register the StreamHandlerFactory
//
// This is the only LogHandlerFactory that we register by default. We
......
......@@ -25,7 +25,7 @@
* The Makefile links it into all of the test programs so that tests do not need
* to - and indeed should typically not - define their own main() functions
*/
int main(int argc, char** argv) __attribute__((__weak__));
FOLLY_ATTR_WEAK int main(int argc, char** argv);
int main(int argc, char** argv) {
#if FOLLY_HAVE_LIBGFLAGS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment