folly.git
8 years agoFix doVecOperation in the SysUio portability header
Christopher Dykes [Thu, 26 May 2016 17:08:13 +0000 (10:08 -0700)]
Fix doVecOperation in the SysUio portability header

Summary: Apparently I failed to accurately transfer this particular change to fbcode, which meant it didn't actually compile on Windows.

Reviewed By: yfeldblum

Differential Revision: D3347976

fbshipit-source-id: 775682f10ab68672f6463ccc69a222ae0a52a097

8 years agoadd Cursor::peekBytes()
Adam Simpkins [Wed, 25 May 2016 19:07:07 +0000 (12:07 -0700)]
add Cursor::peekBytes()

Summary:
The existing Cursor::peek() method pre-dates the existence of folly::ByteRange,
and so it returns a std::pair containing a pointer and length.  This is usually
more awkward to use than ByteRange.

This adds a peekBytes() method that returns a ByteRange object, and updates all
users of peek() in folly to use peekBytes() instead.  Eventually I think we
should add a FOLLY_DEPRECATED attribute to peek().  I will wait to add this tag
until after converting a few other projects to use peekBytes(), though.

Reviewed By: alandau

Differential Revision: D3337302

fbshipit-source-id: 14220a059d915bf5adc66b8b283f7228b796a4dc

8 years agostd::make_unique -> folly::make_unique
Jon Maltiel Swenson [Tue, 24 May 2016 22:41:25 +0000 (15:41 -0700)]
std::make_unique -> folly::make_unique

Summary:
We should use folly::make_unique instead of std::make_unique in order to support
compilers without support for C++14.

Reviewed By: pavlo-fb

Differential Revision: D3343288

fbshipit-source-id: 9150af752e57988962a7580851ffa32086c669d7

8 years agoUpdate generate_varint_tables to support MSVC
Christopher Dykes [Tue, 24 May 2016 20:57:25 +0000 (13:57 -0700)]
Update generate_varint_tables to support MSVC

Summary: MSVC is a massive pain in this respect, and, after testing many workarounds, and only ending up with it just emitting a dynamic initializer for them, it's easier to just generate the table as a `uint64_t` and load it explicitly.

Reviewed By: yfeldblum

Differential Revision: D3270226

fbshipit-source-id: 77bc84e58d393373de05a28a30dcb80b66c09c9f

8 years agoClear old fs::path when moving a TemporaryDirectory
Joseph Griego [Tue, 24 May 2016 20:14:54 +0000 (13:14 -0700)]
Clear old fs::path when moving a TemporaryDirectory

Summary:
If a TemporaryDirectory with scope DELETE_ON_DESTRUCTION gets moved
and then goes out of scope, the directory will be deleted while the moved
object still holds that path; we just clear the path from the old object to
prevent this

Reviewed By: yfeldblum

Differential Revision: D3331079

fbshipit-source-id: 9c99413661e2436ccec937d3fa652da810133b34

8 years agoSwitch HHWheelTimer::SharedPtr to a standard shared pointer
Chad Parry [Tue, 24 May 2016 18:05:14 +0000 (11:05 -0700)]
Switch HHWheelTimer::SharedPtr to a standard shared pointer

Summary:
As part of my campaign to get `HHWheelTimer` away from intrusive ref-counting semantics, (cf. D3237530), I am redefining `HHWheelTimer::SharedPtr`. It is now a true `std::shared_ptr`. This will break clients that attempt the following:

  HHWheelTimer::UniquePtr timer1{HHWheelTimer::newTimer()};
  HHWheelTimer::SharedPtr timer2{timer1};

In the past, that code would compile, because `timer2` could use the intrusive ref-counting, and `timer1` would still be valid. After this change, the second timer would need to be initialized with `std::move(timer1)` instead. The `UniquePtr` is starting to actually be unique.

There is only one place in the code that actually tries to do such a copy. It's in a test, which I have changed. Any other instances of that behavior would create a compilation error, so it's impossible for one to be overlooked.

Reviewed By: djwatson

Differential Revision: D3337038

fbshipit-source-id: 085e4da41c9a142d253a1ac0b1dd0fc508dff704

8 years agoSupport folly::assume under MSVC
Christopher Dykes [Tue, 24 May 2016 00:30:29 +0000 (17:30 -0700)]
Support folly::assume under MSVC

Summary: Actually __assume when we assume.

Reviewed By: meyering

Differential Revision: D3336033

fbshipit-source-id: 6c931e9f832dd1d861d03e3ad8e308f612522401

8 years agoAvoid std::initializer_list ctor in folly::dynamic::array
Yedidya Feldblum [Mon, 23 May 2016 06:35:19 +0000 (23:35 -0700)]
Avoid std::initializer_list ctor in folly::dynamic::array

Summary:
[Folly] Avoid `std::initializer_list` ctor in `folly::dynamic::array`.

This will help deprecate the dangerous initializer-list constructor. The init-list construction is dangerous because its semantics vary by compiler and by compiler version.

Reviewed By: ot

Differential Revision: D3333148

fbshipit-source-id: 031e7593b7e28b299d5eeeb5ce7aed9216dd3a5c

8 years agoMake outstanding LoopKeepAlive hold EventBase destructor
Andrii Grynenko [Fri, 20 May 2016 22:55:24 +0000 (15:55 -0700)]
Make outstanding LoopKeepAlive hold EventBase destructor

Summary:
LoopKeepAlive handle can be grabbed to signal that some external event will later be scheduled on the EventBase via runInEventBaseThread. Usually the code which will be calling runInEventBaseThread only has a raw pointer to an EventBase, so it doesn't have any way to know it was destroyed.

This change ensures that EventBase destructor will keep running the event loop until all such LoopKeepAlive handles are released.

Reviewed By: yfeldblum

Differential Revision: D3323835

fbshipit-source-id: 4071dae691a61dfebe2f1759cf99f661b161fa4a

8 years agoFix the detection of preadv and pwritev on OSX in OSS
Christopher Dykes [Fri, 20 May 2016 21:26:38 +0000 (14:26 -0700)]
Fix the detection of preadv and pwritev on OSX in OSS

Summary:
The configure script doesn't define `FOLLY_HAVE_PREADV` if `preadv` isn't supported, so these checks were wrong. Undefined defines expand to `0`, so this is safe.
Fixes https://github.com/facebook/folly/issues/412

Reviewed By: mzlee, yfeldblum

Differential Revision: D3329405

fbshipit-source-id: faee8951c68d4c67e06e7720dfc142e63a9dbd9f

8 years agotemplating folly::fibers::await by Baton
Shubhanshu Agrawal [Fri, 20 May 2016 05:03:16 +0000 (22:03 -0700)]
templating folly::fibers::await by Baton

Summary:
This diff templates folly::fibers::await by Baton.
This would be helpful in passing in custom BatonType's, which is needed for D3007734

Depends on: D3314891

Reviewed By: andriigrynenko

Differential Revision: D3314925

fbshipit-source-id: 9052dc503b9509f16cd41b5e3ede0479a98067aa

8 years agoPromote memory_order_consume to memory_order_acquire
Alejandro [Thu, 19 May 2016 16:19:54 +0000 (09:19 -0700)]
Promote memory_order_consume to memory_order_acquire

Summary:
The current use case of `std::memory_order_consume` in this project was intended to provide the appropriate synchronization in cases where a consumer spins on `while( spsc_queue.empty() ) {} `, and then attempts to use an element of the queue since the loop was broken out of, according to comments [here](https://reviews.facebook.net/D48141). Consume semantics do not provide this guarantee according to the standard since there is no data dependency from the producer that can be carried to the consumer by doing a load-consume from the corresponding functions. What is needed is a load-acquire. Current compilers promote `memory_order_consume` to `memory_order_acquire`. Thus, this example appears to work simply due to the promotion from consume to acquire, but would fail to generate the right synchronization instructions on weaker architectures once `memory_order_consume` is implemented as intended.  Therefore, the `memory_order` should be tightened to `memory_order_acquire` to guarantee visibility to the consumer
Closes https://github.com/facebook/folly/pull/381

Reviewed By: djwatson

Differential Revision: D3173574

Pulled By: nbronson

fbshipit-source-id: b109be2e74f016750a3fe1f848e3fc66e609b9d2

8 years agoExtract Try to top-level
Yedidya Feldblum [Thu, 19 May 2016 09:20:24 +0000 (02:20 -0700)]
Extract Try to top-level

Summary:
[Folly] Extract `Try` to top-level.

It was in `folly/futures/`, but this diff moves it to `folly/`.

It is needed for futures, but it is are more general than futures and can be used separately.

Use `folly/Try.h` instead of `folly/futures/Try.h`.

Also fixes up all `#include` sites:

    hg grep -lw folly/futures/Try | xargs perl -pi -e 's,\bfolly/futures/Try\b,folly/Try,g'

Reviewed By: markisaa

Differential Revision: D3309908

fbshipit-source-id: cdf13f0ac0b0e36aa07e0f1d04870d06500c5874

8 years agofolly: FBString: avoid ubsan in assert
Lucian Grijincu [Thu, 19 May 2016 08:14:49 +0000 (01:14 -0700)]
folly: FBString: avoid ubsan in assert

Summary:
```
buck-out/gen/folly/__default_headers__#default,headers/folly/FBString.h:365:7: runtime error: null pointer passed as argument 2, which is declared to never be null
third-party-buck/build/glibc/include/string.h:70:33: note: nonnull attribute specified here
    #0 0x433a39 in _ZZN5folly13fbstring_coreIcEC1EPKcmbENKUlvE_clEv ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////buck-out/gen/folly/__default_headers__#default,headers/folly/FBString.h:365:7
    #1 0x4335a9 in _ZN5folly14ScopeGuardImplIZNS_13fbstring_coreIcEC1EPKcmbEUlvE_E7executeEv ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////buck-out/gen/folly/__default_headers__#default,headers/folly/ScopeGuard.h:153:29
    #2 0x4335a9 in _ZN5folly14ScopeGuardImplIZNS_13fbstring_coreIcEC1EPKcmbEUlvE_ED2Ev ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////buck-out/gen/folly/__default_headers__#default,headers/folly/ScopeGuard.h:130
    #3 0x4335a9 in folly::fbstring_core<char>::fbstring_core(char const*, unsigned long, bool) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////buck-out/gen/folly/__default_headers__#default,headers/folly/FBString.h:427
    #4 0x4353fa in folly::basic_fbstring<char, std::char_traits<char>, std::allocator<char>, folly::fbstring_core<char> >::basic_fbstring(char const*, unsigned long, std::allocator<char> const&) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////buck-out/gen/folly/__default_headers__#default,headers/folly/FBString.h:1038:9
```

Reviewed By: Gownta

Differential Revision: D3321266

fbshipit-source-id: 28d5aef16e91a98066a1de6bab95403fbc63eaab

8 years agoMove fibers out of experimental
Andrii Grynenko [Thu, 19 May 2016 05:57:40 +0000 (22:57 -0700)]
Move fibers out of experimental

Summary: folly::fibers have been used by mcrouter for more than 2 years, so not really experimental.

Reviewed By: pavlo-fb

Differential Revision: D3320595

fbshipit-source-id: 68188f92b71a4206d57222993848521ca5437ef5

8 years agoadding Promise::await
Shubhanshu Agrawal [Thu, 19 May 2016 03:42:24 +0000 (20:42 -0700)]
adding Promise::await

Summary:
This diff adds a static await method to Promise.
Also after this, folly::fibers::await is just a wrapper around Promise::await.
This also removes the friend relationship between Promise and await.

This would be helpful in making the folly::fibers::await templated by Baton changes easier to make.

Reviewed By: andriigrynenko

Differential Revision: D3314891

fbshipit-source-id: 361546c078caafd067734d2f474c617d7fb888b0

8 years agoMake Try independent of Future
Yedidya Feldblum [Thu, 19 May 2016 00:39:53 +0000 (17:39 -0700)]
Make Try independent of Future

Summary:
[Folly] Make `Try` independent of `Future`.

`Try` is useful for futures, but it can be used independently from futures as well.

Reviewed By: djwatson

Differential Revision: D3319130

fbshipit-source-id: badfcaa482dee6e7bdef14a501b4efc91634fa51

8 years agoExport documentation from dex to folly
Andrii Grynenko [Thu, 19 May 2016 00:11:24 +0000 (17:11 -0700)]
Export documentation from dex to folly

Reviewed By: yfeldblum

Differential Revision: D3317666

fbshipit-source-id: f5558b117c8da74789ee444cdaa00231e75dc31e

8 years agoFixing typo in Readme
iivlev [Wed, 18 May 2016 23:56:35 +0000 (16:56 -0700)]
Fixing typo in Readme

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

Reviewed By: yfeldblum

Differential Revision: D3320043

Pulled By: elliottneilclark

fbshipit-source-id: 5d21421216180fb601015a40a3de79e3dd2a162e

8 years agoFlesh out the comments about Unit
Yedidya Feldblum [Wed, 18 May 2016 21:46:49 +0000 (14:46 -0700)]
Flesh out the comments about Unit

Summary:
[Folly] Flesh out the comments about `Unit`.

* Remove mention of `Future`.
* Compare `unit` to `void`.

Reviewed By: djwatson

Differential Revision: D3316114

fbshipit-source-id: d30cf36cc029025734bb16c5bdbd640a289cad79

8 years agoExtract Unit to top-level
Yedidya Feldblum [Wed, 18 May 2016 03:38:11 +0000 (20:38 -0700)]
Extract Unit to top-level

Summary:
[Folly] Extract `Unit` to top-level.

It was in `folly/futures/`, but this diff moves it to `folly/`. It is needed for futures, but it is more general than futures and can be used separately.

Users must replace `folly/futures/Unit.h` with `folly/Unit.h`.

Also codemods existing usage sites:

```
hg grep -lw folly/futures/Unit.h | xargs perl -pi -e 's,\bfolly/futures/Unit\.h\b,folly/Unit.h,g'
```

Reviewed By: igorsugak

Differential Revision: D3314280

fbshipit-source-id: 16279b76b1d24529bec49077ccb36cd7d39f23b8

8 years agoadded IOBuf::wrapBufferAsValue()
Ilya Maykov [Wed, 18 May 2016 01:53:27 +0000 (18:53 -0700)]
added IOBuf::wrapBufferAsValue()

Summary:
Added a version of IOBuf::wrapBuffer() which returns the new IOBuf by value rather than heap-allocating it.
Motivation: we have a lot of places in the crypto code that do something like this:

  // take a string or vector parameter
  auto buf = folly::IOBuf::wrapBuffer( /* string or vector goes here */);
  // do something with buf
  // return

In these cases, a stack-allocated IOBuf would save us from an unnecessary heap allocation. But calling `folly::IOBuf(folly::IOBuf::WrapBufferOp::WRAP_BUFFER, ...)` is gross and in practice people just call the much more readable `wrapBuffer()` function. Hypothesis: readability trumps performance, but if we had a readable version that returned a stack-allocated IOBuf, it might see usage.

Reviewed By: yfeldblum

Differential Revision: D3314037

fbshipit-source-id: 4d4b5ec1d067762a27de1d7d6f7cac406388bfa3

8 years agoFix one more race in Promise::setTry
Andrii Grynenko [Wed, 18 May 2016 00:21:56 +0000 (17:21 -0700)]
Fix one more race in Promise::setTry

Summary:
Baton::post has to be the last step of Promise::setTry. If Promise is not owned by
the posting thread, it may be destroyed right after Baton::post is called.

Reviewed By: pavlo-fb

Differential Revision: D3312506

fbshipit-source-id: 6d5c3f0925c3bb9cd3f981e7550f888d5ed76189

8 years agoKeep the Unit test suite free of Promise and Future
Yedidya Feldblum [Wed, 18 May 2016 00:04:40 +0000 (17:04 -0700)]
Keep the Unit test suite free of Promise and Future

Summary:
[Folly] Keep the `Unit` test suite free of `Promise` and `Future`.

Move the `Promise`-related tests to the `Promise` test suite and the `Future`-related tests to the `Future` test suite.

Reviewed By: djwatson

Differential Revision: D3313635

fbshipit-source-id: 05c82c8719719d7709063ad58a4806036ca10fb3

8 years agoSimplify Unit
Yedidya Feldblum [Tue, 17 May 2016 22:27:43 +0000 (15:27 -0700)]
Simplify Unit

Summary:
[Folly] Simplify `Unit`.

Specifically:
* Make `Unit::Lift` and `Unit::Drop` simply be aliases to `std::conditional<...>`. No need for anything more complicated.
* Remove `is_void_or_unit`, which is unused and unnecessary.

Reviewed By: djwatson

Differential Revision: D3312481

fbshipit-source-id: 280d40aa8ef91c52f96a51b03e0a109d76c939ec

8 years agofolly: fbvector: ubsan: don't call memcpy() with nullptr args if size == 0
Marcus Holland-Moritz [Tue, 17 May 2016 20:08:17 +0000 (13:08 -0700)]
folly: fbvector: ubsan: don't call memcpy() with nullptr args if size == 0

Reviewed By: meyering, luciang

Differential Revision: D3310683

fbshipit-source-id: c86471d54062b2f3455f15fb73340fac486d9e44

8 years agoIPAddress::validate
Yedidya Feldblum [Tue, 17 May 2016 01:43:22 +0000 (18:43 -0700)]
IPAddress::validate

Summary: [Folly] `IPAddress::validate`.

Reviewed By: igorsugak

Differential Revision: D3308683

fbshipit-source-id: 48af18d6930f16718372021a4cc08062bf17327e

8 years agoFix a race in Promise::setTry
Andrii Grynenko [Mon, 16 May 2016 21:06:54 +0000 (14:06 -0700)]
Fix a race in Promise::setTry

Summary:
This fixes a race which can only be exposed if Promise is owned by the same thread which was calling await and Promise is fulfilled from a different thread. What could happen then was:
1. Thread 2 fulfills the promise and thus saves the value and posts Baton.
2. Thread 1 wakes up, await returns and then Thread 1 destroys the Promise.
3. Promise destructor checks value_, which is still not null, so it tries to fulfil it with exception.

Reviewed By: spalamarchuk

Differential Revision: D3306969

fbshipit-source-id: adf799cfd7b75b0201fa675a9e44ac7c7c42ac95

8 years agoMake await exception safe
Andrii Grynenko [Mon, 16 May 2016 20:13:24 +0000 (13:13 -0700)]
Make await exception safe

Summary: This fixes fibers::await to correctly handle exception thrown by user-passed lambda. Await still always waits for the promise to be fulfilled (if the promise was not moved out, it will be destroyed and thus auto-fulfilled with "promise not fulfilled" exception). However if user-passed lambda throws, promise result is ignored (even if exception) and exception thrown by lambda is re-thrown.

Reviewed By: pavlo-fb

Differential Revision: D3303393

fbshipit-source-id: c4ba01fde0e156cc88e5d07aaf763e3abe121d11

8 years agoPrefer constexpr to preprocessor conditionals when checking endianness
Yedidya Feldblum [Sat, 14 May 2016 19:49:52 +0000 (12:49 -0700)]
Prefer constexpr to preprocessor conditionals when checking endianness

Summary:
[Folly] Prefer `constexpr` to preprocessor conditionals when checking endianness.

Using `if (folly::kIsLittleEndian) {` v.s. `#if __BYTE_ORDER__ == __LITTLE_ENDIAN__`.

Reviewed By: meyering

Differential Revision: D3296770

fbshipit-source-id: b26df83fdd42a50663746fc7c9d5fbe67e6671eb

8 years agoA thread-per-task executor
Yedidya Feldblum [Sat, 14 May 2016 11:29:37 +0000 (04:29 -0700)]
A thread-per-task executor

Summary:
[Wangle] A thread-per-task executor.

Moved from Folly into Wangle and fleshed out.
* Starts task threads from a control thread, rather than starting task threads from the submitter thread. Because starting task threads is likely to be more expensive than moving a functor.
* Joins task threads as they finish, rather than joining all task threads in the executor's destructor.

Suitable for running tasks which spend most of their time sleeping. Such as blocking IO, blocking fork-exec-wait, etc., when it is inconvenient to use the nonblocking variants with an IO executor.

Reviewed By: simpkins

Differential Revision: D3286988

fbshipit-source-id: 4b91133a7d55332ebbae020c1515c60e816906b3

8 years agofolly: fbstring: ubsan: memcpy/memmove are marked as nonnull - avoid calling them...
Lucian Grijincu [Sat, 14 May 2016 07:38:50 +0000 (00:38 -0700)]
folly: fbstring: ubsan: memcpy/memmove are marked as nonnull - avoid calling them when size == 0 and (likely) source is nullptr

Summary: Also see {D3295811}

Differential Revision: D3302564

fbshipit-source-id: 3f2dbf5a6cfa8199682cb4af90aac372d501919a

8 years agofolly: ubsan: elias-fano avoid memset(nullptr)
Lucian Grijincu [Sat, 14 May 2016 07:09:41 +0000 (00:09 -0700)]
folly: ubsan: elias-fano avoid memset(nullptr)

Reviewed By: ot

Differential Revision: D3300437

fbshipit-source-id: 7e0add5dab6dc1c891b742b4bcedea656c8284a9

8 years agofolly: ubsan: redo BitsTest (no macros) and fix DCHECK in test
Lucian Grijincu [Sat, 14 May 2016 00:23:32 +0000 (17:23 -0700)]
folly: ubsan: redo BitsTest (no macros) and fix DCHECK in test

Reviewed By: meyering

Differential Revision: D3283226

fbshipit-source-id: 7ae2ec7741ca53c494e8325e30f2995a241674c0

8 years agoTest creation of RequestContext inside a fiber task
Mirek Klimos [Fri, 13 May 2016 21:17:12 +0000 (14:17 -0700)]
Test creation of RequestContext inside a fiber task

Summary: ^, as discussed on D3279644

Reviewed By: andriigrynenko

Differential Revision: D3299473

fbshipit-source-id: dc302132db64399f768d69c641f848d0da1075c4

8 years agoReplace RequestContext::setContext with RequestContextScopeGuard in folly
Mirek Klimos [Fri, 13 May 2016 19:02:35 +0000 (12:02 -0700)]
Replace RequestContext::setContext with RequestContextScopeGuard in folly

Summary: To make sure RequestContext is properly unset when we stop processing request on a thread. This changes the API in Fibers, NotificationQueue, HHWheelTimer and AsyncTimeout, and fixes RequestContext handling in Futures (reset RC after the callback is done)

Reviewed By: andriigrynenko

Differential Revision: D3279644

fbshipit-source-id: a6a1c2840cdce179334aa1a3b28fa514cd5358c1

8 years agoConstruct all HHWheelTimer instances with the factory method
Chad Parry [Fri, 13 May 2016 18:56:03 +0000 (11:56 -0700)]
Construct all HHWheelTimer instances with the factory method

Summary:
This diff standardizes `HHWheelTimer` construction. It's not that safe to allow anyone to call `new HHWheelTimer` because the caller needs to remember to call `DelayedDestruction::destroy`.

Once callers are made to be safer, I'll be able to change the `HHWheelTimer` to use standard smart pointers instead of `DelayedDestruction`.

This picks up some work that I started in D2627941 but had to postpone.

This was mostly a mechanical change:

  ( fbgs -ls 'new HHWheelTimer' ; fbgs -ls 'new folly::HHWheelTimer' ) | xargs perl -pi -e 's/\bnew\s+((?:folly::)?HHWheelTimer)\b/$1::newTimer/g'

Then I manually inspected the code. I reverted `folly/io/async/HHWheelTimer.h`, since the `newTimer` factory method is the one place that we still want to call `new HHWheelTimer`. I manually edited `proxygen/lib/utils/SharedWheelTimer.cpp`, since that was using a `shared_ptr` with a custom destructor, which isn't needed anymore. I reverted `common/io/async/d` since the D shim is meant to pass around only raw pointers. I had to replace each instance of `foo.reset(…)` with `foo = â€¦` . Then I made manual edits to `common/clientpool/ClientPool2-inl.h` because that code wants to store the timer in a `ThreadLocalPtr`.

Reviewed By: yfeldblum

Differential Revision: D3237530

fbshipit-source-id: 96bfb6987098618ad5430c21b1314f385f04a93d

8 years agoSuppress new GCC 5 warning -Wbool-compare
Mark Santaniello [Fri, 13 May 2016 15:41:37 +0000 (08:41 -0700)]
Suppress new GCC 5 warning -Wbool-compare

Summary: This -Wbool-compare is apparently new in GCC 5.  We should ignore it, similar to the existing suppression of -Wsign-compare.

Reviewed By: pixelb, yfeldblum

Differential Revision: D3293675

fbshipit-source-id: 5f90b0dbf049a06c0f6c3df2cdfcc8055358e367

8 years agoFix extra bytes in err message
Subodh Iyengar [Fri, 13 May 2016 07:24:05 +0000 (00:24 -0700)]
Fix extra bytes in err message

Summary:
Error message might be < 256 bytes
in which case buf.size() would be greater
than the size of the message written out
and we might have garbled bytes at the end.

ERR_error_string_n null terminates the string
so just use that.

Reviewed By: anirudhvr

Differential Revision: D3297320

fbshipit-source-id: 2ae626ce4c49ca478806c0bcc40a390e5a84f24b

8 years agoRegister custom stack for signal handlers
Andrii Grynenko [Thu, 12 May 2016 23:20:40 +0000 (16:20 -0700)]
Register custom stack for signal handlers

Summary: This updates FiberManager to automatically register custom stack for signal handlers. This ensures signal handlers will work correctly not only in case of stack overflow, but also if fiber stack size is just not enough for them.

Reviewed By: yfeldblum

Differential Revision: D3289912

fbshipit-source-id: 44959b727f70e1f1748d837b1a06c7414433e5ec

8 years agoTransfer ownership from a unique_ptr to a ThreadLocalPtr
Chad Parry [Thu, 12 May 2016 21:47:19 +0000 (14:47 -0700)]
Transfer ownership from a unique_ptr to a ThreadLocalPtr

Summary:
This `ThreadLocalPtr::reset` overload will accept a `unique_ptr`. It's actually not totally exception safe, simply because `ElementWrapper::set` is not exception safe. The best I can say is that my additional code is exactly as safe as the underlying implemenation.

liketolivedangerously

Reviewed By: ericniebler

Differential Revision: D3271563

fbshipit-source-id: 774bcf31924b1ed4e29a6cb1c0a36ad710ab6034

8 years agoPrevent leaks in ThreadLocalPtr initialization
Chad Parry [Thu, 12 May 2016 18:46:42 +0000 (11:46 -0700)]
Prevent leaks in ThreadLocalPtr initialization

Summary: While making an unrelated change, (D3271563, which was needed from an unrelated change, (D3237530)), I noticed a lack of exception safety here. If `std::bad_alloc` were thrown, then we don't want to leak memory.

Reviewed By: ericniebler

Differential Revision: D3271911

fbshipit-source-id: 0d316c0fa865a7d64622c1d62160bb0c2b061d78

8 years agoInclude limits.h in IOVec.h.
Michael Lee [Thu, 12 May 2016 16:44:29 +0000 (09:44 -0700)]
Include limits.h in IOVec.h.

Summary:
According to the POSIX definition, IOV_MAX is defined in
limits.h. Given that IOVec.h is used to provide IOV_MAX and similar,
it seems like we should add limits.h as well.

Differential Revision: D3291996

fbshipit-source-id: 238140ebef7b1b90a28f3a67a25c5f5863538fc7

8 years agoMake the sys/uio.h portability header work for Windows
Christopher Dykes [Wed, 11 May 2016 23:55:28 +0000 (16:55 -0700)]
Make the sys/uio.h portability header work for Windows

Summary: Windows doesn't have sys/uio.h, so implement it. This doesn't adjust any includes of it yet, I'll leave that for a separate diff.

Reviewed By: yfeldblum

Differential Revision: D2978042

fbshipit-source-id: 16d398a856de50b6c662f739eb11dfb851096592

8 years agowangle support for TFO
Subodh Iyengar [Wed, 11 May 2016 19:34:00 +0000 (12:34 -0700)]
wangle support for TFO

Summary: Add server support for TFO to wangle.

Reviewed By: Orvid

Differential Revision: D3275427

fbshipit-source-id: 466baa342e2e0c4751e9c96d1e660cffb90e0634

8 years agofolly: ubsan: format: avoid UB in abs(-INT_MIN)
Lucian Grijincu [Wed, 11 May 2016 17:45:33 +0000 (10:45 -0700)]
folly: ubsan: format: avoid UB in abs(-INT_MIN)

Summary:
abs(-INT_MIN) is UB. Avoid it by first casting the number to
its unsigned equivalent and then negating that.

Reviewed By: yfeldblum

Differential Revision: D3280835

fbshipit-source-id: 40922d686173e6467e15d5a6dc2b62ad718349b5

8 years agoAdd a compatibility shim for working with libevent on MSVC
Christopher Dykes [Wed, 11 May 2016 16:51:11 +0000 (09:51 -0700)]
Add a compatibility shim for working with libevent on MSVC

Summary:
MSVC builds of libevent expect `evutil_socket_t` to be `HANDLE` values, but Folly, HHVM, and Thrift all use them as file descriptors.
This adds a `folly_event_set` function that always expects a file descriptor rather than a socket. This also changes the places in Folly that use it.

Reviewed By: mzlee, yfeldblum

Differential Revision: D2874655

fbshipit-source-id: 66cfd86fd69a9fbac30d150445e4814cd5ca799e

8 years agoMake error size more explicit
Subodh Iyengar [Wed, 11 May 2016 07:14:01 +0000 (00:14 -0700)]
Make error size more explicit

Summary:
We shouldn't rely on the internal buffer size of openssl
for errors.

This makes it more explicit.

Reviewed By: knekritz

Differential Revision: D3285918

fbshipit-source-id: 452bf16a3de151d0aa79c774f2fdfc1e08ee6f9c

8 years agoAdd NETWORK_ERROR to switch statement
Neel Goyal [Tue, 10 May 2016 23:23:24 +0000 (16:23 -0700)]
Add NETWORK_ERROR to switch statement

Summary: Add NETWOR_ERROR to switch so it doesn't fall into Invalid Exception block.

Differential Revision: D3282448

fbshipit-source-id: 2cc5d21e436e6ac8f2f6581d99341ac47cf5b023

8 years agoAdd additional ALPN mismatch tests.
Kyle Nekritz [Tue, 10 May 2016 19:14:39 +0000 (12:14 -0700)]
Add additional ALPN mismatch tests.

Reviewed By: siyengar

Differential Revision: D3264727

fbshipit-source-id: fb10558096e73a3cbb6f2fb93296524c0206910d

8 years agoFix a few typos all over the code
Faidon Liambotis [Tue, 10 May 2016 18:05:26 +0000 (11:05 -0700)]
Fix a few typos all over the code

Summary:
These are pretty trivial. Debian's lint tool (lintian) warns about those
in its verbose mode, and since we saw them when packaging for Debian, we
thought of fixing them and forwarding them upstream.
Closes https://github.com/facebook/folly/pull/345

Reviewed By: Orvid

Differential Revision: D2769801

Pulled By: elliottneilclark

fbshipit-source-id: ad37cc53792f21aae6558ba256f20cb56c6caab5

8 years agodocs/Overview.md: Fixed 2 hyperlinks.
Jaak Ristioja [Tue, 10 May 2016 17:42:47 +0000 (10:42 -0700)]
docs/Overview.md: Fixed 2 hyperlinks.

Summary:
These didn't work properly in GitHub.
Closes https://github.com/facebook/folly/pull/375

Differential Revision: D3281872

Pulled By: elliottneilclark

fbshipit-source-id: b5398267ff5856bb6a7c4a3b963ae5cb47859bc3

8 years agofolly: ubsan: disable integer overflow tests in Histogram
Lucian Grijincu [Tue, 10 May 2016 06:00:19 +0000 (23:00 -0700)]
folly: ubsan: disable integer overflow tests in Histogram

Summary:
It would be nice to fix, but it's going to be easier to do when folly
support is for GCC>=5 which adds `__builtin_add_overflow`.

For now disable the check as the Histgram code handles overflow
correctly and has tests for these cases.

Fixes need to be done for both float and integer types as Histogram is used with both.

Reviewed By: meyering

Differential Revision: D3280260

fbshipit-source-id: 56e524c517566a4547346859be7770eda2acee96

8 years agofolly: ubsan: cast to unsigned to avoid negative-left-shift
Lucian Grijincu [Tue, 10 May 2016 04:16:26 +0000 (21:16 -0700)]
folly: ubsan: cast to unsigned to avoid negative-left-shift

Summary:
The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated
  bits are filled with zeros.

  If E1 has a signed type and non-negative value, and E1 Ã— 2E2 is
  representable in the result type, then that is the resulting value;
  otherwise, the behavior is undefined.

The code assumed the signed left shift worked like an unsigned left
shift, so make that explicit.

Reviewed By: meyering

Differential Revision: D3280325

fbshipit-source-id: 178b95ee36b7a1126a79bb825c2ad2ffa6fa9464

8 years agofolly: ubsan: fix "reference binding to null pointer of type 'char'"
Lucian Grijincu [Tue, 10 May 2016 00:50:08 +0000 (17:50 -0700)]
folly: ubsan: fix "reference binding to null pointer of type 'char'"

Summary:
third-party-buck/build/libgcc/include/c++/4.9.x/bits/stl_vector.h:866:9: runtime error: reference binding to null pointer of type 'char'

```
Breakpoint 2, 0x0000000000494894 in __ubsan_handle_type_mismatch_abort ()
(gdb) bt
```

Reviewed By: meyering, yfeldblum

Differential Revision: D3279234

fbshipit-source-id: 63a761587e5b3f79ece09fc99b9a593da0e44b75

8 years agoDeal with some oddities of MSVC's preprocessor
Christopher Dykes [Tue, 10 May 2016 00:23:41 +0000 (17:23 -0700)]
Deal with some oddities of MSVC's preprocessor

Summary: MSVC's preprocessor is different in how it deals with passing arguments expanded from `__VA_ARGS__`, so we have to add a stub to force it to expand the arguments.

Reviewed By: yfeldblum

Differential Revision: D3256328

fbshipit-source-id: 551434833d40e55498a9ab352eb74acdfd094835

8 years agoFix detection of std::make_unique under MSVC
Christopher Dykes [Tue, 10 May 2016 00:15:22 +0000 (17:15 -0700)]
Fix detection of std::make_unique under MSVC

Summary: MSVC doesn't define `__cplusplus` as a high enough value to trigger this, so add an explicit check for MSVC instead.

Reviewed By: yfeldblum

Differential Revision: D3271647

fbshipit-source-id: a1e5a5a7eb75dce066dfc7fae8b2086880dc4c3d

8 years agofolly: ubsan: &v[0] is undefined if v.empty()
Lucian Grijincu [Tue, 10 May 2016 00:03:34 +0000 (17:03 -0700)]
folly: ubsan: &v[0] is undefined if v.empty()

Summary:
before:

  [ RUN      ] RangeFunc.Vector
  bits/stl_vector.h:866:9: runtime error: reference binding to null pointer of type 'int'

Reviewed By: yfeldblum

Differential Revision: D3279253

fbshipit-source-id: 957a8ec050f5c3b27febf7e6cd16ad1d307da169

8 years agofolly test: fix typo in RandomDataHolder::RandomDataHolder
Jim Meyering [Mon, 9 May 2016 21:05:43 +0000 (14:05 -0700)]
folly test: fix typo in RandomDataHolder::RandomDataHolder

Summary:
Running the folly/io/test:compression_test with a UBSAN-enabled binary would fail with this:

  folly/io/test/CompressionTest.cpp:96:36: runtime error: shift exponent 16777216 is too large for 64-bit type 'size_t' (aka 'unsigned long')

That exposed the unwanted left-shift.
That made it so the actual "start" offsets were in the range [0..numThreads-1], rather than being
e.g., with numThreads == 8, [0, 1677721633554432, ...].  Oops.

Reviewed By: luciang

Differential Revision: D3277606

fbshipit-source-id: 4bc48f84b0065de070b62a810f08b96e36ea7136

8 years agoInclude <nmmintrin.h> in GroupVarint.h
Christopher Dykes [Mon, 9 May 2016 19:57:08 +0000 (12:57 -0700)]
Include <nmmintrin.h> in GroupVarint.h

Summary: Because it is the standard (well, Intel's standard) location for __m128i, and GCC, Clang, MSVC and ICC all implement it in that location.

Reviewed By: yfeldblum

Differential Revision: D3270872

fbshipit-source-id: fa0f0410670cdb310e656ca55ee0f568ca5ee06f

8 years agofolly: fbvector: ubsan: avoid memcpy(dest, nullptr, 0)
Lucian Grijincu [Mon, 9 May 2016 19:16:40 +0000 (12:16 -0700)]
folly: fbvector: ubsan: avoid memcpy(dest, nullptr, 0)

Reviewed By: meyering

Differential Revision: D3277138

fbshipit-source-id: 7050d18c256ac15c8122d4af59aa31208b1466fd

8 years agoExplicitly reference folly::detail
Christopher Dykes [Mon, 9 May 2016 18:36:40 +0000 (11:36 -0700)]
Explicitly reference folly::detail

Summary: Due to some fun with the order MSVC does name lookup in templates, it ends up complaining that these are ambigious between folly::detail and folly::recordio_helpers::detail. The solution is to simply reference folly::detail explicitly.

Reviewed By: yfeldblum

Differential Revision: D3271606

fbshipit-source-id: e599ad8d8fe33b1e4ec0b838ddb5dfacfdf60159

8 years agoFix a few issues in the portability headers
Christopher Dykes [Mon, 9 May 2016 18:36:21 +0000 (11:36 -0700)]
Fix a few issues in the portability headers

Summary:
This fixes a few issues in the portability headers for MSVC.
Not entirely sure how I managed to cause these in the first place, but this fixes them anyways.

Reviewed By: yfeldblum

Differential Revision: D3271859

fbshipit-source-id: 11a5d35246f29112563ee9079525aa37ced206ff

8 years agoReverted commit D3265572
Philip Pronin [Mon, 9 May 2016 07:06:57 +0000 (00:06 -0700)]
Reverted commit D3265572

Summary:
I would switch these to just use the intrinsic functions, but GCC 4.8 doesn't support them.
MSVC supports the intrinsics, which is the primary reason for the switch.

Reviewed By: yfeldblum

Differential Revision: D3265572

fb-gh-sync-id: 3268f90d5234bdf77b3579504efd3dcd43f38aff
fbshipit-source-id: 3268f90d5234bdf77b3579504efd3dcd43f38aff

8 years agoDon't re-throw exceptions from default FiberManager exception handler
Andrii Grynenko [Sat, 7 May 2016 05:02:15 +0000 (22:02 -0700)]
Don't re-throw exceptions from default FiberManager exception handler

Summary: It's very unlikely that caller will handle such exceptions and FiberManager can proceed even if one task failed. DFATAL will ensure we still fail on such exceptions in debug builds.

Reviewed By: yfeldblum

Differential Revision: D3273573

fb-gh-sync-id: 55eba19c16429a3c89a2fdf5363fd4b55b3998a2
fbshipit-source-id: 55eba19c16429a3c89a2fdf5363fd4b55b3998a2

8 years agoDon't throw on late singleton registration
Andrii Grynenko [Fri, 6 May 2016 17:26:04 +0000 (10:26 -0700)]
Don't throw on late singleton registration

Summary: Having singleton registered after registrationComplete() is called is not a hard failure. Replacing exception with ERROR, since we probably still want to avoid such situation.

Reviewed By: yfeldblum

Differential Revision: D3266376

fb-gh-sync-id: 8130d279775348c835265987c95189bd3d8106f9
fbshipit-source-id: 8130d279775348c835265987c95189bd3d8106f9

8 years agoUse intrinsics rather than inline assembly where possible
Christopher Dykes [Fri, 6 May 2016 16:32:30 +0000 (09:32 -0700)]
Use intrinsics rather than inline assembly where possible

Summary:
I would switch these to just use the intrinsic functions, but GCC 4.8 doesn't support them.
MSVC supports the intrinsics, which is the primary reason for the switch.

Reviewed By: yfeldblum

Differential Revision: D3265572

fb-gh-sync-id: f12d16b8f64cf48adcb97958d7ae88d56689a96f
fbshipit-source-id: f12d16b8f64cf48adcb97958d7ae88d56689a96f

8 years agoCreate the stdio.h portability header
Christopher Dykes [Fri, 6 May 2016 16:31:20 +0000 (09:31 -0700)]
Create the stdio.h portability header

Summary: Windows doesn't define a couple of functions.

Reviewed By: yfeldblum

Differential Revision: D2990676

fb-gh-sync-id: 1a1354bd7976cb8b4747436d6907d65210ba506c
fbshipit-source-id: 1a1354bd7976cb8b4747436d6907d65210ba506c

8 years agoBind to a random file in unix domain socket test
Haijun Zhu [Fri, 6 May 2016 09:20:30 +0000 (02:20 -0700)]
Bind to a random file in unix domain socket test

Summary:
test console reports "address already in use" failure so add some
randomness to it.

Reviewed By: yfeldblum

Differential Revision: D3265329

fb-gh-sync-id: a825cce787394783bb8d18d92385d2497b163385
fbshipit-source-id: a825cce787394783bb8d18d92385d2497b163385

8 years agoCreate the unistd.h portability header
Christopher Dykes [Fri, 6 May 2016 00:24:55 +0000 (17:24 -0700)]
Create the unistd.h portability header

Summary: Windows doesn't have it, and it's used in a lot of places.

Reviewed By: yfeldblum

Differential Revision: D2997499

fb-gh-sync-id: fbf8f5f087b8f39197d5bf2177e4d34efd74631f
fbshipit-source-id: fbf8f5f087b8f39197d5bf2177e4d34efd74631f

8 years agoAllow optional atfork hook for singleton destruction
Andrii Grynenko [Thu, 5 May 2016 23:41:33 +0000 (16:41 -0700)]
Allow optional atfork hook for singleton destruction

Summary: Grouping all folly::ThreadLocal atfork hooks in one. This allows proper ordering between folly::ThreadLocal hooks and hooks added by other libraries (we always want folly::ThreadLocal hooks to be registered first).

Reviewed By: ericniebler

Differential Revision: D3262666

fb-gh-sync-id: 1aa928b9ddd484580f4a4a7b320e9e64164bb04a
fbshipit-source-id: 1aa928b9ddd484580f4a4a7b320e9e64164bb04a

8 years agoImplement LoopKeepAlive for EventBase
Andrii Grynenko [Thu, 5 May 2016 20:22:42 +0000 (13:22 -0700)]
Implement LoopKeepAlive for EventBase

Summary: LoopKeepAlive can be useful to tell EventBase, that loop() shouldn't return even if there are no events registered, because some tasks will later be added via runInEventBaseThread. While at least one LoopKeepAlive is alive - EventBase::loop() behaves like EventBase::loopForever().

Reviewed By: yfeldblum

Differential Revision: D3261706

fb-gh-sync-id: d91424d3d12cae11abd72cffdbd57f136f628dae
fbshipit-source-id: d91424d3d12cae11abd72cffdbd57f136f628dae

8 years agoAllow adding tasks to TaskIterator dynamically
Andrii Grynenko [Thu, 5 May 2016 01:15:53 +0000 (18:15 -0700)]
Allow adding tasks to TaskIterator dynamically

Reviewed By: yfeldblum

Differential Revision: D3244669

fb-gh-sync-id: 73fa4ecb0432a802e67ef922255a896d96f32374
fbshipit-source-id: 73fa4ecb0432a802e67ef922255a896d96f32374

8 years agoSwitch gflags to portability/GFlags.h
Michael Lee [Thu, 5 May 2016 00:08:47 +0000 (17:08 -0700)]
Switch gflags to portability/GFlags.h

Summary:
There are two places that still includes gflags/gflags.h:
portability/GFlags.h and futures/exercises/Koan.h. Also removing
gflags entirely from a couple of places which never reference it at
all.

Reviewed By: yfeldblum

Differential Revision: D3203187

fb-gh-sync-id: e7725fbf2c4b3c475c0035e1b0e8c6e1227f277f
fbshipit-source-id: e7725fbf2c4b3c475c0035e1b0e8c6e1227f277f

8 years agoCreate the stdlib.h portability header
Christopher Dykes [Wed, 4 May 2016 23:45:56 +0000 (16:45 -0700)]
Create the stdlib.h portability header

Summary: Windows doesn't have these functions under these names, so be nice to the code using it.

Reviewed By: yfeldblum

Differential Revision: D3003641

fb-gh-sync-id: 1657545af6975c96aea4a48c359250828b5921e0
fbshipit-source-id: 1657545af6975c96aea4a48c359250828b5921e0

8 years agoCreate the fcntl.h portability header
Christopher Dykes [Wed, 4 May 2016 23:45:53 +0000 (16:45 -0700)]
Create the fcntl.h portability header

Summary: Windows has it, but all it does is define a few constants.

Reviewed By: yfeldblum

Differential Revision: D3002161

fb-gh-sync-id: a719faf391125522b2cb21471a56e8a9fe894225
fbshipit-source-id: a719faf391125522b2cb21471a56e8a9fe894225

8 years agorearrange folly::Function so that its template arguments are deducable.
Eric Niebler [Wed, 4 May 2016 21:45:20 +0000 (14:45 -0700)]
rearrange folly::Function so that its template arguments are deducable.

Summary:
`folly::Function` was an alias to a more complex type with template arguments that could not be deduced. For example, the call to `foo` below was failing to compile.

```
template <class R, class... As>
void foo(folly::Function<R(As...)> f) {
}

int main() {
  foo( folly::Function<void(int)>{ [](int i){} } );
}
```

Rearrange the code so that folly::Function is no longer an alias, thus making its template arguments deducable.

Reviewed By: luciang, spacedentist

Differential Revision: D3256130

fb-gh-sync-id: fb403e48d161635b3b7f36e53b1679eb46cbfe7f
fbshipit-source-id: fb403e48d161635b3b7f36e53b1679eb46cbfe7f

8 years agofolly::Future integration with Python
Andrii Grynenko [Wed, 4 May 2016 21:32:54 +0000 (14:32 -0700)]
folly::Future integration with Python

Summary:
This diff implements two functions which can be used to bridge C++ asynchronous APIs with Python.
1. getExecutor(event_loop) allows extracting a folly::Executor-compatible object from Python event_loop.
2. wrapFuture wraps any folly::Future object in a Python Future object.

Reviewed By: ambv

Differential Revision: D2878731

fb-gh-sync-id: 83628b6b24d6039999f88c5de441e41064b2417e
fbshipit-source-id: 83628b6b24d6039999f88c5de441e41064b2417e

8 years agoFix the weak references to JEMalloc under MSVC
Christopher Dykes [Wed, 4 May 2016 17:29:15 +0000 (10:29 -0700)]
Fix the weak references to JEMalloc under MSVC

Summary: While the previous version did compile, it would generate warnings about symbols being defined in multiple places.

Reviewed By: yfeldblum

Differential Revision: D3255815

fb-gh-sync-id: 72f5079a3973a04bdc0b469b97ba46181e40353b
fbshipit-source-id: 72f5079a3973a04bdc0b469b97ba46181e40353b

8 years agoImplement __builtin_ctzll for MSVC
Christopher Dykes [Wed, 4 May 2016 17:28:49 +0000 (10:28 -0700)]
Implement __builtin_ctzll for MSVC

Summary: MSVC doesn't have it, but Folly uses it, so implement it in the Builtins portability header.

Reviewed By: yfeldblum

Differential Revision: D3256123

fb-gh-sync-id: fd9ea1b6098d97cf1fde4732905bae9bde8cd8ad
fbshipit-source-id: fd9ea1b6098d97cf1fde4732905bae9bde8cd8ad

8 years agoDon't initialize kDestroyWaitTime in-class
Christopher Dykes [Wed, 4 May 2016 17:28:12 +0000 (10:28 -0700)]
Don't initialize kDestroyWaitTime in-class

Summary: MSVC doesn't like it when you try to initialize a static in-class non-primitive constexpr member. It was only used in one place, so stick the definition in that function instead.

Reviewed By: yfeldblum

Differential Revision: D3255178

fb-gh-sync-id: e4a862a2662c4f5376c19fc52827cb2953f01e52
fbshipit-source-id: e4a862a2662c4f5376c19fc52827cb2953f01e52

8 years agoUse std::thread::id in Fiber rather than a syscall
Christopher Dykes [Wed, 4 May 2016 17:27:25 +0000 (10:27 -0700)]
Use std::thread::id in Fiber rather than a syscall

Summary: syscall() doesn't exist on Windows, but std::thread::id is standardized, and can do what we need it for, so use it instead.

Reviewed By: yfeldblum

Differential Revision: D3256064

fb-gh-sync-id: efddac82c117ccd8a53c8c93248529000b4326a5
fbshipit-source-id: efddac82c117ccd8a53c8c93248529000b4326a5

8 years agoDon't attempt to implicitly convert an atomic<T> to bool
Christopher Dykes [Wed, 4 May 2016 17:26:43 +0000 (10:26 -0700)]
Don't attempt to implicitly convert an atomic<T> to bool

Summary: MSVC doesn't like it, so the other uses were changed to .load() explicitly a while back, but this use has been added since then.

Reviewed By: yfeldblum

Differential Revision: D3255261

fb-gh-sync-id: 11d49902eb3ef7113a7c57cc760353554a487496
fbshipit-source-id: 11d49902eb3ef7113a7c57cc760353554a487496

8 years agoUnpoison stack memory before deallocation
Marcus Holland-Moritz [Wed, 4 May 2016 10:28:44 +0000 (03:28 -0700)]
Unpoison stack memory before deallocation

Summary:
This is a workaround (maybe even the correct fix if it turns out that ASan
can't detect this FP case) for the problem described in

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

where a memory region previously allocated by a fiber stack can overlap with
the region of an mmap'd file. Accessing parts of the mmap'd file close to
the stack region will trigger a false positive ASan error.

This change makes sure each fiber explicitly unpoisons its stack memory by
calling __asan_unpoison_memory_region in an ASan-enabled build.

Reviewed By: yhfung

Differential Revision: D3257924

fb-gh-sync-id: 484062e80af67dfd39d2eaf3cbb52fa3483924eb
fbshipit-source-id: 484062e80af67dfd39d2eaf3cbb52fa3483924eb

8 years agoOptimize copy/move
Pavlo Kushnir [Wed, 4 May 2016 07:27:53 +0000 (00:27 -0700)]
Optimize copy/move

Summary: this diff provides methods that allow to avoid temporaries while cloning IOBufs. Also optimizes move constructor a bit - there is no need to call `decrementRefCount`, check for self assignment, etc.

Reviewed By: yfeldblum

Differential Revision: D3250456

fb-gh-sync-id: 32b0180c28f36151c6786dba6f511b491b224200
fbshipit-source-id: 32b0180c28f36151c6786dba6f511b491b224200

8 years agoLet via take a functor by universal reference
Yedidya Feldblum [Wed, 4 May 2016 04:32:23 +0000 (21:32 -0700)]
Let via take a functor by universal reference

Summary:
[Folly] Let `via` take a functor by universal reference.

And perfect-forward the functor to the call to `then`.

Reviewed By: fugalh

Differential Revision: D3255684

fb-gh-sync-id: 1b46a70fb9de88d21d785c0ce4d9dd3078829f13
fbshipit-source-id: 1b46a70fb9de88d21d785c0ce4d9dd3078829f13

8 years agoCreate the sockets portability header
Christopher Dykes [Wed, 4 May 2016 00:38:24 +0000 (17:38 -0700)]
Create the sockets portability header

Summary: The one header that doesn't split well. This is the last piece of the portability headers for Windows and is also the piece that has had the most thought put into it's design so-as to be as unintrusive as possible.

Reviewed By: yfeldblum

Differential Revision: D3046525

fb-gh-sync-id: 761a5e359bc130b95585608ee18fda94a30dae2c
fbshipit-source-id: 761a5e359bc130b95585608ee18fda94a30dae2c

8 years agoMore useful logging upon failed AsyncServerSocket::bind()
Marcelo Juchem [Tue, 3 May 2016 22:35:30 +0000 (15:35 -0700)]
More useful logging upon failed AsyncServerSocket::bind()

Summary: `AsyncServerSocket::bind()` would not give information like port or family name when failing to bind a socket. This diff addresses that by including this information in the exception. Two additional helper methods were added to `SocketAddress` to retrieve both the port and the family name from a `sockaddr` structure.

Reviewed By: ckwalsh, yfeldblum

Differential Revision: D3249778

fb-gh-sync-id: 4edb28af5c211b7bf8d525b40844a5b0b6261e07
fbshipit-source-id: 4edb28af5c211b7bf8d525b40844a5b0b6261e07

8 years agofix passing move-only types to via(Executor*, Func)
Sven Over [Tue, 3 May 2016 21:27:37 +0000 (14:27 -0700)]
fix passing move-only types to via(Executor*, Func)

Summary: This diff fixes a problem with passing move-only types to folly::via.

Reviewed By: ericniebler

Differential Revision: D3254906

fb-gh-sync-id: 8a9c703a8db0ccf20b9fb4fe9b80ad6cdcb3e388
fbshipit-source-id: 8a9c703a8db0ccf20b9fb4fe9b80ad6cdcb3e388

8 years agoDeprecate boost::mpl
Yedidya Feldblum [Tue, 3 May 2016 09:15:22 +0000 (02:15 -0700)]
Deprecate boost::mpl

Summary:
[Folly] Deprecate `boost::mpl`.

The `std` has equivalents; prefer them.

Reviewed By: Gownta

Differential Revision: D3247294

fb-gh-sync-id: 873697b7ea3ad069ff14662bc458a2e1cc840339
fbshipit-source-id: 873697b7ea3ad069ff14662bc458a2e1cc840339

8 years agoUse portability for SYS_gettid
Michael Lee [Mon, 2 May 2016 23:14:23 +0000 (16:14 -0700)]
Use portability for SYS_gettid

Summary: It's there for a reason, so use it.

Reviewed By: yfeldblum

Differential Revision: D3249849

fb-gh-sync-id: e9fe330693a173acd987e0c8fd1f03a982c8e082
fbshipit-source-id: e9fe330693a173acd987e0c8fd1f03a982c8e082

8 years agoDon't try to use the malloc_usable_size portability implementation if we have JEMalloc
Christopher Dykes [Mon, 2 May 2016 19:22:28 +0000 (12:22 -0700)]
Don't try to use the malloc_usable_size portability implementation if we have JEMalloc

Summary:
This is only an issue for the OSS HHVM build on OSX, where we have JEMalloc headers included directly.
In the OSS HHVM build, we define `USE_JEMALLOC` globally if we have JEMalloc, so gate the portability implementation behind that.

Reviewed By: mzlee

Differential Revision: D3237449

fb-gh-sync-id: 07cf9b31114723ffd9f2b29cf449bee0ed8f5703
fbshipit-source-id: 07cf9b31114723ffd9f2b29cf449bee0ed8f5703

8 years agoSet the appropriate AsyncSocketExceptionType from SSLException
Neel Goyal [Mon, 2 May 2016 16:30:18 +0000 (09:30 -0700)]
Set the appropriate AsyncSocketExceptionType from SSLException

Summary:
We should use the appropriate AsyncSocketExceptionType when firing SSLExceptions.  This derives the type from the constructor args, and introduces a `NETWORK_ERROR` exception type.  Open to suggestions on reusing something there.

Additionally, rename getType() to getSSLError() to prevent hiding the AsyncSocketException::getType.

Reviewed By: siyengar

Differential Revision: D3241204

fb-gh-sync-id: de631dfb3554177d5bd561f4b91e767c882767d3
fbshipit-source-id: de631dfb3554177d5bd561f4b91e767c882767d3

8 years agoSimplify CryptoSSLRequestManager using unified futures API
Anirudh Ramachandran [Mon, 2 May 2016 16:12:01 +0000 (09:12 -0700)]
Simplify CryptoSSLRequestManager using unified futures API

Summary:
This diff unifies the nearly-replicated call paths for ECDSA and RSA
sign request/response/fallback/etc. into one generic futures-based sign API.
Once this is tested, we should be able to remove ~500 lines of code from
CryptoSSLRequestManager

Depends on D3094660

Reviewed By: siyengar

Differential Revision: D3116535

fb-gh-sync-id: 11c50d81dab39e5426679b5a172c1ece2039fc10
fbshipit-source-id: 11c50d81dab39e5426679b5a172c1ece2039fc10

8 years agoAvoid glog when warning about Singleton double-registration
Yedidya Feldblum [Mon, 2 May 2016 09:26:07 +0000 (02:26 -0700)]
Avoid glog when warning about Singleton double-registration

Summary:
[Folly] Avoid glog when warning about `Singleton` double-registration.

Because registration happens at static initialization time, long before main, and possibly long before glog is initialized.

This makes a difference because, in some cases of double-registration, we can get a SIGSEGV with no message, because we are attempting to `LOG(FATAL)` when glog is uninitialized. What we would much rather have is a SIGABRT with a message.

Reviewed By: meyering

Differential Revision: D3245047

fb-gh-sync-id: 4c5dd9d25025f197d7c490ffbb429af5ccb82182
fbshipit-source-id: 4c5dd9d25025f197d7c490ffbb429af5ccb82182

8 years agoDon't require folly::Unit in addTaskFinally
Andrii Grynenko [Sat, 30 Apr 2016 00:50:50 +0000 (17:50 -0700)]
Don't require folly::Unit in addTaskFinally

Summary:
In D3241498 addTaskFuture was fixed to work with function returning void. This however changed addTaskFinally API to not allow finally functor which accepts Try<void>.

folly::fibers generally supports Try<void> so there's no reason to force users to use folly::Unit instead of void for addTaskFinally too.

Reviewed By: yfeldblum

Differential Revision: D3243893

fb-gh-sync-id: d1df54738157d2019120103956f59b3971ba25ff
fbshipit-source-id: d1df54738157d2019120103956f59b3971ba25ff

8 years agoMake addTask[Remote]Future() work for functions returning void.
Martin Martin [Fri, 29 Apr 2016 18:54:34 +0000 (11:54 -0700)]
Make addTask[Remote]Future() work for functions returning void.

Summary:
There's no Future<void>, you're supposed to use Future<Unit>
instead.  Unit has a "Lift" template to do the conversion.

Reviewed By: andriigrynenko

Differential Revision: D3241498

fb-gh-sync-id: db12d4f343685bc613b701e023c860c2c903ed4c
fbshipit-source-id: db12d4f343685bc613b701e023c860c2c903ed4c

8 years agoClang-format in preparation for other change
Martin Martin [Fri, 29 Apr 2016 17:50:23 +0000 (10:50 -0700)]
Clang-format in preparation for other change

Summary: Clang-format in preparation for other change

Reviewed By: andriigrynenko

Differential Revision: D3241297

fb-gh-sync-id: b7b26812e9e61c291d5c7bdb523df8f28f2d9b4f
fbshipit-source-id: b7b26812e9e61c291d5c7bdb523df8f28f2d9b4f

8 years agodon't destory defaultElfCache in exit handlers
Philip Pronin [Fri, 29 Apr 2016 00:21:06 +0000 (17:21 -0700)]
don't destory defaultElfCache in exit handlers

Summary:
As it might be used during global destruction (for example, to
symbolize unhandled exception happened at that time).

Reviewed By: luciang, ot

Differential Revision: D3238303

fb-gh-sync-id: 39d8a6f99d95e700586349436e961f3624c95718
fbshipit-source-id: 39d8a6f99d95e700586349436e961f3624c95718

8 years agouse std::forward instead of std::move on objects whose types have been deduced; don...
Eric Niebler [Thu, 28 Apr 2016 23:39:30 +0000 (16:39 -0700)]
use std::forward instead of std::move on objects whose types have been deduced; don't take the sizeof incomplete types

Summary: Pretty sure std::forward is needed here instead of std::move. If you trace the call chain to see where the types of the objects come from, you'll see they can be deduced to be lvalues, so std::forward is the right choice. Also, moved some dicey looking code that appeared to be taking the size of some incomkplete types.

Reviewed By: spacedentist

Differential Revision: D3214199

fb-gh-sync-id: 778190ffb25a648b839760a3dddfad8dc6d41c88
fbshipit-source-id: 778190ffb25a648b839760a3dddfad8dc6d41c88