From f842b713b74810cfc0f8b553b16f5efe811662db Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Mon, 8 Jan 2018 15:21:57 -0800 Subject: [PATCH] give all folly exception types default visibility Summary: This makes sure that whether folly is statically or dynamically linked, all folly exception types will have exactly one definition, and one set of type information. Reviewed By: mzlee Differential Revision: D6671431 fbshipit-source-id: 1c06826a05f87cbf9af747c9abdb5f524744d054 --- folly/AtomicHashMap.h | 6 +++--- folly/ExceptionWrapper.h | 2 +- folly/Expected.h | 8 ++++---- folly/Format.h | 3 ++- folly/FormatArg.h | 3 ++- folly/IPAddressException.h | 9 +++++---- folly/Optional.h | 5 ++--- folly/Poly.h | 5 +++-- folly/Subprocess.h | 9 ++++----- folly/Try.h | 7 +++---- folly/dynamic-inl.h | 6 +++--- folly/executors/task_queue/BlockingQueue.h | 7 ++++--- folly/experimental/DynamicParser.h | 7 ++++--- folly/experimental/EnvUtil.h | 9 +++++---- folly/experimental/JSONSchema.cpp | 8 ++++---- folly/experimental/NestedCommandLineApp.h | 6 +++--- folly/experimental/bser/Bser.h | 5 +++-- folly/experimental/logging/LogConfigParser.h | 3 ++- folly/fibers/AtomicBatchDispatcher.h | 20 +++++++++++--------- folly/io/async/AsyncSocketException.h | 6 +++--- folly/json.cpp | 9 ++++----- folly/synchronization/LifoSem.h | 6 +++--- 22 files changed, 78 insertions(+), 71 deletions(-) diff --git a/folly/AtomicHashMap.h b/folly/AtomicHashMap.h index 2243b6be..cfa78104 100644 --- a/folly/AtomicHashMap.h +++ b/folly/AtomicHashMap.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /* * AtomicHashMap -- * @@ -91,6 +90,7 @@ #include #include +#include #include #include #include @@ -149,7 +149,7 @@ namespace folly { // Thrown when insertion fails due to running out of space for // submaps. -struct AtomicHashMapFullError : std::runtime_error { +struct FOLLY_EXPORT AtomicHashMapFullError : std::runtime_error { explicit AtomicHashMapFullError() : std::runtime_error("AtomicHashMap is full") {} diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index ff60aa34..fc0cac77 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -162,7 +162,7 @@ auto fold(Fn&& fn, A&& a, B&& b, Bs&&... bs) { //! \endcode class exception_wrapper final { private: - struct AnyException : std::exception { + struct FOLLY_EXPORT AnyException : std::exception { std::type_info const* typeinfo_; template /* implicit */ AnyException(T&& t) noexcept : typeinfo_(&typeid(t)) {} diff --git a/folly/Expected.h b/folly/Expected.h index 37963367..9d3535f9 100644 --- a/folly/Expected.h +++ b/folly/Expected.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /** * Like folly::Optional, but can store a value *or* an error. * @@ -31,6 +30,7 @@ #include +#include #include #include #include @@ -660,7 +660,7 @@ inline expected_detail::UnexpectedTag unexpected( /** * An exception type thrown by Expected on catastrophic logic errors. */ -class BadExpectedAccess : public std::logic_error { +class FOLLY_EXPORT BadExpectedAccess : public std::logic_error { public: BadExpectedAccess() : std::logic_error("bad Expected access") {} }; @@ -689,7 +689,7 @@ class Unexpected final : ColdClass { * when the user tries to access the nested value but the Expected object is * actually storing an error code. */ - class BadExpectedAccess : public folly::BadExpectedAccess { + class FOLLY_EXPORT BadExpectedAccess : public folly::BadExpectedAccess { public: explicit BadExpectedAccess(Error err) : folly::BadExpectedAccess{}, error_(std::move(err)) {} diff --git a/folly/Format.h b/folly/Format.h index 5980639b..2c5f2fc3 100644 --- a/folly/Format.h +++ b/folly/Format.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -318,7 +319,7 @@ inline std::string svformat(StringPiece fmt, Container&& container) { * makes the exception type small and noexcept-copyable like std::out_of_range, * and therefore able to fit in-situ in exception_wrapper. */ -class FormatKeyNotFoundException : public std::out_of_range { +class FOLLY_EXPORT FormatKeyNotFoundException : public std::out_of_range { public: explicit FormatKeyNotFoundException(StringPiece key); diff --git a/folly/FormatArg.h b/folly/FormatArg.h index df1054e1..62c9705c 100644 --- a/folly/FormatArg.h +++ b/folly/FormatArg.h @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -25,7 +26,7 @@ namespace folly { -class BadFormatArg : public std::invalid_argument { +class FOLLY_EXPORT BadFormatArg : public std::invalid_argument { using invalid_argument::invalid_argument; }; diff --git a/folly/IPAddressException.h b/folly/IPAddressException.h index d1830ba6..0ba74621 100644 --- a/folly/IPAddressException.h +++ b/folly/IPAddressException.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once #include #include #include +#include #include namespace folly { @@ -32,7 +32,7 @@ enum class IPAddressFormatError { INVALID_IP, UNSUPPORTED_ADDR_FAMILY }; /** * Exception for invalid IP addresses. */ -class IPAddressFormatException : public std::exception { +class FOLLY_EXPORT IPAddressFormatException : public std::exception { public: explicit IPAddressFormatException(std::string msg) noexcept : msg_(std::move(msg)) {} @@ -51,7 +51,8 @@ class IPAddressFormatException : public std::exception { std::string msg_; }; -class InvalidAddressFamilyException : public IPAddressFormatException { +class FOLLY_EXPORT InvalidAddressFamilyException + : public IPAddressFormatException { public: explicit InvalidAddressFamilyException(std::string msg) noexcept : IPAddressFormatException(std::move(msg)) {} diff --git a/folly/Optional.h b/folly/Optional.h index 60ae2c73..8f48010f 100644 --- a/folly/Optional.h +++ b/folly/Optional.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once /* @@ -87,7 +86,7 @@ typedef int detail::NoneHelper::*None; const None none = nullptr; -class OptionalEmptyException : public std::runtime_error { +class FOLLY_EXPORT OptionalEmptyException : public std::runtime_error { public: OptionalEmptyException() : std::runtime_error("Empty Optional cannot be unwrapped") {} diff --git a/folly/Poly.h b/folly/Poly.h index 5563f0a3..f2f4b900 100644 --- a/folly/Poly.h +++ b/folly/Poly.h @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -175,7 +176,7 @@ struct PolyMembers {}; /** * Exception type that is thrown on invalid access of an empty `Poly` object. */ -struct BadPolyAccess : std::exception { +struct FOLLY_EXPORT BadPolyAccess : std::exception { BadPolyAccess() = default; char const* what() const noexcept override { return "BadPolyAccess"; @@ -186,7 +187,7 @@ struct BadPolyAccess : std::exception { * Exception type that is thrown when attempting to extract from a `Poly` a * value of the wrong type. */ -struct BadPolyCast : std::bad_cast { +struct FOLLY_EXPORT BadPolyCast : std::bad_cast { BadPolyCast() = default; char const* what() const noexcept override { return "BadPolyCast"; diff --git a/folly/Subprocess.h b/folly/Subprocess.h index 72cf3fe0..597bb573 100644 --- a/folly/Subprocess.h +++ b/folly/Subprocess.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /** * Subprocess library, modeled after Python's subprocess module * (http://docs.python.org/2/library/subprocess.html) @@ -219,7 +218,7 @@ class ProcessReturnCode { /** * Base exception thrown by the Subprocess methods. */ -class SubprocessError : public std::runtime_error { +class FOLLY_EXPORT SubprocessError : public std::runtime_error { public: using std::runtime_error::runtime_error; }; @@ -227,7 +226,7 @@ class SubprocessError : public std::runtime_error { /** * Exception thrown by *Checked methods of Subprocess. */ -class CalledProcessError : public SubprocessError { +class FOLLY_EXPORT CalledProcessError : public SubprocessError { public: explicit CalledProcessError(ProcessReturnCode rc); ~CalledProcessError() throw() override = default; @@ -239,7 +238,7 @@ class CalledProcessError : public SubprocessError { /** * Exception thrown if the subprocess cannot be started. */ -class SubprocessSpawnError : public SubprocessError { +class FOLLY_EXPORT SubprocessSpawnError : public SubprocessError { public: SubprocessSpawnError(const char* executable, int errCode, int errnoValue); ~SubprocessSpawnError() throw() override = default; diff --git a/folly/Try.h b/folly/Try.h index 7b97754c..61753492 100644 --- a/folly/Try.h +++ b/folly/Try.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once #include @@ -29,12 +28,12 @@ namespace folly { -class TryException : public std::logic_error { +class FOLLY_EXPORT TryException : public std::logic_error { public: using std::logic_error::logic_error; }; -class UsingUninitializedTry : public TryException { +class FOLLY_EXPORT UsingUninitializedTry : public TryException { public: UsingUninitializedTry() : TryException("Using uninitialized try") {} }; diff --git a/folly/dynamic-inl.h b/folly/dynamic-inl.h index 7b187d7c..b82126f2 100644 --- a/folly/dynamic-inl.h +++ b/folly/dynamic-inl.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once #include @@ -21,6 +20,7 @@ #include #include +#include #include #include #include @@ -76,7 +76,7 @@ struct hash<::folly::dynamic> { namespace folly { -struct TypeError : std::runtime_error { +struct FOLLY_EXPORT TypeError : std::runtime_error { explicit TypeError(const std::string& expected, dynamic::Type actual); explicit TypeError( const std::string& expected, diff --git a/folly/executors/task_queue/BlockingQueue.h b/folly/executors/task_queue/BlockingQueue.h index 49280954..99147ad6 100644 --- a/folly/executors/task_queue/BlockingQueue.h +++ b/folly/executors/task_queue/BlockingQueue.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once #include @@ -21,6 +20,8 @@ #include +#include + namespace folly { // Some queue implementations (for example, LifoSemMPMCQueue or @@ -28,7 +29,7 @@ namespace folly { // non-blocking (THROW) behaviors. enum class QueueBehaviorIfFull { THROW, BLOCK }; -class QueueFullException : public std::runtime_error { +class FOLLY_EXPORT QueueFullException : public std::runtime_error { using std::runtime_error::runtime_error; // Inherit constructors. }; diff --git a/folly/experimental/DynamicParser.h b/folly/experimental/DynamicParser.h index 386eed32..57a53752 100644 --- a/folly/experimental/DynamicParser.h +++ b/folly/experimental/DynamicParser.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ */ #pragma once +#include #include #include @@ -194,7 +195,7 @@ std::string toPseudoJson(const folly::dynamic& d); * With DynamicParser::OnError::THROW, reports the first error. * It is forbidden to call releaseErrors() if you catch this. */ -struct DynamicParserParseError : public std::runtime_error { +struct FOLLY_EXPORT DynamicParserParseError : public std::runtime_error { explicit DynamicParserParseError(folly::dynamic error) : std::runtime_error(folly::to( "DynamicParserParseError: ", detail::toPseudoJson(error) @@ -217,7 +218,7 @@ struct DynamicParserParseError : public std::runtime_error { * instead of reporting an error via releaseErrors(). It is unsafe to call * any parser methods after catching a LogicError. */ -struct DynamicParserLogicError : public std::logic_error { +struct FOLLY_EXPORT DynamicParserLogicError : public std::logic_error { template explicit DynamicParserLogicError(Args&&... args) : std::logic_error(folly::to(std::forward(args)...)) {} diff --git a/folly/experimental/EnvUtil.h b/folly/experimental/EnvUtil.h index 2d22f298..101966f5 100644 --- a/folly/experimental/EnvUtil.h +++ b/folly/experimental/EnvUtil.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once -#include #include #include #include #include +#include +#include + namespace folly { namespace experimental { @@ -87,7 +88,7 @@ struct EnvironmentState { EnvType env_; }; -struct MalformedEnvironment : std::runtime_error { +struct FOLLY_EXPORT MalformedEnvironment : std::runtime_error { using std::runtime_error::runtime_error; }; } // namespace experimental diff --git a/folly/experimental/JSONSchema.cpp b/folly/experimental/JSONSchema.cpp index d739fd10..5d7f5021 100644 --- a/folly/experimental/JSONSchema.cpp +++ b/folly/experimental/JSONSchema.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include #include #include + +#include #include #include #include @@ -33,8 +34,7 @@ namespace { /** * We throw this exception when schema validation fails. */ -struct SchemaError : std::runtime_error { - +struct FOLLY_EXPORT SchemaError : std::runtime_error { SchemaError(SchemaError&&) = default; SchemaError(const SchemaError&) = default; diff --git a/folly/experimental/NestedCommandLineApp.h b/folly/experimental/NestedCommandLineApp.h index 24210341..a5e3d5e0 100644 --- a/folly/experimental/NestedCommandLineApp.h +++ b/folly/experimental/NestedCommandLineApp.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once #include #include +#include #include namespace folly { @@ -30,7 +30,7 @@ namespace folly { * empty; the message is only allowed when exiting with a non-zero status), and * return the exit code. (Other exceptions will propagate out of run()) */ -class ProgramExit : public std::runtime_error { +class FOLLY_EXPORT ProgramExit : public std::runtime_error { public: explicit ProgramExit(int status, const std::string& msg = std::string()); int status() const { return status_; } diff --git a/folly/experimental/bser/Bser.h b/folly/experimental/bser/Bser.h index 571a7fde..571e3f5e 100644 --- a/folly/experimental/bser/Bser.h +++ b/folly/experimental/bser/Bser.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,6 +14,7 @@ * limitations under the License. */ #pragma once +#include #include #include #include @@ -32,7 +33,7 @@ namespace folly { namespace bser { -class BserDecodeError : public std::runtime_error { +class FOLLY_EXPORT BserDecodeError : public std::runtime_error { public: using std::runtime_error::runtime_error; }; diff --git a/folly/experimental/logging/LogConfigParser.h b/folly/experimental/logging/LogConfigParser.h index fae3863c..d6776319 100644 --- a/folly/experimental/logging/LogConfigParser.h +++ b/folly/experimental/logging/LogConfigParser.h @@ -17,6 +17,7 @@ #include +#include #include #include @@ -34,7 +35,7 @@ namespace folly { struct dynamic; -class LogConfigParseError : public std::invalid_argument { +class FOLLY_EXPORT LogConfigParseError : public std::invalid_argument { public: using std::invalid_argument::invalid_argument; }; diff --git a/folly/fibers/AtomicBatchDispatcher.h b/folly/fibers/AtomicBatchDispatcher.h index 93f9c93b..6dfddd2a 100644 --- a/folly/fibers/AtomicBatchDispatcher.h +++ b/folly/fibers/AtomicBatchDispatcher.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,17 +15,19 @@ */ #pragma once -#include -#include -#include -#include -#include #include #include #include #include #include +#include +#include +#include +#include +#include +#include + namespace folly { namespace fibers { @@ -35,7 +37,7 @@ namespace fibers { * Examples are, multiple dispatch calls on the same token, trying to get more * tokens from the dispatcher after commit has been called, etc. */ -class ABDUsageException : public std::logic_error { +class FOLLY_EXPORT ABDUsageException : public std::logic_error { using std::logic_error::logic_error; }; @@ -43,7 +45,7 @@ class ABDUsageException : public std::logic_error { * An exception class that gets set on the promise for dispatched tokens, when * the AtomicBatchDispatcher was destroyed before commit was called on it. */ -class ABDCommitNotCalledException : public std::runtime_error { +class FOLLY_EXPORT ABDCommitNotCalledException : public std::runtime_error { public: ABDCommitNotCalledException() : std::runtime_error( @@ -57,7 +59,7 @@ class ABDCommitNotCalledException : public std::runtime_error { * Only here so that the caller can distinguish the real failure cause * rather than these subsequently thrown exceptions. */ -class ABDTokenNotDispatchedException : public std::runtime_error { +class FOLLY_EXPORT ABDTokenNotDispatchedException : public std::runtime_error { using std::runtime_error::runtime_error; }; diff --git a/folly/io/async/AsyncSocketException.h b/folly/io/async/AsyncSocketException.h index 83f95ee0..1e9a114a 100644 --- a/folly/io/async/AsyncSocketException.h +++ b/folly/io/async/AsyncSocketException.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,17 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once #include #include +#include #include namespace folly { -class AsyncSocketException : public std::runtime_error { +class FOLLY_EXPORT AsyncSocketException : public std::runtime_error { public: enum AsyncSocketExceptionType { UNKNOWN = 0, diff --git a/folly/json.cpp b/folly/json.cpp index db80b332..a9d7af94 100644 --- a/folly/json.cpp +++ b/folly/json.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include #include @@ -22,13 +21,13 @@ #include #include -#include -#include #include +#include #include #include #include +#include #include namespace folly { @@ -187,7 +186,7 @@ struct Printer { ////////////////////////////////////////////////////////////////////// -struct ParseError : std::runtime_error { +struct FOLLY_EXPORT ParseError : std::runtime_error { explicit ParseError( unsigned int line, std::string const& context, diff --git a/folly/synchronization/LifoSem.h b/folly/synchronization/LifoSem.h index 102154cf..c6ed69b4 100644 --- a/folly/synchronization/LifoSem.h +++ b/folly/synchronization/LifoSem.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #pragma once #include @@ -23,6 +22,7 @@ #include #include +#include #include #include #include @@ -90,7 +90,7 @@ typedef LifoSemImpl<> LifoSem; /// The exception thrown when wait()ing on an isShutdown() LifoSem -struct ShutdownSemError : public std::runtime_error { +struct FOLLY_EXPORT ShutdownSemError : public std::runtime_error { explicit ShutdownSemError(const std::string& msg); ~ShutdownSemError() noexcept override; }; -- 2.34.1