1. 08 Feb, 2018 2 commits
    • Jiawei Ou's avatar
      OpenSSL adaptor for OpenSSL1.1.0 · cd90eca5
      Jiawei Ou authored
      Summary: Implement some OpenSSL 1.1.0 specific methods, so that code written with OpenSSL 1.1.0 can be compiled with OpenSSL 1.0.2
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6930234
      
      fbshipit-source-id: 257893787cecdfeaf9df13dce0ada46c15990699
      cd90eca5
    • Maged Michael's avatar
      hazptr: Fix null domain_ dereference in ~hazptr_array · 8c0bca50
      Maged Michael authored
      Summary: Fix a case of null pointer dereference when ~hazptr_array() calls ~hazptr_holder(). For speed hazptr_array doesn't fill the domain_ field of hazptr_holder. The common case is that elements of the array are taken from and returned to the thread cache. If ~hazptr_array() doesn't find enough space in the thread cache, then it calls ~hazptr_holder() with a null domain_. The fix is to set domain_ to &default_hazptr_domain() before calling ~hazptr_holder() in such a case.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6928705
      
      fbshipit-source-id: 9c756dce2854a2d1869a0712c4e6ed30f5df6b30
      8c0bca50
  2. 07 Feb, 2018 7 commits
    • Yedidya Feldblum's avatar
      Work around UB signed-integer-overflow in Histogram · 72512e53
      Yedidya Feldblum authored
      Summary: [Folly] Work around UB `signed-integer-overflow` in `Histogram`.
      
      Reviewed By: igorsugak
      
      Differential Revision: D6922381
      
      fbshipit-source-id: 96ab6ffae9509ce8138f1741ea976226dec597c8
      72512e53
    • Yedidya Feldblum's avatar
      Fix UB signed-integer-overflow in tracing test · b8d7f18e
      Yedidya Feldblum authored
      Summary: [Folly] Fix UB `signed-integer-overflow` in tracing test.
      
      Reviewed By: igorsugak
      
      Differential Revision: D6922450
      
      fbshipit-source-id: 0d9a338fdcf205987d88875aac4112666ca32b65
      b8d7f18e
    • Fred Emmott's avatar
      add missing ifndef FOLLY_NO_CONFIG around include in folly/compression/Counters.cpp · 10a4cd2a
      Fred Emmott authored
      Summary: Needed to update folly in the open source build of HHVM.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6913772
      
      fbshipit-source-id: 50e540fe30651c991dc198ede66d4816a85f68db
      10a4cd2a
    • Adam Simpkins's avatar
      logging: suppress ASAN warnings about leaking the LoggerDB singleton · d2364be6
      Adam Simpkins authored
      Summary:
      During program destruction we destroy registered log handlers (to allow them to
      flush state if desired).  However we intentionally leak the LoggerDB object
      itself and the LogCategory objects it contains, so it will still be safe if
      static destruction code that runs later still tries to log messages.
      
      However, when run with `ASAN_OPTIONS` set to `detect_leaks=1` ASAN complains
      about the fact that we leak the LoggerDB singleton.
      
      This changes the code to store the LoggerDB address in a static variable, to
      prevent ASAN from complaining that we leak it.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6920772
      
      fbshipit-source-id: 62f6837053ba4a538a89b4b61f9b1c722f253d33
      d2364be6
    • Maged Michael's avatar
      folly] hazptr: Add hazptr_cleanup function · 2518ee52
      Maged Michael authored
      Summary: The free function hazptr_cleanup reclaims all reclaimable objects retired to a domain before this call.
      
      Reviewed By: djwatson
      
      Differential Revision: D6876253
      
      fbshipit-source-id: 54a6b98291712286597561e971fc9b6ac9c4d6f0
      2518ee52
    • Yedidya Feldblum's avatar
      Do nothing in spin_pause_until if spin_max is zero · 5ec4d977
      Yedidya Feldblum authored
      Summary:
      [Folly] Do nothing in `spin_pause_until` if `spin_max` is zero.
      
      Rather than go through the loop at all, if the instruction is not to spin - encoded as `spin_max <= 0` - then return early.
      
      Reviewed By: nbronson
      
      Differential Revision: D6910431
      
      fbshipit-source-id: fa94510e7ec1ebdd7bc3f1a407dcf70e1e153b40
      5ec4d977
    • Zekun Li's avatar
      use weak ref for event loop to avoid leaking it · 3b08af41
      Zekun Li authored
      Summary: This dict holds strong reference to all the loops and leads to leak if new loop is created and used, change it to weakref to avoid it.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6892775
      
      fbshipit-source-id: a628a3743876ef0580acce5fb9f283da573cf459
      3b08af41
  3. 06 Feb, 2018 8 commits
    • Adam Simpkins's avatar
      logging: add a default handler during early initialization · d81cde8f
      Adam Simpkins authored
      Summary:
      This updates the code to create a default LogHandler that logs to stderr when
      the main LoggerDB singleton is first created.  With this change users will get
      reasonable log behavior even if they never call `folly::initLogging()` (log
      messages will go to stderr instead of being ignored).
      
      This new initialization code can potentially run very early during program
      initialization (before `main()` starts and before folly `Singleton`
      initialization) if some code in the program logs messages before main.  However
      this current initialization code should be safe to run before main.
      
      For compilers that support weak symbols (clang and gcc), I have defined
      `initializeLoggerDB()` as a weak symbol, allowing users to override this
      behavior at link time on a per-program basis should they choose to.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6893207
      
      fbshipit-source-id: 13b72a01aa383c4611204df88ff8dad93abcc7b2
      d81cde8f
    • Michael Lee's avatar
      Remove the assertion that thread cache and private are enabled · b05a90dc
      Michael Lee authored
      Summary: With the mobile thread_local changes, these assertions are no longer correct.
      
      Reviewed By: magedm
      
      Differential Revision: D6915065
      
      fbshipit-source-id: 42072ed638b3dca56cba65ca0cff5e4d7aef2cb3
      b05a90dc
    • Adam Simpkins's avatar
      logging: update LoggerDB::get() to return a reference · 9656bacc
      Adam Simpkins authored
      Summary:
      Change `LoggerDB::get()` to a reference instead of a pointer since this
      function can never return null.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6893206
      
      fbshipit-source-id: af47063918a79c851fd39b838d6c63755166e033
      9656bacc
    • Adam Simpkins's avatar
      logging: disallow move construction/assignment for LogCategory · 18c4beb3
      Adam Simpkins authored
      Summary:
      LogCategory objects store pointers to their parent and sibling categories.  The
      address of each LogCategory therefore matters, and we cannot allow moving them
      to another address.
      
      Explicitly delete the move constructor and assignment operator to ensure that
      no-one ever accidentally tries to move a LogCategory object.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6893208
      
      fbshipit-source-id: 32f36c5992e850cc6e90d02c7c74fb758e9f745b
      18c4beb3
    • Adam Simpkins's avatar
      cmake: compile with -Wno-nullability-completeness · d7dfcff9
      Adam Simpkins authored
      Summary:
      When compiling with clang, also specify -Wno-nullability-completeness
      
      We currently use this flag for internal Facebook builds using buck.  This
      brings the CMake and buck compilation command lines closer in sync.  Even
      though the folly code currently does not produce any nullability completeness
      warnings, we are likely to break this in the future since we do not have
      this warning enabled internally.
      
      It also seems like `-Wnullability-completeness` results in code that cannot be
      compiled successfully across various clang versions.  Recent versions of clang
      complain about missing nullability specifiers on `std::unique_ptr` arguments,
      while slightly older clang versions produce compilation errors if nullability
      specifiers are listed on anything but raw pointers.
      
      Reviewed By: igorsugak
      
      Differential Revision: D6902930
      
      fbshipit-source-id: 0b8cd5eca17cf8f9deda6b0c32f5838489542128
      d7dfcff9
    • Alexey Spiridonov's avatar
      Enable IPv6 loopback for tests · 7c644897
      Alexey Spiridonov authored
      Summary:
      Unit tests using the IPv6 loopback would fail on Travis with `[::1]:0: Cannot assign requested address`.
      
      The issue is discussed at length here: https://github.com/travis-ci/travis-ci/issues/8711
      
      Reviewed By: jstrizich
      
      Differential Revision: D6914321
      
      fbshipit-source-id: c247c6760dddcd875a67f7b31419bde974514f19
      7c644897
    • Bennett Magy's avatar
      Added getShared function to Observer::Snapshot · d2604fb2
      Bennett Magy authored
      Summary:
      Added a function to Observer::Snapshot that allows the user to get the shared_ptr held in a snapshot. This is to make it easier to integrate Observers with other Api's that expect shared_ptrs.
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D6909245
      
      fbshipit-source-id: 4fe108e04f43a5a250bd7bdc3031994833d73a60
      d2604fb2
    • Yedidya Feldblum's avatar
      Hack around MSVC not supporting constexpr storage · 63fcb6c7
      Yedidya Feldblum authored
      Summary:
      [Folly] Hack around MSVC not supporting `constexpr` storage.
      
      GCC and Clang do, but MSVC does not, support:
      
      ```lang=c++
      extern int const num;
      constexpr int const num = 3;
      ```
      
      Work around it.
      
      Reviewed By: elsteveogrande
      
      Differential Revision: D6903413
      
      fbshipit-source-id: 3a0957816d8d82718fb6187dc1803df1605f80aa
      63fcb6c7
  4. 05 Feb, 2018 4 commits
    • Dave Watson's avatar
      Increase refcount size · 36f840db
      Dave Watson authored
      Summary:
      The refcounting logic is correct, however, decreasing the next node's
      refcount only happens in ~NodeT, after going through hazptr bulkReclaim.
      
      The current default for bulkReclaim is 1k, which exceeds the value of
      refcount uint8_t.  Increase size to uint16_t so that we don't wrap refcount
      before bulkReclaim calls the node destructors.
      
      Reviewed By: magedm
      
      Differential Revision: D6900530
      
      fbshipit-source-id: 9b2530dc6cd0609b4795b909fd46aeffbb1ae821
      36f840db
    • Adam Simpkins's avatar
      add a build status badge to the README · 8e8bfe9c
      Adam Simpkins authored
      Summary:
      Now that we have Travis CI builds enabled and passing, add a link to the build
      status to the README.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6903206
      
      fbshipit-source-id: 643b72a63a4113e00ff1602b1c3638384115b23d
      8e8bfe9c
    • Petr Lapukhov's avatar
      Add JSONPointer support · 6c653dc9
      Petr Lapukhov authored
      Summary:
      Allow retrieving sub-tree from folly::dynamic using JSON pointer syntax (RFC6901). This adds new overload for the `get_ptr` method, retrieving raw pointer to a sub-tree, or returning `nullptr` if element is not found.
      
      The `folly::dynamic` implementation traverses the path specified by JSON pointer string dynamically every time, since the underlying object may change, and JSON pointer traversal depends on the underlying object structure. E.g. "123" could be a key name for `dynamic::object` and index in `dynamic::array`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6790515
      
      fbshipit-source-id: bb6ea10acb83673e87721cf1e5a02506b44bb273
      6c653dc9
    • Igor Kobzar's avatar
      fbcode_builder: Update cmake for debian 8.6 os image · 32a318c7
      Igor Kobzar authored
      Summary: Debian 8.6 comes with a CMake version that is too old for folly. Add commands to update cmake.
      
      Reviewed By: snarkmaster
      
      Differential Revision: D6842797
      
      fbshipit-source-id: 22f4c407f82a92c3fa90a5c2de334cf8b92e584b
      32a318c7
  5. 03 Feb, 2018 2 commits
    • Adam Simpkins's avatar
      disable function_scheduler_test on cmake-based builds · fe3444b4
      Adam Simpkins authored
      Summary:
      Unfortunately it looks like D6880256 was not sufficient to make
      function_scheduler_test pass reliably on Travis CI builds.  This just disables
      function_scheduler_test on open source CMake-based builds for now.
      
      Ideally in the future we should try to convert most of the function scheduler
      to use proper synchronization mechanisms (like folly::Baton) for synchronizing
      between threads, rather than sleeping and expecting the other thread to have
      completed its work before we wake up.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6891889
      
      fbshipit-source-id: 9ee98f5807e1d90f083bd942ba98df6fad656ba6
      fe3444b4
    • Adam Simpkins's avatar
      logging: support stripping directory prefixes from file names · 21d80675
      Adam Simpkins authored
      Summary:
      The XLOG() macros compute the log category based on the source file name, as
      defined by `__FILE__`.  Both gcc and clang set the `__FILE__` contents to the
      file name passed in on the command line, so if they are invoked with absolute
      path names `__FILE__` will contain an absolute path.  This is normally
      undesirable for `XLOG()` behavior.  Furthermore, CMake always invokes the
      compiler with absolute path names, so it is difficult to avoid this situation
      in open source builds.
      
      This adds support for a `FOLLY_XLOG_STRIP_PREFIXES` macro.  This can be defined
      to a string containing a colon-separated list of directory prefixes to strip
      from `__FILE__` before using it to compute the log category name.  If
      `FOLLY_XLOG_STRIP_PREFIXES` is not defined then the code continues to use
      `__FILE__` as-is.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6868773
      
      fbshipit-source-id: a5c3276d8d22d3b27ae621700a75b1362d049292
      21d80675
  6. 02 Feb, 2018 13 commits
    • Adam Simpkins's avatar
      FunctionSchedulerTest: increase timeFactor to 400ms · 42ec19da
      Adam Simpkins authored
      Summary:
      Many of the tests in FunctionSchedulerTest appear to frequently fail on
      Travis CI builds.  It looks like this is probably due to timing issues where
      events do not fire within the expected time interval.
      
      This diff increases the `timeFactor` value to hopefully make the tests more
      reliable, at the expense of making them take longer to run.
      
      It would be nicer if we had a better solution here that did not involve
      potentially unreliable timing-dependent checks.  Increasing `timeFactor` seems
      like the easiest solution in the short-term though, and avoids just disabling
      the tests entirely.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6880256
      
      fbshipit-source-id: 59da3b20f2bb9c982834752942a984e3f91442fd
      42ec19da
    • Adam Simpkins's avatar
      FunctionSchedulerTest: honor timeFactor correctly · c7ad653c
      Adam Simpkins authored
      Summary:
      Most of the tests in FunctionSchedulerTest sleep for lengths of time based on
      the timeFactor constant set at the top of the file.  However a couple of places
      that need to sleep for non-integral timeFactor durations used manual `usleep()`
      calls instead.  This made the tests break if you change the `timeFactor` value.
      
      This changes `delay()` to accept floating point numbers, and updates the tests
      that were using hard-coded `usleep()` calls to use `delay()` instead.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6880258
      
      fbshipit-source-id: 0cfdf84d3ba27aa2acd1f5210becbc7306b857bf
      c7ad653c
    • Adam Simpkins's avatar
      use atomic variables correctly in FunctionSchedulerTest · 4b34bc38
      Adam Simpkins authored
      Summary:
      Most of the tests in FunctionSchedulerTest update a variable in one thread (the
      FunctionScheduler thread) and then check its value in the main thread.  These
      previously were not using any synchronization between the threads.  This fixes
      them to use `std::atomic` to ensure proper synchronization.
      
      Reviewed By: wez
      
      Differential Revision: D6880254
      
      fbshipit-source-id: facfbdf06312f731c64389fb4382b5cb078b76b9
      4b34bc38
    • Flarnie Marchan's avatar
      Add `CONTRIBUTING` and `CODE_OF_CONDUCT` · 7c4b550e
      Flarnie Marchan authored
      Summary:
      Hi! I noticed this repo could use some documentation to help new contributors.
      
      **why make this change?:**
      Regarding the `CONTRIBUTING.md` -> Including instructions for new contributors to open source is a courtesy that will foster a welcoming and safe open source community at Facebook.
      
      Regarding the Code of Conduct ->
      
      Facebook Open Source provides a Code of Conduct statement for all
      projects to follow, to promote a welcoming and safe open source community.
      
      Exposing the COC via a separate markdown file is a standard being
      promoted by Github via the Community Profile in order to meet their Open
      Source Guide's recommended community standards.
      
      As you can see, adding this file will improve [the folly community profile](https://github.com/facebook/folly/community)
      checklist and increase the visibility of our COC.
      
      Closes https://github.com/facebook/folly/pull/719
      
      Reviewed By: flarnie
      
      Differential Revision: D6881011
      
      Pulled By: simpkins
      
      fbshipit-source-id: a6f0988ac2b49f81bb13d3219095105b7b27e66f
      7c4b550e
    • Adam Simpkins's avatar
      add constexpr_strcmp() · 754ee1bc
      Adam Simpkins authored
      Summary: Add a constexpr implementation of `strcmp()`
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6881816
      
      fbshipit-source-id: 08a9e5ab9ef4a422ff6d004ec13b8ec8c71b0d6f
      754ee1bc
    • Adam Simpkins's avatar
      minor tweaks to constexpr_strlen() definition · 4464999f
      Adam Simpkins authored
      Summary:
      - Use `FOLLLY_HAS_FEATURE(cxx_constexpr_string_builtins)` to check for the
        availability of `__builtin_strlen()` on clang, as recommended by the clang
        documentation (https://clang.llvm.org/docs/LanguageExtensions.html)
      - Only use `std::strlen()` on gcc, rather than having checks to exclude all
        other compilers.  `strlen()` happens to be constexpr on gcc, but this is not
        required by the standard and cannot be assumed to be true in general.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6881815
      
      fbshipit-source-id: 88c614419ae390464893087513dc764b0bfddfb8
      4464999f
    • Michael Lee's avatar
      Mark io/async/test/certs as a content dir for ssl_session_test · 30ad7fa1
      Michael Lee authored
      Summary:
      This test has been failing in travis because it is missing test/certs/tests-cert.pem
      Mark it as a content dir
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6884000
      
      fbshipit-source-id: c7d42a4b23334781de28f1586ecbde04aea74ff2
      30ad7fa1
    • Adam Simpkins's avatar
      update the README to document building with cmake · 67f63db7
      Adam Simpkins authored
      Summary:
      Update the build steps in the README to build using cmake instead of autoconf
      on Linux platforms.
      
      I haven't updated the instructions for Mac OS X or the
      `bootstrap-osx-homebrew.sh` script primarily because I have not tested the
      steps on Mac.  It sounds like the build is close to working on Mac, but
      currently fails due to missing compiler flags to disable some warnings on
      clang.
      
      Reviewed By: akushner
      
      Differential Revision: D6780814
      
      fbshipit-source-id: 9c9c211c306d5b35235549ae451bb620098f37e3
      67f63db7
    • Adam Simpkins's avatar
      cmake: run all tests from the root of the repository · 50f439af
      Adam Simpkins authored
      Summary:
      Update the CMake build process to always invoke test programs from the root of
      the repository.  This makes the CMake build consistent with how we run tests
      internally at Facebook.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6880257
      
      fbshipit-source-id: 4c27cc643faa21d9c26faf8c77f6700ec5fe6393
      50f439af
    • Lee Howes's avatar
      Fix for deferredexecutor behaviour. · 49cf5372
      Lee Howes authored
      Summary: DeferredExecutor suffered from a case where boosting would not work if no work was present. This change modifies is so that on a call to via the next executor will be set in the DeferredExecutor. When add is called the callback will be stored. Whichever happens second actually enqueues the work on the chained executor. get uses via to correctly implement this.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D6663244
      
      fbshipit-source-id: 74600d511373e0f6f7ca4128f25f3947a4981200
      49cf5372
    • Michael Lee's avatar
      Disable thread_local for all mobile targets · 3c49c7d6
      Michael Lee authored
      Summary: Android also has limited support for thread_local so we should not enable it at all as a precaution
      
      Reviewed By: magedm
      
      Differential Revision: D6884145
      
      fbshipit-source-id: f39dd8fd5405ca0bc5be9b3538718a6f58058442
      3c49c7d6
    • Andrii Grynenko's avatar
      Simplify EventBaseLoopController · 5359a760
      Andrii Grynenko authored
      Summary: Make EventBaseLoopController not dependent on EventBase's runOnDestruction. This will allow us to make FiberManager work with any Executor.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6828478
      
      fbshipit-source-id: 4d74776044a02954d022ef6f6f1e6834839973b8
      5359a760
    • Adam Simpkins's avatar
      remove duplicate FunctionSchedulerTest · 425c8833
      Adam Simpkins authored
      Summary:
      FunctionSchedulerTest.cpp was unfortunately copied into folly twice in separate
      locations.  D1845525 moved it into `folly/test`, D2051557 moved it into
      `folly/experimental/test`
      
      The version in `folly/experimental/test` has had several updates and new tests
      added; the version in `folly/test` has had no significant changes since it was
      first added.
      
      This diff deletes the older copy in `folly/test`
      
      Differential Revision: D6880255
      
      fbshipit-source-id: 8a4d5f6421ec18b319ffd76f98915e925b407468
      425c8833
  7. 01 Feb, 2018 4 commits
    • Michael Lee's avatar
      Unconditionally disable thread_local in hazard pointer when on mobile · be9e8ce5
      Michael Lee authored
      Summary:
      Sometimes the compiler lies to us and says it supports thread_local when it is not always fully implemented.
      
      Unconditionally disable this when `FOLLY_MOBILE` is set
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6875230
      
      fbshipit-source-id: 051f79eac78da03973bad9090b6577393b88998b
      be9e8ce5
    • Adam Simpkins's avatar
      cmake: mark the async_test as BROKEN for now · caed689d
      Adam Simpkins authored
      Summary:
      Disable running the async_test in open source builds.  A few of the tests
      functions in this binary are flaky.
      
      Additionally, this test consistently hangs in Travis CI builds.  It hangs in
      `AsyncSocketTest.ServerAcceptOptions`; I suspect it never sees the socket
      accept event and therefore never breaks out of the loop.  I suspect that even
      if we fixed this test other subsequent tests would also hang.  We should
      ideally update all of the tests to always have their own internal event base
      loop timeout rather than potentially looping forever, so it could at least run
      other test functions after a hang like this.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6874011
      
      fbshipit-source-id: 46c07a1cf3216eda1900e214447e6e49b6c8e489
      caed689d
    • Yedidya Feldblum's avatar
      Move invoke helpers into a special detail namespace · 2cd9535c
      Yedidya Feldblum authored
      Summary:
      [Folly] Move `invoke` helpers into a special detail namespace.
      
      So that code in `namespace folly::detail` can use `invoke_result`, etc., unqualified.
      
      Reviewed By: aary
      
      Differential Revision: D6869406
      
      fbshipit-source-id: 1b0ebbfb16621cf7e32c0f89162a19410a70605a
      2cd9535c
    • Adam Simpkins's avatar
      update CI scripts to run ctest with `--output-on-failure` · 047b8261
      Adam Simpkins authored
      Summary:
      Update our continuous integration configuration files to invoke ctest with the
      `--output-on-failure` flag so it will print the output of all tests that fail.
      Without this flag it is rather difficult to debug test failures in CI.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6869299
      
      fbshipit-source-id: 02d2e1ac03f786034b20797d02e9c3aa64c1b30b
      047b8261