folly.git
5 years agoFix getCurrentThreadName() on OSX
Christopher Dykes [Fri, 5 May 2017 19:03:21 +0000 (12:03 -0700)]
Fix getCurrentThreadName() on OSX

Summary: OSX was sad. Now it should be happy.

Reviewed By: mzlee

Differential Revision: D5011751

fbshipit-source-id: 77f22ff461036d8530d8f650396d8e12503448e7

5 years agoControl the number of threads in TestExecutor
Yedidya Feldblum [Fri, 5 May 2017 18:52:53 +0000 (11:52 -0700)]
Control the number of threads in TestExecutor

Summary:
[Folly] Control the number of threads in `TestExecutor`.

Let the caller control the number of threads to use in each given case.

Reviewed By: spacedentist

Differential Revision: D4999699

fbshipit-source-id: 4acf68cf17fbca14f0779daf0268d54c5606e4a8

5 years agoFuture: improve test with task discarding executors
Sven Over [Fri, 5 May 2017 16:12:51 +0000 (09:12 -0700)]
Future: improve test with task discarding executors

Summary:
We have tests that check that the Future implementation deals
cleanly with executors discarding tasks. The existing tests destroy
the tasks immediately when they are passed to Executor::add. This
diff adds corresponding tests for the scenario where the task is
not destroyed right away, but after the call to Future::then has
completed.

This diff also adds a mechanism to detect that the passed callback
function is actually destroyed. We have tested already that the
promise returned by folly::then will be set to a BrokenPromise
exception when the executor discards the task. However, the task
passed to the executor is not only the callback we pass to
folly::then, as the Future implementation wraps it with some code
that stores the return value in a Promise. Existing tests check
that this Promise is destroyed. The added mechanism in this diff
checks that the orignal callback function itself gets destroyed.

Reviewed By: Krigpl

Differential Revision: D5002100

fbshipit-source-id: 4155f61b075d9fe8d1869ad229f4d350571ff4c6

5 years agoAdd full noexcept annotations to Indestructible
Yedidya Feldblum [Fri, 5 May 2017 06:43:22 +0000 (23:43 -0700)]
Add full noexcept annotations to Indestructible

Summary:
[Folly] Add full `noexcept` annotations to `Indestructible`.

And do it without requiring `<type_traits>`.

Reviewed By: Orvid

Differential Revision: D4999243

fbshipit-source-id: f3521237ef4d03d2b187e9ebd6d0c90887872c42

5 years agoDelete operator=(std::string&&) from StringPiece
Christopher Dykes [Fri, 5 May 2017 01:32:45 +0000 (18:32 -0700)]
Delete operator=(std::string&&) from StringPiece

Summary: This can only ever be used unsafely, so delete it.

Reviewed By: yfeldblum

Differential Revision: D4951294

fbshipit-source-id: bbc266d1550fceb48946c7c48e76af07292b4a53

5 years agoSupport naming a ScopedEventBaseThread
Christopher Dykes [Thu, 4 May 2017 23:46:53 +0000 (16:46 -0700)]
Support naming a ScopedEventBaseThread

Summary:
The setThreadName API is in the process of being changed to not accept a thread id, which means the thread itself needs to set the name.
There are times where a `ScopedEventBaseThread` needs to be named, and this makes that possible.

Reviewed By: yfeldblum

Differential Revision: D4916781

fbshipit-source-id: dab05b520a715183ce069151ed16864fa1331abc

5 years agoAdd support for getting the current thread's name
Christopher Dykes [Thu, 4 May 2017 23:31:01 +0000 (16:31 -0700)]
Add support for getting the current thread's name

Summary: It's primarily for use in testing, but is useful for log output as well.

Reviewed By: yfeldblum

Differential Revision: D4943072

fbshipit-source-id: 0ca259d6c90f439e733a6179e7cba85dcd1ec9e7

5 years agoAdd thread-safe priority queue with arbitrary priorities using flat combining
Maged Michael [Thu, 4 May 2017 02:57:21 +0000 (19:57 -0700)]
Add thread-safe priority queue with arbitrary priorities using flat combining

Summary: This template uses flat combining and takes any sequential priority queue implementation that supports the `std::priority_queue` interface (`empty()`, `size()`, `push()`, `top()`, `pop()`) and any lock that meets the standard //Lockable// requirements to implement a thread-safe priority queue that supports arbitrary priorities. The template supports both unbounded and bounded size, and blocking, non-blocking, and timed variants of push, pop, and peek operations.

Reviewed By: djwatson

Differential Revision: D4873602

fbshipit-source-id: 96e1548b4f7427ecd2ee2ead7a19993df4441b33

5 years agotest the typeid of the exception before it is potentially moved
Eric Niebler [Thu, 4 May 2017 02:12:10 +0000 (19:12 -0700)]
test the typeid of the exception before it is potentially moved

Summary: Access the RTTI of the incomming exception before it is potentially moved from when testing for slicing

Reviewed By: yfeldblum

Differential Revision: D4999189

fbshipit-source-id: 3e6c0a9f10a27810484330e9b37a5b0ec450ff88

5 years agoHelper utility to construct, returns an Expected<..>
Aravind Anbudurai [Wed, 3 May 2017 22:33:31 +0000 (15:33 -0700)]
Helper utility to construct, returns an Expected<..>

Summary:
folly::File's throwing constructor results in many try-catches in the callsites
or bugs where the exception is not caught.

This is a helper method to return an Expected with system_error wrapped into an
exception_wrapper.

Reviewed By: yfeldblum

Differential Revision: D4995702

fbshipit-source-id: be0e22b37c21c35bf157ada598916b05dfd32631

5 years agoStore pointers in EliasFanoReader and BitVectorReader only if quantum > 0
Giuseppe Ottaviano [Wed, 3 May 2017 21:58:44 +0000 (14:58 -0700)]
Store pointers in EliasFanoReader and BitVectorReader only if quantum > 0

Summary:
No need to store the pointers to forward and skip arrays if
they're not used.

Reviewed By: luciang

Differential Revision: D4977014

fbshipit-source-id: 2ed13fdcd1561da1a294f5895f3a5e1b77f1701c

5 years agoTemplate EliasFanoReader on size type
Giuseppe Ottaviano [Wed, 3 May 2017 21:58:42 +0000 (14:58 -0700)]
Template EliasFanoReader on size type

Summary: Shrink the reader type if less than 64 bits are sufficient for sizes. Do the same for `BitVectorCoding`, where we don't need an extra template parameter because the size is limited by the value domain.

Reviewed By: philippv, luciang

Differential Revision: D4976756

fbshipit-source-id: 685047da81a556d049fb924c612f99cea3056a82

5 years agoDo not store inner_ in EliasFanoReader and BitVectorReader
Giuseppe Ottaviano [Wed, 3 May 2017 21:58:40 +0000 (14:58 -0700)]
Do not store inner_ in EliasFanoReader and BitVectorReader

Summary: It is not used anywhere except for `previousValue`, but there it can be computed from the other fields. This reduces the `EliasFanoReader` size by 8 bytes.

Reviewed By: philippv, yfeldblum

Differential Revision: D4976704

fbshipit-source-id: 62bc63248b66649e483b59cb9ddf48dfd2c0e992

5 years agoDo not store the lower bits mask in EliasFanoReader
Giuseppe Ottaviano [Wed, 3 May 2017 21:58:39 +0000 (14:58 -0700)]
Do not store the lower bits mask in EliasFanoReader

Summary:
Computing the mask on access has negligible cost as it can be
hoisted out of the linear search loop, and furthermore on Haswell we
can use the the `BZHI` instruction.

I also experimented with `BEXTR` but it ended up being slower because
computing the pattern operand requires a shift and an or (it's
probably meant for when the pattern is precomputed).

Reviewed By: philippv

Differential Revision: D4976657

fbshipit-source-id: e4c4ca5f0a785595587e6d6ad4676f5b216291cf

5 years agoDomain destruction fixes
Dave Watson [Wed, 3 May 2017 17:57:29 +0000 (10:57 -0700)]
Domain destruction fixes

Summary:
If a retired object's destructor retire()s other hazard pointers, currently
these are not cleaned up correctly when the domain destructs.

Retired pointers must be cleaned up before destroying hazptr_recs, and must be done
iteratively until no more garbage is generated.

Reviewed By: magedm

Differential Revision: D4987333

fbshipit-source-id: bcdd61abb47caca0892a8c4dbb864d17d4f2fa30

5 years agoFix a couple of issues with the CMake script
Christopher Dykes [Wed, 3 May 2017 16:28:45 +0000 (09:28 -0700)]
Fix a couple of issues with the CMake script

Summary:
The first issue is that I was missing a `G` in `LIBGFLAGS_INCLUDE_DIR` meaning that it always claimed it couldn't find gflags even though it did, and worked just fine anyways.
The second issue is that it was passing `/permissive-` to MSVC 2015 builds, even though MSVC 2015 doesn't support the permissive flag.

Reviewed By: yfeldblum

Differential Revision: D4988813

fbshipit-source-id: f1ea009226baee54032409ce7add3c41f1fe7a19

5 years agoFix compiling with PThread support on Windows... Again...
Christopher Dykes [Wed, 3 May 2017 14:43:46 +0000 (07:43 -0700)]
Fix compiling with PThread support on Windows... Again...

Summary: I was bad and didn't follow through on my previous test plan, and so didn't check that it completely fixed the issue, instead only fixing one of the two problems. This fixes the other one.

Reviewed By: yfeldblum

Differential Revision: D4988408

fbshipit-source-id: 44389bc67bcb7d6db984075f3600948460fa8c5a

5 years agoFix ExceptionWrapper under MSVC 2015 Update 3
Christopher Dykes [Wed, 3 May 2017 14:11:09 +0000 (07:11 -0700)]
Fix ExceptionWrapper under MSVC 2015 Update 3

Summary: Besides this code being utterly bizzare, it doesn't work under MSVC 2015 Update 3, so rather than doing a `static_cast<bool>(std::conjunction<>())` just do `std::conjunction<>::value`.

Reviewed By: yfeldblum

Differential Revision: D4988341

fbshipit-source-id: ededdbf3f3d945d9e2f140f4e87643ec3c0d4239

5 years agoFix FBString in MSVC 2015
Christopher Dykes [Tue, 2 May 2017 21:21:15 +0000 (14:21 -0700)]
Fix FBString in MSVC 2015

Summary: MSVC 2015 Update 3 is even worse in this particular case, and requires it to be explicitly referenced as being within the `folly` namespace >_>...

Reviewed By: ot, yfeldblum

Differential Revision: D4988025

fbshipit-source-id: dea311dd42f40b442951b8df3c5f68cf70d13769

5 years agoFix the CMake build on Windows when using PThreads
Christopher Dykes [Tue, 2 May 2017 17:31:18 +0000 (10:31 -0700)]
Fix the CMake build on Windows when using PThreads

Summary: I broke things, so now I have to fix them.

Reviewed By: yfeldblum

Differential Revision: D4981674

fbshipit-source-id: 7df4d78cf4f984df158051a3a8b277a0bcad583b

5 years agoFix FBString under MSVC
Christopher Dykes [Tue, 2 May 2017 01:41:19 +0000 (18:41 -0700)]
Fix FBString under MSVC

Summary: MSVC requires the declaration to match a bit closer than GCC does.

Reviewed By: yfeldblum, ot

Differential Revision: D4981404

fbshipit-source-id: 92ee40c40f66725c09a3087e49d99ebae222c2f2

5 years agoFix a race in Observable context destruction
Andrii Grynenko [Mon, 1 May 2017 21:51:49 +0000 (14:51 -0700)]
Fix a race in Observable context destruction

Summary: In the subscribe callback It's possible that we lock the Context shared_ptr and while update is running, all other shared_ptr's are released. This will result in Context to be destroyed from the wrong thread (thread runnning subcribe callback), which is not desired.

Reviewed By: yfeldblum

Differential Revision: D4964605

fbshipit-source-id: 285327a6873ccb7393fa3067ba7e612c29dbc454

5 years agoMore OpenSSL 1.1.0 compatibility fixes
Anirudh Ramachandran [Mon, 1 May 2017 21:48:15 +0000 (14:48 -0700)]
More OpenSSL 1.1.0 compatibility fixes

Summary: A bunch of changes to make fbcode targets build with OpenSSL 1.1.0

Reviewed By: ivmaykov

Differential Revision: D4949822

fbshipit-source-id: 35eda632d8335c4194352196264afeff69d87519

5 years agoRemove unused `constexpr strlen` check v2017.05.01.00
Ted Percival [Sun, 30 Apr 2017 08:26:27 +0000 (01:26 -0700)]
Remove unused `constexpr strlen` check

Summary:
Superseded by `<folly/portability/Constexpr.h>`'s `constexpr_strlen()`.
Closes https://github.com/facebook/folly/pull/585

Reviewed By: yfeldblum

Differential Revision: D4973136

Pulled By: Orvid

fbshipit-source-id: ada9bedf53ce219b0924c3f7aaad75bce9605f0f

5 years agoSimplify BackgroundThreads, move them to folly/experimental/ThreadedRepeatingFunction...
Alexey Spiridonov [Fri, 28 Apr 2017 22:52:16 +0000 (15:52 -0700)]
Simplify BackgroundThreads, move them to folly/experimental/ThreadedRepeatingFunctionRunner

Summary:
- `FunctionScheduler` and `EventBase` are great for sharing one thread for many functions, but one-function-per-thread is messy.
- Both of those implementations are complicated, but `FunctionThreads` is dead-simple.
- I made it even simpler by eliminating the former `incrementalSleep` in favor of `std::future::wait_for`, which allows instant interruption without a tweakable param. h/t aru777 for suggesting `std::future` instead of `std::condition_variable`.

Reviewed By: yfeldblum

Differential Revision: D4742134

fbshipit-source-id: b520bbcd5f218b2276200ffe8926722ae8a8d6ca

5 years agoFix a comment
Giuseppe Ottaviano [Thu, 27 Apr 2017 21:34:29 +0000 (14:34 -0700)]
Fix a comment

Reviewed By: yfeldblum

Differential Revision: D4965608

fbshipit-source-id: db8d67ca7174e0296fbd8da2e1fe90cbbcef9496

5 years agofolly::rvalue_reference_wrapper for store&forward of rvalue references
Philipp Unterbrunner [Thu, 27 Apr 2017 21:03:31 +0000 (14:03 -0700)]
folly::rvalue_reference_wrapper for store&forward of rvalue references

Summary:
Class template that wraps a reference to an rvalue. Similar to std::reference_wrapper but with three important differences:
1) folly::rvalue_reference_wrappers can only be moved, not copied;
2) the get() function and the conversion-to-T operator are destructive and not const, they invalidate the wrapper;
3) the constructor-from-T is explicit.
These restrictions are designed to make it harder to accidentally create a a dangling rvalue reference, or to use an rvalue reference multiple times. (Using an rvalue reference typically implies invalidation of the target object, such as move-assignment to another object.)

Reviewed By: yfeldblum

Differential Revision: D4931483

fbshipit-source-id: 68453553bf4656ec41976699669a4491fcab79c9

5 years agofix silent eax clobbering in CpuId ctor
Philip Pronin [Thu, 27 Apr 2017 17:06:51 +0000 (10:06 -0700)]
fix silent eax clobbering in CpuId ctor

Summary:
`cpuid` uses all of `eax`, `ebx`, `ecx`, `edx` for output, but we
aren't providing such information to GCC in a couple of cases, which might
result in incorrect code being produced;

GCC (unlike clang) doesn't allow the same register to appear both in input and
clobber list, so put `eax` into output list where required.

Reviewed By: ot, lbrandy

Differential Revision: D4961841

fbshipit-source-id: 07ca1977373496bfd794d3b0c8a4ba21333820e4

5 years agoDon't return a nullptr from IOBufQueue::split(0)
Otto Ebeling [Thu, 27 Apr 2017 15:49:50 +0000 (08:49 -0700)]
Don't return a nullptr from IOBufQueue::split(0)

Summary: There's a gotcha case for IOBufQueue::split when  n==0, it will then return an unique_ptr wrapping a nullptr, which many call sites do not expect.

Reviewed By: meyering

Differential Revision: D4868228

fbshipit-source-id: 418256dba8ca3bcfbae420b6099baa240055b9bb

5 years agoFlat combining: Add lock holder with deferred option. Minor fixes.
Maged Michael [Thu, 27 Apr 2017 13:59:10 +0000 (06:59 -0700)]
Flat combining: Add lock holder with deferred option. Minor fixes.

Summary: Added a lock holder with deferred option for cases where the caller may want to call try_lock() later.

Reviewed By: djwatson

Differential Revision: D4949736

fbshipit-source-id: 31e0dc349dc3af9d04a33878e26cef1e48cce674

5 years agoCasing consistency for exception_wrapper::throw_exception
Yedidya Feldblum [Thu, 27 Apr 2017 08:18:43 +0000 (01:18 -0700)]
Casing consistency for exception_wrapper::throw_exception

Summary: [Folly] Casing consistency for `exception_wrapper::throw_exception`.

Reviewed By: Orvid

Differential Revision: D4944818

fbshipit-source-id: 72056fb24ab6362e9a0319f73b5bbf8c92d658ca

5 years agofolly::overload and folly::variant_match
Pavel Aslanov [Wed, 26 Apr 2017 21:15:50 +0000 (14:15 -0700)]
folly::overload and folly::variant_match

Summary: Pattern matching like functionality for boost::vairant. See unittests for usage examples.

Reviewed By: yfeldblum, ericniebler

Differential Revision: D4851133

fbshipit-source-id: cda7dc766dac5870bcc4ab1859de0e4e7f0a6599

5 years agosmall_vector improvements
Nick Terrell [Wed, 26 Apr 2017 17:32:25 +0000 (10:32 -0700)]
small_vector improvements

Summary:
1. `emplace_back()` is broken when there are at least two arguments and one is a reference to inside the vector. See the `ForwardingEmplaceInsideVector` test.
2. Only `push_back(value_type&&)` did exponential growth, every other function grew linearly. The bug is hidden inside of facebook because `goodMallocSize()` grows fast enough to not be horribly slow. When not using jemalloc, it will grow one element at a time.
3. `push_back(value_type const& t)` performed a copy and a move on `t` when `size() == capacity()`. Remove the extra move.

Fixes https://github.com/facebook/folly/issues/541.

Reviewed By: luciang

Differential Revision: D4875084

fbshipit-source-id: eefa76028c6bfd9d7c73af65e8bb9d4baf49b8cb

5 years agoMake folly pass TSAN checks
Dave Watson [Wed, 26 Apr 2017 17:04:04 +0000 (10:04 -0700)]
Make folly pass TSAN checks

Summary:
Currently, contbuild has a blanket TSAN suppression for folly.
Fix PicoSpinLock instead

This should fix TSAN errors as an alternative to D4781776

Some of the tests even had TSAN errors, fixed those.

Reviewed By: davidtgoldblatt

Differential Revision: D4795284

fbshipit-source-id: 9f0fc6868399da2f86be355ce3c081990260a649

5 years agoFix virtual struct bug
Dave Watson [Wed, 26 Apr 2017 16:56:26 +0000 (09:56 -0700)]
Fix virtual struct bug

Summary: virtual classes currently don't work in hazard pointers, and get incorrectly reclaimed.

Reviewed By: magedm

Differential Revision: D4951584

fbshipit-source-id: 8200df6bb8d500af2e89086edf7835d4fb90b6a2

5 years agoDelete the non-char integeral forms of fbstring::operator=
Christopher Dykes [Wed, 26 Apr 2017 00:14:26 +0000 (17:14 -0700)]
Delete the non-char integeral forms of fbstring::operator=

Summary: They allow for assignments that make no sense, so make it impossible to do so.

Reviewed By: yfeldblum

Differential Revision: D4919606

fbshipit-source-id: 24d8e036eff33a8c6def4672c0d098f0edd5c5b3

5 years agoGuard SSLContext lock checks with init mutex and add setSSLLockTypesAndInitOpenSSL
Neel Goyal [Tue, 25 Apr 2017 14:31:39 +0000 (07:31 -0700)]
Guard SSLContext lock checks with init mutex and add setSSLLockTypesAndInitOpenSSL

Summary:
Improve concurrency guards for `setSSLLockTypes` and `isSSLLockDisabled` by using initMutex.  Also verify that openssl has been initialized w/ DCHECK in isSSLLockDisabled.

We also add a method to do the setting of locks and initialization in one shot.

Reviewed By: knekritz

Differential Revision: D4937242

fbshipit-source-id: 308f516c17485281604d4322954c09beb58688e2

5 years agoRemove thread-safety comment from EventBaseLocal
Andrii Grynenko [Tue, 25 Apr 2017 03:04:03 +0000 (20:04 -0700)]
Remove thread-safety comment from EventBaseLocal

Reviewed By: vitaut

Differential Revision: D4940976

fbshipit-source-id: 0c4ebf8f358e6f54a7b5e81f2e73649b030006c9

5 years agoShift the implementation of setThreadName out of the header
Christopher Dykes [Tue, 25 Apr 2017 01:41:06 +0000 (18:41 -0700)]
Shift the implementation of setThreadName out of the header

Summary:
`folly::setThreadName` is neither performance critical, nor (after this diff) is it a template, so exposing the mess that is its implementation to the world isn't worth it.
The implementation is expected to get even more messy as I add support for getting the current thread's name, and eventually also add support for Windows as well.

This also required exposing whether the current platform supports setting the name of the current or other threads.

Reviewed By: yfeldblum

Differential Revision: D4942401

fbshipit-source-id: 0e3be203995fa6ed667a5fd28dac7ba7fa49d683

5 years agoProperly gate the wchar tests in FBStringTest
Michael Lee [Mon, 24 Apr 2017 17:47:24 +0000 (10:47 -0700)]
Properly gate the wchar tests in FBStringTest

Summary: Using `#ifndef __ANDROID__` does not necessarily handle all cases of gating the wchar tests

Reviewed By: Orvid

Differential Revision: D4938634

fbshipit-source-id: a2184e20b8c382e5a34947c029f7e3746272b407

5 years agoIgnore setSSLLockTypes() calls after SSLContext is initialized. v2017.04.24.00
Neel Goyal [Sat, 22 Apr 2017 16:18:55 +0000 (09:18 -0700)]
Ignore setSSLLockTypes() calls after SSLContext is initialized.

Summary: We set the actual locks on initialization, so attempting to change locks after had no affect, other than making isSSLLockDisabled() report incorrect information.

Reviewed By: yfeldblum

Differential Revision: D4935475

fbshipit-source-id: 7b80cd530801c925ade769163579b86b1a8f0027

5 years agoAlso exclude the wstring test
Michael Lee [Sat, 22 Apr 2017 00:19:25 +0000 (17:19 -0700)]
Also exclude the wstring test

Summary: ^^^

Reviewed By: yangchi

Differential Revision: D4934455

fbshipit-source-id: babf56f4705ae06f46b694df3f2890d4b9506861

5 years agoTurn off failing FBString test for Android
Michael Lee [Fri, 21 Apr 2017 22:08:18 +0000 (15:08 -0700)]
Turn off failing FBString test for Android

Summary: The traitsLength call in the basic_fbstring constructor is returning a bad value.

Reviewed By: Orvid

Differential Revision: D4930106

fbshipit-source-id: 556a61c4496c2af91cb70db6d62cdc7e915edd55

5 years agoUse std::nullptr_t in dynamic
Christopher Dykes [Fri, 21 Apr 2017 18:25:39 +0000 (11:25 -0700)]
Use std::nullptr_t in dynamic

Summary: It was changed to a `void*` previously due to an ICE in GCC 4.7. GCC 4.7 hasn't been supported in quite a while, and newer versions of GCC don't crash, so it's time to switch it back to `nullptr_t`.

Reviewed By: yfeldblum

Differential Revision: D4917389

fbshipit-source-id: fc48642026c7e3aaeadef27bb949f70648c2312c

5 years agoFix issue where compiler cannot determine address of ::free at compile time
Cameron Pickett [Fri, 21 Apr 2017 01:33:05 +0000 (18:33 -0700)]
Fix issue where compiler cannot determine address of ::free at compile time

Reviewed By: Orvid

Differential Revision: D4921738

fbshipit-source-id: 69848cda3638fca4ead73dcc9949af0f600f33bb

5 years agoEventBaseLocal cleanup
Andrii Grynenko [Thu, 20 Apr 2017 21:54:37 +0000 (14:54 -0700)]
EventBaseLocal cleanup

Summary:
1. Restrict EventBaseLocal API to only be used from EventBase thread to avoid extra locking.
2. Make sure objects stored in EventBaseLocal are destroyed in EventBase thread.

Reviewed By: yfeldblum

Differential Revision: D4918282

fbshipit-source-id: b7cb4c2b62fef85a9b1d796fa71af8af9087479d

5 years agoRemove unpackHack from smallVector
Nicholas Ormrod [Thu, 20 Apr 2017 17:07:21 +0000 (10:07 -0700)]
Remove unpackHack from smallVector

Summary:
This change removes the unpackHack function from small_vector, which was blocking ##-Waddress-of-packed-member## from being enabled. The fix is split the pointer-getting non-const ##getCapacity## into a normal getter and setter.

(lithium is flakey, according to continuous, and is push-blocking)

Reviewed By: yfeldblum

Differential Revision: D4918188

fbshipit-source-id: 435e030ad659f5dc9c42d90e9bfee9ca564a120a

5 years agoAdded pkg-config as required dependency
Maxim [Wed, 19 Apr 2017 22:01:49 +0000 (15:01 -0700)]
Added pkg-config as required dependency

Summary:
Faced this problem on Ubuntu 14.04.4 LTS

```
configure:16581: error: possibly undefined macro: AC_MSG_NOTICE
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
```
Fixed with `apt-get install pkg-config`
Closes https://github.com/facebook/folly/pull/579

Reviewed By: yfeldblum

Differential Revision: D4886216

Pulled By: Orvid

fbshipit-source-id: 88159b70bfcf62d01bef502b3a5da6c9d81499bc

5 years agoImprove string comparisons
Phil Willoughby [Wed, 19 Apr 2017 12:34:26 +0000 (05:34 -0700)]
Improve string comparisons

Summary:
Any pair of read-compatible (same type, same traits) basic_strings (`basic_fbstring` or `std::basic_string`) can now be compared to each other with the `==`, `!=`, `<`, `>`, `<=`, and `>=` operators.

If you have a C++14 environment this allows you to use the heterogeneous comparison lookup methods from N3657: you can query containers which store either string type with either string type efficiently.

Reviewed By: yfeldblum, ot

Differential Revision: D4905697

fbshipit-source-id: 2ea976ebf40af45d64c1d8c1c08847feb3b9db68

5 years agoInclude <strings.h> in portability/String.h
Andrew Krieger [Wed, 19 Apr 2017 01:01:23 +0000 (18:01 -0700)]
Include <strings.h> in portability/String.h

Summary:
portabilty/String.h defines functions for Windows which
are provided by <strings.h> on other platforms, but doesn't include
<strings.h> in that case.

Reviewed By: Orvid

Differential Revision: D4908770

fbshipit-source-id: b3326f78509c2aa1acb9c9279f01537b0a243400

5 years agoFail on implicit convert from BOOL on ObjC in folly::dynamic
Marc Horowitz [Tue, 18 Apr 2017 22:21:35 +0000 (15:21 -0700)]
Fail on implicit convert from BOOL on ObjC in folly::dynamic

Summary: On some platforms (iPhone 5C at least), ObjC/Objc++ BOOL is really signed char.  There is code which expects this to be a boolean when converted to dynamic (and then to JSON and into JS), but the old code treated it as a number.  This makes such code (like [mobileConfig getBool:]) fail to compile, so the developer needs to resolve the ambiguity one way or the other.

Reviewed By: yfeldblum

Differential Revision: D4648133

fbshipit-source-id: 76ece7803a1e966dca08bdb857af7990035544a0

5 years agoFix ASAN reported bug
Angelo Failla [Tue, 18 Apr 2017 07:10:48 +0000 (00:10 -0700)]
Fix ASAN reported bug

Reviewed By: yfeldblum

Differential Revision: D4898404

fbshipit-source-id: 82256ae3dcd76444dc1b192d3bb6d50f142cee81

5 years agofix incorrect usage of FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER in folly::Histogram
Tianjiao Yin [Tue, 18 Apr 2017 04:28:57 +0000 (21:28 -0700)]
fix incorrect usage of FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER in folly::Histogram

Summary: According to [clang documentation](http://clang.llvm.org/docs/AttributeReference.html#no-sanitize-clang-no-sanitize), the format is incorrect. This results unit-test failure with ubsan.

Reviewed By: yfeldblum

Differential Revision: D4901777

fbshipit-source-id: e9d012366c5e1911632e47fa4fb690820b761fc3

5 years agoFlat combining: Update statistics.
Maged Michael [Tue, 18 Apr 2017 00:59:47 +0000 (17:59 -0700)]
Flat combining: Update statistics.

Summary:
Modified FC stats. Added number of sessions and removed the number of out-of-memory record allocations.
Removed locking from reading stats to avoid deadlock if the lock is already held. Reading stats now assumes exclusive access.

Reviewed By: djwatson

Differential Revision: D4857132

fbshipit-source-id: 81e4f25040af3691f3e82fe3794ee72c7ff53a99

5 years agoRefactor setThreadName to have the std::thread::id overload as the implementation
Christopher Dykes [Tue, 18 Apr 2017 00:54:50 +0000 (17:54 -0700)]
Refactor setThreadName to have the std::thread::id overload as the implementation

Summary: The pthread_t overload will die in the next diff, but cleanup needs to be done first.

Reviewed By: yfeldblum

Differential Revision: D4900830

fbshipit-source-id: d0cd56c5bd7fe22904f631c0cc64dff66448127c

5 years agoDon't invoke undefined behavior when getting the pthread_t out of std::thread::id
Christopher Dykes [Mon, 17 Apr 2017 22:40:29 +0000 (15:40 -0700)]
Don't invoke undefined behavior when getting the pthread_t out of std::thread::id

Summary: This assumes I understand strict-aliasing rules correctly.

Reviewed By: yfeldblum

Differential Revision: D4900118

fbshipit-source-id: edba535d3ba799ac665d3f859dc4154b2c1b22cb

5 years agoAllow error message callback cancellation regardless of socket state.
Maxim Georgiev [Mon, 17 Apr 2017 19:04:17 +0000 (12:04 -0700)]
Allow error message callback cancellation regardless of socket state.

Summary: We should be able to reset error message callback in AsyncSocket evein if the socket is closed yet. It's common to keep callback installed while the socket is connected. Once the socket is closed, the deinitialization process starts. If the callback callee component gets deallocated before the socket object is deallocated, it should be able to cancel callbacks.

Reviewed By: yfeldblum

Differential Revision: D4897335

fbshipit-source-id: 8eee26f9ebcb78a01d55598be3aff6595a3ed852

5 years ago`IPVAddressV(46)::fromInverseArpaName` static methods v2017.04.17.00
Angelo Failla [Sun, 16 Apr 2017 10:10:17 +0000 (03:10 -0700)]
`IPVAddressV(46)::fromInverseArpaName` static methods

Summary:
In a previous diff I added toInverseArpaName methods but I forgot to add the
inverse. This change adds `IPVAddressV(46)::fromInverseArpaName` static methods.
I have also implemented some suggestions that were in D4867502 but I couldn't
incorporate because the diff was landed already.

Reviewed By: yfeldblum

Differential Revision: D4885198

fbshipit-source-id: b95752aa695d6675cb293f8df2daa1787383390f

5 years agoreplace #include <ios> in FBString.h with lighter #include <iosfwd>
Eric Niebler [Sat, 15 Apr 2017 16:47:21 +0000 (09:47 -0700)]
replace #include <ios> in FBString.h with lighter #include <iosfwd>

Summary:
FBString.h doesn't really use any of the facilities defined in <ios>, such as the stream manipulators. No sense dragging it into FBString.h.

This could potentially break downstream users if they are not already including the io facilities they are using. It's unlikely though because the actual stream types (std::ostream, std::istream) and stream objects (std::cout, std::cin) are defined in other headers that #include <ios>.

Reviewed By: yfeldblum, Orvid

Differential Revision: D4886133

fbshipit-source-id: 56adb93280eeeef8b09320b30fb224d4f72707bf

5 years agoAdd exception_tracer to OSS build
Tudor Bosman [Sat, 15 Apr 2017 02:57:03 +0000 (19:57 -0700)]
Add exception_tracer to OSS build

Summary:
What it says on the tin. Add the exception_tracer library to the folly OSS build, enabled with `--enable-exception-tracer`.
Closes https://github.com/facebook/folly/pull/580

Reviewed By: Orvid

Differential Revision: D4895533

Pulled By: yfeldblum

fbshipit-source-id: 4878826c71e7d6af17845b23abc07dc48ea1aa51

5 years agoAdd portability support for PThread's TLS API
Christopher Dykes [Sat, 15 Apr 2017 00:05:09 +0000 (17:05 -0700)]
Add portability support for PThread's TLS API

Summary:
This is the last piece needed to get Folly working on Windows without PThreads.
Updating Folly's test suite to support compiling without PThreads will come next.

Reviewed By: yfeldblum

Differential Revision: D4894048

fbshipit-source-id: 6076317e1364aef82a5d3cb306bea7c2226b3cdc

5 years agoRemove unused local in OpenSSLCertUtils
Christopher Dykes [Sat, 15 Apr 2017 00:03:04 +0000 (17:03 -0700)]
Remove unused local in OpenSSLCertUtils

Summary: It's unused, and MSVC is warning about that fact.

Reviewed By: anirudhvr

Differential Revision: D4894403

fbshipit-source-id: 767b944eb9fa0376c795555357c09bbf9179e24f

5 years agoSuppress more warnings for MSVC
Andrew Krieger [Fri, 14 Apr 2017 21:36:30 +0000 (14:36 -0700)]
Suppress more warnings for MSVC

Summary:
Several other warnings that aren't reasonable to disable globally occur in folly headers.

- Wrap the unreachable code warnings in MSVC specific disable blocks to prevent problems for users.
- Use more careful bit twiddling instead of negating unsigned types
- Enable a simpler overload for bool->float conversion than one which attempts float->bool.
- Delete one unneeded undef.

Reviewed By: yfeldblum

Differential Revision: D4891583

fbshipit-source-id: 4d2efda1fe720abcb083bf29b578c065127cda24

5 years agoUse folly::getCurrentThreadId() in SSLContext
Christopher Dykes [Fri, 14 Apr 2017 21:09:23 +0000 (14:09 -0700)]
Use folly::getCurrentThreadId() in SSLContext

Summary: Rather than duplicating logic (and #ifdefs), just call the helper function instead.

Reviewed By: yfeldblum

Differential Revision: D4888362

fbshipit-source-id: f5096f6029cf05526aa74bd40235ac8014824789

5 years agoMake folly::getCurrentThreadId() return a thread ID on OSX
Christopher Dykes [Fri, 14 Apr 2017 20:54:32 +0000 (13:54 -0700)]
Make folly::getCurrentThreadId() return a thread ID on OSX

Summary: It was previously returning a pointer masquerading as a `uint64_t`.

Reviewed By: yfeldblum

Differential Revision: D4888325

fbshipit-source-id: 6cf6ed09f0e7a39a8a2f93d3fa14b06913c27805

5 years agoAdd FOLLY_HAVE_PTRHEAD
Christopher Dykes [Fri, 14 Apr 2017 20:53:52 +0000 (13:53 -0700)]
Add FOLLY_HAVE_PTRHEAD

Summary:
Folly is gaining support for compiling without PThread support on Windows, but we need a way to know that at compile-time for certain APIs.
This also includes changes to guard the only API outside of portability/PThread.h that needs to be guarded on the existence of PThread.

Reviewed By: yfeldblum

Differential Revision: D4889526

fbshipit-source-id: 21175ad90f60a47718c7e2775e3b429b2aad62e2

5 years agoAdd support for building without PThread to the CMake files
Christopher Dykes [Fri, 14 Apr 2017 20:51:43 +0000 (13:51 -0700)]
Add support for building without PThread to the CMake files

Summary: Because, soon it won't be required.

Reviewed By: yfeldblum

Differential Revision: D4892076

fbshipit-source-id: 6bfbf5bf523262659c0af336f659398ae8545e50

5 years agoRemove the old SpinLock implementations
Christopher Dykes [Fri, 14 Apr 2017 18:14:45 +0000 (11:14 -0700)]
Remove the old SpinLock implementations

Summary: They aren't actually needed as the primary implementation is supported on all platforms.

Reviewed By: yfeldblum

Differential Revision: D4882687

fbshipit-source-id: 7208c5d3c1f35b29b0cabb6a20fe030fbf10b131

5 years agoRevert D4805628: [folly] Suppress more warnings for MSVC
Mark Williams [Fri, 14 Apr 2017 16:00:08 +0000 (09:00 -0700)]
Revert D4805628: [folly] Suppress more warnings for MSVC

Summary: This reverts commit 9574ea984e1e3daca01101259687f46effcf3a9f

Differential Revision: D4805628

fbshipit-source-id: 3285317a4c3f2012da1f13e9c91b6c623726c9b7

5 years agoInitialize the singleton-vault early in init()
Yedidya Feldblum [Fri, 14 Apr 2017 07:22:47 +0000 (00:22 -0700)]
Initialize the singleton-vault early in init()

Summary:
Initialize the singleton-vault early in `init()` to avoid ordering problems with other parts of `init()`.

Initialization is done by calling `SingletonVault::singleton()->registrationComplete()`. Do that before (almost) everything, in particular, before parsing args and initializing logging.

Note that this just marks it okay for singletons to be instantiated, but does not by itself instantiate any singletons. However, this is useful if, in some way, parsing args or initializing logging should happen to use singletons.

Reviewed By: andriigrynenko

Differential Revision: D4889777

fbshipit-source-id: 6817db22d38a498cd20e361fc574a146029432ec

5 years agoSuppress more warnings for MSVC
Andrew Krieger [Fri, 14 Apr 2017 07:06:53 +0000 (00:06 -0700)]
Suppress more warnings for MSVC

Summary:
Several other warnings that aren't reasonable to disable globally occur in folly headers.
- Wrap the unreachable code warnings in MSVC specific disable blocks to prevent problems for users.
- Cast to signed types to perform integral negation before casting back to unsigned for bit operations.
- Enable a simpler overload for bool->float conversion than one which attempts float->bool.
- Delete one unneeded undef.

(Note: this ignores all push blocking failures!)

Reviewed By: yfeldblum

Differential Revision: D4805628

fbshipit-source-id: 9574ea984e1e3daca01101259687f46effcf3a9f

5 years agoRemove pthread dependency from CacheLocality.h
Andrew Krieger [Fri, 14 Apr 2017 05:57:20 +0000 (22:57 -0700)]
Remove pthread dependency from CacheLocality.h

Summary:
For getting a thread id for hashing, std::this_thread::get_id()
is just as good and also removes an unneeded pthreads dependency. This enables
using MPMCQueue on Windows without pthreads as well.

Reviewed By: Orvid, yfeldblum

Differential Revision: D4879940

fbshipit-source-id: c4fb5eea165eb450240f94904aa26a10aa394d1b

5 years agoSwitch TimedRWMutex implementation to use lock_guard where possible
Christopher Dykes [Fri, 14 Apr 2017 04:25:29 +0000 (21:25 -0700)]
Switch TimedRWMutex implementation to use lock_guard where possible

Summary: As titled. There are some places where scoping prevents trivial conversion, so I've left those places with explicit lock/unlock calls.

Reviewed By: andriigrynenko, yfeldblum

Differential Revision: D4888812

fbshipit-source-id: c124306e0373ee9eb395cb98f88df63c91523d48

5 years agoUse getCurrentThreadID() rather than pthread_self() in MemoryIdler
Christopher Dykes [Fri, 14 Apr 2017 04:19:08 +0000 (21:19 -0700)]
Use getCurrentThreadID() rather than pthread_self() in MemoryIdler

Summary: Ignoring the questionability of the approach it's being used in, it's better to not have the direct PThread dependency.

Reviewed By: yfeldblum

Differential Revision: D4889245

fbshipit-source-id: da099c6f938dbe98c1b9eeaf4de0a27a2c4d65f1

5 years agoExplicitly use CreateFileA in readlink
Andrew Krieger [Fri, 14 Apr 2017 02:23:50 +0000 (19:23 -0700)]
Explicitly use CreateFileA in readlink

Summary:
In Unicode enabled projects, this errors because CreateFile aliases
CreateFileW, which takes wchar_t* not char*.

Reviewed By: Orvid, yfeldblum

Differential Revision: D4878424

fbshipit-source-id: b44b369c0533e74163f68d95c2bf353584033731

5 years agoSupport folly::getCurrentThreadID() without PThread
Christopher Dykes [Fri, 14 Apr 2017 01:52:20 +0000 (18:52 -0700)]
Support folly::getCurrentThreadID() without PThread

Summary: Just use the native Windows API call instead, as it gives the same result.

Reviewed By: yfeldblum

Differential Revision: D4887587

fbshipit-source-id: adbfd288bea425f1aff46d0685083807490f7f09

5 years agoDon't use pthread_spinlock_t in TimedRWMutex
Christopher Dykes [Fri, 14 Apr 2017 00:56:39 +0000 (17:56 -0700)]
Don't use pthread_spinlock_t in TimedRWMutex

Summary: `TimedMutex` was already using `folly::SpinLock`, so switch `TimedRWMutex` to do the same.

Reviewed By: andriigrynenko

Differential Revision: D4888005

fbshipit-source-id: 6e782347bc22dc186ed41f2e77c6614b8444bae2

5 years agoSwitch includes of PThread to the portability header
Christopher Dykes [Thu, 13 Apr 2017 20:57:26 +0000 (13:57 -0700)]
Switch includes of PThread to the portability header

Summary:
As part of the work towards getting Folly compiling without PThread, it needs to be treated as a non-portable include.
This switches the includes not already covered by other diffs.

Reviewed By: yfeldblum

Differential Revision: D4882777

fbshipit-source-id: d9521564c814f9bcff2fcb358cbb89b3777c327d

5 years agoFix 1/2 of exception_wrapper under MSVC
Christopher Dykes [Thu, 13 Apr 2017 19:45:06 +0000 (12:45 -0700)]
Fix 1/2 of exception_wrapper under MSVC

Summary:
MSVC didn't like referring to members of `exception_wrapper` in the initializer for a `static constexpr` field directly in `exception_wrapper`, so shift the initialization to the actual definition of the fields.
As the fields are only referred to via their address, dropping the `constexpr` loses nothing.

Reviewed By: ericniebler

Differential Revision: D4873939

fbshipit-source-id: 30b690b1ab3f2f7a25b9dc4863b46f64c811797d

5 years agoAdd method to check if SSL Lock is disabled
Neel Goyal [Thu, 13 Apr 2017 19:14:40 +0000 (12:14 -0700)]
Add method to check if SSL Lock is disabled

Summary:
Add a method where users can determine if a SSL lock is disabled.

This can help when it comes to making decisions about things like whether reusing SSL Contexts is safe in multithreaded programs.

Reviewed By: siyengar

Differential Revision: D4875780

fbshipit-source-id: 91e9259fee25856be1b77823559d16d0679bde5b

5 years agoKill a couple of PThread includes
Christopher Dykes [Thu, 13 Apr 2017 18:24:51 +0000 (11:24 -0700)]
Kill a couple of PThread includes

Summary: They aren't actually needed, and are in the way of being able to build Folly without PThread.

Reviewed By: yfeldblum

Differential Revision: D4882410

fbshipit-source-id: e4a48600f79c57bb965a35fab94962a29b8e06d4

5 years agoAdd CMake build system
Christopher Dykes [Thu, 13 Apr 2017 05:25:15 +0000 (22:25 -0700)]
Add CMake build system

Summary: This is for use on Windows only, and does not support Linux or OSX in the slightest. There are probably still a few hacks laying around in it, but it works, and that's good enough for now.

Reviewed By: yfeldblum

Differential Revision: D4873498

fbshipit-source-id: 5952a927037dc1d56c51e71d51ba506d2cd17357

5 years agoAdd bzip2 support
Nick Terrell [Thu, 13 Apr 2017 02:43:02 +0000 (19:43 -0700)]
Add bzip2 support

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

5 years agoFix the last issues with exception_wrapper under MSVC
Christopher Dykes [Thu, 13 Apr 2017 01:19:37 +0000 (18:19 -0700)]
Fix the last issues with exception_wrapper under MSVC

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

5 years agoReplace Subprocess::pipe* syntax sugar with Subprocess::Options().pipe*
Alexey Spiridonov [Wed, 12 Apr 2017 21:43:04 +0000 (14:43 -0700)]
Replace Subprocess::pipe* syntax sugar with Subprocess::Options().pipe*

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

5 years agoDelete | operator for Subprocess::Options
Alexey Spiridonov [Wed, 12 Apr 2017 21:43:03 +0000 (14:43 -0700)]
Delete | operator for Subprocess::Options

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

5 years agoFix zlib + lzma memory usage inefficiency
Nick Terrell [Wed, 12 Apr 2017 19:44:56 +0000 (12:44 -0700)]
Fix zlib + lzma memory usage inefficiency

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

5 years agocodemod: ASN1_STRING_data -> ASN1_STRING_get0_data
Jude Taylor [Wed, 12 Apr 2017 17:57:54 +0000 (10:57 -0700)]
codemod: ASN1_STRING_data -> ASN1_STRING_get0_data

Reviewed By: anirudhvr

Differential Revision: D4830205

fbshipit-source-id: 55f34c3bddead8a73174c403f76572248c541a10

5 years agoMake folly::StrictConjunction usable under MSVC
Christopher Dykes [Wed, 12 Apr 2017 17:44:00 +0000 (10:44 -0700)]
Make folly::StrictConjunction usable under MSVC

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

5 years agoProvide a copy ctor for Digest that copies the current hash context
Jude Taylor [Wed, 12 Apr 2017 16:40:55 +0000 (09:40 -0700)]
Provide a copy ctor for Digest that copies the current hash context

Summary: opensource changes for t16702532

Reviewed By: yfeldblum

Differential Revision: D4846899

fbshipit-source-id: 67a610ff399e95c7cf1c9c8a5950f79bfc3aabb9

5 years agoAdd memory padding and alignment to prevent false sharing
Artem Lantsev [Wed, 12 Apr 2017 09:16:51 +0000 (02:16 -0700)]
Add memory padding and alignment to prevent false sharing

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

5 years agoSupport linux namespace clone flags
Aravind Anbudurai [Wed, 12 Apr 2017 08:36:29 +0000 (01:36 -0700)]
Support linux namespace clone flags

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

5 years agoIPAddressV(46) methods to convert IPs to their inverse in-addr.arpa / ip6.arpa repres...
Angelo Failla [Wed, 12 Apr 2017 04:13:21 +0000 (21:13 -0700)]
IPAddressV(46) methods to convert IPs to their inverse in-addr.arpa / ip6.arpa representation

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

5 years agonon-throwing, non-allocating exception_wrapper
Eric Niebler [Tue, 11 Apr 2017 23:12:59 +0000 (16:12 -0700)]
non-throwing, non-allocating exception_wrapper

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

5 years agoTreat OpenSSL as a non-portable include
Christopher Dykes [Tue, 11 Apr 2017 21:17:10 +0000 (14:17 -0700)]
Treat OpenSSL as a non-portable include

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

5 years agoImplement clearenv in the portability headers
Christopher Dykes [Tue, 11 Apr 2017 19:26:53 +0000 (12:26 -0700)]
Implement clearenv in the portability headers

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

5 years agoFix TLRefCount::useGlobal to work with TSAN
Andrii Grynenko [Tue, 11 Apr 2017 06:30:46 +0000 (23:30 -0700)]
Fix TLRefCount::useGlobal to work with TSAN

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

5 years agoFix Fiber::LocalData leak for large fiber locals
Andrii Grynenko [Tue, 11 Apr 2017 06:14:38 +0000 (23:14 -0700)]
Fix Fiber::LocalData leak for large fiber locals

Summary: facepaw

Reviewed By: yfeldblum

Differential Revision: D4856227

fbshipit-source-id: 17a73d4d630c6efe1763bbd8aff8b7a2c7721c27

5 years agoRevert D4832473: [Folly] Disable EnvUtil::setAsCurrentEnvironment() on platforms...
Christopher Dykes [Tue, 11 Apr 2017 02:23:54 +0000 (19:23 -0700)]
Revert D4832473: [Folly] Disable EnvUtil::setAsCurrentEnvironment() on platforms without clearenv()

Summary: This reverts commit a80aabb5a223264746ab45e3138d065bce5fe99c

Differential Revision: D4832473

fbshipit-source-id: 1a78d61f3f09f1064876a786c15601a091f4402b

5 years agoRemove superfluous std::move
Alexander Shaposhnikov [Mon, 10 Apr 2017 22:24:47 +0000 (15:24 -0700)]
Remove superfluous std::move

Summary: Cleanup: remove superfluous std::move for return values.

Reviewed By: yfeldblum

Differential Revision: D4856421

fbshipit-source-id: bf2cb66f3b43eb8f3b183e22b0acd31e0a0c0958