6 years agoallow AsyncSignalHandler to attach and detach from an EventBase
Adam Simpkins [Tue, 27 Jun 2017 02:27:32 +0000 (19:27 -0700)]
allow AsyncSignalHandler to attach and detach from an EventBase

Add attachEventBase() and detachEventBase() methods to AsyncSignalHandler,
similar to the methods of AsyncSocket.

The main benefit of this is that it allows creating an AsyncSignalHandler with
an initially null EventBase, and then attaching it to an EventBase at some
later point in time.

Reviewed By: yfeldblum

Differential Revision: D5315325

fbshipit-source-id: 8a4ca483a62ca86837ea0bb54fa9a70d59f2f04e

6 years agomake io::Cursor::push() safe to call with an empty ByteRange
Adam Simpkins [Tue, 27 Jun 2017 02:15:05 +0000 (19:15 -0700)]
make io::Cursor::push() safe to call with an empty ByteRange

Clang's UndefinedBehaviorSanitizer flagged an issue that pushAtMost() could
call `memcpy(dest, nullptr, 0)` if the input was an empty `ByteRange`.  A
default constructed `ByteRange` (or `StringPiece`) will be empty and both its
begin and end pointers will be null.  Unfortunately it is undefined behavior to
call `memcpy()` with a null source pointer even if the length is 0.

This updates the `Cursor` and `Appender` code to avoid calling `memcpy()` at
all when the input length is 0.

Reviewed By: yfeldblum

Differential Revision: D5322917

fbshipit-source-id: 67fce9579f97e7e93a5767b11cc5e43ff7be5876

6 years agoImprove Format's handling of temporaries
Giuseppe Ottaviano [Mon, 26 Jun 2017 21:42:31 +0000 (14:42 -0700)]
Improve Format's handling of temporaries

`FormatValue` holds non-integral objects by reference, which
can cause subtle problems if a formatter is constructed with temporary
arguments and used beyond the expression that constructs it.

With this diff the arguments are perfectly forwarded into a tuple, so
the formatter will take ownership of the temporaries while holding
references to lvalues as before.

The only downside is that now `FormatValue` objects are constructed
every time the formatter is used, rather than only at formatter
construction. This should not be noticeable as those objects'
constructors should just take a reference to the argument.

Note that the format string is still held by reference, but this is
fine because it should almost always be a string literal.

Reviewed By: ericniebler

Differential Revision: D5317382

fbshipit-source-id: ef8355194b634d3751ef1ccca32dd1db29e27c48

6 years agoSupport marking a file-descriptor as blocking via fcntl
Christopher Dykes [Mon, 26 Jun 2017 21:39:26 +0000 (14:39 -0700)]
Support marking a file-descriptor as blocking via fcntl

Summary: Previously, only marking it as non-blocking was supported.

Reviewed By: simpkins

Differential Revision: D5307769

fbshipit-source-id: 03ed7c35632dbc9551552b21c401ea709bd6eaaa

6 years agoEdited folly synchronized doc because one of the functions was incorrect
Marie Bremner [Mon, 26 Jun 2017 21:21:01 +0000 (14:21 -0700)]
Edited folly synchronized doc because one of the functions was incorrect

Summary: Edited the example function for withWLock

Reviewed By: simpkins

Differential Revision: D5322000

fbshipit-source-id: 6d95b173087dec33cfdc0d0cee9c605cdf4e2593

6 years agoLet make_exception_wrapper construct on-heap objects in-place
Yedidya Feldblum [Mon, 26 Jun 2017 20:22:19 +0000 (13:22 -0700)]
Let make_exception_wrapper construct on-heap objects in-place

[Folly] Let `make_exception_wrapper` construct on-heap objects in-place.

Currently, it constructs on-heap objects on the stack and then move-constructs them into on-heap storage.

Reviewed By: ericniebler

Differential Revision: D5315104

fbshipit-source-id: cc0493e7d98aacadd342eb56601028ced4a19bb3

6 years agoFix SharedPromise::isFulfilled doesn't get back correct value when it's running in...
Bi Xue [Mon, 26 Jun 2017 19:19:40 +0000 (12:19 -0700)]
Fix SharedPromise::isFulfilled doesn't get back correct value when it's running in a different thread of SharedPromise::setValue

Summary: The implementation of `SharedPromise::isFulfilled` return `hasValue_` directly without taking a lock. `isFulfilled` can be accessed concurrently, but `hasValue_` is not synchronized. Adding a lock fix the issue.

Reviewed By: yfeldblum

Differential Revision: D5319030

fbshipit-source-id: a94b12ed277aa64254680ae84cb18946226cceea

6 years agoResolve the circular dependency between ThreadLocalDetail and ThreadLocal
Christopher Dykes [Mon, 26 Jun 2017 18:42:42 +0000 (11:42 -0700)]
Resolve the circular dependency between ThreadLocalDetail and ThreadLocal

Summary: There was a circular dependency between the `detail/ThreadLocalDetail.(cpp|h)` files and `ThreadLocal.(cpp|h)`, this resolves that circular dependency by moving a couple of declarations into the detail file.

Reviewed By: yfeldblum

Differential Revision: D5318875

fbshipit-source-id: 61de7c4b3ffa30f9eb11bd97e0493e9de12c5804

6 years agoRevert D5312574: [folly] Fix up and namespace clock_gettime and clock_getres for... v2017.06.26.01
Christopher Dykes [Mon, 26 Jun 2017 17:25:00 +0000 (10:25 -0700)]
Revert D5312574: [folly] Fix up and namespace clock_gettime and clock_getres for MacOS

Summary: This reverts commit f16634ce92ee6c299613d3db22f0537bd31ac14d

Differential Revision: D5312574

fbshipit-source-id: 1557ac17f79fb8e3530a09d69fa978ddd38e5093

6 years agoImprove efficiency of trivial toDelim calls
Phil Willoughby [Mon, 26 Jun 2017 14:08:25 +0000 (07:08 -0700)]
Improve efficiency of trivial toDelim calls

`toDelim` with a single parameter of the same type as the target type was
previously copy-constructing its result. It will now construct it with perfect
forwarding which is more efficient if the input is a temporary.

This brings `toDelim` into line with the similar implementations of `to` and

Reviewed By: yfeldblum

Differential Revision: D5301427

fbshipit-source-id: 843a2d93384de88cce42f26da6562a1a6ed0dc9c

6 years agoExplicitly specify that timezone is a struct v2017.06.26.00
Christopher Dykes [Sun, 25 Jun 2017 00:00:32 +0000 (17:00 -0700)]
Explicitly specify that timezone is a struct

Summary: In the parameter declarations for the `gettimeofday` portability header implementation. More details on exactly why can be found in the newly added comment on the function.

Reviewed By: yfeldblum

Differential Revision: D5281301

fbshipit-source-id: 1b246adc7743b5470201e452c008418429f7f142

6 years agoExclude experimental/logging/example from the main folly_base rule
Christopher Dykes [Sat, 24 Jun 2017 23:59:30 +0000 (16:59 -0700)]
Exclude experimental/logging/example from the main folly_base rule

Summary: It's an example, not part of the main Folly library.

Reviewed By: yfeldblum

Differential Revision: D5304985

fbshipit-source-id: 7cfb95da5795af61e9307882f71836ef7fa5a463

6 years agoSplit the futures and logging tests in the CMake build
Christopher Dykes [Sat, 24 Jun 2017 23:58:33 +0000 (16:58 -0700)]
Split the futures and logging tests in the CMake build

Summary: They are intended to be run as separate sets of tests, and the logging tests define multiple mains.

Reviewed By: yfeldblum

Differential Revision: D5307503

fbshipit-source-id: ed38a762177cec3c600791b861584dd47019b5a9

6 years agoFix up and namespace clock_gettime and clock_getres for MacOS
Michael Lee [Sat, 24 Jun 2017 03:11:14 +0000 (20:11 -0700)]
Fix up and namespace clock_gettime and clock_getres for MacOS

Resolve two issues with folly's clock_gettime() shim on Apple platforms (iOS, macOS, etc.):

When detecting whether folly should define clock_gettime() on Apple platforms, don't assume clock_gettime() is declared in Apple's headers just because MAC_OS_X_VERSION_10_12/__IPHONE_10_0 is defined. Someone might use a newer macOS or iOS SDK (which defines MAC_OS_X_VERSION_10_12/__IPHONE_10_0), but not have clock_gettime() (because _DARWIN_FEATURE_CLOCK_GETTIME isn't set).

When defining a shim for clock_gettime(), don't rely on Apple's clock_gettime() declaration. Instead, shadow Apple's declaration with our own. This prevents folly from inheriting Apple's availability and visibility attributes for clock_gettime().

Reviewed By: yfeldblum

Differential Revision: D5312574

fbshipit-source-id: f16634ce92ee6c299613d3db22f0537bd31ac14d

6 years agoMove address caching logic from AsyncSSLSocket to AsyncSocket.
Kyle Nekritz [Fri, 23 Jun 2017 22:51:53 +0000 (15:51 -0700)]
Move address caching logic from AsyncSSLSocket to AsyncSocket.

Summary: So that it is available on other transports.

Reviewed By: Orvid

Differential Revision: D5302039

fbshipit-source-id: cbfdadd158061ed9a2b3ed3e0960ce66f0d545fd

6 years agofix UBSAN failure in atomic_shared_ptr_test
Ilya Maykov [Fri, 23 Jun 2017 22:43:48 +0000 (15:43 -0700)]
fix UBSAN failure in atomic_shared_ptr_test

Summary: Fix UBSAN failure in atomic_shared_ptr_test by using reinterpret_cast instead of static_cast.

Reviewed By: yfeldblum

Differential Revision: D5314116

fbshipit-source-id: 8479c9c4bdeeb155067a3de75efe4e97c36519e5

6 years agoMoveOnly utility
Giuseppe Ottaviano [Fri, 23 Jun 2017 22:19:01 +0000 (15:19 -0700)]
MoveOnly utility

Summary: Same as `boost::noncopyable` but it does not disable move constructor/assignment.

Reviewed By: luciang

Differential Revision: D5311043

fbshipit-source-id: 44fe95712169b95a00e474385be43fa857cfd8ec

6 years agoFix AsyncFileWriterTest due to long being 32-bit on Windows
Christopher Dykes [Fri, 23 Jun 2017 21:13:19 +0000 (14:13 -0700)]
Fix AsyncFileWriterTest due to long being 32-bit on Windows

Summary: `long` is only 32-bits on Windows, which means this call to `std::min` was ambiguous, which caused a compile error.

Reviewed By: simpkins

Differential Revision: D5305964

fbshipit-source-id: 7e4152006e163a0301652be46318f0fc937e5ead

6 years agoFix exception_wrapper on Windows by abusing internals
Andrew Krieger [Fri, 23 Jun 2017 20:58:11 +0000 (13:58 -0700)]
Fix exception_wrapper on Windows by abusing internals

exception_wrapper's non-allocating variant was depending
on the exception reference being a reference to a heap object,
which is not the case on Windows. All thrown exceptions are
copied to the stack first.

So, we abuse internals of exception_ptr to get the internally
heap allocated copy of the object. What could possibly go wrong.

Reviewed By: yfeldblum, ericniebler, Orvid

Differential Revision: D5270634

fbshipit-source-id: 2983a6af9a2c3cb66cbee8a382707a76b582c489

6 years agomove input shared_ptr in atomic_shared_ptr constructor
Ilya Maykov [Fri, 23 Jun 2017 18:32:32 +0000 (11:32 -0700)]
move input shared_ptr in atomic_shared_ptr constructor

Summary: By moving the input shared_ptr instead of copying it, we avoid doing an unnecessary ref count increment + decrement.

Reviewed By: djwatson, yfeldblum

Differential Revision: D5298467

fbshipit-source-id: b9f0b6999278609417bb4dc062030ca2388ba20a

6 years agoFix GlogFormatterTest on Windows
Christopher Dykes [Fri, 23 Jun 2017 02:55:36 +0000 (19:55 -0700)]
Fix GlogFormatterTest on Windows

It was missing a portability header needed for `setenv`, and was assuming that the `system_clock` was represented as nanoseconds.
On Windows `std::chrono::system_clock` is represented as 100s of nanoseconds, ie. `FILETIME`.

Reviewed By: simpkins

Differential Revision: D5308182

fbshipit-source-id: facb922ebe1587723358b38499dadac683e3517b

6 years agoStop MSVC from complaining about digraphs not being supported
Christopher Dykes [Fri, 23 Jun 2017 01:09:20 +0000 (18:09 -0700)]
Stop MSVC from complaining about digraphs not being supported

Summary: MSVC complains about `<:` being a digraph and that it isn't interpreting it as one (C4628). Make it be quiet by making it not look like a digraph.

Reviewed By: simpkins

Differential Revision: D5305162

fbshipit-source-id: 7385164e8f73226ce18bc04c32894c2f27f8ae25

6 years agoSwitch the logging tests from .native() to .string()
Christopher Dykes [Fri, 23 Jun 2017 01:08:23 +0000 (18:08 -0700)]
Switch the logging tests from .native() to .string()

Summary: These were using `boost::filesystem::path.native()` in contexts where an `std::string` was the expected output. `boost::filesystem::path.native()` returns a `std::wstring` on Windows, so use `.string()` instead.

Reviewed By: simpkins

Differential Revision: D5305649

fbshipit-source-id: 3c7cd53d2f33d2dbb222731655cdab69d1c4a187

6 years agoFix ThreadName.cpp on Windows
Christopher Dykes [Fri, 23 Jun 2017 01:07:39 +0000 (18:07 -0700)]
Fix ThreadName.cpp on Windows

Summary: I failed to realize that this helper function also needs to be guarded on `!_WIN32`, because the assertions are false on Windows.

Reviewed By: ot, luciang

Differential Revision: D5304914

fbshipit-source-id: f2564cb2fcbfdc73a2529d4a41df2995748bc3f6

6 years agoEnable more auto-deps in Folly
Christopher Dykes [Fri, 23 Jun 2017 01:06:21 +0000 (18:06 -0700)]
Enable more auto-deps in Folly

Summary: This enables auto-deps support in more places in Folly. It also fixes a couple of auto-deps declarations that were missing an `s`.

Reviewed By: yfeldblum

Differential Revision: D5289542

fbshipit-source-id: 7d34b29bcc172fb31f91f1ba880864e2d5869ffd

6 years agoallow passing function pointers to Future::onError()
Adam Simpkins [Thu, 22 Jun 2017 20:39:56 +0000 (13:39 -0700)]
allow passing function pointers to Future::onError()

Add appropriate specializations for detail::Extract() so that you can pass a
plain function pointer to `onError()`.  Previously the code only worked with
member function pointers and functor-style objects.

Reviewed By: yfeldblum, wez

Differential Revision: D5286773

fbshipit-source-id: 67b44d1d7573eb1da501475045fd24ad4ab1c074

6 years agologging: fix issues detecting XLOG(FATAL) statements as noreturn
Adam Simpkins [Thu, 22 Jun 2017 18:44:38 +0000 (11:44 -0700)]
logging: fix issues detecting XLOG(FATAL) statements as noreturn

Update the FB_LOG() and XLOG() macros so that FATAL log messages are correctly
detected as not returning, by both clang and gcc.

We have to ensure that both sides of the log statement check (log message
enabled or disabled) evaluate to `[[noreturn]]` expressions.  I did try
updating the log check itself so that it could be constexpr detected as always
passing, but this was not sufficient.

Reviewed By: wez

Differential Revision: D5290780

fbshipit-source-id: 773a56a8392dfd7c310d5d84fc9311e66edf99cb

6 years agoAsyncSSLSocket connect without SSL
Aaron Balsara [Thu, 22 Jun 2017 18:26:36 +0000 (11:26 -0700)]
AsyncSSLSocket connect without SSL

Currently when calling connect with AsyncSSLSocket in unencrypted
mode it still attempts to perform a SSL handshake. Add check to not
do SSL. Calling sslConnect will always run the SSL handshake

Reviewed By: jrahman

Differential Revision: D5153456

fbshipit-source-id: 4d9164115be72c8ee76e383535561e3083a327e3

6 years agologging: improve the AsyncFileWriter flush test()
Adam Simpkins [Thu, 22 Jun 2017 03:38:47 +0000 (20:38 -0700)]
logging: improve the AsyncFileWriter flush test()

This test has run into occasional failures on continuous build test runs.
Unfortunately when something goes wrong it crashes in the std::thread
destructor due to this thread still being joinable when it is destroyed, which
hides information about what actually failed in the test.

This updates the test to immediately detach the thread, so that on error we
will be able see the real failure reason.

This also increases the size of the message that we write, which will hopefully
help ensure that this write always blocks.

Reviewed By: wez

Differential Revision: D5295574

fbshipit-source-id: ea8cfa855613398f88f9f982c600ec661018a31c

6 years agologging: fully convert the ERROR level to ERR
Adam Simpkins [Thu, 22 Jun 2017 00:23:21 +0000 (17:23 -0700)]
logging: fully convert the ERROR level to ERR

Switch all code in the logging library from using `ERROR` to `ERR`,
and remove the `ERROR` LogLevel entirely, even if it is not already
defined as a macro.

Previously the code kept `ERROR` available as a LogLevel name if it had
not already been defined as a macro (which is done by common Windows header
files).  However, this made for inconsistent behavior, and made it easy to
write code that would not be portable to Windows.

This diff fully drops the `ERROR` name for consistency across platforms.

Reviewed By: wez

Differential Revision: D5288600

fbshipit-source-id: 8d2d52e955959c278345fc9c2086c7cacf9660f9

6 years agologging: add more tests for fatal log messages
Adam Simpkins [Thu, 22 Jun 2017 00:05:20 +0000 (17:05 -0700)]
logging: add more tests for fatal log messages

Add some tests for fatal log messages during static initialization and
destruction.  Ideally most programs won't actually do much real work before or
after main, but make sure the logging framework behaves sanely in these

This also fixes a bug in the `test_none()` test, which previously caused it to
always succeed without testing the desired behavior.

Reviewed By: wez

Differential Revision: D5281718

fbshipit-source-id: ca838c098886e99418264acf9a4d651ea9e7502c

6 years agoAdd support for move operations on hazptr-holder. Other optimizations.
Maged Michael [Wed, 21 Jun 2017 22:56:45 +0000 (15:56 -0700)]
Add support for move operations on hazptr-holder. Other optimizations.

- Support empty hazptr_holder, move constructor and assignment operator
- Limit thread caching to the default domain to improve performance of thread caching
- Fix unnecessary calls to stats singleton
- Use the mprotect version of AsymmetricMemoryBarrier for reducing the overhead of bulkReclaim().
- Update read-side benchmark results

Reviewed By: djwatson

Differential Revision: D5292885

fbshipit-source-id: bc5713ac95492a7114e1e467e71d2278e64b165d

6 years agologging: shorten output of logLevelToString()
Adam Simpkins [Wed, 21 Jun 2017 20:23:28 +0000 (13:23 -0700)]
logging: shorten output of logLevelToString()

Remove the "LogLevel::" prefix from the logLevelToString() output.

This makes the output shorter and easier to read, and makes it simpler to write
LogFormatter implementations that want a short human-readable level
description.  Callers can always add a "LogLevel::" prefix on their own if

Reviewed By: wez

Differential Revision: D5288601

fbshipit-source-id: 046579ebdda76842d5a44c33d68941d73dd81162

6 years agoPrint expected/actual thread names when running EventBase logic in unexpected thread
Giuseppe Ottaviano [Wed, 21 Jun 2017 19:28:52 +0000 (12:28 -0700)]
Print expected/actual thread names when running EventBase logic in unexpected thread

Summary: The existing assertion errors do not give a lot of information to track down which thread is incorrectly using the `EventBase`. Print both the current thread name and the name of the thread running the event base loop.

Reviewed By: luciang

Differential Revision: D5289790

fbshipit-source-id: 563c7f68b7f9b7a6e85e22290d7e81afbf89871e

6 years agoCall onRecycle after element is marked as deallocated in IndexedMemPool
Victor Zverovich [Wed, 21 Jun 2017 18:38:32 +0000 (11:38 -0700)]
Call onRecycle after element is marked as deallocated in IndexedMemPool

Summary: Make `IndexedMemPool` call `Traits::onRecycle` on the element just before it is marked as deallocated. This mirrors the allocation behavior implemented in D5177462 and simplifies preventing access to recycled elements (the client just needs to check `isAllocated` before accessing the element).

Reviewed By: nbronson

Differential Revision: D5275283

fbshipit-source-id: 58365b5b7b32b07fa56529c476078f241fc20811

6 years agoShift the exception tracer benchmark and test into the test directory
Christopher Dykes [Wed, 21 Jun 2017 18:22:23 +0000 (11:22 -0700)]
Shift the exception tracer benchmark and test into the test directory

Summary: Tests and benchmarks don't belong in the same directory as source code.

Reviewed By: yfeldblum

Differential Revision: D5288080

fbshipit-source-id: 865c6dfbeff751bda49870e5284e168d33aff256

6 years agoAdd flags to asymmetric mem barrier
Dave Watson [Wed, 21 Jun 2017 17:54:54 +0000 (10:54 -0700)]
Add flags to asymmetric mem barrier

Original sys_membarrier call supported an EXPEDITED flag, that was much faster than the current version, at some extra CPU cost.

The basic idea was a normal one would be used in a background thread, while EXPEDITED would be useful inline in foreground threads.

Add the flag here, and use the mprotect hack until sys_membarrier supports both.

Reviewed By: magedm

Differential Revision: D5292680

fbshipit-source-id: 30edf27514976991bbaa8e776a7138eb815ade36

6 years agoHave reserved sockopt to disable TSOCKS
Petr Lapukhov [Wed, 21 Jun 2017 14:41:46 +0000 (07:41 -0700)]
Have reserved sockopt to disable TSOCKS

Summary: as title, similar to TTLS

Reviewed By: djwatson

Differential Revision: D5284200

fbshipit-source-id: 7eb95668740b239349c6e73f3b152e6506671072

6 years agoAdd missing uint32 type to folly::ProgramOptions::gFlagAdders
Uladzislau Paulovich [Wed, 21 Jun 2017 13:19:44 +0000 (06:19 -0700)]
Add missing uint32 type to folly::ProgramOptions::gFlagAdders

Summary: Absence of "uint32" type in gFlagAdders map breaks all apps that use gflags of this type (i.e. define a flag with "DEFINE_uint32").

Reviewed By: WillerZ

Differential Revision: D5286720

fbshipit-source-id: c02bd959cb9ea9a47fba1e01429181ba09edf5dd

6 years agoAdd support for getting other threads' names
Giuseppe Ottaviano [Wed, 21 Jun 2017 06:03:57 +0000 (23:03 -0700)]
Add support for getting other threads' names

Summary: Complete the `ThreadName.h` API.

Reviewed By: luciang, Orvid

Differential Revision: D5289160

fbshipit-source-id: a48e61093008039da50b1c568364fa5b8744b401

6 years agologging: reduce the amount of code emitted for log statements
Adam Simpkins [Wed, 21 Jun 2017 02:44:20 +0000 (19:44 -0700)]
logging: reduce the amount of code emitted for log statements

This refactors the logging code with the aim of reducing the amount of assembly
code emitted for each log statement, particularly for `XLOG()` statements.
Ideally it should be possible to put debug `XLOG()` statements throughout your
code without having to worry about the performance overhead.  Therefore we
should attempt to make sure that `XLOG()` statements do not generate a lot of
assembly and hurt icache performance.

This diff does not have any code behavior changes--it just moves code around a
bit.  The high-level summary is:

- Move as much code as possible into the LogStreamProcessor constructors and
  destructor.  Make sure these methods are defined in LogStreamProcessor.cpp to
  avoid having them be emitted inline at each log statement.
- Move some of the XLOG level checking logic into separate non-inline functions
  defined in xlog.cpp
- Pass xlog category information around as a pair of (categoryName,
  isOverridden) parameters.  If isOverridden is true then the categoryName
  parameter should be used as the category name directly.  If isOverridden is
  false, then categoryName is a filename that needs to go through filename to
  category name string processing.  This allows the category name processing to
  be done in non-inlined code.

Reviewed By: wez

Differential Revision: D5269976

fbshipit-source-id: 7a7877ddfed66cd27ed82f052330b6aa2be4b37b

6 years agologging: add printf-style logging macros
Adam Simpkins [Wed, 21 Jun 2017 02:44:18 +0000 (19:44 -0700)]
logging: add printf-style logging macros

Add new `FB_LOGC()` and `XLOGC()` macros that accept C-style printf format
strings.  (The `FB_LOGF()` and `XLOGF()` macro names are already used for
`folly::format()` style formatting.)

This will make it easier for users to update existing printf-style code to use
this new logging library.

These are in a separate `printf.h` header file that must be explicitly included
to have access to these macros.  The intent is to encourage users to use one of
the other APIs (streaming, append-style, or `folly::format()`) instead of these
printf-like APIs in new code.

Reviewed By: omry

Differential Revision: D5269974

fbshipit-source-id: 56e55f9642bb00806d9b4c762fb6a91778ef6ad3

6 years agologging: make XLOG_GET_CATEGORY() safe for all callers
Adam Simpkins [Wed, 21 Jun 2017 02:44:17 +0000 (19:44 -0700)]
logging: make XLOG_GET_CATEGORY() safe for all callers

The `XLOG_GET_CATEGORY()` macro was previously written assuming it was only
used inside `XLOG()` statement.  When used inside the main translation unit
being compiled (e.g., a .cpp file and not a header file), the code assumed that
the file-scope category had already been initialized, since a level check had
presumably already been performed.

However, it is useful in some places for external users (outside of the logging
library itself) to call `XLOG_GET_CATEGORY()`.  In these cases a log level
check may not have been performed yet, so the file-scope category may not be
initialized yet.

This diff renames the existing `XLOG_GET_CATEGORY()` macro to
`XLOG_GET_CATEGORY_INTERNAL()` and adds a new `XLOG_GET_CATEGORY()` macro that
is slower (it always looks up the category by name) but always safe to use.

This also adds a new `XLOG_GET_CATEGORY_NAME()` macro, and renames the existing
`XLOG_SET_CATEGORY()` macro to `XLOG_SET_CATEGORY_NAME()` for API consistency.

Reviewed By: wez

Differential Revision: D5269975

fbshipit-source-id: 373805255823855282fa7a8d4a4d232ba06367f6

6 years agologging: improve the AsyncFileWriterTest discard test
Adam Simpkins [Wed, 21 Jun 2017 02:44:16 +0000 (19:44 -0700)]
logging: improve the AsyncFileWriterTest discard test

This improves the test that exercises the AsyncFileWriter message discarding

Previously each writer thread wrote a fixed number of small messages.  This was
fairly slow, and wasn't always guaranteed to reliably produce discards.
Now each writer thread writes larger messages, which produce discards faster.
The test also automatically stops after 10 separate discard events, so that it
finishes faster (typically a few hundred milliseconds, rather than 5+ seconds).

This also updates the test to use XLOG() internally rather than using fprintf()
to print to stderr, now that the XLOG() diffs have landed.

Reviewed By: wez

Differential Revision: D5261059

fbshipit-source-id: 120224706fee36948ef76efbeb579ccc56400c51

6 years agologging: implement FATAL and DFATAL log levels
Adam Simpkins [Tue, 20 Jun 2017 21:01:59 +0000 (14:01 -0700)]
logging: implement FATAL and DFATAL log levels

Add new `FATAL` and `DFATAL` log levels.

Any log message with a level of `FATAL` always crashes the program.  Log
messages with a level of `DFATAL` crash the program in debug build modes.

Before crashing, the code makes sure to flush all LogHandlers, so that the
fatal message is not lost if some of the LogHandlers process messages
asynchronously.  If no LogHandlers were configured, the message is printed to

Reviewed By: wez

Differential Revision: D5189497

fbshipit-source-id: c45dbd582fb1c3a962d00effb2967737ef97cc8b

6 years agoUpdate hazard pointer interface to standard proposal P0233R4
Maged Michael [Tue, 20 Jun 2017 19:10:45 +0000 (12:10 -0700)]
Update hazard pointer interface to standard proposal P0233R4

Updated to the interface to be in synch with the latest standard proposal in P0233R4 as follows:
- Renamed hazptr_owner as hazptr_holder.
- Combined hazptr_holder member functions set() and clear() as reset().
- Replaced the template parameter A for hazptr_holder member function templates try_protect() and get_protected with atomic<T*>.
- Moved the template parameter T from the class hazptr_holder to its member functions try_protect(), get_protected(), and reset().
- Added a non-template overload of hazptr_holder::reset() with an optional nullptr_t parameter.
- Removed the template parameter T from the free function swap() as hazptr_holder is no longer a template.

Reviewed By: davidtgoldblatt

Differential Revision: D5283863

fbshipit-source-id: 2bc1a09f4f844aa72d9b7dff9c450540bbe09972

6 years agofix folly::FunctionScheduler.cancelFunctionAndWait() hanging issue
Qi Zhou [Tue, 20 Jun 2017 18:36:53 +0000 (11:36 -0700)]
fix folly::FunctionScheduler.cancelFunctionAndWait() hanging issue

- only one function is scheduled in FunctionScheduler; and
- the function is running while cancelFunctionAndWait() is being called;
FunctionScheduler.cancelFunctionAndWait() will hang forever.  The root cause is that the condition in cancelFunctionAndWait() is incorrect:

runningCondvar_.wait(l, [currentFunction, this]() {
  return currentFunction != currentFunction_;

because currentFunction will not be changed if only one function is in the scheduler.

The fix here is to
- clear currentFunction as nullptr.  This also makes the internal behaviors of cancelFunction() and cancelFunctionAndWait() consistent.
- introduces additional variable to indicate the state of cancelling current function.  After running the function, the background thread will detect cancellation of current function and clear the variable.
- cancelFunctionAndWait() condition variable will wait for the variable to be cleared.

Similarly, cancelAllFunctionsAndWait() also suffers from the same issue.

Unit tests are added to reproduce the issue.

Reviewed By: yfeldblum

Differential Revision: D5271664

fbshipit-source-id: acb223304d3eab23129907ce9ff5e57e55f1e909

6 years agologging: add LoggerDB::flushAllHandlers()
Adam Simpkins [Tue, 20 Jun 2017 18:02:00 +0000 (11:02 -0700)]
logging: add LoggerDB::flushAllHandlers()

Add a method to flush all LogHandler objects.

This will be necessary to implement FB_LOG(FATAL), as we will want to flush all
outstanding messages before crashing.

Reviewed By: wez

Differential Revision: D5189501

fbshipit-source-id: faf260b8e71e5dfed4a3b1c1aee32f072bd7b764

6 years agologging: add a LogHandler::flush() call
Adam Simpkins [Tue, 20 Jun 2017 18:01:57 +0000 (11:01 -0700)]
logging: add a LogHandler::flush() call

Add a flush() call to the LogHandler interface.  This is needed to implement
`FB_LOG(FATAL)` so that we can flush all LogHandlers before aborting the

Reviewed By: wez

Differential Revision: D5189499

fbshipit-source-id: 75fa4d7e75ea26de5b7383bf7e8d073fb37e9309

6 years agologging: add a NEVER_DISCARD flag to LogWriter
Adam Simpkins [Tue, 20 Jun 2017 18:01:55 +0000 (11:01 -0700)]
logging: add a NEVER_DISCARD flag to LogWriter

Add a flag to the LogWriter so we can ensure that particular messages are never
discarded, even when the LogWriter is throttling messages.

This functionality will be necessary to implement `FB_LOG(FATAL)` to that we
can avoid discarding the reason for crashing.

Reviewed By: wez

Differential Revision: D5189498

fbshipit-source-id: dc4322ea5ba449a341cdbdc32afb0ed466019801

6 years agologging: add a small example program
Adam Simpkins [Tue, 20 Jun 2017 18:01:53 +0000 (11:01 -0700)]
logging: add a small example program

This adds a small example program which demonstrates using the logging library.

This gives a very basic example of how the library is intended to be used, and
can also be used to play around with controlling the log levels from the
command line argument.

Reviewed By: wez

Differential Revision: D5083104

fbshipit-source-id: ab09c6c88db33065f6e39f35b28014f2a6153cef

6 years agoDelete folly/futures/OpaqueCallbackShunt.h
Christopher Dykes [Tue, 20 Jun 2017 17:11:42 +0000 (10:11 -0700)]
Delete folly/futures/OpaqueCallbackShunt.h

Summary: It is not used anywhere, not even in tests, so kill it.

Reviewed By: yfeldblum

Differential Revision: D5280800

fbshipit-source-id: 7e6a308bf09198548b77dcc1bfacc0ee95eb4887

6 years agoRevert D5278412: [Folly] Merge StringBase.cpp and String.cpp
Christopher Dykes [Tue, 20 Jun 2017 04:23:56 +0000 (21:23 -0700)]
Revert D5278412: [Folly] Merge StringBase.cpp and String.cpp

Summary: This reverts commit 07639e155421f31a6cc7ed16cba2034750e44325

Differential Revision: D5278412

fbshipit-source-id: 4b4d60f1f472ebe2e68e8eea1a31f42bc55c60ed

6 years agoMerge StringBase.cpp and String.cpp
Christopher Dykes [Tue, 20 Jun 2017 00:24:45 +0000 (17:24 -0700)]
Merge StringBase.cpp and String.cpp

Summary: The only reason these were split was because of the use of `folly::format`

Reviewed By: yfeldblum

Differential Revision: D5278412

fbshipit-source-id: 07639e155421f31a6cc7ed16cba2034750e44325

6 years agoSwitch pid_t to be defined as int rather than void*
Christopher Dykes [Tue, 20 Jun 2017 00:23:19 +0000 (17:23 -0700)]
Switch pid_t to be defined as int rather than void*

Summary: Because an `int` plays much much nicer with code already written for Windows than `void*` does. It takes quite a bit of hackery to make it possible with the pthread implementation we support using, but it is possible and is worth the effort.

Reviewed By: yfeldblum

Differential Revision: D5276968

fbshipit-source-id: 4cd0d3120a4f19976e76853ef4b337e96d5005a8

6 years agoMake semaphore.h a non-portable header
Christopher Dykes [Mon, 19 Jun 2017 21:34:21 +0000 (14:34 -0700)]
Make semaphore.h a non-portable header

Summary: On Windows it has include order requirements.

Reviewed By: yfeldblum

Differential Revision: D5277151

fbshipit-source-id: a6cf923d78e5944ac34e885e32a7cf072f904720

6 years agoDocument the preferred alternatives in Foreach.h
Phil Willoughby [Mon, 19 Jun 2017 12:51:34 +0000 (05:51 -0700)]
Document the preferred alternatives in Foreach.h

Reviewed By: yfeldblum

Differential Revision: D5228760

fbshipit-source-id: bcad4237997e611e06c93b476c5b673dc93c0621

6 years agoFix the build of detail/CacheLocality.h on Windows
Christopher Dykes [Mon, 19 Jun 2017 07:04:43 +0000 (00:04 -0700)]
Fix the build of detail/CacheLocality.h on Windows

Summary: It was broken by D5139886 which added a call to `std::__throw_bad_alloc` without first including the correct portability header.

Reviewed By: yfeldblum

Differential Revision: D5273016

fbshipit-source-id: cac1772f41ae5942a29cefa69fb07d9cf94b5aab

6 years agoFix the CMake build with tests enabled
Christopher Dykes [Mon, 19 Jun 2017 05:42:40 +0000 (22:42 -0700)]
Fix the CMake build with tests enabled

Summary: I broke it when I moved the stats tests around.

Reviewed By: yfeldblum

Differential Revision: D5258526

fbshipit-source-id: 70982ffaaed89a548e943e4b011b013c89808666

6 years agoMake DestructorCheck::Safety no-copy, no-move v2017.06.19.00
Alan Frindell [Mon, 19 Jun 2017 04:01:03 +0000 (21:01 -0700)]
Make DestructorCheck::Safety no-copy, no-move

Summary: It's not safe because of how it manipulates the linked list.  The intended usage is to declare it locally on the stack

Reviewed By: yfeldblum

Differential Revision: D5267507

fbshipit-source-id: 07a55eaee2c6a266bb233432f6a3383236594195

6 years agoFix a few exception_wrapper tests under MSVC
Christopher Dykes [Sun, 18 Jun 2017 18:14:46 +0000 (11:14 -0700)]
Fix a few exception_wrapper tests under MSVC

Summary: They were incorrectly comparing against string literals rather than the actual demangled names. MSVC includes `class/struct` as part of the mangled name, so they also appear in the demangled name, in contrast to GCC/Clang, which don't.

Reviewed By: yfeldblum

Differential Revision: D5271087

fbshipit-source-id: 41fa0cebe098b1b935e1f8b1af5882c412cf6254

6 years agoworking and warning tweak for UninitializedMemoryHacks
Nathan Bronson [Sat, 17 Jun 2017 16:49:56 +0000 (09:49 -0700)]
working and warning tweak for UninitializedMemoryHacks

Improve documentation and use the correct pragma for warning
on the unsupported path.

Reviewed By: ot

Differential Revision: D5264582

fbshipit-source-id: 710ee46fef6d8f37f665f4bb6f7e4c5dc0b27436

6 years agoRevert D4567233: [Folly] Drop support for Clang < 3.9
Christopher Dykes [Fri, 16 Jun 2017 20:59:23 +0000 (13:59 -0700)]
Revert D4567233: [Folly] Drop support for Clang < 3.9

Summary: This reverts commit cd94c711f0390d249b6736ab292721a477022b02

Differential Revision: D4567233

fbshipit-source-id: a10aff6b4c231666aec9f40ab65e881c3cd870dc

6 years agoImprove get_fiber_manager_map_*() error reporting
Peter DeLong [Fri, 16 Jun 2017 17:32:35 +0000 (10:32 -0700)]
Improve get_fiber_manager_map_*() error reporting

get_fiber_manager_map_vevb() and get_fiber_manager_map_evb() don't
provide very useful feedback when called with an empty map (just the former) or
with a program that doesn't have debug symbols (both)

Reviewed By: andriigrynenko

Differential Revision: D5260114

fbshipit-source-id: c44b4e279e5c88dc08507b969339a4befc23d79b

6 years agoFix class member shadowing in folly::ProducerConsumerQueue
Uladzislau Paulovich [Fri, 16 Jun 2017 09:27:40 +0000 (02:27 -0700)]
Fix class member shadowing in folly::ProducerConsumerQueue

Summary: Previous version failed to compile with "-Werror=shadow" flag, this commit fixes the problem.

Reviewed By: WillerZ

Differential Revision: D5255814

fbshipit-source-id: c1252474ed5415b47759022bcbabc78c1639e10a

6 years agoRemove the relative comparison operators on LogLevel
Christopher Dykes [Fri, 16 Jun 2017 08:12:53 +0000 (01:12 -0700)]
Remove the relative comparison operators on LogLevel

Summary: MSVC, GCC, and Clang define the relative comparison operators by default on `enum class` values, however under MSVC defining them explicitly causes the compiler to fail to resolve which operator to use, so just remove them entirely, as they aren't needed.

Reviewed By: simpkins

Differential Revision: D5259835

fbshipit-source-id: 1b91db5de0fc47320daabfdd7132ae910887ff0f

6 years agoDon't declare caught exceptions when not actually used
Christopher Dykes [Fri, 16 Jun 2017 02:47:37 +0000 (19:47 -0700)]
Don't declare caught exceptions when not actually used

Summary: There are a couple of places where the caught exception was being given a name that was never used, generating a warning under MSVC.

Reviewed By: simpkins

Differential Revision: D5260131

fbshipit-source-id: f82c6bd1266f6a4c916594ec3ac94edc9a2e48fe

6 years agoDon't try to use _CrtDbgReport in the logging framework
Christopher Dykes [Thu, 15 Jun 2017 23:54:38 +0000 (16:54 -0700)]
Don't try to use _CrtDbgReport in the logging framework

Summary: Glog doesn't try to, so there's no real reason to try and be smart. Just do the same thing as every other platform for now until we have reason to do otherwise.

Reviewed By: simpkins

Differential Revision: D5259435

fbshipit-source-id: dcdf55f51f2e13945afd351cb45e9c1a22f56218

6 years agoEnsure LogWriter::writeMessage(std::string&&) is in the overload set of ImmediateFile...
Christopher Dykes [Thu, 15 Jun 2017 23:53:09 +0000 (16:53 -0700)]
Ensure LogWriter::writeMessage(std::string&&) is in the overload set of ImmediateFileWriter

Summary: As MSVC correctly warns via C4266, the overload sets of functions in base classes are not part of the overload set in derived classes where you've declared an overload (or override) unless you've explicitly imported it.

Reviewed By: simpkins

Differential Revision: D5260056

fbshipit-source-id: bbbeeea3c13201a3a6eba6e62cfa5a49a9470d43

6 years agoInclude the time portability header in GlogStyleFormatter.cpp
Christopher Dykes [Thu, 15 Jun 2017 23:52:29 +0000 (16:52 -0700)]
Include the time portability header in GlogStyleFormatter.cpp

Summary: It is needed on Windows for the `localtime_r` function.

Reviewed By: simpkins

Differential Revision: D5259944

fbshipit-source-id: e380ecf42252ecabec168cf87668ace3ff4c0a9f

6 years agoExplicitly initialize the base class of LogStream
Christopher Dykes [Thu, 15 Jun 2017 23:51:24 +0000 (16:51 -0700)]
Explicitly initialize the base class of LogStream

The standard does not define that `std::ostream` should have a default constructor, so this was invalid and was an error on Windows.
This explicitly initializes the base class by passing a `nullptr`.

Reviewed By: simpkins

Differential Revision: D5259690

fbshipit-source-id: b8914d73ff2682e1a4447b8338860259778b2247

6 years agoFix Observable to not trigger unneccessary refresh if the value didn't change
Andrii Grynenko [Thu, 15 Jun 2017 21:37:41 +0000 (14:37 -0700)]
Fix Observable to not trigger unneccessary refresh if the value didn't change

Differential Revision: D5251218

fbshipit-source-id: 1ceb37dd727e8ac2fd842e2c437cdaa9017221c8

6 years agofix issues with the open source tests
Adam Simpkins [Thu, 15 Jun 2017 18:28:06 +0000 (11:28 -0700)]
fix issues with the open source tests

Fix build problems in the open source Makefiles that cause issues when running
`make check`

- The test subdirectory needs to be processed before experimental, since some
  tests in experimental/ depend on libfollytestmain from test/
- The stats/test Makefile had an incorrectly copy-and-pasted line for
  libgtest_la_SOURCES but didn't actually build a library.
- The test/ Makefile defined thread_id_test but forgot to add it to TESTS so
  that it would actually be run as part of "make check"

Reviewed By: Orvid

Differential Revision: D5249132

fbshipit-source-id: 5a71e1f72a39d5407b843a5876891c67238ec006

6 years agologging: add initialization convenience functions
Adam Simpkins [Thu, 15 Jun 2017 18:04:00 +0000 (11:04 -0700)]
logging: add initialization convenience functions

Add a logging/Init.h header file with a couple convenience functions for
initializing log levels and log handlers.

This is pretty basic for now, but simplifies usage for small programs that just
want to easily initialize the logging library.

Reviewed By: wez

Differential Revision: D5083106

fbshipit-source-id: 73c1fd00df2eaf506b9c1485d6afd12570412a0f

6 years agologging: add GlogStyleFormatter
Adam Simpkins [Thu, 15 Jun 2017 18:03:58 +0000 (11:03 -0700)]
logging: add GlogStyleFormatter

Add a LogFormatter implementation that logs messages using a similar format to
the glog library.

Reviewed By: wez

Differential Revision: D5083108

fbshipit-source-id: 75f0a6b78ce5406b4557d6c4394f033d5e019f71

6 years agologging: add AsyncFileWriter
Adam Simpkins [Thu, 15 Jun 2017 18:03:57 +0000 (11:03 -0700)]
logging: add AsyncFileWriter

Add an AsyncFileWriter class that implements the LogWriter interface using a
separate I/O thread to write the log messages to a file descriptor.

This LogWriter implementation ensures that normal process threads will never
block due to logging I/O.  By default it will buffer up to 1MB of data.  If
log messages are generated faster than they can be written to the file, log
messages will be discarded once the buffer limit is exceeded.  The LogWriter
will emit a message into the file recording how many messages were discarded
where the dropped messages should have been.

The downside of this class is that unwritten log messages still in the buffer
will be lost when the program crashes.

Reviewed By: wez

Differential Revision: D5083107

fbshipit-source-id: c67226f4d0726675d480b03eae83a29c5c3431b2

6 years agologging: add ImmediateFileWriter
Adam Simpkins [Thu, 15 Jun 2017 18:03:55 +0000 (11:03 -0700)]
logging: add ImmediateFileWriter

Add an ImmediateFileWriter class that implements the LogWriter interface by
immediately writing data it receives to a file descriptor.

This LogWriter implementation can be used by users that want to ensure log
messages are immediately flushed to a file as soon as they are written, at the
expense of possibly having logging I/O block their normal process threads.

Reviewed By: wez

Differential Revision: D5083105

fbshipit-source-id: 15cd071834e1784fe50e1d6d6ce403b9bc907047

6 years agologging: add a LoggerDB::internalWarning() function
Adam Simpkins [Thu, 15 Jun 2017 18:03:52 +0000 (11:03 -0700)]
logging: add a LoggerDB::internalWarning() function

A few places in the logging code need to report issues when something goes
wrong in the logging code itself.  This adds a new LoggerDB::internalWarning()
method for use in these places.

This provides a default implementation that logs these warnings with
_CrtDbgReport() on Windows, and writes to stderr on non-Windows platforms.
The default implementation can also be overridden for programs that want some
alternative behavior.

Reviewed By: wez

Differential Revision: D5157731

fbshipit-source-id: e27f5587d58b3941fca8d5b38c8c3edbcb75d7f3

6 years agologging: add new RateLimiter helper class
Adam Simpkins [Thu, 15 Jun 2017 18:03:50 +0000 (11:03 -0700)]
logging: add new RateLimiter helper class

Add a new RateLimiter API to the logging library, to support rate limiting
messages in the future.  I have included a single IntervalRateLimiter
implementation in this diff.  In the future we can add more implementations if
necessary, to mimic the functionality available with our older logging code, to
make it easier for users to convert to the new framework.

Note that RateLimiter is inside a `folly::logging` namespace, unlike most of
the other code in the logging library that lives directly in the `folly`
namespace.  I intentionally chose this since RateLimiter is a fairly generic
class name, and I wanted to distinguish it from other possible generic class
names in folly.  On the other hand, most of the other class names already start
with `Log`, so there seems to be no need to put them in a `logging` namespace.

Nothing is using this new API yet, but I will use it for some internal logging
APIs in an upcoming diff.  Later on I also plan to use it to implement
per-LogCategory rate limiting, and possibly per-LogHandler rate limiting.

Reviewed By: wez

Differential Revision: D5162805

fbshipit-source-id: 9b81c2f4544006cd392152a768296bce0c5daaa1

6 years agologging: add LogFormatter and LogWriter interfaces
Adam Simpkins [Thu, 15 Jun 2017 18:03:48 +0000 (11:03 -0700)]
logging: add LogFormatter and LogWriter interfaces

This simplifies the LogHandler interface to a single generic `handleMessage()`,
and adds a `StandardLogHandler` implementation that defers to separate
`LogFormatter` and `LogWriter` objects.

The `LogFormatter` class is responsible for serializing the `LogMessage` object
into a string, and `LogWriter` is responsible for then doing something with
the serialized string.

This will make it possible in the future to have separate `LogWriter`
implementations that all share the same log formatting code.  For example, this
will allow separate `LogWriter` implementations for performing file I/O
immediately versus performing I/O asynchronously in a separate thread.

Reviewed By: yfeldblum

Differential Revision: D5083103

fbshipit-source-id: e3f5ece25e260c825d49a5eb30e942973d6b68bf

6 years agologging: add XLOG() and XLOGF() logging macros
Adam Simpkins [Thu, 15 Jun 2017 18:03:46 +0000 (11:03 -0700)]
logging: add XLOG() and XLOGF() logging macros

This adds new `XLOG()` and `XLOGF()` macros to the logging library.  These are
similar to `FB_LOG()` and `FB_LOGF()`, but do not require a Logger argument.
Instead, the log category is picked automatically based on the current file
name.  The basic algorithm for picking the category name is to replace
directory separators with '.', and to strip off the filename extension.

For instance, all `XLOG()` statements in `src/foo/bar.cpp` will log to the
category ``.  This also works correctly in header files: `XLOG()`
statements in `src/foo/mylib.h` will log to ``

This should generally result in a good log category hierarchy without the user
having to spend additional time picking category names--we simply re-use the
decisions that they already made for their directory layout.

In general I expect the `XLOG()` macros to be convenient enough that users will
use `XLOG()` in almost all cases rather than using `FB_LOG()`.

The log category name used by `XLOG()` statements can be overridden using
`XLOG_SET_CATEGORY()`, but this only works in .cpp files, not in header files.

Reviewed By: wez

Differential Revision: D4920257

fbshipit-source-id: 7ffafd9a4c87e6fb5eb35d86e0eb86ef1ed5be95

6 years agoAdd thread caching of hazard pointers. Benchmarks. Minor fixes, optimizations, and...
Maged Michael [Thu, 15 Jun 2017 17:43:26 +0000 (10:43 -0700)]
Add thread caching of hazard pointers. Benchmarks. Minor fixes, optimizations, and refactoring.

Added support for thread caching of hazard pointers.
Added thread caching benchmarks.
Removed function call from hazptr_domain constexpr constructor.
Optimizations of memory order and code refactoring.

Reviewed By: davidtgoldblatt

Differential Revision: D5249070

fbshipit-source-id: 487fb23abccde228c3c726de4ac8e9f07bfa9498

6 years agoFix a memory leak in 1.1.0 related to initial_ctx
Neel Goyal [Thu, 15 Jun 2017 14:51:57 +0000 (07:51 -0700)]
Fix a memory leak in 1.1.0 related to initial_ctx

Summary: We would always up_ref the ctx before setting it as the initial_ctx.  This causes a leak in 1.1.0 since the initial_ctx isn't set in this version of OpenSSL.  We'll move the up_ref for the initial_ctx into the OpenSSLUtils helper.

Reviewed By: anirudhvr

Differential Revision: D5227823

fbshipit-source-id: b4490b317bd4dc8752a8d7e244fd153100a52aa6

6 years agofix rest of non-portable includes
James Sedgwick [Thu, 15 Jun 2017 06:03:28 +0000 (23:03 -0700)]
fix rest of non-portable includes

Summary: According to internal linter

Reviewed By: Orvid

Differential Revision: D5051010

fbshipit-source-id: febdeca05ac1cf3ad82617169f90912a445cf173

6 years agoFixing opt-asan/ubsan fail for folly contbuild
Jonathan Kron [Wed, 14 Jun 2017 15:46:15 +0000 (08:46 -0700)]
Fixing opt-asan/ubsan fail for folly contbuild

Summary: Flag caused compilation error on unused param, asserts optimized out in opt-asan/ubsan builds.  Replaced with DCHECK as per meyering's advice.

Reviewed By: meyering

Differential Revision: D5246089

fbshipit-source-id: dc0abda91f900dd98af31410f4667c52404997f5

6 years agoAdd fuzz testing
Nick Terrell [Tue, 13 Jun 2017 21:04:08 +0000 (14:04 -0700)]
Add fuzz testing

Summary: `ZSTD_decompress()` doesn't verify the uncompressed length in the frame as I thought, so throw an exception instead of `DCHECK()`.

Reviewed By: meyering

Differential Revision: D5234576

fbshipit-source-id: f72cf085a7267de32ce13553ce7ebbfe3b8a3f05

6 years agoremove misleading comment in Partial.h
Sven Over [Tue, 13 Jun 2017 16:17:06 +0000 (09:17 -0700)]
remove misleading comment in Partial.h

The removed comment cites a gcc compiler bug as a reason to spell
out the return type of the three operator() methods. While that
compiler bug can lead to compiler errors in some situations,
it is not the only reason why we need the return type arrow

If the compiler tries to instantiate operator() with a set of
parameters that the embedded function does not accept, then the
substitution failure is inside decltype, which is not a compiler
error (SFINAE) but just means that the Partial class doesn't define
operator() for that parameter signature. Without decltype, the body
of operator() is ill-formed and that is a compiler error.

Reviewed By: meyering

Differential Revision: D5236537

fbshipit-source-id: 7daa0fbcf128a2c7c5c36532a5402deba394e1b8

6 years agoAdd toFullyQualifiedAppend() methods
Nick Terrell [Tue, 13 Jun 2017 06:12:42 +0000 (23:12 -0700)]
Add toFullyQualifiedAppend() methods

Summary: A common use case for `IPAddress::toFullyQualified()` is to print a `<ip>:<port>` string. It is faster to reserve enough space for both beforehand than create 2 strings.

Reviewed By: yfeldblum

Differential Revision: D5224454

fbshipit-source-id: 4536f89a9d51d39dd9fd970c753ecb8ecced5d22

6 years agoFix decompression of truncated data
Nick Terrell [Tue, 13 Jun 2017 02:00:54 +0000 (19:00 -0700)]
Fix decompression of truncated data

Summary: During decompression, when the data is truncated, `StreamCodec::doUncompress()` loops forever, since it doesn't check forward progress. `Bzip2Codec` does the same.

Reviewed By: chipturner

Differential Revision: D5233052

fbshipit-source-id: 8797a7f06d9afa494eea292a8a5dc980c7571bd0

6 years agologging: if folly::format() fails, also log the arguments
Adam Simpkins [Tue, 13 Jun 2017 01:33:06 +0000 (18:33 -0700)]
logging: if folly::format() fails, also log the arguments

If the folly::sformat() call fails in an FB_LOGF() statement, make a
best-effort attempt to log the format arguments as well, in addition to the
format string.  For each argument, folly::to<std::string>() is use if it is
supported for this argument.

This will help ensure that the arguments that were being logged aren't lost
even if the format string was incorrect.

Reviewed By: WillerZ

Differential Revision: D5082978

fbshipit-source-id: 0d56030e639cd7e8f2242bb43646ab4248c6a877

6 years agologging: add support for streaming operators
Adam Simpkins [Tue, 13 Jun 2017 01:33:05 +0000 (18:33 -0700)]
logging: add support for streaming operators

Update the logging library so that FB_LOG() and FB_LOGF() also accept
streaming style arguments:

  FB_LOG(logger) << "logs can be written like this now: " << 1234;
  FB_LOG(logger, "both styles can be used") << " together";
  FB_LOGF(logger, "test: {}, {}", 1234, 5678) << " and with FB_LOGF() too";

Streaming support does make the upcoming XLOG() macros more complicated to
implement, since the macro has to expand to a single ternary `?` expression.
However I was able to come up with a solution that works and has minimal

Reviewed By: wez

Differential Revision: D5082979

fbshipit-source-id: 11734e39c02ad28aceb44bbfbd137d781caa30cf

6 years agoadd a new logging library
Adam Simpkins [Tue, 13 Jun 2017 01:33:03 +0000 (18:33 -0700)]
add a new logging library

This begins adding a new logging library for efficient, hierarchical logging.

This includes the basic library framework, plus a README file with a brief
overview and the motivation for creating a new logging library.

Reviewed By: wez

Differential Revision: D4911867

fbshipit-source-id: 359623e11feeaa547f3ac2c369bf806ee6996554

6 years agofix build due to stats test refactor
Theo Najim [Mon, 12 Jun 2017 18:27:38 +0000 (11:27 -0700)]
fix build due to stats test refactor

Summary: Closes

Differential Revision: D5228342

Pulled By: Orvid

fbshipit-source-id: edb81284a0401a4ea267310e1ca01c390bcdfb32

6 years agofix FutexTest v2017.06.12.00
Tianjiao Yin [Sat, 10 Jun 2017 05:03:48 +0000 (22:03 -0700)]
fix FutexTest

Summary: 2_ms seems too short. I am not sure whether it's feasible to check whether thread is waiting for an address. We could wait for longer to reduce false alarm.

Reviewed By: nbronson

Differential Revision: D5220819

fbshipit-source-id: 42f31206e9cb7f9addaa049d0e7cd995f6735f6c

6 years agoLet SubprocessError inherit std::runtime_error
Yedidya Feldblum [Sat, 10 Jun 2017 03:19:01 +0000 (20:19 -0700)]
Let SubprocessError inherit std::runtime_error

[Folly] Let `SubprocessError` inherit `std::runtime_error`.

As an added bonus, this gives it `std::runtime_error`'s refcounted string for cheap copies.

Reviewed By: ericniebler

Differential Revision: D5216758

fbshipit-source-id: 43298e06f02cfd88abf2d73f7aa16117a6cb052b

6 years agoReorganize the stats directory
Christopher Dykes [Sat, 10 Jun 2017 02:48:51 +0000 (19:48 -0700)]
Reorganize the stats directory

Summary: The source and tests for the stats directory was spread across folly/detail and folly/test, move them into folly/stats directly instead.

Reviewed By: yfeldblum

Differential Revision: D5216810

fbshipit-source-id: 00a8bb95a4f7830d0bc46b3f914f256a37833b78

6 years agoapply clang-tidy modernize-use-override
Victor Gao [Fri, 9 Jun 2017 18:26:26 +0000 (11:26 -0700)]
apply clang-tidy modernize-use-override

Summary: Use clang-tidy to mechanically add missing `override` and remove redundant `virtual`.

Reviewed By: igorsugak

Differential Revision: D5211868

fbshipit-source-id: 6a85f7c4a543a4c9345ec5b0681a8853707343dc

6 years agoapply clang-tidy modernize-use-override
Victor Gao [Fri, 9 Jun 2017 18:23:25 +0000 (11:23 -0700)]
apply clang-tidy modernize-use-override

Summary: Use clang-tidy to mechanically add missing `override` and remove redundant `virtual`.

Reviewed By: igorsugak

Differential Revision: D5211868

fbshipit-source-id: 4118c4c72f8ec3485507f69679f7e852b3eaeb73

6 years agoSaner test exception in ExceptionWrapperTest.cpp
Yedidya Feldblum [Fri, 9 Jun 2017 06:45:51 +0000 (23:45 -0700)]
Saner test exception in ExceptionWrapperTest.cpp

[Folly] Saner test exception in `ExceptionWrapperTest.cpp`.

Make construction do the work and make `what()` free.

Reviewed By: andrewjcg

Differential Revision: D5216707

fbshipit-source-id: bfb4c2473a61ff7da7a3a01adc85facae30d6586

6 years agoSome more OpenSSL 1.1.0 compat APIs
Anirudh Ramachandran [Fri, 9 Jun 2017 06:06:24 +0000 (23:06 -0700)]
Some more OpenSSL 1.1.0 compat APIs

Summary: Add a few more compatibility wrappers for pre-1.1.0 APIs

Reviewed By: yfeldblum

Differential Revision: D5194164

fbshipit-source-id: ae8db08c31370eca729df2927798b6f4d99ee70c