1. 30 Dec, 2016 3 commits
    • Zbigniew Szymanski's avatar
      Move internal `decodeUtf8` method from json.cpp to public util Unicode.h · 67f7bb72
      Zbigniew Szymanski authored
      Summary:
      Moved decodeUtf8 -> folly::utf8ToCodePoint.
      Implementation was not changed to make sure no bugs are introduced.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4372739
      
      fbshipit-source-id: a015a9c47ece825e09e7c243fae454f21f99db80
      67f7bb72
    • Yedidya Feldblum's avatar
      Let Future::then call callbacks outside of the catch handler · 1d36d464
      Yedidya Feldblum authored
      Summary:
      [Folly] Let `Future::then` call callbacks outside of the catch handler.
      
      And `Future::onError`.
      
      This makes the behavior of calls to `Future` callbacks with respect to currently-handled ("active") exceptions consistent - there will not be an active exception by the time the `Future` callback is called. (Unless `Future::then` or `Future::onError`, etc., is itself called with an active exception. Or unless the `Promise` is fulfilled, outside of the `Future` implementation code, with an active exception.)
      
      This will affect any code which tries to call `std::current_exception()` or `throw;` from within a `Future` callback, such as an `onError` handler. That code will crash. (It was incorrect anyway, and relied on misusing Folly Futures.)
      
      Reviewed By: ericniebler
      
      Differential Revision: D4372173
      
      fbshipit-source-id: 600b22e4db63c98358de29a6abcee807fbc53b0f
      1d36d464
    • Yedidya Feldblum's avatar
      Const-correctness for folly::exception_wrapper::with_exception with non-std::exception · 686092cb
      Yedidya Feldblum authored
      Summary:
      [Folly] Const-correctness for `folly::exception_wrapper::with_exception` with non-`std::exception`.
      
      This also lets us unify the various flavors of `with_exception` and `is_compatible_with`. And fix `is_compatible_with` for non-`exception` types.
      
      Reviewed By: ericniebler
      
      Differential Revision: D4364474
      
      fbshipit-source-id: 417edfd45f7cfba952ce961559da67769b7c41bc
      686092cb
  2. 29 Dec, 2016 7 commits
    • Eric Niebler's avatar
      folly::TryException inherits from std::logic_error, like... · 06649f43
      Eric Niebler authored
      folly::TryException inherits from std::logic_error, like std::bad_optional_access; becomes no-throw copyable
      
      Summary:
      folly::TryException was inheriting from std::exception and managing its own message in a std::string data member.
      That is suboptimal for the following reasons:
      
      1) The analagous std:: type, std::bad_optional_access, inherits from std::logic_error. According to the Principle of Least
         Astonishment, folly::TryException should follow suit.
      2) std::logic_error has a nothrow copy constructor. (This is typically implemented with a ref-counted string.)
         std::string does not. By explicitly managing its own message, folly::TryException picks up a throwing copy
         constructor. Exception classes should try to be nothrow copyable.
      3) With most stdlib implementations, std::string is larger by a lot than the std:: exceptions. By changing
         folly::TryException as suggested, its size drops from 40 bytes to 16 on clang and gcc >=5.0.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4368760
      
      fbshipit-source-id: 327f78f428419ccf9c7af3e0f57cc478d147fb37
      06649f43
    • Eric Niebler's avatar
      folly::FutureException inherits from std::logic_error, like std::future_error;... · 42ba1a22
      Eric Niebler authored
      folly::FutureException inherits from std::logic_error, like std::future_error; becomes smaller and nothrow-copy
      
      Summary:
      folly::FutureException was inheriting from std::exception and managing its own message in a std::string data member.
      That is suboptimal for the following reasons:
      
      1) The analagous std:: type, std::future_error, inherits from std::logic_error. According to the Principle of Least
         Astonishment, folly::FutureExpception should follow suit.
      2) std::logic_error has a nothrow copy constructor. (This is typically implemented with a ref-counted string.)
         std::string does not. By explicitly managing its own message, folly::FutureException picks up a throwing copy
         constructor. Exception classes should try to be nothrow copyable.
      3) With most stdlib implementations, std::string is larger by a lot than the std:: exceptions. By changing
         folly::FutureException as suggested, its size drops from 40 bytes to 16 on clang and gcc >=5.0.
      
      Also, I took the liberty of fixing some copy-pastas that gave some of these exception types explicit default
      constructors.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4367909
      
      fbshipit-source-id: 1639d404237493f929db6116a760c2d0e599877d
      42ba1a22
    • Bi Xue's avatar
      Make FunctionRef support bool operator · 42f55fa5
      Bi Xue authored
      Summary:
      To support following code:
      ```
      void foo(folly::FunctionRef<void(void)> callback = {}) {
        if (callback) {
          callback();
        }
      }
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4372296
      
      fbshipit-source-id: 7d21e6a44b6f6b046b424f0139465511dbae7b8b
      42f55fa5
    • Giuseppe Ottaviano's avatar
      Avoid shadowing warnings in SYNCHRONIZED · e910dd4b
      Giuseppe Ottaviano authored
      Summary: If two `SYNCHRONIZED` blocks are nested the internal `SYNCHRONIZED_*` variables can be compatible shadows (`SYNCHRONIZED_state` always is), so GCC will issue a warning with `-Wshadow-compatible-local`. This diff disambiguates the variable names for each `SYNCHRONIZED` block (as long as they appear on different lines).
      
      Reviewed By: yfeldblum, philippv
      
      Differential Revision: D4371263
      
      fbshipit-source-id: b467a1a2651667c679382a1cc1eaa28f7ee4e6b3
      e910dd4b
    • Anirudh Ramachandran's avatar
      Add OpenSSL portability layer · 87659d07
      Anirudh Ramachandran authored
      Summary:
      Enable folly to build with OpenSSL alternatives (e.g., BoringSSL).
      
      Some SSL-related tests are disabled:
      
       - Async session cache ones (BoringSSL has an async cache impl but with a different API)
       - TFO tests
       - Some changes to error tests which expect specific error strings. This is
         flaky as a test because it will break everytime even within a version, so we
         should fix that first.
      
      This should be a noop for OpenSSL 1.0.2.
      
      BoringSSL commit used is 35c8afd3143289c99aa3820e01950c564d7aced8 (10/26/2016)
      
      Closes: https://github.com/facebook/folly/issues/198
      
      Reviewed By: siyengar
      
      Differential Revision: D3280382
      
      fbshipit-source-id: 4141d992e0d8dd797ac4af479cfe90844a23278f
      87659d07
    • Yedidya Feldblum's avatar
      folly::copy · ec5f59cf
      Yedidya Feldblum authored
      Summary:
      [Folly] `folly::copy`.
      
      Usable when you have a function with two overloads:
      
          class MyData;
          void something(MyData&&);
          void something(const MyData&);
      
      Where the purpose is to make copies and moves explicit without having to spell out the full type names - in this case, for copies, to invoke copy constructors.
      
      When the caller wants to pass a copy of an lvalue, the caller may:
      
          void foo() {
            MyData data;
            something(folly::copy(data)); // explicit copy
            something(std::move(data)); // explicit move
            something(data); // const& - neither move nor copy
          }
      
      Reviewed By: markisaa, ericniebler
      
      Differential Revision: D3462023
      
      fbshipit-source-id: 6c777be288f2a7012c1b4b46dc988890b8662595
      ec5f59cf
    • Philip Pronin's avatar
      nuke UNSYNCHRONIZED · 1c3b25b2
      Philip Pronin authored
      Summary:
      API of `UNSYNCHRONIZED` is confusing as if you have two nested
      `SYNCHRONIZED` blocks, `UNSYNCHRONIZED` always unlocks the inner-most,
      even if you pass in the variable name used in the outer `SYNCHRONIZED`
      block.
      
      The macro was marked as "deprecated" in D3526489, remove it here.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4371297
      
      fbshipit-source-id: 13ddc1ff77cb3d5045844c5ade0e95dbe2bccf6d
      1c3b25b2
  3. 28 Dec, 2016 1 commit
    • Yedidya Feldblum's avatar
      A smaller implementation of try_and_catch · f4dd104c
      Yedidya Feldblum authored
      Summary:
      [Folly] A smaller implementation of `try_and_catch`.
      
      No longer done as a derived class. This lets us make the protected members of `exception_wrapper` into private members.
      
      Reviewed By: ericniebler
      
      Differential Revision: D4366065
      
      fbshipit-source-id: ae4763b55e431ac08260f74f6a23a257581247c9
      f4dd104c
  4. 27 Dec, 2016 3 commits
    • Adrian Hamza's avatar
      Make UncaughtExceptionCounter public · 1e039743
      Adrian Hamza authored
      Summary: Make UncaughtExceptionCounter public by moving it from folly/detail to folly. I am adding a scope performance counter that works in a similar way to SCOPE_EXIT/SCOPE_ERROR and I need the UncaughtExceptionCounter functionality.
      
      Reviewed By: yfeldblum, ericniebler
      
      Differential Revision: D4342783
      
      fbshipit-source-id: a1848e89cbb6340e2ac48adabf7bf76cece1b86d
      1e039743
    • Eric Niebler's avatar
      Add proper Doxygen comment markings around exception_wrapper example. · 8f0aa1f8
      Eric Niebler authored
      Summary: The Doxegen-generated documentation for exception_wrapper is unreadable. The code needs to be denoted with \code...\endcode tags; otherwise, it is formatted like a paragraph and newlines are ignored.
      
      Reviewed By: igorsugak
      
      Differential Revision: D4367636
      
      fbshipit-source-id: 680bedfb152300d8a6287bf441dd9b81b9b94c80
      8f0aa1f8
    • Christopher Small's avatar
      pass RNG by reference so state is updated on each call · f2987ecd
      Christopher Small authored
      Summary: folly::Random was taking the RNG by value (not reference) so it was not updating the RNG's state on each invocation -- so the RNG would not advance to the next value in the sequence.
      
      Reviewed By: yfeldblum, nbronson
      
      Differential Revision: D4362999
      
      fbshipit-source-id: f93fc11911b92e230ac0cc2406151474d15f85af
      f2987ecd
  5. 25 Dec, 2016 1 commit
    • Sven Over's avatar
      fix include dependencies in folly/stats · d9817812
      Sven Over authored
      Summary:
      Histogram-defs.h depends on Histogram.h, so it should include it.
      
      This missing dependency is especially annoying because users who
      include both Histogram.h and Histogram-defs.h will find that
      clang-format reorders the includes such that Histogram-defs.h will
      be included before Histogram.h, which breaks the build.
      
      Same for BucketedTimeSeries-defs.h and TimeseriesHistogram-defs.h.
      
      Reviewed By: pixelb
      
      Differential Revision: D4366282
      
      fbshipit-source-id: 518ef315154c28beb091e5c097db2bec6eea3ba0
      d9817812
  6. 24 Dec, 2016 1 commit
  7. 23 Dec, 2016 2 commits
    • Christopher Dykes's avatar
      Use std::chrono for timeouts to sslAccept and sslConn in AsyncSSLSocket · 3caa3408
      Christopher Dykes authored
      Summary: Because `std::chrono` makes it clear exactly what unit of time is in use.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4363560
      
      fbshipit-source-id: 47aeef21f842f39d8e886bec441897ecf1f3761b
      3caa3408
    • Jacob Bower's avatar
      Enable making libfollyinit even when libdwarf is not available · ecd7292d
      Jacob Bower authored
      Summary:
      The hard requirement for libdwarf when building libfollyinit does not appear to be needed.
      
      Without libfollyinit, code with calls to folly::init() won't build. Notably this is breaking build/execution of tests + examples for the Watchman C++ client in Watchman.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4361498
      
      fbshipit-source-id: f3586d8cdca36eda3634663e95a4a61d879de6cf
      ecd7292d
  8. 22 Dec, 2016 8 commits
    • Yedidya Feldblum's avatar
      Move Thrower into exception_wrapper · 6e0964d9
      Yedidya Feldblum authored
      Summary:
      [Folly] Move `Thrower` into `exception_wrapper`.
      
      It is only used by `exception_wrapper`, so it might as well be a member type.
      
      Also, make it private. That means we need to tweak `try_and_catch`.
      
      Since we are tweaking `try_and_catch`, tweak all similar cases.
      
      Reviewed By: luciang
      
      Differential Revision: D4361815
      
      fbshipit-source-id: c5025894465a2c7760bd79dbbd272079fd34dd79
      6e0964d9
    • Yedidya Feldblum's avatar
      Move the guts of try_and_catch into a detail namespace · c60d131b
      Yedidya Feldblum authored
      Summary:
      [Folly] Move the guts of `try_and_catch` into a `detail` namespace.
      
      Just a bit cleaner this way. Also, now we always slice before returning the derived object, so the derived type never escapes.
      
      Reviewed By: luciang
      
      Differential Revision: D4361471
      
      fbshipit-source-id: 5c9567d3c5480ee9943a85139b8f27ba3b9da2d6
      c60d131b
    • Jason Leng's avatar
      Update future interrupts example in README · 8d510416
      Jason Leng authored
      Summary: Updated the future interrupts example to get rid of the shared pointer circular reference problem
      
      Reviewed By: djwatson
      
      Differential Revision: D4360037
      
      fbshipit-source-id: cb959929a508df4dcf3b81d01012bc55044a0b17
      8d510416
    • Jacob Bower's avatar
      Make folly pkg-config more usable on OS X · 6536cf29
      Jacob Bower authored
      Summary:
      As part of open-sourcing the Watchman C++ client I'm adding an (optional) dependency in Watchman to Folly. When I tried to build this client with Folly on OS X I ran into some problems using the libfolly pkg-config file. This diff addresses these issues:
      
      1. When using `build/bootstrap-osx-homebrew.sh`, the compile config for gflags and OpenSSL are overriden. If present, these custom flags will now be propagated to `libfolly.pc`.
      2. I changed the the package requirements in `libfolly.pc` from `Requires.private` to just `Requires`.
      
      Both of these changes are needed as much of Folly's implementation is in header files. As such, consumers of libfolly need to use the same library/include paths when building.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4332720
      
      fbshipit-source-id: 6a051ae318ac10bdeb4dc383a16de81f1c0327bb
      6536cf29
    • Yedidya Feldblum's avatar
      to_weak_ptr · ed6a4850
      Yedidya Feldblum authored
      Summary:
      [Folly] `to_weak_ptr`.
      
      Make a `weak_ptr` and return it from a `shared_ptr` without specifying the template type parameter and letting the compiler deduce it.
      
      So you can write this:
      
          auto wptr = to_weak_ptr(getSomethingShared<T>());
      
      Instead of this:
      
          auto wptr = weak_ptr<T>(getSomethingShared<T>());
      
      Useful when `T` is long, such as:
      
          using T = foobar::FooBarAsyncClient;
      
      Reviewed By: nbronson
      
      Differential Revision: D4361276
      
      fbshipit-source-id: 782a1d2d57b6e5823cb4018e445110098f1ce41f
      ed6a4850
    • Christopher Dykes's avatar
      Support fchmod and include the correct portability headers for FileUtil · df148cba
      Christopher Dykes authored
      Summary: `FileUtil.cpp` uses `fchmod`, which Windows doesn't have, so implement it and also include the correct portability headers for the use of `mkstemp` and now `fchmod` as well.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4360650
      
      fbshipit-source-id: 300163689c54574548e7bf274a56264714d216ed
      df148cba
    • Yedidya Feldblum's avatar
      Add missing includes in folly/experimental/observer · 2c45faef
      Yedidya Feldblum authored
      Summary:
      [Folly] Add missing includes in `folly/experimental/observer`.
      
      In particular, the missing includes of `folly/ExceptionString.h`.
      
      Motivation.
      
      Reviewed By: andrewjcg, nbronson
      
      Differential Revision: D4360991
      
      fbshipit-source-id: 4e4407669926b55d6d85df08edea70784a8f348c
      2c45faef
    • Amir Shalem's avatar
      FBString: remove unnecessary 7-byte padding in large strings · d83fd99b
      Amir Shalem authored
      Summary:
      RefCounted struct contains a pointer to `Char data_[1]`
      This saved us a +1 when calculating sizes for the null terminator,
      but the compiler made the struct size to be 16, instead of a 8+1.
      
      Reviewed By: Gownta, ot
      
      Differential Revision: D4356429
      
      fbshipit-source-id: 420694feb4b367b0c73d44f83c21a9559ac5e7a3
      d83fd99b
  9. 21 Dec, 2016 2 commits
  10. 20 Dec, 2016 5 commits
    • Eric Niebler's avatar
      use folly::FunctionRef for EventBase::run(ImmediatelyOrRun)?InEventBaseThreadAndWait · 054b2c1a
      Eric Niebler authored
      Summary: folly::FunctionRef never allocates memory and is cheaper to pass around. Use it in the interface of EventBase where we can.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4353992
      
      fbshipit-source-id: 259c5214ed48d30981eb8e38b062aad31d80a080
      054b2c1a
    • Michael Lee's avatar
      Fix sysconf return type · 219f48ef
      Michael Lee authored
      Summary: The sysconf return type is supposed to be long, not unsigned.
      
      Reviewed By: Orvid
      
      Differential Revision: D4350903
      
      fbshipit-source-id: 29d86081bf75d123e76b831a669b0fd3936ce102
      219f48ef
    • Christopher Dykes's avatar
      Enable -Wunreachable-code · ce7d3124
      Christopher Dykes authored
      Summary:
      Because it finds dead code.
      This also removes the dead code found.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4342893
      
      fbshipit-source-id: e500734ff5927320b2356106d10016e298d67393
      ce7d3124
    • Misty De Meo's avatar
      Fix search name for gflags's .pc file · 8d7ec4c6
      Misty De Meo authored
      Summary:
      gflags's pkg-config file is installed by default under the name gflags.pc; however, folly has been searching for it under the name libgflags.pc.
      
      Several package managers (Homebrew, apt) install the .pc file under its default upstream name; as such it seems appropriate for folly to look for it under that name, too.
      
      refs Homebrew/homebrew-core#7977.
      Closes https://github.com/facebook/folly/pull/531
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4348089
      
      Pulled By: Orvid
      
      fbshipit-source-id: 6adec290ec88b5d3f66103cf8e5094e99f2512ad
      8d7ec4c6
    • Guobao Sun's avatar
      Fix library name for thread_local_test in open source builds · 0a0da529
      Guobao Sun authored
      Summary: Test case ThreadLocal.SharedLibrary is failing due to looking for "thread_local_test_lib.so", while the actual .so generated is "lib_thread_local_test.so". Change Makefile.am to conform it.
      
      Reviewed By: Orvid
      
      Differential Revision: D4350758
      
      fbshipit-source-id: 9a2a23325059ed71529821620398ffa6ed84f83e
      0a0da529
  11. 19 Dec, 2016 3 commits
  12. 18 Dec, 2016 1 commit
    • Mathieu Baudet's avatar
      fbcode: remove unused includes from .cpp files with no #if and #define · d0856c87
      Mathieu Baudet authored
      Summary:
      This is a first diff to remove the "easiest" unused includes in fbcode.
      
      * For safety, we only touch .cpp files without #if and #define,
      * We do not try to remove redundant systems headers (aka. "packing").
      
      The diff was generated as follows:
      ```
      foundation/scripts/ls-cpp-dirs | grep -v '^\(\.\.\|external/\|.*/external\)' | xargs ffmr -o /tmp/ffmr-diff-1 codegraph/scripts/ffmr/analyze_includes_no_headers_no_packing_skipping_ifdefs.sh
      
      cat /tmp/ffmr-diff-1/*.diff | patch -p2
      hg commit -m something
      arc diff --prepare --nolint --nounit --less-context --excuse refactoring
      ```
      
      Note: `grep -v` is just an optimization. The actual configuration is in these two files:
      diffusion/FBS/browse/master/fbcode/codegraph/analysis/config.py
      diffusion/FBS/browse/master/fbcode/codegraph/scripts/ffmr/analyze_includes_no_headers_no_packing_skipping_ifdefs.sh
      
      See the task for more context, and the recent "safety" improvements on the tool.
      
      depends on D4317825 for very few cases where `nolint` had to be manually added.
      
      Reviewed By: igorsugak
      
      Differential Revision: D4312617
      
      fbshipit-source-id: ecc1f0addfd0651fa4770fcc43cd1314661a311a
      d0856c87
  13. 17 Dec, 2016 2 commits
    • Yedidya Feldblum's avatar
      Let ScopedEventBaseThread destruct the EventBase in the IO thread · 45d349f0
      Yedidya Feldblum authored
      Summary: [Folly] Let `ScopedEventBaseThread` destruct the `EventBase` in the IO thread.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D4330951
      
      fbshipit-source-id: 5b0e7071800e1d49048b08aa1233d72b820fe55d
      45d349f0
    • Yedidya Feldblum's avatar
      Split EventBaseThread from ScopedEventBaseThread · e5cb9b3d
      Yedidya Feldblum authored
      Summary:
      [Folly] Split `EventBaseThread` from `ScopedEventBaseThread`.
      
      Now `ScopedEventBaseThread` is really scoped and immovable, while `EventBaseThread` is movable and can be started and stopped.
      
      Users which will never move, and will never start or stop, the `ScopedEventBaseThread` can continue using it. Users which need to move, or which need to start and stop, the object will use `EventBaseThread` instead.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D4338447
      
      fbshipit-source-id: 57c186630bc199a7a7b7223b1fcb077ce3d86743
      e5cb9b3d
  14. 16 Dec, 2016 1 commit