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
Mirek Klimos [Mon, 18 Apr 2016 21:28:06 +0000 (14:28 -0700)]
API to set folly::RequestContext for current scope
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:
cfb678531810e8be5faaf02cb7803bd247557e42
fbshipit-source-id:
cfb678531810e8be5faaf02cb7803bd247557e42
Brian Walker [Mon, 18 Apr 2016 17:59:14 +0000 (10:59 -0700)]
NotificationQueue Logging for Android bug
Summary: Add some logging to figure out the state of the Qeueu when the write error happens.
Differential Revision:
D3190882
fb-gh-sync-id:
6515d77df8aa3086922cb4053f2e437f3e527a36
fbshipit-source-id:
6515d77df8aa3086922cb4053f2e437f3e527a36
Sven Over [Mon, 18 Apr 2016 01:37:01 +0000 (18:37 -0700)]
remove superfluous include directive
Summary:folly::fibers does not use folly::MoveWrapper anymore, so no need to
include that header file.
Reviewed By: yfeldblum
Differential Revision:
D3169374
fb-gh-sync-id:
2409b46156843fb0a1454b560c42186f1c412988
fbshipit-source-id:
2409b46156843fb0a1454b560c42186f1c412988
Sven Over [Sat, 16 Apr 2016 03:26:30 +0000 (20:26 -0700)]
remove MoveWrapper from io/async/AsyncUDPServerSocket.h
Summary:This is the last place in folly that uses MoveWrapper (other than
the MoveWrapper implementation itself and its tests, of course).
Instead of using a MoveWrapper, the object in question is moved
into the lambda using C++14 syntax, and the lambda is moved in a
call to EventBase::runInEventBaseThread which is possible now
that the EventBase methods accept non-copyable callbacks.
Reviewed By: yfeldblum
Differential Revision:
D3169316
fb-gh-sync-id:
2dcb1a523ac417f4619c607898e58b572648e3da
fbshipit-source-id:
2dcb1a523ac417f4619c607898e58b572648e3da
Andrii Grynenko [Sat, 16 Apr 2016 02:50:46 +0000 (19:50 -0700)]
Non-intrusive AtomicLinkedList
Summary:Renamed AtomicLinkedList to AtomicIntrusiveLinkedList.
AtomicLinkedList is a simple AtomicIntrusiveLinkedList wrapper, which handles intrusive list hook.
Reviewed By: yfeldblum
Differential Revision:
D3188171
fb-gh-sync-id:
0823b04a48336d65e0a6a8cd412c75f52afe02b9
fbshipit-source-id:
0823b04a48336d65e0a6a8cd412c75f52afe02b9
Michael Lee [Fri, 15 Apr 2016 22:16:46 +0000 (15:16 -0700)]
Forgot to fix the guard for String.cpp
Summary:
9ab69bc removed `__APPLE__` around the strndup definition
because it is defined on modern OSX. But there was another reference
in String.cpp. Fixing that.
Reviewed By: yfeldblum
Differential Revision:
D3186360
fb-gh-sync-id:
709c3b93cd22945e2237412637929df1979526c1
fbshipit-source-id:
709c3b93cd22945e2237412637929df1979526c1
Christopher Dykes [Fri, 15 Apr 2016 17:57:01 +0000 (10:57 -0700)]
Remove the strings.h portability header
Summary:Although, according to the manpage, these functions are defined in `strings.h`, but they are also defined in `string.h`. We never actually use these functions via `strings.h`, and instead only ever reference them via `string.h`.
To keep things sane, lets just move the functions into `string.h` and kill `strings.h`.
Reviewed By: yfeldblum
Differential Revision:
D3181596
fb-gh-sync-id:
8a474df510ddafc4c595b08b809a7c33e3256177
fbshipit-source-id:
8a474df510ddafc4c595b08b809a7c33e3256177
David Goldblatt [Fri, 15 Apr 2016 17:14:13 +0000 (10:14 -0700)]
Correctly deduce RNG type in folly::Random
Summary:Fix a bug in folly where it can't infer any RNG type except the
default-supplied parameter.
Differential Revision:
D3163421
fb-gh-sync-id:
23d3963ba19dac93fa3407f3a2dfd1d9aa39ea44
fbshipit-source-id:
23d3963ba19dac93fa3407f3a2dfd1d9aa39ea44
Michael Lee [Fri, 15 Apr 2016 00:20:26 +0000 (17:20 -0700)]
Fix build for no FOLLY_TLD_USE_FOLLY_TLS
Summary: unique_ptr doesn't cast to void*
Reviewed By: andriigrynenko
Differential Revision:
D3181346
fb-gh-sync-id:
5b912d2b5d46f3c9953b44d5ced7a8e1b4320678
fbshipit-source-id:
5b912d2b5d46f3c9953b44d5ced7a8e1b4320678
Andrii Grynenko [Thu, 14 Apr 2016 18:19:59 +0000 (11:19 -0700)]
Improve folly::ThreadLocal perf
Summary: This fixes folly::ThreadLocal perf after several refactorings which touched the code.
Reviewed By: ericniebler
Differential Revision:
D3170761
fb-gh-sync-id:
d44198f19aebc9f9f2588a65950efba0694e2a11
fbshipit-source-id:
d44198f19aebc9f9f2588a65950efba0694e2a11
Andrii Grynenko [Thu, 14 Apr 2016 04:30:45 +0000 (21:30 -0700)]
Fix GuardPageAllocator to do mprotect lazily
Summary:Currently GuargPageAllocator mmap's a memory block enough for 100 fiber stacks and then protects a bottom page for each stack. If FiberManager is used to process a single task, protecting 100 stacks doesn't make much sense, but is costly.
This change makes sure we protect a bottom page of every stack the first time given stack is requested.
Reviewed By: alikhtarov
Differential Revision:
D3139944
fb-gh-sync-id:
d9d724eaa0e65a227eac1d09a33018e6cb098aae
fbshipit-source-id:
d9d724eaa0e65a227eac1d09a33018e6cb098aae
Den Raskovalov [Thu, 14 Apr 2016 02:46:08 +0000 (19:46 -0700)]
remove duplicate licence prolog
Reviewed By: yfeldblum
Differential Revision:
D3174112
fb-gh-sync-id:
00a01f64fb43d2333818097bb2212e26e4dd5775
fbshipit-source-id:
00a01f64fb43d2333818097bb2212e26e4dd5775
Christopher Dykes [Wed, 13 Apr 2016 17:19:24 +0000 (10:19 -0700)]
Fix the includes in portability/Malloc.h
Summary:We use `size_t` but didn't include `<stdlib.h>`.
Fix #385
Reviewed By: markisaa
Differential Revision:
D3171643
fb-gh-sync-id:
1f915f9602c4be59a21cdf77b31fe18816f35f81
fbshipit-source-id:
1f915f9602c4be59a21cdf77b31fe18816f35f81
Neel Goyal [Wed, 13 Apr 2016 15:04:45 +0000 (08:04 -0700)]
Add method to get the connect timeout used for an AsyncSocket
Summary: Have the AsyncSocket keep track of the timeout used for connecting and add a getter to retrieve it.
Reviewed By: hiteshk
Differential Revision:
D3170625
fb-gh-sync-id:
61d0ecd8d975c49978a1cf222671aa16a2160499
fbshipit-source-id:
61d0ecd8d975c49978a1cf222671aa16a2160499
Michael Lee [Tue, 12 Apr 2016 17:59:21 +0000 (10:59 -0700)]
Sorry, forgot to add portability/Memory.cpp
Summary: Add it to the Makefile.am
Reviewed By: Orvid
Differential Revision:
D3168833
fb-gh-sync-id:
7184acc565ffebde0f93bc8bdce4d38ba1a79923
fbshipit-source-id:
7184acc565ffebde0f93bc8bdce4d38ba1a79923
Alexander Shaposhnikov [Mon, 11 Apr 2016 20:15:45 +0000 (13:15 -0700)]
Fix the order of EXPECT_EQ parameters
Summary:Change the order of EXPECT_EQ parameters to
EXPECT_EQ(expected, actual). It will make gtest print
the correct error message if a test fails.
Reviewed By: yfeldblum
Differential Revision:
D3161878
fb-gh-sync-id:
69e4536c6f396858d189a9d25904ef4df639ad49
fbshipit-source-id:
69e4536c6f396858d189a9d25904ef4df639ad49
Yedidya Feldblum [Sun, 10 Apr 2016 21:51:09 +0000 (14:51 -0700)]
Some cleanups to folly::EventBase after converting to folly::Function
Summary:[Folly] Some cleanups to `folly::EventBase` after converting to `folly::Function`.
* Fix up some comments referring to `std::function`.
* Remove the `SmallFunctor` bits - `folly::Function` takes over for that.
* Remove `runFunctionPtr` - it's unused.
Reviewed By: spacedentist
Differential Revision:
D3155511
fb-gh-sync-id:
38c75d1254993f59c8eaa7826dc8d9facb50a3a1
fbshipit-source-id:
38c75d1254993f59c8eaa7826dc8d9facb50a3a1
Adam Norton [Sat, 9 Apr 2016 02:30:43 +0000 (19:30 -0700)]
Add <new> header for placement new
Summary: This header is necessary for the placement new operator used in the construct method (line 265)
Reviewed By: yfeldblum
Differential Revision:
D3156741
fb-gh-sync-id:
84a64821553b42d46fb70b5ee267a401028c94f2
fbshipit-source-id:
84a64821553b42d46fb70b5ee267a401028c94f2
Tom Jackson [Thu, 7 Apr 2016 21:01:28 +0000 (14:01 -0700)]
Extensibility for folly::to<> through ADL
Summary: Primarily to support slightly more flexible implementations of `split()`;
Reviewed By: ot
Differential Revision:
D3116763
fb-gh-sync-id:
69023c0f26058516f25b9c1f9824055efc7021f9
fbshipit-source-id:
69023c0f26058516f25b9c1f9824055efc7021f9
Alexey Spiridonov [Thu, 7 Apr 2016 16:53:34 +0000 (09:53 -0700)]
DynamicParser to reliably and reversibly convert JSON to structs
Summary:We have a bunch of code that manually parses `folly::dynamic`s into program structures. I can be quite hard to get this parsing to be good, user-friendly, and concise. This diff was primarily motivated by the mass of JSON-parsing done by Bistro, but this pattern recurs in other pieces of internal code that parse dynamics.
This diff **not** meant to replace using Thrift structs with Thrift's JSON serialization / deserialization. When all you have to deal with is correct, structured plain-old-data objects produced by another program -- **not** manually entered user input -- Thrift + JSON is perfect. Go use that.
However, sometimes you need to parse human-edited configuration. The input JSON might have complex semantics, and require validation beyond type-checking. The UI for editing your configs can easily enforce correct JSON syntax. Perhaps, you can use `folly/experimental/JSONSchema.h` to have your edit UI provide type correctness. Despite all this, people can still make semantic errors, and those can be impossible to detect until you interpret the config at runtime. Also, as your system evolves, sometimes you need to break semantic backwards-compatibility for the sake of moving forward ? thus making previously valid configurations invalid, and requiring them to be fixed up manually.
So, people end up needing to write manual parsers for `dynamic`s. These all have very similar recurring issues:
- Verbose: to get an int field out of an object, typical code: (i) tests if the field is present, (ii) checks if the field is an integer, (iii) extracts the integer. Sometimes, you also want to handle exceptions, and compose helpful error messages. This makes the code far longer than its intent, and encourages people to write bad parsers.
- Unsystematic: sometimes, we use `if (const auto* p = dyn_obj.get_ptr("key")) { ... }`, other times we use `dyn_obj.getDefault()` or `if (dyn_obj.count())`, and so on. The patterns differ subtly in meaning. Exceptions sometimes get thrown, leading to error messages that cannot be understood by the user.
- Imperative parses: a typical parse proceeds step by step, and throws at the earliest error. This is bad because (i) errors have to be fixed one-by-one, instead of getting a full list upfront, (ii) even if 99% of the config is parseable, the imperative code has no way of recording the information it would have parsed after the first error.
`DynamicParser` fixes all of the above, and makes your parsing so clean that you might not even bother with `JSONSchema` as your first line of defense -- type-coercing, type-enforcing, friendly-error-generating C++ ends up being more concise. Besides all the sweet syntax sugar, `DynamicParser` lets you parse **all** the valid data in your config, while recording *all* the errors in a way that does not lose the original, buggy config. This means your code can parse a config that has errors, and still be able to meaningfully export it back to JSON. As a result, stateless clients (think REST APIs) can provide a far better user experience than just discarding the user?s input, and returning a cryptic error message.
For the details, read the docs (and see the example) in `DynamicParser.h`. Here are the principles of `DynamicParser::RECORD` mode in a nutshell:
- Pre-populate your program struct with meaningful defaults **before** you parse.
- Any config part that fails to parse will keep the default.
- Any config part that parses successfully will get to update the program struct.
- Any errors will be recorded with a helpful error message, the portion of the dynamic that caused the error, and the path through the dynamic to that portion.
I ported Bistro to use this in
D3136954. I looked at using this for JSONSchema's parsing of schemas, but it seemed like too much trouble for the gain, since it would require major surgery on the code.
Reviewed By: yfeldblum
Differential Revision:
D2906819
fb-gh-sync-id:
aa997b0399b17725f38712111715191ffe7f27aa
fbshipit-source-id:
aa997b0399b17725f38712111715191ffe7f27aa
Yedidya Feldblum [Thu, 7 Apr 2016 10:30:56 +0000 (03:30 -0700)]
Use folly::Function in folly::EventBase
Summary:[Folly] Use `folly::Function` in `folly::EventBase`.
`folly::Function` is moveable but noncopyable and therefore supports wrapping moveable but noncopyable lambdas - like the kind that arises when move-capturing a `std::unique_ptr`.
`std::function` is copyable - therefore it does not support wrapping such noncopyable lambdas.
Switching `folly::EventBase` to use it will allow callers to pass such noncopyable lambdas, allowing, e.g.:
```
auto numptr = folly::make_unique<int>(7); // unique_ptr is noncopyable
folly::EventBase eb;
eb.runInLoop([numptr = std::move(numptr)] { // therefore lambda is noncopyable
int num = *numptr;
});
eb.loop();
```
This allows us to move away from the `folly::MoveWrapper` hack, which worked like:
```
auto numptr = folly::make_unique<int>(7); // unique_ptr is noncopyable
auto numptrw = folly::makeMoveWrapper(std::move(numptr)); // MoveWrapper is "copyable" - hacky
folly::EventBase eb;
eb.runInLoop([numptrw] { // therefore lambda is "copyable" - hacky
int num = **numptrw;
});
```
We needed to do that hack while:
But neither condition is true anymore.
Reviewed By: spacedentist
Differential Revision:
D3143931
fb-gh-sync-id:
4fbdf5fb77eb5848ed1c6de942b022382141577f
fbshipit-source-id:
4fbdf5fb77eb5848ed1c6de942b022382141577f
Giuseppe Ottaviano [Wed, 6 Apr 2016 18:57:19 +0000 (11:57 -0700)]
Remove leftover comment in Portability.h
Reviewed By: luciang
Differential Revision:
D3145033
fb-gh-sync-id:
f37d0a2c6e22c1866134159b78722ff43d70918b
fbshipit-source-id:
f37d0a2c6e22c1866134159b78722ff43d70918b
Bert Maher [Wed, 6 Apr 2016 18:31:41 +0000 (11:31 -0700)]
malloc.h doesn't exist on OSX
Summary: Use malloc/malloc.h there instead
Reviewed By: Orvid
Differential Revision:
D3143768
fb-gh-sync-id:
3258b68df49cf7fbff28a3853663d39c147aee8b
fbshipit-source-id:
3258b68df49cf7fbff28a3853663d39c147aee8b
Michael Lee [Wed, 6 Apr 2016 15:00:14 +0000 (08:00 -0700)]
Start compiling a bit of `-Wshadow`
Summary: Sometimes variable shadowing is fine, sometimes it can cause subtle mistakes.
Reviewed By: yfeldblum
Differential Revision:
D3140450
fb-gh-sync-id:
acf7195ad65614d4f012bef8ce7dccb3a3038456
fbshipit-source-id:
acf7195ad65614d4f012bef8ce7dccb3a3038456
Sven Over [Wed, 6 Apr 2016 10:55:14 +0000 (03:55 -0700)]
folly::fibers::Fiber: use folly::Function instead of std::function
Summary:We are jumping through some ugly hoops in the implementation of
fibers to allow for non-copyable functors/lambdas. We can get rid of
those by using folly::Function instead of std::function to store
functions in folly::fibers::Fiber.
This involves one observable interface change: the virtual function
folly::fibers::InlineFunctionRunner::run must take a
folly::Function<void()> argument instead of a std::function<void()>.
Reviewed By: andriigrynenko
Differential Revision:
D3102711
fb-gh-sync-id:
56705b972dc24cc0da551109ed44732b97cb6e13
fbshipit-source-id:
56705b972dc24cc0da551109ed44732b97cb6e13
Dmitry Pleshkov [Wed, 6 Apr 2016 04:39:18 +0000 (21:39 -0700)]
Allow usage of Symbolizer options for ExceptionStats printing
Summary: For exceptions aggregation conveniece
Reviewed By: philippv
Differential Revision:
D3128132
fb-gh-sync-id:
48c72df364228c1d2c8f29161c2b85c131b4fea8
fbshipit-source-id:
48c72df364228c1d2c8f29161c2b85c131b4fea8
James Sedgwick [Tue, 5 Apr 2016 22:05:33 +0000 (15:05 -0700)]
Function::asStdFunction()
Summary:This is an ugly but occassionally useful hack to accomodate cases
where we want to propagate folly::Function but run into the brick wall that is
std::function
@override-unit-failures
Reviewed By: spacedentist
Differential Revision:
D3118432
fb-gh-sync-id:
80ed56494dfcf60e0f266013d880107acabc7dcf
fbshipit-source-id:
80ed56494dfcf60e0f266013d880107acabc7dcf
Giuseppe Ottaviano [Tue, 5 Apr 2016 19:30:17 +0000 (12:30 -0700)]
Update libgcc and boost symlinks (Disable SSO on ASan builds)
Summary: Allow ASan to detect access to invalidated strings even when they are small (in-situ). See
D3114022 for details.
Reviewed By: luciang
Differential Revision:
D3118161
fb-gh-sync-id:
3b83e3309d510ee9721dd505d176b09bdb7fd42d
fbshipit-source-id:
3b83e3309d510ee9721dd505d176b09bdb7fd42d
Sven Over [Tue, 5 Apr 2016 18:34:21 +0000 (11:34 -0700)]
folly/futures: replace MoveWrappers with generalised lambda capture
Summary:Now that folly::Future uses folly::Function, we can use non-copyable
callbacks. That allows us to get rid of folly::MoveWrapper in the
implementaion.
This diff also enforces perfect forwarding in the implementation of
folly::Future, thereby reducing the number of times that a callable
that is passed to Future::then et al. gets passed by value.
Before folly::Function, Future::then(callback) has invoked the move
constructor of the callback type 5 times for small callback objects
(fitting into the in-place storage inside folly::detail::Core) and
6 times for large callback objects. This has been reduced to 5 times
in all cases with the switch to UniqueFunction. This diff reduces it
to 2 times.
Reviewed By: yfeldblum
Differential Revision:
D2976647
fb-gh-sync-id:
9da470d7e9130bd7ad8af762fd238ef9a3ac5892
fbshipit-source-id:
9da470d7e9130bd7ad8af762fd238ef9a3ac5892
Sven Over [Mon, 4 Apr 2016 09:32:10 +0000 (02:32 -0700)]
folly::FunctionScheduler: replace std::function w/ folly::Function
Summary:By using folly::Function instead of std::function to internally store
functions in FunctionScheduler, this diff allows users to pass
non-copyable lambdas to FunctionScheduler::addFunction.
All exisiting unit tests still pass. Also, passing std::function to
addFunction still works, as the std::function will be implicitly
converted (i.e. wrapped) in a folly::Function. However, this implies
a performance penalty.
Reviewed By: fugalh
Differential Revision:
D3092944
fb-gh-sync-id:
1e8081e70d4717025f2eadbb6b6da173460d4373
fbshipit-source-id:
1e8081e70d4717025f2eadbb6b6da173460d4373
Giuseppe Ottaviano [Sat, 2 Apr 2016 22:12:30 +0000 (15:12 -0700)]
fbstring: Make SSO disabling and insertImplDiscr implementation simpler
Summary:Instead of using preprocessor to disable SSO, use a default argument. Also
reimplement `insertImplDiscr` to mirror `insertImpl`.
Reviewed By: philippv
Differential Revision:
D3130901
fb-gh-sync-id:
a5b0ba97b3c7d91323be01ab617ca9b09dbb0fd2
fbshipit-source-id:
a5b0ba97b3c7d91323be01ab617ca9b09dbb0fd2
Christopher Dykes [Sat, 2 Apr 2016 01:29:47 +0000 (18:29 -0700)]
Add portability header for libgen.h
Summary: The only thing that matters in it is dirname, and Windows doesn't have it.
Reviewed By: yfeldblum
Differential Revision:
D2977655
fb-gh-sync-id:
eb5703485089f5c66882fbc9cc142686214c1148
fbshipit-source-id:
eb5703485089f5c66882fbc9cc142686214c1148
Christopher Dykes [Sat, 2 Apr 2016 01:28:33 +0000 (18:28 -0700)]
Create a portability header for syslog.h
Summary: Windows doesn't have it, so stub it out for now, because not getting output to the system log is a minor inconvience, not a breaking issue.
Reviewed By: yfeldblum
Differential Revision:
D2977537
fb-gh-sync-id:
b05d9d3c722ad4f3953a979f91024602d17d3ed0
fbshipit-source-id:
b05d9d3c722ad4f3953a979f91024602d17d3ed0
Christopher Dykes [Sat, 2 Apr 2016 00:56:17 +0000 (17:56 -0700)]
Don't use the plus operator unecessarily
Summary: MSVC doesn't like this and complains about ambigious overloads.
Reviewed By: ericniebler
Differential Revision:
D3107438
fb-gh-sync-id:
597ba85fdb7640b0a0fda352bf53ce31cf0e38b7
fbshipit-source-id:
597ba85fdb7640b0a0fda352bf53ce31cf0e38b7
Sven Over [Sat, 2 Apr 2016 00:55:57 +0000 (17:55 -0700)]
folly::Function: fix swap function and put in correct namespace
Summary:The swap function belongs in the same namespace as Function: folly.
Also, to avoid amibiguities with a generic swap function in
<algorithm>, we need two variants: one for identical types of
folly::Function, and one for folly::Functions with different
configurations.
Reviewed By: ericniebler
Differential Revision:
D3106429
fb-gh-sync-id:
11b04e9bc709d52016ac94c078278410f5ee43c6
fbshipit-source-id:
11b04e9bc709d52016ac94c078278410f5ee43c6
Adam Simpkins [Fri, 1 Apr 2016 18:35:38 +0000 (11:35 -0700)]
update SocketAddress::setFromPath() to take a StringPiece
Summary:Update setFromPath() to accept a StringPiece rather than just std::string
or a plain const char*.
Also fix two other minor issues:
- Leave the old address untouched on failure. Previously it could leave the
SocketAddress in a partially updated state.
- Don't assume the input is nul terminated. Previously the input code read
one past the specified input length, and copied this into the address,
assuming it was a nul terminator. The new code explicitly writes a 0 byte.
Reviewed By: yfeldblum
Differential Revision:
D3119882
fb-gh-sync-id:
3e2258f42034b4f470ade0a23ea085e132a3dd0f
fbshipit-source-id:
3e2258f42034b4f470ade0a23ea085e132a3dd0f
Christopher Dykes [Fri, 1 Apr 2016 18:19:53 +0000 (11:19 -0700)]
Create the Builtins portability header
Summary: Because we don't have these builtins under MSVC, and not having to deal with the differences in API in the places that use these builtins is good.
Reviewed By: yfeldblum
Differential Revision:
D2984842
fb-gh-sync-id:
34db7455debf81e4abffe57c154eb731ae097ff6
fbshipit-source-id:
34db7455debf81e4abffe57c154eb731ae097ff6
Christopher Dykes [Fri, 1 Apr 2016 18:18:42 +0000 (11:18 -0700)]
Create the dirent.h portability header
Summary: We don't have dirent.h on Windows, but we can emulate its behavior.
Reviewed By: yfeldblum
Differential Revision:
D2978570
fb-gh-sync-id:
af5ade0ea64ba22900440250e7125aa039a77f62
fbshipit-source-id:
af5ade0ea64ba22900440250e7125aa039a77f62
Christopher Dykes [Fri, 1 Apr 2016 18:16:57 +0000 (11:16 -0700)]
Create the pthread.h portability header
Summary: The primary issue is that the pthread implementation we use for Windows defines `pthread_t` as a struct (yes, it is allowed to do this), which breaks a lot of things.
Reviewed By: yfeldblum
Differential Revision:
D2862671
fb-gh-sync-id:
551569b6a9e2e374cf77e186e148b6b397f8f25f
fbshipit-source-id:
551569b6a9e2e374cf77e186e148b6b397f8f25f
Michael Lee [Fri, 1 Apr 2016 16:32:29 +0000 (09:32 -0700)]
`strndup` is defined on modern OSX
Summary: `strndup` is defined on modern versions of OSX
Reviewed By: Orvid, grp
Differential Revision:
D3122635
fb-gh-sync-id:
678792765addf2fb226e835d3b7a67e155ed6dc5
fbshipit-source-id:
678792765addf2fb226e835d3b7a67e155ed6dc5
Sven Over [Fri, 1 Apr 2016 15:31:10 +0000 (08:31 -0700)]
folly: replace old-style header guards with "pragma once"
Summary:Most header files in folly already used "#pragma once" to
protect against multiple inclusion. This diff removes old-style
ifndef/define/endif header guards and replaces them with
pragma once.
In some cases the defined symbol is tested in other header
files. In those cases the "#define" is kept.
Reviewed By: igorsugak
Differential Revision:
D3054492
fb-gh-sync-id:
20aa0b9b926a30dd021e4b8f5440e8888874681c
fbshipit-source-id:
20aa0b9b926a30dd021e4b8f5440e8888874681c
Sven Over [Fri, 1 Apr 2016 14:13:33 +0000 (07:13 -0700)]
folly/docs: add documentation about folly::Function
Summary: This diff adds folly/docs/Function.md
Reviewed By: yfeldblum
Differential Revision:
D3120617
fb-gh-sync-id:
fecc0e507e05016aaac43ba981eab49431229bd7
fbshipit-source-id:
fecc0e507e05016aaac43ba981eab49431229bd7
Andrii Grynenko [Fri, 1 Apr 2016 00:57:14 +0000 (17:57 -0700)]
Implement GDB pretty-printers for folly::fibers
Summary:This adds basic print functions for FiberManager, Fiber and FiberManager map.
It also adds a global list of fibers to FiberManager. Fibers are only removed from that list on Fiber object destruction, so it shouldn't have any perf impact.
Inspired by tao/server/scripts/fiber_bt.gdb
FiberManager map example:
(gdb) print_folly_fiber_manager_map
Global FiberManager map has 2 entries.
(folly::EventBase*)0x7fffffffdb60 -> (folly::fibers::FiberManager*)0x7ffff5b58480
(folly::EventBase*)0x7fffffffd930 -> (folly::fibers::FiberManager*)0x7ffff5b58300
FiberManager example:
(gdb) print_folly_fiber_manager &manager
(folly::fibers::FiberManager*)0x7fffffffdbe0
Fibers active: 3
Fibers allocated: 3
Fibers pool size: 0
Active fiber: (folly::fibers::Fiber*)(nil)
Current fiber: (folly::fibers::Fiber*)(nil)
Active fibers:
(folly::fibers::Fiber*)0x7ffff5b5b000 State: Awaiting
(folly::fibers::Fiber*)0x7ffff5b5b300 State: Awaiting
(folly::fibers::Fiber*)0x7ffff5b5b600 State: Awaiting
Fiber example: P56244621
Reviewed By: yfeldblum
Differential Revision:
D3119616
fb-gh-sync-id:
defa27b84aafbd4333b2ca301f07c226f0386f44
fbshipit-source-id:
defa27b84aafbd4333b2ca301f07c226f0386f44
Nicholas Ormrod [Thu, 31 Mar 2016 22:09:14 +0000 (15:09 -0700)]
New strings no longer relocatable
Summary:gcc-5.0 introduced non-relocatable strings in libgcc. Only treat gcc < 5 strings as relocatable. Enable relocation for fbstrings via typedef.
Re https://github.com/facebook/folly/issues/316, thanks tomhughes for reporting this.
Reviewed By: snarkmaster, ot
Differential Revision:
D3115580
fb-gh-sync-id:
d8aff947d55a0a0c57f6b997f651a190e05f2779
fbshipit-source-id:
d8aff947d55a0a0c57f6b997f651a190e05f2779
Giuseppe Ottaviano [Thu, 31 Mar 2016 20:39:21 +0000 (13:39 -0700)]
Simplify fbstring::insertImpl
Summary:The current implementation of `insertImpl` assumes that
`expand_noinit` does not reallocate if the `size() + delta <=
capacity()`, but
D3114022 makes this assumption invalid when compiling
with ASan. It also doesn't guarantee exponential growth, so repeated
inserting at the end could trigger quadratic behavior.
The new implementation fixes the problems above, and it's much
simpler.
Reviewed By: yfeldblum, Orvid
Differential Revision:
D3119813
fb-gh-sync-id:
946ebeeaf924a531f7f03fb7e79c75e352a50c58
fbshipit-source-id:
946ebeeaf924a531f7f03fb7e79c75e352a50c58
Kyle Nekritz [Thu, 31 Mar 2016 18:57:38 +0000 (11:57 -0700)]
Log SSL alerts received on the server.
Summary: Alerts may be sent by clients, potentially letting us know why connections fail.
Reviewed By: siyengar
Differential Revision:
D3117395
fb-gh-sync-id:
bddf51f2399eb9e7e397981d5440adb3e815d6d2
fbshipit-source-id:
bddf51f2399eb9e7e397981d5440adb3e815d6d2
Christopher Dykes [Thu, 31 Mar 2016 17:49:17 +0000 (10:49 -0700)]
Create the sys/resource.h portability header
Summary: Windows doesn't have it, so be nice and at least stub it out.
Reviewed By: yfeldblum
Differential Revision:
D2984232
fb-gh-sync-id:
3e8871ab78c5d7c8785a52af24548245f842f19b
fbshipit-source-id:
3e8871ab78c5d7c8785a52af24548245f842f19b
Christopher Dykes [Thu, 31 Mar 2016 17:44:33 +0000 (10:44 -0700)]
Create a malloc.h portability header
Summary:Let's break OSX!
Alright, maybe not. Neither OSX nor Windows define malloc_usable_size, so we implement them based on what is available on the respective platforms.
This moves the implementation for OSX out of Portability.h and into the new header, so it likely breaks something on OSX, although I'm not sure what.
Reviewed By: yfeldblum
Differential Revision:
D3019938
fb-gh-sync-id:
df95faef09535098fb73b7b3479d7a73f6b49712
fbshipit-source-id:
df95faef09535098fb73b7b3479d7a73f6b49712
Andrii Grynenko [Thu, 31 Mar 2016 17:31:15 +0000 (10:31 -0700)]
Add create-move-invoke benchmark for folly::Function
Summary: Adding a benchmark for one the most common scenarios (used in Futures, EventBase, fibers etc).
Reviewed By: yfeldblum
Differential Revision:
D3106365
fb-gh-sync-id:
8cb55959b3803e8836ab5a5bdf43fdfc1db02d4c
fbshipit-source-id:
8cb55959b3803e8836ab5a5bdf43fdfc1db02d4c
Christopher Dykes [Thu, 31 Mar 2016 17:14:42 +0000 (10:14 -0700)]
Fix the portability implementation of strndup
Summary:It was mistakenly assuming the length passed in included the null terminator.
This also makes the portability implementation of `strndup` available to OSX and FreeBSD, where they weren't present, and where HHVM had a wrapper for them.
This also removes the extra pair of conditions around `memrchr`, as the main define should always be getting set.
Reviewed By: yfeldblum
Differential Revision:
D3116467
fb-gh-sync-id:
243dd4dace219efab2c2bf2f383202e70fbec4de
fbshipit-source-id:
243dd4dace219efab2c2bf2f383202e70fbec4de
Christopher Dykes [Thu, 31 Mar 2016 17:12:30 +0000 (10:12 -0700)]
Support SSE 4.2 qfind under MSVC
Summary:MSVC has support in the compiler for the intrinsics required, but both refuses to tell us that, and also gives them proper names.
The code already checks for runtime support, this just enables compiling the SSE 4.2 version in the first place.
Reviewed By: yfeldblum
Differential Revision:
D3104296
fb-gh-sync-id:
9143240bede9b756817691fdd86818001267dac1
fbshipit-source-id:
9143240bede9b756817691fdd86818001267dac1
Neel Goyal [Thu, 31 Mar 2016 17:10:17 +0000 (10:10 -0700)]
include glog for CHECK_EQ
Summary: OpenSSLPtrTypes.h uses CHECK_EQ which is included in glog/logging.
Reviewed By: knekritz
Differential Revision:
D3118577
fb-gh-sync-id:
f8a00aa5a523bf88a3f783433c6699d555799225
fbshipit-source-id:
f8a00aa5a523bf88a3f783433c6699d555799225
Christopher Dykes [Thu, 31 Mar 2016 17:09:38 +0000 (10:09 -0700)]
Update the sys/syscall.h portability header for Windows
Summary: This adds Windows support to the portability header for sys/syscall.h, which was previously named portability/Syscall.h, which is inconsistent with the naming of the other headers, so it's now also been renamed to SysSyscall.h, and the one place that used it updated to reflect the new name.
Reviewed By: yfeldblum
Differential Revision:
D2984383
fb-gh-sync-id:
c0e4ce55c7bc2aa6db9b084e09d9762ba587002d
fbshipit-source-id:
c0e4ce55c7bc2aa6db9b084e09d9762ba587002d
Giuseppe Ottaviano [Wed, 30 Mar 2016 23:39:11 +0000 (16:39 -0700)]
Do not use small category in fbstring when in ASan mode
Summary:`fbstring`'s small string optimization prevents ASan to catch invalid
accesses to the data of a destroyed string, for example if a
`StringPiece` is initialized from a temporary string.
This diff disables building a string with the small category when
compiled with ASan: small strings will be constructed as
`Medium`-category strings and heap-allocated. This is done by only
changing the behavior of construction and resizing, so that the ABI is
preserved and it is still possible to link an ASan-enabled object file
with a library that wasn't compiled with ASan.
The diff also fixes a blind spot in `fbstring_core`'s constructor,
which disabled ASan altogether in order to allow fast word-aligned
copy of small strings. Since small string construction is now disabled
under ASan, we don't need to disable it anymore.
Lastly, it always clears moved-from strings, even when they are small.
This improves the performance of the move constructor (no more conditional
needed) and it uncovers another class of potential bugs.
Reviewed By: luciang
Differential Revision:
D3114022
fb-gh-sync-id:
4e180fbf2b8aced3b977afc985d26fdf244d9598
fbshipit-source-id:
4e180fbf2b8aced3b977afc985d26fdf244d9598
Yang Chi [Wed, 30 Mar 2016 22:46:17 +0000 (15:46 -0700)]
use unit64_t for numElements in HHWheelTimer
Summary: Some compiler will complain about this when calling std::min with a size_t and a uint64_t. So use unit64_t for numElements in HHWheelTimer.
Reviewed By: mzlee
Differential Revision:
D3116346
fb-gh-sync-id:
67a9eebf4f9e8fe0e732a7292af55122be04163b
fbshipit-source-id:
67a9eebf4f9e8fe0e732a7292af55122be04163b
Misha Shneerson [Wed, 30 Mar 2016 05:42:54 +0000 (22:42 -0700)]
fix stack usage in HHWhileTimer
Summary:We should be able to use HHWheelTimer in fibers. So it should use way less stack.
Alternative solution to
D3112305
Reviewed By: haijunz
Differential Revision:
D3112558
fb-gh-sync-id:
3a52a37d9f9347639005fdf84524f7f8c3041918
fbshipit-source-id:
3a52a37d9f9347639005fdf84524f7f8c3041918
Yedidya Feldblum [Tue, 29 Mar 2016 19:53:16 +0000 (12:53 -0700)]
IPAddressV[46]::validate
Summary:[Folly] `IPAddressV[46]::validate(StringPiece)`.
Just perform the check without allocations or throws.
Reviewed By: meyering
Differential Revision:
D3103545
fb-gh-sync-id:
2918c1398935738f597b9045cf7dadbe42da2527
fbshipit-source-id:
2918c1398935738f597b9045cf7dadbe42da2527
Neel Goyal [Tue, 29 Mar 2016 17:47:14 +0000 (10:47 -0700)]
Change SSLContext to use a ThreadLocalPRNG
Summary:Use a ThreadLocalPRNG insteaad of a per context RNG. This avoids
calls to Random::seed on context creation which can get expensive
when many are created in an application.
Reviewed By: siyengar
Differential Revision:
D3105501
fb-gh-sync-id:
92d987c27a1f190a98035ca25c23b994ca915007
fbshipit-source-id:
92d987c27a1f190a98035ca25c23b994ca915007
Nicholas Ormrod [Tue, 29 Mar 2016 16:28:51 +0000 (09:28 -0700)]
Make FBVector faster
Summary:Per https://github.com/facebook/folly/issues/379, github user pmalek determined that fbvector's insert function was a lot slower than std::vector's. While insert is often imagined to be a second-class vector function (if you're inserting in the middle, don't use a vector!), it is the correct function to use when inserting multiple elements at the back of an array (since the standard lacks an ##append(multiple-elements)## function). The code, therefore, required optimization.
There are three things that were slowing down fbvector:
- Excessive asserts. The fbvector code contains internal asserts that ensure proper calling of private methods. These are mostly unnecessary, given the extensive test suite that batters fbvector, in addition to fbvector's battle tested history. I have removed these.
- Internal data checks. When inserting into a vector, the elements being inserted may not reference the contents of the vector in question. If the client supplies internal references, then the standard allows for undefined behavior. An old design decision for fbvector was to be forgiving of this error; we check for internal data before performing internal data moves. This is expensive. Further, it is unnecessary when the insertion point is at the end of the vector (which is the valid case we are optimizing) or if the vector is being reallocated. I've rearchitected the insert macros to only perform the internal-data-check when it is absolutely necessary. While rearchitecting the checks, I also reorganized the n==0 base case checking.
- The 'window' function is pretty expensive when called with the end() iterator. It is effectively a no-op, but the function (and some of its called functions) are too big to inline, so the call overhead is non-trivial. I've put window calls behind a conditional to save this overhead.
I added a benchmark test to FBVectorTestBenchmark.cpp.h, but the particular pattern in that file caused the results to be completely optimized away, voiding the test. Oh well.
Running the github benchmarks show a 4x speedup for inserting a single element on the back, bringing it quite close to that of std::vector. The multi-insert function got a bit faster, though the exact number of iterations seems to be having an effect on the numbers (running the tests 10,000 times, intead of only 1,000 times, yields results that are 90% as fast as std::vector, instead of 75%). Both of these cases are now looking quite a bit better.
I resurrected the old StlVectorTest suite, since I was mucking with the complicated insert code. The suite had one latent compilation error (caught with newer compiler warnings - fortunately this particular case was benign). The test suite caught an error in shrink_to_fit, where a clean-slate optimization for empty vectors (see
D2696314) that trampled the vector's allocator. I have fixed that small bug in this diff, too.
Reviewed By: ot
Differential Revision:
D3105962
fb-gh-sync-id:
ac9fa9d7ca79335cf0ff6bb9010af1ed8bd7916b
fbshipit-source-id:
ac9fa9d7ca79335cf0ff6bb9010af1ed8bd7916b
Sven Over [Tue, 29 Mar 2016 10:28:31 +0000 (03:28 -0700)]
folly/futures: use folly::Function to store callback
Summary:This diff makes it possible to pass callables (such as lambdas) to
folly::Future::then that are not copy-constructible. As a consequence, move-only
types (such as folly::Promise or std::unique_ptr) can now be captured in lambdas
passed to folly::Future::then.
Using C++14 notation, the following is now possible:
Future<Unit>().then([promise = std::move(promise)]() mutable {
promise.setValue(123);
});
See folly/futures/test/NonCopyableLambdaTest.cpp for more examples.
folly::Future uses std::function to store callback functions. (More precisely,
the callback function is stored in a std::function in folly::detail::Core.)
std::function is a copy-constructible type and it requires that the callable
that it stores is copy constructible as well.
This diff changes the implementation of folly::detail::Core to use
folly::Function instead of std::function. It also simplifies the code in
folly::detail::Core a little bit: Core had a reserved space of size
8*sizeof(void*) to store callbacks in-place. Only larger callbacks (capturing
more data) would be stored in the std::function, which puts those on the heap.
folly::Function has a template parameter to set the size of the in-place
callable storage. In Core, it is set to 8*sizeof(void*), so all callbacks that
used to be stored in-place inside Core, are now stored in-place inside
folly::Function. This even reduces the size of a Core object: the
folly::Function object occupies 80 bytes, which is 16 bytes less than what was
used before for a std::function (32 bytes) and the callback storage (64
bytes). The resulting size of a Core<Unit> goes down from 192 to 176 bytes (on
x86_64).
Reviewed By: fugalh
Differential Revision:
D2884868
fb-gh-sync-id:
35548890c392f80e6c680676b0f98e711bc03ca3
fbshipit-source-id:
35548890c392f80e6c680676b0f98e711bc03ca3
Subodh Iyengar [Mon, 28 Mar 2016 23:48:51 +0000 (16:48 -0700)]
Fix cases of overwriting errno
Summary:AsyncSocket has a few cases where
we might overwrite errno, with another function
call that is done during use.
For example withAddr could cause an EBADF if the fd
was bad.
This fixes these cases by copying errno, before doing
anything else
Reviewed By: afrind
Differential Revision:
D3101932
fb-gh-sync-id:
73d4810314c90cb987936a0a3a9dc977af07243a
fbshipit-source-id:
73d4810314c90cb987936a0a3a9dc977af07243a
Yedidya Feldblum [Mon, 28 Mar 2016 23:44:02 +0000 (16:44 -0700)]
s/MAX_STATIC_CONSTRUCTOR_PRIORITY/FOLLY_STATIC_CTOR_PRIORITY_MAX/g
Summary:[Folly] `s/MAX_STATIC_CONSTRUCTOR_PRIORITY/FOLLY_STATIC_CTOR_PRIORITY_MAX/g`.
Namespace it with a `FOLLY_` prefix - when Folly introduces its own symbols, it is best when they are namespaced.
And stick `_MAX` at the end. Reads a bit more hierarchically to me that way.
Reviewed By: andriigrynenko
Differential Revision:
D3095964
fb-gh-sync-id:
4ac8c00c03c8bd146fad9be96ce3849830504d96
fbshipit-source-id:
4ac8c00c03c8bd146fad9be96ce3849830504d96
Andrii Grynenko [Mon, 28 Mar 2016 22:14:46 +0000 (15:14 -0700)]
Allocate stacks with guard pages by default
Summary: This was on for mcrouter for very long time. We should make it default for everyone.
Reviewed By: yfeldblum
Differential Revision:
D3023133
fb-gh-sync-id:
6401f86df754e9490d46beb5fd9d0cf4b3675208
fbshipit-source-id:
6401f86df754e9490d46beb5fd9d0cf4b3675208
Sven Over [Mon, 28 Mar 2016 21:13:24 +0000 (14:13 -0700)]
folly::fibers: do not move out of lvalue references
Summary:If you pass an lvalue to folly::fibers::Fiber::setFunction or
setFunctionFinally, you do not expect that those methods move
the function out of your lvalue.
This diff uses std::forward for perfect forwarding, so if an lvalue
is passed, a copy is made.
If and when when start using folly::Function for storing the
functions in the Fiber object, passing an lvalue will trigger a
compiler error because folly::Function is not copyable. That is
a good thing, as it enforces calling setFunction with std::move
if you use a named object, making clear that the named object
gets moved out of. Often people will pass temporary objects
(like a lambda defined i- place), which a rvalues anyway, so
this will not be a problem anyway.
Reviewed By: andriigrynenko
Differential Revision:
D3102685
fb-gh-sync-id:
87bf3135f7f6630766f97be351599ff488e4b796
fbshipit-source-id:
87bf3135f7f6630766f97be351599ff488e4b796
Christopher Dykes [Mon, 28 Mar 2016 18:22:53 +0000 (11:22 -0700)]
Create the string.h portability header
Summary: Windows has it, but some things aren't there, and some have different names.
Reviewed By: yfeldblum
Differential Revision:
D2990475
fb-gh-sync-id:
3f30e084eb7789c13b3981ec0fbf5b7b642c3367
fbshipit-source-id:
3f30e084eb7789c13b3981ec0fbf5b7b642c3367
Christopher Dykes [Mon, 28 Mar 2016 18:20:18 +0000 (11:20 -0700)]
Move asm portability to an Asm portability header
Summary: Portabilty.h is just a mashup of everything that was needed up-to now, however, with the Windows port significantly expanding the scope of portability in Folly, it no longer needs to be a massive mashup, so start things by splitting out the asm stubs.
Reviewed By: yfeldblum
Differential Revision:
D3007018
fb-gh-sync-id:
f32913f74660aaa8889a553ae5d6f7182a4f5789
fbshipit-source-id:
f32913f74660aaa8889a553ae5d6f7182a4f5789
Haijun Zhu [Sun, 27 Mar 2016 07:12:23 +0000 (00:12 -0700)]
Move event_base_new out of critical region
Summary:event_base_new does not change the global current_base so no need to
call it with the mutex held.
Reviewed By: chadparry
Differential Revision:
D3055963
fb-gh-sync-id:
df420b189ef0d7d56eda5ad6c32e03b195804e6b
fbshipit-source-id:
df420b189ef0d7d56eda5ad6c32e03b195804e6b
Sven Over [Sat, 26 Mar 2016 09:10:46 +0000 (02:10 -0700)]
folly::Function: improve conversion of return types
Summary:Treat any return type as convertible to void:
As of C++17, std::function<void(Args...)> can be set to callables
returning non-void types when called with parameters Args....
This diff adds that capability to folly::Function. It also adds
unit tests, not only for ignoring return types, but also for
correctly converting between the return type of the embedded
callabled and the return type of the encapsulating folly::Function.
Allow conversion of one folly::Function type to another one which
declares a return type the original one can be converted to:
E.g. allow to construct a Function<double()> from a
Function<int()> or a Function<Base*()> from a
Function<Derived*()>.
Reviewed By: yfeldblum
Differential Revision:
D3095583
fb-gh-sync-id:
6d924dc6e97f759d8109db4200e1cb9333a98d31
fbshipit-source-id:
6d924dc6e97f759d8109db4200e1cb9333a98d31
Bert Maher [Sat, 26 Mar 2016 03:36:30 +0000 (20:36 -0700)]
Fix portability/Time.h on OSX
Summary: It needs stdint to define uint8_t
Reviewed By: yfeldblum, mzlee
Differential Revision:
D3101140
fb-gh-sync-id:
308507af1ccd81e2eb389a400376556a6cc597b2
fbshipit-source-id:
308507af1ccd81e2eb389a400376556a6cc597b2
Kevin McCray [Thu, 24 Mar 2016 19:54:28 +0000 (12:54 -0700)]
folly: avoid using atomic operations android can't handle
Summary:On Android, clang 3.8 + libstdc++ doesn't support the full
range of atomic operations. This diff fixes up the ones we
ran into when building fb4a.
Reviewed By: mzlee
Differential Revision:
D3092352
fb-gh-sync-id:
7fea8513e23425fc37050ad14d82aabaceb00352
shipit-source-id:
7fea8513e23425fc37050ad14d82aabaceb00352
Yedidya Feldblum [Thu, 24 Mar 2016 01:07:02 +0000 (18:07 -0700)]
Fix Build: folly after replacing FOLLY_NORETURN
Summary:[Folly] Fix Build: `folly` after replacing `FOLLY_NORETURN`.
Problem 1:
* Clang does not treat `[[noreturn]]` and `__attribute__((__noreturn__))` as the same attribute. When a function is declared twice with the noreturn attribute, both declarations must use either the one syntax or the other; Clang fails if the two declarations mix-and-match. When both `folly/detail/FunctionalExcept.h` and gcc49's `bits/functexcept.h` are both included from the same source, they (now) mix-and-match the attribute syntaxes and Clang emits an error.
* `folly/detail/FunctionalExcept.h` should be included only when `bits/functexcept.h` is unavailable - somehow, both headers were being included.
We fix the latter problem and keep our `[[noreturn]]` syntax.
Found from WDT build failures in Travis CI.
Reviewed By: ldemailly
Differential Revision:
D3089987
fb-gh-sync-id:
705a087fc2a9629739d6cedd8315d56111204e6d
shipit-source-id:
705a087fc2a9629739d6cedd8315d56111204e6d
Yedidya Feldblum [Wed, 23 Mar 2016 19:19:45 +0000 (12:19 -0700)]
Use C++'s standardized [[noreturn]] attribute
Summary:Use C++'s standardized `[[noreturn]]` attribute.
All supported compilers (and some unsupported compilers) also support the standardized syntax.
GCC >= 4.8, Clang >= 3.0, and MSVC >= 2015 have direct support for the C++'s standardized way of writing the attribute.
Clang - http://goo.gl/ftJGVM
GCC 4.8.2 - http://goo.gl/ORCVOD
ICC 13.0.1 - http://goo.gl/I5tn5I
MSVC 2015 - https://msdn.microsoft.com/en-us/library/hh567368.aspx
(Regardling Clang, earlier versions may support it. 3.0 was the earliest Clang version listed at godbolt.com, so that's as far back as I went.)
Therefore, we no longer need to use the compiler-specific syntaxes, or use preprocessor macros with per-compiler definitions:
__attribute__((__noreturn__))
__attribute__((noreturn))
__declspec(noreturn)
Reviewed By: Orvid
Differential Revision:
D3073621
fb-gh-sync-id:
32d4771d1bf1974693b8574fa2d39c9559872945
shipit-source-id:
32d4771d1bf1974693b8574fa2d39c9559872945
Christopher Dykes [Wed, 23 Mar 2016 17:10:36 +0000 (10:10 -0700)]
Move the clock details over to the Time.h portability header
Summary: Because things belong places.
Reviewed By: mzlee
Differential Revision:
D3077737
fb-gh-sync-id:
966f37df722ae737481d776ff1c9b0d5132b7a58
shipit-source-id:
966f37df722ae737481d776ff1c9b0d5132b7a58
Michael Lee [Tue, 22 Mar 2016 18:45:43 +0000 (11:45 -0700)]
Add APPLE to portability/Config
Summary: And use that to guard the use of posix_memalign.
Reviewed By: benyl
Differential Revision:
D3081743
fb-gh-sync-id:
2c71d9cbeeaeb59d1600d486cccfc2109699ba6b
shipit-source-id:
2c71d9cbeeaeb59d1600d486cccfc2109699ba6b
Sven Over [Tue, 22 Mar 2016 13:10:19 +0000 (06:10 -0700)]
Introducing folly::Function
Summary:std::function is copy-constructible and requires that the callable that it wraps
is copy-constructible as well, which is a constraint that is often inconvenient.
In most cases when using a std::function we don't make use of its
copy-constructibility.
This diff introduces a templated type called folly::Function that is very
similar to a std::function, except it is not copy-constructible and doesn't
require the callable to be either.
Like std::function, Function is a templated type with template parameters
for return type and argument types of the callable, but not the callable's
specific type. It can store function pointers, static member function pointers,
std::function objects, std::reference_wrapper objects and arbitrary callable
types (functors) with matching return and argument types.
Much like std::function, Function will store small callables in-place, so
that no additional memory allocation is necessary. For larger callables,
Function will allocate memory on the heap.
Function has two more template parameters: firstly, an enum parameter of
type folly::FunctionMoveCtor, which defaults to NO_THROW and determines
whether no-except-movability should be guaranteed. If set to NO_THROW,
callables that are not no-except-movable will be stored on the heap, even
if they would fit into the storage area within Function.
Secondly, a size_t parameter (EmbedFunctorSize), which determines the size of
the internal callable storage. If you know the specific type of the callable you
want to store, you can set EmbedFunctorSize to sizeof(CallableType).
The original motivation of this diff was to allow to pass lambdas to
folly::Future::then that are not copy-constructible because they capture
non-copyable types, such as a promise or a unique pointer.
Another diff will shortly follow that changes folly::Future to use
folly::Function instead of std::function for callbacks, thus allowing to
pass non-copyable lambdas to folly::Future::then.
Reviewed By: fugalh
Differential Revision:
D2844587
fb-gh-sync-id:
3bee2af75ef8a4eca4409aaa679cc13762cae0d0
shipit-source-id:
3bee2af75ef8a4eca4409aaa679cc13762cae0d0
Michael Lee [Tue, 22 Mar 2016 01:02:31 +0000 (18:02 -0700)]
Use FOLLY_MOBILE to split some functionality
Summary: The guards already look for __APPLE__, but __ANDROID__ needs this as well.
Reviewed By: yfeldblum
Differential Revision:
D3053976
fb-gh-sync-id:
a9ba7a612d29502d4a7e691c6741837d4a8b42f0
shipit-source-id:
a9ba7a612d29502d4a7e691c6741837d4a8b42f0
Orvid King [Tue, 22 Mar 2016 17:21:25 +0000 (10:21 -0700)]
Revert "Changed AC_LANG from PROGRAM to SOURCE to prevent double definition of main"
This reverts commit
bb733f43b5674294a12c99ac3e686c4b54427917.
Anirudh Ramachandran [Mon, 21 Mar 2016 23:25:46 +0000 (16:25 -0700)]
Add support for probabilistically choosing server ciphers
Summary:Since SSLContextManager sets SSL_OP_CIPHER_SERVER_PREFERENCE on the SSL_CTX
when it creates contexts, we may be unable to accommodate any clients who
prefer a different ciphersuite. Having differently weighted cipher preference
lists allows SSLContext to set a list with a different most-preferred cipher
for some fraction of new handshakes.
Note: resumption will work with the previously negotiated ciphersuite even if
the server doesn't explicitly prefer/support it anymore, provided the cipher is
supported in OpenSSL.
Reviewed By: knekritz
Differential Revision:
D3050496
fb-gh-sync-id:
1c3b77ce3af87f939f8b8c6fe72b6a64eeaeeeb4
shipit-source-id:
1c3b77ce3af87f939f8b8c6fe72b6a64eeaeeeb4
Michael Lee [Mon, 21 Mar 2016 22:52:19 +0000 (15:52 -0700)]
Have StringTest use PRI*64 instead
Summary: This helps account for 32-bit vs. 64-bit compilation targets.
Reviewed By: benyl
Differential Revision:
D3076523
fb-gh-sync-id:
56f49daaf55d242ac48f8b8d38a40c6d6230818b
shipit-source-id:
56f49daaf55d242ac48f8b8d38a40c6d6230818b
Anirudh Ramachandran [Mon, 21 Mar 2016 22:46:23 +0000 (15:46 -0700)]
Add option to retrieve hex representation of client ciphers
Summary: A more compact hex representation of ciphers in ClientHello can be useful, e.g., for logging.
Reviewed By: knekritz
Differential Revision:
D3052308
fb-gh-sync-id:
beaf6fcd4705d4d7fae652d8d8b95b52ca9e07a9
shipit-source-id:
beaf6fcd4705d4d7fae652d8d8b95b52ca9e07a9
Christopher Dykes [Mon, 21 Mar 2016 22:05:49 +0000 (15:05 -0700)]
Add Windows support to portability/Memory.h
Summary: This adds Windows support to portability/Memory.h and also does some refactoring to be more correct about when to use posix_memalign, and also changes it to fall back to memalign rather than posix_memalign.
Reviewed By: mzlee
Differential Revision:
D3069990
fb-gh-sync-id:
88861583c6028e9fb02a3e3804bd6d476956c555
shipit-source-id:
88861583c6028e9fb02a3e3804bd6d476956c555
Giuseppe Ottaviano [Mon, 21 Mar 2016 03:34:23 +0000 (20:34 -0700)]
Optimize fbstring::append()
Summary:Instead of relying on `push_back()` to guarantee exponential growth,
delegate to `expand_noinit`. This removes the duplication of logic
between the two functions, and significantly speeds up short appends.
```
$ _bin/folly/test/fbstring_benchmark_using_jemalloc --bm_min_usec=100000
Before: After:
============================================================================ ===================
./folly/test/FBStringTestBenchmarks.cpp.h relative time/iter iters/s time/iter iters/s
============================================================================ ===================
...
BM_push_back_fbstring(1) 7.51ns 133.20M 6.87ns 145.49M
BM_push_back_fbstring(23) 175.08ns 5.71M 173.92ns 5.75M
BM_push_back_fbstring(127) 586.02ns 1.71M 585.70ns 1.71M
BM_push_back_fbstring(1024) 3.30us 302.81K 3.41us 293.13K
BM_short_append_fbstring(23) 367.01ns 2.72M 179.45ns 5.57M
BM_short_append_fbstring(1024) 9.33us 107.20K 5.72us 174.95K
...
============================================================================ ===================
```
Reviewed By: philippv
Differential Revision:
D3075249
fb-gh-sync-id:
497775ba3fc707bf50821a3cf10fb9d247b9352d
shipit-source-id:
497775ba3fc707bf50821a3cf10fb9d247b9352d
Christopher Dykes [Sun, 20 Mar 2016 18:06:56 +0000 (11:06 -0700)]
Add features to portability/Config.h
Summary: It is perfectly reasonable to need to feature macros when checking configuration, and the configuration is needed to know if features.h exists, so put it in the same file.
Reviewed By: yfeldblum
Differential Revision:
D3072255
fb-gh-sync-id:
0f253dd1fa2f4a95adb11f11c45e6b86ef9c25bc
shipit-source-id:
0f253dd1fa2f4a95adb11f11c45e6b86ef9c25bc
Christopher Dykes [Sun, 20 Mar 2016 18:06:40 +0000 (11:06 -0700)]
Split iovec out of SysUio.h
Summary: This is needed to avoid a circular dependency.
Reviewed By: yfeldblum
Differential Revision:
D3072037
fb-gh-sync-id:
546a46fd68f25f0c5b027d4d938335b2711d8fdd
shipit-source-id:
546a46fd68f25f0c5b027d4d938335b2711d8fdd
Mark Reitblatt [Sun, 20 Mar 2016 09:00:17 +0000 (02:00 -0700)]
fix typo in log printing in AsyncSSLSocket
Reviewed By: pritamdamania
Differential Revision:
D3068807
fb-gh-sync-id:
0b45ab678e2ec5565eb379540576527cf8b1d308
shipit-source-id:
0b45ab678e2ec5565eb379540576527cf8b1d308
Jeremy Wright [Sat, 19 Mar 2016 00:11:23 +0000 (17:11 -0700)]
Upgrade ScopeGuard for Visual Studio 2015
Summary:Upgrade UncaughtExceptionCounter to use std::uncaught_exceptions on Visual Studio 2015 Update 1
Closes https://github.com/facebook/folly/pull/358
Reviewed By: yfeldblum
Differential Revision:
D3066005
Pulled By: Orvid
fb-gh-sync-id:
6bc7129aa794257b1f6e7a084139d8a3a52fa4a8
shipit-source-id:
6bc7129aa794257b1f6e7a084139d8a3a52fa4a8
Christopher Dykes [Fri, 18 Mar 2016 21:57:46 +0000 (14:57 -0700)]
Create the sys/mman.h portability header
Summary: Something that Windows very definitely lacks. This is a fun one.
Reviewed By: yfeldblum
Differential Revision:
D2979661
fb-gh-sync-id:
e23c1db0cb8655b22308b874bd421a7cc1e4759e
shipit-source-id:
e23c1db0cb8655b22308b874bd421a7cc1e4759e
Yedidya Feldblum [Thu, 17 Mar 2016 21:08:38 +0000 (14:08 -0700)]
Remove pthread_yield support
Summary:[Folly] Remove `pthread_yield` support.
* It is not actually part of POSIX - rather, `sched_yield` is.
* In C++, we should be using `std::this_thread::yield` anyway.
Reviewed By: Gownta
Differential Revision:
D3056221
fb-gh-sync-id:
2fea55dd7b715149327987d61e5a573ad0455330
shipit-source-id:
2fea55dd7b715149327987d61e5a573ad0455330
Subodh Iyengar [Thu, 17 Mar 2016 20:06:21 +0000 (13:06 -0700)]
Allow override of session context
Summary:We currently set the session context to the
default of common name, this allows session
context to be set to a different value
for different applications
Reviewed By: ngoyal
Differential Revision:
D3059769
fb-gh-sync-id:
185afeb487c2c62dcf44f96076bd05871692c7ab
shipit-source-id:
185afeb487c2c62dcf44f96076bd05871692c7ab
Andrew Cox [Thu, 17 Mar 2016 14:09:07 +0000 (07:09 -0700)]
Tell ASAN about fiber stacks
Summary:ASAN needs to know about the stack extents. Currently it has no knowledge of
fibers and so it can give false positives, particularly in cases of no-return
(think exceptions).
See: https://github.com/google/sanitizers/issues/189
This change along with a related ASAN diff fixes that, and I've verified it
fixes false positive test failures I'm seeing when throws happen from fibers.
Also rips out some hacks that attempted to work around the limitations of
ASAN these changes should fix.
This change depends on:
D3017630
D2952854
D3017619
And will also depend on rollout of libasan.so to /usr/local/fbcode platform dirs on all machines.
Reviewed By: andriigrynenko
Differential Revision:
D2952899
fb-gh-sync-id:
19da779227c6c0f30c5755806325aa4cba364cfe
shipit-source-id:
19da779227c6c0f30c5755806325aa4cba364cfe
Christopher Dykes [Wed, 16 Mar 2016 22:15:52 +0000 (15:15 -0700)]
Create portability/Config.h
Summary: Because including the root portability header just to get a couple of defines to be able to enable things is a waste. In addition, it would be nice if the config defines are never needed outside of the portability headers.
Reviewed By: yfeldblum
Differential Revision:
D3059651
fb-gh-sync-id:
1cb9910d850ea015616a598808556b4815b3fb74
shipit-source-id:
1cb9910d850ea015616a598808556b4815b3fb74
Eric Niebler [Wed, 16 Mar 2016 16:54:38 +0000 (09:54 -0700)]
move StaticMeta::onThreadExit into libfolly_thread_local.so
Summary: Fix folly/test:thread_local_test in the shared library scenario by moving onThreadExit into libfolly_thread_local.so, avoiding the crash when a user's .so is dlclosed.
Reviewed By: andriigrynenko
Differential Revision:
D2919287
fb-gh-sync-id:
ecc4220fd40203289366eb1a6391b8b6d971e65f
shipit-source-id:
ecc4220fd40203289366eb1a6391b8b6d971e65f
Phil Willoughby [Wed, 16 Mar 2016 14:22:26 +0000 (07:22 -0700)]
Remove `using std::make_unique`
Summary: Older compilers do not have have `std::make_unique`. We have `folly::make_unique` which does the same job, and because we already have `using namespace folly` in this file it suffices to erase the `using std::make_unique` line.
Reviewed By: eduardosuarez
Differential Revision:
D3058089
fb-gh-sync-id:
a5a5eb54e2bc0ba7ef0880f2b5680a79d1f41d37
shipit-source-id:
a5a5eb54e2bc0ba7ef0880f2b5680a79d1f41d37