1. 18 Apr, 2014 9 commits
    • Victor Loh's avatar
      Use StringPiece instead of String · 30a71566
      Victor Loh authored
      Summary:
      Using StringPiece makes it easier than std::string
      
      Facebook: Motivation for this diff is found in D1253595
      
      Test Plan:
      Added new unittest
      
      fbconfig folly/io/test && fbmake runtests_opt
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D1276185
      30a71566
    • Elizabeth Smith's avatar
      uint isn't portable and makes some compilers angry, change to unsigned int · 32d518c3
      Elizabeth Smith authored
      Summary: As part of the windows port, uint is not defined as a type and is not standard, it makes msvc choke, a simple change to unsigned int fixes the issue
      
      Test Plan: fbmake runtests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D1278487
      32d518c3
    • Tudor Bosman's avatar
      Add non-const operator[] to TypedIOBuf · 0c8631dc
      Tudor Bosman authored
      Test Plan: used it
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D1277063
      
      @override-unit-failures
      0c8631dc
    • Lucian Grijincu's avatar
      folly: improve ProducerConsumerQueueBenchmark (misplaced doNotOptimizeAway) · e39dfd9d
      Lucian Grijincu authored
      Summary:
      as per discussion from https://phabricator.fb.com/D1274352
      
      After changing the queue length to be a small value (100) I didn't see
      improvement from cache alignment of atomics (too much noise). Dropping
      that and just fixing the benchmark.
      
      Test Plan: n/a
      
      Reviewed By: ngbronson@fb.com
      
      FB internal diff: D1276591
      e39dfd9d
    • Nicholas Ormrod's avatar
      Fix apparent race in SubprocessTest · 1321eef0
      Nicholas Ormrod authored
      Summary:
      The code originally contained the line
      
      EXPECT_EQ((rcount == lineCount), r); // EOF iff at lineCount
      
      Which asserted that, on the last iteration, EOF was being read (and thus
      r was true).
      
      This line has been causing errors in contbuild. There seem to be two
      issues at play.
      
      First, the left hand side of the EXPECT_EQ is always false. rcount is
      incremented three lines down, and the (implicit) loop ends when rcount
      equals lineCount. This means that, on the last iteration, rcount is
      actually one less than lineCount. Hence the check is effectively
      asserting that r is false.
      
      The second issue is that r is rarely true. Empirically, a necessary but
      not sufficient condition is that there be lots of other processes
      running at the same time (such as when running fbconfig -r folly &&
      fbmake runtests_opt). This would explain why the test passes during
      development but fails in contbuild.
      
      I am guessing that, when there are few processes running, Subprocess is
      predictably ceasing to read before whichever other process yields EOF,
      and that this does not always happen when there is resource contention.
      
      As an immediate fix, I am asserting that r may only be true on the last
      iteration. Could someone (cc @tudorb) who is more familiar with the
      intricacies of Subprocess please check to see if this is an idiosyncrasy
      of the test, or if there is actually an underlying bug.
      
      Test Plan:
      Before the change, run fbconfig -r folly && fbmake runtests_opt
      repeatedly. Notice that most of the iterations yield an error from line
      376 (which is consistent with contbuild error logs).
      
      After the change, notice that the error disappears.
      
      Reviewed By: andrewjcg@fb.com
      
      FB internal diff: D1269124
      1321eef0
    • Lucian Grijincu's avatar
      folly: gen: pmap: parallel version of map · 89c3562e
      Lucian Grijincu authored
      Summary:
      same as map, but runs it's argument in parallel over a number of threads.
      
      @override-unit-failures
      
      Test Plan: added test
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D1258364
      89c3562e
    • Alexey Spiridonov's avatar
      Change child's working directory · 188e13f3
      Alexey Spiridonov authored
      Summary: Changing the parent's WD is prone to race conditions of various sorts, and needlessly alters parent state. Python's subprocess also has this feature.
      
      Test Plan: fbmake dbg _bin/folly/test/subprocess_test ; ../_bin/folly/test/subprocess_test
      
      Reviewed By: agoder@fb.com
      
      FB internal diff: D1269526
      188e13f3
    • Jim Meyering's avatar
      folly: allow to build with clang.dev (flex arrays vs. lambda) · a6e257a5
      Jim Meyering authored
      Summary:
      * folly/test/CacheLocalityTest.cpp (contentionAtWidth): Work around
      clang's prohibition against using flexible arrays in a lambda.
      
      Test Plan:
      fbconfig --clang --with-project-version clang:dev folly/test \
      && fbmake runtests
      
      Reviewed By: ngbronson@fb.com
      
      FB internal diff: D1263620
      a6e257a5
    • Philip Pronin's avatar
      configurable alignment for Arena · 970c7961
      Philip Pronin authored
      Summary: Allow specifying custom alignment.
      
      Test Plan: fbconfig -r folly/test && fbmake opt -j32
      
      @override-unit-failures
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D1264851
      970c7961
  2. 09 Apr, 2014 11 commits
    • ptarjan's avatar
      Make header compatible with warp · 074bdb7f
      ptarjan authored
      074bdb7f
    • Philip Pronin's avatar
      fix ConcurrentSkipList::Recycler layout · d92b1b90
      Philip Pronin authored
      Summary:
      D1261546 introduced regression in `sizeof(ConcurrentSkipList)`.
      In case of `NodeAlloc = folly::SysAlloc`, size of an empty `NodeAlloc` struct
      is 1 byte, due to the alignment requirements of the next field, it got
      translated into wasting 8 bytes.
      
      Test Plan: fbconfig -r folly/test && fbmake opt -j32
      
      @override-unit-failures
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D1264730
      d92b1b90
    • Jim Meyering's avatar
      folly: accommodate fact that clang's strlen is not constexpr · bfdcbc20
      Jim Meyering authored
      Summary:
      * folly/folly-config.h (FOLLY_HAVE_CONSTEXPR_STRLEN): Define to
      zero when compiling with clang, since clang's strlen is not constexpr.
      
      Test Plan:
      Run this:
      fbconfig --clang --with-project-version clang:dev folly/test && fbconfig dbg
      and observe that the following no longer strikes:
      folly/test/RangeTest.cpp:304:25: error: constexpr variable 'hello1' must be initialized by a constant expression
      
      I also tried using clang-3.4 (the current default),
      fbconfig --clang folly/test && fbmake dbg
      with these results:
      https://phabricator.fb.com/P8583443
      
      Reviewed By: pgriess@fb.com
      
      FB internal diff: D1262840
      bfdcbc20
    • Dave Watson's avatar
      Fix make check · 8e82fd34
      Dave Watson authored
      Summary: Fix make check.  Benchmark.cpp was included twice, eventfd doesn't exist anymore.
      
      Test Plan: autoreconf -i; ./configure; make check on ubuntu
      
      Reviewed By: pgriess@fb.com
      
      FB internal diff: D1259706
      8e82fd34
    • Dave Watson's avatar
      fix automake · d666fcdb
      Dave Watson authored
      Summary:
      Automake complains there are two Malloc.cpp rules - rename one of them.
      
      Facebook: Actually this file doesn't even build in fbconfig - is it still necessary?
      
      Test Plan: autoreconf -i on ubuntu doens't fail
      
      Reviewed By: pgriess@fb.com
      
      FB internal diff: D1257372
      d666fcdb
    • Hans Fugal's avatar
      (wangle) codegen then() variant tests · 64d0f9a3
      Hans Fugal authored
      Summary:
      When all the variants I am dreaming of work, there's a little more than
      100 tests generated.
      
      Test Plan: fbmake runtests
      
      Reviewed By: hannesr@fb.com
      
      FB internal diff: D1258754
      64d0f9a3
    • Hannes Roth's avatar
      (Folly/FBString) Fix compilation time of test with opt · a71d861b
      Hannes Roth authored
      Summary: Now compiles in 18 seconds. Took two minutes before.
      
      Test Plan: `fbmake runtests_opt`
      
      Reviewed By: smith@fb.com
      
      FB internal diff: D1243689
      a71d861b
    • Philip Pronin's avatar
      configurable node allocator for ConcurrentSkipList · ac2aa280
      Philip Pronin authored
      Summary:
      Allow specifying `SimpleAllocator` to use for node allocation.
      Added optimizations for arena allocators.
      
      Test Plan: fbconfig -r folly/test && fbmake opt -j32
      
      Reviewed By: soren@fb.com
      
      FB internal diff: D1261546
      ac2aa280
    • Philip Pronin's avatar
      make ConcurrentSkipList ctor public · 0fd4f579
      Philip Pronin authored
      Summary:
      There is no reason to force heap allocation for
      `ConcurrentSkipList`.
      
      Test Plan: fbconfig -r unicorn/test && fbmake opt -j32
      
      @override-unit-failures
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D1261183
      0fd4f579
    • Tom Jackson's avatar
      Adding support for signed integers · ff03c3a8
      Tom Jackson authored
      Summary: For use with Thrift::Frozen, especially.
      
      Test Plan: Unit tests
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D1255257
      ff03c3a8
    • Nicholas Ormrod's avatar
      Bugfix in iterator emplace · 14e2c0f8
      Nicholas Ormrod authored
      Summary:
      Subtle bugfix to fbvector
      
      Reproduction requirements:
      - emplace into a vector at a non-end position
      - the vector has enough capacity for the extra elements
      - the value type's internal state is poisoned after a move
      
      What should happen, explained by picture:
      
      INITIAL SETUP
      
      abc1234XY____
      ^
      want to insert two elements here
      
      FIRST STEP: uninitialized move-construction
      x and y are initialized, but could be in an invalid state
      
      abc1234xyXY__
      
      SECOND STEP: move-assignment, in reverse order
      
      abc123xy4XY__
      abc12xy34XY__
      abc1xy234XY__
      abcxy1234XY__
      
      What actually happens:
      An indexing error causes the entire tail (##1234xy##) to be
      move-assigned, instead of the intended head of the tail (##1234##).
      
      If the data type's move operator does not invalidate its own data (i.e.
      move is essentially a copy, as is the case with atomic types) then the
      move assignment of ##y## onto ##Y## and ##x## onto ##X## is basically a
      no-op. However, for types that do invalidate their own data when being
      the source of a move (e.g. non-empty vectors and fbvectors), then the
      end result will have bad data in place of ##X## and ##Y##.
      
      Detection:
      This bug has lain dormant for a while.
      
      Very few people emplace into a vector, and those few who do could be
      saved by using a copy-movable type like int.
      
      The original test case did not use a data type which poisoned itself
      after being the source of a move, so the tests did not notice any
      oddities.
      
      A new testsuite, which does poison itself, did notice.
      
      Test Plan:
      re-enable the test/stl_test mega-test. Run it. All tests
      pass.
      
      fbconfig -r folly && fbmake runtests_opt
      
      Run fbvector through the new test suite (which initially caught the
      error). It now passes.
      
      Reviewed By: robbert@fb.com
      
      FB internal diff: D1257258
      14e2c0f8
  3. 04 Apr, 2014 6 commits
    • Hans Fugal's avatar
      A few missing includes · fbee7f6b
      Hans Fugal authored
      Summary: These were required to build folly on OSX.
      
      Test Plan: build
      
      Reviewed By: davejwatson@fb.com
      
      FB internal diff: D1256856
      fbee7f6b
    • Hans Fugal's avatar
      (wangle) Use an atomic_flag to make FutureObject threadsafe · 8fefa085
      Hans Fugal authored
      Summary:
      There are two operations on `FutureObject` (the backing object that both `Future` and `Promise` front), which are not threadsafe currently. Those are `setContinuation` and `fulfil`. They're not threadsafe because they have a race condition between checking to see whether they should run the continuation and the other side making its modification. This diff introduces a `std::atomic_flag` variable to avoid the race and make these threadsafe.
      
      NB Making `Future`/`Promise` threadsafe does not make this pattern safe:
      
      f1.via(...).then(...).then(...)
      
      (In a hypothetical world where `Future::via` is another name for `executeWithSameThread`)
      There is a race between the future from `via` and the call of `then` (and between the first and second `then`s), so the `then`s could execute in the far thread as intended, or they could execute in the current thread (probably not what was intended). This diff does not solve that semantic problem of which thread this runs in. But it does make it safer, in that all those continuations will always execute, just maybe not in the thread you had intended.
      
      You may ask what is the benefit if that semantic problem still exists? That's up for debate. I think the safety is worth it: at least everything a n00b throws at it will *work*. The question of thread semantics can iterate. If we end up with thread semantics that really don't need locks (e.g. maybe because we move to an Rx/Later style "launch" at the end of a chain) we can always toss this atomic.
      
      How does this affect performance? I'm doing some experiments and going to write up my findings. Early results indicate that outlier performance is impacted but not by a lot, but don't count those chickens until I hatch them. Part of the reason for sending this diff out is to run windtunnel experiments.
      
      Test Plan: tests, benchmark, close inspection
      
      Reviewed By: davejwatson@fb.com
      
      FB internal diff: D1241822
      8fefa085
    • Louis Kruger's avatar
      Fix TIMED_SYNCHRONIZED_CONST bug · 7de41cd3
      Louis Kruger authored
      Summary:
      TIMED_SYNCHRONIZED_CONST is acquiring a read-write lock but releasing a shared lock.  Chaos ensues.
      @override-unit-failures
      
      Test Plan: Add unit test, test times out before fix, passes after fix.
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D1251518
      
      Blame Revision: D327492
      7de41cd3
    • Tudor Bosman's avatar
      Add ability to silence callbacks for Subprocess::communicate · 30c26b8f
      Tudor Bosman authored
      Summary:
      Subprocess::communicate callbacks are level-triggered, which makes writing
      "chatty" communication protocols difficult -- you often want to silence the
      write callback until you read the expected message. Add
      Subprocess::enableNotifications() for this purpose.
      
      Test Plan: test added
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D1251564
      
      @override-unit-failures
      30c26b8f
    • Stepan Palamarchuk's avatar
      Add loopOnce() method to folly::EventBase · 2d08baf6
      Stepan Palamarchuk authored
      Summary: Add loopOnce() method which provides functionality similar to event_base_loop(base, EVLOOP_ONCE);
      
      Test Plan: fbmake
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D1249753
      2d08baf6
    • Mikhail Okunev's avatar
      Utility that converts from prettyPrint format back to double (e.g. 10M = 10 000 000) · 36194671
      Mikhail Okunev authored
      Summary: Utility is doing reverse of prettyPrint. This is a first sketch.
      
      Test Plan:
      1) We can reverse all tests from prettyPrint test and use for our function. For now I just reversed several of them
      2) We can also test prettyPrint and prettyToDouble together by checking whether prettyToDouble(prettyPrint(X)) == X. This is implemented.
      
      Reviewed By: marcelo.juchem@fb.com
      
      FB internal diff: D1159879
      36194671
  4. 31 Mar, 2014 9 commits
    • Hannes Roth's avatar
      (Folly/FBString) Use a lambda to throw an exception for NULL input · 72c2a0d3
      Hannes Roth authored
      Summary:
      This should be standard compliant. `__PRETTY_FUNCTION__` seems
      unnecessary, it just prints `basic_fbstring`, might as well use that and
      simplify the code.
      
      Test Plan:
      `fbconfig --platform-all=gcc-4.8.1-glibc-2.17-fb folly/test`
      `fbmake runtests_dbg`
      `fbmake runtests_opt`
      
      `fbconfig --platform-all=gcc-4.7.1-glibc-2.14.1 folly/test`
      `fbmake runtests_dbg`
      `fbmake runtests_opt`
      
      `fbconfig --clang folly/test`
      `...`
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D1243670
      72c2a0d3
    • Nicholas Ormrod's avatar
      NULL -> nullptr · 52fceaf4
      Nicholas Ormrod authored
      Summary:
      Change NULLs to nullptrs.
      
      Facebook:
      I was tired of seeing lint errors for NULL -> nullptr, so I
      fixed it.
      
      How: modified flint's tokenizer to output lines of the form
      
      sed -i '__LINE__s|\<NULL\>|nullptr|g' __FILE__
      
      for each NULL token encountered.
      
      Ran the sed lines, restricted to filepaths with extensions
      h,hpp,cc,cpp,tcc. Did not apply to FacebookUpdate, due to weird
      formatting; hphp, to be done in a separate diff; payment, due to a large
      number of generated text which didn't play well with my flow; and
      memcache, which has lots of .h's that cannot contain nullptr's because
      they are included from .c's.
      
      @bypass-lint
      
      Test Plan:
      fbconfig -r common folly && fbmake opt && fbmake runtests_opt
      ^ of the 4k+ test cases, about two dozen are failing. Slightly more
      failed in master than with my diff applied.
      
      arc unit
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D1234261
      52fceaf4
    • Tom Jackson's avatar
      Range::contains(x) · 7154531b
      Tom Jackson authored
      Test Plan: Unit tests
      
      Reviewed By: marcelo.juchem@fb.com
      
      FB internal diff: D1236630
      7154531b
    • Tudor Bosman's avatar
      Optionally specify page size in MemoryMapping ctor · 922f80e0
      Tudor Bosman authored
      Summary:
      For proper rounding, and also so memOpInChunks doesn't try to mlock / munlock /
      madvise / munmap in chunks smaller than the page size.
      
      Test Plan: memory_mapping_test
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D1232153
      922f80e0
    • Hannes Roth's avatar
      (Wangle) Sanity check for the small_vector test · d4738210
      Hannes Roth authored
      Summary:
      Let's double check that `small_vector` is doing the right thing. So
      it doesn't just accidentally work.
      
      Test Plan:
      `fbconfig folly/wangle && fbmake runtests`
      `fbconfig --clang folly/wangle && fbmake runtests`
      
      Reviewed By: marccelani@fb.com
      
      FB internal diff: D1231360
      d4738210
    • Dave Watson's avatar
      EventBase cleanup · 7697ddef
      Dave Watson authored
      Summary: Moar c++11 features.  marccelani's comments in D1195393, but in a separate diff.
      
      Test Plan:
      contbuild
      fbconfig thrift/lib/cpp/test/
      fbmake runtests
      
      Reviewed By: rajat@fb.com
      
      FB internal diff: D1219158
      7697ddef
    • Nima Aghdaii's avatar
      Performance Improvement for AsciiCaseInsensitive · 10a36321
      Nima Aghdaii authored
      Summary:
      This implementation improves the performance of AsciiCaseInsensitive.
      AsciiCaseInsensitive uses toupper, and it's slow.
      Since toupper only works for ascii characters and this function does exactly the same thing over the range of [0..256), we can gain 3x performance here.
      
      Test Plan: unit test and benchmark
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D1217596
      
      @override-unit-failures
      10a36321
    • Hannes Roth's avatar
      (Wangle) Fix tests for clang · 11aac0ec
      Hannes Roth authored
      Summary: `std::async` doesn't play nicely with our clang. Replace it with `std::thread`.
      
      Test Plan: `fbconfig --clang folly/wangle && fbmake runtests`
      
      Reviewed By: marccelani@fb.com
      
      FB internal diff: D1230197
      11aac0ec
    • Tudor Bosman's avatar
      Harden usingJEMalloc() · cd838428
      Tudor Bosman authored
      Summary:
      In a shared library, we're using whichever memory allocator the main program
      uses, but we may still believe we're using jemalloc if we load libjemalloc.so
      (because rallocm is defined). This means we'll pass to rallocm pointers that
      were not allocated by jemalloc, which is bad.
      
      Test Plan: tests added
      
      Reviewed By: ngbronson@fb.com
      
      FB internal diff: D1228483
      cd838428
  5. 18 Mar, 2014 5 commits
    • Tom Jackson's avatar
      range(), for making Range<T*> from arrays and std::vector · d9c79af8
      Tom Jackson authored
      Summary: So people can more easily write functions which take contiguous values from memory.
      
      Test Plan: Unit tests
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D1217809
      d9c79af8
    • Tianjiao Yin's avatar
      Add constexpr specifier for small_vector::max_size · 00162667
      Tianjiao Yin authored
      Summary: Now we could use small_vector::max_size in constant expressions
      
      Test Plan: unittest
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D1224274
      00162667
    • Tudor Bosman's avatar
      Unbreak Symbolizer with small ElfCache · 4d966258
      Tudor Bosman authored
      Test Plan: fbconfig -r folly/experimental/symbolizer && fbmake runtests_opt && fbmake runtests
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D1224552
      
      @override-unit-failures
      4d966258
    • Alexey Spiridonov's avatar
      Move commited bits out of folly · 7f4c8868
      Alexey Spiridonov authored
      Summary: Preparing to land the other diffs. No code changes here, just moving files around.
      
      Test Plan: fbconfig bistro/common/cron/test bistro/common/cron/utils/test ; fbmake runtests
      
      Reviewed By: yinwang@fb.com
      
      FB internal diff: D1225159
      7f4c8868
    • Marc Celani's avatar
      sorted_vector_types have move inserts · cc4eb4c8
      Marc Celani authored
      Summary: sorted_vector_types were missing move inserts that come with std::map in c++11. This prevents me from using move iterators in folly::merge use case.
      
      Test Plan: unit tests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D1223426
      cc4eb4c8