1. 13 Oct, 2016 3 commits
  2. 12 Oct, 2016 7 commits
    • Zonr Chang's avatar
      Access SSL cipher info with a const reference. · cef27cd0
      Zonr Chang authored
      Summary:
      BoringSSL returns `const SSL_CIPHER*` from sk_SSL_CIPHER_value().
      Closes https://github.com/facebook/folly/pull/492
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4009712
      
      Pulled By: Orvid
      
      fbshipit-source-id: cca2e8cb6aab0a459dca55b8f23ef57fa5c8251f
      cef27cd0
    • Zonr Chang's avatar
      Fix call to SSL_SESSION_up_ref(). · b6dfac67
      Zonr Chang authored
      Summary:
      `SSL_SESSION_up_ref()` in both BoringSSL and OpenSSL 1.1.0 takes a
      `SSL_SESSION*`.
      Closes https://github.com/facebook/folly/pull/493
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4009706
      
      Pulled By: Orvid
      
      fbshipit-source-id: 68ea201821e7a6d5835a79b34187344ba251e239
      b6dfac67
    • Philip Pronin's avatar
      ZSTDCodec should properly handle non-shortcut levels · 339ce0bf
      Philip Pronin authored
      Summary:
      Currently only shortcut levels are properly handled, others result in
      using level 1.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4008123
      
      fbshipit-source-id: 37845eeec139007738f99e72ecfb969c6a2e5652
      339ce0bf
    • Phil Willoughby's avatar
      Print why we called std::terminate · fec7b1bc
      Phil Willoughby authored
      Summary:
      When terminating because we were told to rethrow a nonexistent exception, we
      now print that to `std::cerr` for the benefit of users on platforms which do not dump a stack trace on
      `std::terminate`
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4001087
      
      fbshipit-source-id: 5b834cfc75bf42bec06a49ac9db55789a83df180
      fec7b1bc
    • Giuseppe Ottaviano's avatar
      Add support in enumerate() for iterators with exotic pointers · 1d2f2dcf
      Giuseppe Ottaviano authored
      Summary: I thought we wouldn't need this but it turns out Thrift Frozen2 iterators return proxies (it's proxies all the way down). Thanks to ericniebler for trick.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4005700
      
      fbshipit-source-id: 1911996afa075c1d819a3aaea2ee924bc2ae2f20
      1d2f2dcf
    • Christopher Dykes's avatar
      Fix build on Mac OSX Sierra · a34e06a1
      Christopher Dykes authored
      Summary:
      There are two changes here.
      The first is to eliminate `detail::DEFAULT_CLOCK_ID` from `Benchmark.[cpp|h]` as Sierra defines `clockid_t` as an enum type, which means that calling `clock_gettime(detail::DEFAULT_CLOCK_ID` would fail, because the enums are incompatible. As this was being used as a default, but is not actually changable anywhere, I just got rid of `detail::DEFAULT_CLOCK_ID` entirely.
      The second is to move `portability/BitsFunctexcept.cpp` into `libfollybase_la_SOURCES`, because it's needed for generating the fingerprint tables.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4004843
      
      fbshipit-source-id: b2a9c33f8e516d8eb3cdc5ab093f4946ac9ed37e
      a34e06a1
    • Lucian Grijincu's avatar
      folly: signal-handler: dynamic cache size, based on number of dynamic-loaded ELF files · 74ea0a31
      Lucian Grijincu authored
      Summary:
      I added kFatalSignalHandlerCacheSize in {D3984649}, and chose a big
      number to satisfy most use-cases. But the size increase is non-trivial.
      
      Memory usage:
      
      - before: 5.1 MB in folly::symbolizer::SignalSafeElfCache::SignalSafeElfCache
      - after: 80.0 MB in folly::symbolizer::SignalSafeElfCache::SignalSafeElfCache
      
      Switch to a dynamic approach and everyone pays for what they use.
      
      https://github.com/bminor/glibc/blob/ee19f1de0d0da24114be554fdf94243c0ec6b86c/elf/rtld-debugger-interface.txt#L10-L20
      ```
      The r_debug structure contains (amongst others) the following fields:
      
        struct link_map *r_map:
          A linked list of loaded objects.
      
        enum { RT_CONSISTENT, RT_ADD, RT_DELETE } r_state:
          The current state of the r_map list.  RT_CONSISTENT means that r_map
          is not currently being modified and may safely be inspected.  RT_ADD
          means that an object is being added to r_map, and that the list is
          not guaranteed to be consistent.  Likewise RT_DELETE means that an
          object is being removed from the list.
      ```
      
      https://github.com/bminor/glibc/blob/ee19f1de0d0da24114be554fdf94243c0ec6b86c/elf/rtld.c#L303-L307
      ```
        /* Call the OS-dependent function to set up life so we can do things like
           file access.  It will call `dl_main' (below) to do all the real work
           of the dynamic linker, and then unwind our frame and run the user
           entry point on the same stack we entered on.  */
        start_addr = _dl_sysdep_start (arg, &dl_main);
      ```
      
      dl_main: https://github.com/bminor/glibc/blob/ee19f1de0d0da24114be554fdf94243c0ec6b86c/elf/rtld.c#L1192-L1199
      ```
        /* Initialize the data structures for the search paths for shared
           objects.  */
        _dl_init_paths (library_path);
      
        /* Initialize _r_debug.  */
        struct r_debug *r = _dl_debug_initialize (GL(dl_rtld_map).l_addr,
      					    LM_ID_BASE);
        r->r_state = RT_CONSISTENT;
      ...
      
        /* We start adding objects.  */
        r->r_state = RT_ADD;
        _dl_debug_state ();
        LIBC_PROBE (init_start, 2, LM_ID_BASE, r);
      
      ...
      
        /* Notify the debugger all new objects are now ready to go.  We must re-get
           the address since by now the variable might be in another object.  */
        r = _dl_debug_initialize (0, LM_ID_BASE);
        r->r_state = RT_CONSISTENT;
        _dl_debug_state ();
        LIBC_PROBE (init_complete, 2, LM_ID_BASE, r);
      
      ```
      
      Reviewed By: bixue2010
      
      Differential Revision: D3996974
      
      fbshipit-source-id: e24d72e3cc0339e4cf1acdd2f4c9a7ebfcfdf739
      74ea0a31
  3. 11 Oct, 2016 3 commits
    • Jim Meyering's avatar
      folly/ConcurrentSkipList.h: avoid shadowing warnings (trivial) · 70b158bb
      Jim Meyering authored
      Summary:
      Compiling with gcc's proposed -Wshadow-compatible-local option
      exposed some fix-worthy warnings. Rename to avoid the shadowing.
      
      Reviewed By: evilmucedin
      
      Differential Revision: D3999026
      
      fbshipit-source-id: 26cb3033ba8c5538cc9217993f2fda6aef954a8f
      70b158bb
    • Shubhanshu Agrawal's avatar
      BatchDispatcher add() interface · fb77b407
      Shubhanshu Agrawal authored
      Summary: converting add(value&&) to add(value) to make it easier for callsites to use.
      
      Reviewed By: A5he
      
      Differential Revision: D4000416
      
      fbshipit-source-id: c66f4d93d1223286bbc786d17f65ed02a63cc794
      fb77b407
    • Louis Boval's avatar
      Disabling failing test for fbandroid · 40e6161e
      Louis Boval authored
      Summary: this particular test fails reliably for fbandroid. Modifying the code in fbcode, assuming it will be synced promptly.
      
      Reviewed By: edelron
      
      Differential Revision: D4000722
      
      fbshipit-source-id: fca5e691ea5c972ddd245acee1c17720730539d4
      40e6161e
  4. 10 Oct, 2016 3 commits
    • Nicholas Ormrod's avatar
      Remove memcpy-UB in fbstring · 7c2ef80c
      Nicholas Ormrod authored
      Summary:
      The bug report in t13764686 shows that `folly::StringPiece().str()` causes undefined behavior by passing nullptr into memcpy: the default-initialized StringPiece has two null pointers, which will call `string(char*, size)` with nullptr and 0. This gets forwarded to `podCopy` in fbstring, which calls memcpy and has undefined behavior.
      
      The call pattern `string(nullptr, 0)` is not illegal (note: that syntax is ambiguous, as the literal `0` can be converted to a pointer). Prevent this legal call pattern from causing undefined behavior in fbstring.
      
      This diff puts asserts in podCopy to catch errors, and ensures that current podCopy callsites ensure that the pointer is non-null.
      
      Most podCopy callsites do not need to guarded, since the size is guaranteed to be greater than 0 (which will hard crash instead). The interesting callsite is in `initMedium`, because there is a mode (disableSSO) which will allocate empty strings on the heap, so we need to add a guard there.
      
      Reviewed By: luciang
      
      Differential Revision: D3996440
      
      fbshipit-source-id: b311a311973d1d969542245c72035c5b38da58e3
      7c2ef80c
    • Maged Michael's avatar
      Update hazard pointers prototype · 328c1a56
      Maged Michael authored
      Summary:
      Interface:
      - Got rid of std::function reclamation functions and added a Deleter template parameter.
      - Got rid of the flush() member functions of hazptr_domain
      - Added a lock-free non-bool member function to get a protected pointer.
      Implementation:
      - Implemented the interface changes.
      - Changed the order of accesses in reading the shared list of objects vs reading the hazard pointers. I think the previous order would have allowed recently protected objects to be reclaimed incorrectly.
      Updated the examples and tests accordingly.
      
      Reviewed By: davidtgoldblatt
      
      Differential Revision: D3981284
      
      fbshipit-source-id: 35ff60da3aea1f67c58d82437dda58f6d8b07bf5
      328c1a56
    • Phil Willoughby's avatar
      Make exception_wrapper::throwException() strict · a62c9841
      Phil Willoughby authored
      Summary:
      The definition of `throwException()` is changed to add the `[[noreturn]]`
      attribute for consistency with `std::rethrow_exception`. If the
      `exception_wrapper` contains an exception, that is rethrown; if not, then
      `std::terminate` is called.
      
      An alternative design which threw an exception if the `exception_wrapper` did not contain an exception was rejected because of the ambiguity it introduced as to whether the exception thrown was wrapped or not.
      
      Benchmarks before:
      
      ```
      
      ============================================================================
      folly/test/ExceptionWrapperBenchmark.cpp        relative  time/iter  iters/s
      ============================================================================
      exception_ptr_create_and_test                                1.45us  689.01K
      exception_wrapper_create_and_test               4337.80%    33.46ns   29.89M
      ----------------------------------------------------------------------------
      exception_ptr_create_and_test_concurrent                   342.99us    2.92K
      exception_wrapper_create_and_test_concurrent     101.41%   338.21us    2.96K
      ----------------------------------------------------------------------------
      exception_ptr_create_and_throw                               3.05us  327.89K
      exception_wrapper_create_and_throw               140.22%     2.17us  459.77K
      exception_wrapper_create_and_cast               8956.80%    34.05ns   29.37M
      ----------------------------------------------------------------------------
      exception_ptr_create_and_throw_concurrent                  372.68us    2.68K
      exception_wrapper_create_and_throw_concurrent    102.54%   363.44us    2.75K
      exception_wrapper_create_and_cast_concurrent     110.93%   335.97us    2.98K
      ============================================================================
      ```
      
      and after:
      
      ```
      
      ============================================================================
      folly/test/ExceptionWrapperBenchmark.cpp        relative  time/iter  iters/s
      ============================================================================
      exception_ptr_create_and_test                                1.46us  684.09K
      exception_wrapper_create_and_test               4368.84%    33.46ns   29.89M
      ----------------------------------------------------------------------------
      exception_ptr_create_and_test_concurrent                   341.20us    2.93K
      exception_wrapper_create_and_test_concurrent      99.88%   341.60us    2.93K
      ----------------------------------------------------------------------------
      exception_ptr_create_and_throw                               3.08us  324.93K
      exception_wrapper_create_and_throw               106.93%     2.88us  347.46K
      exception_wrapper_create_and_cast               9532.05%    32.29ns   30.97M
      ----------------------------------------------------------------------------
      exception_ptr_create_and_throw_concurrent                  363.73us    2.75K
      exception_wrapper_create_and_throw_concurrent    101.04%   360.00us    2.78K
      exception_wrapper_create_and_cast_concurrent     104.50%   348.07us    2.87K
      ============================================================================
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3923939
      
      fbshipit-source-id: 6fc58ac571e59e4122f1fbd194c678e3a3841057
      a62c9841
  5. 09 Oct, 2016 1 commit
    • Jim Meyering's avatar
      folly/Foreach.h: allow FOR_EACH to be nested with no shadowing · ba22e52f
      Jim Meyering authored
      Summary:
      Prior to this change, any nested use of FOR_EACH would
      induce a shadowed declaration for each of the two local
      state variables it declares.
      
      This makes the names of those variables __LINE__-dependent,
      so that there is no shadowing, as long as each nested use
      is on a different line.
      
      This also adds a new test that (prior to this change) would fail to
      compile with an option like -Werror=shadow-compatible-local.
      
      Since this change relies on cpp token concatenation, I have included
      The fix defines a new helper macro, _FE_ANON, to derive each new variable
      name. I wondered whether to do this for every other FOR_* macro here, but
      since so far, I have encountered more than 10 cases of nested FOR_EACH
      uses in a large corpus, but no nesting of any other FOR_* macro, I am
      content to do it only for this one.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3992956
      
      fbshipit-source-id: f26fba89bc661bb9d22747dec0acdcf8c648fb83
      ba22e52f
  6. 08 Oct, 2016 3 commits
  7. 07 Oct, 2016 3 commits
    • Nicholas Ormrod's avatar
      Disallow COW in FBString · 427c43f4
      Nicholas Ormrod authored
      Summary:
      Remove all code that create large strings.
      
      This diff does not remove code that deals with large strings, so that the transition to libgcc will be smoother. Note that the FBSTRING_ASSERT inside of setCapacity will be disabled in the libgcc build.
      
      Reviewed By: luciang, ot
      
      Differential Revision: D3977459
      
      fbshipit-source-id: 09c1712854b31509138c5cc8baf19caf3c715bb6
      427c43f4
    • Lucian Grijincu's avatar
      folly: symbolizer: increase default signal-handler symbolizer elf file cache... · bde0ad1f
      Lucian Grijincu authored
      folly: symbolizer: increase default signal-handler symbolizer elf file cache size (make it work with large number of .so)
      
      Summary:
      Bump the default size so we can symbolize symbols in dynamically linked
      binaries with lots and lots of shared libraries :)
      
      folly/experimental/symbolizer/ElfCache.h
      ```
        * Will not grow; once the capacity is reached, lookups for files that
        * aren't already in the cache will fail (return nullptr).
        class SignalSafeElfCache
      ```
      
      Reviewed By: ot, philippv
      
      Differential Revision: D3984649
      
      fbshipit-source-id: acdca9b9adf6c16f3a1556bc3f57b28844cdd9cc
      bde0ad1f
    • Mirek Klimos's avatar
      FunctionScheduler - return whether shutdown was successful · 46930a2a
      Mirek Klimos authored
      Summary: We want to fail fast if we attempt to stop a scheduler that was not running
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3976919
      
      fbshipit-source-id: d8aa8b35aa9e22758e6a7ef64f48a7dd6d990b1c
      46930a2a
  8. 06 Oct, 2016 3 commits
    • Alex Yarmula's avatar
      Reverted commit D3979179 · b59ee680
      Alex Yarmula authored
      Summary:
      When `delayed` is called on the Future, the underlying `futures::sleep` call runs on a timer thread, and the resulting callback is called on the same thread. Therefore, in the following sequence:
      
        f.via(&someExecutor).within(one_ms).then([&]() { /* [1] */ })
      
      The code in [1] is not running in someExecutor. This can cause confusion by users of the library who expect the initial `via` to be sticky.
      
      This change returns to the prior `Executor` after `delayed` is finished.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3979179
      
      fbshipit-source-id: e1448f5603f0c9440490ae3bf0e670687f4179f3
      b59ee680
    • Jim Meyering's avatar
      folly/io: avoid shadowing warnings · d359ca68
      Jim Meyering authored
      Summary: Fix shadowing warnings.
      
      Reviewed By: russoue
      
      Differential Revision: D3979165
      
      fbshipit-source-id: 19a3940e210e4d5a698dbc0e6d74b317a74a94fa
      d359ca68
    • Alex Yarmula's avatar
      use previous Executor after delayed · 67fcea20
      Alex Yarmula authored
      Summary:
      When `delayed` is called on the Future, the underlying `futures::sleep` call runs on a timer thread, and the resulting callback is called on the same thread. Therefore, in the following sequence:
      
        f.via(&someExecutor).within(one_ms).then([&]() { /* [1] */ })
      
      The code in [1] is not running in someExecutor. This can cause confusion by users of the library who expect the initial `via` to be sticky.
      
      This change returns to the prior `Executor` after `delayed` is finished.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3979179
      
      fbshipit-source-id: 936ff5626e8ac377ffb15babf573349466984e3a
      67fcea20
  9. 05 Oct, 2016 7 commits
  10. 04 Oct, 2016 6 commits
    • Qinfan Wu's avatar
      Implicit construct sorted_vector_set from std::initializer_list · 06767a9b
      Qinfan Wu authored
      Summary:
      The following thrift file doesn't work:
        typedef set<i32> (cpp.template = "folly::sorted_vector_set") IntSet
        struct Test {
          1: map<i32, IntSet> m = {7: [1, 2]},
        }
      
      The generated file looks like this:
        Test()
            : m(std::initializer_list<
                std::pair<const int32_t, folly::sorted_vector_set<int32_t>>>{
                {7, std::initializer_list<int32_t>{1, 2}}}) {}
      
      Given that `std::set` allows implicit construction from `std::initializer_list`, it's probably okay to make `folly::sorted_vector_set` the same.
      
      Reviewed By: ot
      
      Differential Revision: D3968054
      
      fbshipit-source-id: 978d59a7e545e44d603eeb9671815ac7f2c57342
      06767a9b
    • Jim Meyering's avatar
      folly/io/async/AsyncSocket.cpp: avoid shadowing warning for "rv" · 0e125753
      Jim Meyering authored
      Summary:
      Enabling the proposed-for-upstream gcc -Wshadow-local option exposes this shadowing:
      ```
      folly/io/async/AsyncSocket.cpp: In member function 'virtual void folly::AsyncSocket::connect(folly::AsyncSocket::ConnectCallback*, const folly::SocketAddress&, int, const OptionMap&, const folly::SocketAddress&)':
      folly/io/async/AsyncSocket.cpp:421:11: error: declaration of 'rv' shadows a previous local [-Werror=shadow-compatible-local]
      folly/io/async/AsyncSocket.cpp:364:9: error: shadowed declaration is here [-Werror=shadow-compatible-local]
      ```
      
      Reviewed By: ngoyal, knekritz
      
      Differential Revision: D3963873
      
      fbshipit-source-id: 85b3ab1fc3b200b81615a00d66a183cc9c792a90
      0e125753
    • Arthur O'Dwyer's avatar
      hazptr: Replace friend "swap" with a member function and a non-friend · 4d012b25
      Arthur O'Dwyer authored
      Summary:
      This matches what the STL does with e.g. std::vector::swap() and std::shared_ptr::swap().
      
      http://en.cppreference.com/w/cpp/container/vector/swap
      http://en.cppreference.com/w/cpp/memory/shared_ptr/swap
      
      Should be relatively uncontroversial, I would think.
      Closes https://github.com/facebook/folly/pull/489
      
      Reviewed By: magedm
      
      Differential Revision: D3963285
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: 3fa6bf77e66fa9a673cb648b0bf87b1db3caa6c8
      4d012b25
    • Jim Meyering's avatar
      folly/io/Compression.cpp: avoid shadowing warnings for "rc" · e7256a8a
      Jim Meyering authored
      Summary:
      gcc's -Wshadow (and the under-review -Wshadow-local) would evoke this:
      ```
      folly/io/Compression.cpp:650:9: error: declaration of 'rc' shadows a previous local [-Werror=shadow-compatible-local]
      folly/io/Compression.cpp:637:7: error: shadowed declaration is here [-Werror=shadow-compatible-local]
      folly/io/Compression.cpp:566:9: error: declaration of 'rc' shadows a previous local [-Werror=shadow-compatible-local]
      folly/io/Compression.cpp:548:7: error: shadowed declaration is here [-Werror=shadow-compatible-local]
      ```
      In each case, I removed the "int" from the latter declaration.
      
      Reviewed By: philippv
      
      Differential Revision: D3966308
      
      fbshipit-source-id: 584cb9ffe8ba0e56914223c440efabe9e0de6b17
      e7256a8a
    • Giuseppe Ottaviano's avatar
      Outline several fbstring/malloc functions · 2ff9d181
      Giuseppe Ottaviano authored
      Summary: Outline all the non-trivial constructor and the destructor, `assign()`, and `append()` to reduce code size. The fast path of copy, and moves, are instead still inlined.
      
      Reviewed By: philippv
      
      Differential Revision: D3896612
      
      fbshipit-source-id: 25050d4ba28d25da226a7bc49d5b542947d0c512
      2ff9d181
    • Giuseppe Ottaviano's avatar
      Fix a typo · 471f03d0
      Giuseppe Ottaviano authored
      Reviewed By: lbrandy
      
      Differential Revision: D3964328
      
      fbshipit-source-id: 0b1dc2d4b2a1565019770668445a624625b8257e
      471f03d0
  11. 03 Oct, 2016 1 commit
    • Shubhanshu Agrawal's avatar
      add BatchDispatcher · 52736dce
      Shubhanshu Agrawal authored
      Summary:
      This diff adds BatchDispatcher, which can be used to batch values while performing IO.
      This would be useful in writing single id code in node, and would be use to batch ids while doing IO at storage adapter.
      
      Differential Revision: D3900404
      
      fbshipit-source-id: f53aa352344ff55674c7544302b6a1b4726214b6
      52736dce