Chad Parry [Thu, 12 May 2016 18:46:42 +0000 (11:46 -0700)]
Prevent leaks in ThreadLocalPtr initialization
Summary: While making an unrelated change, (
D3271563, which was needed from an unrelated change, (
D3237530)), I noticed a lack of exception safety here. If `std::bad_alloc` were thrown, then we don't want to leak memory.
Reviewed By: ericniebler
Differential Revision:
D3271911
fbshipit-source-id:
0d316c0fa865a7d64622c1d62160bb0c2b061d78
Michael Lee [Thu, 12 May 2016 16:44:29 +0000 (09:44 -0700)]
Include limits.h in IOVec.h.
Summary:
According to the POSIX definition, IOV_MAX is defined in
limits.h. Given that IOVec.h is used to provide IOV_MAX and similar,
it seems like we should add limits.h as well.
Differential Revision:
D3291996
fbshipit-source-id:
238140ebef7b1b90a28f3a67a25c5f5863538fc7
Christopher Dykes [Wed, 11 May 2016 23:55:28 +0000 (16:55 -0700)]
Make the sys/uio.h portability header work for Windows
Summary: Windows doesn't have sys/uio.h, so implement it. This doesn't adjust any includes of it yet, I'll leave that for a separate diff.
Reviewed By: yfeldblum
Differential Revision:
D2978042
fbshipit-source-id:
16d398a856de50b6c662f739eb11dfb851096592
Subodh Iyengar [Wed, 11 May 2016 19:34:00 +0000 (12:34 -0700)]
wangle support for TFO
Summary: Add server support for TFO to wangle.
Reviewed By: Orvid
Differential Revision:
D3275427
fbshipit-source-id:
466baa342e2e0c4751e9c96d1e660cffb90e0634
Lucian Grijincu [Wed, 11 May 2016 17:45:33 +0000 (10:45 -0700)]
folly: ubsan: format: avoid UB in abs(-INT_MIN)
Summary:
abs(-INT_MIN) is UB. Avoid it by first casting the number to
its unsigned equivalent and then negating that.
Reviewed By: yfeldblum
Differential Revision:
D3280835
fbshipit-source-id:
40922d686173e6467e15d5a6dc2b62ad718349b5
Christopher Dykes [Wed, 11 May 2016 16:51:11 +0000 (09:51 -0700)]
Add a compatibility shim for working with libevent on MSVC
Summary:
MSVC builds of libevent expect `evutil_socket_t` to be `HANDLE` values, but Folly, HHVM, and Thrift all use them as file descriptors.
This adds a `folly_event_set` function that always expects a file descriptor rather than a socket. This also changes the places in Folly that use it.
Reviewed By: mzlee, yfeldblum
Differential Revision:
D2874655
fbshipit-source-id:
66cfd86fd69a9fbac30d150445e4814cd5ca799e
Subodh Iyengar [Wed, 11 May 2016 07:14:01 +0000 (00:14 -0700)]
Make error size more explicit
Summary:
We shouldn't rely on the internal buffer size of openssl
for errors.
This makes it more explicit.
Reviewed By: knekritz
Differential Revision:
D3285918
fbshipit-source-id:
452bf16a3de151d0aa79c774f2fdfc1e08ee6f9c
Neel Goyal [Tue, 10 May 2016 23:23:24 +0000 (16:23 -0700)]
Add NETWORK_ERROR to switch statement
Summary: Add NETWOR_ERROR to switch so it doesn't fall into Invalid Exception block.
Differential Revision:
D3282448
fbshipit-source-id:
2cc5d21e436e6ac8f2f6581d99341ac47cf5b023
Kyle Nekritz [Tue, 10 May 2016 19:14:39 +0000 (12:14 -0700)]
Add additional ALPN mismatch tests.
Reviewed By: siyengar
Differential Revision:
D3264727
fbshipit-source-id:
fb10558096e73a3cbb6f2fb93296524c0206910d
Faidon Liambotis [Tue, 10 May 2016 18:05:26 +0000 (11:05 -0700)]
Fix a few typos all over the code
Summary:
These are pretty trivial. Debian's lint tool (lintian) warns about those
in its verbose mode, and since we saw them when packaging for Debian, we
thought of fixing them and forwarding them upstream.
Closes https://github.com/facebook/folly/pull/345
Reviewed By: Orvid
Differential Revision:
D2769801
Pulled By: elliottneilclark
fbshipit-source-id:
ad37cc53792f21aae6558ba256f20cb56c6caab5
Jaak Ristioja [Tue, 10 May 2016 17:42:47 +0000 (10:42 -0700)]
docs/Overview.md: Fixed 2 hyperlinks.
Summary:
These didn't work properly in GitHub.
Closes https://github.com/facebook/folly/pull/375
Differential Revision:
D3281872
Pulled By: elliottneilclark
fbshipit-source-id:
b5398267ff5856bb6a7c4a3b963ae5cb47859bc3
Lucian Grijincu [Tue, 10 May 2016 06:00:19 +0000 (23:00 -0700)]
folly: ubsan: disable integer overflow tests in Histogram
Summary:
It would be nice to fix, but it's going to be easier to do when folly
support is for GCC>=5 which adds `__builtin_add_overflow`.
For now disable the check as the Histgram code handles overflow
correctly and has tests for these cases.
Fixes need to be done for both float and integer types as Histogram is used with both.
Reviewed By: meyering
Differential Revision:
D3280260
fbshipit-source-id:
56e524c517566a4547346859be7770eda2acee96
Lucian Grijincu [Tue, 10 May 2016 04:16:26 +0000 (21:16 -0700)]
folly: ubsan: cast to unsigned to avoid negative-left-shift
Summary:
The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated
bits are filled with zeros.
If E1 has a signed type and non-negative value, and E1 × 2E2 is
representable in the result type, then that is the resulting value;
otherwise, the behavior is undefined.
The code assumed the signed left shift worked like an unsigned left
shift, so make that explicit.
Reviewed By: meyering
Differential Revision:
D3280325
fbshipit-source-id:
178b95ee36b7a1126a79bb825c2ad2ffa6fa9464
Lucian Grijincu [Tue, 10 May 2016 00:50:08 +0000 (17:50 -0700)]
folly: ubsan: fix "reference binding to null pointer of type 'char'"
Summary:
third-party-buck/build/libgcc/include/c++/4.9.x/bits/stl_vector.h:866:9: runtime error: reference binding to null pointer of type 'char'
```
Breakpoint 2, 0x0000000000494894 in __ubsan_handle_type_mismatch_abort ()
(gdb) bt
```
Reviewed By: meyering, yfeldblum
Differential Revision:
D3279234
fbshipit-source-id:
63a761587e5b3f79ece09fc99b9a593da0e44b75
Christopher Dykes [Tue, 10 May 2016 00:23:41 +0000 (17:23 -0700)]
Deal with some oddities of MSVC's preprocessor
Summary: MSVC's preprocessor is different in how it deals with passing arguments expanded from `__VA_ARGS__`, so we have to add a stub to force it to expand the arguments.
Reviewed By: yfeldblum
Differential Revision:
D3256328
fbshipit-source-id:
551434833d40e55498a9ab352eb74acdfd094835
Christopher Dykes [Tue, 10 May 2016 00:15:22 +0000 (17:15 -0700)]
Fix detection of std::make_unique under MSVC
Summary: MSVC doesn't define `__cplusplus` as a high enough value to trigger this, so add an explicit check for MSVC instead.
Reviewed By: yfeldblum
Differential Revision:
D3271647
fbshipit-source-id:
a1e5a5a7eb75dce066dfc7fae8b2086880dc4c3d
Lucian Grijincu [Tue, 10 May 2016 00:03:34 +0000 (17:03 -0700)]
folly: ubsan: &v[0] is undefined if v.empty()
Summary:
before:
[ RUN ] RangeFunc.Vector
bits/stl_vector.h:866:9: runtime error: reference binding to null pointer of type 'int'
Reviewed By: yfeldblum
Differential Revision:
D3279253
fbshipit-source-id:
957a8ec050f5c3b27febf7e6cd16ad1d307da169
Jim Meyering [Mon, 9 May 2016 21:05:43 +0000 (14:05 -0700)]
folly test: fix typo in RandomDataHolder::RandomDataHolder
Summary:
Running the folly/io/test:compression_test with a UBSAN-enabled binary would fail with this:
folly/io/test/CompressionTest.cpp:96:36: runtime error: shift exponent
16777216 is too large for 64-bit type 'size_t' (aka 'unsigned long')
That exposed the unwanted left-shift.
That made it so the actual "start" offsets were in the range [0..numThreads-1], rather than being
e.g., with numThreads == 8, [0,
16777216,
33554432, ...]. Oops.
Reviewed By: luciang
Differential Revision:
D3277606
fbshipit-source-id:
4bc48f84b0065de070b62a810f08b96e36ea7136
Christopher Dykes [Mon, 9 May 2016 19:57:08 +0000 (12:57 -0700)]
Include <nmmintrin.h> in GroupVarint.h
Summary: Because it is the standard (well, Intel's standard) location for __m128i, and GCC, Clang, MSVC and ICC all implement it in that location.
Reviewed By: yfeldblum
Differential Revision:
D3270872
fbshipit-source-id:
fa0f0410670cdb310e656ca55ee0f568ca5ee06f
Lucian Grijincu [Mon, 9 May 2016 19:16:40 +0000 (12:16 -0700)]
folly: fbvector: ubsan: avoid memcpy(dest, nullptr, 0)
Reviewed By: meyering
Differential Revision:
D3277138
fbshipit-source-id:
7050d18c256ac15c8122d4af59aa31208b1466fd
Christopher Dykes [Mon, 9 May 2016 18:36:40 +0000 (11:36 -0700)]
Explicitly reference folly::detail
Summary: Due to some fun with the order MSVC does name lookup in templates, it ends up complaining that these are ambigious between folly::detail and folly::recordio_helpers::detail. The solution is to simply reference folly::detail explicitly.
Reviewed By: yfeldblum
Differential Revision:
D3271606
fbshipit-source-id:
e599ad8d8fe33b1e4ec0b838ddb5dfacfdf60159
Christopher Dykes [Mon, 9 May 2016 18:36:21 +0000 (11:36 -0700)]
Fix a few issues in the portability headers
Summary:
This fixes a few issues in the portability headers for MSVC.
Not entirely sure how I managed to cause these in the first place, but this fixes them anyways.
Reviewed By: yfeldblum
Differential Revision:
D3271859
fbshipit-source-id:
11a5d35246f29112563ee9079525aa37ced206ff
Philip Pronin [Mon, 9 May 2016 07:06:57 +0000 (00:06 -0700)]
Reverted commit
D3265572
Summary:
I would switch these to just use the intrinsic functions, but GCC 4.8 doesn't support them.
MSVC supports the intrinsics, which is the primary reason for the switch.
Reviewed By: yfeldblum
Differential Revision:
D3265572
fb-gh-sync-id:
3268f90d5234bdf77b3579504efd3dcd43f38aff
fbshipit-source-id:
3268f90d5234bdf77b3579504efd3dcd43f38aff
Andrii Grynenko [Sat, 7 May 2016 05:02:15 +0000 (22:02 -0700)]
Don't re-throw exceptions from default FiberManager exception handler
Summary: It's very unlikely that caller will handle such exceptions and FiberManager can proceed even if one task failed. DFATAL will ensure we still fail on such exceptions in debug builds.
Reviewed By: yfeldblum
Differential Revision:
D3273573
fb-gh-sync-id:
55eba19c16429a3c89a2fdf5363fd4b55b3998a2
fbshipit-source-id:
55eba19c16429a3c89a2fdf5363fd4b55b3998a2
Andrii Grynenko [Fri, 6 May 2016 17:26:04 +0000 (10:26 -0700)]
Don't throw on late singleton registration
Summary: Having singleton registered after registrationComplete() is called is not a hard failure. Replacing exception with ERROR, since we probably still want to avoid such situation.
Reviewed By: yfeldblum
Differential Revision:
D3266376
fb-gh-sync-id:
8130d279775348c835265987c95189bd3d8106f9
fbshipit-source-id:
8130d279775348c835265987c95189bd3d8106f9
Christopher Dykes [Fri, 6 May 2016 16:32:30 +0000 (09:32 -0700)]
Use intrinsics rather than inline assembly where possible
Summary:
I would switch these to just use the intrinsic functions, but GCC 4.8 doesn't support them.
MSVC supports the intrinsics, which is the primary reason for the switch.
Reviewed By: yfeldblum
Differential Revision:
D3265572
fb-gh-sync-id:
f12d16b8f64cf48adcb97958d7ae88d56689a96f
fbshipit-source-id:
f12d16b8f64cf48adcb97958d7ae88d56689a96f
Christopher Dykes [Fri, 6 May 2016 16:31:20 +0000 (09:31 -0700)]
Create the stdio.h portability header
Summary: Windows doesn't define a couple of functions.
Reviewed By: yfeldblum
Differential Revision:
D2990676
fb-gh-sync-id:
1a1354bd7976cb8b4747436d6907d65210ba506c
fbshipit-source-id:
1a1354bd7976cb8b4747436d6907d65210ba506c
Haijun Zhu [Fri, 6 May 2016 09:20:30 +0000 (02:20 -0700)]
Bind to a random file in unix domain socket test
Summary:
test console reports "address already in use" failure so add some
randomness to it.
Reviewed By: yfeldblum
Differential Revision:
D3265329
fb-gh-sync-id:
a825cce787394783bb8d18d92385d2497b163385
fbshipit-source-id:
a825cce787394783bb8d18d92385d2497b163385
Christopher Dykes [Fri, 6 May 2016 00:24:55 +0000 (17:24 -0700)]
Create the unistd.h portability header
Summary: Windows doesn't have it, and it's used in a lot of places.
Reviewed By: yfeldblum
Differential Revision:
D2997499
fb-gh-sync-id:
fbf8f5f087b8f39197d5bf2177e4d34efd74631f
fbshipit-source-id:
fbf8f5f087b8f39197d5bf2177e4d34efd74631f
Andrii Grynenko [Thu, 5 May 2016 23:41:33 +0000 (16:41 -0700)]
Allow optional atfork hook for singleton destruction
Summary: Grouping all folly::ThreadLocal atfork hooks in one. This allows proper ordering between folly::ThreadLocal hooks and hooks added by other libraries (we always want folly::ThreadLocal hooks to be registered first).
Reviewed By: ericniebler
Differential Revision:
D3262666
fb-gh-sync-id:
1aa928b9ddd484580f4a4a7b320e9e64164bb04a
fbshipit-source-id:
1aa928b9ddd484580f4a4a7b320e9e64164bb04a
Andrii Grynenko [Thu, 5 May 2016 20:22:42 +0000 (13:22 -0700)]
Implement LoopKeepAlive for EventBase
Summary: LoopKeepAlive can be useful to tell EventBase, that loop() shouldn't return even if there are no events registered, because some tasks will later be added via runInEventBaseThread. While at least one LoopKeepAlive is alive - EventBase::loop() behaves like EventBase::loopForever().
Reviewed By: yfeldblum
Differential Revision:
D3261706
fb-gh-sync-id:
d91424d3d12cae11abd72cffdbd57f136f628dae
fbshipit-source-id:
d91424d3d12cae11abd72cffdbd57f136f628dae
Andrii Grynenko [Thu, 5 May 2016 01:15:53 +0000 (18:15 -0700)]
Allow adding tasks to TaskIterator dynamically
Reviewed By: yfeldblum
Differential Revision:
D3244669
fb-gh-sync-id:
73fa4ecb0432a802e67ef922255a896d96f32374
fbshipit-source-id:
73fa4ecb0432a802e67ef922255a896d96f32374
Michael Lee [Thu, 5 May 2016 00:08:47 +0000 (17:08 -0700)]
Switch gflags to portability/GFlags.h
Summary:
There are two places that still includes gflags/gflags.h:
portability/GFlags.h and futures/exercises/Koan.h. Also removing
gflags entirely from a couple of places which never reference it at
all.
Reviewed By: yfeldblum
Differential Revision:
D3203187
fb-gh-sync-id:
e7725fbf2c4b3c475c0035e1b0e8c6e1227f277f
fbshipit-source-id:
e7725fbf2c4b3c475c0035e1b0e8c6e1227f277f
Christopher Dykes [Wed, 4 May 2016 23:45:56 +0000 (16:45 -0700)]
Create the stdlib.h portability header
Summary: Windows doesn't have these functions under these names, so be nice to the code using it.
Reviewed By: yfeldblum
Differential Revision:
D3003641
fb-gh-sync-id:
1657545af6975c96aea4a48c359250828b5921e0
fbshipit-source-id:
1657545af6975c96aea4a48c359250828b5921e0
Christopher Dykes [Wed, 4 May 2016 23:45:53 +0000 (16:45 -0700)]
Create the fcntl.h portability header
Summary: Windows has it, but all it does is define a few constants.
Reviewed By: yfeldblum
Differential Revision:
D3002161
fb-gh-sync-id:
a719faf391125522b2cb21471a56e8a9fe894225
fbshipit-source-id:
a719faf391125522b2cb21471a56e8a9fe894225
Eric Niebler [Wed, 4 May 2016 21:45:20 +0000 (14:45 -0700)]
rearrange folly::Function so that its template arguments are deducable.
Summary:
`folly::Function` was an alias to a more complex type with template arguments that could not be deduced. For example, the call to `foo` below was failing to compile.
```
template <class R, class... As>
void foo(folly::Function<R(As...)> f) {
}
int main() {
foo( folly::Function<void(int)>{ [](int i){} } );
}
```
Rearrange the code so that folly::Function is no longer an alias, thus making its template arguments deducable.
Reviewed By: luciang, spacedentist
Differential Revision:
D3256130
fb-gh-sync-id:
fb403e48d161635b3b7f36e53b1679eb46cbfe7f
fbshipit-source-id:
fb403e48d161635b3b7f36e53b1679eb46cbfe7f
Andrii Grynenko [Wed, 4 May 2016 21:32:54 +0000 (14:32 -0700)]
folly::Future integration with Python
Summary:
This diff implements two functions which can be used to bridge C++ asynchronous APIs with Python.
1. getExecutor(event_loop) allows extracting a folly::Executor-compatible object from Python event_loop.
2. wrapFuture wraps any folly::Future object in a Python Future object.
Reviewed By: ambv
Differential Revision:
D2878731
fb-gh-sync-id:
83628b6b24d6039999f88c5de441e41064b2417e
fbshipit-source-id:
83628b6b24d6039999f88c5de441e41064b2417e
Christopher Dykes [Wed, 4 May 2016 17:29:15 +0000 (10:29 -0700)]
Fix the weak references to JEMalloc under MSVC
Summary: While the previous version did compile, it would generate warnings about symbols being defined in multiple places.
Reviewed By: yfeldblum
Differential Revision:
D3255815
fb-gh-sync-id:
72f5079a3973a04bdc0b469b97ba46181e40353b
fbshipit-source-id:
72f5079a3973a04bdc0b469b97ba46181e40353b
Christopher Dykes [Wed, 4 May 2016 17:28:49 +0000 (10:28 -0700)]
Implement __builtin_ctzll for MSVC
Summary: MSVC doesn't have it, but Folly uses it, so implement it in the Builtins portability header.
Reviewed By: yfeldblum
Differential Revision:
D3256123
fb-gh-sync-id:
fd9ea1b6098d97cf1fde4732905bae9bde8cd8ad
fbshipit-source-id:
fd9ea1b6098d97cf1fde4732905bae9bde8cd8ad
Christopher Dykes [Wed, 4 May 2016 17:28:12 +0000 (10:28 -0700)]
Don't initialize kDestroyWaitTime in-class
Summary: MSVC doesn't like it when you try to initialize a static in-class non-primitive constexpr member. It was only used in one place, so stick the definition in that function instead.
Reviewed By: yfeldblum
Differential Revision:
D3255178
fb-gh-sync-id:
e4a862a2662c4f5376c19fc52827cb2953f01e52
fbshipit-source-id:
e4a862a2662c4f5376c19fc52827cb2953f01e52
Christopher Dykes [Wed, 4 May 2016 17:27:25 +0000 (10:27 -0700)]
Use std::thread::id in Fiber rather than a syscall
Summary: syscall() doesn't exist on Windows, but std::thread::id is standardized, and can do what we need it for, so use it instead.
Reviewed By: yfeldblum
Differential Revision:
D3256064
fb-gh-sync-id:
efddac82c117ccd8a53c8c93248529000b4326a5
fbshipit-source-id:
efddac82c117ccd8a53c8c93248529000b4326a5
Christopher Dykes [Wed, 4 May 2016 17:26:43 +0000 (10:26 -0700)]
Don't attempt to implicitly convert an atomic<T> to bool
Summary: MSVC doesn't like it, so the other uses were changed to .load() explicitly a while back, but this use has been added since then.
Reviewed By: yfeldblum
Differential Revision:
D3255261
fb-gh-sync-id:
11d49902eb3ef7113a7c57cc760353554a487496
fbshipit-source-id:
11d49902eb3ef7113a7c57cc760353554a487496
Marcus Holland-Moritz [Wed, 4 May 2016 10:28:44 +0000 (03:28 -0700)]
Unpoison stack memory before deallocation
Summary:
This is a workaround (maybe even the correct fix if it turns out that ASan
can't detect this FP case) for the problem described in
https://llvm.org/bugs/show_bug.cgi?id=27627
where a memory region previously allocated by a fiber stack can overlap with
the region of an mmap'd file. Accessing parts of the mmap'd file close to
the stack region will trigger a false positive ASan error.
This change makes sure each fiber explicitly unpoisons its stack memory by
calling __asan_unpoison_memory_region in an ASan-enabled build.
Reviewed By: yhfung
Differential Revision:
D3257924
fb-gh-sync-id:
484062e80af67dfd39d2eaf3cbb52fa3483924eb
fbshipit-source-id:
484062e80af67dfd39d2eaf3cbb52fa3483924eb
Pavlo Kushnir [Wed, 4 May 2016 07:27:53 +0000 (00:27 -0700)]
Optimize copy/move
Summary: this diff provides methods that allow to avoid temporaries while cloning IOBufs. Also optimizes move constructor a bit - there is no need to call `decrementRefCount`, check for self assignment, etc.
Reviewed By: yfeldblum
Differential Revision:
D3250456
fb-gh-sync-id:
32b0180c28f36151c6786dba6f511b491b224200
fbshipit-source-id:
32b0180c28f36151c6786dba6f511b491b224200
Yedidya Feldblum [Wed, 4 May 2016 04:32:23 +0000 (21:32 -0700)]
Let via take a functor by universal reference
Summary:
[Folly] Let `via` take a functor by universal reference.
And perfect-forward the functor to the call to `then`.
Reviewed By: fugalh
Differential Revision:
D3255684
fb-gh-sync-id:
1b46a70fb9de88d21d785c0ce4d9dd3078829f13
fbshipit-source-id:
1b46a70fb9de88d21d785c0ce4d9dd3078829f13
Christopher Dykes [Wed, 4 May 2016 00:38:24 +0000 (17:38 -0700)]
Create the sockets portability header
Summary: The one header that doesn't split well. This is the last piece of the portability headers for Windows and is also the piece that has had the most thought put into it's design so-as to be as unintrusive as possible.
Reviewed By: yfeldblum
Differential Revision:
D3046525
fb-gh-sync-id:
761a5e359bc130b95585608ee18fda94a30dae2c
fbshipit-source-id:
761a5e359bc130b95585608ee18fda94a30dae2c
Marcelo Juchem [Tue, 3 May 2016 22:35:30 +0000 (15:35 -0700)]
More useful logging upon failed AsyncServerSocket::bind()
Summary: `AsyncServerSocket::bind()` would not give information like port or family name when failing to bind a socket. This diff addresses that by including this information in the exception. Two additional helper methods were added to `SocketAddress` to retrieve both the port and the family name from a `sockaddr` structure.
Reviewed By: ckwalsh, yfeldblum
Differential Revision:
D3249778
fb-gh-sync-id:
4edb28af5c211b7bf8d525b40844a5b0b6261e07
fbshipit-source-id:
4edb28af5c211b7bf8d525b40844a5b0b6261e07
Sven Over [Tue, 3 May 2016 21:27:37 +0000 (14:27 -0700)]
fix passing move-only types to via(Executor*, Func)
Summary: This diff fixes a problem with passing move-only types to folly::via.
Reviewed By: ericniebler
Differential Revision:
D3254906
fb-gh-sync-id:
8a9c703a8db0ccf20b9fb4fe9b80ad6cdcb3e388
fbshipit-source-id:
8a9c703a8db0ccf20b9fb4fe9b80ad6cdcb3e388
Yedidya Feldblum [Tue, 3 May 2016 09:15:22 +0000 (02:15 -0700)]
Deprecate boost::mpl
Summary:
[Folly] Deprecate `boost::mpl`.
The `std` has equivalents; prefer them.
Reviewed By: Gownta
Differential Revision:
D3247294
fb-gh-sync-id:
873697b7ea3ad069ff14662bc458a2e1cc840339
fbshipit-source-id:
873697b7ea3ad069ff14662bc458a2e1cc840339
Michael Lee [Mon, 2 May 2016 23:14:23 +0000 (16:14 -0700)]
Use portability for SYS_gettid
Summary: It's there for a reason, so use it.
Reviewed By: yfeldblum
Differential Revision:
D3249849
fb-gh-sync-id:
e9fe330693a173acd987e0c8fd1f03a982c8e082
fbshipit-source-id:
e9fe330693a173acd987e0c8fd1f03a982c8e082
Christopher Dykes [Mon, 2 May 2016 19:22:28 +0000 (12:22 -0700)]
Don't try to use the malloc_usable_size portability implementation if we have JEMalloc
Summary:
This is only an issue for the OSS HHVM build on OSX, where we have JEMalloc headers included directly.
In the OSS HHVM build, we define `USE_JEMALLOC` globally if we have JEMalloc, so gate the portability implementation behind that.
Reviewed By: mzlee
Differential Revision:
D3237449
fb-gh-sync-id:
07cf9b31114723ffd9f2b29cf449bee0ed8f5703
fbshipit-source-id:
07cf9b31114723ffd9f2b29cf449bee0ed8f5703
Neel Goyal [Mon, 2 May 2016 16:30:18 +0000 (09:30 -0700)]
Set the appropriate AsyncSocketExceptionType from SSLException
Summary:
We should use the appropriate AsyncSocketExceptionType when firing SSLExceptions. This derives the type from the constructor args, and introduces a `NETWORK_ERROR` exception type. Open to suggestions on reusing something there.
Additionally, rename getType() to getSSLError() to prevent hiding the AsyncSocketException::getType.
Reviewed By: siyengar
Differential Revision:
D3241204
fb-gh-sync-id:
de631dfb3554177d5bd561f4b91e767c882767d3
fbshipit-source-id:
de631dfb3554177d5bd561f4b91e767c882767d3
Anirudh Ramachandran [Mon, 2 May 2016 16:12:01 +0000 (09:12 -0700)]
Simplify CryptoSSLRequestManager using unified futures API
Summary:
This diff unifies the nearly-replicated call paths for ECDSA and RSA
sign request/response/fallback/etc. into one generic futures-based sign API.
Once this is tested, we should be able to remove ~500 lines of code from
CryptoSSLRequestManager
Depends on
D3094660
Reviewed By: siyengar
Differential Revision:
D3116535
fb-gh-sync-id:
11c50d81dab39e5426679b5a172c1ece2039fc10
fbshipit-source-id:
11c50d81dab39e5426679b5a172c1ece2039fc10
Yedidya Feldblum [Mon, 2 May 2016 09:26:07 +0000 (02:26 -0700)]
Avoid glog when warning about Singleton double-registration
Summary:
[Folly] Avoid glog when warning about `Singleton` double-registration.
Because registration happens at static initialization time, long before main, and possibly long before glog is initialized.
This makes a difference because, in some cases of double-registration, we can get a SIGSEGV with no message, because we are attempting to `LOG(FATAL)` when glog is uninitialized. What we would much rather have is a SIGABRT with a message.
Reviewed By: meyering
Differential Revision:
D3245047
fb-gh-sync-id:
4c5dd9d25025f197d7c490ffbb429af5ccb82182
fbshipit-source-id:
4c5dd9d25025f197d7c490ffbb429af5ccb82182
Andrii Grynenko [Sat, 30 Apr 2016 00:50:50 +0000 (17:50 -0700)]
Don't require folly::Unit in addTaskFinally
Summary:
In
D3241498 addTaskFuture was fixed to work with function returning void. This however changed addTaskFinally API to not allow finally functor which accepts Try<void>.
folly::fibers generally supports Try<void> so there's no reason to force users to use folly::Unit instead of void for addTaskFinally too.
Reviewed By: yfeldblum
Differential Revision:
D3243893
fb-gh-sync-id:
d1df54738157d2019120103956f59b3971ba25ff
fbshipit-source-id:
d1df54738157d2019120103956f59b3971ba25ff
Martin Martin [Fri, 29 Apr 2016 18:54:34 +0000 (11:54 -0700)]
Make addTask[Remote]Future() work for functions returning void.
Summary:
There's no Future<void>, you're supposed to use Future<Unit>
instead. Unit has a "Lift" template to do the conversion.
Reviewed By: andriigrynenko
Differential Revision:
D3241498
fb-gh-sync-id:
db12d4f343685bc613b701e023c860c2c903ed4c
fbshipit-source-id:
db12d4f343685bc613b701e023c860c2c903ed4c
Martin Martin [Fri, 29 Apr 2016 17:50:23 +0000 (10:50 -0700)]
Clang-format in preparation for other change
Summary: Clang-format in preparation for other change
Reviewed By: andriigrynenko
Differential Revision:
D3241297
fb-gh-sync-id:
b7b26812e9e61c291d5c7bdb523df8f28f2d9b4f
fbshipit-source-id:
b7b26812e9e61c291d5c7bdb523df8f28f2d9b4f
Philip Pronin [Fri, 29 Apr 2016 00:21:06 +0000 (17:21 -0700)]
don't destory defaultElfCache in exit handlers
Summary:
As it might be used during global destruction (for example, to
symbolize unhandled exception happened at that time).
Reviewed By: luciang, ot
Differential Revision:
D3238303
fb-gh-sync-id:
39d8a6f99d95e700586349436e961f3624c95718
fbshipit-source-id:
39d8a6f99d95e700586349436e961f3624c95718
Eric Niebler [Thu, 28 Apr 2016 23:39:30 +0000 (16:39 -0700)]
use std::forward instead of std::move on objects whose types have been deduced; don't take the sizeof incomplete types
Summary: Pretty sure std::forward is needed here instead of std::move. If you trace the call chain to see where the types of the objects come from, you'll see they can be deduced to be lvalues, so std::forward is the right choice. Also, moved some dicey looking code that appeared to be taking the size of some incomkplete types.
Reviewed By: spacedentist
Differential Revision:
D3214199
fb-gh-sync-id:
778190ffb25a648b839760a3dddfad8dc6d41c88
fbshipit-source-id:
778190ffb25a648b839760a3dddfad8dc6d41c88
Andrew Birchall [Thu, 28 Apr 2016 23:39:10 +0000 (16:39 -0700)]
Create ReadHolder::unlock
Summary:
Currently you need to depend on the destructor of `ReadHolder` (using closures as in code block #1 below or empty assignment as in code block #2 below) to ensure that a `ReadHolder` goes out of scope (and unlocks) in order to subsequently acquire a write lock via `WriteHolder` without deadlocking.
This diff introduces a way of unlocking a `ReadHolder` while it's still in scope such that a `WriteHolder` can be acquired. This makes the code more straight forward (reducing the risk of deadlock due to a programmer's misunderstanding of how `SharedMutex` / the holder framework works) => see code block # 3 below
Also add some documentation about why `WriteHolder::WriteHolder(ReadHolder&&)` doesn't exist
Code Block #1 : Use of closures
```
class foo {
public:
std::string getMemoizedData() {
{
folly::SharedMutex::ReadHolder readHolder(lock_);
if (!data_.empty()) {
// important to return by value, otherwise caller might access
// data_ after we release the read lock
return data_;
}
}
{
// try again with a write lock
folly::SharedMutex::WriteHolder writeHolder(lock_);
if (data_.empty()) {
data_ = "my awesome string";
}
return data_;
}
}
private:
folly::SharedMutex lock_;
std::string data_;
};
```
Code Block #2 : Use of empty assignment
```
class foo {
public:
std::string getMemoizedData() {
folly::SharedMutex::ReadHolder readHolder(lock_);
if (!data_.empty()) {
// important to return by value, otherwise caller might access
// data_ after we release the read lock
return data_;
}
readHolder = {};
// try again with a write lock
folly::SharedMutex::WriteHolder writeHolder(lock_);
if (data_.empty()) {
data_ = "my awesome string";
}
return data_;
}
private:
folly::SharedMutex lock_;
std::string data_;
};
```
Code Block #3 : Use of unlock()
```
class foo {
public:
std::string getMemoizedData() {
folly::SharedMutex::ReadHolder readHolder(lock_);
if (!data_.empty()) {
// important to return by value, otherwise caller might access
// data_ after we release the read lock
return data_;
}
readHolder->unlock();
// try again with a write lock
folly::SharedMutex::WriteHolder writeHolder(lock_);
if (data_.empty()) {
data_ = "my awesome string";
}
return data_;
}
private:
folly::SharedMutex lock_;
std::string data_;
};
```
Reviewed By: yfeldblum
Differential Revision:
D3176025
fb-gh-sync-id:
c7d47ca71df08673c7c1f1fd5ed9e01a663c1797
fbshipit-source-id:
c7d47ca71df08673c7c1f1fd5ed9e01a663c1797
Lucian Grijincu [Thu, 28 Apr 2016 21:34:27 +0000 (14:34 -0700)]
folly: Function: in-class init, drop (void*) casts
Summary: A few code cleanups, no functionality changes.
Reviewed By: ericniebler
Differential Revision:
D3231369
fb-gh-sync-id:
1a1c8508aab6dce7279e9dfc3f3da6add5496c67
fbshipit-source-id:
1a1c8508aab6dce7279e9dfc3f3da6add5496c67
Subodh Iyengar [Thu, 28 Apr 2016 19:10:12 +0000 (12:10 -0700)]
Better exception types to SSLexception
Summary:
Better enum exception types for SSLException.
These enum types are fairly high level, and more
info can be gleaned from the error.what()
Reviewed By: knekritz
Differential Revision:
D3234501
fb-gh-sync-id:
7cd4fbccd7f4367354dc3bd1fe4cd480d58d6173
fbshipit-source-id:
7cd4fbccd7f4367354dc3bd1fe4cd480d58d6173
Subodh Iyengar [Thu, 28 Apr 2016 19:10:01 +0000 (12:10 -0700)]
Stop abusing errno
Summary:
We abuse errno to propagate exceptions from AsyncSSLSocket.
Stop doing this and propagate exceptions correctly.
This also formats the exception messages better.
Reviewed By: anirudhvr
Differential Revision:
D3226808
fb-gh-sync-id:
15a5e67b0332136857e5fb85b1765757e548e040
fbshipit-source-id:
15a5e67b0332136857e5fb85b1765757e548e040
Subodh Iyengar [Thu, 28 Apr 2016 18:12:54 +0000 (11:12 -0700)]
Strict validation for certs
Summary: Add X509 param types
Reviewed By: knekritz
Differential Revision:
D3230008
fb-gh-sync-id:
660a2f5bdc9355f5b42c2ccfb1d7cab83df34fc2
fbshipit-source-id:
660a2f5bdc9355f5b42c2ccfb1d7cab83df34fc2
Nicholas Ormrod [Thu, 28 Apr 2016 17:41:19 +0000 (10:41 -0700)]
Fix asan build
Summary:
The array-bounds checker in gcc complains that r could be -1 after leaving CHECK_ERR in ASAN mode. Switch to DCHECK to avoid this possibility. The code was not initially compiling; now it does.
Error from gcc:
array subscript is below array bounds [-Werror=array-bounds]
Reviewed By: yfeldblum
Differential Revision:
D3232694
fb-gh-sync-id:
17f579eb152b661a8e5e4ed29ef91eec405fb90a
fbshipit-source-id:
17f579eb152b661a8e5e4ed29ef91eec405fb90a
Christopher Dykes [Thu, 28 Apr 2016 17:17:19 +0000 (10:17 -0700)]
Use the portability header for malloc_usable_size in small_vector.h
Summary: `small_vector.h` had it's own thing being defined inline, and it was breaking the OSX build of HHVM, so have it use the portability header instead.
Reviewed By: yfeldblum
Differential Revision:
D3232885
fb-gh-sync-id:
2078a54d1ec9700e81e0a9f4baed8e2d623fa5f3
fbshipit-source-id:
2078a54d1ec9700e81e0a9f4baed8e2d623fa5f3
Andrii Grynenko [Thu, 28 Apr 2016 04:00:57 +0000 (21:00 -0700)]
Fix races in TLRefCount
Summary:
This fixes 2 races in TLRefCount:
1. Thread-local constructor race, exposed by the stress test. It was possible for LocalRefCount to be created (grabbing collectGuard), but not be added to the thread-local list, so that accessAllThreads wasn't collecting it. collectAll() was then blocking waiting on baton to be posted, causing a dead-lock.
2. LocalRefCount::count_ has to be made atomic, because otherwise += operation may be not flushed (nbronson explained the race in
D3133443).
Reviewed By: djwatson
Differential Revision:
D3166956
fb-gh-sync-id:
17d58a215ebfc572f8316ed46bafaa5e6a9e2368
fbshipit-source-id:
17d58a215ebfc572f8316ed46bafaa5e6a9e2368
Giuseppe Ottaviano [Thu, 28 Apr 2016 00:47:43 +0000 (17:47 -0700)]
Further Function simplification
Summary:
Use tag dispatching instead of `enable_if`: it is clearer, it
sidesteps the GCC mangling bug, and more importantly the conditional
doesn't leak into the symbol, making stack traces and profiles more
readable.
Testing on a compilation unit with 1000 `Function`s from simple lambdas.
Before:
```
folly::impl::Function<int (), false>::Function<main::{lambda()#1}, {lambda()#1}>(main::{lambda()#1}&&, std::enable_if<std::integral_constant<bool, ((sizeof (std::decay<main::{lambda()#1}>::type))<=(sizeof folly::detail::function::Data::small))&&std::is_nothrow_move_constructible<std::decay<main::{lambda()#1}> >::value>::value, folly::detail::Tag>::type)::Ops::call(folly::detail::function&)
```
After:
```
folly::impl::Function<int (), false>::OpsSmall<main::{lambda()#1}>::call(folly::detail::function::Data&)
```
Note that the function type is repeated 5 times before, and only once after. This makes a large difference with long namespaces.
Binary size is almost unaffected, compile times slightly better:
Before:
GCC opt: 22.3 seconds,
4435232 bytes
Clang dev: 7.7 seconds,
5257344 bytes
After:
GCC opt: 18.6 seconds,
4493920 bytes
Clang dev: 7.2 seconds,
5469136 bytes
Reviewed By: ericniebler
Differential Revision:
D3231530
fb-gh-sync-id:
6aa76e7f780a8afdbfed8a378f257ceb86dce704
fbshipit-source-id:
6aa76e7f780a8afdbfed8a378f257ceb86dce704
Pavlo Kushnir [Thu, 28 Apr 2016 00:45:07 +0000 (17:45 -0700)]
Faster onDestroy
Summary: there is no need to call `std::function::invoke` for every DestructorGuard.
Reviewed By: yfeldblum
Differential Revision:
D3229345
fb-gh-sync-id:
c42f8cd05576d56b6a9b2f9d06878d9b01a36e94
fbshipit-source-id:
c42f8cd05576d56b6a9b2f9d06878d9b01a36e94
Christopher Dykes [Wed, 27 Apr 2016 21:34:33 +0000 (14:34 -0700)]
Have the GFlags portability header stick things in namespaces
Summary:
Just like the real thing does.
This was causing some issues when trying to link against glog, which expects the flags to be namespaced like this.
Reviewed By: mzlee
Differential Revision:
D3230630
fb-gh-sync-id:
a73ab3044560d561a39eb91ceee1588c147a46c5
fbshipit-source-id:
a73ab3044560d561a39eb91ceee1588c147a46c5
Eric Niebler [Wed, 27 Apr 2016 17:02:00 +0000 (10:02 -0700)]
Reimplement folly::Function to improve compile times.
Summary:
folly::Function is causing significant compile time regressions. Reimplement it in a simpler way.
These are the times for a file containing 1000 instantiations of folly::Fuction (old), folly::Function (new), and std::function with **g++ 4.8 -O3** on my CentOS7 server.
| | Old `folly::Function` | `std::function` | New `folly::Function` |
|--------|-----------------------|-----------------|-----------------------|
| Time | 10m37s | 0m16.81s | 0m14.75s |
And for the executable size:
| | Old `folly::Function` | `std::function` | New `folly::Function` |
|--------|-----------------------|-----------------|-----------------------|
| Size | 10,409,504 | 732,150 | 562,781 |
That's a **43X** improvement in compile times and an **18X** reduction in executable bloat over the old implementation.
The times for **clang (trunk)** are very different:
| | Old `folly::Function` | `std::function` | New `folly::Function` |
|-------|-----------------------|-----------------|-----------------------|
| Time | 4m6s | 0m45.27s | 0m11.78s |
That's a **20X** improvement over the old implementation and almost a **4X** improvement over `std::function`.
For **gcc-5.3.0**, compile times are again different:
| | Old `folly::Function` | `std::function` | New `folly::Function` |
|-------|-----------------------|-----------------|-----------------------|
| Time | 2m49s | 0m18.99s | 0m20.70s |
With gcc-5.3, the new implementation "only" compiles 8x faster than the old one, and is roughly the same as `std::function`.
Reviewed By: spacedentist, ot, luciang
Differential Revision:
D3199985
fb-gh-sync-id:
b97982a9dc3a63140510babea34988932e89f2d9
fbshipit-source-id:
b97982a9dc3a63140510babea34988932e89f2d9
Kyle Nekritz [Wed, 27 Apr 2016 16:42:56 +0000 (09:42 -0700)]
Add recursion limit to folly::parseJson.
Summary: Without this, malicious inputs can crash anything using folly::parseJson.
Reviewed By: yfeldblum
Differential Revision:
D3219036
fb-gh-sync-id:
3604a060170c0201473c420035b21b018383789c
fbshipit-source-id:
3604a060170c0201473c420035b21b018383789c
Subodh Iyengar [Wed, 27 Apr 2016 16:13:48 +0000 (09:13 -0700)]
Remove dead code in AsyncSSLSocket
Summary: Remove dead code in AsyncSSLSocket.
Reviewed By: knekritz
Differential Revision:
D3226948
fb-gh-sync-id:
e85823f311de2539c6aa2d6bcc3ff3aee07045bf
fbshipit-source-id:
e85823f311de2539c6aa2d6bcc3ff3aee07045bf
Sven Over [Wed, 27 Apr 2016 13:46:08 +0000 (06:46 -0700)]
fix access-after-free bug in ProducerConsumerQueueTest
Summary: This bug causes failure when the test is run under ASAN.
Reviewed By: meyering
Differential Revision:
D3229494
fb-gh-sync-id:
a43c8332cc45f7892ac86cd0abb799616bca7779
fbshipit-source-id:
a43c8332cc45f7892ac86cd0abb799616bca7779
Pavlo Kushnir [Wed, 27 Apr 2016 07:20:04 +0000 (00:20 -0700)]
Cheaper bumpHandlingTime
Summary: no need in virtual call from EventHandler.
Reviewed By: yfeldblum
Differential Revision:
D3226960
fb-gh-sync-id:
eb9c191630e1a1ac022666201100e3778eb7b611
fbshipit-source-id:
eb9c191630e1a1ac022666201100e3778eb7b611
Jon Maltiel Swenson [Wed, 27 Apr 2016 01:12:20 +0000 (18:12 -0700)]
Optimize away IOBuf clones on hot path
Summary:
'get' is the most frequent memcached operation. On a get reply, we should go to heap
as little as possible. This diff optimizes for this scenario, where replies
have only one IOBuf field.
Reviewed By: pavlo-fb
Differential Revision:
D3226592
fb-gh-sync-id:
92e1a1fac5735bd268691cf11990a96ae6fa8309
fbshipit-source-id:
92e1a1fac5735bd268691cf11990a96ae6fa8309
Aditya Muttur [Tue, 26 Apr 2016 22:53:40 +0000 (15:53 -0700)]
Adding a constructor to UTF8Range that uses std::string
Summary:
Currently UTF8Range has a constructor that allows you construct an object of type UTF8Range using only an object of type folly::Range. Adding a constructor so that we can construct an UTF8Range object using a std::string.
Currently,
void sampleMethod(UTF8StringPiece sp) {...}
/*
...
*/
std::string str = "example";
folly::UTF8Range utf8Range(str);
folly::StringPiece sp(str);
sampleMethod(utf8Range); // works
sampleMethod(sp); // works
sampleMethod(str); // doesn't work
This diff hopes to fix this issue.
Reviewed By: ddrcoder
Differential Revision:
D3221144
fb-gh-sync-id:
dd6ec4d7790d4602dccb3b63a4861d358aed3608
fbshipit-source-id:
dd6ec4d7790d4602dccb3b63a4861d358aed3608
Mirek Klimos [Tue, 26 Apr 2016 16:58:33 +0000 (09:58 -0700)]
API to set folly::RequestContext for current scope, try 2
Summary: same as
D3156698, without changes in Cpp2Connection (which was the only real change in the diff)
Reviewed By: haijunz
Differential Revision:
D3222792
fb-gh-sync-id:
245c7add837c0fc6d0bc84aa7d80b929ba2ce386
fbshipit-source-id:
245c7add837c0fc6d0bc84aa7d80b929ba2ce386
Christopher Dykes [Tue, 26 Apr 2016 16:38:18 +0000 (09:38 -0700)]
Define DECLARE_VARIABLE in portability/GFlags.h
Summary: If we don't, then anywhere we include `glog/logging.h` after the portability header will get the `DECLARE_*` and `DEFINE_*` macros undefined -_-....
Reviewed By: mzlee
Differential Revision:
D3220797
fb-gh-sync-id:
52907ddcd6b222fb1c6423034ea999eac5ce09ab
fbshipit-source-id:
52907ddcd6b222fb1c6423034ea999eac5ce09ab
Michael Lee [Tue, 26 Apr 2016 15:43:27 +0000 (08:43 -0700)]
Remove extra dependency on Portability.h
Summary: This dependency is in the wrong order.
Reviewed By: knekritz
Differential Revision:
D3224312
fb-gh-sync-id:
98d2c58b75cf5f16892d462ae1b877d06bce3faa
fbshipit-source-id:
98d2c58b75cf5f16892d462ae1b877d06bce3faa
Pavlo Kushnir [Tue, 26 Apr 2016 09:27:37 +0000 (02:27 -0700)]
Use std::string in folly::dynamic
Summary: Why not kill fbstring entirely? There are some legitimate use cases. For example, `folly::IOBuf` supports `moveToFbstring()` method which is impossible to implement with `std::string`.
Reviewed By: joeg, snarkmaster
Differential Revision:
D3189410
fb-gh-sync-id:
9bb9090ca6012ac32ba9fb79041b26ec4888781f
fbshipit-source-id:
9bb9090ca6012ac32ba9fb79041b26ec4888781f
Yedidya Feldblum [Tue, 26 Apr 2016 07:56:27 +0000 (00:56 -0700)]
Retire BOOST_STATIC_ASSERT in favor of static_assert
Summary:
Retire `BOOST_STATIC_ASSERT` in favor of `static_assert`.
`static_assert` is part of C++ now, so we don't need workarounds like `BOOST_STATIC_ASSERT` anymore.
Partially automated:
hg grep -lw BOOST_STATIC_ASSERT | xargs perl -pi -e 's~\bBOOST_STATIC_ASSERT\(([^;]*)\);~static_assert(\1, "");~g'
hg grep -lw 'boost/static_assert.hpp' | xargs perl -pi -e 's,^#include <boost/static_assert\.hpp>\n,,gm'
Caught most instances. Formatting and remaining instances addressed manually.
Reviewed By: meyering
Differential Revision:
D3215944
fb-gh-sync-id:
f4552d5d9bfc416ce283923abe880437a4d0cba5
fbshipit-source-id:
f4552d5d9bfc416ce283923abe880437a4d0cba5
Stepan Palamarchuk [Mon, 25 Apr 2016 21:12:21 +0000 (14:12 -0700)]
Remove unnecessary construction of IOBuf in Cursor
Summary: This assignment is unnecessary, because in `for` loop we **always** call `cloneOneInto` that would assign another IOBuf to that IOBuf.
Reviewed By: alikhtarov
Differential Revision:
D3215861
fb-gh-sync-id:
ad87b99848aaae79f0870d49e0474f1abf0f28e5
fbshipit-source-id:
ad87b99848aaae79f0870d49e0474f1abf0f28e5
Andrew Cox [Mon, 25 Apr 2016 17:51:47 +0000 (10:51 -0700)]
UndelayedDestruction virtual=>override
Summary:
Had this in another diff, but it caused too much test noise. So I've separated
it out on it's own.
Reviewed By: yfeldblum
Differential Revision:
D3213605
fb-gh-sync-id:
9ebfcf8430da7c66a31868032a0cef1e616ffc58
fbshipit-source-id:
9ebfcf8430da7c66a31868032a0cef1e616ffc58
Sven Over [Sat, 23 Apr 2016 15:07:25 +0000 (08:07 -0700)]
use forward instead of move for universal references
Summary:When dealing with universal references, std::move will move from
objects that are passed as lvalue references. Instead std::forward
should be used, which only moves from an object if it's passed
as rvalue reference.
Reviewed By: yfeldblum
Differential Revision:
D3200402
fb-gh-sync-id:
14be071e8498dd64cb8b2583c0cc2dd383bfebb8
fbshipit-source-id:
14be071e8498dd64cb8b2583c0cc2dd383bfebb8
Hans Fugal [Fri, 22 Apr 2016 21:11:29 +0000 (14:11 -0700)]
update futures README
Summary:It's been awhile.
Still has intern URLs (#
10943549) but I'll fix that separately.
Reviewed By: jsedgwick
Differential Revision:
D3213245
fb-gh-sync-id:
ff60193ff368deaac8ca233d4289f30d8f6bb223
fbshipit-source-id:
ff60193ff368deaac8ca233d4289f30d8f6bb223
Sven Over [Fri, 22 Apr 2016 18:00:39 +0000 (11:00 -0700)]
Subprocess: allow non-copyable callbacks
Summary:Instead of std::function<bool(int, int)>, use folly::Function to
pass callbacks to Subprocess::communicate. This makes it possible
to pass non-copyable callables, which is especially interesting
because Subprocess::readLinesCallback returns a non-copyable
object.
This diff also fixes the forwarding of the callback passed to
readLinesCallback in case you pass an lvalue reference.
Reviewed By: snarkmaster
Differential Revision:
D3169956
fb-gh-sync-id:
7a906f9a3ab50502fc04e0d83a23ca5e0201bb3e
fbshipit-source-id:
7a906f9a3ab50502fc04e0d83a23ca5e0201bb3e
Yedidya Feldblum [Fri, 22 Apr 2016 06:14:27 +0000 (23:14 -0700)]
get_default and get_ref_default variants taking functions
Summary:[Folly] `get_default` and `get_ref_default` variants taking functions.
Useful if the default value is computationally expensive to construct or requires IO.
Reviewed By: andriigrynenko, spacedentist
Differential Revision:
D3189247
fb-gh-sync-id:
51c64293f8712d7590348d53cbfd892a5efd9e82
fbshipit-source-id:
51c64293f8712d7590348d53cbfd892a5efd9e82
Tobias Ritzau [Fri, 22 Apr 2016 02:04:13 +0000 (19:04 -0700)]
Updates the internal representation of signals in NotificationQueue
Summary: The signals were represented using bytes in a pipe or using a count on an event fd (when available). This count was ever growing and caused the pipe to overflow, and in both cases you would get signals on empty queues. This diff only writes to the fd if it there are no bytes to read. Due to races there can still be multiple bytes in the pipe, but overflowing should not be possible. Instead of blindly signaling when there could be messages in the queue, the signals are now synchronized with the state of the queue so that the signals are drained when the queue is empty. This also made it possible to skip the semaphore behavior of the event fd which should improve perf.
Reviewed By: dcolascione
Differential Revision:
D3198252
fb-gh-sync-id:
39e620b10c254ffcacabc4c5ac36950a215d4803
fbshipit-source-id:
39e620b10c254ffcacabc4c5ac36950a215d4803
Taiyuan Zhang [Thu, 21 Apr 2016 22:42:26 +0000 (15:42 -0700)]
fix cancelAllFunctions
Summary: as titled. When I tried re-adding all functions after cancelAllFunctions, it throws error. This is because it doesn't reset currentFunction to null.
Reviewed By: jjs0
Differential Revision:
D3209237
fb-gh-sync-id:
5b6e2d967fc3c0986320d23b8d61eb1bfbff8940
fbshipit-source-id:
5b6e2d967fc3c0986320d23b8d61eb1bfbff8940
chenkan [Thu, 21 Apr 2016 22:02:44 +0000 (15:02 -0700)]
fix: readvNoInt use wrong read function
Summary: Closes https://github.com/facebook/folly/pull/401
Reviewed By: yfeldblum
Differential Revision:
D3207682
Pulled By: snarkmaster
fb-gh-sync-id:
617aeec0e6fe1f46d2464df4b72a3e91c953dc12
fbshipit-source-id:
617aeec0e6fe1f46d2464df4b72a3e91c953dc12
Michael Lee [Wed, 20 Apr 2016 22:54:54 +0000 (15:54 -0700)]
Define more pieces of portability/GFlags
Summary: Add more compatibility for missing gflags
Reviewed By: yfeldblum
Differential Revision:
D3202560
fb-gh-sync-id:
d25e4abfe8ceee9fb329c9ba12d259d1d03d4974
fbshipit-source-id:
d25e4abfe8ceee9fb329c9ba12d259d1d03d4974
Marcelo Juchem [Wed, 20 Apr 2016 21:23:31 +0000 (14:23 -0700)]
Added FOLLY_IGNORE and FOLLY_SEMICOLON helper macros
Summary: these macros are generally useful for other higher-order macros
Reviewed By: yfeldblum
Differential Revision:
D3194777
fb-gh-sync-id:
667fc51c681786ad422309ee463881dc22c972f7
fbshipit-source-id:
667fc51c681786ad422309ee463881dc22c972f7
Michael Lee [Wed, 20 Apr 2016 20:24:25 +0000 (13:24 -0700)]
Clean up deprecation warnings
Summary:Clean up a deprecation warning for JSONSchema's use of
Singleton. This is in experimental, so the interface change should be
reasonable..
Reviewed By: agoder
Differential Revision:
D3203348
fb-gh-sync-id:
3283c7d9c507a545f3217eb5afc3734eb047b833
fbshipit-source-id:
3283c7d9c507a545f3217eb5afc3734eb047b833
Michael Lee [Wed, 20 Apr 2016 20:24:18 +0000 (13:24 -0700)]
Fix use of dynamic {} initialization in JSONSchemaTest
Summary: find replace 's/{([0-9, a-z"-]+)}/dynamic::array(\1)/g'
Reviewed By: agoder
Differential Revision:
D3203454
fb-gh-sync-id:
064bb2bdd0e19a80da32e8f4eb730fc4268d7cad
fbshipit-source-id:
064bb2bdd0e19a80da32e8f4eb730fc4268d7cad
Mirek Klimos [Wed, 20 Apr 2016 20:08:48 +0000 (13:08 -0700)]
Reverted commit
D3156698
Summary:There're currently two ways to set RequestContext
- RequestContext::create() - creates new context and sets it
- RequestContext::setContext(context) - sets context previously captured by saveContext
In most cases, the RequestContext is set back after the request is processed but sometimes it's not (especially with RequestContext::create). We want to measure cpu time for a request by measuring the total cpu time when a RequestContext is set, so we need to make sure that it's properly reset after the thread is done with the request. Scope guards can help us with that.
Reviewed By: haijunz
Differential Revision:
D3156698
fb-gh-sync-id:
7c3eb06c1cc27849071625011bf64c5ad36c0612
fbshipit-source-id:
7c3eb06c1cc27849071625011bf64c5ad36c0612
Alexey Spiridonov [Wed, 20 Apr 2016 19:08:29 +0000 (12:08 -0700)]
Throw on errors in read callback
Summary: Before this fix, the callback would silently ignore `ret == -1` if the error isn't `EAGAIN`.
Reviewed By: spacedentist
Differential Revision:
D3193845
fb-gh-sync-id:
e4a7aa37de7dab8ebe0633dd9888d8adc11dd1c2
fbshipit-source-id:
e4a7aa37de7dab8ebe0633dd9888d8adc11dd1c2
Michael Lee [Wed, 20 Apr 2016 02:47:54 +0000 (19:47 -0700)]
Backward compatibility for older versions of clang.
Summary: `__attribute__((no_sanitize("address")))` is not valid in clang 3.6 and earlier
Reviewed By: skotchvail
Differential Revision:
D3197412
fb-gh-sync-id:
bd555b030fe48268988299dd88b9b7aea54c1a73
fbshipit-source-id:
bd555b030fe48268988299dd88b9b7aea54c1a73
Michael Lee [Tue, 19 Apr 2016 14:52:23 +0000 (07:52 -0700)]
`detail::Futex` wants 4 bytes but MicroLock only gives you one
Summary: ^^^ this is a stack overflow in the test, and a possible stack or heap overflow.
Reviewed By: dcolascione
Differential Revision:
D3151717
fb-gh-sync-id:
b4f0660ebbb89139dff003870e132c312068d9a8
fbshipit-source-id:
b4f0660ebbb89139dff003870e132c312068d9a8
Mark Isaacson [Tue, 19 Apr 2016 07:46:56 +0000 (00:46 -0700)]
Add make_array to folly
Summary: This function is being proposed in WG21, the C++ standards body for inclusion in the STL via the Library Fundamentals v2 TS. Using the normal constructor for a std::array with an initializer list introduces a source of coupling between the # of elements you put in the initializer list and the size of the array you specify as a template argument. Worse still, if you put less things in the initializer list than the template argument specifies, it doesn't warn you that you've probably made a pretty devious and subtle error. With this function your array size will always be the same as the # of things you actually put in it. What's more, in some cases this can deduce the type of the elements as well.
Reviewed By: yfeldblum
Differential Revision:
D3164432
fb-gh-sync-id:
beceaae2ee01cd5f93dec86cf36efdb78a28b4a3
fbshipit-source-id:
beceaae2ee01cd5f93dec86cf36efdb78a28b4a3