1. 19 May, 2016 1 commit
  2. 18 May, 2016 5 commits
    • Yedidya Feldblum's avatar
      Flesh out the comments about Unit · 004d6c17
      Yedidya Feldblum authored
      Summary:
      [Folly] Flesh out the comments about `Unit`.
      
      * Remove mention of `Future`.
      * Compare `unit` to `void`.
      
      Reviewed By: djwatson
      
      Differential Revision: D3316114
      
      fbshipit-source-id: d30cf36cc029025734bb16c5bdbd640a289cad79
      004d6c17
    • Yedidya Feldblum's avatar
      Extract Unit to top-level · a3323738
      Yedidya Feldblum authored
      Summary:
      [Folly] Extract `Unit` to top-level.
      
      It was in `folly/futures/`, but this diff moves it to `folly/`. It is needed for futures, but it is more general than futures and can be used separately.
      
      Users must replace `folly/futures/Unit.h` with `folly/Unit.h`.
      
      Also codemods existing usage sites:
      
      ```
      hg grep -lw folly/futures/Unit.h | xargs perl -pi -e 's,\bfolly/futures/Unit\.h\b,folly/Unit.h,g'
      ```
      
      Reviewed By: igorsugak
      
      Differential Revision: D3314280
      
      fbshipit-source-id: 16279b76b1d24529bec49077ccb36cd7d39f23b8
      a3323738
    • Ilya Maykov's avatar
      added IOBuf::wrapBufferAsValue() · 6b5a25fc
      Ilya Maykov authored
      Summary:
      Added a version of IOBuf::wrapBuffer() which returns the new IOBuf by value rather than heap-allocating it.
      Motivation: we have a lot of places in the crypto code that do something like this:
      
        // take a string or vector parameter
        auto buf = folly::IOBuf::wrapBuffer( /* string or vector goes here */);
        // do something with buf
        // return
      
      In these cases, a stack-allocated IOBuf would save us from an unnecessary heap allocation. But calling `folly::IOBuf(folly::IOBuf::WrapBufferOp::WRAP_BUFFER, ...)` is gross and in practice people just call the much more readable `wrapBuffer()` function. Hypothesis: readability trumps performance, but if we had a readable version that returned a stack-allocated IOBuf, it might see usage.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3314037
      
      fbshipit-source-id: 4d4b5ec1d067762a27de1d7d6f7cac406388bfa3
      6b5a25fc
    • Andrii Grynenko's avatar
      Fix one more race in Promise::setTry · 4ffd39d6
      Andrii Grynenko authored
      Summary:
      Baton::post has to be the last step of Promise::setTry. If Promise is not owned by
      the posting thread, it may be destroyed right after Baton::post is called.
      
      Reviewed By: pavlo-fb
      
      Differential Revision: D3312506
      
      fbshipit-source-id: 6d5c3f0925c3bb9cd3f981e7550f888d5ed76189
      4ffd39d6
    • Yedidya Feldblum's avatar
      Keep the Unit test suite free of Promise and Future · 72320612
      Yedidya Feldblum authored
      Summary:
      [Folly] Keep the `Unit` test suite free of `Promise` and `Future`.
      
      Move the `Promise`-related tests to the `Promise` test suite and the `Future`-related tests to the `Future` test suite.
      
      Reviewed By: djwatson
      
      Differential Revision: D3313635
      
      fbshipit-source-id: 05c82c8719719d7709063ad58a4806036ca10fb3
      72320612
  3. 17 May, 2016 3 commits
    • Yedidya Feldblum's avatar
      Simplify Unit · e38ff539
      Yedidya Feldblum authored
      Summary:
      [Folly] Simplify `Unit`.
      
      Specifically:
      * Make `Unit::Lift` and `Unit::Drop` simply be aliases to `std::conditional<...>`. No need for anything more complicated.
      * Remove `is_void_or_unit`, which is unused and unnecessary.
      
      Reviewed By: djwatson
      
      Differential Revision: D3312481
      
      fbshipit-source-id: 280d40aa8ef91c52f96a51b03e0a109d76c939ec
      e38ff539
    • Marcus Holland-Moritz's avatar
      folly: fbvector: ubsan: don't call memcpy() with nullptr args if size == 0 · 1072a897
      Marcus Holland-Moritz authored
      Reviewed By: meyering, luciang
      
      Differential Revision: D3310683
      
      fbshipit-source-id: c86471d54062b2f3455f15fb73340fac486d9e44
      1072a897
    • Yedidya Feldblum's avatar
      IPAddress::validate · 01dbb37f
      Yedidya Feldblum authored
      Summary: [Folly] `IPAddress::validate`.
      
      Reviewed By: igorsugak
      
      Differential Revision: D3308683
      
      fbshipit-source-id: 48af18d6930f16718372021a4cc08062bf17327e
      01dbb37f
  4. 16 May, 2016 2 commits
    • Andrii Grynenko's avatar
      Fix a race in Promise::setTry · 87e5b407
      Andrii Grynenko authored
      Summary:
      This fixes a race which can only be exposed if Promise is owned by the same thread which was calling await and Promise is fulfilled from a different thread. What could happen then was:
      1. Thread 2 fulfills the promise and thus saves the value and posts Baton.
      2. Thread 1 wakes up, await returns and then Thread 1 destroys the Promise.
      3. Promise destructor checks value_, which is still not null, so it tries to fulfil it with exception.
      
      Reviewed By: spalamarchuk
      
      Differential Revision: D3306969
      
      fbshipit-source-id: adf799cfd7b75b0201fa675a9e44ac7c7c42ac95
      87e5b407
    • Andrii Grynenko's avatar
      Make await exception safe · 9b311838
      Andrii Grynenko authored
      Summary: This fixes fibers::await to correctly handle exception thrown by user-passed lambda. Await still always waits for the promise to be fulfilled (if the promise was not moved out, it will be destroyed and thus auto-fulfilled with "promise not fulfilled" exception). However if user-passed lambda throws, promise result is ignored (even if exception) and exception thrown by lambda is re-thrown.
      
      Reviewed By: pavlo-fb
      
      Differential Revision: D3303393
      
      fbshipit-source-id: c4ba01fde0e156cc88e5d07aaf763e3abe121d11
      9b311838
  5. 14 May, 2016 5 commits
    • Yedidya Feldblum's avatar
      Prefer constexpr to preprocessor conditionals when checking endianness · e788c8ca
      Yedidya Feldblum authored
      Summary:
      [Folly] Prefer `constexpr` to preprocessor conditionals when checking endianness.
      
      Using `if (folly::kIsLittleEndian) {` v.s. `#if __BYTE_ORDER__ == __LITTLE_ENDIAN__`.
      
      Reviewed By: meyering
      
      Differential Revision: D3296770
      
      fbshipit-source-id: b26df83fdd42a50663746fc7c9d5fbe67e6671eb
      e788c8ca
    • Yedidya Feldblum's avatar
      A thread-per-task executor · 0afc1272
      Yedidya Feldblum authored
      Summary:
      [Wangle] A thread-per-task executor.
      
      Moved from Folly into Wangle and fleshed out.
      * Starts task threads from a control thread, rather than starting task threads from the submitter thread. Because starting task threads is likely to be more expensive than moving a functor.
      * Joins task threads as they finish, rather than joining all task threads in the executor's destructor.
      
      Suitable for running tasks which spend most of their time sleeping. Such as blocking IO, blocking fork-exec-wait, etc., when it is inconvenient to use the nonblocking variants with an IO executor.
      
      Reviewed By: simpkins
      
      Differential Revision: D3286988
      
      fbshipit-source-id: 4b91133a7d55332ebbae020c1515c60e816906b3
      0afc1272
    • Lucian Grijincu's avatar
      folly: fbstring: ubsan: memcpy/memmove are marked as nonnull - avoid calling... · bc02b7a4
      Lucian Grijincu authored
      folly: fbstring: ubsan: memcpy/memmove are marked as nonnull - avoid calling them when size == 0 and (likely) source is nullptr
      
      Summary: Also see {D3295811}
      
      Differential Revision: D3302564
      
      fbshipit-source-id: 3f2dbf5a6cfa8199682cb4af90aac372d501919a
      bc02b7a4
    • Lucian Grijincu's avatar
      folly: ubsan: elias-fano avoid memset(nullptr) · 3ce293fa
      Lucian Grijincu authored
      Reviewed By: ot
      
      Differential Revision: D3300437
      
      fbshipit-source-id: 7e0add5dab6dc1c891b742b4bcedea656c8284a9
      3ce293fa
    • Lucian Grijincu's avatar
      folly: ubsan: redo BitsTest (no macros) and fix DCHECK in test · 5fc9d571
      Lucian Grijincu authored
      Reviewed By: meyering
      
      Differential Revision: D3283226
      
      fbshipit-source-id: 7ae2ec7741ca53c494e8325e30f2995a241674c0
      5fc9d571
  6. 13 May, 2016 5 commits
    • Mirek Klimos's avatar
      Test creation of RequestContext inside a fiber task · aabeca71
      Mirek Klimos authored
      Summary: ^, as discussed on D3279644
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3299473
      
      fbshipit-source-id: dc302132db64399f768d69c641f848d0da1075c4
      aabeca71
    • Mirek Klimos's avatar
      Replace RequestContext::setContext with RequestContextScopeGuard in folly · 4d499e08
      Mirek Klimos authored
      Summary: To make sure RequestContext is properly unset when we stop processing request on a thread. This changes the API in Fibers, NotificationQueue, HHWheelTimer and AsyncTimeout, and fixes RequestContext handling in Futures (reset RC after the callback is done)
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3279644
      
      fbshipit-source-id: a6a1c2840cdce179334aa1a3b28fa514cd5358c1
      4d499e08
    • Chad Parry's avatar
      Construct all HHWheelTimer instances with the factory method · 6da3b849
      Chad Parry authored
      Summary:
      This diff standardizes `HHWheelTimer` construction. It's not that safe to allow anyone to call `new HHWheelTimer` because the caller needs to remember to call `DelayedDestruction::destroy`.
      
      Once callers are made to be safer, I'll be able to change the `HHWheelTimer` to use standard smart pointers instead of `DelayedDestruction`.
      
      This picks up some work that I started in D2627941 but had to postpone.
      
      This was mostly a mechanical change:
      
        ( fbgs -ls 'new HHWheelTimer' ; fbgs -ls 'new folly::HHWheelTimer' ) | xargs perl -pi -e 's/\bnew\s+((?:folly::)?HHWheelTimer)\b/$1::newTimer/g'
      
      Then I manually inspected the code. I reverted `folly/io/async/HHWheelTimer.h`, since the `newTimer` factory method is the one place that we still want to call `new HHWheelTimer`. I manually edited `proxygen/lib/utils/SharedWheelTimer.cpp`, since that was using a `shared_ptr` with a custom destructor, which isn't needed anymore. I reverted `common/io/async/d` since the D shim is meant to pass around only raw pointers. I had to replace each instance of `foo.reset(…)` with `foo = …` . Then I made manual edits to `common/clientpool/ClientPool2-inl.h` because that code wants to store the timer in a `ThreadLocalPtr`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3237530
      
      fbshipit-source-id: 96bfb6987098618ad5430c21b1314f385f04a93d
      6da3b849
    • Mark Santaniello's avatar
      Suppress new GCC 5 warning -Wbool-compare · 2f1ac690
      Mark Santaniello authored
      Summary: This -Wbool-compare is apparently new in GCC 5.  We should ignore it, similar to the existing suppression of -Wsign-compare.
      
      Reviewed By: pixelb, yfeldblum
      
      Differential Revision: D3293675
      
      fbshipit-source-id: 5f90b0dbf049a06c0f6c3df2cdfcc8055358e367
      2f1ac690
    • Subodh Iyengar's avatar
      Fix extra bytes in err message · 2b6dd2e5
      Subodh Iyengar authored
      Summary:
      Error message might be < 256 bytes
      in which case buf.size() would be greater
      than the size of the message written out
      and we might have garbled bytes at the end.
      
      ERR_error_string_n null terminates the string
      so just use that.
      
      Reviewed By: anirudhvr
      
      Differential Revision: D3297320
      
      fbshipit-source-id: 2ae626ce4c49ca478806c0bcc40a390e5a84f24b
      2b6dd2e5
  7. 12 May, 2016 5 commits
    • Andrii Grynenko's avatar
      Register custom stack for signal handlers · af8129a2
      Andrii Grynenko authored
      Summary: This updates FiberManager to automatically register custom stack for signal handlers. This ensures signal handlers will work correctly not only in case of stack overflow, but also if fiber stack size is just not enough for them.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3289912
      
      fbshipit-source-id: 44959b727f70e1f1748d837b1a06c7414433e5ec
      af8129a2
    • Chad Parry's avatar
      Transfer ownership from a unique_ptr to a ThreadLocalPtr · 0a0e47de
      Chad Parry authored
      Summary:
      This `ThreadLocalPtr::reset` overload will accept a `unique_ptr`. It's actually not totally exception safe, simply because `ElementWrapper::set` is not exception safe. The best I can say is that my additional code is exactly as safe as the underlying implemenation.
      
      liketolivedangerously
      
      Reviewed By: ericniebler
      
      Differential Revision: D3271563
      
      fbshipit-source-id: 774bcf31924b1ed4e29a6cb1c0a36ad710ab6034
      0a0e47de
    • Chad Parry's avatar
      Prevent leaks in ThreadLocalPtr initialization · 34986bb4
      Chad Parry authored
      Summary: While making an unrelated change, (D3271563, which was needed from an unrelated change, (D3237530)), I noticed a lack of exception safety here. If `std::bad_alloc` were thrown, then we don't want to leak memory.
      
      Reviewed By: ericniebler
      
      Differential Revision: D3271911
      
      fbshipit-source-id: 0d316c0fa865a7d64622c1d62160bb0c2b061d78
      34986bb4
    • Michael Lee's avatar
      Include limits.h in IOVec.h. · da5b2838
      Michael Lee authored
      Summary:
      According to the POSIX definition, IOV_MAX is defined in
      limits.h. Given that IOVec.h is used to provide IOV_MAX and similar,
      it seems like we should add limits.h as well.
      
      Differential Revision: D3291996
      
      fbshipit-source-id: 238140ebef7b1b90a28f3a67a25c5f5863538fc7
      da5b2838
    • Christopher Dykes's avatar
      Make the sys/uio.h portability header work for Windows · c6ad47b6
      Christopher Dykes authored
      Summary: Windows doesn't have sys/uio.h, so implement it. This doesn't adjust any includes of it yet, I'll leave that for a separate diff.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2978042
      
      fbshipit-source-id: 16d398a856de50b6c662f739eb11dfb851096592
      c6ad47b6
  8. 11 May, 2016 4 commits
    • Subodh Iyengar's avatar
      wangle support for TFO · bd52f502
      Subodh Iyengar authored
      Summary: Add server support for TFO to wangle.
      
      Reviewed By: Orvid
      
      Differential Revision: D3275427
      
      fbshipit-source-id: 466baa342e2e0c4751e9c96d1e660cffb90e0634
      bd52f502
    • Lucian Grijincu's avatar
      folly: ubsan: format: avoid UB in abs(-INT_MIN) · b3c4aa79
      Lucian Grijincu authored
      Summary:
      abs(-INT_MIN) is UB. Avoid it by first casting the number to
      its unsigned equivalent and then negating that.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3280835
      
      fbshipit-source-id: 40922d686173e6467e15d5a6dc2b62ad718349b5
      b3c4aa79
    • Christopher Dykes's avatar
      Add a compatibility shim for working with libevent on MSVC · d618bf95
      Christopher Dykes authored
      Summary:
      MSVC builds of libevent expect `evutil_socket_t` to be `HANDLE` values, but Folly, HHVM, and Thrift all use them as file descriptors.
      This adds a `folly_event_set` function that always expects a file descriptor rather than a socket. This also changes the places in Folly that use it.
      
      Reviewed By: mzlee, yfeldblum
      
      Differential Revision: D2874655
      
      fbshipit-source-id: 66cfd86fd69a9fbac30d150445e4814cd5ca799e
      d618bf95
    • Subodh Iyengar's avatar
      Make error size more explicit · 75ed8035
      Subodh Iyengar authored
      Summary:
      We shouldn't rely on the internal buffer size of openssl
      for errors.
      
      This makes it more explicit.
      
      Reviewed By: knekritz
      
      Differential Revision: D3285918
      
      fbshipit-source-id: 452bf16a3de151d0aa79c774f2fdfc1e08ee6f9c
      75ed8035
  9. 10 May, 2016 10 commits
    • Neel Goyal's avatar
      Add NETWORK_ERROR to switch statement · bc9992bf
      Neel Goyal authored
      Summary: Add NETWOR_ERROR to switch so it doesn't fall into Invalid Exception block.
      
      Differential Revision: D3282448
      
      fbshipit-source-id: 2cc5d21e436e6ac8f2f6581d99341ac47cf5b023
      bc9992bf
    • Kyle Nekritz's avatar
      Add additional ALPN mismatch tests. · c76ee315
      Kyle Nekritz authored
      Reviewed By: siyengar
      
      Differential Revision: D3264727
      
      fbshipit-source-id: fb10558096e73a3cbb6f2fb93296524c0206910d
      c76ee315
    • Faidon Liambotis's avatar
      Fix a few typos all over the code · f7f9e64e
      Faidon Liambotis authored
      Summary:
      These are pretty trivial. Debian's lint tool (lintian) warns about those
      in its verbose mode, and since we saw them when packaging for Debian, we
      thought of fixing them and forwarding them upstream.
      Closes https://github.com/facebook/folly/pull/345
      
      Reviewed By: Orvid
      
      Differential Revision: D2769801
      
      Pulled By: elliottneilclark
      
      fbshipit-source-id: ad37cc53792f21aae6558ba256f20cb56c6caab5
      f7f9e64e
    • Jaak Ristioja's avatar
      docs/Overview.md: Fixed 2 hyperlinks. · 119aae2d
      Jaak Ristioja authored
      Summary:
      These didn't work properly in GitHub.
      Closes https://github.com/facebook/folly/pull/375
      
      Differential Revision: D3281872
      
      Pulled By: elliottneilclark
      
      fbshipit-source-id: b5398267ff5856bb6a7c4a3b963ae5cb47859bc3
      119aae2d
    • Lucian Grijincu's avatar
      folly: ubsan: disable integer overflow tests in Histogram · 9dd251b3
      Lucian Grijincu authored
      Summary:
      It would be nice to fix, but it's going to be easier to do when folly
      support is for GCC>=5 which adds `__builtin_add_overflow`.
      
      For now disable the check as the Histgram code handles overflow
      correctly and has tests for these cases.
      
      Fixes need to be done for both float and integer types as Histogram is used with both.
      
      Reviewed By: meyering
      
      Differential Revision: D3280260
      
      fbshipit-source-id: 56e524c517566a4547346859be7770eda2acee96
      9dd251b3
    • Lucian Grijincu's avatar
      folly: ubsan: cast to unsigned to avoid negative-left-shift · 6c4dfb8a
      Lucian Grijincu authored
      Summary:
      The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated
        bits are filled with zeros.
      
        If E1 has a signed type and non-negative value, and E1 × 2E2 is
        representable in the result type, then that is the resulting value;
        otherwise, the behavior is undefined.
      
      The code assumed the signed left shift worked like an unsigned left
      shift, so make that explicit.
      
      Reviewed By: meyering
      
      Differential Revision: D3280325
      
      fbshipit-source-id: 178b95ee36b7a1126a79bb825c2ad2ffa6fa9464
      6c4dfb8a
    • Lucian Grijincu's avatar
      folly: ubsan: fix "reference binding to null pointer of type 'char'" · c03fd9b7
      Lucian Grijincu authored
      Summary:
      third-party-buck/build/libgcc/include/c++/4.9.x/bits/stl_vector.h:866:9: runtime error: reference binding to null pointer of type 'char'
      
      ```
      Breakpoint 2, 0x0000000000494894 in __ubsan_handle_type_mismatch_abort ()
      (gdb) bt
      ```
      
      Reviewed By: meyering, yfeldblum
      
      Differential Revision: D3279234
      
      fbshipit-source-id: 63a761587e5b3f79ece09fc99b9a593da0e44b75
      c03fd9b7
    • Christopher Dykes's avatar
      Deal with some oddities of MSVC's preprocessor · dc8c21a9
      Christopher Dykes authored
      Summary: MSVC's preprocessor is different in how it deals with passing arguments expanded from `__VA_ARGS__`, so we have to add a stub to force it to expand the arguments.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3256328
      
      fbshipit-source-id: 551434833d40e55498a9ab352eb74acdfd094835
      dc8c21a9
    • Christopher Dykes's avatar
      Fix detection of std::make_unique under MSVC · d65a097e
      Christopher Dykes authored
      Summary: MSVC doesn't define `__cplusplus` as a high enough value to trigger this, so add an explicit check for MSVC instead.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3271647
      
      fbshipit-source-id: a1e5a5a7eb75dce066dfc7fae8b2086880dc4c3d
      d65a097e
    • Lucian Grijincu's avatar
      folly: ubsan: &v[0] is undefined if v.empty() · 70cab78c
      Lucian Grijincu authored
      Summary:
      before:
      
        [ RUN      ] RangeFunc.Vector
        bits/stl_vector.h:866:9: runtime error: reference binding to null pointer of type 'int'
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3279253
      
      fbshipit-source-id: 957a8ec050f5c3b27febf7e6cd16ad1d307da169
      70cab78c