Fix libc++ build errors
authorTudor Bosman <tudorb@fb.com>
Sat, 5 Jul 2014 15:50:38 +0000 (08:50 -0700)
committerTudor Bosman <tudorb@fb.com>
Wed, 9 Jul 2014 20:52:07 +0000 (13:52 -0700)
Summary:
Reported externally:

https://github.com/facebook/folly/issues/70
https://github.com/facebook/folly/issues/71
https://github.com/facebook/folly/issues/72
https://github.com/facebook/folly/issues/73

Note that I can't test on libc++ myself, but the reports suggested fixes which
sounded good.

Test Plan: fbconfig -r folly && fbmake runtests_opt

Reviewed By: marcelo.juchem@fb.com

Subscribers: jhj, ntv, lesha, kma, fugalh, jdelong

FB internal diff: D1421029

folly/Malloc.cpp
folly/Malloc.h
folly/Portability.h
folly/Random-inl.h
folly/wangle/Executor.h

index fe8d8b6a421635193f13cad56a5d33bf6df13003..d81c30d23119ed26637c6f6e1d586b8b321c622f 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <folly/Malloc.h>
 
+#include <cstdint>
+
 namespace folly {
 
 // How do we determine that we're using jemalloc?
index b8ee18c58a83a7a8a96b2dd3310369340e10c9e4..59745b5fd0c47615a72a6739f40000697c59b864 100644 (file)
@@ -29,6 +29,7 @@
 #include <folly/detail/Malloc.h>
 
 #include <string>
+
 namespace folly {
   using std::goodMallocSize;
   using std::jemallocMinInPlaceExpandable;
index 9c65c650c14f2b68496028ffedbc13d185902e3d..61b9eb22ff30234b47d969fffddf01ad6e6409b7 100644 (file)
@@ -173,6 +173,7 @@ struct MaxAlign { char c; } __attribute__((aligned));
 // the 'std' namespace; the latter uses inline namepsaces. Wrap this decision
 // up in a macro to make forward-declarations easier.
 #if FOLLY_USE_LIBCPP
+#include <__config>
 #define FOLLY_NAMESPACE_STD_BEGIN     _LIBCPP_BEGIN_NAMESPACE_STD
 #define FOLLY_NAMESPACE_STD_END       _LIBCPP_END_NAMESPACE_STD
 #else
index 9da9a824bfe011abf1919255543e45c78daeeaa2..f18a0b5118db89d1fbcd6b36da1b88601e680057 100644 (file)
@@ -105,23 +105,28 @@ constexpr size_t
 StateSize<std::subtract_with_carry_engine<UIntType, w, s, r>>::value;
 
 template <class RNG>
-std::seed_seq generateSeed() {
-  std::array<uint32_t, StateSize<RNG>::value> seed_data;
-  Random::secureRandom(seed_data.begin(), seed_data.size() * sizeof(uint32_t));
-  return std::seed_seq(std::begin(seed_data), std::end(seed_data));
-}
+struct SeedData {
+  SeedData() {
+    Random::secureRandom(seedData.begin(), seedData.size() * sizeof(uint32_t));
+  }
+
+  static constexpr size_t stateSize = StateSize<RNG>::value;
+  std::array<uint32_t, stateSize> seedData;
+};
 
 }  // namespace detail
 
 template <class RNG>
 void Random::seed(ValidRNG<RNG>& rng) {
-  auto s = detail::generateSeed<RNG>();
+  detail::SeedData<RNG> sd;
+  std::seed_seq s(std::begin(sd.seedData), std::end(sd.seedData));
   rng.seed(s);
 }
 
 template <class RNG>
 auto Random::create() -> ValidRNG<RNG> {
-  auto s = detail::generateSeed<RNG>();
+  detail::SeedData<RNG> sd;
+  std::seed_seq s(std::begin(sd.seedData), std::end(sd.seedData));
   return RNG(s);
 }
 
index a248c28e19591ce5ebf65f9b303c28a582bfe66e..00a52b17b537445e0194439faa4a28e42803c702 100644 (file)
@@ -20,6 +20,7 @@
 #include <chrono>
 #include <functional>
 #include <memory>
+#include <stdexcept>
 
 namespace folly { namespace wangle {
   /// An Executor accepts units of work with add(), which should be