folly.git
7 years agoLet folly::range be constexpr
Yedidya Feldblum [Sun, 6 Nov 2016 21:09:44 +0000 (13:09 -0800)]
Let folly::range be constexpr

Summary:
[Folly] Let `folly::range` be `constexpr`.

It will be useful to have this helper function be `constexpr` to support further compile-time code.

Reviewed By: juchem

Differential Revision: D4135943

fbshipit-source-id: a62be93f9e492ca302130d1a3b190ed4b69f7a80

7 years agooperator== for ReadMostlySharedPtr to nullptr_t
Christopher Small [Sat, 5 Nov 2016 19:36:36 +0000 (12:36 -0700)]
operator== for ReadMostlySharedPtr to nullptr_t

Summary: add operator== against nullptr_t for ReadMostlySharedPtr

Reviewed By: andriigrynenko, nbronson, yfeldblum

Differential Revision: D4128722

fbshipit-source-id: 40d08bb85bfe2f96ad4ed4995f5829e0616d0661

7 years agoAdd StringKeyedMap/Set.h to OSS build
Zach Amsden [Fri, 4 Nov 2016 19:59:59 +0000 (12:59 -0700)]
Add StringKeyedMap/Set.h to OSS build

Summary: Eden uses this and won't build with OSS folly without it.

Reviewed By: Orvid

Differential Revision: D4132103

fbshipit-source-id: 68d6c7dc642a7401eca60b0713db9f90cc11ced1

7 years agoTrying to improve the efficiency of RequestContext callbacks
Mirek Klimos [Fri, 4 Nov 2016 18:10:46 +0000 (11:10 -0700)]
Trying to improve the efficiency of RequestContext callbacks

Summary: Changed RWSpinLock to a SharedMutex in the RequestContext to see if this would lower the overhead of the onSet/onUnset callbacks.

Reviewed By: djwatson

Differential Revision: D3780396

fbshipit-source-id: 3d91f8194357533072fe053d23e0454a36faecff

7 years agoAdd splitAtMost to IOBufQueue.
Kyle Nekritz [Thu, 3 Nov 2016 22:53:52 +0000 (15:53 -0700)]
Add splitAtMost to IOBufQueue.

Summary: This allows getting up to n bytes from the queue without first having to check the length.

Reviewed By: yfeldblum

Differential Revision: D4083484

fbshipit-source-id: 2a468992c97f036c22f1a0d9f830e6d5286a4bc2

7 years agoAllow folly::io::Cursor to move backwards.
Kyle Nekritz [Thu, 3 Nov 2016 22:53:50 +0000 (15:53 -0700)]
Allow folly::io::Cursor to move backwards.

Summary: This is helpful for parsing data IOBufs in reverse.

Reviewed By: siyengar

Differential Revision: D4082810

fbshipit-source-id: 6a201d25e7d22befe28f92e4a1d7aa41ad7d6817

7 years agoquiet -Wmaybe-uninitialized
Louis Brandy [Thu, 3 Nov 2016 17:35:18 +0000 (10:35 -0700)]
quiet -Wmaybe-uninitialized

Summary: gcc-4.9 doesn't appreciate this clever loop and worries about `prev` being uninitialized on first use. Assuming the rest of the program behaves properly and preserves the invariant this code is expecting, this isn't bugged. But let's initialize it anyway.

Reviewed By: meyering

Differential Revision: D4120746

fbshipit-source-id: 1a7c323a4b6296a81768a62dd7d72337c5c35bf0

7 years agofolly/test/RangeFindBenchmark.cpp: avoid shadowing warning: rename inner "n": s/...
Jim Meyering [Thu, 3 Nov 2016 02:02:20 +0000 (19:02 -0700)]
folly/test/RangeFindBenchmark.cpp: avoid shadowing warning: rename inner "n": s/\<n\>/c/

Reviewed By: yfeldblum

Differential Revision: D4120553

fbshipit-source-id: 87c202232bcfabeff7eb62a8133b9b5577b09cbc

7 years agofolly/test/ThreadLocalBenchmark.cpp: avoid shadowing warning
Jim Meyering [Thu, 3 Nov 2016 02:02:00 +0000 (19:02 -0700)]
folly/test/ThreadLocalBenchmark.cpp: avoid shadowing warning

Summary:
There was a doubly-nested loop, both with index "i".
Change the inner for-loop index from i to j.

Reviewed By: yfeldblum

Differential Revision: D4120589

fbshipit-source-id: c786d8f7bb1ee05fc990db898b15836032e93940

7 years agofolly/test/ExceptionWrapperBenchmark.cpp: avoid shadowing warnings
Jim Meyering [Thu, 3 Nov 2016 02:00:24 +0000 (19:00 -0700)]
folly/test/ExceptionWrapperBenchmark.cpp: avoid shadowing warnings

Reviewed By: jsedgwick

Differential Revision: D4120563

fbshipit-source-id: c97645a068662e41d5038bcd1e9805bdf6f0490c

7 years agoAllow getting the sequence number of a token via a read only getter function
Ameya Limaye [Thu, 3 Nov 2016 01:01:53 +0000 (18:01 -0700)]
Allow getting the sequence number of a token via a read only getter function

Summary: Allow getting the sequence number of a token via a read only getter function

Reviewed By: yfeldblum

Differential Revision: D4120900

fbshipit-source-id: b664dda29d13a1755e041ab9c33c0d7324690ba7

7 years agoUse loopKeepAlive() mechanism in FiberManager
Andrii Grynenko [Thu, 3 Nov 2016 00:39:29 +0000 (17:39 -0700)]
Use loopKeepAlive() mechanism in FiberManager

Reviewed By: yfeldblum

Differential Revision: D4086486

fbshipit-source-id: bd0cca8dd2c9b74d5c30e4cd095191c1d1ecab79

7 years agoCompile RangeSse42.cpp with -msse4.2
Tudor Bosman [Wed, 2 Nov 2016 22:00:45 +0000 (15:00 -0700)]
Compile RangeSse42.cpp with -msse4.2

Summary:
Solves #509 by creating a libtool convenience library that's compiled with -msse4.2.
Closes https://github.com/facebook/folly/pull/510

Differential Revision: D4120400

Pulled By: yfeldblum

fbshipit-source-id: bf5d937dc37ef8707e755c89f1883d65b4d21b0f

7 years agofix race between StaticMetaBase::destroy() and StaticMetaBase::onThreadExit()
Philip Pronin [Wed, 2 Nov 2016 04:24:55 +0000 (21:24 -0700)]
fix race between StaticMetaBase::destroy() and StaticMetaBase::onThreadExit()

Summary:
We would like to guarantee that after `folly::ThreadLocal<>` dtor
returns no per-thread instances are longer alive.  Currently this is not a case:

* T1 is excuting `StaticMetaBase::onThreadExit()`, it acquired all per-thread
  instances and erased them from meta under `accessAllThreadsLock_`.
* T2 destroys `folly::ThreadLocal<>`, it executes `StaticMetaBase::destroy()`,
  collects all per-thread instances (thus missing the ones being destroyed by
  T1), destroys them and returns.
* T1 executes dtor of per-thread instances, after parent `folly::ThreadLocal<>`
  dtor is finished.

Reviewed By: ot

Differential Revision: D4109820

fbshipit-source-id: d547b8cc77c9871126538c38644c2e98ddccf220

7 years agoMake sequence number in AtomicBatchDispatcher<....>::Token non-const
Ameya Limaye [Wed, 2 Nov 2016 03:28:09 +0000 (20:28 -0700)]
Make sequence number in AtomicBatchDispatcher<....>::Token non-const

Summary:
Make sequence number in AtomicBatchDispatcher<....>::Token non-const:
- The field is already private and having it as const prevents a
  move assignment operator from getting defined

Reviewed By: yfeldblum

Differential Revision: D4114851

fbshipit-source-id: 9f7a4003daff02c007c01747cca6ae9da17fcb79

7 years agoDon't declare the extern FingerprintTable specializations under MSVC
Christopher Dykes [Tue, 1 Nov 2016 23:50:28 +0000 (16:50 -0700)]
Don't declare the extern FingerprintTable specializations under MSVC

Summary:
MSVC doesn't allow uninitialized non-`extern` `const` declarations, but we can't mark them `extern` because they are part of a template specialization. We also can't initialize them, because they'd conflict with the definition specializations in the generated tables.
As the forward-declarations aren't required for it to work under MSVC, as the specializations are found appropriately, just don't declare the specializations under MSVC.

Reviewed By: yfeldblum

Differential Revision: D4098282

fbshipit-source-id: 84b73d63bbe6cf9c54b7fe7a3bfc2488699df7c2

7 years agoFix CLANG compilation: folly/TokenBucket.h
David Callahan [Tue, 1 Nov 2016 19:56:08 +0000 (12:56 -0700)]
Fix CLANG compilation: folly/TokenBucket.h

Summary:
In the next revision of clang, compilation generates multiple erroes of the form

   folly/TokenBucket.h:127:29: error: exception specification is not available until end of  class definition
         double nowInSeconds = defaultClockNow()) {

which are eliminated by reordering the method declaration for defaultClockNow()

Refer https://llvm.org/bugs/show_bug.cgi?id=30860

Reviewed By: philippu, yfeldblum

Differential Revision: D4107443

fbshipit-source-id: ce64f2ae7983e533c2fcb5cb043dbdd3da5c00f7

7 years agoEliminate more VLAs
Christopher Dykes [Tue, 1 Nov 2016 18:24:18 +0000 (11:24 -0700)]
Eliminate more VLAs

Summary:
MSVC doesn't support them, so use dynamic allocation instead.
This also fixes a place where MSVC wasn't propogating the constexpr-ness of a local into the body of a lambda, resulting in an attempt to create a VLA.

Reviewed By: yfeldblum

Differential Revision: D4098932

fbshipit-source-id: 742b2fcd96f7f6eceb5043159403d557f7fc9673

7 years agouint8_t isn't a valid template argument for uniform_int_distribution
Christopher Dykes [Tue, 1 Nov 2016 18:24:09 +0000 (11:24 -0700)]
uint8_t isn't a valid template argument for uniform_int_distribution

Summary: Clang and GCC allow it, but the spec, and MSVC, don't, so use uint16_t instead.

Reviewed By: yfeldblum

Differential Revision: D4099285

fbshipit-source-id: cdf7ba14b6c00e1bcdfc3650b76e6e4a47a61929

7 years agoSilence a couple of warnings for MSVC in Optional.h
Christopher Dykes [Tue, 1 Nov 2016 18:23:40 +0000 (11:23 -0700)]
Silence a couple of warnings for MSVC in Optional.h

Summary: Silence a couple of warnings that get very spammy for MSVC.

Reviewed By: yfeldblum

Differential Revision: D4098682

fbshipit-source-id: b410b56062cdf82367675ea9c3dd22975e7b91bd

7 years agoFix BoostContextCompatibility for boost >= 1.61
Andrii Grynenko [Tue, 1 Nov 2016 01:16:50 +0000 (18:16 -0700)]
Fix BoostContextCompatibility for boost >= 1.61

Reviewed By: yfeldblum

Differential Revision: D4100221

fbshipit-source-id: 7778b48f1bba9be85f5712f61d6e1731524901c3

7 years agoSimplify the API exposed by BoostContextCompatibility
Andrii Grynenko [Tue, 1 Nov 2016 01:05:31 +0000 (18:05 -0700)]
Simplify the API exposed by BoostContextCompatibility

Summary: Instead of exposing raw jumpContext, it now exposes a higher-level FiberImpl class, which can be extended for newer versions of jump_fcontext.

Reviewed By: yfeldblum

Differential Revision: D4099849

fbshipit-source-id: 28c7ce32284a0109cf040c264d46a31a45867934

7 years agoSimplify activateFiber()/deactivateFiber()
Andrii Grynenko [Mon, 31 Oct 2016 23:08:47 +0000 (16:08 -0700)]
Simplify activateFiber()/deactivateFiber()

Summary: A cleanup in preparation to make folly::fibers work with newer boost.

Reviewed By: jsedgwick

Differential Revision: D4093947

fbshipit-source-id: e9a0aaeb915c40af96282169d4758afe572f2dd8

7 years agoUpdate hazard pointers interface and implementation
Maged Michael [Mon, 31 Oct 2016 21:47:41 +0000 (14:47 -0700)]
Update hazard pointers interface and implementation

Summary:
The main purpose of this diff and this library at this point is to be a public reference for the C++ standard committee and whoever is interested in the proposal to the committee.

This diff aims to be consistent with the latest version of the proposal (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0233r2.pdf).

The current interface proposal focuses on the core components (domain, object base, and raii owner). Once, that part is settled we can add to the interface:
- Thread local options (thread caching of hazard pointers and private storage of retired objects)
- Programmer control of reclamation (when and by which threads)
Also, at this point the implementation does not optimize memory ordering.

I removed hazptr_domain::try_reclaim() from the public interface at this point. The latest update to interface aims to relieve the programmer from the need to take spacial precautions against shutdown fiascos involving reclamation functions of objects stored by the default domain. Please let me know if you have any concerns about this.

Having said that about the current purpose of this library, I really appreciate any comments (in this diff or separately) on the interface in general and any suggestions for the eventual optimized implementation.

Reviewed By: davidtgoldblatt

Differential Revision: D4104381

fbshipit-source-id: df98adf6fd9b7a93406cb8eeca8fe2ad12388139

7 years agofolly: AsyncSignalHandler: update comments to match code
Lucian Grijincu [Mon, 31 Oct 2016 19:56:26 +0000 (12:56 -0700)]
folly: AsyncSignalHandler: update comments to match code

Summary: #accept2ship

Reviewed By: jsedgwick

Differential Revision: D4105140

fbshipit-source-id: eca1f7066e514ec3c5d316f974edc34e03872784

7 years agoAccess the individual words of an IPv6 address correctly in IPAddressTest on Windows
Christopher Dykes [Mon, 31 Oct 2016 19:00:28 +0000 (12:00 -0700)]
Access the individual words of an IPv6 address correctly in IPAddressTest on Windows

Summary: Winsock defines the internals of `in6_addr` in its own way, so we have to account for that.

Reviewed By: jsedgwick

Differential Revision: D4099453

fbshipit-source-id: c0ebb4e2017f61bed7d5d63058161ef3f16f9a65

7 years agoIn the portability implementation of sendmsg return a partial message send if it...
Christopher Dykes [Mon, 31 Oct 2016 18:59:37 +0000 (11:59 -0700)]
In the portability implementation of sendmsg return a partial message send if it would block

Summary: If multiple iovs are passed to sendmsg, sendmsg is supposed to return the number of bytes sent if it would block, but only if the number of bytes sent is greater than 0.

Reviewed By: yfeldblum

Differential Revision: D4099691

fbshipit-source-id: e58fa71604966129b1fbd418c24b1bf012060428

7 years agoImplement AtomicBatchDispatcher in folly::fibers
Ameya Limaye [Mon, 31 Oct 2016 16:26:16 +0000 (09:26 -0700)]
Implement AtomicBatchDispatcher in folly::fibers

Summary:
Implement AtomicBatchDispatcher in folly::fibers
- Details about how to use the added functionality can be found
  in the doc comment for class AtomicBatchDispatcher.

Reviewed By: andriigrynenko

Differential Revision: D4054148

fbshipit-source-id: 090272eeab8c8abb15d5e400e52725853fcfc364

7 years agoUse MSG_MORE instead of 2 setsockopt calls on every AsyncSSLSocket write.
Kyle Nekritz [Mon, 31 Oct 2016 15:09:06 +0000 (08:09 -0700)]
Use MSG_MORE instead of 2 setsockopt calls on every AsyncSSLSocket write.

Summary: Previously we set the cork option on the socket before making multiple writes, and then unset it after, which elip found was hurting perf with 2 extra syscalls. The cork logic was also not the same as the buffer combining logic, which made us often set cork even when only doing one write.

Reviewed By: djwatson

Differential Revision: D4058357

fbshipit-source-id: 1a07447ff5e027751e455a2403e0042bf67cb1c5

7 years agoimprovements to folly::doNotOptimizeAway v2016.10.31.00
Nathan Bronson [Mon, 31 Oct 2016 01:12:26 +0000 (18:12 -0700)]
improvements to folly::doNotOptimizeAway

Summary:
A common failure mode for folly::doNotOptimizeAway is to pass it a
pointer to a complex object that the caller wants to ensure is fully
calculated, which doesn't actually ensure that.  Also, the GCC and
MSVC implementations used inline assembly with an in-out parameter,
which causes a store.  A survey of many usages of doNotOptimizeAway
found only 1 that relies on this make-unpredictable behavior.

This diff makes doNotOptimizeAway(&x) equivalent to doNotOptimizeAway(x)
for GCC and clang, and makes it a read-only sink.  For the rare
case that the benchmark wants to disable subexpression elimination,
constant propagation, or power reduction, there is a new function
makeUnpredictable.  It also merges the clang and GCC implementations,
removing a potential bias in our microbenchmarks.

Reviewed By: davidtgoldblatt

Differential Revision: D4074670

fbshipit-source-id: 43f02e7fe149147bb172babe77787dea06e098fa

7 years agoInclude the Time.h portability header where needed
Christopher Dykes [Sat, 29 Oct 2016 00:20:16 +0000 (17:20 -0700)]
Include the Time.h portability header where needed

Summary: In this case, the SpookyHash tests, which call `clock_gettime`.

Reviewed By: yfeldblum

Differential Revision: D4098997

fbshipit-source-id: e402fd6626e59ccc555513384e93ef0ef891bbf3

7 years agoDon't abort when calling qfind_first_byte_of_sse42 without compiler support for SSE 4.2
Christopher Dykes [Fri, 28 Oct 2016 21:20:34 +0000 (14:20 -0700)]
Don't abort when calling qfind_first_byte_of_sse42 without compiler support for SSE 4.2

Summary:
If Folly was compiled without support for SSE 4.2, but this function ends up getting called, we'd abort due to the check failing.
To solve this, just don't do the check and fall back to the non-sse version.

This is reasonable because it means that the code calling `qfind_first_byte_of_sse42` only needs to care whether there is CPU support for SSE 4.2, not whether we were able to actually implement the search with SSE 4.2 based on compiler support.

Reviewed By: yfeldblum

Differential Revision: D4096645

fbshipit-source-id: d26a791c09f61595e40c84c47a7a2596b9b69c1e

7 years agofolly/experimental/hazptr: mark static local as "library-local"
Andrew Gallagher [Thu, 27 Oct 2016 18:38:46 +0000 (11:38 -0700)]
folly/experimental/hazptr: mark static local as "library-local"

Summary:
When using `-fvisibility-inlines-hidden` or using C/C++ shared libs
transitively from a Python binary, static locals in inline functions
can potentially have more than one definition at runtime.  This diff
explicitly marks this static local as safe for this scenario.

Reviewed By: djwatson

Differential Revision: D4082831

fbshipit-source-id: 75616ac26a39f44691ef59b889ea555e9daa391b

7 years agoAdd default constructor to dynamic, make other constructors simpler and stricter
Giuseppe Ottaviano [Wed, 26 Oct 2016 23:47:00 +0000 (16:47 -0700)]
Add default constructor to dynamic, make other constructors simpler and stricter

Summary:
Now that the initializer list syntax has been removed we can add a default constructor.
Also,
- The `dynamic(T)` constructor was unconstrained, so it would match any type but then fail to compile (as a side effect, `is_convertible<T, dynamic>` would be always true). This also leaked the implementation details of `Array` and `Object`, as they were accepted as arguments. The diff makes the constructor accept only integral and float arguments, and all other types are SFINAEd out.
- `dynamic(Iterator, Iterator)` is made `explicit` to avoid accepting statements like `dynamic d = {"a", "b"};`.
- `object(...)` methods are simplified.

Reviewed By: luciang

Differential Revision: D4065021

fbshipit-source-id: ac289da7bece67c674b7036b7b51d5e016b297e5

7 years agoMove inline functions with static-locals to implementation files
Andrew Gallagher [Wed, 26 Oct 2016 08:24:23 +0000 (01:24 -0700)]
Move inline functions with static-locals to implementation files

Summary:
This refactors inline functions defined in headers which had static locals
so that their definition is moved to the corresponding implementation file.

Reviewed By: yfeldblum

Differential Revision: D4049175

fbshipit-source-id: 56eeb82eb23b04c3b9940d803d05050949aa5ef9

7 years agoSmall rewording in folly Benchmark comment
Matthieu Martin [Tue, 25 Oct 2016 23:50:39 +0000 (16:50 -0700)]
Small rewording in folly Benchmark comment

Summary: A bit more clear

Reviewed By: yfeldblum

Differential Revision: D4075931

fbshipit-source-id: 1398500336d412b5e7663ef1e67b20a329ce2979

7 years agoFix maybe-uninitialized warning in Conv.h
Michael Lee [Tue, 25 Oct 2016 16:45:49 +0000 (09:45 -0700)]
Fix maybe-uninitialized warning in Conv.h

Summary: Some compilers think result may be uninitialized

Reviewed By: francis-ma

Differential Revision: D4074526

fbshipit-source-id: 5df4568cfa5eb8f3b2993a82b831fd5e4028a281

7 years agofix Expected<..., eUnion> move / copy ctor
Philip Pronin [Tue, 25 Oct 2016 06:27:16 +0000 (23:27 -0700)]
fix Expected<..., eUnion> move / copy ctor

Summary:
Consider `Expected<..., eUnion>(Expected&&)` ctor, where
`ExpectedUnion` move ctor would be called first, which is noop leaving
`which_`  uninitialized; then `MoveConstructible` ctor is executed, calling
`assignValue()`, which performs action depending on uninitialized `which_`.

Reviewed By: yfeldblum

Differential Revision: D4073199

fbshipit-source-id: 623660e7047afcebf9f72d83f91f84ff6078090f

7 years agoprevPowTwo / faster bit operations
Ben Maurer [Tue, 25 Oct 2016 03:14:08 +0000 (20:14 -0700)]
prevPowTwo / faster bit operations

Summary:
Add a prevPowTwo method to bits.h and optimize the current code for
GCCs output.

Reviewed By: ot

Differential Revision: D4072341

fbshipit-source-id: 6e949d0bfcf88ff8500022939d08a2b5aa9e00c9

7 years agoNo need for libdwarf, only the header file matters
Tudor Bosman [Tue, 25 Oct 2016 03:04:41 +0000 (20:04 -0700)]
No need for libdwarf, only the header file matters

Summary:
folly/experimental/symbolizer doesn't actually link with libdwarf, it only requires dwarf.h.
Closes https://github.com/facebook/folly/pull/501

Differential Revision: D4068438

Pulled By: djwatson

fbshipit-source-id: 6339eabf8fceac300caafb478c003833768125fd

7 years agoAdd smart pointer types for ec
Subodh Iyengar [Mon, 24 Oct 2016 20:51:50 +0000 (13:51 -0700)]
Add smart pointer types for ec

Summary:
Add smart pointer types for ec groups
and points

Reviewed By: yfeldblum

Differential Revision: D4066848

fbshipit-source-id: f8a5c59cf902584e5a4bea7265834fcc8898677b

7 years agosync README
James Sedgwick [Mon, 24 Oct 2016 17:29:14 +0000 (10:29 -0700)]
sync README

Summary: as above

Reviewed By: yfeldblum

Differential Revision: D4066250

fbshipit-source-id: 7dfe07656dd338ec42fcd966328e46331202bf58

7 years agoadd folly::Function::asSharedProxy v2016.10.24.00
Sven Over [Mon, 24 Oct 2016 05:06:45 +0000 (22:06 -0700)]
add folly::Function::asSharedProxy

Summary:
This diff adds a method to folly::Function that moves the
Function object into a copyable, callable proxy object.

folly::Function already has the asStdFunction method, which
does the same, but wraps the proxy object in a std::function.
When a copyable shared-state proxy of a folly::Function is needed,
it is not necessarily to turn it into a std::function.
If instead the shared proxy will be passed to several functions
taking folly::Function, what happens is the folly::Function
is moved on the heap, a shared_ptr is put into a std::function,
and that is wrapped in a new folly::Function, which always
requires a memory allocation, because std::function is not
noexcept-movable. When using asSharedProxy instead, an
unspecified copyable type is returned that can implicitly
converted into a folly::Function, but without an additional
memory allocation at this point.

Reviewed By: yfeldblum

Differential Revision: D4048621

fbshipit-source-id: b642027b0a6957058fe0089cceeb657ec52e8669

7 years agoRemove dynamic's initializer_list constructor
Giuseppe Ottaviano [Sat, 22 Oct 2016 18:31:19 +0000 (11:31 -0700)]
Remove dynamic's initializer_list constructor

Summary: It has been deprecated for several months, time to nuke it.

Reviewed By: yfeldblum

Differential Revision: D4045250

fbshipit-source-id: 21b55a7c99602c42b1a87ced6a59788fe0ac25d7

7 years agoReverted commit D3927397
Eric Niebler [Thu, 20 Oct 2016 23:57:29 +0000 (16:57 -0700)]
Reverted commit D3927397

Summary: Someone debugged a runtime crash and traced it back to code like: `vector<fbstring>{{"this", "that"}}`. Presumably the user thought they were passing an initializer list of strings to the vector constructor. Instead, they constructed a single fbstring with two char pointers pointing into //different// strings. With the appropriate fbstring constructors, we can flag this as invalid at compile-time.

Reviewed By: yfeldblum

Differential Revision: D3927397

fbshipit-source-id: ab61e1e8498ec99592a2a7726eaf1cb6324f1455

7 years agoimprove documentation of custom singleton creation through an example
Laurent Demailly [Thu, 20 Oct 2016 23:42:56 +0000 (16:42 -0700)]
improve documentation of custom singleton creation through an example

Summary:
improve documentation of custom singleton creation through an example
(from fbcode SIOF thread suggestion)

Reviewed By: yfeldblum

Differential Revision: D4053322

fbshipit-source-id: e9c2ef3d1ef43d52c0bf0a601d94c017047a23a3

7 years agoPrevent erroneous code like vector<fbstring>{{"this", "that"}} from compiling
Eric Niebler [Thu, 20 Oct 2016 22:20:48 +0000 (15:20 -0700)]
Prevent erroneous code like vector<fbstring>{{"this", "that"}} from compiling

Summary: Someone debugged a runtime crash and traced it back to code like: `vector<fbstring>{{"this", "that"}}`. Presumably the user thought they were passing an initializer list of strings to the vector constructor. Instead, they constructed a single fbstring with two char pointers pointing into //different// strings. With the appropriate fbstring constructors, we can flag this as invalid at compile-time.

Reviewed By: yfeldblum

Differential Revision: D3927397

fbshipit-source-id: a5f335073fb55bbb703a23f06874238cbdb5d91a

7 years agofolly/Synchronized.h: avoid shadowing warnings
Jim Meyering [Thu, 20 Oct 2016 16:57:12 +0000 (09:57 -0700)]
folly/Synchronized.h: avoid shadowing warnings

Summary:
Nested uses of SYNCHRONIZED (and related) macros leads
inevitably to shadowed variable declarations.
There is already a use of FOLLY_GCC_DISABLE_WARNING(shadow)
to disable -Wshadow in that code, but obviously, that cannot
help with the new options, so do similar for them via
the new FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS.

Depends on D4041696

Reviewed By: markisaa

Differential Revision: D4041728

fbshipit-source-id: b85fb3452f6855d359f9b910abbd02cf8433f3f7

7 years agoconfigure.ac: check for -Wshadow-local and -Wshadow-compatible-local
Jim Meyering [Thu, 20 Oct 2016 14:50:18 +0000 (07:50 -0700)]
configure.ac: check for -Wshadow-local and -Wshadow-compatible-local

Summary:
Add a configure-time check for whether -Wshadow-local and
-Wshadow-compatible-local are supported.  If so, arrange to
define HAVE_SHADOW_LOCAL_WARNINGS.

In Portability.h, use that new symbol to choose whether
to define FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS, which
used pragmas to disable those new warnings.

Differential Revision: D4041696

fbshipit-source-id: 520ee88ae55147a13d0a045aca7d86567a8da99d

7 years agoadd missing includes
Shubhanshu Agrawal [Thu, 20 Oct 2016 01:24:30 +0000 (18:24 -0700)]
add missing includes

Summary: add missing includes in folly fibers.q

Reviewed By: A5he

Differential Revision: D4036830

fbshipit-source-id: 4dcb87377979f2875ba31b4869c2637a82298957

7 years agoFix ExceptionCounter.oneThread test case
Dmitry Pleshkov [Wed, 19 Oct 2016 22:57:39 +0000 (15:57 -0700)]
Fix ExceptionCounter.oneThread test case

Summary: Test fails because of loop unrolling: frames are not being grouped up

Reviewed By: ot

Differential Revision: D4034910

fbshipit-source-id: 159d3a4f116f90fdd0d51ee9de38634167ed0dc4

7 years agoReverted commit D4035769
Andrii Grynenko [Wed, 19 Oct 2016 18:51:44 +0000 (11:51 -0700)]
Reverted commit D4035769

Summary: This diff adapts the fibers code to the modified `fcontext` API from Boost 1.61

Reviewed By: Orvid

Differential Revision: D4035769

fbshipit-source-id: d3f4b6b03efdd3b6e4b92e0e1c7373747bb74fbb

7 years agofolly/experimental: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 16:00:05 +0000 (09:00 -0700)]
folly/experimental: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Reviewed By: philippv

Differential Revision: D4041749

fbshipit-source-id: 9e0dcec3b35c60e5588a2e53dfdb8605e74721c4

7 years agofolly/test/SynchronizedTestLib-inl.h: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 15:43:59 +0000 (08:43 -0700)]
folly/test/SynchronizedTestLib-inl.h: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Reviewed By: igorsugak

Differential Revision: D4041931

fbshipit-source-id: fcddbc8636c16124a9711c4491a08cc7db76a224

7 years agoAdd capacity to semaphore so that initial size can be queried later.
Lee Howes [Wed, 19 Oct 2016 15:34:20 +0000 (08:34 -0700)]
Add capacity to semaphore so that initial size can be queried later.

Reviewed By: yfeldblum

Differential Revision: D4035412

fbshipit-source-id: 4b7a178088d2950f9f042e0c79b54b3982eb43f5

7 years agofolly/futures/test/NonCopyableLambdaTest.cpp: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 15:09:51 +0000 (08:09 -0700)]
folly/futures/test/NonCopyableLambdaTest.cpp: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Reviewed By: markisaa

Differential Revision: D4041764

fbshipit-source-id: b2aa6543ce4bc36069b010f1107f1ac117073b26

7 years agofolly/futures/test/ViaTest.cpp: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 03:29:34 +0000 (20:29 -0700)]
folly/futures/test/ViaTest.cpp: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Reviewed By: igorsugak

Differential Revision: D4041769

fbshipit-source-id: 257bfe9370279f755b8e965ffc1c37fef454d4c4

7 years agofolly/test/ExceptionWrapperTest.cpp: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 03:29:22 +0000 (20:29 -0700)]
folly/test/ExceptionWrapperTest.cpp: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Reviewed By: igorsugak

Differential Revision: D4041789

fbshipit-source-id: 79eefaccbe2ca27993ab102ac1b6e3caf3bfb7ce

7 years agofolly/test/ThreadCachedIntTest.cpp: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 03:28:45 +0000 (20:28 -0700)]
folly/test/ThreadCachedIntTest.cpp: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Reviewed By: igorsugak

Differential Revision: D4041937

fbshipit-source-id: a9412dae6d1e43931f3b65bffaf462225f667f13

7 years agofolly/test/SpinLockTest.cpp: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 03:28:30 +0000 (20:28 -0700)]
folly/test/SpinLockTest.cpp: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Reviewed By: igorsugak

Differential Revision: D4041919

fbshipit-source-id: 52579a4b7477192ec7145f81216200f81b191183

7 years agofolly/test/SmallLocksTest.cpp: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 03:27:40 +0000 (20:27 -0700)]
folly/test/SmallLocksTest.cpp: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Reviewed By: igorsugak

Differential Revision: D4041910

fbshipit-source-id: d00ea6b294559f80244a226fadf1a3a54c50c78a

7 years agofolly/test/ThreadLocalTest.cpp: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 03:05:57 +0000 (20:05 -0700)]
folly/test/ThreadLocalTest.cpp: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Reviewed By: andrewjcg

Differential Revision: D4041950

fbshipit-source-id: 7c18564273c5839c647709307f56b2fb5e0f6588

7 years agofolly/test/SingletonTest.cpp: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 03:03:27 +0000 (20:03 -0700)]
folly/test/SingletonTest.cpp: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Reviewed By: elsteveogrande

Differential Revision: D4041798

fbshipit-source-id: 9fb6901e791176eb42c31f287655aea6be95a30b

7 years agofolly/fibers/test/FibersTest.cpp: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 03:01:55 +0000 (20:01 -0700)]
folly/fibers/test/FibersTest.cpp: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Differential Revision: D4041756

fbshipit-source-id: 21faf6ad6bf39b0df42e6ef27481d1c81d37ef99

7 years agofolly/futures/test/WhileDoTest.cpp: avoid shadowing warnings
Jim Meyering [Wed, 19 Oct 2016 03:01:00 +0000 (20:01 -0700)]
folly/futures/test/WhileDoTest.cpp: avoid shadowing warnings

Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.

Reviewed By: nisardan

Differential Revision: D4041779

fbshipit-source-id: 375e485a30f01a0610d881fe8b3237cc062aedef

7 years agoCodeMod: dynamic-init-list-ctor
Yedidya Feldblum [Wed, 19 Oct 2016 00:26:55 +0000 (17:26 -0700)]
CodeMod: dynamic-init-list-ctor

Summary:
CodeMod: `dynamic-init-list-ctor`.

The `folly::dynamic::dynamic(std::initializer_list<folly::dynamic>)` constructor is deprecated because its meaning is ambiguous and variable across compilers and compiler versions.

This diff codemods uses of that constructor to use `folly::dynamic::array<...>(...)` instead.

This codemod may not get 100%, but that's okay. Any amount helps.

Reviewed By: ot

Differential Revision: D4013979

fbshipit-source-id: c6873dbc8027b38e71a0f291466ed2d9bd204a53

7 years agofolly: fixes for use with `-fvisibility-inlines-hidden`
Andrew Gallagher [Tue, 18 Oct 2016 22:50:58 +0000 (15:50 -0700)]
folly: fixes for use with `-fvisibility-inlines-hidden`

Summary:
- Annotate non-`const` static locals in inline functions which don't require
  a single copy be used globally at runtime.
- Move implmentation from header file to source file (to avoid multiple
  copies at runtime).
- Mark a non-stateful static local as `const` to it easy to ignore when
  searching for problematic static locals.

Reviewed By: yfeldblum

Differential Revision: D4010101

fbshipit-source-id: 3be94a5dc5b7029a26e11b2145c0d41968979a5c

7 years agoFix for ExceptionWrapperTest
Phil Willoughby [Tue, 18 Oct 2016 22:42:55 +0000 (15:42 -0700)]
Fix for ExceptionWrapperTest

Summary:
Some platforms do not output anything when `std::terminate` is called; this
fixes the test on those platforms.

Reviewed By: yfeldblum, jsedgwick

Differential Revision: D4001052

fbshipit-source-id: 671fbca9d6d22e372189b6554440c268c0cff60b

7 years agoGetting fibers to build with boost 1.61
Marcelo Juchem [Tue, 18 Oct 2016 20:49:17 +0000 (13:49 -0700)]
Getting fibers to build with boost 1.61

Summary: This diff adapts the fibers code to the modified `fcontext` API from Boost 1.61

Reviewed By: Orvid

Differential Revision: D4035769

fbshipit-source-id: 54a97294d33c2901af78b8dec95baaefa085c4f5

7 years agofall back to .debug_info scan in fatal signal handler v2016.10.17.00
Philip Pronin [Sat, 15 Oct 2016 04:44:00 +0000 (21:44 -0700)]
fall back to .debug_info scan in fatal signal handler

Summary:
We've found clang might be generating incomplete `.debug_aranges`,
while falling back to linear `.debug_info` scan is too expensive and shouldn't
be used by default, we can afford doing that in fatal signal handler.

Also optimize `exception_tracer::printExceptionInfo()` to avoid `LocationInfo`
resolution if `NO_FILE_AND_LINE` is used.

Reviewed By: luciang, ot

Differential Revision: D4020989

fbshipit-source-id: 84172208736b224c19206da48bcb3b5c0b2c67d0

7 years agoBacked out changeset 09c1712854b3
Nicholas Ormrod [Fri, 14 Oct 2016 18:32:14 +0000 (11:32 -0700)]
Backed out changeset 09c1712854b3

Summary: Removing COW from fbstring had adverse memory consequences when sync'd with libgcc. Revert this diff to keep folly and libgcc in sync.

Reviewed By: yfeldblum, luciang

Differential Revision: D4019604

fbshipit-source-id: 80bd31c220098bfab37f0effc90f67876432369d

7 years agoBatchDispatcher exception handling
Shubhanshu Agrawal [Fri, 14 Oct 2016 13:43:42 +0000 (06:43 -0700)]
BatchDispatcher exception handling

Summary: error handling for batch dispatcher, for the case where dispatch function throws.

Reviewed By: yfeldblum

Differential Revision: D4016246

fbshipit-source-id: ac61b873a425128be7839a119591fca10608210a

7 years agonoexcept CollectVariadicContext destructor
Matthieu Martin [Fri, 14 Oct 2016 02:43:20 +0000 (19:43 -0700)]
noexcept CollectVariadicContext destructor

Summary: To be explicit about our assumption from D4013691

Reviewed By: andriigrynenko

Differential Revision: D4015816

fbshipit-source-id: 24f984ac9959d0c4c0aeac34b3dce8dfcf2c1354

7 years agoAdd missing include
Csaba Kertesz [Thu, 13 Oct 2016 21:39:07 +0000 (14:39 -0700)]
Add missing include

Summary:
String.h references std::vector, but it is not included.
Closes https://github.com/facebook/folly/pull/496

Reviewed By: yfeldblum, meyering

Differential Revision: D4009410

Pulled By: Orvid

fbshipit-source-id: f21ce0d5833f0959a83e75e2fbcbe2beedbb5b6f

7 years agoAvoid setting OPENSSL_IS_{101,102,110} when using BoringSSL.
Zonr Chang [Thu, 13 Oct 2016 21:07:57 +0000 (14:07 -0700)]
Avoid setting OPENSSL_IS_{101,102,110} when using BoringSSL.

Summary: Closes https://github.com/facebook/folly/pull/497

Reviewed By: anirudhvr

Differential Revision: D4016114

Pulled By: Orvid

fbshipit-source-id: ce9da1e20390a2c834e376a7a06f6002103ff1e4

7 years agofix .debug_aranges parsing
Philip Pronin [Thu, 13 Oct 2016 17:09:36 +0000 (10:09 -0700)]
fix .debug_aranges parsing

Summary:
Each sequence of tuples within an entires set is terminated with (0,
0) according to the DWARF standard (see 7.20 in
http://www.dwarfstd.org/doc/DWARF4.pdf).

Reviewed By: ot, luciang

Differential Revision: D4014952

fbshipit-source-id: c4b034c94adc4a0d9b052456c02919a54a79eaf1

7 years agoProvide a unpackTryTuple function in folly
Matthieu Martin [Thu, 13 Oct 2016 07:09:32 +0000 (00:09 -0700)]
Provide a unpackTryTuple function in folly

Summary: This feature already exists in detail, move it to public instead.

Reviewed By: andriigrynenko

Differential Revision: D4013691

fbshipit-source-id: 1779cc53d114ddc97993b41e0ad63c104008f6b0

7 years agoAdd update-mutex into Observable
Andrii Grynenko [Thu, 13 Oct 2016 01:30:12 +0000 (18:30 -0700)]
Add update-mutex into Observable

Reviewed By: yfeldblum

Differential Revision: D4013256

fbshipit-source-id: 771f9becfa9e7676439209dfbf4a746c110d629d

7 years agoAccess SSL cipher info with a const reference.
Zonr Chang [Wed, 12 Oct 2016 20:16:27 +0000 (13:16 -0700)]
Access SSL cipher info with a const reference.

Summary:
BoringSSL returns `const SSL_CIPHER*` from sk_SSL_CIPHER_value().
Closes https://github.com/facebook/folly/pull/492

Reviewed By: yfeldblum

Differential Revision: D4009712

Pulled By: Orvid

fbshipit-source-id: cca2e8cb6aab0a459dca55b8f23ef57fa5c8251f

7 years agoFix call to SSL_SESSION_up_ref().
Zonr Chang [Wed, 12 Oct 2016 20:14:31 +0000 (13:14 -0700)]
Fix call to SSL_SESSION_up_ref().

Summary:
`SSL_SESSION_up_ref()` in both BoringSSL and OpenSSL 1.1.0 takes a
`SSL_SESSION*`.
Closes https://github.com/facebook/folly/pull/493

Reviewed By: yfeldblum

Differential Revision: D4009706

Pulled By: Orvid

fbshipit-source-id: 68ea201821e7a6d5835a79b34187344ba251e239

7 years agoZSTDCodec should properly handle non-shortcut levels
Philip Pronin [Wed, 12 Oct 2016 17:57:13 +0000 (10:57 -0700)]
ZSTDCodec should properly handle non-shortcut levels

Summary:
Currently only shortcut levels are properly handled, others result in
using level 1.

Reviewed By: yfeldblum

Differential Revision: D4008123

fbshipit-source-id: 37845eeec139007738f99e72ecfb969c6a2e5652

7 years agoPrint why we called std::terminate
Phil Willoughby [Wed, 12 Oct 2016 09:44:45 +0000 (02:44 -0700)]
Print why we called std::terminate

Summary:
When terminating because we were told to rethrow a nonexistent exception, we
now print that to `std::cerr` for the benefit of users on platforms which do not dump a stack trace on
`std::terminate`

Reviewed By: yfeldblum

Differential Revision: D4001087

fbshipit-source-id: 5b834cfc75bf42bec06a49ac9db55789a83df180

7 years agoAdd support in enumerate() for iterators with exotic pointers
Giuseppe Ottaviano [Wed, 12 Oct 2016 04:12:59 +0000 (21:12 -0700)]
Add support in enumerate() for iterators with exotic pointers

Summary: I thought we wouldn't need this but it turns out Thrift Frozen2 iterators return proxies (it's proxies all the way down). Thanks to ericniebler for trick.

Reviewed By: yfeldblum

Differential Revision: D4005700

fbshipit-source-id: 1911996afa075c1d819a3aaea2ee924bc2ae2f20

7 years agoFix build on Mac OSX Sierra
Christopher Dykes [Wed, 12 Oct 2016 00:40:01 +0000 (17:40 -0700)]
Fix build on Mac OSX Sierra

Summary:
There are two changes here.
The first is to eliminate `detail::DEFAULT_CLOCK_ID` from `Benchmark.[cpp|h]` as Sierra defines `clockid_t` as an enum type, which means that calling `clock_gettime(detail::DEFAULT_CLOCK_ID` would fail, because the enums are incompatible. As this was being used as a default, but is not actually changable anywhere, I just got rid of `detail::DEFAULT_CLOCK_ID` entirely.
The second is to move `portability/BitsFunctexcept.cpp` into `libfollybase_la_SOURCES`, because it's needed for generating the fingerprint tables.

Reviewed By: yfeldblum

Differential Revision: D4004843

fbshipit-source-id: b2a9c33f8e516d8eb3cdc5ab093f4946ac9ed37e

7 years agofolly: signal-handler: dynamic cache size, based on number of dynamic-loaded ELF...
Lucian Grijincu [Wed, 12 Oct 2016 00:03:55 +0000 (17:03 -0700)]
folly: signal-handler: dynamic cache size, based on number of dynamic-loaded ELF files

Summary:
I added kFatalSignalHandlerCacheSize in {D3984649}, and chose a big
number to satisfy most use-cases. But the size increase is non-trivial.

Memory usage:

- before: 5.1 MB in folly::symbolizer::SignalSafeElfCache::SignalSafeElfCache
- after: 80.0 MB in folly::symbolizer::SignalSafeElfCache::SignalSafeElfCache

Switch to a dynamic approach and everyone pays for what they use.

https://github.com/bminor/glibc/blob/ee19f1de0d0da24114be554fdf94243c0ec6b86c/elf/rtld-debugger-interface.txt#L10-L20
```
The r_debug structure contains (amongst others) the following fields:

  struct link_map *r_map:
    A linked list of loaded objects.

  enum { RT_CONSISTENT, RT_ADD, RT_DELETE } r_state:
    The current state of the r_map list.  RT_CONSISTENT means that r_map
    is not currently being modified and may safely be inspected.  RT_ADD
    means that an object is being added to r_map, and that the list is
    not guaranteed to be consistent.  Likewise RT_DELETE means that an
    object is being removed from the list.
```

https://github.com/bminor/glibc/blob/ee19f1de0d0da24114be554fdf94243c0ec6b86c/elf/rtld.c#L303-L307
```
  /* Call the OS-dependent function to set up life so we can do things like
     file access.  It will call `dl_main' (below) to do all the real work
     of the dynamic linker, and then unwind our frame and run the user
     entry point on the same stack we entered on.  */
  start_addr = _dl_sysdep_start (arg, &dl_main);
```

dl_main: https://github.com/bminor/glibc/blob/ee19f1de0d0da24114be554fdf94243c0ec6b86c/elf/rtld.c#L1192-L1199
```
  /* Initialize the data structures for the search paths for shared
     objects.  */
  _dl_init_paths (library_path);

  /* Initialize _r_debug.  */
  struct r_debug *r = _dl_debug_initialize (GL(dl_rtld_map).l_addr,
    LM_ID_BASE);
  r->r_state = RT_CONSISTENT;
...

  /* We start adding objects.  */
  r->r_state = RT_ADD;
  _dl_debug_state ();
  LIBC_PROBE (init_start, 2, LM_ID_BASE, r);

...

  /* Notify the debugger all new objects are now ready to go.  We must re-get
     the address since by now the variable might be in another object.  */
  r = _dl_debug_initialize (0, LM_ID_BASE);
  r->r_state = RT_CONSISTENT;
  _dl_debug_state ();
  LIBC_PROBE (init_complete, 2, LM_ID_BASE, r);

```

Reviewed By: bixue2010

Differential Revision: D3996974

fbshipit-source-id: e24d72e3cc0339e4cf1acdd2f4c9a7ebfcfdf739

7 years agofolly/ConcurrentSkipList.h: avoid shadowing warnings (trivial)
Jim Meyering [Tue, 11 Oct 2016 18:25:41 +0000 (11:25 -0700)]
folly/ConcurrentSkipList.h: avoid shadowing warnings (trivial)

Summary:
Compiling with gcc's proposed -Wshadow-compatible-local option
exposed some fix-worthy warnings. Rename to avoid the shadowing.

Reviewed By: evilmucedin

Differential Revision: D3999026

fbshipit-source-id: 26cb3033ba8c5538cc9217993f2fda6aef954a8f

7 years agoBatchDispatcher add() interface
Shubhanshu Agrawal [Tue, 11 Oct 2016 15:02:40 +0000 (08:02 -0700)]
BatchDispatcher add() interface

Summary: converting add(value&&) to add(value) to make it easier for callsites to use.

Reviewed By: A5he

Differential Revision: D4000416

fbshipit-source-id: c66f4d93d1223286bbc786d17f65ed02a63cc794

7 years agoDisabling failing test for fbandroid
Louis Boval [Tue, 11 Oct 2016 05:11:03 +0000 (22:11 -0700)]
Disabling failing test for fbandroid

Summary: this particular test fails reliably for fbandroid. Modifying the code in fbcode, assuming it will be synced promptly.

Reviewed By: edelron

Differential Revision: D4000722

fbshipit-source-id: fca5e691ea5c972ddd245acee1c17720730539d4

7 years agoRemove memcpy-UB in fbstring
Nicholas Ormrod [Mon, 10 Oct 2016 22:45:25 +0000 (15:45 -0700)]
Remove memcpy-UB in fbstring

Summary:
The bug report in t13764686 shows that `folly::StringPiece().str()` causes undefined behavior by passing nullptr into memcpy: the default-initialized StringPiece has two null pointers, which will call `string(char*, size)` with nullptr and 0. This gets forwarded to `podCopy` in fbstring, which calls memcpy and has undefined behavior.

The call pattern `string(nullptr, 0)` is not illegal (note: that syntax is ambiguous, as the literal `0` can be converted to a pointer). Prevent this legal call pattern from causing undefined behavior in fbstring.

This diff puts asserts in podCopy to catch errors, and ensures that current podCopy callsites ensure that the pointer is non-null.

Most podCopy callsites do not need to guarded, since the size is guaranteed to be greater than 0 (which will hard crash instead). The interesting callsite is in `initMedium`, because there is a mode (disableSSO) which will allocate empty strings on the heap, so we need to add a guard there.

Reviewed By: luciang

Differential Revision: D3996440

fbshipit-source-id: b311a311973d1d969542245c72035c5b38da58e3

7 years agoUpdate hazard pointers prototype
Maged Michael [Mon, 10 Oct 2016 13:43:52 +0000 (06:43 -0700)]
Update hazard pointers prototype

Summary:
Interface:
- Got rid of std::function reclamation functions and added a Deleter template parameter.
- Got rid of the flush() member functions of hazptr_domain
- Added a lock-free non-bool member function to get a protected pointer.
Implementation:
- Implemented the interface changes.
- Changed the order of accesses in reading the shared list of objects vs reading the hazard pointers. I think the previous order would have allowed recently protected objects to be reclaimed incorrectly.
Updated the examples and tests accordingly.

Reviewed By: davidtgoldblatt

Differential Revision: D3981284

fbshipit-source-id: 35ff60da3aea1f67c58d82437dda58f6d8b07bf5

7 years agoMake exception_wrapper::throwException() strict
Phil Willoughby [Mon, 10 Oct 2016 10:55:14 +0000 (03:55 -0700)]
Make exception_wrapper::throwException() strict

Summary:
The definition of `throwException()` is changed to add the `[[noreturn]]`
attribute for consistency with `std::rethrow_exception`. If the
`exception_wrapper` contains an exception, that is rethrown; if not, then
`std::terminate` is called.

An alternative design which threw an exception if the `exception_wrapper` did not contain an exception was rejected because of the ambiguity it introduced as to whether the exception thrown was wrapped or not.

Benchmarks before:

```

============================================================================
folly/test/ExceptionWrapperBenchmark.cpp        relative  time/iter  iters/s
============================================================================
exception_ptr_create_and_test                                1.45us  689.01K
exception_wrapper_create_and_test               4337.80%    33.46ns   29.89M
----------------------------------------------------------------------------
exception_ptr_create_and_test_concurrent                   342.99us    2.92K
exception_wrapper_create_and_test_concurrent     101.41%   338.21us    2.96K
----------------------------------------------------------------------------
exception_ptr_create_and_throw                               3.05us  327.89K
exception_wrapper_create_and_throw               140.22%     2.17us  459.77K
exception_wrapper_create_and_cast               8956.80%    34.05ns   29.37M
----------------------------------------------------------------------------
exception_ptr_create_and_throw_concurrent                  372.68us    2.68K
exception_wrapper_create_and_throw_concurrent    102.54%   363.44us    2.75K
exception_wrapper_create_and_cast_concurrent     110.93%   335.97us    2.98K
============================================================================
```

and after:

```

============================================================================
folly/test/ExceptionWrapperBenchmark.cpp        relative  time/iter  iters/s
============================================================================
exception_ptr_create_and_test                                1.46us  684.09K
exception_wrapper_create_and_test               4368.84%    33.46ns   29.89M
----------------------------------------------------------------------------
exception_ptr_create_and_test_concurrent                   341.20us    2.93K
exception_wrapper_create_and_test_concurrent      99.88%   341.60us    2.93K
----------------------------------------------------------------------------
exception_ptr_create_and_throw                               3.08us  324.93K
exception_wrapper_create_and_throw               106.93%     2.88us  347.46K
exception_wrapper_create_and_cast               9532.05%    32.29ns   30.97M
----------------------------------------------------------------------------
exception_ptr_create_and_throw_concurrent                  363.73us    2.75K
exception_wrapper_create_and_throw_concurrent    101.04%   360.00us    2.78K
exception_wrapper_create_and_cast_concurrent     104.50%   348.07us    2.87K
============================================================================
```

Reviewed By: yfeldblum

Differential Revision: D3923939

fbshipit-source-id: 6fc58ac571e59e4122f1fbd194c678e3a3841057

7 years agofolly/Foreach.h: allow FOR_EACH to be nested with no shadowing v2016.10.10.00
Jim Meyering [Sun, 9 Oct 2016 21:53:30 +0000 (14:53 -0700)]
folly/Foreach.h: allow FOR_EACH to be nested with no shadowing

Summary:
Prior to this change, any nested use of FOR_EACH would
induce a shadowed declaration for each of the two local
state variables it declares.

This makes the names of those variables __LINE__-dependent,
so that there is no shadowing, as long as each nested use
is on a different line.

This also adds a new test that (prior to this change) would fail to
compile with an option like -Werror=shadow-compatible-local.

Since this change relies on cpp token concatenation, I have included
The fix defines a new helper macro, _FE_ANON, to derive each new variable
name. I wondered whether to do this for every other FOR_* macro here, but
since so far, I have encountered more than 10 cases of nested FOR_EACH
uses in a large corpus, but no nesting of any other FOR_* macro, I am
content to do it only for this one.

Reviewed By: yfeldblum

Differential Revision: D3992956

fbshipit-source-id: f26fba89bc661bb9d22747dec0acdcf8c648fb83

7 years agofolly/io/async/HHWheelTimer.cpp: remove decl of unused variable (trivial)
Jim Meyering [Sat, 8 Oct 2016 15:39:18 +0000 (08:39 -0700)]
folly/io/async/HHWheelTimer.cpp: remove decl of unused variable (trivial)

Summary:
In HHWheelTimer::scheduleTimeout, remove the declaration of the
unused variable, "prev".

Reviewed By: yfeldblum

Differential Revision: D3987409

fbshipit-source-id: 3a9291bf104e6865d608adfb6118609faa0aea96

7 years agoLimit maximum number of iterations in folly::Benchmark with bm_max_iters
Yinghai Lu [Sat, 8 Oct 2016 01:38:14 +0000 (18:38 -0700)]
Limit maximum number of iterations in folly::Benchmark with bm_max_iters

Summary:
We are using `bm_max_iters` in folly and other part of the code in fbcode but it didn't really exist in Benchmark.cpp. For example: https://github.com/facebook/folly/blob/master/folly/test/function_benchmark/main.cpp#L29

This patch adds back this functionality.

This diff depends on D3990600.

Reviewed By: yfeldblum

Differential Revision: D3989499

fbshipit-source-id: d2303b2bebb196e84a592d54a72af68171971491

7 years agoClang-format the flag declarations in Benchmark.cpp
Yinghai Lu [Sat, 8 Oct 2016 01:38:12 +0000 (18:38 -0700)]
Clang-format the flag declarations in Benchmark.cpp

Summary: This patch prepares the later diff which will add a new flag. Just make things nice.

Reviewed By: igorsugak

Differential Revision: D3990600

fbshipit-source-id: d4f53a5b44708ca025e4f6615d161b24de685931

7 years agoDisallow COW in FBString
Nicholas Ormrod [Fri, 7 Oct 2016 20:05:44 +0000 (13:05 -0700)]
Disallow COW in FBString

Summary:
Remove all code that create large strings.

This diff does not remove code that deals with large strings, so that the transition to libgcc will be smoother. Note that the FBSTRING_ASSERT inside of setCapacity will be disabled in the libgcc build.

Reviewed By: luciang, ot

Differential Revision: D3977459

fbshipit-source-id: 09c1712854b31509138c5cc8baf19caf3c715bb6

7 years agofolly: symbolizer: increase default signal-handler symbolizer elf file cache size...
Lucian Grijincu [Fri, 7 Oct 2016 19:58:50 +0000 (12:58 -0700)]
folly: symbolizer: increase default signal-handler symbolizer elf file cache size (make it work with large number of .so)

Summary:
Bump the default size so we can symbolize symbols in dynamically linked
binaries with lots and lots of shared libraries :)

folly/experimental/symbolizer/ElfCache.h
```
  * Will not grow; once the capacity is reached, lookups for files that
  * aren't already in the cache will fail (return nullptr).
  class SignalSafeElfCache
```

Reviewed By: ot, philippv

Differential Revision: D3984649

fbshipit-source-id: acdca9b9adf6c16f3a1556bc3f57b28844cdd9cc

7 years agoFunctionScheduler - return whether shutdown was successful
Mirek Klimos [Fri, 7 Oct 2016 18:18:57 +0000 (11:18 -0700)]
FunctionScheduler - return whether shutdown was successful

Summary: We want to fail fast if we attempt to stop a scheduler that was not running

Reviewed By: yfeldblum

Differential Revision: D3976919

fbshipit-source-id: d8aa8b35aa9e22758e6a7ef64f48a7dd6d990b1c

7 years agoReverted commit D3979179
Alex Yarmula [Thu, 6 Oct 2016 15:51:33 +0000 (08:51 -0700)]
Reverted commit D3979179

Summary:
When `delayed` is called on the Future, the underlying `futures::sleep` call runs on a timer thread, and the resulting callback is called on the same thread. Therefore, in the following sequence:

  f.via(&someExecutor).within(one_ms).then([&]() { /* [1] */ })

The code in [1] is not running in someExecutor. This can cause confusion by users of the library who expect the initial `via` to be sticky.

This change returns to the prior `Executor` after `delayed` is finished.

Reviewed By: yfeldblum

Differential Revision: D3979179

fbshipit-source-id: e1448f5603f0c9440490ae3bf0e670687f4179f3

7 years agofolly/io: avoid shadowing warnings
Jim Meyering [Thu, 6 Oct 2016 15:07:29 +0000 (08:07 -0700)]
folly/io: avoid shadowing warnings

Summary: Fix shadowing warnings.

Reviewed By: russoue

Differential Revision: D3979165

fbshipit-source-id: 19a3940e210e4d5a698dbc0e6d74b317a74a94fa