Mark Logan [Fri, 3 Feb 2017 18:09:57 +0000 (10:09 -0800)]
Add ContainerT&& ctors to sorted_vector_map and sorted_vector_set.
Summary:
Add ContainerT&& ctors to sorted_vector_map and sorted_vector_set,
to support more efficient bulk-construction of these containers. With the
prior constructors, the only way to do bulk-construction efficiently was
by using the iterator constructors with a pre-sorted range. If you didn't
have a presorted range, you would need to make a temporary container in
order to get a sorted range. Repeatedly calling insert() without a sorted
range is quadratic, hence not an option.
Reviewed By: yfeldblum
Differential Revision:
D4491299
fbshipit-source-id:
041c546578f44ee6928c5506e8d8191092143b12
Mark Logan [Fri, 3 Feb 2017 18:09:52 +0000 (10:09 -0800)]
Fix worst-case quadratic behavior of iterator constructors and range insert()
Summary:
The iterator constructors and the range insert() method previously
had quadratic runtime if given an unsorted range. This is now fixed. We
append the entire range to the container, sort that subrange, and merge it
into the already-sorted container. Sorting and merging is skipped when possible.
Reviewed By: yfeldblum
Differential Revision:
D4493534
fbshipit-source-id:
e6d73b5c19e374001f9e340ff527c5257bef2ca3
Pádraig Brady [Thu, 2 Feb 2017 19:35:54 +0000 (11:35 -0800)]
Fix build failure with GCC 5
Summary:
GCC 5 doesn't recognize LOG(FATAL) as [[noreturn]],
so remove [[noreturn]] to avoid that warning and build failure.
Reviewed By: yfeldblum
Differential Revision:
D4484625
fbshipit-source-id:
ca129ca3a52239becd7d80f99107e64745bf8838
Christopher Dykes [Thu, 2 Feb 2017 01:22:36 +0000 (17:22 -0800)]
Correct the API of some functions in the portability headers
Summary: They were based on the signatures of the original functions as defined by MSVC. They should be based on the signatures as defined by Posix instead.
Reviewed By: yfeldblum
Differential Revision:
D4471711
fbshipit-source-id:
8a6fd60ba2b326ca57058c119fc77c46f1d21d10
Yedidya Feldblum [Wed, 1 Feb 2017 21:57:34 +0000 (13:57 -0800)]
Assorted cleanups for folly/portability/BitsFunctexcept.h
Summary: [Folly] Assorted cleanups for `folly/portability/BitsFunctexcept.h`.
Reviewed By: Orvid, smeenai
Differential Revision:
D4492264
fbshipit-source-id:
5e85ac2ad96ef84627cc5473ec0b16c4c9b5da26
Scott Michelson [Wed, 1 Feb 2017 20:03:48 +0000 (12:03 -0800)]
MPMCQueue Wrapper with priorities
Summary: In many cases where MPMCQueue would be used, it's useful to be able to prioritize requests. This implements a thin wrapper on MPMCQueue to accomplish this (albeit in a bit of a memory inefficient way)
Reviewed By: haijunz
Differential Revision:
D4465498
fbshipit-source-id:
6630b80ccf3138b5c135e7f7f281133b37d82b4d
Christopher Dykes [Wed, 1 Feb 2017 01:35:51 +0000 (17:35 -0800)]
Swap a few APIs to reduce sign and implicit truncations required to work with it
Summary: This results in a more uniform API within Folly, allowing for a more uniform API to use outside of Folly.
Reviewed By: yfeldblum
Differential Revision:
D4471471
fbshipit-source-id:
f798a6498bd1a05ed12adea362ff4aedd25789ee
Christopher Dykes [Wed, 1 Feb 2017 00:34:49 +0000 (16:34 -0800)]
Use std::chrono::high_resolution_clock for folly::Benchmark
Summary: `clock_gettime(CLOCK_REALTIME)` is based on `std::system_clock` on Windows, but that only has a resolution that's the same as `FILETIME` (100s of nanoseconds), so modernize things and use `std::chrono::high_resolution_clock` which is intended for this purpose.
Reviewed By: yfeldblum
Differential Revision:
D4476671
fbshipit-source-id:
3db1debc8f408f689b5c9fe1966a72b8dad4da93
Igor Adamski [Tue, 31 Jan 2017 10:15:36 +0000 (02:15 -0800)]
FunctionScheduler - set running_ when it has actually started running
Summary:
When start() throws because of reasons (in my case it was std::system_error("Resource temporarily unavailalble") coming from std::thread constructo)
and during the exception propagation we will have to destroy FunctionScheduler then
thread_.join() in shutdown will throw again.
This diff sets running_ after the thread is created.
Reviewed By: yfeldblum
Differential Revision:
D4469816
fbshipit-source-id:
cde54dfbf39f04d3ea9dfa02a65295f5440e5ea4
Phil Willoughby [Tue, 31 Jan 2017 09:37:27 +0000 (01:37 -0800)]
Require compile-time constant format strings to `shellify`
Summary:
Because it's impossible to require that a parameter to a function is a compile-time constant string this replaces `shellify()` with the user-defined-literal suffix `_shellify()`.
It's trivial to convert previously-correct code: `shellify("whatever {}", A)` => `"whatever {}"_shellify(A)`
The previous `folly::shellify()` API is still present as a transition measure. Compilers will issue a deprecation warning if it is used.
Reviewed By: yfeldblum
Differential Revision:
D4435512
fbshipit-source-id:
6639cd91280dc72108e47a8a7775c5160a4e644f
Michael Lee [Tue, 31 Jan 2017 00:00:33 +0000 (16:00 -0800)]
crt_externs.h is not available on all platforms
Summary: Different deployments of don't always have access to crt_externs.h.
Reviewed By: yfeldblum, Orvid
Differential Revision:
D4480621
fbshipit-source-id:
f0b18d15fa253d6ba28dee68859cf9a34bf41255
Michael Lee [Mon, 30 Jan 2017 21:15:26 +0000 (13:15 -0800)]
Fix folly/Makefile.am
Summary: Missed a `\`
Reviewed By: Orvid
Differential Revision:
D4483602
fbshipit-source-id:
91451c3476756125abdbd0dd98ab9fb38bcf2c32
Michael Lee [Mon, 30 Jan 2017 20:03:04 +0000 (12:03 -0800)]
Split up experimental/TestUtil
Summary: TestUtil is primarily a temporary file and temporary directory. Split out the env variable manipulation into a different file.
Reviewed By: Orvid
Differential Revision:
D4482071
fbshipit-source-id:
9d1a4a08010a8fad270aa56a7e1432829eb6484c
Michael Lee [Sun, 29 Jan 2017 03:43:50 +0000 (19:43 -0800)]
char ** enivron is inconsistent on some platforms
Summary: The forward declaration of `extern char ** environ` is inconsistent on some platforms.
Reviewed By: strager, Orvid
Differential Revision:
D4474856
fbshipit-source-id:
c73a7c7d5a247e962fab06aeb65df7815f0e3bcb
Jason Rahman [Sat, 28 Jan 2017 06:24:55 +0000 (22:24 -0800)]
RFC: Include timeout duration in exception message
Summary: For debugging purposes, it's often extremely useful to have the duration of the expired timeout in the exception message (in case the timeout was excessively low, or to understand exactly how long the operation ran before failing due to timeout). Here we make a best effort to include the timeout when possible.
Reviewed By: yfeldblum
Differential Revision:
D4476038
fbshipit-source-id:
f2d0aa5e1f6367a3cfe20579c27577ab91fd8d9c
Christopher Dykes [Sat, 28 Jan 2017 00:45:00 +0000 (16:45 -0800)]
Actually do the stress test on RCURefCount and make the TLRefCountTest not take 2 minutes
Summary: Adjusting the iteration count significantly reduces the runtime of the `TLRefCount.Stress` test to ~5 seconds. Working with that same timeframe, we can get away with increasing the iteration count of the (now tested) `RCURefCount.Stress` test to 100k, up from it's previous 10k.
Reviewed By: markisaa
Differential Revision:
D4477750
fbshipit-source-id:
6a89dbb65f460655db0cb33926cc331dc1904f1c
Phil Willoughby [Fri, 27 Jan 2017 14:43:33 +0000 (06:43 -0800)]
Namespace rename from UpperCamelCase to snake_case
Summary:
`folly::literals` is to `folly` what `std::literals` is to `std`.
More importantly we should be consitent; snake_case is how other folly sub-namespaces are named, such as:
`array_detail`
`apply_tuple`
`format_value`
`threadlocal_detail`
`recordio_helpers`
`exception_tracer`
Reviewed By: ericniebler
Differential Revision:
D4468281
fbshipit-source-id:
de10bec74c9a38f387d62bd55da947291c23970b
Angelo Failla [Fri, 27 Jan 2017 08:35:27 +0000 (00:35 -0800)]
Implemented IPAddressV6::getMacAddressFromLinkLocal
Summary: It is possible to extract a MAC address from a link-local IPv6 address. This diff provides the logic for it.
Reviewed By: simpkins
Differential Revision:
D4461970
fbshipit-source-id:
cb4a5d774c3b4a20716d1742c961e02952ddf80d
Christopher Dykes [Fri, 27 Jan 2017 02:11:24 +0000 (18:11 -0800)]
Move the Environment portability header to the stdlib header
Summary: This completely kills the environment portability header, which was among the earliest, and was created before the general convention of splitting based on the header they are in, in the standard library, existed. The functions that were defined in it are expected to be in stdlib, so move them there.
Reviewed By: mzlee
Differential Revision:
D4462502
fbshipit-source-id:
c4549b9d1ea623644223db4365b81507f443ad5e
Christopher Dykes [Fri, 27 Jan 2017 02:01:31 +0000 (18:01 -0800)]
Make most implicit integer truncations and sign conversions explicit
Summary:
This makes a large number of implicit truncations and sign conversions into explicit casts, in preparation for eventually enabling `-Wconversion` on Folly.
This set of changes should have zero semantic change.
This focuses on the core of Folly and leaves the tests alone for the most part. A future diff will cleanup the warnings in the tests as well.
Reviewed By: yfeldblum
Differential Revision:
D4454096
fbshipit-source-id:
af1e1831675a804ec5679266c30c1fae62e8c35c
Christopher Dykes [Thu, 26 Jan 2017 18:44:00 +0000 (10:44 -0800)]
Add __builtin___clear_cache to the portability headers
Summary:
HHVM uses this heavily in it's ARM JIT, so provide an implementation. With GCC & Clang this function is a no-op on x86_64 where the requirement doesn't exist, so do the same in the portability header.
This doesn't include the Windows portability header on x64 specifically because it is a very heavy header and this is currently very lightweight.
Reviewed By: yfeldblum
Differential Revision:
D4451032
fbshipit-source-id:
0af57448577635f9cd690ea9b09ce46a244191e1
Daniel Sommermann [Wed, 25 Jan 2017 21:01:37 +0000 (13:01 -0800)]
Add ability to set custom SSLContext on TestSSLServer
Summary:
This is needed if you want to test other scenarios where the
server has other OpenSSL settings.
Differential Revision:
D4463587
fbshipit-source-id:
ffd4019e921649dee703363b2ff028b4d8063210
Michael Lee [Wed, 25 Jan 2017 17:36:05 +0000 (09:36 -0800)]
Re-Gate setenv/unsetenv
Summary: `setenv`/`unsetenv` is not always declared the same way on all of the places folly is compiled.
Reviewed By: matbd
Differential Revision:
D4462056
fbshipit-source-id:
6dd68f6fc5a6a435f145cbaa43bee02b5fa7170c
Daniel Sommermann [Wed, 25 Jan 2017 17:32:24 +0000 (09:32 -0800)]
Split out SSL test server for reuse
Summary:
The TestSSLServer is useful to have on its own for reuse. This
diff separates it out to make reuse possible.
Reviewed By: yfeldblum
Differential Revision:
D4457976
fbshipit-source-id:
1fe6b71e930859ef04487e29047dcf603a79834b
Christopher Dykes [Wed, 25 Jan 2017 16:49:59 +0000 (08:49 -0800)]
Fix JemallocNodumpAllocator when compiled without folly-config.h
Summary: HHVM compiles without `folly-config.h`, so this was preventing us from updating to the newest version of Folly.
Reviewed By: yfeldblum
Differential Revision:
D4456890
fbshipit-source-id:
ed118ff0cf7f254a5f99be68f171d1b34ebf5c5c
Petr Lapukhov [Wed, 25 Jan 2017 05:23:20 +0000 (21:23 -0800)]
Add disableTransparentTls call
Summary: Similar to AsyncSocket, allow setting reserved sockopt after bind(). This will be recognized by intercepted accept4() call and forked sockets will properly have the TLS flag disabled.
Reviewed By: djwatson
Differential Revision:
D4458831
fbshipit-source-id:
fa753b9d849bd661563364d36229113f7abb0ee0
Christopher Dykes [Wed, 25 Jan 2017 00:15:19 +0000 (16:15 -0800)]
Actually allow SFINAE to occur with setThreadName
Summary:
It wasn't actually SFINAE the way it was setup previously, which meant it was just a hard error under MSVC.
Whoops.
Reviewed By: yfeldblum
Differential Revision:
D4453702
fbshipit-source-id:
5be600fb5ecdc8255795fefbd37c1fe26e7266dd
Mathieu Baudet [Tue, 24 Jan 2017 22:34:42 +0000 (14:34 -0800)]
folly: remove unused includes
Summary:
Found with our include analysis tool.
I had to tweak `portability/Environment.h` to avoid a false positive breaking win32.
Reviewed By: yfeldblum, Orvid
Differential Revision:
D4452463
fbshipit-source-id:
e2e862e204892037ddde8815218e4deab1bfbb06
Ryan Wilson [Tue, 24 Jan 2017 22:22:17 +0000 (14:22 -0800)]
Add needsPeerVerification function to check if peer cert should be verified
Summary:
This patch adds a function to AsyncSSLSocket, so the user can check if the peer cert
should be verified. This allows the user to implement custom logic for peer cert validation.
Reviewed By: Orvid
Differential Revision:
D4456402
fbshipit-source-id:
2f8a5c932d0341d6c9290bcb52264dd4fa174263
Christopher Dykes [Tue, 24 Jan 2017 21:28:28 +0000 (13:28 -0800)]
Ensure portability/Windows.h is included before OpenSSL headers
Summary: Because OpenSSL is evil to Windows, and you have to forcefully include winsock2 before winsock.
Reviewed By: yfeldblum
Differential Revision:
D4453742
fbshipit-source-id:
3b1b5b1f999722559693164148245f52b1e94104
Igor Zinkovsky [Fri, 20 Jan 2017 23:45:47 +0000 (15:45 -0800)]
fix use-after-free in addFunctionOnce
Summary: see title
Reviewed By: meyering
Differential Revision:
D4441266
fbshipit-source-id:
4a8f589e2995a463e54b3979035a623824acf39e
Maged Michael [Fri, 20 Jan 2017 20:20:31 +0000 (12:20 -0800)]
Made atomics generic in hazptr_owner member functions
Summary:
As suggested by the C++ committee in November 2016, made atomics generic to allow other atomic types (e.g., folly::DeterministicAtomic<T*>),
Also removed obsolete comments.
Reviewed By: davidtgoldblatt
Differential Revision:
D4443355
fbshipit-source-id:
d9e21a959f2c7e3dd07c0ed4808236da80ef6dcd
Christopher Dykes [Fri, 20 Jan 2017 18:35:09 +0000 (10:35 -0800)]
Define AF_LOCAL in the socket portability layer
Summary: It's the exact same as `PF_LOCAL`, and is used interchangibly.
Reviewed By: yfeldblum
Differential Revision:
D4439558
fbshipit-source-id:
fd1ff813db5349369fc77888dfd854fc36a2a3be
Kyle Nekritz [Fri, 20 Jan 2017 17:02:40 +0000 (09:02 -0800)]
Clear OpenSSL error stack after loading certificate file.
Summary: SSL_CTX_load_verify_locations interally end up using X509_load_cert_crt_file, which has an unchecked call to X509_STORE_add_cert. This can fail and add an error to the error stack without causing SSL_CTX_load_verify_locations to return an error.
Reviewed By: siyengar
Differential Revision:
D4442017
fbshipit-source-id:
a4cf7f5ee2c18d90d5d61baf3acb99ffca6b8af0
Luca Niccolini [Fri, 20 Jan 2017 00:50:37 +0000 (16:50 -0800)]
Revert
D4389970: add an option to clear error before calling ssl methods
Summary: This reverts commit
12da254d6b281c2b9d522ba19999b2489c0083a2
Differential Revision:
D4389970
fbshipit-source-id:
7651425adcf3b86c066d657308af1a0aa6bce5dd
Maxim Georgiev [Fri, 20 Jan 2017 00:14:24 +0000 (16:14 -0800)]
Enable EOR flag configuration for folly::AsyncSocket.
Summary: EOR flag was hardcoded to "false" in folly::AsyncSocket. This diff enables changing EOR flag using AsyncSocket::setEorTracking() method.
Reviewed By: yfeldblum
Differential Revision:
D4421966
fbshipit-source-id:
2e1b9b19ced6555845396ec33bfd3d5feb710640
Phil Willoughby [Thu, 19 Jan 2017 21:42:48 +0000 (13:42 -0800)]
Modernise and clang-format existing formatting benchmark
Summary: Changes nothing fundamental, just makes it easier to work on in the future.
Reviewed By: yfeldblum
Differential Revision:
D4435805
fbshipit-source-id:
725944a12922abde137bb7e21726c97beb558b5f
Andrii Grynenko [Thu, 19 Jan 2017 01:09:38 +0000 (17:09 -0800)]
Add fiber-print-limit command
Summary: Limits number of fibers printed for each FiberManager.
Reviewed By: yfeldblum
Differential Revision:
D4432488
fbshipit-source-id:
1791c2bfe6d5b0c2f54142dc068b473fd72f5d5d
Maxim Georgiev [Wed, 18 Jan 2017 22:30:57 +0000 (14:30 -0800)]
Adding 'compound assignment union operator' for folly::WriteFlags enum class
Summary: There is "operator|()" defined for folly::WriteFlags enum class, but no "operator=|()". Because of that adding a new flag to an existing set of flags looks awkward. Adding the missing operator.
Reviewed By: yfeldblum
Differential Revision:
D4421892
fbshipit-source-id:
a053a8cc5b1d07579c233d19029a9801b8188413
Eric Niebler [Wed, 18 Jan 2017 17:26:27 +0000 (09:26 -0800)]
Add a missing #include. Remove an unnecessary #include.
Summary:
'Nuf said.
Depends on
D4413112
Reviewed By: yfeldblum, spacedentist
Differential Revision:
D4425605
fbshipit-source-id:
a7c98867cfa5c859a1b4d2eb78724710c4f1115f
Christopher Dykes [Mon, 16 Jan 2017 02:21:28 +0000 (18:21 -0800)]
Drop unneeded Pthread include
Summary: It was killed in an earlier diff.
Reviewed By: yfeldblum
Differential Revision:
D4418832
fbshipit-source-id:
c9a5134fa100b24a3394607dea20e6e8a8d341e1
Christopher Dykes [Mon, 16 Jan 2017 01:46:24 +0000 (17:46 -0800)]
Don't use Pthread in EventBase
Summary:
Pthread is currently a dependency of Folly that is not really necessary on Windows, or even with standard C++ for the most part, so start work on killing it in Folly.
This switches EventBase to using `std::thread::id`'s instead, which also means we aren't reliant on the implementation detail that thread id 0 is invalid. Well, we are, but it's now the standard library's fault not ours.
Reviewed By: yfeldblum
Differential Revision:
D4418128
fbshipit-source-id:
a9c95ac6c7305c960156a4ad684b6db89b5856d9
Christopher Dykes [Mon, 16 Jan 2017 01:46:23 +0000 (17:46 -0800)]
Support setting thread name via std::thread::id
Summary: It's possible via some hackery, so wrap it up nicely into the API.
Reviewed By: yfeldblum
Differential Revision:
D4418728
fbshipit-source-id:
f00aed95cdbdc3cc83a0ab96565117cd01141c2e
Igor Sugak [Sat, 14 Jan 2017 00:36:13 +0000 (16:36 -0800)]
remove override from adjacent_tokens_only
Summary:
Our internal version of boost contains a patch that reverts the following commit to boost filesystem module:
https://github.com/boostorg/program_options/commit/
88dea3c6fdea8c9ea894911897b1770599c383e4
It was done due to a breaking change that disallows the use of "--key value" for implicit options, allowing only "--key=value" style syntax. Since there are too many tests to fix, and it's probably going to be reverted in the upstream as well (see below), removing the `override` keyword here to fix folly build.
https://github.com/boostorg/program_options/issues/25
Reviewed By: meyering
Differential Revision:
D4415347
fbshipit-source-id:
c215331338b3aa218d26890a83aa0b363514fe79
Marcus Holland-Moritz [Fri, 13 Jan 2017 21:47:19 +0000 (13:47 -0800)]
Protect memcpy calls against undefined behaviour
Summary:
While running a UBSan enabled binary, I got:
folly/io/IOBuf.cpp:671:15: runtime error: null pointer passed as argument 2, which is declared to never be null
This change protects all calls to memcpy from passing `nullptr`.
Reviewed By: pixelb
Differential Revision:
D4415355
fbshipit-source-id:
a27ba74244abcca8cd4e106967222890a67f5b6d
Jim Meyering [Fri, 13 Jan 2017 21:01:25 +0000 (13:01 -0800)]
folly/Traits.h: fix a deep problem with FBVector
Summary:
This started when many fbvector-related tests began failing with reports of
ASAN-detected heap abuse (usually invalid free of an address 16 bytes
into an already-freed buffer).
It was very specific, though. The bug struck only when:
- gcc-5-based platform
- compiling with clang (~3.8) and GCC5's libstdc++, not gcc
- strings were short enough to reside within an in-situ std::string
Why? because FBVector.h:1588's conditional:
if (folly::IsRelocatable<T>::value && usingStdAllocator::value) {
was true for clang (erroneously), but false for gcc. The difference
was in `IsRelocatable<std::string>::value`. However, manual tests showed that
each component from the definition of `IsRelocatable` were the same for both
gcc and clang. Then Jay Feldblum realized that we'd probably specialized
that trait for `std::string`, and sure enough, I found the culprit:
```
FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string)
```
Reviewed By: pixelb
Differential Revision:
D4414159
fbshipit-source-id:
60e3fb4b096ec77cbd2b48c561e5c6ec8f128fff
Eric Niebler [Fri, 13 Jan 2017 20:16:51 +0000 (12:16 -0800)]
capture exception information when creating exception_wrapper
Summary:
prefer creating an exception_wrapper with a reference to the active exception
Depends on
D4410421
Reviewed By: spacedentist
Differential Revision:
D4410455
fbshipit-source-id:
d6b6aeb5fa72782e31d754a0b853514af5fdb8cd
Dave Watson [Fri, 13 Jan 2017 18:32:13 +0000 (10:32 -0800)]
Add AsyncSSLSocket option to turn off transparent tls
Summary: Folly parts of
D4383906.
Reviewed By: plapukhov
Differential Revision:
D4387254
fbshipit-source-id:
3c039720c88c91b7292d60a85272dd1978510296
Yedidya Feldblum [Wed, 11 Jan 2017 04:53:38 +0000 (20:53 -0800)]
Slight simplification of exception_wrapper constructor
Summary: [Folly] Slight simplification of `exception_wrapper` constructor.
Reviewed By: ericniebler
Differential Revision:
D4391899
fbshipit-source-id:
ddb066723bcd10abb0dbbaeab12b1e9be4f39acc
Subodh Iyengar [Tue, 10 Jan 2017 23:51:33 +0000 (15:51 -0800)]
add an option to clear error before calling ssl methods
Summary:
Normally clearing out the error before calling into an openssl method
is a bad idea. However there might be other code outside AsyncSSLSocket
calling into openssl in the same thread that doesn't use openssl
correctly. This allows users of AsyncSSLSocket to safeguard themselves
from such code.
Reviewed By: anirudhvr
Differential Revision:
D4389970
fbshipit-source-id:
12da254d6b281c2b9d522ba19999b2489c0083a2
Yedidya Feldblum [Tue, 10 Jan 2017 19:57:31 +0000 (11:57 -0800)]
Fix an inefficiency in json-serializing a dynamic with sorted keys
Summary:
[Folly] Fix an inefficiency in json-serializing a `dynamic` with sorted keys.
The inefficiency is that, at each level of the `dynamic` which is map-typed, we effectively make a full copy of the `dynamic` object. This can be expensive.
Reviewed By: Gownta
Differential Revision:
D4389671
fbshipit-source-id:
223739397f913d3e65a421a9a4dcb089ec757ec6
kumagi [Tue, 10 Jan 2017 19:55:42 +0000 (11:55 -0800)]
fix typo in comments. s/unitialized/uninitialized/g
Summary:
`unitialized` seems to be typo.
Closes https://github.com/facebook/folly/pull/538
Reviewed By: igorsugak
Differential Revision:
D4397318
Pulled By: yfeldblum
fbshipit-source-id:
a2e6c665b4dfe95d769430405886b0725423aac2
Yedidya Feldblum [Tue, 10 Jan 2017 04:30:42 +0000 (20:30 -0800)]
Rename exception_wrapper::getExceptionPtr to to_exception_ptr
Summary:
[Folly] Rename `exception_wrapper::getExceptionPtr` to `to_exception_ptr`.
Make it clear that this will sometimes be an expensive operation. Using the word `to` evokes the possibility of an expensive conversion, while using the word `get` implies cheap access.
Reviewed By: djwatson
Differential Revision:
D4391621
fbshipit-source-id:
33ca051d9be5a6050ba9f30b20faee35b7e58afb
Maged Michael [Tue, 10 Jan 2017 02:31:20 +0000 (18:31 -0800)]
Fix dynamic MPMCQueue tryObtainPromisedPushTicket() to prevent tryWriteUntil() and writeIfNotFull() from blocking indefinitely for a matching read.
Summary:
The bug was reported by Alexander Pronchenkov in https://fb.facebook.com/groups/
560979627394613/permalink/
837052843120622/
Under certain conditions a `tryWriteUntil()`--and also `writeIfNotFull()`--operation may block indefinitely awaiting a matching read. This could happen because in each dynamic MPMCQueue expansion, typically one or two tickets are associated with the closed array not the new one. In the incorrect code, a `tryWriteUntil()` operation that induced expansion but gets a ticket associated with the closed array, incorrectly assumes that because the expansion succeeded then there is space for it. However because the ticket is associated with the closed array, the operation needs to wait (possibly indefinitely) for space to open in the closed array.
The fix: Changed the code in tryObtainPromisedPushTicket() such that the operation tries to acquire a ticket only if there is promised space in the array associated with that ticket. If there is no space, an expansion is attempted if the ticket is not associated with a closed array. If not or if expansion fails because of reaching maximum capacity or for being out-of-memory, then the operation returns false without attempting to acquire the ticket.
Other changes:
- Added a note about this difference in semantic between the dynamic and non-dynamic version to the main comment about the dynamic version.
- Changed `oldCap` to `curCap` because the value is actually current not old.
- Added two tests for checking that tryWriteUntil() never blocks indefinitely for both dynamic and non-dynamic versions.
- Removed all the `never_fail` tests for the dynamic version, because such operations may fails as described above.
- Added `asm_volatile_pause` when spinning on the seqlock.
Reviewed By: djwatson
Differential Revision:
D4389347
fbshipit-source-id:
c46dbefc9fe08e146250d2ad8ba68b0887f97436
Christopher Dykes [Mon, 9 Jan 2017 21:04:47 +0000 (13:04 -0800)]
Use 2 second loop smoothing period rather than 20 seconds
Summary: This was accidentally changed in
D4375539.
Reviewed By: philippv
Differential Revision:
D4393574
fbshipit-source-id:
0420223575bad0c6b0e89f8cf5ed138e063462b9
Kyle Nekritz [Mon, 9 Jan 2017 19:51:34 +0000 (11:51 -0800)]
Add pre received data API to AsyncSSLSocket.
Summary: This allows something else (ie fizz) to read data from a socket, and then later decide to to accept an SSL connection with OpenSSL by inserting the data it read in front of future reads on the socket.
Reviewed By: anirudhvr
Differential Revision:
D4325634
fbshipit-source-id:
05076d2d911fda681b9c4e5d9d3375559293ea35
Kyle Nekritz [Mon, 9 Jan 2017 19:51:33 +0000 (11:51 -0800)]
Set custom ssl bio read method.
Summary: Similar to the bio write method. This should be essentially a no-op, bioRead has the same functionality as the openssl version. This is needed in the next diff.
Reviewed By: siyengar
Differential Revision:
D4325622
fbshipit-source-id:
a90b9ec06bee920a1a73551a3ea4c77e1ee0ab08
Zonr Chang [Mon, 9 Jan 2017 18:28:20 +0000 (10:28 -0800)]
Include <errno.h> for using "errno" and ENOMEM.
Summary: Closes https://github.com/facebook/folly/pull/537
Reviewed By: yfeldblum
Differential Revision:
D4391871
Pulled By: Orvid
fbshipit-source-id:
80401dd65ae376f9ebbb0b079577d0a1fd15475b
Nick Wolchko [Mon, 9 Jan 2017 17:20:48 +0000 (09:20 -0800)]
Remove folly::Future conversion constructor
Summary:
This constructor is unsafe. The check it uses before doing the comparison isn't a safe enough check to see if the cast is valid. For example, this is broken in the presence of multiple inheritance because it doesn't adjust the pointer offset to the correct vtable.
e.g.
struct A {
virtual ~A() {};
virtual void doSomething() = 0;
};
struct B {
virtual ~B() {}
virtual void doSomethingElse() = 0;
};
struct C : public B, public A {
virtual ~C() {}
void doSomething() override {
std::cout << "Something!" << std::endl;
}
void doSomethingElse() override {
std::cout << "Something Else!" << std::endl;
}
};
int main (int argc, char **argv) {
auto c = folly::makeFuture<std::shared_ptr<C>>(std::make_shared<C>());
folly::Future<std::shared_ptr<A>> a = std::move(c);
a.get()->doSomething();
return 0;
}
This code will print "Something else!" when run.
Reviewed By: siyengar
Differential Revision:
D3679673
fbshipit-source-id:
dcbf40ca82d458f17ee11191591f8b8daf58c919
Michael O'Farrell [Mon, 9 Jan 2017 15:22:20 +0000 (07:22 -0800)]
Fix folly json to only sort properties of objects based on their key not value.
Reviewed By: yfeldblum
Differential Revision:
D4386258
fbshipit-source-id:
23499267eb4390f0f40b3643760514cae1ca7838
Igor Sugak [Sun, 8 Jan 2017 05:58:13 +0000 (21:58 -0800)]
remove always true if-predicate (gcc-5 -Wlogical-op)
Summary:
gcc-5 -Wlogical-op reports:
```lang=bash
folly/io/async/AsyncSSLSocket.cpp: In member function 'void folly::AsyncSSLSocket::invalidState(folly::AsyncSSLSocket::HandshakeCB*)':
folly/io/async/AsyncSSLSocket.cpp:418:35: error: logical 'or' of collectively exhaustive tests is always true [-Werror=logical-op]
```
Reviewed By: yfeldblum
Differential Revision:
D4391317
fbshipit-source-id:
c0f5ce748f1fc21678e4080c7f6351e7fada1e2b
Eric Niebler [Sun, 8 Jan 2017 05:44:02 +0000 (21:44 -0800)]
add folly::as_const, like C++17's std::as_const
Summary: A one-liner from C++17, but a useful one. Const-qualifies an lvalue reference, avoiding the need for an awkward const_cast in some cases.
Reviewed By: yfeldblum
Differential Revision:
D4389929
fbshipit-source-id:
1650c4901489eb0dd62fd9fa633b4a0da9f01954
Christopher Dykes [Sat, 7 Jan 2017 20:51:23 +0000 (12:51 -0800)]
Properly std::chrono'ize HHWheelTimer
Summary: It was using `std::chrono::milliseconds` to represent a point in time, so use a time point instead.
Reviewed By: yfeldblum
Differential Revision:
D4378116
fbshipit-source-id:
f0b10bb7894dda44d78b31672d2b6735f3e1cbf4
Christopher Dykes [Sat, 7 Jan 2017 20:51:21 +0000 (12:51 -0800)]
std::chrono'ize EventBase::loopBody
Summary: Because modern is good, and this allows for cleaner interaction with the other APIs being `std::chrono`ized.
Reviewed By: yfeldblum
Differential Revision:
D4377773
fbshipit-source-id:
42ad5ad8476a3678e02e9314f9592f5449102f00
Christopher Dykes [Sat, 7 Jan 2017 20:51:20 +0000 (12:51 -0800)]
std::chrono'ize EventBase::setMaxLatency
Summary: Onward towards more modern code!
Reviewed By: yfeldblum
Differential Revision:
D4377678
fbshipit-source-id:
6ca5ecd902be9028fb55f139374f7919fa522899
Yedidya Feldblum [Sat, 7 Jan 2017 06:40:09 +0000 (22:40 -0800)]
Remove <glog/logging.h> from folly/Indestructible.h
Summary:
[Folly] Remove `<glog/logging.h>` from `folly/Indestructible.h`.
This makes the header much lighter. And abort on invalid access (the use-case for `glog`) only in `!defined(NDEBUG)` mode.
Anti-Pattern Combined Mega-Diff Description:
* Add non-`explicit` default ctor.
* Disable ctor explicitly when underlying ctor would fail to compile. Not sure how useful it would be, but it makes type-traits work correctly for whatever that is worth.
* Switch boolean flag to `erased_{false}` so that it is zero-initializable, because that's better.
Reviewed By: ericniebler
Differential Revision:
D4380469
fbshipit-source-id:
a39cb7470f7ee678fa722778da587409f468d985
Eric Niebler [Sat, 7 Jan 2017 02:32:01 +0000 (18:32 -0800)]
add folly::void_t like C++17's std::void_t
Summary:
C++17 is adding std::void_t. It's handy for controlling class template partial specialization. Folly should have it too.
See http://en.cppreference.com/w/cpp/types/void_t
Reviewed By: yfeldblum
Differential Revision:
D4387302
fbshipit-source-id:
85f955f3d8cfacbd6c9e61fb3f5cf53c056459bb
Yedidya Feldblum [Sat, 7 Jan 2017 00:43:48 +0000 (16:43 -0800)]
Skip defined checks in folly/Memory.h
Summary:
[Folly] Skip `defined` checks in `folly/Memory.h`.
Undefined symbols, when evaluated by the preprocessor in preprocessor integer contexts, evaluate to `0`. That works for these checks.
Reviewed By: ericniebler
Differential Revision:
D4385026
fbshipit-source-id:
3162f8b83431ebab2de53f9ba202e7ea8c339210
Zonr Chang [Fri, 6 Jan 2017 23:07:40 +0000 (15:07 -0800)]
__throw* functions seem to be available in LLVM 4.0 or above.
Summary:
__throw* functions exist in master branch but are not included in both
libc++ 3.9.0 and 3.9.1. Expect them to appear in next LLVM release
(which is 4.0).
Closes https://github.com/facebook/folly/pull/536
Reviewed By: yfeldblum, Orvid
Differential Revision:
D4377002
Pulled By: smeenai
fbshipit-source-id:
5dd311ca3ec43955f29dd1197fd8fbeb9564a7f6
Christopher Dykes [Fri, 6 Jan 2017 22:00:46 +0000 (14:00 -0800)]
std::chrono'ize EventBase::setLoadAvgMsec
Summary: Modernization is good.
Reviewed By: yfeldblum
Differential Revision:
D4377612
fbshipit-source-id:
adb03d8a92f25c8a792c8e7240a93ab20180b038
Christopher Dykes [Fri, 6 Jan 2017 20:36:54 +0000 (12:36 -0800)]
std::chrono'ize EventBase::SmoothLoopTime
Summary: Modernizing for the future.
Reviewed By: yfeldblum
Differential Revision:
D4375539
fbshipit-source-id:
e3edf8dd6b77d3338f8cf58ed128bc5bce62da32
Igor Sugak [Fri, 6 Jan 2017 17:53:00 +0000 (09:53 -0800)]
fix gcc-5 build
Summary:
```lang=bash
folly/test/SmallLocksBenchmark.cpp:212:18: error: use of undeclared identifier 'sqrt'
double stdev = sqrt(accum / (results.size() - 1));
^
folly/test/SmallLocksBenchmark.cpp:221:20: error: use of undeclared identifier 'sqrt'
double stddev2 = sqrt(variance);
^
2 errors generated.
```
Add the missing header.
Reviewed By: yfeldblum
Differential Revision:
D4386343
fbshipit-source-id:
79c3dcae32c62f9b6d162862deabccf5fea7eaef
Igor Sugak [Fri, 6 Jan 2017 04:11:17 +0000 (20:11 -0800)]
fix gcc-5 build
Summary:
Clang with libgcc-5 reported:
```lang=bash
folly/experimental/test/BitsTest.cpp:249:16: error: use of undeclared identifier 'pow'
auto value = pow(2, bits) * (negate ? -2.0 : 2.0) / 3.0;
^
```
Add missing include statement, and elaborate with the namespace.
Reviewed By: yfeldblum
Differential Revision:
D4385807
fbshipit-source-id:
a847dd439cd4c9f28ea8f222aa4ab60876949d13
Michael Lee [Thu, 5 Jan 2017 23:49:03 +0000 (15:49 -0800)]
make_unique is ambiguous with c++14 for some platforms
Summary: Missing compatibility case for Android
Reviewed By: yfeldblum
Differential Revision:
D4384944
fbshipit-source-id:
0b3e43fb284b6a71c6ae2a2162d1ea7cb99bc817
Eric Niebler [Thu, 5 Jan 2017 21:48:28 +0000 (13:48 -0800)]
don't use assert in benchmarks. it gets stripped out in release mode.
Summary: Critical tests in benchmarks should not be in asserts since they will be stripped out in release mode, which is the only mode interesting for benchmarks.
Reviewed By: yfeldblum
Differential Revision:
D4384411
fbshipit-source-id:
5237ab48f99ddcd2bce7a159fcf82900303efec2
Yedidya Feldblum [Thu, 5 Jan 2017 17:57:26 +0000 (09:57 -0800)]
Namespace the UBSAN_DISABLE symbol
Summary:
[Folly] Namespace the `UBSAN_DISABLE` symbol.
Symbols defined by Folly should typically be namespaced to Folly.
Reviewed By: igorsugak
Differential Revision:
D4378401
fbshipit-source-id:
ff72f5f44e7c9d1bbf08efcec24bd3dc05d10ee7
Yedidya Feldblum [Thu, 5 Jan 2017 17:54:44 +0000 (09:54 -0800)]
Backport ceil, floor, round from C++17 std::chrono
Summary:
[Folly] Backport `ceil`, `floor`, `round` from C++17 `std::chrono`.
These functions for operating on `std::chrono::duration` and `std::chrono::time_point` values are useful
Note: The implementations are derived from cppreference.com, which has a notice listing all content there as licensed under CC-BY-SA.
Reviewed By: ericniebler
Differential Revision:
D4375603
fbshipit-source-id:
36a098bf5f75db071c1670518fc42bbc6df2817d
Yedidya Feldblum [Wed, 4 Jan 2017 21:24:48 +0000 (13:24 -0800)]
Keep the std::exception* or std::type_info* in folly::exception_wrapper
Summary:
[Folly] Keep the `std::exception*` or `std::type_info*` in `folly::exception_wrapper`.
In the case of construction with a `std::exception_ptr`. Instead of keeping a pair of `std::string`s, strictly losing information (not that we use any more information, but theoretically we could).
Of note:
* Shrinks the size of `folly::exception_wrapper`, in all cases, to 48 bytes. Down from 32 bytes + 2 S bytes on 64-bit architectures, where S is the size in bytes of `std::string`. In particular, `libstdc++`'s implementation is 32 bytes, while `libc++`'s and Folly's implementations are 24 bytes on 64-bit architectures, for total original sizes of 96 bytes or 80 bytes.
* Allows to avoid rethrowing in `with_exception` in the case of an instance constructed with an `std::exception_ptr` plus an `std::exception&`.
Reviewed By: ericniebler
Differential Revision:
D4369935
fbshipit-source-id:
35155e0b271959a4878fe077fc911b17767a2358
Shoaib Meenai [Wed, 4 Jan 2017 18:53:21 +0000 (10:53 -0800)]
Add preprocessor macro to disable throw* definitions
Summary:
libc++ 4.0 and above define the throw* functions in `stdexcept`, so
Folly doesn't need to define them itself. In case those definitions are
backported to 3.9, add a Folly macro to skip the definitions regardless
of the libc++ version number.
Reviewed By: yfeldblum, Orvid
Differential Revision:
D4378102
fbshipit-source-id:
674d98d7c448aa7e75bdd8b6e9fe965cd34a83d7
Yedidya Feldblum [Wed, 4 Jan 2017 03:37:13 +0000 (19:37 -0800)]
folly::_t and use it in folly::exception_wrapper
Summary:
[Folly] `folly::_t` and use it in `folly::exception_wrapper`.
Intended in part for use in Folly code, but can be used outside.
Instead of:
```lang=c++
namespace folly {
using original = //...
using decayed = typename std::decay<original>::type;
}
```
In C++14:
```lang=c++
namespace folly {
using original = //...
using decayed = std::decay_t<original>;
}
```
And in C++11:
```lang=c++
namespace folly {
using original = //...
using decayed = _t<std::decay<original>>:
}
```
Not perfect, but better.
HT ericniebler and https://github.com/eniebler/meta.
Reviewed By: ericniebler
Differential Revision:
D4371539
fbshipit-source-id:
9046d9caab73141b95f4bce4fb1af26e0c1ac739
Yedidya Feldblum [Wed, 4 Jan 2017 02:49:30 +0000 (18:49 -0800)]
2017
Summary: [Folly] 2017.
Reviewed By: Orvid
Differential Revision:
D4378593
fbshipit-source-id:
4a448228bb1ddbe191b6e8562483867a399be846
Steve O'Brien [Tue, 3 Jan 2017 21:45:15 +0000 (13:45 -0800)]
folly: ReadMostlySharedPtr fix for `getStdShared()` method
Summary:
Fix this error:
In file included from FooUtils.cpp:2:
folly/experimental/ReadMostlySharedPtr.h:323:21: error: 'ptr_' is a private member of 'folly::detail::ReadMostlySharedPtrCore<Foo, folly::TLRefCount>'
return impl_->ptr_;
^
... in instantiation of member function 'folly::ReadMostlySharedPtr<Foo, folly::TLRefCount>::getStdShared' requested here:
getSomeReadMostlySharedPtr().getStdShared();
^
buck-out/dev/gen/folly/__default_headers__#default,headers/folly/experimental/ReadMostlySharedPtr.h:94:22: note: declared private here
std::shared_ptr<T> ptr_;
^
1 error generated.
The added test case repro's the above error (and the changes to the class fixes it).
Alternatives include just making `ReadMostlySharedPtr` a friend class of `ReadMostlySharedPtrCore`, but that seems uglier than this fix, which was to simply use the public `getShared` method which already exists.
As luck would have it, I had tried that, and also found that a `const ReadMostlySharedPtr` would still give some trouble because `getStdShared` was not marked `const`. Fixed that too. (I assume if a copy of a const `shared_ptr` member / such a member of a `const` instance is permissible, then the method should be const as well. Plus it's const in the other `ReadMostlySharedPtr` class.)
Reviewed By: djwatson
Differential Revision:
D4377690
fbshipit-source-id:
8e9e778ca991fd04b0eb1e5762795d871ce0ee8d
Yedidya Feldblum [Tue, 3 Jan 2017 21:44:19 +0000 (13:44 -0800)]
Drop the boost dependency from Traits.h and FBVector.h
Summary:
[Folly] Drop the `boost` dependency from `Traits.h` and `FBVector.h`.
Should not need it anymore with the currently supported compilers.
Reviewed By: ericniebler
Differential Revision:
D4375572
fbshipit-source-id:
df890c07f49b0499d2d2d08aa21c226b2893281e
Christopher Dykes [Tue, 3 Jan 2017 17:39:23 +0000 (09:39 -0800)]
Kill a dead constant in EventBase
Summary: It's only accessible within EventBase, and is never used.
Reviewed By: yfeldblum
Differential Revision:
D4375541
fbshipit-source-id:
a0c6d86a2b1968c37c67303c8411a23ed936d9d5
Mathieu Baudet [Mon, 2 Jan 2017 13:19:07 +0000 (05:19 -0800)]
fbcode: remove unused includes from .cpp files without #if (but possibly #define)
Summary: Same as
D4312617 but this time not excluding source files with `#define`.
Reviewed By: soumith
Differential Revision:
D4344811
fbshipit-source-id:
5a314960c319f029c6737c8c8ac8224ec2f20218
Yedidya Feldblum [Mon, 2 Jan 2017 06:25:38 +0000 (22:25 -0800)]
Drop <boost/operators.hpp> as a dependency of FBVector.h
Summary:
[Folly] Drop `<boost/operators.hpp>` as a dependency of `FBVector.h`.
We can rough it.
Reviewed By: wqfish
Differential Revision:
D4375986
fbshipit-source-id:
6b8c16ca9a55341fee396a253f7ad0c4d0201b0e
Yedidya Feldblum [Mon, 2 Jan 2017 06:25:37 +0000 (22:25 -0800)]
Move the traits factories up, and remove <boost/mpl/has_xxx.hpp>
Summary:
[Folly] Move the traits factories up, and remove `<boost/mpl/has_xxx.hpp>`.
Also, they now generate aliases to the types aliased by `std::true_type` and `std::false_type`. So now the API is entirely compatible with the requirements of `std::integral_constant` (because it is `std::integral_constant`).
Reviewed By: wqfish
Differential Revision:
D4375944
fbshipit-source-id:
dfd41283f13d793f7fc1f173590cd93cdee39a10
Zonr Chang [Mon, 2 Jan 2017 00:24:34 +0000 (16:24 -0800)]
Add FOLLY_OPENSSL_HAS_ALPN and FOLLY_OPENSSL_HAS_SNI.
Summary:
This expresses the intention of long predicate on OpenSSL version and
OPENSSL_NO_TLSEXT more clearly.
This also enables ALPN and SNI support when BoringSSL is in use.
ALPN is an essential function to make HTTP/2 work when building Proxygen
with BoringSSL.
Closes https://github.com/facebook/folly/pull/534
Reviewed By: Orvid
Differential Revision:
D4375391
Pulled By: yfeldblum
fbshipit-source-id:
009f311bceb0ee911d904d96a3e678a5f7241575
Yedidya Feldblum [Sun, 1 Jan 2017 23:03:34 +0000 (15:03 -0800)]
Fix assorted missing includes
Summary: Fix assorted missing includes.
Reviewed By: wqfish
Differential Revision:
D4375902
fbshipit-source-id:
2b32631857c8f94e505153d32932cdf97d8d0b33
Petr Lapukhov [Sat, 31 Dec 2016 00:11:41 +0000 (16:11 -0800)]
Add more MSG_OOB tests for EventHandler
Summary:
Sending OOB messages allows for single byte to be sent truly out of band and placed in an OOB buffer. This byte can then be read (by default) independent from normal data.
The two test-cases validate that
(1) We can receive OOB and normal data on same socket
(2) Sending OOB byte does not affect regular data
NOTE: sending more than one byte usually means the OOB data interleaved with regular data.
Reviewed By: alandau
Differential Revision:
D4370652
fbshipit-source-id:
a573dae7e5afba5a4a410be5371faf4f065c74e9
Zbigniew Szymanski [Fri, 30 Dec 2016 13:19:20 +0000 (05:19 -0800)]
Move internal `decodeUtf8` method from json.cpp to public util Unicode.h
Summary:
Moved decodeUtf8 -> folly::utf8ToCodePoint.
Implementation was not changed to make sure no bugs are introduced.
Reviewed By: yfeldblum
Differential Revision:
D4372739
fbshipit-source-id:
a015a9c47ece825e09e7c243fae454f21f99db80
Yedidya Feldblum [Fri, 30 Dec 2016 01:25:26 +0000 (17:25 -0800)]
Let Future::then call callbacks outside of the catch handler
Summary:
[Folly] Let `Future::then` call callbacks outside of the catch handler.
And `Future::onError`.
This makes the behavior of calls to `Future` callbacks with respect to currently-handled ("active") exceptions consistent - there will not be an active exception by the time the `Future` callback is called. (Unless `Future::then` or `Future::onError`, etc., is itself called with an active exception. Or unless the `Promise` is fulfilled, outside of the `Future` implementation code, with an active exception.)
This will affect any code which tries to call `std::current_exception()` or `throw;` from within a `Future` callback, such as an `onError` handler. That code will crash. (It was incorrect anyway, and relied on misusing Folly Futures.)
Reviewed By: ericniebler
Differential Revision:
D4372173
fbshipit-source-id:
600b22e4db63c98358de29a6abcee807fbc53b0f
Yedidya Feldblum [Thu, 29 Dec 2016 23:47:55 +0000 (15:47 -0800)]
Const-correctness for folly::exception_wrapper::with_exception with non-std::exception
Summary:
[Folly] Const-correctness for `folly::exception_wrapper::with_exception` with non-`std::exception`.
This also lets us unify the various flavors of `with_exception` and `is_compatible_with`. And fix `is_compatible_with` for non-`exception` types.
Reviewed By: ericniebler
Differential Revision:
D4364474
fbshipit-source-id:
417edfd45f7cfba952ce961559da67769b7c41bc
Eric Niebler [Thu, 29 Dec 2016 19:51:18 +0000 (11:51 -0800)]
folly::TryException inherits from std::logic_error, like std::bad_optional_access; becomes no-throw copyable
Summary:
folly::TryException was inheriting from std::exception and managing its own message in a std::string data member.
That is suboptimal for the following reasons:
1) The analagous std:: type, std::bad_optional_access, inherits from std::logic_error. According to the Principle of Least
Astonishment, folly::TryException should follow suit.
2) std::logic_error has a nothrow copy constructor. (This is typically implemented with a ref-counted string.)
std::string does not. By explicitly managing its own message, folly::TryException picks up a throwing copy
constructor. Exception classes should try to be nothrow copyable.
3) With most stdlib implementations, std::string is larger by a lot than the std:: exceptions. By changing
folly::TryException as suggested, its size drops from 40 bytes to 16 on clang and gcc >=5.0.
Reviewed By: yfeldblum
Differential Revision:
D4368760
fbshipit-source-id:
327f78f428419ccf9c7af3e0f57cc478d147fb37
Eric Niebler [Thu, 29 Dec 2016 19:50:57 +0000 (11:50 -0800)]
folly::FutureException inherits from std::logic_error, like std::future_error; becomes smaller and nothrow-copy
Summary:
folly::FutureException was inheriting from std::exception and managing its own message in a std::string data member.
That is suboptimal for the following reasons:
1) The analagous std:: type, std::future_error, inherits from std::logic_error. According to the Principle of Least
Astonishment, folly::FutureExpception should follow suit.
2) std::logic_error has a nothrow copy constructor. (This is typically implemented with a ref-counted string.)
std::string does not. By explicitly managing its own message, folly::FutureException picks up a throwing copy
constructor. Exception classes should try to be nothrow copyable.
3) With most stdlib implementations, std::string is larger by a lot than the std:: exceptions. By changing
folly::FutureException as suggested, its size drops from 40 bytes to 16 on clang and gcc >=5.0.
Also, I took the liberty of fixing some copy-pastas that gave some of these exception types explicit default
constructors.
Reviewed By: yfeldblum
Differential Revision:
D4367909
fbshipit-source-id:
1639d404237493f929db6116a760c2d0e599877d
Bi Xue [Thu, 29 Dec 2016 06:18:32 +0000 (22:18 -0800)]
Make FunctionRef support bool operator
Summary:
To support following code:
```
void foo(folly::FunctionRef<void(void)> callback = {}) {
if (callback) {
callback();
}
}
```
Reviewed By: yfeldblum
Differential Revision:
D4372296
fbshipit-source-id:
7d21e6a44b6f6b046b424f0139465511dbae7b8b
Giuseppe Ottaviano [Thu, 29 Dec 2016 04:18:43 +0000 (20:18 -0800)]
Avoid shadowing warnings in SYNCHRONIZED
Summary: If two `SYNCHRONIZED` blocks are nested the internal `SYNCHRONIZED_*` variables can be compatible shadows (`SYNCHRONIZED_state` always is), so GCC will issue a warning with `-Wshadow-compatible-local`. This diff disambiguates the variable names for each `SYNCHRONIZED` block (as long as they appear on different lines).
Reviewed By: yfeldblum, philippv
Differential Revision:
D4371263
fbshipit-source-id:
b467a1a2651667c679382a1cc1eaa28f7ee4e6b3
Anirudh Ramachandran [Thu, 29 Dec 2016 02:54:04 +0000 (18:54 -0800)]
Add OpenSSL portability layer
Summary:
Enable folly to build with OpenSSL alternatives (e.g., BoringSSL).
Some SSL-related tests are disabled:
- Async session cache ones (BoringSSL has an async cache impl but with a different API)
- TFO tests
- Some changes to error tests which expect specific error strings. This is
flaky as a test because it will break everytime even within a version, so we
should fix that first.
This should be a noop for OpenSSL 1.0.2.
BoringSSL commit used is
35c8afd3143289c99aa3820e01950c564d7aced8 (10/26/2016)
Closes: https://github.com/facebook/folly/issues/198
Reviewed By: siyengar
Differential Revision:
D3280382
fbshipit-source-id:
4141d992e0d8dd797ac4af479cfe90844a23278f
Yedidya Feldblum [Thu, 29 Dec 2016 02:03:39 +0000 (18:03 -0800)]
folly::copy
Summary:
[Folly] `folly::copy`.
Usable when you have a function with two overloads:
class MyData;
void something(MyData&&);
void something(const MyData&);
Where the purpose is to make copies and moves explicit without having to spell out the full type names - in this case, for copies, to invoke copy constructors.
When the caller wants to pass a copy of an lvalue, the caller may:
void foo() {
MyData data;
something(folly::copy(data)); // explicit copy
something(std::move(data)); // explicit move
something(data); // const& - neither move nor copy
}
Reviewed By: markisaa, ericniebler
Differential Revision:
D3462023
fbshipit-source-id:
6c777be288f2a7012c1b4b46dc988890b8662595
Philip Pronin [Thu, 29 Dec 2016 00:28:30 +0000 (16:28 -0800)]
nuke UNSYNCHRONIZED
Summary:
API of `UNSYNCHRONIZED` is confusing as if you have two nested
`SYNCHRONIZED` blocks, `UNSYNCHRONIZED` always unlocks the inner-most,
even if you pass in the variable name used in the outer `SYNCHRONIZED`
block.
The macro was marked as "deprecated" in
D3526489, remove it here.
Reviewed By: yfeldblum
Differential Revision:
D4371297
fbshipit-source-id:
13ddc1ff77cb3d5045844c5ade0e95dbe2bccf6d