1. 13 Apr, 2017 2 commits
    • Nick Terrell's avatar
      Add bzip2 support · d216a9bd
      Nick Terrell authored
      Summary:
      Adds bzip2 support to `folly/io/Compression.h`.
      Adds bzip2 to the default set of supported codecs for the `AutomaticCodec`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4873771
      
      fbshipit-source-id: d4f4861aef7e4b9efb67095e8892c265b5ae5557
      d216a9bd
    • Christopher Dykes's avatar
      Fix the last issues with exception_wrapper under MSVC · 3a7cbbe4
      Christopher Dykes authored
      Summary:
      Well, MSVC 2017 anyways.
      MSVC 2017 wasn't able to handle the decltype in the type specialization, which was also entirely unnecesary.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4880272
      
      fbshipit-source-id: b6deed72a12d4b58d6eca200e7287e536f94ca30
      3a7cbbe4
  2. 12 Apr, 2017 9 commits
    • Alexey Spiridonov's avatar
      Replace Subprocess::pipe* syntax sugar with Subprocess::Options().pipe* · b4bcc1a7
      Alexey Spiridonov authored
      Summary:
      This is a bit too magical -- it's not clear that the thing produces an Options object. If you do know that you can chain further option setters off this thing, it's nice, but otherwise, the first impression is "what just happened?".
      
      So, let's have one good way for doing things.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4863947
      
      fbshipit-source-id: 3dfe83cfc077d47f604f47dcb21149fbaa2d2243
      b4bcc1a7
    • Alexey Spiridonov's avatar
      Delete | operator for Subprocess::Options · 0e5ec48b
      Alexey Spiridonov authored
      Summary:
      This operator is WRONG. It has not worked correctly for years, e.g. it lacks support for chdir, and several other options.
      
      The operator is not really useful after C++11. Usually, you should just chain setters, e.g. `Subprocess::Options().pipeStdout().pipeStderr()`. If you must repeatedly mutate options in a fixed way, in the C++11 world you can use a lambda instead.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4862698
      
      fbshipit-source-id: a2d8ace53424b9232e178cf202cf51beb7b59b12
      0e5ec48b
    • Nick Terrell's avatar
      Fix zlib + lzma memory usage inefficiency · 6bb90698
      Nick Terrell authored
      Summary:
      Since IOBuf rounds to a good malloc size, zlib and lzma waste space.
      For a 4 MiB `length`, about 1 MiB of the IOBuf is wasted.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4872830
      
      fbshipit-source-id: 42fc83277b2dae22b75403e0e71c43e8f2b19f21
      6bb90698
    • Jude Taylor's avatar
      codemod: ASN1_STRING_data -> ASN1_STRING_get0_data · 6dbd9e97
      Jude Taylor authored
      Reviewed By: anirudhvr
      
      Differential Revision: D4830205
      
      fbshipit-source-id: 55f34c3bddead8a73174c403f76572248c541a10
      6dbd9e97
    • Christopher Dykes's avatar
      Make folly::StrictConjunction usable under MSVC · 44ce72fd
      Christopher Dykes authored
      Summary:
      Template pack expansion plays much nicer when being expanded into the template parameters of a base class than it does as the template parameters to a templated `using` when under MSVC.
      This fixes the other half of `folly::exception_wrapper`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4874047
      
      fbshipit-source-id: 6593d10f8737b940bd550353e54f43bc96402a48
      44ce72fd
    • Jude Taylor's avatar
      Provide a copy ctor for Digest that copies the current hash context · 68a3d541
      Jude Taylor authored
      Summary: opensource changes for t16702532
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4846899
      
      fbshipit-source-id: 67a610ff399e95c7cf1c9c8a5950f79bfc3aabb9
      68a3d541
    • Artem Lantsev's avatar
      Add memory padding and alignment to prevent false sharing · a9d90ea1
      Artem Lantsev authored
      Summary: This is a follow up commit for the thread https://github.com/facebook/folly/pull/378
      
      Reviewed By: nbronson
      
      Differential Revision: D4860356
      
      fbshipit-source-id: f10a0d12a593c18b1abf94da5b477c524c04f4be
      a9d90ea1
    • Aravind Anbudurai's avatar
      Support linux namespace clone flags · 4e9783b9
      Aravind Anbudurai authored
      Summary:
      This diffs adds supports on folly::Subprocess to be able to take clone flags and
      use them to call clone(2) instead of the default vfork()
      
      I checked that all tests pass when I replace vfork with fork on trunk. So there
      isn't anything built assuming the parent is paused for an execve. Correct me if
      I am wrong here.
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: snarkmaster
      
      Differential Revision: D4853169
      
      fbshipit-source-id: 7e5851df3a49996a4a5dc1945457686dd042e1f4
      4e9783b9
    • Angelo Failla's avatar
      IPAddressV(46) methods to convert IPs to their inverse in-addr.arpa / ip6.arpa representation · b41eb6f0
      Angelo Failla authored
      Summary: As per the title, this adds methods to convert IPv(46) to their inverse representation, this is useful for applications that needs to calculate the inverse arpa representation, typically used when making PTR DNS requests.
      
      Reviewed By: Orvid
      
      Differential Revision: D4867502
      
      fbshipit-source-id: 190e5c309b17a633e1c97b077f212ab38725860f
      b41eb6f0
  3. 11 Apr, 2017 6 commits
    • Eric Niebler's avatar
      non-throwing, non-allocating exception_wrapper · 19e3e9fe
      Eric Niebler authored
      Summary:
      The purpose of this reimplementation of `exception_wrapper` is threefold:
      
      - Make `exception_wrapper` smaller. It goes from 48 bytes to 24.
      - Give it `noexcept` ~~copy and~~ move
      - Store small exception objects in an internal buffer; i.e., with zero allocations.
      
      The ultimate goal is to change `folly::Try<T>` to a thin wrapper over `folly::Expected<T, exception_wrapper>`. (Currently, it stores the `exception_wrapper` on the heap.)
      
      As part of this redesign, I:
      
      - Remove `exception_wrapper::getCopied`. The user shouldn't care how the `exception_wrapper` stores the exception.
      - Remove `exception_wrapper::operator==`. It was only used in 2 places in test code. The existing semantics (return true IFF two `exception_wrapper`s point to the //same// exception object) prevented the small-object optimization.
      - Add new `handle()` API that behaves like cascading `catch` clauses. For instance:
      ```lang=c++
      exception_wrapper ew = ...;
      ew.handle(
          [&](const SomeException& e) { /*...*/ },
          [&](const AnotherException& e) { /*...*/ },
          [&](...) { /* catch all*/ }, // yes, lambda with ellipses works!
      ```
      - Add a `type()` member for accessing the `typeid` of the wrapped exception, if it's known or can be determined with a `catch(std::exception&)`.
      
      This table shows the percent improvement for the exception_wrapper_benchmark test:
      
      | Test  | Percent improvement (gcc-5)  | Percent improvement (gcc-4)
      | -----  | -----  | -----
      | exception_wrapper_create_and_test  | 14.33%    | -6.50%
      | exception_wrapper_create_and_test_concurrent | 11.91% | 20.15%
      | exception_wrapper_create_and_throw | -0.82% | -0.25%
      | exception_wrapper_create_and_cast | 15.02% | 14.31%
      | exception_wrapper_create_and_throw_concurrent | 18.37% | 8.03%
      | exception_wrapper_create_and_cast_concurrent | 28.18% | -10.77%
      
      The percent win for gcc-5 is 15% on average. The non-throwing tests show a greater win since the cost of actually throwing an exception drowns out the other improvements. (One of the reasons to use `exception_wrapper` is to not need to throw in the first place.) On gcc-4, there is roughly no change since the gcc-4 standard exceptions (`std::runtime_error`, std::logic_error`) are non-conforming since they have throwing copy operations.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4385822
      
      fbshipit-source-id: 63a8316c2923b29a79f8fa446126a8c37aa32989
      19e3e9fe
    • Christopher Dykes's avatar
      Treat OpenSSL as a non-portable include · c5b9338e
      Christopher Dykes authored
      Summary: On Windows, the OpenSSL headers have to be included in a specific order relative to WinSock. Fixing the issues ad-hock is not a viable way to continue, so treat it as completely non-portable and require all includes of it in Folly to go through the portability header.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4856858
      
      fbshipit-source-id: 56aca1fb0fe095f41a8af12488c6c2080344603d
      c5b9338e
    • Christopher Dykes's avatar
      Implement clearenv in the portability headers · a5a61149
      Christopher Dykes authored
      Summary:
      It doesn't exist on OSX or Windows, so implement it.
      
      Closes https://github.com/facebook/folly/issues/567
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4783463
      
      fbshipit-source-id: 0a2586aced7123b797a8e55a3e86124b449634e4
      a5a61149
    • Andrii Grynenko's avatar
      Fix TLRefCount::useGlobal to work with TSAN · 1d11ad7a
      Andrii Grynenko authored
      Summary: TSAN has a limitation for the number of locks held concurrently - https://github.com/llvm-mirror/compiler-rt/blob/master/lib/sanitizer_common/sanitizer_deadlock_detector.h#L126, so we have to work around that.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4866477
      
      fbshipit-source-id: 958251e97d91c1c46ef4e907de2cf189fb04f88e
      1d11ad7a
    • Andrii Grynenko's avatar
      Fix Fiber::LocalData leak for large fiber locals · 42f6e99c
      Andrii Grynenko authored
      Summary: facepaw
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4856227
      
      fbshipit-source-id: 17a73d4d630c6efe1763bbd8aff8b7a2c7721c27
      42f6e99c
    • Christopher Dykes's avatar
      Revert D4832473: [Folly] Disable EnvUtil::setAsCurrentEnvironment() on platforms without clearenv() · 4fe88e4c
      Christopher Dykes authored
      Summary: This reverts commit a80aabb5a223264746ab45e3138d065bce5fe99c
      
      Differential Revision: D4832473
      
      fbshipit-source-id: 1a78d61f3f09f1064876a786c15601a091f4402b
      4fe88e4c
  4. 10 Apr, 2017 7 commits
    • Alexander Shaposhnikov's avatar
      Remove superfluous std::move · 0fa94136
      Alexander Shaposhnikov authored
      Summary: Cleanup: remove superfluous std::move for return values.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4856421
      
      fbshipit-source-id: bf2cb66f3b43eb8f3b183e22b0acd31e0a0c0958
      0fa94136
    • Nick Terrell's avatar
      Fix std::max() call in Compression.cpp · 03ce292a
      Nick Terrell authored
      Summary:
      `std::max(uint64_t, size_t)` was called.
      Fixes https://github.com/facebook/folly/issues/576.
      
      Reviewed By: Orvid
      
      Differential Revision: D4861336
      
      fbshipit-source-id: 1b6f67b291451048ba79d638d2c1184f9245dc0c
      03ce292a
    • Christopher Dykes's avatar
      Fix the build... Whoops... · b8ec2ef5
      Christopher Dykes authored
      Summary: I landed a change to Folly that used a feature I had just re-written in Folly without updating the change. This has broken everything. Whoops.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4861562
      
      fbshipit-source-id: 05beadbe233d1fdf90fb4435e65b718cdec7f63e
      b8ec2ef5
    • Christopher Dykes's avatar
      Re-work the OpenSSL portability header to be a portability header · 9783dc4e
      Christopher Dykes authored
      Summary:
      It was defining the same functions as OpenSSL, but it was putting them in the `folly::ssl` namespace and requiring a manual `use namespace` everywhere to actually be able to use it. Proper portability headers require no interaction to function correctly other than including them in the build.
      This adjusts it so including it is all that is required to get an OpenSSL 1.1.0 compatible API.
      This also re-organizes the code to significantly lower the amount of nesting in the `#if`'s, and puts it in order from oldest APIs to newest, rather than haphazard.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4856784
      
      fbshipit-source-id: 7c00fdf4a3e51e37287d2b1ef294046f38a96a43
      9783dc4e
    • Jason Fried's avatar
      Client RequestChannels and folly/python/futures.h · 46b709bc
      Jason Fried authored
      Summary:
      Use RequestChannel to construct Thrift Clients.
      
      use folly/python/futures.h to marry up thrift client rpc futures to
      asyncio futures. No gil exchanges
      
      py3 clients are async context managers now.
      
      Reviewed By: ambv, yfeldblum
      
      Differential Revision: D4639677
      
      fbshipit-source-id: 6b400747507446882d3cfcb1cf7e85c3daa07a2e
      46b709bc
    • Andrii Grynenko's avatar
      Fix folly/test:singleton_test - Singleton.SharedPtrUsage · b422f6b5
      Andrii Grynenko authored
      Reviewed By: yfeldblum
      
      Differential Revision: D4856138
      
      fbshipit-source-id: 19eee4f8c4108ef168d82d5e9b1f2d65ff9b03bd
      b422f6b5
    • Christopher Dykes's avatar
      Refactor FOLLY_GCC_DISABLE_WARNING to play nice with clang-format · e15da103
      Christopher Dykes authored
      Summary: Currently clang-format cannot be run on any file using the macro because it breaks it. By putting the warning name in a string clang-format no longer breaks it.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4856945
      
      fbshipit-source-id: ebd2d223dd97f66224e9e2912610057e36287dae
      e15da103
  5. 08 Apr, 2017 6 commits
    • Yedidya Feldblum's avatar
      All template params for PriorityMPMCQueue · 1f52e58c
      Yedidya Feldblum authored
      Summary:
      [Folly] All template params for `PriorityMPMCQueue`.
      
      Mimic the suite of template params of `MPMCQueue`.
      
      Reviewed By: magedm
      
      Differential Revision: D4857179
      
      fbshipit-source-id: 3d441099c46ea1223155bd3f4cc819595814c47b
      1f52e58c
    • Christopher Dykes's avatar
      Fix include ordering for OpenSSLPtrTypes.h · 3e09d2ba
      Christopher Dykes authored
      Summary: When including OpenSSL on Windows, the portability header must be included before including any OpenSSL headers.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4856376
      
      fbshipit-source-id: a8e6533b2ba3c003314ae2426605031fa67be05f
      3e09d2ba
    • Christopher Dykes's avatar
      Qualify a couple local constexpr values as 'static' to allow use from within non-capturing lambdas · 3e0c28fd
      Christopher Dykes authored
      Summary: MSVC doesn't allow non-static locals to be accessed within a non-capturing lambda, and some were introduced into the json code.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4856242
      
      fbshipit-source-id: b2db36ca37a79a41237d39cc7e7b839a5416922f
      3e0c28fd
    • Giuseppe Ottaviano's avatar
      Fix leak in EliasFanoCodingTest · 92693aaf
      Giuseppe Ottaviano authored
      Summary: `EliasFanoCompressedList` requires explicit freeing.
      
      Reviewed By: lbrandy, philippv, yfeldblum, luciang
      
      Differential Revision: D4855200
      
      fbshipit-source-id: ccee44b6371ae743ef15a72af9b691d5b56e37c2
      92693aaf
    • Louis Brandy's avatar
      ReadMostlySharedPtrTest, subtle test bug caught by -fsanitize-address-use-after-scope · 5c04f9ac
      Louis Brandy authored
      Summary: Because these `atomic<int>` are referenced in the destructor of the `ReadMostlyMainPtr`, they must be declared before it, otherwise they are destroyed before it i.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4854964
      
      fbshipit-source-id: 625a8f890bba166b682ca13558f8bcde86edcc75
      5c04f9ac
    • Louis Brandy's avatar
      fix EvictingCacheMap test bug found w/ -fsanitize-address-use-after-scope · 6ea7629b
      Louis Brandy authored
      Summary: This test actually stores references to `sum` in objects it puts into the `EvictingCacheMap`. Those references get accessed in the destructor of the objects, which is the destructor of the `EvictingCacheMap`. That means the `sum` variable must outlive (and be declared -before-) the `EvictingCacheMap` it's testing.
      
      Reviewed By: yfeldblum, meyering
      
      Differential Revision: D4854619
      
      fbshipit-source-id: b0a3109278f48d10b4cd0c52a12cb2064f4a00c5
      6ea7629b
  6. 07 Apr, 2017 2 commits
    • Anirudh Ramachandran's avatar
      Fix leak in HMAC_CTX_free compat API · 9620aea0
      Anirudh Ramachandran authored
      Summary:
      D4406876 replaced EVP_MD_CTX and HMAC_CTX on the stack with heap-allocated
      versions. We omitted the _cleanup functions thinking those didn't actually free
      anything, but turns out HMAC_CTX_cleanup internally calls EVP_MD_CTX_cleanup
      which OPENSSL_frees a bunch of stuff.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4850388
      
      fbshipit-source-id: 4ef1413a4105f3638140e4d12aeae64afe43f099
      9620aea0
    • Phil Willoughby's avatar
      Fix a logic error in StringKeyedTest · 905ba447
      Phil Willoughby authored
      Summary: Make sure that the last use of `s6` is sequenced before it is moved-from.
      
      Reviewed By: nbronson
      
      Differential Revision: D4850480
      
      fbshipit-source-id: 5272c14475ae2c62bc613cfd54f5df482b19d3dc
      905ba447
  7. 06 Apr, 2017 4 commits
    • Alan Frindell's avatar
      Get rid of try/catch in messageAvailable, which is now noexcept · 3a7d377d
      Alan Frindell authored
      Summary: The problem with catching the exception here is stack information is lost.  Just let it std::terminate if it throws
      
      Reviewed By: ikobzar
      
      Differential Revision: D4831909
      
      fbshipit-source-id: 42139bd7caee0fedff13328d52fa3be1c517e730
      3a7d377d
    • Andrii Grynenko's avatar
      Require registrationComplete() not only in dbg builds · 1b6b202c
      Andrii Grynenko authored
      Summary: Improve error message and change DFATAL to FATAL.
      
      Reviewed By: yfeldblum, meyering
      
      Differential Revision: D4837840
      
      fbshipit-source-id: 54ae53c9356fc2e85266b037996aa7b2bae3d4e4
      1b6b202c
    • Phil Willoughby's avatar
      Update StringKeyed... benchmarks to tell the whole story · dc235503
      Phil Willoughby authored
      Summary:
      Benchmark each type with its native key type and with its non-native key type.
      This allows you to make a more-informed decision about which to use based on
      the types you have available at insertion/lookup time.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4826527
      
      fbshipit-source-id: ee4ef5255d2bdd955e9deb30dc4c28be183cee07
      dc235503
    • Maged Michael's avatar
      IndexedMemPool: Fix race condition on size_ that can cause the destructor to... · bba519bf
      Maged Michael authored
      IndexedMemPool: Fix race condition on size_ that can cause the destructor to access nonexistent slots
      
      Summary:
      Contention on allocation when there is exactly one slot remaining can cause size_ to exceed actualCapacity_.
      Without taking the min of size_ and actualCapacity_ the destructor may try to destroy out-of-bound slots.
      
      Added a test to test/IndexedMemPoolTest.cpp that failed before the fix and passes after the fix.
      
      Reviewed By: nbronson
      
      Differential Revision: D4837251
      
      fbshipit-source-id: a887487727f17eaf2ba66345f40fc91d2fe3bc00
      bba519bf
  8. 05 Apr, 2017 3 commits
    • Alan Frindell's avatar
      Make NotificationQueue::Consumer::messageAvailable noexcept · 674533ad
      Alan Frindell authored
      Summary: There's a comment in that code that states that it *it* noexcept, and that is common for most folly async io callbacks.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4831800
      
      fbshipit-source-id: 78894ad72504b9dfe540c14b8d7bbb29247aaf87
      674533ad
    • Subodh Iyengar's avatar
      Add trimAtMost functions · 120cc11d
      Subodh Iyengar authored
      Summary:
      Add trimAtMost start and trimAtMost end.
      These are useful functions to have if you
      don't care about trimming an exact amount.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4658087
      
      fbshipit-source-id: f7dd62c0f4837503e59cdec75fdad433be20306c
      120cc11d
    • Christopher Dykes's avatar
      Disable EnvUtil::setAsCurrentEnvironment() on platforms without clearenv() · 2d2d3d3f
      Christopher Dykes authored
      Summary:
      Implementing `clearenv()` correctly on multiple OS's without relying on underlying implementation details is significantly more complicated, and this is preventing being able to build on OSX.
      This function isn't actually used anywhere currently.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4832473
      
      fbshipit-source-id: a80aabb5a223264746ab45e3138d065bce5fe99c
      2d2d3d3f
  9. 04 Apr, 2017 1 commit