1. 22 Dec, 2016 8 commits
    • Yedidya Feldblum's avatar
      Move Thrower into exception_wrapper · 6e0964d9
      Yedidya Feldblum authored
      Summary:
      [Folly] Move `Thrower` into `exception_wrapper`.
      
      It is only used by `exception_wrapper`, so it might as well be a member type.
      
      Also, make it private. That means we need to tweak `try_and_catch`.
      
      Since we are tweaking `try_and_catch`, tweak all similar cases.
      
      Reviewed By: luciang
      
      Differential Revision: D4361815
      
      fbshipit-source-id: c5025894465a2c7760bd79dbbd272079fd34dd79
      6e0964d9
    • Yedidya Feldblum's avatar
      Move the guts of try_and_catch into a detail namespace · c60d131b
      Yedidya Feldblum authored
      Summary:
      [Folly] Move the guts of `try_and_catch` into a `detail` namespace.
      
      Just a bit cleaner this way. Also, now we always slice before returning the derived object, so the derived type never escapes.
      
      Reviewed By: luciang
      
      Differential Revision: D4361471
      
      fbshipit-source-id: 5c9567d3c5480ee9943a85139b8f27ba3b9da2d6
      c60d131b
    • Jason Leng's avatar
      Update future interrupts example in README · 8d510416
      Jason Leng authored
      Summary: Updated the future interrupts example to get rid of the shared pointer circular reference problem
      
      Reviewed By: djwatson
      
      Differential Revision: D4360037
      
      fbshipit-source-id: cb959929a508df4dcf3b81d01012bc55044a0b17
      8d510416
    • Jacob Bower's avatar
      Make folly pkg-config more usable on OS X · 6536cf29
      Jacob Bower authored
      Summary:
      As part of open-sourcing the Watchman C++ client I'm adding an (optional) dependency in Watchman to Folly. When I tried to build this client with Folly on OS X I ran into some problems using the libfolly pkg-config file. This diff addresses these issues:
      
      1. When using `build/bootstrap-osx-homebrew.sh`, the compile config for gflags and OpenSSL are overriden. If present, these custom flags will now be propagated to `libfolly.pc`.
      2. I changed the the package requirements in `libfolly.pc` from `Requires.private` to just `Requires`.
      
      Both of these changes are needed as much of Folly's implementation is in header files. As such, consumers of libfolly need to use the same library/include paths when building.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4332720
      
      fbshipit-source-id: 6a051ae318ac10bdeb4dc383a16de81f1c0327bb
      6536cf29
    • Yedidya Feldblum's avatar
      to_weak_ptr · ed6a4850
      Yedidya Feldblum authored
      Summary:
      [Folly] `to_weak_ptr`.
      
      Make a `weak_ptr` and return it from a `shared_ptr` without specifying the template type parameter and letting the compiler deduce it.
      
      So you can write this:
      
          auto wptr = to_weak_ptr(getSomethingShared<T>());
      
      Instead of this:
      
          auto wptr = weak_ptr<T>(getSomethingShared<T>());
      
      Useful when `T` is long, such as:
      
          using T = foobar::FooBarAsyncClient;
      
      Reviewed By: nbronson
      
      Differential Revision: D4361276
      
      fbshipit-source-id: 782a1d2d57b6e5823cb4018e445110098f1ce41f
      ed6a4850
    • Christopher Dykes's avatar
      Support fchmod and include the correct portability headers for FileUtil · df148cba
      Christopher Dykes authored
      Summary: `FileUtil.cpp` uses `fchmod`, which Windows doesn't have, so implement it and also include the correct portability headers for the use of `mkstemp` and now `fchmod` as well.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4360650
      
      fbshipit-source-id: 300163689c54574548e7bf274a56264714d216ed
      df148cba
    • Yedidya Feldblum's avatar
      Add missing includes in folly/experimental/observer · 2c45faef
      Yedidya Feldblum authored
      Summary:
      [Folly] Add missing includes in `folly/experimental/observer`.
      
      In particular, the missing includes of `folly/ExceptionString.h`.
      
      Motivation.
      
      Reviewed By: andrewjcg, nbronson
      
      Differential Revision: D4360991
      
      fbshipit-source-id: 4e4407669926b55d6d85df08edea70784a8f348c
      2c45faef
    • Amir Shalem's avatar
      FBString: remove unnecessary 7-byte padding in large strings · d83fd99b
      Amir Shalem authored
      Summary:
      RefCounted struct contains a pointer to `Char data_[1]`
      This saved us a +1 when calculating sizes for the null terminator,
      but the compiler made the struct size to be 16, instead of a 8+1.
      
      Reviewed By: Gownta, ot
      
      Differential Revision: D4356429
      
      fbshipit-source-id: 420694feb4b367b0c73d44f83c21a9559ac5e7a3
      d83fd99b
  2. 21 Dec, 2016 2 commits
  3. 20 Dec, 2016 5 commits
    • Eric Niebler's avatar
      use folly::FunctionRef for EventBase::run(ImmediatelyOrRun)?InEventBaseThreadAndWait · 054b2c1a
      Eric Niebler authored
      Summary: folly::FunctionRef never allocates memory and is cheaper to pass around. Use it in the interface of EventBase where we can.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4353992
      
      fbshipit-source-id: 259c5214ed48d30981eb8e38b062aad31d80a080
      054b2c1a
    • Michael Lee's avatar
      Fix sysconf return type · 219f48ef
      Michael Lee authored
      Summary: The sysconf return type is supposed to be long, not unsigned.
      
      Reviewed By: Orvid
      
      Differential Revision: D4350903
      
      fbshipit-source-id: 29d86081bf75d123e76b831a669b0fd3936ce102
      219f48ef
    • Christopher Dykes's avatar
      Enable -Wunreachable-code · ce7d3124
      Christopher Dykes authored
      Summary:
      Because it finds dead code.
      This also removes the dead code found.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4342893
      
      fbshipit-source-id: e500734ff5927320b2356106d10016e298d67393
      ce7d3124
    • Misty De Meo's avatar
      Fix search name for gflags's .pc file · 8d7ec4c6
      Misty De Meo authored
      Summary:
      gflags's pkg-config file is installed by default under the name gflags.pc; however, folly has been searching for it under the name libgflags.pc.
      
      Several package managers (Homebrew, apt) install the .pc file under its default upstream name; as such it seems appropriate for folly to look for it under that name, too.
      
      refs Homebrew/homebrew-core#7977.
      Closes https://github.com/facebook/folly/pull/531
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4348089
      
      Pulled By: Orvid
      
      fbshipit-source-id: 6adec290ec88b5d3f66103cf8e5094e99f2512ad
      8d7ec4c6
    • Guobao Sun's avatar
      Fix library name for thread_local_test in open source builds · 0a0da529
      Guobao Sun authored
      Summary: Test case ThreadLocal.SharedLibrary is failing due to looking for "thread_local_test_lib.so", while the actual .so generated is "lib_thread_local_test.so". Change Makefile.am to conform it.
      
      Reviewed By: Orvid
      
      Differential Revision: D4350758
      
      fbshipit-source-id: 9a2a23325059ed71529821620398ffa6ed84f83e
      0a0da529
  4. 19 Dec, 2016 3 commits
  5. 18 Dec, 2016 1 commit
    • Mathieu Baudet's avatar
      fbcode: remove unused includes from .cpp files with no #if and #define · d0856c87
      Mathieu Baudet authored
      Summary:
      This is a first diff to remove the "easiest" unused includes in fbcode.
      
      * For safety, we only touch .cpp files without #if and #define,
      * We do not try to remove redundant systems headers (aka. "packing").
      
      The diff was generated as follows:
      ```
      foundation/scripts/ls-cpp-dirs | grep -v '^\(\.\.\|external/\|.*/external\)' | xargs ffmr -o /tmp/ffmr-diff-1 codegraph/scripts/ffmr/analyze_includes_no_headers_no_packing_skipping_ifdefs.sh
      
      cat /tmp/ffmr-diff-1/*.diff | patch -p2
      hg commit -m something
      arc diff --prepare --nolint --nounit --less-context --excuse refactoring
      ```
      
      Note: `grep -v` is just an optimization. The actual configuration is in these two files:
      diffusion/FBS/browse/master/fbcode/codegraph/analysis/config.py
      diffusion/FBS/browse/master/fbcode/codegraph/scripts/ffmr/analyze_includes_no_headers_no_packing_skipping_ifdefs.sh
      
      See the task for more context, and the recent "safety" improvements on the tool.
      
      depends on D4317825 for very few cases where `nolint` had to be manually added.
      
      Reviewed By: igorsugak
      
      Differential Revision: D4312617
      
      fbshipit-source-id: ecc1f0addfd0651fa4770fcc43cd1314661a311a
      d0856c87
  6. 17 Dec, 2016 2 commits
    • Yedidya Feldblum's avatar
      Let ScopedEventBaseThread destruct the EventBase in the IO thread · 45d349f0
      Yedidya Feldblum authored
      Summary: [Folly] Let `ScopedEventBaseThread` destruct the `EventBase` in the IO thread.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D4330951
      
      fbshipit-source-id: 5b0e7071800e1d49048b08aa1233d72b820fe55d
      45d349f0
    • Yedidya Feldblum's avatar
      Split EventBaseThread from ScopedEventBaseThread · e5cb9b3d
      Yedidya Feldblum authored
      Summary:
      [Folly] Split `EventBaseThread` from `ScopedEventBaseThread`.
      
      Now `ScopedEventBaseThread` is really scoped and immovable, while `EventBaseThread` is movable and can be started and stopped.
      
      Users which will never move, and will never start or stop, the `ScopedEventBaseThread` can continue using it. Users which need to move, or which need to start and stop, the object will use `EventBaseThread` instead.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D4338447
      
      fbshipit-source-id: 57c186630bc199a7a7b7223b1fcb077ce3d86743
      e5cb9b3d
  7. 16 Dec, 2016 11 commits
    • Christopher Dykes's avatar
      Fix some implicit truncation and implicit sign coersion warnings in the Windows portability layer · d496cae9
      Christopher Dykes authored
      Summary: More progress towards being able to build Folly cleanly with MSVC's truncation and sign coersion warnings enabled.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4288060
      
      fbshipit-source-id: ce42d2099163ed5a9c9a9bb736a80bb2407f7595
      d496cae9
    • Junlin Zhang's avatar
      add cancelFunctionAndWait and cancelAllFunctionsAndWait to FunctionScheduler · 2a7bf484
      Junlin Zhang authored
      Summary: In FunctionScheduler, cancelFunction and cancelAllFunction will not wait for current running function, which will lead to segmentation fault if the function captures resource to be destructed right after calling cancelFunction or cancelAllFunction. This diff introduces cancelFunctionAndWait and cancelAllFunctionsAndWait, making it possible to wait for completion of current running function.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4324384
      
      fbshipit-source-id: ac4b272894f753ef3bb175173f10d1ca20c17c41
      2a7bf484
    • Andrii Grynenko's avatar
      Fix TimedMutex deadlock when used both from fiber and main context · 2b06a716
      Andrii Grynenko authored
      Summary: TimedMutex is a fair mutex, which can cause a deadlock if same mutex is requested first in a fiber, and then in main context.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4209155
      
      fbshipit-source-id: 0623d9a2e6a0b5cc310fb71ad1b1cf33afd6a30e
      2b06a716
    • Yinghai Lu's avatar
      Add BEXTR instruction support · 9660cdb0
      Yinghai Lu authored
      Summary: BEXTR is an instruction in BMI set, which extract given number of bits from a 64 bit register starting from a given position. The position and size of extracted bits are packed into a one 64bit integer.
      
      Reviewed By: Orvid
      
      Differential Revision: D4316516
      
      fbshipit-source-id: 3f752388763b0e26c506d7d49cf6c05cf28271c0
      9660cdb0
    • Christopher Dykes's avatar
      Revert D4310312: [Folly] Enable -Wunreachable-code · eac2f407
      Christopher Dykes authored
      Summary: This reverts commit 8178dacc9268e1001efc5f803a35ef49e23d692a
      
      Differential Revision: D4310312
      
      fbshipit-source-id: 7c4b90e834f1a95e51524e1e82ac5294e5ba2dc5
      eac2f407
    • Yedidya Feldblum's avatar
      Always use an EventBaseManager with ScopedEventBaseThread · 536bac28
      Yedidya Feldblum authored
      Summary: [Folly] Always use an `EventBaseManager` with `ScopedEventBaseThread`.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D4336412
      
      fbshipit-source-id: 459a679f8fda0db1ca0a9fdca2f852bb00c5231e
      536bac28
    • Christopher Dykes's avatar
      Enable -Wunreachable-code · a83ba29c
      Christopher Dykes authored
      Summary:
      Because it finds dead code.
      This also removes the dead code found.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4310312
      
      fbshipit-source-id: 8178dacc9268e1001efc5f803a35ef49e23d692a
      a83ba29c
    • Christopher Dykes's avatar
      Allow folly to compile cleanly with most of the rest of MSVC's sign mismatch warnings · d7d91eb1
      Christopher Dykes authored
      Summary:
      This allows folly to compile with warnings 4245, 4287 and 4365 enabled, all of which are sign mismatch warnings.
      This is labeled as 'mostly' because I'll probably have to clean up a few more of these.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4263259
      
      fbshipit-source-id: 0db618f0405817503a63094edd75b24ec1e5c9ad
      d7d91eb1
    • Christopher Dykes's avatar
      More implicit truncation warning fixes · 1c098e27
      Christopher Dykes authored
      Summary:
      This makes the changes required to compile Folly cleanly with the rest of MSVC's truncation warnings, 4244 & 4267.
      Only another 2800 sign mismatch warnings left to go.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4257094
      
      fbshipit-source-id: 1651eca875a31f53774d36c682f5e2745ddfcda5
      1c098e27
    • Christopher Dykes's avatar
      Refactor stats to use the same type for indexes · 654cce1e
      Christopher Dykes authored
      Summary:
      This refactors folly/stats/* to use a single type for indexes rather than `size_t`, `int`, `unsigned int`, `uint64_t` and `int64_t` depending on where you looked.
      This also has the result of getting MSVC to not complain about implicit sign conversions and implicit truncations.
      
      Reviewed By: simpkins
      
      Differential Revision: D4282174
      
      fbshipit-source-id: 8529be34dce8ad18bc64395330bbdf2cd7305be4
      654cce1e
    • Christopher Dykes's avatar
      Include <cassert> when using assert · 16c6735f
      Christopher Dykes authored
      Summary:
      We were using `assert` without including anything that defines it.
      
      Closes https://github.com/facebook/folly/issues/530
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4337047
      
      fbshipit-source-id: 327d19a685e7a4cc1e1eb6e471a6457fe9dee6c7
      16c6735f
  8. 15 Dec, 2016 5 commits
    • Yedidya Feldblum's avatar
      Check the baton waits in the ScopedEventBaseThread tests · b1cc5501
      Yedidya Feldblum authored
      Summary:
      [Folly] Check the baton waits in the `ScopedEventBaseThread` tests.
      
      Also:
      * `Baton<T>::timed_wait` can take a `duration`, not just a `time_point`.
      * Allow a bit more time for waiting, just in case the machine running the tests is under load.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D4330126
      
      fbshipit-source-id: 55878577b1deeb260686647e5f22a81d6fb9e06d
      b1cc5501
    • Andrii Grynenko's avatar
      Require runBeforeLoop callbacks to be canceled prior to EventBase destruction · e3f67e10
      Andrii Grynenko authored
      Summary: This makes it similar to other other events registered with EventBase.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4331277
      
      fbshipit-source-id: 5d728d4ae5faff1a72ed724b4e2a6c0dd6c3b02d
      e3f67e10
    • Wez Furlong's avatar
      add folly::init to libfolly for OSS build · 8d0d6318
      Wez Furlong authored
      Summary:
      We use this in eden and this avoids needing to patch the homebrew recipe.
      
      I've also made the use of the folly symbolizer specific to the facebook
      internal build of folly, because it fails to compile in the Linux OSS build
      too.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4292166
      
      fbshipit-source-id: b69153be8ab9cc461bc7f456248e73972ba7f461
      8d0d6318
    • Andrii Grynenko's avatar
      Make FunctionLoopCallback available outside of EventBase.cpp · 489524aa
      Andrii Grynenko authored
      Reviewed By: yfeldblum
      
      Differential Revision: D4331194
      
      fbshipit-source-id: 1e1579e3b775b1b4e329aa28aae11a2b54294697
      489524aa
    • Andrii Grynenko's avatar
      Make SingletonVault state use ReadPriority mutex · 4092256e
      Andrii Grynenko authored
      Summary: This fixes a deadlock possible when singleton chain is created concurrently with destroyInstances().
      
      Reviewed By: lbrandy, yfeldblum
      
      Differential Revision: D4329028
      
      fbshipit-source-id: a11b3ff42d164ead2f8e3e77e0e17be43a8ad306
      4092256e
  9. 14 Dec, 2016 3 commits
    • Eric Niebler's avatar
      work around GCC#61971 (spurious -Warray-bounds warnings) in folly::FixedString · 6ed9b4c6
      Eric Niebler authored
      Summary:
      GCC has the temerity to insinuate that my code has out-of-array-bounds access. After cross-checking with clang and ubsan, reviewing the code, and running constexpr tests (for which out-of-range errors are caught at compile time), I can say with pretty high confidence that this is an instance of GCC#61971 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61971). Basically, the gcc-4 series is known to issue spurious -Warray-bounds warnings. The "fix" is to route internal accesses to some helper functions, for which -Warray-bounds has been suppressed.
      
      User code that accesses elements with operator[] will still warn on out-of-bounds access. If this is a problem in practice, we can suppress the warning there, too. Trying this for now since it is less likely to hide real problems.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4317305
      
      fbshipit-source-id: 7bf92f993ac1a29631463c582c1b64d76f755181
      6ed9b4c6
    • Nathan Bronson's avatar
      fix ExceptionTracerTest build · 56ef367e
      Nathan Bronson authored
      Summary:
      A recent diff added [[noreturn]] annotations that cause buck
      build to fail for ExceptionTracerTest.cpp, due to our use of -Werror
      and -Wunreachable-code-return.  This diff removes the unreachable return
      statement.
      
      Differential Revision: D4326888
      
      fbshipit-source-id: 7863c163eedcf2a7e19730c1de194f05c544a2c0
      56ef367e
    • Christopher Dykes's avatar
      Allow building with -Wmissing-noreturn · f3f4bcfb
      Christopher Dykes authored
      Summary: If your function doesn't return you should be explicit about it.
      
      Reviewed By: meyering
      
      Differential Revision: D4309893
      
      fbshipit-source-id: ce275ec8f42e2cb3253a1e40e263934649f09d9e
      f3f4bcfb