1. 17 Mar, 2021 2 commits
    • Aaryaman Sagar's avatar
      Add options to disable gflags to folly::InitOptions · f8c901f5
      Aaryaman Sagar authored
      Summary:
      As title.  CLI applications that don't use gflags might not care about
      process-wide gflags, so add an option to kill it.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27066900
      
      fbshipit-source-id: d412391879cd5ac89eba5903fd033775cf0ca49a
      f8c901f5
    • Lee Howes's avatar
      Make getGlobalIOExecutor return a KeepAlive<IOExecutor> · 31477657
      Lee Howes authored
      Summary: By returning a generic KeepAlive<> the global IO executor was losing the IOExecutor interface. This fixes it by returning the right type.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27061083
      
      fbshipit-source-id: d57f67982c3467a6b814b17e851e4513ffd33502
      31477657
  2. 16 Mar, 2021 5 commits
    • Yedidya Feldblum's avatar
      reset_once · 47ed7d6e
      Yedidya Feldblum authored
      Summary: Add `reset_once`, a mechanism to reset a `once_flag`.
      
      Reviewed By: Mizuchi
      
      Differential Revision: D27071246
      
      fbshipit-source-id: 4824782fb0ce6380b72e3e657e6f5073029eaf14
      47ed7d6e
    • Yedidya Feldblum's avatar
      keep_sink · ee776518
      Yedidya Feldblum authored
      Summary: A helper for use with check functions using `FOLLY_KEEP`.
      
      Reviewed By: luciang
      
      Differential Revision: D27072070
      
      fbshipit-source-id: 9c106ca1e0854b0f16453e8ad73d7001c3b7fff6
      ee776518
    • Yedidya Feldblum's avatar
      fix safe-assert test link failures without weak symbols · f4f864ef
      Yedidya Feldblum authored
      Reviewed By: luciang
      
      Differential Revision: D27071414
      
      fbshipit-source-id: 8bbe12e8f8264f2040c030e0353e1e4d59efae55
      f4f864ef
    • Jason Rahman's avatar
      Remove setZeroCopy() override · bda140dc
      Jason Rahman authored
      Summary:
      When folly::AsyncSSLSocket is used in unencrypted mode, zero copy is
      possible due to OpenSSL being bypassed, but the setZeroCopy() override in
      AsyncSSLSocket prevents zero copy from being used. Remove the override (no
      callers currently check the return value anyway).
      
      Reviewed By: yfeldblum, yqz, jalatif
      
      Differential Revision: D27044720
      
      fbshipit-source-id: ec402ad2badb84150ecd1b7639770a49e16e9183
      bda140dc
    • Oleg Osovitskiy's avatar
      Add CoInvokeWithoutArgs googletest helper · eef86a25
      Oleg Osovitskiy authored
      Summary: Add `CoInvokeWithoutArgs` helper, coroutine-aware version of `InvokeWithoutArgs`
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27060013
      
      fbshipit-source-id: 8024a5818fbe7759d3f9827d260c4e7370444bb0
      eef86a25
  3. 15 Mar, 2021 3 commits
    • Yedidya Feldblum's avatar
      deprecate try_and_catch taking explicit types · 29de57bd
      Yedidya Feldblum authored
      Summary: Encourage new uses to use the overload which does not take an explicit list of exception types.
      
      Reviewed By: aary
      
      Differential Revision: D27041702
      
      fbshipit-source-id: aa808bb432c2aea6e2c1cb10d76f2492875bae93
      29de57bd
    • Dan Melnic's avatar
      Fix -Werror,-Wshadow-uncaptured-local errors · 9a474aec
      Dan Melnic authored
      Summary: Fix -Werror,-Wshadow-uncaptured-local errors
      
      Reviewed By: yfeldblum, iahs
      
      Differential Revision: D27052090
      
      fbshipit-source-id: 843bf9374ff16bfe422ef78e889f1c1286335c1a
      9a474aec
    • Yedidya Feldblum's avatar
      revise FOLLY_SAFE_CHECK · b4f7d822
      Yedidya Feldblum authored
      Summary:
      Principally, this change shrink the code generated by `FOLLY_SAFE_CHECK` by:
      * Moving the literal arguments which would be passed to the backing functions into a constexpr data structure and passing only a pointer to that data structure.
      * Passing all the arguments through via C variadic arguments rather than inlining the sequence of calls to handle them into the caller.
      
      Reviewed By: swolchok, luciang
      
      Differential Revision: D26996101
      
      fbshipit-source-id: 61c39c08758a9de28ba0cfd342b174185e80ad9f
      b4f7d822
  4. 14 Mar, 2021 1 commit
    • Yedidya Feldblum's avatar
      let some thunk members take variadic args · 55dfcb03
      Yedidya Feldblum authored
      Summary: In particular, let `make` and `ctor` take variadic arguments since there is no cost.
      
      Reviewed By: iahs
      
      Differential Revision: D27024839
      
      fbshipit-source-id: 805c65fdc79f60af1256a4c36be94bb22c163bdd
      55dfcb03
  5. 13 Mar, 2021 3 commits
    • Yedidya Feldblum's avatar
      thunk::noop<...> · 6329dbd5
      Yedidya Feldblum authored
      Summary: So that downstream locations do not have to write their own noop functions.
      
      Reviewed By: iahs
      
      Differential Revision: D27022664
      
      fbshipit-source-id: e8f69c7babf853a71dedd24ded59c5017cf18ad6
      6329dbd5
    • Yedidya Feldblum's avatar
      expand the erased_unique_ptr facility · b3cbe1d5
      Yedidya Feldblum authored
      Summary:
      The interface:
      
        erased_unique_ptr
        to_erased_unique_ptr
        make_erased_unique
        copy_to_erased_unique_ptr
        empty_erased_unique_ptr
      
      Reviewed By: iahs
      
      Differential Revision: D26980776
      
      fbshipit-source-id: c520993a2191e7f74c5056a4854e2b85731a09a0
      b3cbe1d5
    • Yedidya Feldblum's avatar
      avoid snprintf in Elf code · 63ee5137
      Yedidya Feldblum authored
      Summary: `snprintf` may not be async-signal-safe, but Elf code is intended for use in signal handlers.
      
      Reviewed By: luciang
      
      Differential Revision: D27000080
      
      fbshipit-source-id: 818f48787b5712b7334eca782e18c71c17d03361
      63ee5137
  6. 12 Mar, 2021 6 commits
  7. 11 Mar, 2021 5 commits
    • Roger Kim's avatar
      Replace if-statements with `if constexpr` statements · e741d8ef
      Roger Kim authored
      Summary:
      We have found that BitVectorCoding.h incorrectly outputs
      -Wdivision-by-zero errors when another file that includes it fails to compile.
      In the absence of other compilation errors, the -Wdivision-by-zero error does
      not appear (since the compiler correctly can tell that "division by zero" is
      not an issue in the code).
      
      In order to get rid of these erroneous error logs, we decided to replace the
      if-statements that surround the divisions (and check that the divisor is not
      zero) with `if constexpr` statements since those will stop the compiler from
      mistakenly thinking that division by zero is possible.
      
      Reviewed By: ot, philippv, luciang
      
      Differential Revision: D26961916
      
      fbshipit-source-id: f65ef6d7782c94e58d6d28b9f8b053f205e3b7c1
      e741d8ef
    • Srivatsan Ramesh's avatar
      A new NotificationQueue without read limit for server responses · 28799ed1
      Srivatsan Ramesh authored
      Summary: Using a separate queue for server replies without any limit on the number of items read at once.
      
      Differential Revision: D26612326
      
      fbshipit-source-id: d56c892c87bafa701c12b6da780e9b2d4710ee2c
      28799ed1
    • Giuseppe Ottaviano's avatar
      Make parseTo work with arbitrary string types · db94b222
      Giuseppe Ottaviano authored
      Summary: `to<T>` already works in simple cases when `IsSomeString<T>`; by generalizing `parseTo` any string-like `T` gets full functionality without having to copy-paste the overload.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26831450
      
      fbshipit-source-id: c09629bb7173dde1e0986654128b8e1d7c48b9ba
      db94b222
    • Brandon Schlinker's avatar
      Stop relying on net_tstamp.h in AsyncSocket · e9d7342e
      Brandon Schlinker authored
      Summary:
      `net_tstamp.h` is incomplete on some platforms, particularly OSS.
      
      One option would be to make `FOLLY_HAVE_SO_TIMESTAMPING` conditional on all of the timestamp flags being present. However, I'm instead going to just decouple this support from the underlying platform's headers.
      
      Reviewed By: rsunkad
      
      Differential Revision: D26971541
      
      fbshipit-source-id: 01b24f57ab827aca42889138e4cca4d488ae0940
      e9d7342e
    • Lee Howes's avatar
      Remove default argument for SerialExecutor::createUnique · df81d76c
      Lee Howes authored
      Summary: Remove the default argument for the deprecated createUnique operation for SerialExecutor.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26916321
      
      fbshipit-source-id: e6fb1766bfaae4d6e702982c5527d483e6d8c036
      df81d76c
  8. 10 Mar, 2021 4 commits
    • Yedidya Feldblum's avatar
      fix to_ascii under 32-bit msvc builds · 14c99ce6
      Yedidya Feldblum authored
      Summary:
      Under gcc and clang, we use the intrinsic `__builtin_clzll`. This builtin is available regardless of whether the `clz` instruction is available on the target platform - when it is, the backend chooses it; when it is not, the backend emits emulation code.
      
      Under msvc, the builtin is `__lzcnt64`. However, this builtin is available only in x64 builds; there is no fallback to emulation code, and 32-bit builds fail to compile.
      
      Differential Revision: D26918251
      
      fbshipit-source-id: a4d9c199f632c5a210bd6fd8782d327f7aac774e
      14c99ce6
    • Jason Fried's avatar
      get_running_executor a modern alternative · 749f7a4b
      Jason Fried authored
      Summary:
      In the long term I want to force all usage of get_executor to require that the call comes from a running asyncio eventloop as its safer/saner than allowing the default un-running loop to be used since it may never actually run.  Until then I have created get_running_executor that I can use in various places. When get_running_executor(True) is used everywhere we can codemod it back to get_executor() and have asyncio.get_running_loop() used exclusively.
      
      A folly::IOBuf can be built around a Python Buffer.  It supports three ways to ask python to cleanup that buffer.
      
      1. If it has the GIL just decref the buffer
      2. else if it has a Python Executor it can schedule the cleanup
      3. it can rely on some cPython magic called "Py_AddPendingCall"
      
      thrift-py3 deserialize wraps a python buffer in a IOBuf, but since ownership is not handed off to C++ it has the GIL when we destroy the IOBUF so it doesn't need an Executor.
      
      IOBuf calls folly.executor.get_executor() which will create a AsyncioExecutor and bind it to the default eventloop.
      
      So using deserialize right before a python fork, would cause a ABORT in the child since the AsyncioExecutor would try to drive() itself during its destruction.
      
      The asyncio default eventloop is considered a bad thing, new interfaces like asyncio.run() does not rely on a default loop but creating its own.
      To insure we only ever use the eventloop from a running loop, use get_running_loop.
      
      Reviewed By: sdunster
      
      Differential Revision: D26794162
      
      fbshipit-source-id: 8e7e53c453c9ccff7e81f02e0692c8bebad70edd
      749f7a4b
    • Zhengxu Chen's avatar
      Make XLOG_EVENT_MS capture variables inside expanded lambda. · 7d413635
      Zhengxu Chen authored
      Summary:
      Just capture ms value for XLOG_EVERY_MS since it's executed inline.
      
      The use case here is we need to pass a non constant value as the milliseconds param, e.g:
      ```
      XLOG_EVERY_MS(INFO, configValue) << msg;
      ```
      
      Reviewed By: yfeldblum, simpkins
      
      Differential Revision: D26746623
      
      fbshipit-source-id: 849ad9a20ff4088ffb5a2df99c9c424592b47867
      7d413635
    • Yedidya Feldblum's avatar
      fix F14 fallback find() for stateful key-equal · 431c16c3
      Yedidya Feldblum authored
      Summary:
      The fallback implementation of F14 does a clever trick in its implementation of `find()` to support heterogeneous lookup. But this trick is UB and its implementation assumes that the key-equal type is empty, not specially-aligned, and not final. Relax these constraints.
      
      As it turns out, fbthrift streaming uses an F14 map with a stateful key-equal, triggering this UB in the fallback implementation: `StreamMap` uses key-equal type `StreamMapEquals`, which is nonempty and has a `StreamIdResolver` field, which itself is empty but which causes `StreamMapEquals` not to be empty. The simplest fix is, of course, to switch to using `StreamIdResolver` as a base, but this would be a bug in the F14 fallback regardless.
      
      `BottomKeyEqual` must have the same size, alignment, emptiness, and finality as `KeyEqual`.
      
      Reviewed By: aary
      
      Differential Revision: D26905527
      
      fbshipit-source-id: 023feb3963fc7b2e779fb591e737ea4b70ded476
      431c16c3
  9. 09 Mar, 2021 10 commits
    • Alex Snast's avatar
      add heterogeneous access support to EvictingCacheMap · 0efd32c4
      Alex Snast authored
      Summary:
      Heterogeneous access is described [here](https://github.com/facebook/folly/blob/master/folly/container/F14.md#heterogeneous-key-type-with-transparent-hash-and-equality) and this diff adds this capability to EvictingCacheMap.
      
      See `HeterogeneousAccess` test from EvictingCacheMapTest.cpp for usage example.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26879601
      
      fbshipit-source-id: 027352f2daa6773ab981b924732e1056550f6ea2
      0efd32c4
    • Tom Kwong's avatar
      Add StreamingStats functionality · 0fbe9c5b
      Tom Kwong authored
      Summary:
      This diff adds new capability to calculate statistics efficiently in a single pass. In particular, it uses Welford's algorithm to track an internal state such that variance and standard deviation can be obtained at O(1).
      
      The following statistics are available:
      - count
      - minimum
      - maximum
      - mean
      - sample and population variance
      - sample and population standard deviation
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26667517
      
      fbshipit-source-id: c4eb31e93646b9cff2f6516039170c8d88a5bf33
      0fbe9c5b
    • Philip Pronin's avatar
      define GENERATOR_REF · 438afd7d
      Philip Pronin authored
      Summary:
      Version of `GENERATOR` that we're already using in a few places where
      it doesn't leave its original scope.
      
      Reviewed By: ddrcoder, luciang
      
      Differential Revision: D26909115
      
      fbshipit-source-id: 5fbae8bd44c62d4d96427a4fd3ef60a8d9cb40e3
      438afd7d
    • Alan Frindell's avatar
      remove folly/io/coro/Socket.h shim · 3af4c3db
      Alan Frindell authored
      Summary: All dependencies have migrated to folly/io/coro/Transport.h
      
      Reviewed By: yairgott
      
      Differential Revision: D26837064
      
      fbshipit-source-id: abc46819e4d9bdec6ff5898d0295731781c7925d
      3af4c3db
    • Alan Frindell's avatar
      rename coro::Socket to coro::Transport · 8b4086af
      Alan Frindell authored
      Summary: This also renames the file and creates a Socket.h shim for compatabilty.
      
      Reviewed By: yairgott
      
      Differential Revision: D26837068
      
      fbshipit-source-id: 47c8f7b410540d1ad0aa03f4bc96816f8a93ef1c
      8b4086af
    • Alan Frindell's avatar
      coro::Socket wraps AsyncTransport · c3156ea8
      Alan Frindell authored
      Summary: This allows coro::Socket to be used with non-socket AsyncTransports, notably Fizz.  A subsequent diff renames the class and file, and creates a shim for callers.
      
      Reviewed By: yairgott
      
      Differential Revision: D26610473
      
      fbshipit-source-id: d64597ef0de3c90ab084249b20e85d97b34857a6
      c3156ea8
    • generatedunixname89002005325676's avatar
      Daily `arc lint --take CLANGFORMAT` · 2f7a1264
      generatedunixname89002005325676 authored
      Reviewed By: zertosh
      
      Differential Revision: D26908037
      
      fbshipit-source-id: 5c636fd281066f1d9af0d92f6f0b015ebf77437b
      2f7a1264
    • Dave Rigby's avatar
      Mark StaticMata as FOLLY_EXPORT (#1533) · 7c7531bd
      Dave Rigby authored
      Summary:
      When using folly::ThreadLocal<> to create thread-local variables, if a thread-local is set from two different libraries which are compiled with -fvisibility=hidden and using libc++, then a nullptr dereference is seen when attempting to set the thread-local from the second DLL.
      
      This is due to StaticMetaBase (which should be a singleton) getting created twice. This results in the thread local metadata getting corrupted and hence attempting to dereference a nullptr.
      
      Fix by marking StaticMeta as FOLLY_EXPORT, so only a single instance exists at runtime.
      
      Fixes https://github.com/facebook/folly/issues/1431
      
      Pull Request resolved: https://github.com/facebook/folly/pull/1533
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26818467
      
      Pulled By: Orvid
      
      fbshipit-source-id: 6b22627bc51060260e653885bdeb0df111207617
      7c7531bd
    • Yedidya Feldblum's avatar
      reduce inline code size of Executor::invokeCatchingExns · 5a37f8c8
      Yedidya Feldblum authored
      Summary: Some use-cases can be sensitive to inline code size, so reduce the inline code size of `Executor::invokeCatchingExns` just in case.
      
      Reviewed By: vitaut, zhxchen17
      
      Differential Revision: D26875990
      
      fbshipit-source-id: 0b822f7425bb47c98837faf08216092b49a7ed38
      5a37f8c8
    • Adam Simpkins's avatar
      update farmhash.cpp to avoid an unused function error on android · 4d235eee
      Adam Simpkins authored
      Summary:
      The `Fetch128()` function is only used in `#ifdef` sections that check for
      either `can_use_sse42` or `can_use_sse41 && x86_64`.  On Android builds this
      function was defined as a static function that was never used, causing
      compiler errors when compiled with `-Werror -Wunused-function`
      
      Reviewed By: mzlee
      
      Differential Revision: D26865431
      
      fbshipit-source-id: 5cd7ce12aa614f3d904df40ba21842223502a9ec
      4d235eee
  10. 08 Mar, 2021 1 commit
    • Kenny Yu's avatar
      Print async stack trace in signal handler · e85a11d5
      Kenny Yu authored
      Summary:
      If there is an active async operation on the current thread, then the signal
      handler will also print the async stack trace as well. Note that an async stack
      trace can have a mix of both non-async and async frames. This is an example
      of what an async stack trace might print:
      
      ```
      funcF      <- non async, top of stack
      funcE      <- non async
      co_funcD   <- async
      funcC      <- non async, blocking call. Second async stack root here
      co_funcB   <- async
      co_funcA   <- async
      main       <- non async. First async stack root here
      ```
      
      If there is no async operation in progress, there is no change in behavior
      (only normal stack trace is printed).
      
      This also adds a helper `getAsyncStackTraceStr()` to easily dump
      the async stack trace on demand. This helper is NOT async-signal-safe
      and is only meant for debugging purposes.
      
      Reviewed By: yfeldblum, andriigrynenko
      
      Differential Revision: D26661006
      
      fbshipit-source-id: f6e913910eb45c438a3e1e29d231e224eed15ef2
      e85a11d5