folly.git
9 years agoPrevent accidental moves in filter()
Tom Jackson [Tue, 18 Aug 2015 19:52:16 +0000 (12:52 -0700)]
Prevent accidental moves in filter()

Summary: Per Boris's report.

Reviewed By: @yfeldblum

Differential Revision: D2357299

9 years agoAdjust Format-inl.h to work with MSVC
Orvid King [Tue, 18 Aug 2015 18:53:33 +0000 (11:53 -0700)]
Adjust Format-inl.h to work with MSVC

Summary: Originally #247, which was closed before being merged, this doesn't change the behavior of the formatting function now.
Closes #297

Reviewed By: @yfeldblum

Differential Revision: D2340712

Pulled By: @sgolemon

9 years agoEnvVarSaver.
Yedidya Feldblum [Tue, 18 Aug 2015 09:09:11 +0000 (02:09 -0700)]
EnvVarSaver.

Summary: [Folly] EnvVarSaver.

    TEST(SomeBigClassTest, ChangesEnvVars) {
      folly::EnvVarSaver saver;
      setenv("USER", "root", 1);
      BigClass().doSomethingWithUser();
    }

Reviewed By: @Gownta

Differential Revision: D2354679

9 years agoRefactor HandshakeHelper and add a peeking handshake helper
Subodh Iyengar [Tue, 18 Aug 2015 04:28:08 +0000 (21:28 -0700)]
Refactor HandshakeHelper and add a peeking handshake helper

Summary: This adds support to Acceptor to be able to switch between
multiple protcols when SSL is being negotiated using MSG_PEEK.

The motivation for this is to be able to try out multiple protocols.

Reviewed By: @djwatson

Differential Revision: D2327946

9 years agoBump version to 54:0 v0.54.0
Sara Golemon [Mon, 17 Aug 2015 19:36:48 +0000 (12:36 -0700)]
Bump version to 54:0

9 years agoLimit use of hardware crc32 check to SSE 4.2
Daniel M. Weeks [Mon, 17 Aug 2015 17:40:12 +0000 (10:40 -0700)]
Limit use of hardware crc32 check to SSE 4.2

Summary: Fixes compiling crc32c function on older hardware. (I believe this problem was introduced by 7ec1fc0e0e27ed56c1d18d33af9711a17e9ec750).

Also ensures is in final library since the API suggests it should be. This should correct a number of build problems for other projects like wdt and hhvm when they are compiled using a shared folly library rather than borrowing sources at compile time.
Closes #296

Reviewed By: @yfeldblum

Differential Revision: D2340699

Pulled By: @sgolemon

9 years agoRemove `unsigned char v = static_cast<unsigned char>(v);`
Orvid King [Mon, 17 Aug 2015 17:37:08 +0000 (10:37 -0700)]
Remove `unsigned char v = static_cast<unsigned char>(v);`

Summary: MSVC spotted this very suspicious line when I was running it with /analyze, and complained about using an unitialized variable. This variable isn't used anywhere in the function, and is initializing itself with itself. I have no idea how this compiled in the first place, but apparently it does.
This removes the line in question.
Closes #295

Reviewed By: @yfeldblum, @paulbiss

Differential Revision: D2340688

Pulled By: @sgolemon

9 years agoImplement Random.cpp for MSVC
Orvid King [Mon, 17 Aug 2015 17:32:51 +0000 (10:32 -0700)]
Implement Random.cpp for MSVC

Summary: This uses `<random>` to implement it, because there is no `/dev/urandom` on Windows.
Closes #250

Reviewed By: @yfeldblum

Differential Revision: D2282887

Pulled By: @sgolemon

9 years agoExtract folly/io/async/test/RequestContextTest.cpp (from Thrift).
Yedidya Feldblum [Mon, 17 Aug 2015 07:51:43 +0000 (00:51 -0700)]
Extract folly/io/async/test/RequestContextTest.cpp (from Thrift).

Summary: [Folly] Extract folly/io/async/test/RequestContextTest.cpp (from Thrift).

Reviewed By: @haijunz

Differential Revision: D2350908

9 years agoMore descriptive message when we fail with a "Double registration of singleton" error
Dhruv Matani [Sat, 15 Aug 2015 15:37:23 +0000 (08:37 -0700)]
More descriptive message when we fail with a "Double registration of singleton" error

Summary: When we FATAL with a "Double registration of singleton" error, make it abundantly clear why such a thing could have happended so that the developer doesn't feel lost.

Reviewed By: @chipturner

Differential Revision: D2345728

9 years agoAllow AysncUDPSocket to work without SO_REUSEADDR flag
Naizhi Li [Fri, 14 Aug 2015 20:16:53 +0000 (13:16 -0700)]
Allow AysncUDPSocket to work without SO_REUSEADDR flag

Summary: Today it's hardcoded to use the flag, which could result
in some problem. We should allow callers to choose.

Reviewed By: @djwatson

Differential Revision: D2345036

9 years agoRemove dep on boost_thread
Dave Watson [Fri, 14 Aug 2015 18:56:32 +0000 (11:56 -0700)]
Remove dep on boost_thread

Summary: Remove recently introduced dependency on boost_thread by breaking EventBaseLocal off to its own rule

Introduced in D2203063

Reviewed By: @​mzlee

Differential Revision: D2301943

9 years agoFix AtomicHashArray::defaultConfig SIOF.
Yedidya Feldblum [Fri, 14 Aug 2015 08:57:38 +0000 (01:57 -0700)]
Fix AtomicHashArray::defaultConfig SIOF.

Summary: [Folly] Fix AtomicHashArray::defaultConfig SIOF.

May fix https://github.com/facebook/folly/issues/300.

Reviewed By: @paulbiss

Differential Revision: D2343162

9 years agoSet IPV6_V6ONLY in folly::AsyncUDPServerSocket
Peter Griess [Thu, 13 Aug 2015 17:19:09 +0000 (10:19 -0700)]
Set IPV6_V6ONLY in folly::AsyncUDPServerSocket

Summary: - This mirrors the behavior in AsyncServerSocket

Reviewed By: @yfeldblum

Differential Revision: D2338665

9 years agoDetect clang in folly/Portability.h
Yang Chi [Thu, 13 Aug 2015 14:58:03 +0000 (07:58 -0700)]
Detect clang in folly/Portability.h

Summary: The fix in D2283221 was specific to a bug in gcc 4.8 but the macro was failing
to filter out clang compilers.

Reviewed By: @yfeldblum

Differential Revision: D2340160

9 years agoDon't warn if pthread_atfork isn't avaliable on MSVC
Orvid King [Wed, 12 Aug 2015 20:40:33 +0000 (13:40 -0700)]
Don't warn if pthread_atfork isn't avaliable on MSVC

Summary: Because we don't even have `fork` to begin with under MSVC.
Closes #278

Reviewed By: @yfeldblum

Differential Revision: D2306518

Pulled By: @sgolemon

9 years agoAdd MSVC support to MaxAlign
Orvid King [Wed, 12 Aug 2015 20:39:29 +0000 (13:39 -0700)]
Add MSVC support to MaxAlign

Summary: This adds MSVC support to the detection of `MaxAlign` in `Portability.h`.
Closes #256

Reviewed By: @yfeldblum

Differential Revision: D2283221

Pulled By: @sgolemon

9 years agoHandle some scoping issues in Conv.h under MSVC
Orvid King [Wed, 12 Aug 2015 20:37:02 +0000 (13:37 -0700)]
Handle some scoping issues in Conv.h under MSVC

Summary: No idea why these are the only two places it complains about, but it does.
This just explicitly scopes them.
Closes #253

Reviewed By: @yfeldblum

Differential Revision: D2282985

Pulled By: @sgolemon

9 years agoCodeMod apache::thrift::transport::TSocketAddress to folly::SocketAddress.
Yedidya Feldblum [Wed, 12 Aug 2015 20:29:16 +0000 (13:29 -0700)]
CodeMod apache::thrift::transport::TSocketAddress to folly::SocketAddress.

Summary: [Folly] CodeMod apache::thrift::transport::TSocketAddress to folly::SocketAddress.

    yes | codemod --extensions h,tcc,cpp '^#include [<"]thrift/lib/cpp/transport/TSocketAddress\.h[>"]$' '#include <folly/SocketAddress.h>'
    yes | codemod --extensions h,tcc '\b(((apache::)?thrift::)?transport::)?TSocketAddress\b' 'folly::SocketAddress'
    yes | codemod --extensions cpp '^using apache::thrift::transport::TSocketAddress;$' 'using folly::SocketAddress;'
    yes | codemod --file-list "$(git ls-files "**/*.cpp" | xargs grep -P '^using (namespace folly|folly::SocketAddress);$' | cut -d: -f1 | paste -s -d,)" '\b(((apache::)?thrift::)?transport::)?TSocketAddress\b' 'SocketAddress'
    yes | codemod --extensions cpp '\b(((apache::)?thrift::)?transport::)?TSocketAddress\b' 'folly::SocketAddress'
    yes | codemod --extensions h,tcc,cpp -m '^\s*typedef folly::SocketAddress folly::SocketAddress;\n' ''
    yes | codemod --file-list thrift/lib/cpp/Makefile.am -m '^\s*transport/TSocketAddress\.h \\\n' ''
    rm thrift/lib/cpp/transport/TSocketAddress.h

Reviewed By: @Invalid auth token., @​luk

Differential Revision: D2325523

9 years agoDisable VDSO on MSVC
Orvid King [Wed, 12 Aug 2015 20:12:46 +0000 (13:12 -0700)]
Disable VDSO on MSVC

Summary: MSVC will never be able to load VDSO, and doesn't even have dlopen, so just return `nullptr`, and let the fallback mechanisms handle it from there.
Closes #282

Reviewed By: @yfeldblum

Differential Revision: D2307461

Pulled By: @sgolemon

9 years ago(Wangle) Use perfect forwarding for LambdaBufHelper
Hannes Roth [Tue, 11 Aug 2015 23:11:59 +0000 (16:11 -0700)]
(Wangle) Use perfect forwarding for LambdaBufHelper

Summary: Perfect forwarding only works if the function is templated on the same type, not if the type is a class template.

Discovered by @lbrandy.

Reviewed By: @yfeldblum, @lbrandy

Differential Revision: D2333005

9 years ago(Wangle) Align lambdaBuf_
Hannes Roth [Tue, 11 Aug 2015 23:11:11 +0000 (16:11 -0700)]
(Wangle) Align lambdaBuf_

Summary: Not aligning `lambdaBuf_` can lead to unaligned reads, which can be a problem on some platforms.

We use `lambdaBuf_` to store a type of up to `lambdaBufSize`, so aligning it to that should always be safe.

Reviewed By: @alexshap

Differential Revision: D2319347

9 years agoEmplacement in folly::padded::Adaptor, if the adapted class allows.
Yedidya Feldblum [Tue, 11 Aug 2015 18:47:39 +0000 (11:47 -0700)]
Emplacement in folly::padded::Adaptor, if the adapted class allows.

Summary: [Folly] Emplacement in folly::padded::Adaptor, if the adapted class allows.

Reviewed By: @Gownta

Differential Revision: D2157162

9 years agoAdded futures helpers times, when, and whileDo
Noel Sardana [Tue, 11 Aug 2015 18:13:29 +0000 (11:13 -0700)]
Added futures helpers times, when, and whileDo

Summary: Implemented the given functions by porting similar functionality from the twitter Future utility.

Reviewed By: @​hannesr

Differential Revision: D2303701

9 years agoBump version to 53:0 v0.53.0
Sara Golemon [Mon, 10 Aug 2015 20:18:38 +0000 (13:18 -0700)]
Bump version to 53:0

9 years agoSupport dynamic field width in folly::format()
Brett Simmers [Sun, 9 Aug 2015 22:41:15 +0000 (15:41 -0700)]
Support dynamic field width in folly::format()

Summary: I added this to support logging with varying indentation levels, but
it could also be useful in other situations. Examples are in the
test/documentation.

Reviewed By: @tudor

Differential Revision: D2322206

9 years agoAvoid incorrect constexpr in folly/AtomicHashArray.h.
Yedidya Feldblum [Fri, 7 Aug 2015 19:34:34 +0000 (12:34 -0700)]
Avoid incorrect constexpr in folly/AtomicHashArray.h.

Summary: [Folly] Avoid incorrect constexpr in folly/AtomicHashArray.h.

It's actually not transitively constexpr, because it uses const values that are not themselves constexpr. Depending on the compiler, it could theoretically fail to build.

Reviewed By: @Gownta

Differential Revision: D2322143

9 years agoEasy: disable guard pages by default
Anton Likhtarov [Thu, 6 Aug 2015 22:24:56 +0000 (15:24 -0700)]
Easy: disable guard pages by default

Summary: Mcrouter still enables these by default.  Tracking down a perf regression in another code path that uses fibers.

Reviewed By: @JohnRambo

Differential Revision: D2320772

9 years agoMake Core.size test portable
Alexander Shaposhnikov [Thu, 6 Aug 2015 02:25:51 +0000 (19:25 -0700)]
Make Core.size test portable

Summary: Add a golden struct for checking the size of Core.
It makes this test pass on OSX
(now failing because of the different size of std::function).

Reviewed By: @​hannesr

Differential Revision: D2315429

9 years agoScopedEventBaseThread should support an EventBaseManager context.
Yedidya Feldblum [Wed, 5 Aug 2015 21:44:14 +0000 (14:44 -0700)]
ScopedEventBaseThread should support an EventBaseManager context.

Summary: [Folly] ScopedEventBaseThread should support an EventBaseManager context.

Reviewed By: @Gownta

Differential Revision: D2314049

9 years agoUse static const keys in AtomicHashArray::Config.
Yedidya Feldblum [Wed, 5 Aug 2015 18:48:13 +0000 (11:48 -0700)]
Use static const keys in AtomicHashArray::Config.

Summary: [Folly] Use static const keys in AtomicHashArray::Config.

From https://github.com/facebook/folly/pull/264/, MSVC may have a hard time with certain expressions. D2284130 factored them out as `static constexpr` members, but Clang had a hard time with that in HPHP. This adds a test case that triggers the same failure to the Folly build. Not quite sure how this impacts MSVC though.

Reviewed By: @Gownta

Differential Revision: D2304346

9 years agoUse .string() not .native() in TestUtil.cpp
Orvid King [Tue, 4 Aug 2015 23:02:44 +0000 (16:02 -0700)]
Use .string() not .native() in TestUtil.cpp

Summary: Because `.native()` returns a wide string on MSVC, but a normal string is expected by the rest of the code.
Closes #283

Reviewed By: @yfeldblum

Differential Revision: D2307488

Pulled By: @sgolemon

9 years agoMake some types and constexprs public
Orvid King [Tue, 4 Aug 2015 23:01:48 +0000 (16:01 -0700)]
Make some types and constexprs public

Summary: MSVC has some odd accessibility rules,
so this makes a couple of things public rather than private.
Closes #284

Reviewed By: @yfeldblum

Differential Revision: D2307578

Pulled By: @sgolemon

9 years agomake RetryingTest more robust
Nathan Bronson [Tue, 4 Aug 2015 21:02:33 +0000 (14:02 -0700)]
make RetryingTest more robust

Summary: Make RetryingTest more robust by giving it multiple chances to
meeting timing criteria.

Reviewed By: @yfeldblum

Differential Revision: D2306245

9 years agoRefactor extract FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEX.
Yedidya Feldblum [Tue, 4 Aug 2015 16:54:07 +0000 (09:54 -0700)]
Refactor extract FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEX.

Summary: [Folly] Refactor extract FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEX.

The same complex check is done in two places. Ick. Extract it to a single place.

Reviewed By: @​mzlee

Differential Revision: D2302885

9 years agoFix a bad bug in folly::ThreadLocal (incorrect using of pthread)
Alexander Shaposhnikov [Tue, 4 Aug 2015 06:24:18 +0000 (23:24 -0700)]
Fix a bad bug in folly::ThreadLocal (incorrect using of pthread)

Summary: Fix incorrect using of pthread in folly::ThreadLocal.

The root of the trouble (see man pthread_key_create):
"At thread exit, if a key value has a non-NULL destructor pointer,
and the thread has a non-NULL value associated with that key,
the value of the key is set to NULL, and then the function pointed to is called
with the previously associated value as its sole argument."

At thread exit we need to recover the thread-specific threadEntry
otherwise the subsequent calls of getThreadEntry may recreate it
(what actually DOES  happen in the test ThreadLocalPtr.CreateOnThreadExit)
and the newly created threadEntry will "leak". It will live longer than the corresponding
thread violating the internal invariant of StaticMeta and also it will break
the code of the method onThreadExit. In particular this bug causes the failure
of the test ThreadLocalPtr.CreateOnThreadExit on OSX.

Reviewed By: @lbrandy

Differential Revision: D2304950

9 years agoAdd MSVC support to futures/Deprecated.h
Orvid King [Mon, 3 Aug 2015 19:36:24 +0000 (12:36 -0700)]
Add MSVC support to futures/Deprecated.h

Summary: It was originally unconditionally useing `__attribute__` syntax, so this makes it conditionally use the `__declspec` syntax.
Closes #268

Reviewed By: @yfeldblum

Differential Revision: D2283909

Pulled By: @sgolemon

9 years agoFix ASAN failure in folly/io/async/test/NotificationQueueTest.cpp.
Yedidya Feldblum [Sun, 2 Aug 2015 23:15:04 +0000 (16:15 -0700)]
Fix ASAN failure in folly/io/async/test/NotificationQueueTest.cpp.

Summary: [Folly] Fix ASAN failure in folly/io/async/test/NotificationQueueTest.cpp.

Reviewed By: @djwatson

Differential Revision: D2299112

9 years agoRevert "Use constexpr initializers for AtomicHashArray Config"
Brett Simmers [Sat, 1 Aug 2015 20:39:19 +0000 (13:39 -0700)]
Revert "Use constexpr initializers for AtomicHashArray Config"

Summary: D2284130 broke the HHVM clang build.

Reviewed By: @mxw

Differential Revision: D2303914

9 years agoNot to use EventBaseLocal on mobile
Michael Lee [Fri, 31 Jul 2015 22:51:59 +0000 (15:51 -0700)]
Not to use EventBaseLocal on mobile

Summary: Temp remove EventBaseLocal on mobile.

Reviewed By: @djwatson

Differential Revision: D2302322

9 years agoNo std::recursive_timed_mutex and std::timed_mutex.
Michael Lee [Fri, 31 Jul 2015 21:06:17 +0000 (14:06 -0700)]
No std::recursive_timed_mutex and std::timed_mutex.

Summary: Do not use these if __ANDROID__ is defined as well.

Reviewed By: @​yangchi

Differential Revision: D2301782

9 years agoFix a parse error in detail/ThreadLocalDetail.h under MSVC
Orvid King [Mon, 27 Jul 2015 21:41:06 +0000 (14:41 -0700)]
Fix a parse error in detail/ThreadLocalDetail.h under MSVC

Summary: I have no idea why this specific declaration would error, or if there is a difference in meaning, but this fixes MSVC's absurd parser error.
Closes #277

Reviewed By: @yfeldblum

Differential Revision: D2284096

9 years agoGeneralize FOLLY_SPIN_WAIT to use Portability methods
Orvid King [Fri, 31 Jul 2015 19:43:41 +0000 (12:43 -0700)]
Generalize FOLLY_SPIN_WAIT to use Portability methods

Summary: Improves MSVC support.
Closes #274

Note that this diff has been heavily modified from @Orvid's original PR by @yfeldblum and @sgolemon

Reviewed By: @yfeldblum

Differential Revision: D2284035

Pulled By: @sgolemon

9 years agoUse constexpr initializers for AtomicHashArray Config
Orvid King [Fri, 31 Jul 2015 19:40:07 +0000 (12:40 -0700)]
Use constexpr initializers for AtomicHashArray Config

Summary: Closes #264

Modified by @sgolemon from the original PR to declare MSVC2015-final as the official minimum version, making the defines in the original PR unnecessary.

Reviewed By: @yfeldblum

Differential Revision: D2284130

Pulled By: @sgolemon

9 years agoOverload on dynamic object reference type.
Nick Terrell [Fri, 31 Jul 2015 16:57:00 +0000 (09:57 -0700)]
Overload on dynamic object reference type.

Summary: There are a bunch of methods in `folly::dynamic` that return a
reference to a sub-object, e.g. `getString()`.
These methods are a bit unsafe because it allows you to write code with dangling
references when the `folly::dynamic` object is an rvalue:

  auto& obj = parse_json(some_string).at("key");

However, the bigger win is that when we have an rvalue `folly::dynamic`, such as
returned by `getDefault(...)`, we can move the sub-object out:

  auto obj = parse_json(some_string).at("key");
  auto str = obj.getDefault("another-key", "").getString();

In the first line, the subobject is copied out when it could be safely moved out.
In the second line `getDefault(...)` copies the dynamic sub-object out, and then
`getString()` copies the string out, when the string could be moved.

Also in the case of `getDefault()` being called on a rvalue, we can move the
sub-object out.

Reviewed By: @marcinpe

Differential Revision: D2267588

9 years agoDelayedDestruction cleanup
Sophia Wang [Fri, 31 Jul 2015 16:32:55 +0000 (09:32 -0700)]
DelayedDestruction cleanup

Summary: remove unnecessary stuff

Reviewed By: @siyengar

Differential Revision: D2284095

9 years agoAdd accessor to estimate a FiberManager's run queue size
Brian Watling [Fri, 31 Jul 2015 15:52:36 +0000 (08:52 -0700)]
Add accessor to estimate a FiberManager's run queue size

Summary: Add accessor to estimate a FiberManager's run queue size

Reviewed By: @sarangbh

Differential Revision: D2293367

9 years agofolly: fix another test running under buck
Andrew Gallagher [Fri, 31 Jul 2015 10:31:44 +0000 (03:31 -0700)]
folly: fix another test running under buck

Reviewed By: @yfeldblum

Differential Revision: D2300047

9 years agofolly: fix tests running under buck (w/ clang and dynamic linking)
Andrew Gallagher [Fri, 31 Jul 2015 10:10:03 +0000 (03:10 -0700)]
folly: fix tests running under buck (w/ clang and dynamic linking)

Summary: Various fixes to get tests passing using buck's dev mode.

Reviewed By: @yfeldblum

Differential Revision: D2299981

9 years agofutures::retrying.
Yedidya Feldblum [Fri, 31 Jul 2015 03:10:19 +0000 (20:10 -0700)]
futures::retrying.

Summary: [Folly] futures::retrying.

Reviewed By: @fugalh

Differential Revision: D2201630

9 years agoFix 'missing declarations' and 'unusued parameter' warnings
Ondrej Lehecka [Fri, 31 Jul 2015 00:33:21 +0000 (17:33 -0700)]
Fix 'missing declarations' and 'unusued parameter' warnings

Summary: enum iterators operator!= didn't use the iterator parameter for comparison
because they assumed you only ever compare to end. Change the operator!= to
look at the iterator parameter to check if it was end.

Thrift generated code for reflection initializers for some types that weren't
declared before definition because they were never called outside of the file.
Marked those initializers as 'static'.

Reviewed By: @alandau

Differential Revision: D2284371

9 years agoadd EventBase-local storage abstraction
Mark McDuff [Tue, 30 Jun 2015 01:26:40 +0000 (18:26 -0700)]
add EventBase-local storage abstraction

Summary: This has come up a couple times, and the implementation is never nice.  Just like we have thread-local storage, it will be useful to also have evb-local storage.  Provides at pretty simple get/set/delete interface (see unittest).

Reviewed By: @djwatson

Differential Revision: D2203063

9 years agoFix Infinity
Nima Aghdaii [Thu, 30 Jul 2015 05:19:54 +0000 (22:19 -0700)]
Fix Infinity

Summary: folly only accepts "Infinity" while deserializing but writes "infinity" when serializing.
This means folly cannot deserialize what it serialized before.
If we agree on this, we could update ##fbcode/common## as well: https://fburl.com/136793901

Reviewed By: @marcinpe

Differential Revision: D2293627

9 years agoRemoved an unneeded typename in dynamic.h
Orvid King [Wed, 29 Jul 2015 23:57:06 +0000 (16:57 -0700)]
Removed an unneeded typename in dynamic.h

Summary: This `typename` qualifier was unneeded, and MSVC errors if it's there, so remove it.
Closes #275

Reviewed By: @yfeldblum

Differential Revision: D2284056

Pulled By: @sgolemon

9 years agoAdd MSVC support to Singleton's fatalHelper
Orvid King [Wed, 29 Jul 2015 21:51:04 +0000 (14:51 -0700)]
Add MSVC support to Singleton's fatalHelper

Summary: MSVC doesn't support constructor priorities, so use the same code as OSX.
Closes #272

Reviewed By: @yfeldblum

Differential Revision: D2283998

Pulled By: @sgolemon

9 years agoUse strerror_s on MSVC
Orvid King [Wed, 29 Jul 2015 21:51:46 +0000 (14:51 -0700)]
Use strerror_s on MSVC

Summary: Support for this under mingw was already present, this just uses that for MSVC as well.
Closes #273

Reviewed By: @yfeldblum

Differential Revision: D2284007

Pulled By: @sgolemon

9 years agoHandle MSVC in FBString.h
Orvid King [Wed, 29 Jul 2015 21:46:30 +0000 (14:46 -0700)]
Handle MSVC in FBString.h

Summary: Specifically, MSVC doesn't define `std::__ostream_insert`, so just write to the stream instead.
Closes #270

Reviewed By: @yfeldblum

Differential Revision: D2283960

Pulled By: @sgolemon

9 years agoSwitch a couple of uses of __thread to FOLLY_TLS
Orvid King [Wed, 29 Jul 2015 21:44:59 +0000 (14:44 -0700)]
Switch a couple of uses of __thread to FOLLY_TLS

Summary: Because MSVC doesn't support `__thread`, and `FOLLY_TLS` is already setup to use the MSVC syntax when needed.
Closes #269

Reviewed By: @yfeldblum

Differential Revision: D2283919

Pulled By: @sgolemon

9 years agoAdded asm_volatile_memory
Orvid King [Wed, 29 Jul 2015 18:36:32 +0000 (11:36 -0700)]
Added asm_volatile_memory

Summary: This adds `asm_volatile_memory`, which goes along with the same style used by `asm_volatile_pause`.
This also switches the two places in `RWSpinLock.h` that were using inline assembly for this to use the new functions instead.
Closes #260

Reviewed By: @yfeldblum

Differential Revision: D2283541

Pulled By: @sgolemon

9 years agoAdded FOLLY_ALIGNED(), to allow aligning on MSVC as well
Orvid King [Wed, 29 Jul 2015 18:44:32 +0000 (11:44 -0700)]
Added FOLLY_ALIGNED(), to allow aligning on MSVC as well

Summary: This adds `FOLLY_ALIGNED` to `Portability.h`, and adjusts the places that were previously using the raw aligned attribute to use this instead.

Closes #262

Reviewed By: @yfeldblum

Differential Revision: D2283639

Pulled By: @sgolemon

9 years agoFix Random-inl.h under MSVC
Orvid King [Wed, 29 Jul 2015 17:45:41 +0000 (10:45 -0700)]
Fix Random-inl.h under MSVC

Summary: With MSVC, `seedData.begin()` does not return a `void*`, so get a pointer to the data, and explicitly cast that to a `void*` instead.
Closes #251

Reviewed By: @yfeldblum

Differential Revision: D2282929

Pulled By: @sgolemon

9 years agoImplemented VersionCheck.h for MSVC
Orvid King [Wed, 29 Jul 2015 17:42:54 +0000 (10:42 -0700)]
Implemented VersionCheck.h for MSVC

Summary: This implements it via a function called on startup. The mechanism used is roughly equivelent of `__attribute__((__constructor__))` in that it doesn't have the ability to set the order of invokation.
Closes #249

Reviewed By: @yfeldblum

Differential Revision: D2282860

Pulled By: @sgolemon

9 years agoAdd space to error message
Andrey Goder [Wed, 29 Jul 2015 15:24:28 +0000 (08:24 -0700)]
Add space to error message

Summary: Before this change you would get an error like:
"Expected to get greater than or equal to1 for value 0"

Now it add in the space correctly:
"Expected to get greater than or equal to 1 for value 0"

Reviewed By: @snarkmaster

Differential Revision: D2288454

9 years agoAllow ProgramExit(0), add some comments
Tudor Bosman [Wed, 29 Jul 2015 14:48:48 +0000 (07:48 -0700)]
Allow ProgramExit(0), add some comments

Summary: exit() is evil, let's make it easier for programs that want to exit
successfully.

Reviewed By: @meyering

Differential Revision: D2290201

9 years agoAdd hasher specializations for enums, pairs and tuples
Alexander Shaposhnikov [Wed, 29 Jul 2015 03:35:46 +0000 (20:35 -0700)]
Add hasher specializations for enums, pairs and tuples

Summary: This diff adds partial specializations of folly::hasher for enum types, std::pair and std::tuple.
We also restrict the specialization for folly::Range to POD value types.

Reviewed By: @ot, @ddrcoder

Differential Revision: D2285554

9 years agoFix Build: FOLLY_SSE and preprocessor floats.
Yedidya Feldblum [Wed, 29 Jul 2015 02:55:09 +0000 (19:55 -0700)]
Fix Build: FOLLY_SSE and preprocessor floats.

Summary: [Folly] Fix Build: FOLLY_SSE and preprocessor floats.

Float values for preprocessor symbols are not a thing.

Reviewed By: @​fyan

Differential Revision: D2289436

9 years ago[folly] Enable support of applyTuple for const tuples
Alexander Shaposhnikov [Tue, 28 Jul 2015 23:35:54 +0000 (16:35 -0700)]
[folly] Enable support of applyTuple for const tuples

Summary: This diff fixes the helper template ReturnValue to enable using of applyTuple with
constant refs.

Reviewed By: @ot, @ddrcoder

Differential Revision: D2284733

9 years agoRegenerate README.md from source
Sara Golemon [Tue, 28 Jul 2015 23:41:16 +0000 (16:41 -0700)]
Regenerate README.md from source

Summary: Also fix URLs hand-modified by D2219135 which didn't quite update them enough.
Point them at the new repo.

Reviewed By: @yfeldblum

Differential Revision: D2285053

9 years agoMove various attributes before the declaration to be compatible with MSVC
Orvid King [Tue, 28 Jul 2015 22:59:31 +0000 (15:59 -0700)]
Move various attributes before the declaration to be compatible with MSVC

Summary: MSVC will just produce syntax errors if these are left where they currently are. GCC and LLVM support them in either location with the same meaning.
Closes #267

Reviewed By: @yfeldblum

Differential Revision: D2283889

Pulled By: @sgolemon

9 years agoUse fsync on MSVC, as fdatasync doesn't exist
Orvid King [Tue, 28 Jul 2015 22:15:49 +0000 (15:15 -0700)]
Use fsync on MSVC, as fdatasync doesn't exist

Summary: Closes #266

Reviewed By: @yfeldblum

Differential Revision: D2283774

Pulled By: @sgolemon

9 years agoUse intrinsics for RWSpinLock when on MSVC.
Orvid King [Tue, 28 Jul 2015 21:26:48 +0000 (14:26 -0700)]
Use intrinsics for RWSpinLock when on MSVC.

Summary: Closes #261

Reviewed By: @yfeldblum

Differential Revision: D2283554

Pulled By: @sgolemon

9 years agoAdd MSVC support for FOLLY_DEPRECATED
Orvid King [Tue, 28 Jul 2015 21:15:02 +0000 (14:15 -0700)]
Add MSVC support for FOLLY_DEPRECATED

Summary: This adds MSVC support for `FOLLY_DEPRECATED`.
Closes #257

Reviewed By: @yfeldblum

Differential Revision: D2283484

Pulled By: @sgolemon

9 years agoNormalize SSE support detection
Orvid King [Tue, 28 Jul 2015 21:23:14 +0000 (14:23 -0700)]
Normalize SSE support detection

Summary: This unifies ways of detecting SSE support into the FOLLY_SSE define which is a numeric value from 0 to 4.2 depending on detected level.
This also adds a `#define` for `__extension__` which is used in folly, but is GCC specific.
Closes #259

Reviewed By: @yfeldblum

Differential Revision: D2283522

Pulled By: @sgolemon

9 years agoAdd MSVC support for FOLLY_FINAL and FOLLY_OVERRIDE
Orvid King [Tue, 28 Jul 2015 21:18:10 +0000 (14:18 -0700)]
Add MSVC support for FOLLY_FINAL and FOLLY_OVERRIDE

Summary: This adds MSVC support for `FOLLY_FINAL` and `FOLLY_OVERRIDE`.
Closes #258

Reviewed By: @yfeldblum

Differential Revision: D2283502

Pulled By: @sgolemon

9 years agoAdd detection of MSVC RTTI
Orvid King [Tue, 28 Jul 2015 21:09:55 +0000 (14:09 -0700)]
Add detection of MSVC RTTI

Summary: This adds MSVC support to the detection of FOLLY_HAS_RTTI.
Closes #255

Reviewed By: @yfeldblum

Differential Revision: D2283036

Pulled By: @sgolemon

9 years agoAllow for mutable lambdas with Future::ensure()
Jason Rahman [Tue, 28 Jul 2015 06:48:48 +0000 (23:48 -0700)]
Allow for mutable lambdas with Future::ensure()

Summary: Update the internal lambda to mutable to support mutable lambdas as
parameters to Future::ensure()

Reviewed By: @yfeldblum

Differential Revision: D2286097

9 years agoAdd typename qualifiers to Singleton.h
Orvid King [Mon, 27 Jul 2015 22:42:23 +0000 (15:42 -0700)]
Add typename qualifiers to Singleton.h

Summary: MSVC complains if these are not there.
Closes #248

Reviewed By: @yfeldblum

Differential Revision: D2282845

Pulled By: @sgolemon

9 years agoSupport GroupVarint.h under MSVC
Orvid King [Mon, 27 Jul 2015 23:06:57 +0000 (16:06 -0700)]
Support GroupVarint.h under MSVC

Summary: MSVC supports the intrinsics used by it without any issue other changes, so just make sure the error doesn't trigger on MSVC.
Closes #252

Reviewed By: @yfeldblum

Differential Revision: D2282942

Pulled By: @sgolemon

9 years agoAdd support for MSVC in asm_pause in Portability.h
Orvid King [Mon, 27 Jul 2015 23:16:56 +0000 (16:16 -0700)]
Add support for MSVC in asm_pause in Portability.h

Summary: This implements support for `asm_volatile_pause` and `asm_pause`, as defined in `Portability.h`, for MSVC.
This is needed because MSVC x64 doesn't support inline assembly.
Closes #254

Reviewed By: @yfeldblum

Differential Revision: D2283006

Pulled By: @sgolemon

9 years agoAdjust a literal in AtomicHashMap.h to be correctly sized
Orvid King [Mon, 27 Jul 2015 22:09:31 +0000 (15:09 -0700)]
Adjust a literal in AtomicHashMap.h to be correctly sized

Summary: Noticed because of a warning emitted by MSVC, this fixees the literal for `kLockedPtr_` to correctly be 64-bits under MSVC, rather than 32-bit.
Closes #245

Reviewed By: @yfeldblum

Differential Revision: D2282806

Pulled By: @sgolemon

9 years agoFix the size of the enum in FBString.h under MSVC
Orvid King [Mon, 27 Jul 2015 22:17:32 +0000 (15:17 -0700)]
Fix the size of the enum in FBString.h under MSVC

Summary: MSVC defaults enum sizes to int, so explicitly use `size_t` as the base to have it correctly sized.
Closes #246

Reviewed By: @yfeldblum

Differential Revision: D2282816

Pulled By: @sgolemon

9 years agofix clang ASAN error in DelayedDestructionBaseTest
Sophia Wang [Mon, 27 Jul 2015 18:38:54 +0000 (11:38 -0700)]
fix clang ASAN error in DelayedDestructionBaseTest

Summary: fix a use after free bug. this line is stupid!

Reviewed By: @siyengar

Differential Revision: D2283041

9 years agodelete folly/wangle
James Sedgwick [Mon, 27 Jul 2015 18:11:00 +0000 (11:11 -0700)]
delete folly/wangle

Summary: she's gooooooone, oh why, oh why, i better learn how to face it...

https://www.youtube.com/watch?v=bnVXIUyshng

Reviewed By: @djwatson

Differential Revision: D2219135

9 years agoBump version to 52:0 v0.52.0
Sara Golemon [Mon, 27 Jul 2015 16:46:56 +0000 (09:46 -0700)]
Bump version to 52:0

9 years agoMake ProcessReturnCode default-constructible
Alexey Spiridonov [Mon, 27 Jul 2015 02:36:57 +0000 (19:36 -0700)]
Make ProcessReturnCode default-constructible

Summary: We have this previously-unused "NOT STARTED" status, which I recently appropriated to denote moved-out `ProcessReturnCode`s.

It's natural to also use this for default-constructed `ProcessReturnCodes`. Lacking a default constructor leads to a bunch of unnecessarily annoying use of `folly::Optional` in my upcoming diff, so I wanted to get rid of that, see e.g.

differential/diff/7657906/

Reviewed By: @tudor

Differential Revision: D2097368

9 years agoImprove waitpid error handling
Alexey Spiridonov [Mon, 27 Jul 2015 02:32:03 +0000 (19:32 -0700)]
Improve waitpid error handling

Summary: Using `checkUnixError` after `waitpid()` is confusing and useless, because the only two possible errors are `ECHILD` (some other part of the program waited for this process!?) and `EINVAL` (invalid options, which are hardcoded in both `Subprocess::wait()` and `poll()`). Neither of these are recoverable. Moreover, even if the caller catches the exception, `~Subprocess` is still booby-trapped to `abort()` since its status remains `RUNNING`.

In short, just abort.

Reviewed By: @yfeldblum

Differential Revision: D2079415

9 years agoFix some warnings in folly
mwilliams [Fri, 24 Jul 2015 18:44:20 +0000 (11:44 -0700)]
Fix some warnings in folly

Summary: Remove a couple of unused variables, and move one
that was only used inside an ifdef

Reviewed By: @yfeldblum

Differential Revision: D2279989

9 years agoadded a missing hook to IndexedMemPool's testing harness
Nathan Bronson [Fri, 24 Jul 2015 21:57:33 +0000 (14:57 -0700)]
added a missing hook to IndexedMemPool's testing harness

Summary: IndexedMemPool had one bare usage of std::atomic, rather than
the templated type Atom.  This doesn't affect any non-testing template
instantiations, because those two are usually synonyms, but it could cause
spurious failures of DeterministicSchedule tests.  Found via inspection,
not via failed tests.

Reviewed By: @yfeldblum

Differential Revision: D2277424

9 years agoPrint type of singleton that is requested after destruction
Misha Shneerson [Fri, 24 Jul 2015 18:57:21 +0000 (11:57 -0700)]
Print type of singleton that is requested after destruction

Summary: As titled
Trying to troubleshoot shutdown problems in HHVM and I see:
  EventBase::runAfterDelay() callback threw St13runtime_error exception: Raw pointer to a singleton requested after its destruction.
Would be much easier to troubleshoot if I know what is it being requested.

Reviewed By: @chipturner

Differential Revision: D2274497

9 years agoimprovements to DeterministicSchedule
Nathan Bronson [Fri, 24 Jul 2015 15:20:45 +0000 (08:20 -0700)]
improvements to DeterministicSchedule

Summary: This diff isolates the CacheLocality back end for DeterministicSchedule
from one invocation to the next (the last one was deterministic
across the entire program but not per-DeterministicSchedule instance),
and makes it easy to do extensive tracing of memory accesses during
a deterministic test.  These changes were made while tracking down a
bug, but don't fix any bugs on their own (and in fact don't affect any
production code at all).

Reviewed By: @yfeldblum

Differential Revision: D1842390

9 years agoFix oss build
Andre Pinto [Fri, 24 Jul 2015 00:15:26 +0000 (17:15 -0700)]
Fix oss build

Summary: Add program_options to fix oss build

Reviewed By: @tudor

Differential Revision: D2274863

9 years agoDelete functions that return a pointer when the dynamic object is a rvalue.
Nick Terrell [Fri, 24 Jul 2015 00:46:30 +0000 (17:46 -0700)]
Delete functions that return a pointer when the dynamic object is a rvalue.

Summary: This diff is not yet complete, I want to see the contbuild before I change the
functions that return references to member functions.

It is unsafe to return a pointer when the dynamic object is a rvalue, because if
the pointer escapes the expression after the object is destroyed, we go into
segfault / undefined behavior land.
I have deleted these overloads.  The amount of valid code that is now disallowed
is minimal.  The only valid case I can think of is returing a pointer and
passing it to a function in the same expression that does not save the pointer.
However, this case is also dangerous, because if the function you pass it to
decides to save the pointer for later, we are in trouble, e.g.

  save_ptr(dynamic("str").c_str())

Since there are simple workarounds (naming the object), I think that is a small
price to pay for the greatly increased safety.

The next step is to overload all members that return a reference to a member
to move the member out if the dynamic is a rvalue:

  const dynamic& at(dynamic const&) const&;
        dynamic& at(dynamic const&)      &;
        dynamic  at(dynamic const&)      &&;  // Move out

I also need to go over the code more carefully to make sure that nothing went
wrong.

Reviewed By: @marcinpe

Differential Revision: D2257914

9 years agoHelper for writing nested command line apps
Tudor Bosman [Thu, 23 Jul 2015 14:30:52 +0000 (07:30 -0700)]
Helper for writing nested command line apps

Summary: Many command line apps are of the form
"program [--global_options] command [--command_options] args..."

Make writing such things less painful.

+jdelong because smcc

Reviewed By: @meyering

Differential Revision: D2217248

9 years agoMake gflags and boost::program_options play nice with each other
Tudor Bosman [Thu, 23 Jul 2015 14:30:41 +0000 (07:30 -0700)]
Make gflags and boost::program_options play nice with each other

Summary: GFlags is useful for global program options. boost::program_options makes it
easier to write command-line utilities. They don't, unfortunately, play
very nicely with each other.

Add a addGFlags() function to convert all GFlags to boost::program_options
options; you can then use boost::program_options::parse_command_line() to
parse all arguments, GFlags or not.

Also add a helper function to make parsing nested command lines easier.

Reviewed By: @fugalh

Differential Revision: D2215285

9 years agofix racy assert in SharedMutex
Nathan Bronson [Wed, 22 Jul 2015 22:14:58 +0000 (15:14 -0700)]
fix racy assert in SharedMutex

Summary: SharedMutex purposely allows the inline reader count to underflow in some
situations while preserving proper locking behavior (the inline reader
count is only trusted if all deferred locks have been applied), but there
was an additional way that this could occur that wasn't documented or
allowed by the asserts.  The effect was a false positive assert in rare
conditions or the possibility of losing track of a deferred lock slot.
This diff fixes both the over-aggressive assert and the potential loss
of the shared slot.  If the assert didn't fire for you then this diff
won't change the correctness of your program.

Reviewed By: @yfeldblum

Differential Revision: D2269018

9 years agoAdd executable_path() and convert SubprocessTest to use it
Tudor Bosman [Wed, 22 Jul 2015 19:43:36 +0000 (12:43 -0700)]
Add executable_path() and convert SubprocessTest to use it

Summary: Because I didn't want to write it again.

Reviewed By: @yfeldblum

Differential Revision: D2217246

9 years agomaking thrift and folly header files compile clean with -Wunused-parameter
Ondrej Lehecka [Wed, 22 Jul 2015 18:57:18 +0000 (11:57 -0700)]
making thrift and folly header files compile clean with -Wunused-parameter

Summary: fixing compiler errors when compiling with Wunused-parameter

Reviewed By: @yfeldblum

Differential Revision: D2267014

9 years ago(Wangle) window, fix test
Hannes Roth [Wed, 22 Jul 2015 16:35:19 +0000 (09:35 -0700)]
(Wangle) window, fix test

Summary: Thanks @​peijinz for finding this.

Reviewed By: @​peijinz

Differential Revision: D2268532

9 years agoAdd bounds check in get_ptr.
Nick Terrell [Tue, 21 Jul 2015 18:34:55 +0000 (11:34 -0700)]
Add bounds check in get_ptr.

Summary: `get_ptr()` checks if the index is past the end of the array, but it
doesn't check if it is less than 0, while `at()` does.

Reviewed By: @yfeldblum

Differential Revision: D2258548

9 years ago(Wangle) within should raise TimedOut()
Hannes Roth [Tue, 21 Jul 2015 02:42:45 +0000 (19:42 -0700)]
(Wangle) within should raise TimedOut()

Summary: A timeout now raises `TimedOut()` on the current Future.

Reviewed By: @fugalh

Differential Revision: D2261559