folly.git
10 years agoOnly run eventfd tests on Linux.
Peter Griess [Thu, 26 Sep 2013 14:20:24 +0000 (09:20 -0500)]
Only run eventfd tests on Linux.

Summary:
- Detect Linux and define the HAVE_LINUX autoconf macro. Use this to
elide eventfd tests in tests/Makefile.am.

Test Plan:
- fbconfig -r folly && fbmake runtests
- ./configure && make check on Ubuntu/FC/Mac

Reviewed By: delong.j@fb.com

FB internal diff: D998507

10 years agoFix ifunc test in configure.ac to make unknown attribute warnings fatal.
Peter Griess [Tue, 10 Sep 2013 20:33:09 +0000 (15:33 -0500)]
Fix ifunc test in configure.ac to make unknown attribute warnings fatal.

Summary:
- By default, GCC only warns on unknown attributes. As a result our
FOLLY_HAVE_IFUNC test doesn't actually catch instances where we don't
support this.

Test Plan:
- fbconfig -r folly && fbmake runtests
- ./configure && make check on Ubuntu/FC/Mac

Reviewed By: oyamauchi@fb.com

FB internal diff: D998506

10 years agoPass 'nostdinc' to AM_INIT_AUTOMAKE().
Peter Griess [Fri, 20 Sep 2013 21:00:49 +0000 (16:00 -0500)]
Pass 'nostdinc' to AM_INIT_AUTOMAKE().

Summary:
- On hosts with case-insensitive filesystems, adding folly/ directory to
the include path causes String.h to get picked up as <string.h>. Add
'nostdinc' to the AM_INIT_AUTOMAKE() invocation to remove these
standard includes from the set of compile flags.

Test Plan:
- fbconfig -r folly && fbmake runtests
- ./configure && make check on Ubuntu/FC/Mac

Reviewed By: delong.j@fb.com

FB internal diff: D998505

10 years agoClean up use of Boost and PThread libraries.
Peter Griess [Mon, 23 Sep 2013 16:47:58 +0000 (09:47 -0700)]
Clean up use of Boost and PThread libraries.

Summary:
- Use AM_LDFLAGS rather than AM_CXXFLAGS to link against Boost.
- Link against $(BOOST_REGEX_LIB) in addition to other Boost libs.
- Add $(BOOST_LDFLAGS) to AM_LDFLAGS so that we get the library path
that we configured Boost to use.
- Add -lpthread to AM_LDFLAGS rather than ad-hoc '-lpthread' additions
to various library builds.

Test Plan:
- fbconfig -r folly && fbmake runtests
- ./configure && make check on Ubuntu/FC/Mac

Reviewed By: oyamauchi@fb.com

FB internal diff: D998504

10 years agoAdd missing ax_boost_system.m4.
Peter Griess [Mon, 23 Sep 2013 22:48:56 +0000 (17:48 -0500)]
Add missing ax_boost_system.m4.

Summary:
- Link ConcurrentSkiplistBenchmark with $(BOOST_SYSTEM_LIB) to resolve
linker errors for boost::system symbols.

Test Plan:
- fbconfig -r folly && fbmake runtests
- ./configure && make check on Ubuntu/FC/Mac

Reviewed By: oyamauchi@fb.com

FB internal diff: D998503

10 years agoAdded initializer_list ctors to sorted_vector_{set,map}
Soren Lassen [Fri, 27 Sep 2013 19:23:06 +0000 (12:23 -0700)]
Added initializer_list ctors to sorted_vector_{set,map}

Test Plan: unittest

Reviewed By: tudorb@fb.com

FB internal diff: D987910

10 years agoSupport constexpr StringPiece.
Soren Lassen [Sun, 29 Sep 2013 00:53:52 +0000 (17:53 -0700)]
Support constexpr StringPiece.

Test Plan: fbconfig folly/test --platform=gcc-4.8.1-glibc-2.17 && fbmake dbg _bin/folly/test/range_test && _bin/folly/test/range_test

Reviewed By: tudorb@fb.com

FB internal diff: D989142

10 years agoAdd MaxString<__uint128_t>
Tim Hanson [Thu, 3 Oct 2013 20:17:10 +0000 (13:17 -0700)]
Add MaxString<__uint128_t>

Summary: For GCC 3.6+, define a template specialization for MaxString<__uint128_t>.

@override-unit-failures

Test Plan: Unit tests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D995290

10 years agoAdd bad input to Uri in exception messages
Rajat Goel [Wed, 2 Oct 2013 03:07:23 +0000 (20:07 -0700)]
Add bad input to Uri in exception messages

Summary:
It helps if you can directly see the offending URI from the error
message (specially when you dont want to handle errors and let process crash).

@override-unit-failures

Test Plan: unit-tests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D993025

10 years agoadd functions to return string's internal pointers
Louis Brandy [Wed, 11 Sep 2013 16:15:59 +0000 (09:15 -0700)]
add functions to return string's internal pointers

Summary: See title. This avoids unnecessary copies when needing to access string data directly. These will throw if the dynamic isn't a string.

@override-unit-failures

Test Plan: Unit test.

Reviewed By: delong.j@fb.com

FB internal diff: D986331

10 years agoAdd a comment about takeOwnership()
Daniel Sommermann [Mon, 30 Sep 2013 21:02:07 +0000 (14:02 -0700)]
Add a comment about takeOwnership()

Summary:
It is dangerous to pass memory into an IOBuf since usually in C++
programs, memory is allocated using `new`, while IOBuf by default frees
memory that it has taken ownership of with `free()`. For now, add a
comment warning about this (address sanitizer will warn you about this
when it happens in a live process).

Test Plan: NA

Reviewed By: tudorb@fb.com

FB internal diff: D990056

@override-unit-failures

10 years agoFix bad bug in folly::ThreadLocal
Tudor Bosman [Fri, 27 Sep 2013 00:19:24 +0000 (17:19 -0700)]
Fix bad bug in folly::ThreadLocal

Summary:
There were a few bugs, actually:

1. prevSize < jemallocMinInPlaceExpandable compared an element count with
a byte size; this hid the next bug for a while (as we needed 4096
ThreadLocalPtr objects in order to trigger it)

2. if rallocm(... ALLOCM_NO_MOVE) succeeds in expanding in place, we don't
increment elementsCapacity_, which is bad.

Switched to allocm() so we always take advantage of all memory that was
actually allocated.

@override-unit-failures
Clearly unrelated
+Warning: This development build of composer is over 30 days old. It
is recommended to update it by running
"hphp/test/slow/ext_phar/composer.php self-update" to get the latest
version.

Test Plan: test added, which failed before and doesn't any more

Reviewed By: lucian@fb.com

FB internal diff: D987009

10 years agoAdd declaration for allocm
Tudor Bosman [Fri, 27 Sep 2013 00:19:01 +0000 (17:19 -0700)]
Add declaration for allocm

Test Plan: compiled

Reviewed By: lucian@fb.com

FB internal diff: D986998

10 years agoadd test for numeric -> string conversions
Louis Brandy [Fri, 27 Sep 2013 17:02:51 +0000 (10:02 -0700)]
add test for numeric -> string conversions

Summary: We don't test this functionality (pulling a number out as a string). Almost commited a bug this would have caught.

Test Plan: Run the test.

Reviewed By: delong.j@fb.com

FB internal diff: D987607

10 years agodynamic::get_ptr
Tom Jackson [Fri, 27 Sep 2013 00:12:38 +0000 (17:12 -0700)]
dynamic::get_ptr

Summary: For testing containment and using the value in one operation.

Test Plan: Unit tests

Reviewed By: tudorb@fb.com

FB internal diff: D986986

10 years agoTidied up some includes.
Nicholas Ormrod [Thu, 26 Sep 2013 23:33:38 +0000 (16:33 -0700)]
Tidied up some includes.

Summary: Changed #include "..." to #include <...> where possible.

Test Plan: recompile

Reviewed By: delong.j@fb.com

FB internal diff: D986803

10 years agoFile::dup
Philip Pronin [Thu, 26 Sep 2013 08:45:07 +0000 (01:45 -0700)]
File::dup

Test Plan: fbconfig -r folly && fbmake opt -j32

@override-unit-failures

Reviewed By: soren@fb.com

FB internal diff: D985595

10 years agoFix performance issues with folly::Uri::authority().
Stephane Sezer [Wed, 25 Sep 2013 17:50:46 +0000 (10:50 -0700)]
Fix performance issues with folly::Uri::authority().

Summary: String concatenation was not performed correctly in folly::Uri::authority(). This commit fixes the issue by pre-allocating enough space and buliding the string left to right.

Test Plan: Unit tests in folly/test.

Reviewed By: tudorb@fb.com

FB internal diff: D981069

10 years agoAdd noexcept specification for move ctor, move assignment, dtor in fbstring
Tudor Bosman [Tue, 24 Sep 2013 23:49:24 +0000 (16:49 -0700)]
Add noexcept specification for move ctor, move assignment, dtor in fbstring

Test Plan: fbstring_test, test added

Reviewed By: ngbronson@fb.com

FB internal diff: D983278

10 years agofolly: add a FOLLY_SANITIZE_ADDRESS macro to Portability.h
Andrew Gallagher [Fri, 20 Sep 2013 11:28:39 +0000 (04:28 -0700)]
folly: add a FOLLY_SANITIZE_ADDRESS macro to Portability.h

Summary:
Defines a macro to portably test whether address sanitizer is
enabled across the different compilers we use.

Test Plan:
Compiled source file with address sanitizer and verified macro
was defined.

Reviewed By: delong.j@fb.com

FB internal diff: D978196

10 years agoAdd an authority() method to folly::Uri.
Stephane Sezer [Mon, 23 Sep 2013 21:42:11 +0000 (14:42 -0700)]
Add an authority() method to folly::Uri.

Summary: facebook::strings::URL has an authority() method. Having the same thing for folly::Uri help converting users of the URL class. This method just takes username, password, host, and port, and builds a string in the form <username>:<password>@<host>:<port>.

Test Plan: None.

Reviewed By: rajat@fb.com

FB internal diff: D977450

10 years agodeprecating boost::shared_ptr
Louis Brandy [Fri, 16 Aug 2013 22:19:09 +0000 (15:19 -0700)]
deprecating boost::shared_ptr

Summary:
Replacing boost::shared_ptr with std::shared_ptr.

Test Plan: .

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D932119

10 years agoFix small race in subprocess_test
Tudor Bosman [Sun, 22 Sep 2013 02:03:20 +0000 (19:03 -0700)]
Fix small race in subprocess_test

Summary:
It is possible for subprocess_test_parent_death_helper's child to signal
the parent between the check for "caught" and the call to "pause()", and
therefore pause() blocks forever.

Test Plan: ran the test in a loop

Reviewed By: delong.j@fb.com

FB internal diff: D979872

10 years agoAdd various functions to wrapNoInt
Tudor Bosman [Wed, 18 Sep 2013 23:16:22 +0000 (16:16 -0700)]
Add various functions to wrapNoInt

Test Plan: used them

Reviewed By: soren@fb.com

FB internal diff: D976393

10 years agoFixed-size atomic bitset
Tudor Bosman [Tue, 17 Sep 2013 00:27:30 +0000 (17:27 -0700)]
Fixed-size atomic bitset

Summary: No magic; what it says on the package.

Test Plan: atomic_bitset_test

Reviewed By: delong.j@fb.com

FB internal diff: D971875

10 years agoParametrize allocator in AtomicHash{Array,Map}
Max Wang [Thu, 19 Sep 2013 20:47:22 +0000 (13:47 -0700)]
Parametrize allocator in AtomicHash{Array,Map}

Summary: Maybe at some point somebody won't want malloc, e.g. me.

Test Plan: Ran AtomicHashArrayTest using an mmap allocator.

Reviewed By: delong.j@fb.com

FB internal diff: D960192

10 years agoMake folly::Uri::port() return uint16_t instead of uint32_t.
Stephane Sezer [Thu, 19 Sep 2013 19:19:26 +0000 (12:19 -0700)]
Make folly::Uri::port() return uint16_t instead of uint32_t.

Summary: We can safely assume that ports are always going to be 16bit (TCP or UDP), so no need to have a uint32_t here.

Test Plan: Ran tests in folly/tests.

Reviewed By: tudorb@fb.com

FB internal diff: D973291

10 years agoRemove problematic log lines from folly JSON test.
Stephane Sezer [Wed, 18 Sep 2013 23:37:49 +0000 (16:37 -0700)]
Remove problematic log lines from folly JSON test.

Summary: We are logging UTF-8 data in this test. This makes the test infra fail (when using `fbmake runtests` for example).

Test Plan: Run existing JSON tests.

Reviewed By: shreehari@fb.com

FB internal diff: D975249

10 years agofix minor typo in comment
Andrey Goder [Mon, 16 Sep 2013 17:43:15 +0000 (10:43 -0700)]
fix minor typo in comment

Test Plan: n/a

Reviewed By: delong.j@fb.com

FB internal diff: D970791

10 years agoAsyncIO::initializeContext() should provide more debug output when io_queue_init...
Altan Alpay [Thu, 12 Sep 2013 21:08:01 +0000 (14:08 -0700)]
AsyncIO::initializeContext() should provide more debug output when io_queue_init fails

Summary: It would be good idea to provide more information if the io_queue_init() failed due to resource allocation.

Test Plan:
Run standart tests + manual testing
1. fbconfig -r folly/experimental/ && fbmake runtests
2. Ask a capacity larger than aio_max_nr and check failure messages

Reviewed By: agartrell@fb.com

FB internal diff: D965260

10 years agofix memcpy-param-overlap (asan) in GroupVarint
Philip Pronin [Tue, 10 Sep 2013 13:24:40 +0000 (06:24 -0700)]
fix memcpy-param-overlap (asan) in GroupVarint

Test Plan: .

Reviewed By: tudorb@fb.com

FB internal diff: D962972

10 years agofolly: don't inline functions with ASAN disabled
Andrew Gallagher [Tue, 10 Sep 2013 20:22:22 +0000 (13:22 -0700)]
folly: don't inline functions with ASAN disabled

Summary:
The address sanitizer disabling attribute has some issues in gcc when
the function is inlined.

Test Plan: Built and ran tao tests with ASAN.

Reviewed By: philipp@fb.com

FB internal diff: D962930

10 years agorange checks in DynamicConverter
Nicholas Ormrod [Tue, 10 Sep 2013 16:59:04 +0000 (09:59 -0700)]
range checks in DynamicConverter

Summary:
Add range-checking to convertTo for small numeric types.

Internally, dynamics represent a numeric with an int64_t or a double.
When converting to a smaller numeric type, DynamicConverter uses a
static_cast. This causes some confusion (re D936940). The code now uses
folly::to, which throws a std::range_error on overflow.

While working on this I also added some light comments to the new
toDynamic section, for consistency with the original convertTo
commenting. I also renamed the internal trait is_associative_container
to is_map, since is_associative_container is looking for a mapped_type
typedef and hence excludes such associative containers as sets.

While adding the overflow tests, I also augmented the typetraits test to
include the is_map and is_range traits, which hitherto had no test
coverage.

Test Plan: build and run tests, both in dbg and opt

Reviewed By: cberner@fb.com

FB internal diff: D961605

10 years agodisable asan for qfind_first_byte_of_needles16
Philip Pronin [Tue, 10 Sep 2013 13:25:53 +0000 (06:25 -0700)]
disable asan for qfind_first_byte_of_needles16

Summary:
It's expected to read past the string (within the same memory
page).

Test Plan: .

Reviewed By: tudorb@fb.com

FB internal diff: D962974

10 years agofix heap-buffer-overflow (asan) in EliasFanoCoding
Philip Pronin [Tue, 10 Sep 2013 13:21:36 +0000 (06:21 -0700)]
fix heap-buffer-overflow (asan) in EliasFanoCoding

Test Plan:
fbconfig folly/experimental/test:elias_fano_test && fbmake runtests_opt

Reviewed By: tudorb@fb.com

FB internal diff: D962971

10 years agoSome fixes for building stuff with clang
Jordan DeLong [Wed, 4 Sep 2013 01:52:52 +0000 (18:52 -0700)]
Some fixes for building stuff with clang

@override-unit-failures

Summary: Not that much.

Test Plan:
Compiled hphp with clang.

Reviewed By: oyamauchi@fb.com

FB internal diff: D954663

10 years agofolly: disable address sanitizer warnings on fbstring
Andrew Gallagher [Tue, 3 Sep 2013 07:26:59 +0000 (00:26 -0700)]
folly: disable address sanitizer warnings on fbstring

Summary:
The fbstring constructor does word-aligned copies which may creep
past the end of the C string, which address sanitizer doesn't like.

This also adds a address-sanitizer-disabling-attribute to both
Portability.h (for general use) and a (gross) copy in FBString.h
since it gets put into libstdc++.

Test Plan: ran address sanitizer on folly tests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D950586

10 years agoabort instead of throwing an exception on bad format strings
bsimmers [Tue, 27 Aug 2013 23:27:09 +0000 (16:27 -0700)]
abort instead of throwing an exception on bad format strings

Summary:
Errors that happen during format are almost always programmer
error in the form of a bad format string. Abort instead of throwing in
these cases.

Test Plan: automated tests, added a couple new tests

Reviewed By: tudorb@fb.com

FB internal diff: D947470

10 years agox86intrinsic seems to be problematic for clang
Dave Watson [Thu, 29 Aug 2013 22:40:57 +0000 (15:40 -0700)]
x86intrinsic seems to be problematic for clang

Summary: fbinject (clang code parser) throws some errors when
including the x86intrinsic header.

Test Plan:
D929356 compiles after this diff.  It adds a dep on RWSpinLock.

Reviewed By: beng@fb.com

FB internal diff: D950285

10 years agoFix insignificant CRTP bug
Tudor Bosman [Thu, 29 Aug 2013 00:46:16 +0000 (17:46 -0700)]
Fix insignificant CRTP bug

Summary:

@override-unit-failures
Flaky unit tests passed on the second try, but the git hook still
complains

Test Plan: iobuf_cursor_test

Reviewed By: philipp@fb.com

FB internal diff: D948768

10 years agofix folly build on OSX with gcc 4.8
Sean Cannella [Thu, 29 Aug 2013 16:16:54 +0000 (09:16 -0700)]
fix folly build on OSX with gcc 4.8

Summary:
- gcc 4.8 + boost 1.53 do not like the Oxford comma in template
arguments

Test Plan: compiled on OSX with gcc 4.8 and boost 1.53

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D949373

10 years agofolly::io::QueueAppender speedup
Tudor Bosman [Wed, 28 Aug 2013 01:31:27 +0000 (18:31 -0700)]
folly::io::QueueAppender speedup

Summary:
Make QueueAppender (as used in the thrift2 protocol writer) much faster.
Benchmarks in a separate diff (for thrift2).

A few things:
- remove IOBuf range checks in optimized mode
- simplify QueueAppender: maxGrowth wasn't used, removed it
- simplify QueueAppender: don't duplicate the work in IOBufQueue, let
IOBufQueue keep track of memory
- speed up IOBuf::isSharedOne(): fast-path case where the buffer was never
shared (so don't read the reference count in that case)
- fast-path in QueueAppender if size is known at compile time

@override-unit-failures
compilation errors outside of folly fixed in subsequent diff

Test Plan: folly/io/test, both dbg and opt

Reviewed By: davejwatson@fb.com

FB internal diff: D946907

10 years agoUpdate build for Ubuntu 12.10. 12.04 seems to no longer compile
Dave Watson [Mon, 22 Apr 2013 22:05:36 +0000 (15:05 -0700)]
Update build for Ubuntu 12.10. 12.04 seems to no longer compile

Summary: Dave Watson put this in github a few months ago.

Test Plan: None

Reviewed By: delong.j@fb.com

FB internal diff: D912681

10 years agoUnbreak build: -Werror=pragmas (srsly)
Tudor Bosman [Tue, 27 Aug 2013 19:17:48 +0000 (12:17 -0700)]
Unbreak build: -Werror=pragmas (srsly)

Summary:
gcc 4.6 doesn't know of -Wmaybe-uninitialized, so it reports a warning, which
we treat as an error.

Test Plan: compiled folly/test folly/experimental/test with gcc 4.6.2, 4.7.1, 4.8.1

Reviewed By: philipp@fb.com

FB internal diff: D945766

10 years agoExpand the range where uninitialized warnings are ignored
Tudor Bosman [Tue, 27 Aug 2013 04:39:36 +0000 (21:39 -0700)]
Expand the range where uninitialized warnings are ignored

Summary: gcc 4.8 is picky

Test Plan: folly tests, compiled unicorn with gcc 4.8

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D945336

10 years agofolly: adjust more headers to be -Wshadow-clean
Jim Meyering [Sat, 24 Aug 2013 02:46:09 +0000 (19:46 -0700)]
folly: adjust more headers to be -Wshadow-clean

Summary:
This is part of what's required to make mcrouter compile warning-free
with gcc -Wshadow.  In case it's not obvious why this is worth doing,
see t2719164.

I've used two techniques:
rename one of the shadowed variables
bracket offending code with #pragma directives to disable the warning there.

* folly/Bits.h (BitIterator): Guard this function with #pragma
to avoid a warning about its member-shadowing "bitOffset" parameter.
* folly/Memory.h (StlAllocator): Rename parameter in trivial, one-line
function definition, s/alloc/a/, to avoid shadowing the member function.
Let me know if you'd prefer #pragma directives instead.
* folly/io/Cursor.h (pull,skip,clone): Rename parameter, s/length/len/,
not to shadow the member function name.

Test Plan:
build and run tests of a few tools that use these headers

Reviewed By: jon.coens@fb.com

FB internal diff: D940493

10 years agounbreak build
Tudor Bosman [Sat, 24 Aug 2013 00:14:08 +0000 (17:14 -0700)]
unbreak build

Test Plan: built producer_consumer_queue_test with gcc 4.7.1
@override-unit-failures

Reviewed By: chip@fb.com

FB internal diff: D942465

10 years agoUse boost:has_trivial_destructor instead of std::...
Sara Golemon [Fri, 23 Aug 2013 23:22:09 +0000 (16:22 -0700)]
Use boost:has_trivial_destructor instead of std::...

Summary: Boost's version is 4.8 safe.  std's version changes name

Test Plan: hhvm builds

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D883508

10 years agostd::map and std::set are not relocatable
Tudor Bosman [Thu, 22 Aug 2013 14:26:48 +0000 (07:26 -0700)]
std::map and std::set are not relocatable

Summary: https://github.com/facebook/folly/issues/35

@override-unit-failures
hphp tests independently broken

Test Plan: test added

Reviewed By: delong.j@fb.com

FB internal diff: D939323

10 years agofolly: improve Subprocess::enforce() error message
Lucian Grijincu [Tue, 20 Aug 2013 22:50:39 +0000 (15:50 -0700)]
folly: improve Subprocess::enforce() error message

Summary: Previous implementation only printed the desired state, not the actual runtime state. Fix that.

Test Plan: n/a

Reviewed By: tudorb@fb.com

FB internal diff: D936279

10 years agomake StringGen clang-compatible
Philip Pronin [Tue, 20 Aug 2013 10:18:39 +0000 (03:18 -0700)]
make StringGen clang-compatible

Test Plan:
fbconfig -r folly/test && fbmake opt -j32

Reviewed By: tjackson@fb.com

FB internal diff: D935182

10 years agoretry flock() if interrupted (EINTR)
Philip Pronin [Sat, 17 Aug 2013 09:06:35 +0000 (02:06 -0700)]
retry flock() if interrupted (EINTR)

Test Plan: fbconfig folly/test:file_test && fbmake runtests_opt

Reviewed By: soren@fb.com

FB internal diff: D932782

10 years agoFix overeager assertion
Tudor Bosman [Thu, 15 Aug 2013 21:49:47 +0000 (14:49 -0700)]
Fix overeager assertion

Summary: Also important spelling mistakes.
@override-unit-failures

Test Plan: string_test

Reviewed By: tjackson@fb.com

FB internal diff: D930037

10 years agoAdd Varint-length-prefixed flavor of LZ4
Tudor Bosman [Thu, 15 Aug 2013 02:37:40 +0000 (19:37 -0700)]
Add Varint-length-prefixed flavor of LZ4

Test Plan: test added

Reviewed By: alandau@fb.com

FB internal diff: D928836

10 years agoVarint in folly
Tudor Bosman [Thu, 15 Aug 2013 02:17:09 +0000 (19:17 -0700)]
Varint in folly

Test Plan: test added

Reviewed By: alandau@fb.com

FB internal diff: D928835

10 years agoFix a ThreadLocal bug: hold the meta lock when resizing the element vector
Jordan DeLong [Thu, 15 Aug 2013 00:03:04 +0000 (17:03 -0700)]
Fix a ThreadLocal bug: hold the meta lock when resizing the element vector

Summary:
There appears to be a race here.  leizha reported issues with
a heavily recycled AtomicHashMap (ThreadCachedInt inside).  It looks
like what's happening is this:

- Thread A: ~ThreadCachedInt from an AHM
- meta lock is taken, and the ThreadElement list is iterated
- all entries are zerod, and the id is marked free
- then releases the lock
- Thread B: someone is calling get() on an unrelated id
- hit reserve: rallocm on the pointer or unsynchronized memcpy from
the element vector
- waits on the lock
- when it gets the lock, it stores back the value that it read that
was zero'd by A.

Later, someone reuses the id from the freelist, and reuses the
previously freed pointer, and eventually double-freeing it.  (nullptr
is the signifier for "this thread doesn't have an instance of the
threadlocal yet").

Test Plan:
leizha's test case doesn't segv after this diff---it was
reliably breaking with corruption in malloc before it.  I'm working on
making that test case into a unit test to add to this diff, but I'm
putting it up early in case there's something wrong with the theory
above or in case someone has an idea for a better fix.

Reviewed By: tudorb@fb.com

FB internal diff: D928534

10 years agofolly: attribute-aligned-arg must now be constant (not enum)
Jim Meyering [Tue, 13 Aug 2013 16:31:45 +0000 (09:31 -0700)]
folly: attribute-aligned-arg must now be constant (not enum)

Summary:
With gcc-4.8.[01], the argument to __attribute__((__aligned__(...)))
must be a literal;  using an enum member evokes this:

./folly/MPMCQueue.h:341:63: error: requested alignment is not an \
integer constant
size_t capacity_ FOLLY_ON_NEXT_CACHE_LINE;

Changing the enum member to this made no difference:

static constexpr size_t kFalseSharingRange = 64;

Test Plan: compile tao and run test suite

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D926221

@override-unit-failures

10 years agofolly/Conv.h: remove unused local typedef
Andrew Gallagher [Mon, 12 Aug 2013 20:13:05 +0000 (13:13 -0700)]
folly/Conv.h: remove unused local typedef

Test Plan: compiled using gcc-4.8

Reviewed By: meyering@fb.com

FB internal diff: D923895

10 years agofolly: avoid use of has_trivial_destructor in FBVector.h
Jim Meyering [Wed, 29 May 2013 01:06:16 +0000 (18:06 -0700)]
folly: avoid use of has_trivial_destructor in FBVector.h

Summary:
This is required for gcc-4.8.x.
Use boost::has_trivial_destructor, not std::has_trivial_destructor.
The latter was never standard, and the now-std name (and the only one
supported in gcc-4.8.0) is std::is_trivially_destructible.

Test Plan:
fbmake runtests and then
run_unit_tests.sh with -r and again with -d

Reviewed By: njormrod@fb.com

FB internal diff: D923359

@override-unit-failures

10 years agoIOBuf compression
Tudor Bosman [Wed, 7 Aug 2013 00:01:37 +0000 (17:01 -0700)]
IOBuf compression

Summary: davejwatson: you asked

Test Plan: test added

Reviewed By: davejwatson@fb.com

FB internal diff: D917336

10 years agoRevert "[clang support] removed superfluous declarations from header files"
Andrew Gallagher [Mon, 5 Aug 2013 23:42:39 +0000 (16:42 -0700)]
Revert "[clang support] removed superfluous declarations from header files"

Summary: This reverts commit 49b197dfd02443e958906bac45059cea460e4e10.

Test Plan: contbuild

Reviewed By: akhilravidas@fb.com

FB internal diff: D915386

@override-unit-failures

10 years agoremoved superfluous declarations from header files
Bob Haarman [Mon, 5 Aug 2013 23:06:50 +0000 (16:06 -0700)]
removed superfluous declarations from header files

Summary:
Clang doesn't like the same member of a class being defined more than once,
or default argument values being defined more than once. This diff removes some
instances.

@override-unit-failures

Test Plan: Compiled the code with Clang and GCC

Reviewed By: andrewjcg@fb.com

FB internal diff: D913226

10 years agodereference
Tom Jackson [Sun, 4 Aug 2013 21:30:06 +0000 (14:30 -0700)]
dereference

Summary:
For dealing with sequences of pointers. Works with pointer wrappers,
and filters out nullptrs, see tests.

Test Plan: Unit tests

Reviewed By: tulloch@fb.com

FB internal diff: D914069

10 years agoFixing Until, Take
Tom Jackson [Fri, 2 Aug 2013 20:51:47 +0000 (13:51 -0700)]
Fixing Until, Take

Summary:
`apply()` returns false if and only if the handler it was //directly//
passed returned false. `Take` didn't do this right, and `Until` was just broken.

Test Plan: More thorough unit tests.

Reviewed By: kittipat@fb.com

FB internal diff: D913185

10 years agomake folly/Bits.h clang-compatible
Philip Pronin [Thu, 1 Aug 2013 08:42:27 +0000 (01:42 -0700)]
make folly/Bits.h clang-compatible

Summary: In clang (as of 3.2) intrinsics aren't `constexpr`.

Test Plan:
fbconfig folly/test:bits_test && fbmake opt -j32
fbconfig --clang folly/test:bits_test && fbmake opt -j32

Reviewed By: lucian@fb.com

FB internal diff: D910310

10 years agoBatch
Kittipat Virochsiri [Fri, 2 Aug 2013 20:25:35 +0000 (13:25 -0700)]
Batch

Summary: Convert stream of elements to stream of fixed-sized vectors.

Test Plan: unit tests

Reviewed By: tjackson@fb.com

FB internal diff: D912290

10 years agoUpdate build for Ubuntu 12.10. 12.04 seems to no longer compile
Dave Watson [Mon, 22 Apr 2013 22:05:36 +0000 (15:05 -0700)]
Update build for Ubuntu 12.10. 12.04 seems to no longer compile

Summary: Dave Watson put this in github a few months ago.

Test Plan: None

Reviewed By: delong.j@fb.com

FB internal diff: D912681

10 years agoMake ThreadLocalPtr behave sanely around fork()
Tudor Bosman [Thu, 1 Aug 2013 21:21:52 +0000 (14:21 -0700)]
Make ThreadLocalPtr behave sanely around fork()

Summary:
Threads and fork still don't mix, but we shouldn't help you shoot yourself in
the foot if you decide to do it.

Test Plan: test added

Reviewed By: mshneer@fb.com

FB internal diff: D911224

10 years agoCycle
Tom Jackson [Thu, 1 Aug 2013 20:54:24 +0000 (13:54 -0700)]
Cycle

Summary: For repeating a generator's values endlessly.

Test Plan: Unit tests

Reviewed By: kittipat@fb.com

FB internal diff: D911178

10 years agoFix build break for Clang builds.
Andrew Tulloch [Thu, 1 Aug 2013 21:26:12 +0000 (14:26 -0700)]
Fix build break for Clang builds.

Summary:
Complains about

```
In file included from crypto/lib/cpp/CryptoException.cpp:1:
In file included from crypto/lib/cpp/CryptoException.h:5:
In file included from ./folly/Conv.h:30:
./folly/Range.h:573:19: error: redefinition of default argument
Comp eq = Comp()) {
^    ~~~~~~
./folly/Range.h:55:26: note: previous definition is here
Comp eq = Comp());
^    ~~~~~~
```

Redefinition of default arguments is not allowed in C++.

Test Plan:
```
fbconfig --clang admarket/adpublisher && fbmake dbg
```

contbuild, etc.

Reviewed By: lucian@fb.com

FB internal diff: D910800

10 years agoUse std::equal<> as qfind default comparator
Josh Metzler [Tue, 30 Jul 2013 17:36:58 +0000 (10:36 -0700)]
Use std::equal<> as qfind default comparator

Summary:
qfind(haystack, needle) is templated, but used a non-templated
default comparator that cast everything to char.  This works find for
8-bit types, but not for others such as the uint32_t Ranges we are
using.  Replace the default comparator with std::equal<> to use a
working comparator for whatever type is being searched.

Test Plan:
Compiles, unit tests (including a new one that fails with the
old code) pass.  Not sure how to test other users of this, or measure
performance impact. :(

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D906311

10 years agofix folly Range compilation on FreeBSD
Sean Cannella [Mon, 29 Jul 2013 19:36:55 +0000 (12:36 -0700)]
fix folly Range compilation on FreeBSD

Summary: - memrchr is GNU + Linux specific, it turns out

Test Plan: - compiled on FreeBSD, contbuild

Reviewed By: delong.j@fb.com

FB internal diff: D900935

10 years agofix folly compilation on FreeBSD
Sean Cannella [Tue, 23 Jul 2013 18:25:13 +0000 (11:25 -0700)]
fix folly compilation on FreeBSD

Summary:
- fix folly compilation on FreeBSD

Github Author: Martin Matuska <martin@matuska.org>

Test Plan: - compiled

Reviewed By: tudorb@fb.com

FB internal diff: D896747

10 years agoMulti-Producer, Multi-Consumer pipeline
Tudor Bosman [Fri, 19 Jul 2013 01:05:51 +0000 (18:05 -0700)]
Multi-Producer, Multi-Consumer pipeline

Summary:
A bunch of MPMCQueues linked together. Stage i produces exactly Ki (default 1)
outputs for each input. Ordering is preserved, even though stages might
produce (intermediate or final) results in parallel and in any order; we do
this by abusing the enqueueing mechanism in MPMCQueue. (Read the code for
details)

Test Plan: test added, more tests to be written before commit

Reviewed By: ngbronson@fb.com

FB internal diff: D892388

10 years agofolly/MPMCQueue sizeGuess should return a signed int
Nathan Bronson [Fri, 19 Jul 2013 18:12:59 +0000 (11:12 -0700)]
folly/MPMCQueue sizeGuess should return a signed int

Summary:
Like size(), sizeGuess() is allowed to return a negative value,
so it should be ssize_t instead of uint64_t.

Test Plan: fbmake, wait for contbuild

Reviewed By: tudorb@fb.com

FB internal diff: D893075

10 years agofolly/Hash.h add a test to ensure different hashes
Hans Fugal [Thu, 18 Jul 2013 00:40:41 +0000 (17:40 -0700)]
folly/Hash.h add a test to ensure different hashes

Summary:
"Wouldn't this test case still pass if the hash function didn't depend on the value?

It would be nice to verify that different tuple values produce different hash values (or maybe there's another test that verifies that), especially since this is a tricky thing to get right."

I think there's not much chance of this failing since it's just leveraging hash_combine and that's already tested. But it's easy to add another sanity check, so here we are.

Test Plan: runtests

Reviewed By: tulloch@fb.com

FB internal diff: D890448

Blame Revision: D888796

10 years agotuple hashing
Hans Fugal [Wed, 17 Jul 2013 01:34:51 +0000 (18:34 -0700)]
tuple hashing

Summary:
Add hash support for std::tuple.
See also D490478 (where a first attempt was made) and D543586 (where that attempt was deemed broken and removed).

Test Plan: unit test

Reviewed By: chip@fb.com

FB internal diff: D888796

10 years agoOSX compat fixes
Sean Cannella [Mon, 15 Jul 2013 15:32:29 +0000 (08:32 -0700)]
OSX compat fixes

Summary:
fix OSX compat issues

Github Author: Daniel Sloof <goapsychadelic@gmail.com>

Test Plan: - compiled

Reviewed By: pt@fb.com

FB internal diff: D877309

10 years agoAdd initializer_list support to folly::join
Chip Turner [Mon, 8 Jul 2013 19:36:53 +0000 (12:36 -0700)]
Add initializer_list support to folly::join

Summary:
Apparently the templates don't like to match the initlializer
list, so this needed to be added.  This allows for things like:

auto s = join(":", {val1, val2, val3, val4, val4});

Test Plan: run tests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D878032

10 years agoguard<Exception>() (redo)
Tom Jackson [Mon, 8 Jul 2013 19:41:11 +0000 (12:41 -0700)]
guard<Exception>() (redo)

Summary:
For handling exceptions from downstream operations.

Now with cleaner build.

Test Plan: Unit tests, including those outside `folly`.

Reviewed By: marcelo.juchem@fb.com

FB internal diff: D877795

Blame Revision: https://phabricator.fb.com/D872581

10 years agoFix folly/FBString.h build error
Chip Turner [Wed, 10 Jul 2013 21:05:49 +0000 (14:05 -0700)]
Fix folly/FBString.h build error

Summary:
Looks like D880140 left off this part when it was committed.

This fixes the build.

Test Plan: runtests

Reviewed By: vini@fb.com

FB internal diff: D881445

10 years agoFix build breakage in hphp
Andrei Alexandrescu [Tue, 9 Jul 2013 23:11:19 +0000 (16:11 -0700)]
Fix build breakage in hphp

Summary:
This should fix the build breakage in hphp caused by the latest fbstring changes (after being ported to engshare). Note that I'm flying blind here; I couldn't test with the hphp build because I don't have write access to engshare. @agallagher could you please make sure that this works after the fix?

fbconfig -r hphp && fbmake dbg

Test Plan: tested on folly

Reviewed By: tudorb@fb.com

FB internal diff: D880140

10 years agofbstring::shrink_to_fit
Andrei Alexandrescu [Fri, 28 Jun 2013 01:40:35 +0000 (18:40 -0700)]
fbstring::shrink_to_fit

Summary: Adds the eponymous C++11 capability to fbstring.

Test Plan: fbstring runtests

Reviewed By: tudorb@fb.com

FB internal diff: D867995

10 years agoAllowing trailing comma in folly::parseJson
Tom Jackson [Tue, 2 Jul 2013 19:29:10 +0000 (12:29 -0700)]
Allowing trailing comma in folly::parseJson

Summary:
Introduced a new serialization option, `allow_trailing_comma`, which allows trailing commas to be included in strings when they are parsed. This isn't strictly allowed by RFC 4627, but we're allowing more than that anyway.

I've run into this dozens of times, especially while using SMC.

Test Plan: Unit tests

Reviewed By: delong.j@fb.com

FB internal diff: D872581

10 years agoRevert D874344 (it broke the build)
Chip Turner [Mon, 8 Jul 2013 18:05:36 +0000 (11:05 -0700)]
Revert D874344 (it broke the build)

Summary:
Clean revert.  Please be more careful; phabricator warned you
these would break the build.

Test Plan: build something that wasn't working

Reviewed By: myang@fb.com

FB internal diff: D877526

10 years agoguard<Exception>()
Tom Jackson [Wed, 3 Jul 2013 18:38:32 +0000 (11:38 -0700)]
guard<Exception>()

Summary: For handling exceptions from downstream operations.

Test Plan: Unit tests

Reviewed By: marcelo.juchem@fb.com

FB internal diff: D874344

10 years agomove assignment operators for folly::Synchronized
Philip Pronin [Fri, 5 Jul 2013 03:01:37 +0000 (20:01 -0700)]
move assignment operators for folly::Synchronized

Summary:
* added move assignment operators,
* fixed `operator=(const Synchronized& rhs)` (it had a typo),
* fixed deadlock on self-assignment,
* changed `swap` to call `swap(lhs.datum_, rhs.datum_)` instead of `lhs.datum_.swap(rhs.datum_)`.

Test Plan: fbconfig -r folly/test && fbmake opt -j32 && fbmake runtests_opt

Reviewed By: delong.j@fb.com

FB internal diff: D875977

10 years agomemrchr and *timed_mutex are platform-specific
Sean Cannella [Wed, 3 Jul 2013 20:36:28 +0000 (13:36 -0700)]
memrchr and *timed_mutex are platform-specific

Summary:
- conditionally compile rfind overrides
- conditionally add support for timed_mutex/recursive_timed_mutex

Test Plan:
- compiled on OSX
- unit tests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D872272

10 years agostrerror_r is XSI compliant on Apple/FreeBSD
Sean Cannella [Mon, 1 Jul 2013 15:06:12 +0000 (08:06 -0700)]
strerror_r is XSI compliant on Apple/FreeBSD

Summary:
- Noticed this due to an -fpermissive compiler warning while compiling
HHVM for OSX (complaint of trying to cast int to char*)

Test Plan:
- Compiled
- Confirmed the build warning is fixed by this on the Mac OS X build

Reviewed By: tudorb@fb.com

FB internal diff: D865169

10 years agotoDynamic(T)
Tom Jackson [Tue, 23 Apr 2013 17:02:07 +0000 (10:02 -0700)]
toDynamic(T)

Summary: It only makes sense to be able to go the other direction, too.

Test Plan: Unit tests

Reviewed By: delong.j@fb.com

FB internal diff: D785282

10 years agoRange<T>::rfind()
Tom Jackson [Wed, 26 Jun 2013 23:53:58 +0000 (16:53 -0700)]
Range<T>::rfind()

Test Plan: Unit tests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D865951

10 years agoMulti-producer multi-consumer queue with optional blocking
Nathan Bronson [Fri, 28 Jun 2013 20:42:14 +0000 (13:42 -0700)]
Multi-producer multi-consumer queue with optional blocking

Summary:
MPMCQueue<T> is a high-performance bounded concurrent queue that
supports multiple producers, multiple consumers, and optional blocking.
The queue has a fixed capacity, for which all memory will be allocated
up front.  The bulk of the work of enqueuing and dequeuing can be
performed in parallel.

To make an MPMCQueue<T>, T must satisfy either of two conditions:
- it has been tagged FOLLY_ASSUME_FBVECTOR_COMPATIBLE; or
- both the constructor used during enqueue and the move operator are
marked noexcept.

This diff extracts the generic component from tao/queues/ConcurrentQueue
and renames identifiers to match those of existing folly queues.
It also includes an extraction of Futex, which wraps the futex syscall,
and DeterministicScheduler, which allows for deterministic exploration
of thread interleavings for components built from std::atomic and Futex.

Test Plan: new unit tests

Reviewed By: tudorb@fb.com

FB internal diff: D866566

10 years agoconst'ing sorted_vector_map::count()
Tom Jackson [Wed, 26 Jun 2013 19:32:28 +0000 (12:32 -0700)]
const'ing sorted_vector_map::count()

Test Plan: Use it

Reviewed By: tudorb@fb.com

FB internal diff: D865211

10 years agofix tautological comparisons in Conv.h
Louis Brandy [Thu, 20 Jun 2013 00:01:38 +0000 (17:01 -0700)]
fix tautological comparisons in Conv.h

Summary:
We have an off-by-one in our enable_if/sfinae logic here. We do not want to actually do the comparison in `less_than` when the rhs is exactly the minimum possible lhs. This results in a tautological comparison.

I added a unit test for these traits that test all the various sfinae cases.

Test Plan: See the clang tautological warnings go away. Under gcc, rerun all tests. All pass.

Reviewed By: marcelo.juchem@fb.com

FB internal diff: D856869

10 years agoSpeed up EventCount, now 64-bit only
Tudor Bosman [Fri, 21 Jun 2013 03:14:35 +0000 (20:14 -0700)]
Speed up EventCount, now 64-bit only

Summary:
Don't use two atomic variables when only one will suffice (otherwise, the
increments in doNotify() and prepareWait() would require memory_model_seq_cst,
because they need to globally order a store before a load, and no weaker
model allows you to do that)

Of course, this makes this 64-bit only, but I don't care.

Test Plan: eventcount_test, tests outside of folly

Reviewed By: delong.j@fb.com

FB internal diff: D858963

10 years agoStringPiece comparisons are broken
Tudor Bosman [Mon, 24 Jun 2013 19:48:43 +0000 (12:48 -0700)]
StringPiece comparisons are broken

Summary:
8-bit StringPiece comparisons are broken.
The reason is char_traits is magic for 'char', but not 'const char'.

Test Plan: test added

Reviewed By: chip@fb.com

FB internal diff: D861521

10 years agoadd Chrono.h to patch around a gcc 4.6 issue
Tudor Bosman [Fri, 21 Jun 2013 16:18:37 +0000 (09:18 -0700)]
add Chrono.h to patch around a gcc 4.6 issue

Test Plan: used it

Reviewed By: soren@fb.com

FB internal diff: D859244

10 years agoUse libunwind instead of the heavyweight thing from libgcc
Tudor Bosman [Thu, 20 Jun 2013 21:15:17 +0000 (14:15 -0700)]
Use libunwind instead of the heavyweight thing from libgcc

Test Plan: exception_tracer_test

Reviewed By: bmaurer@fb.com

FB internal diff: D858195

10 years agoAdd MultiLevelTimeSeries to folly.
Stephen Chen [Fri, 14 Jun 2013 22:46:44 +0000 (15:46 -0700)]
Add MultiLevelTimeSeries to folly.

Summary:
Add MultiLevelTimeSeries class which represents a timeseries which keeps several
levels of data granularity (similar in principle to the loads reported by the
UNIX 'uptime' command).  It uses several instances (one per level) of
BucketedTimeSeries as the underlying storage.

This can easily be used to track sums (and thus rates or averages) over several
predetermined time periods, as well as all-time sums.  For example, you would
use to it to track query rate or response speed over the last 5, 15, 30, and 60
minutes.

Test Plan: unittest included.

Reviewed By: simpkins@fb.com

FB internal diff: D851444

10 years agorename template parameters in folly::greater_than
Louis Brandy [Wed, 19 Jun 2013 23:39:45 +0000 (16:39 -0700)]
rename template parameters in folly::greater_than

Summary: This template is only used in folly::Conv (to avoid tautological comparisons) and as best as I can tell, the rhs/lhs names are not correct as it's currently used (and not consistent with `less_than`). Just swap rhs/lhs variable names.

Test Plan:
Test Results Summary:
Passed: 471
100% successful

Reviewed By: marcelo.juchem@fb.com

FB internal diff: D856785