1. 18 Jan, 2017 1 commit
  2. 16 Jan, 2017 3 commits
    • Christopher Dykes's avatar
      Drop unneeded Pthread include · b2dd1005
      Christopher Dykes authored
      Summary: It was killed in an earlier diff.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4418832
      
      fbshipit-source-id: c9a5134fa100b24a3394607dea20e6e8a8d341e1
      b2dd1005
    • Christopher Dykes's avatar
      Don't use Pthread in EventBase · 01f97980
      Christopher Dykes authored
      Summary:
      Pthread is currently a dependency of Folly that is not really necessary on Windows, or even with standard C++ for the most part, so start work on killing it in Folly.
      This switches EventBase to using `std::thread::id`'s instead, which also means we aren't reliant on the implementation detail that thread id 0 is invalid. Well, we are, but it's now the standard library's fault not ours.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4418128
      
      fbshipit-source-id: a9c95ac6c7305c960156a4ad684b6db89b5856d9
      01f97980
    • Christopher Dykes's avatar
      Support setting thread name via std::thread::id · f57ddfc7
      Christopher Dykes authored
      Summary: It's possible via some hackery, so wrap it up nicely into the API.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4418728
      
      fbshipit-source-id: f00aed95cdbdc3cc83a0ab96565117cd01141c2e
      f57ddfc7
  3. 14 Jan, 2017 1 commit
  4. 13 Jan, 2017 4 commits
    • Marcus Holland-Moritz's avatar
      Protect memcpy calls against undefined behaviour · b0c9ca0f
      Marcus Holland-Moritz authored
      Summary:
      While running a UBSan enabled binary, I got:
      
        folly/io/IOBuf.cpp:671:15: runtime error: null pointer passed as argument 2, which is declared to never be null
      
      This change protects all calls to memcpy from passing `nullptr`.
      
      Reviewed By: pixelb
      
      Differential Revision: D4415355
      
      fbshipit-source-id: a27ba74244abcca8cd4e106967222890a67f5b6d
      b0c9ca0f
    • Jim Meyering's avatar
      folly/Traits.h: fix a deep problem with FBVector · 73199d4c
      Jim Meyering authored
      Summary:
      This started when many fbvector-related tests began failing with reports of
      ASAN-detected heap abuse (usually invalid free of an address 16 bytes
      into an already-freed buffer).
      
      It was very specific, though. The bug struck only when:
        - gcc-5-based platform
        - compiling with clang (~3.8) and GCC5's libstdc++, not gcc
        - strings were short enough to reside within an in-situ std::string
      
      Why? because FBVector.h:1588's conditional:
      
        if (folly::IsRelocatable<T>::value && usingStdAllocator::value) {
      
      was true for clang (erroneously), but false for gcc. The difference
      was in `IsRelocatable<std::string>::value`.  However, manual tests showed that
      each component from the definition of `IsRelocatable` were the same for both
      gcc and clang. Then Jay Feldblum realized that we'd probably specialized
      that trait for `std::string`, and sure enough, I found the culprit:
      
      ```
      FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string)
      ```
      
      Reviewed By: pixelb
      
      Differential Revision: D4414159
      
      fbshipit-source-id: 60e3fb4b096ec77cbd2b48c561e5c6ec8f128fff
      73199d4c
    • Eric Niebler's avatar
      capture exception information when creating exception_wrapper · 0e7c824d
      Eric Niebler authored
      Summary:
      prefer creating an exception_wrapper with a reference to the active exception
      
      Depends on D4410421
      
      Reviewed By: spacedentist
      
      Differential Revision: D4410455
      
      fbshipit-source-id: d6b6aeb5fa72782e31d754a0b853514af5fdb8cd
      0e7c824d
    • Dave Watson's avatar
      Add AsyncSSLSocket option to turn off transparent tls · 1e531547
      Dave Watson authored
      Summary: Folly parts of D4383906.
      
      Reviewed By: plapukhov
      
      Differential Revision: D4387254
      
      fbshipit-source-id: 3c039720c88c91b7292d60a85272dd1978510296
      1e531547
  5. 11 Jan, 2017 2 commits
    • Yedidya Feldblum's avatar
      Slight simplification of exception_wrapper constructor · f144d224
      Yedidya Feldblum authored
      Summary: [Folly] Slight simplification of `exception_wrapper` constructor.
      
      Reviewed By: ericniebler
      
      Differential Revision: D4391899
      
      fbshipit-source-id: ddb066723bcd10abb0dbbaeab12b1e9be4f39acc
      f144d224
    • Subodh Iyengar's avatar
      add an option to clear error before calling ssl methods · 3a8c98ea
      Subodh Iyengar authored
      Summary:
      Normally clearing out the error before calling into an openssl method
      is a bad idea. However there might be other code outside AsyncSSLSocket
      calling into openssl in the same thread that doesn't use openssl
      correctly. This allows users of AsyncSSLSocket to safeguard themselves
      from such code.
      
      Reviewed By: anirudhvr
      
      Differential Revision: D4389970
      
      fbshipit-source-id: 12da254d6b281c2b9d522ba19999b2489c0083a2
      3a8c98ea
  6. 10 Jan, 2017 4 commits
    • Yedidya Feldblum's avatar
      Fix an inefficiency in json-serializing a dynamic with sorted keys · 266c8377
      Yedidya Feldblum authored
      Summary:
      [Folly] Fix an inefficiency in json-serializing a `dynamic` with sorted keys.
      
      The inefficiency is that, at each level of the `dynamic` which is map-typed, we effectively make a full copy of the `dynamic` object. This can be expensive.
      
      Reviewed By: Gownta
      
      Differential Revision: D4389671
      
      fbshipit-source-id: 223739397f913d3e65a421a9a4dcb089ec757ec6
      266c8377
    • kumagi's avatar
      fix typo in comments. s/unitialized/uninitialized/g · f47621ec
      kumagi authored
      Summary:
      `unitialized` seems to be typo.
      Closes https://github.com/facebook/folly/pull/538
      
      Reviewed By: igorsugak
      
      Differential Revision: D4397318
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: a2e6c665b4dfe95d769430405886b0725423aac2
      f47621ec
    • Yedidya Feldblum's avatar
      Rename exception_wrapper::getExceptionPtr to to_exception_ptr · cd058f18
      Yedidya Feldblum authored
      Summary:
      [Folly] Rename `exception_wrapper::getExceptionPtr` to `to_exception_ptr`.
      
      Make it clear that this will sometimes be an expensive operation. Using the word `to` evokes the possibility of an expensive conversion, while using the word `get` implies cheap access.
      
      Reviewed By: djwatson
      
      Differential Revision: D4391621
      
      fbshipit-source-id: 33ca051d9be5a6050ba9f30b20faee35b7e58afb
      cd058f18
    • Maged Michael's avatar
      Fix dynamic MPMCQueue tryObtainPromisedPushTicket() to prevent tryWriteUntil()... · 232f650c
      Maged Michael authored
      Fix dynamic MPMCQueue tryObtainPromisedPushTicket() to prevent tryWriteUntil() and writeIfNotFull() from blocking indefinitely for a matching read.
      
      Summary:
      The bug was reported by Alexander Pronchenkov in https://fb.facebook.com/groups/560979627394613/permalink/837052843120622/
      
      Under certain conditions a `tryWriteUntil()`--and also `writeIfNotFull()`--operation may block indefinitely awaiting a matching read. This could happen because in each dynamic MPMCQueue expansion, typically one or two tickets are associated with the closed array not the new one. In the incorrect code, a `tryWriteUntil()` operation that induced expansion but gets a ticket associated with the closed array, incorrectly assumes that because the expansion succeeded then there is space for it. However because the ticket is associated with the closed array, the operation needs to wait (possibly indefinitely) for space to open in the closed array.
      
      The fix: Changed the code in tryObtainPromisedPushTicket() such that the operation tries to acquire a ticket only if there is promised space in the array associated with that ticket. If there is no space, an expansion is attempted if the ticket is not associated with a closed array. If not or if expansion fails because of reaching maximum capacity or for being out-of-memory, then the operation returns false without attempting to acquire the ticket.
      
      Other changes:
      - Added a note about this difference in semantic between the dynamic and non-dynamic version to the main comment about the dynamic version.
      - Changed `oldCap` to `curCap` because the value is actually current not old.
      - Added two tests for checking that tryWriteUntil() never blocks indefinitely for both dynamic and non-dynamic versions.
      - Removed all the `never_fail` tests for the dynamic version, because such operations may fails as described above.
      - Added `asm_volatile_pause` when spinning on the seqlock.
      
      Reviewed By: djwatson
      
      Differential Revision: D4389347
      
      fbshipit-source-id: c46dbefc9fe08e146250d2ad8ba68b0887f97436
      232f650c
  7. 09 Jan, 2017 6 commits
    • Christopher Dykes's avatar
      Use 2 second loop smoothing period rather than 20 seconds · 410f652b
      Christopher Dykes authored
      Summary: This was accidentally changed in D4375539.
      
      Reviewed By: philippv
      
      Differential Revision: D4393574
      
      fbshipit-source-id: 0420223575bad0c6b0e89f8cf5ed138e063462b9
      410f652b
    • Kyle Nekritz's avatar
      Add pre received data API to AsyncSSLSocket. · 3a033f27
      Kyle Nekritz authored
      Summary: This allows something else (ie fizz) to read data from a socket, and then later decide to to accept an SSL connection with OpenSSL by inserting the data it read in front of future reads on the socket.
      
      Reviewed By: anirudhvr
      
      Differential Revision: D4325634
      
      fbshipit-source-id: 05076d2d911fda681b9c4e5d9d3375559293ea35
      3a033f27
    • Kyle Nekritz's avatar
      Set custom ssl bio read method. · f3c3434c
      Kyle Nekritz authored
      Summary: Similar to the bio write method. This should be essentially a no-op, bioRead has the same functionality as the openssl version. This is needed in the next diff.
      
      Reviewed By: siyengar
      
      Differential Revision: D4325622
      
      fbshipit-source-id: a90b9ec06bee920a1a73551a3ea4c77e1ee0ab08
      f3c3434c
    • Zonr Chang's avatar
      Include <errno.h> for using "errno" and ENOMEM. · 94dad222
      Zonr Chang authored
      Summary: Closes https://github.com/facebook/folly/pull/537
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4391871
      
      Pulled By: Orvid
      
      fbshipit-source-id: 80401dd65ae376f9ebbb0b079577d0a1fd15475b
      94dad222
    • Nick Wolchko's avatar
      Remove folly::Future conversion constructor · 22d54e0b
      Nick Wolchko authored
      Summary:
      This constructor is unsafe. The check it uses before doing the comparison isn't a safe enough check to see if the cast is valid. For example, this is broken in the presence of multiple inheritance because it doesn't adjust the pointer offset to the correct vtable.
      
      e.g.
        struct A {
          virtual ~A() {};
          virtual void doSomething() = 0;
        };
        struct B {
          virtual ~B() {}
          virtual void doSomethingElse() = 0;
        };
        struct C : public B, public A {
          virtual ~C() {}
          void doSomething() override {
            std::cout << "Something!" << std::endl;
          }
          void doSomethingElse() override {
            std::cout << "Something Else!" << std::endl;
          }
        };
        int main (int argc, char **argv) {
          auto c = folly::makeFuture<std::shared_ptr<C>>(std::make_shared<C>());
          folly::Future<std::shared_ptr<A>> a = std::move(c);
          a.get()->doSomething();
          return 0;
        }
      This code will print "Something else!" when run.
      
      Reviewed By: siyengar
      
      Differential Revision: D3679673
      
      fbshipit-source-id: dcbf40ca82d458f17ee11191591f8b8daf58c919
      22d54e0b
    • Michael O'Farrell's avatar
      Fix folly json to only sort properties of objects based on their key not value. · 05d3945f
      Michael O'Farrell authored
      Reviewed By: yfeldblum
      
      Differential Revision: D4386258
      
      fbshipit-source-id: 23499267eb4390f0f40b3643760514cae1ca7838
      05d3945f
  8. 08 Jan, 2017 2 commits
    • Igor Sugak's avatar
      remove always true if-predicate (gcc-5 -Wlogical-op) · 7895dc70
      Igor Sugak authored
      Summary:
      gcc-5 -Wlogical-op reports:
      ```lang=bash
      folly/io/async/AsyncSSLSocket.cpp: In member function 'void folly::AsyncSSLSocket::invalidState(folly::AsyncSSLSocket::HandshakeCB*)':
      folly/io/async/AsyncSSLSocket.cpp:418:35: error: logical 'or' of collectively exhaustive tests is always true [-Werror=logical-op]
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4391317
      
      fbshipit-source-id: c0f5ce748f1fc21678e4080c7f6351e7fada1e2b
      7895dc70
    • Eric Niebler's avatar
      add folly::as_const, like C++17's std::as_const · 3cec19d4
      Eric Niebler authored
      Summary: A one-liner from C++17, but a useful one. Const-qualifies an lvalue reference, avoiding the need for an awkward const_cast in some cases.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4389929
      
      fbshipit-source-id: 1650c4901489eb0dd62fd9fa633b4a0da9f01954
      3cec19d4
  9. 07 Jan, 2017 6 commits
    • Christopher Dykes's avatar
      Properly std::chrono'ize HHWheelTimer · 3cdd3857
      Christopher Dykes authored
      Summary: It was using `std::chrono::milliseconds` to represent a point in time, so use a time point instead.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4378116
      
      fbshipit-source-id: f0b10bb7894dda44d78b31672d2b6735f3e1cbf4
      3cdd3857
    • Christopher Dykes's avatar
      std::chrono'ize EventBase::loopBody · 77249d4d
      Christopher Dykes authored
      Summary: Because modern is good, and this allows for cleaner interaction with the other APIs being `std::chrono`ized.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4377773
      
      fbshipit-source-id: 42ad5ad8476a3678e02e9314f9592f5449102f00
      77249d4d
    • Christopher Dykes's avatar
      std::chrono'ize EventBase::setMaxLatency · aee08623
      Christopher Dykes authored
      Summary: Onward towards more modern code!
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4377678
      
      fbshipit-source-id: 6ca5ecd902be9028fb55f139374f7919fa522899
      aee08623
    • Yedidya Feldblum's avatar
      Remove <glog/logging.h> from folly/Indestructible.h · 8f22c4e3
      Yedidya Feldblum authored
      Summary:
      [Folly] Remove `<glog/logging.h>` from `folly/Indestructible.h`.
      
      This makes the header much lighter. And abort on invalid access (the use-case for `glog`) only in `!defined(NDEBUG)` mode.
      
      Anti-Pattern Combined Mega-Diff Description:
      * Add non-`explicit` default ctor.
      * Disable ctor explicitly when underlying ctor would fail to compile. Not sure how useful it would be, but it makes type-traits work correctly for whatever that is worth.
      * Switch boolean flag to `erased_{false}` so that it is zero-initializable, because that's better.
      
      Reviewed By: ericniebler
      
      Differential Revision: D4380469
      
      fbshipit-source-id: a39cb7470f7ee678fa722778da587409f468d985
      8f22c4e3
    • Eric Niebler's avatar
      add folly::void_t like C++17's std::void_t · e3974815
      Eric Niebler authored
      Summary:
      C++17 is adding std::void_t. It's handy for controlling class template partial specialization. Folly should have it too.
      
      See http://en.cppreference.com/w/cpp/types/void_t
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4387302
      
      fbshipit-source-id: 85f955f3d8cfacbd6c9e61fb3f5cf53c056459bb
      e3974815
    • Yedidya Feldblum's avatar
      Skip defined checks in folly/Memory.h · c5e6d87b
      Yedidya Feldblum authored
      Summary:
      [Folly] Skip `defined` checks in `folly/Memory.h`.
      
      Undefined symbols, when evaluated by the preprocessor in preprocessor integer contexts, evaluate to `0`. That works for these checks.
      
      Reviewed By: ericniebler
      
      Differential Revision: D4385026
      
      fbshipit-source-id: 3162f8b83431ebab2de53f9ba202e7ea8c339210
      c5e6d87b
  10. 06 Jan, 2017 6 commits
    • Zonr Chang's avatar
      __throw* functions seem to be available in LLVM 4.0 or above. · 084f9e18
      Zonr Chang authored
      Summary:
      __throw* functions exist in master branch but are not included in both
      libc++ 3.9.0 and 3.9.1. Expect them to appear in next LLVM release
      (which is 4.0).
      Closes https://github.com/facebook/folly/pull/536
      
      Reviewed By: yfeldblum, Orvid
      
      Differential Revision: D4377002
      
      Pulled By: smeenai
      
      fbshipit-source-id: 5dd311ca3ec43955f29dd1197fd8fbeb9564a7f6
      084f9e18
    • Christopher Dykes's avatar
      std::chrono'ize EventBase::setLoadAvgMsec · 02cae39d
      Christopher Dykes authored
      Summary: Modernization is good.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4377612
      
      fbshipit-source-id: adb03d8a92f25c8a792c8e7240a93ab20180b038
      02cae39d
    • Christopher Dykes's avatar
      std::chrono'ize EventBase::SmoothLoopTime · 7b4bb3f5
      Christopher Dykes authored
      Summary: Modernizing for the future.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4375539
      
      fbshipit-source-id: e3edf8dd6b77d3338f8cf58ed128bc5bce62da32
      7b4bb3f5
    • Igor Sugak's avatar
      fix gcc-5 build · f65d8d2c
      Igor Sugak authored
      Summary:
      ```lang=bash
      folly/test/SmallLocksBenchmark.cpp:212:18: error: use of undeclared identifier 'sqrt'
        double stdev = sqrt(accum / (results.size() - 1));
                       ^
      folly/test/SmallLocksBenchmark.cpp:221:20: error: use of undeclared identifier 'sqrt'
        double stddev2 = sqrt(variance);
                         ^
      2 errors generated.
      ```
      Add the missing header.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4386343
      
      fbshipit-source-id: 79c3dcae32c62f9b6d162862deabccf5fea7eaef
      f65d8d2c
    • Igor Sugak's avatar
      fix gcc-5 build · 36a9fc06
      Igor Sugak authored
      Summary:
      Clang with libgcc-5 reported:
      ```lang=bash
      folly/experimental/test/BitsTest.cpp:249:16: error: use of undeclared identifier 'pow'
        auto value = pow(2, bits) * (negate ? -2.0 : 2.0) / 3.0;
                     ^
      ```
      Add missing include statement, and elaborate with the namespace.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4385807
      
      fbshipit-source-id: a847dd439cd4c9f28ea8f222aa4ab60876949d13
      36a9fc06
    • Michael Lee's avatar
      make_unique is ambiguous with c++14 for some platforms · 918988e5
      Michael Lee authored
      Summary: Missing compatibility case for Android
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4384944
      
      fbshipit-source-id: 0b3e43fb284b6a71c6ae2a2162d1ea7cb99bc817
      918988e5
  11. 05 Jan, 2017 3 commits
    • Eric Niebler's avatar
      don't use assert in benchmarks. it gets stripped out in release mode. · 7ea05dfb
      Eric Niebler authored
      Summary: Critical tests in benchmarks should not be in asserts since they will be stripped out in release mode, which is the only mode interesting for benchmarks.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4384411
      
      fbshipit-source-id: 5237ab48f99ddcd2bce7a159fcf82900303efec2
      7ea05dfb
    • Yedidya Feldblum's avatar
      Namespace the UBSAN_DISABLE symbol · 9b7138e4
      Yedidya Feldblum authored
      Summary:
      [Folly] Namespace the `UBSAN_DISABLE` symbol.
      
      Symbols defined by Folly should typically be namespaced to Folly.
      
      Reviewed By: igorsugak
      
      Differential Revision: D4378401
      
      fbshipit-source-id: ff72f5f44e7c9d1bbf08efcec24bd3dc05d10ee7
      9b7138e4
    • Yedidya Feldblum's avatar
      Backport ceil, floor, round from C++17 std::chrono · cd578dbf
      Yedidya Feldblum authored
      Summary:
      [Folly] Backport `ceil`, `floor`, `round` from C++17 `std::chrono`.
      
      These functions for operating on `std::chrono::duration` and `std::chrono::time_point` values are useful
      
      Note: The implementations are derived from cppreference.com, which has a notice listing all content there as licensed under CC-BY-SA.
      
      Reviewed By: ericniebler
      
      Differential Revision: D4375603
      
      fbshipit-source-id: 36a098bf5f75db071c1670518fc42bbc6df2817d
      cd578dbf
  12. 04 Jan, 2017 2 commits
    • Yedidya Feldblum's avatar
      Keep the std::exception* or std::type_info* in folly::exception_wrapper · eaa278a5
      Yedidya Feldblum authored
      Summary:
      [Folly] Keep the `std::exception*` or `std::type_info*` in `folly::exception_wrapper`.
      
      In the case of construction with a `std::exception_ptr`. Instead of keeping a pair of `std::string`s, strictly losing information (not that we use any more information, but theoretically we could).
      
      Of note:
      * Shrinks the size of `folly::exception_wrapper`, in all cases, to 48 bytes. Down from 32 bytes + 2 S bytes on 64-bit architectures, where S is the size in bytes of `std::string`. In particular, `libstdc++`'s implementation is 32 bytes, while `libc++`'s and Folly's implementations are 24 bytes on 64-bit architectures, for total original sizes of 96 bytes or 80 bytes.
      * Allows to avoid rethrowing in `with_exception` in the case of an instance constructed with an `std::exception_ptr` plus an `std::exception&`.
      
      Reviewed By: ericniebler
      
      Differential Revision: D4369935
      
      fbshipit-source-id: 35155e0b271959a4878fe077fc911b17767a2358
      eaa278a5
    • Shoaib Meenai's avatar
      Add preprocessor macro to disable throw* definitions · dc938550
      Shoaib Meenai authored
      Summary:
      libc++ 4.0 and above define the throw* functions in `stdexcept`, so
      Folly doesn't need to define them itself. In case those definitions are
      backported to 3.9, add a Folly macro to skip the definitions regardless
      of the libc++ version number.
      
      Reviewed By: yfeldblum, Orvid
      
      Differential Revision: D4378102
      
      fbshipit-source-id: 674d98d7c448aa7e75bdd8b6e9fe965cd34a83d7
      dc938550