1. 19 Mar, 2013 34 commits
    • David Vickrey's avatar
      Make hash_combine accept a configurable hash function · e4f530f8
      David Vickrey authored
      Summary:
      std::hash is not awesome and not configurable.  Typical cases you might want to customize are:
      string: I happen to know that fnv isn't super awesome, for example, and that's what folly uses for std::hash fbstring.
      pointers: you may want to hash the contents of the pointer instead of the address for certain types.
      
      This is a very simple diff that lets you do that.  It provides StdHasher that passes through to std::hash and uses that for hash_combine, so this should be 100% backward compatible.
      
      Test Plan: test_hash.  I will add another test for using a hasher besides StdHasher shortly.
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D733899
      e4f530f8
    • Tom Jackson's avatar
      Fixing namespace for GeneratorBuilder, more moves for Params · 9fb46d14
      Tom Jackson authored
      Summary:
      GENERATOR was broken if you didn't `using namespace folly::gen`, and
      we're still copying quite a few functors where we could move them.
      
      Test Plan: Unit tests
      
      Reviewed By: chaoyc@fb.com
      
      FB internal diff: D731253
      9fb46d14
    • Lovro Puzar's avatar
      Add explicit assignment operator definitions to Optional · fd20c97c
      Lovro Puzar authored
      Summary:
      See new test.  Under GCC 4.6 (which is what the folly tests build with) the old code works fine but under 4.7 building fails with:
      
      folly/test/OptionalTest.cpp: In member function ‘virtual void Optional_AssignmentContained_Test::TestBody()’:
      folly/test/OptionalTest.cpp:122:14: error: use of deleted function ‘ContainsOptional& ContainsOptional::operator=(const ContainsOptional&)’
      folly/test/OptionalTest.cpp:106:21: note: ‘ContainsOptional& ContainsOptional::operator=(const ContainsOptional&)’ is implicitly deleted because the default definition would be ill-formed:
      folly/test/OptionalTest.cpp:106:21: error: use of deleted function ‘folly::Optional<int>& folly::Optional<int>::operator=(const folly::Optional<int>&)’
      In file included from folly/test/OptionalTest.cpp:17:0:
      ./folly/Optional.h:84:7: note: ‘folly::Optional<int>& folly::Optional<int>::operator=(const folly::Optional<int>&)’ is implicitly declared as deleted because ‘folly::Optional<int>’ declares a move constructor or move assignment operator
      folly/test/OptionalTest.cpp:129:30: error: use of deleted function ‘ContainsOptional& ContainsOptional::operator=(ContainsOptional&&)’
      folly/test/OptionalTest.cpp:108:21: note: ‘ContainsOptional& ContainsOptional::operator=(ContainsOptional&&)’ is implicitly deleted because the default definition would be ill-formed:
      folly/test/OptionalTest.cpp:108:21: error: non-static data member ‘ContainsOptional::opt_’ does not have a move assignment operator or trivial copy assignment operator
      folly/test/OptionalTest.cpp:137:14: error: use of deleted function ‘ContainsOptional& ContainsOptional::operator=(const ContainsOptional&)’
      
      Test Plan:
      (1) fbconfig folly/test && fbmake dbg && _build/dbg/folly/test/optional_test
      (2) Remove folly/PLATFORM to build with gcc 4.7, then repeat (1).  Without the code fix, the new test fails to build.  With the fix, the test builds and runs fine.
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D732402
      fd20c97c
    • Ben Gertzfield's avatar
      folly (easy): Disable GCC-specific warning disabling hacks in clang · d006f324
      Ben Gertzfield authored
      Summary:
      When compiling folly with clang, the compiler warns about our
      use of GCC-specific pragmas to silence incorrect compiler warnings:
      
      folly/Optional.h:79:33: warning: unknown warning group '-Wpragmas', ignored [-Wunknown-pragmas]
      folly/Optional.h:80:33: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-pragmas]
      
      Thankfully, those incorrect compiler warnings are not emitted by
      clang, so we can just disable the pragmas in clang.
      
      Test Plan:
      Built folly in gcc and ran it through clang. Warning above
      is gone.
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D733323
      d006f324
    • Tudor Bosman's avatar
      Add CHECK for out-of-range minRequests · 30313905
      Tudor Bosman authored
      Test Plan: async_io_test
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D730100
      30313905
    • Tom Jackson's avatar
      Remove File::tryOpen · a6fac16f
      Tom Jackson authored
      Summary:
      In hopes of keeping 'busywork' helpers out of folly, I've moved this
      closer to the code that needed to do this.
      
      Test Plan: Unit tests
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D729194
      
      Blame Revision: D726916
      a6fac16f
    • Tom Jackson's avatar
      File::tryOpen · 9d6c66dd
      Tom Jackson authored
      Summary:
      Now that we have truthy files, it would be nice to be able to simply
      //try// opening files and return a possibly-initialized File.
      
      Test Plan: Unit tests
      
      Reviewed By: chaoyc@fb.com
      
      FB internal diff: D726916
      9d6c66dd
    • Tom Jackson's avatar
      Truthy File · 9d7cc509
      Tom Jackson authored
      Summary:
      File has a default constructor so it can be initialized late, but it
      doesn't have a good canonical way to see if it's been initialized. This adds an
      //explicit// operator bool so you can test files like `if (file) ...`.
      
      Test Plan: Unit tests
      
      Reviewed By: chaoyc@fb.com
      
      FB internal diff: D726914
      9d7cc509
    • Tudor Bosman's avatar
      Add resizing constructor to folly::padded::Adaptor · f4cbf351
      Tudor Bosman authored
      Summary: Added Adaptor(size_t, const value_type&)
      
      Test Plan: test added
      
      Reviewed By: soren@fb.com
      
      FB internal diff: D726358
      f4cbf351
    • Tom Jackson's avatar
      Adding useful error message for File · 218b5231
      Tom Jackson authored
      Summary:
      'open() failed' isn't too helpful. Seeing a filename there is. So I
      added it.
      
      Test Plan: Unit test
      
      Reviewed By: mohittalwar@fb.com
      
      FB internal diff: D725204
      218b5231
    • Adam Simpkins's avatar
      provide a flag to control the minimum number of iterations · f0abc60e
      Adam Simpkins authored
      Summary:
      Add a --bm_min_iters flag to control the minimum number of iterations
      that the benchmark code starts with on each epoch.
      
      This can be used on benchmarks that test very cheap operations, but take
      a long time to set up.  Otherwise the benchmark code may have to retry
      many times before it hits a large enough number of iterations to get a
      meaningful result, and each time it still pays the fixed setup cost.
      
      This also helps with benchmarks when some of the setup cost cannot be
      hidden with BenchmarkSuspender for some reason.  --bm_min_iters can be
      set to a large enough value so that the extra startup cost will not
      affect the measurements too much.
      
      Test Plan:
      Used this with the thread local stats benchmark.  During setup/cleanup,
      this benchmark starts and synchronizes with many threads.  The entire
      setup time cannot be reliably hidden with BenchmarkSuspender; the
      synchronization between the threads takes a relatively long time
      compared to the cost of the operation being benchmarked.  --bm_min_iters
      allows a relatively high number of iterations to be used, masking this
      cost.
      
      Reviewed By: rajat@fb.com
      
      FB internal diff: D723304
      f0abc60e
    • Mike Curtiss's avatar
      folly::make_optional · 8c89c7dd
      Mike Curtiss authored
      Summary:
      Helper method for creating a folly::Optional<T> by just passing
      in a T reference.  Analogous to boost::make_optional.
      
      Test Plan: Added test case
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D721762
      8c89c7dd
    • Lucian Grijincu's avatar
      MemoryMapping::data() returns StringPiece ::range() returns ByteRange · cb610acb
      Lucian Grijincu authored
      Summary: MemoryMapping::data() returns StringPiece ::range() returns ByteRange
      
      Test Plan: tests
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D720985
      cb610acb
    • Owen Yamauchi's avatar
      Abstract ifunc support into a define · 3a976a95
      Owen Yamauchi authored
      Summary:
      There are platforms other than clang that don't support ifuncs. (The one
      I'm concerned about is ARM.) I changed the ifdef __clang__ around the
      ifunc attributes to be more abstract, so we can can pass in this flag on
      the command line, or use autoconf to detect it.
      
      Test Plan:
      fbmake runtests. Manually define HAVE_IFUNC 0 and make sure the
      popcount() and popcountll() functions get compiled as calls to
      popcount_builtin.
      
      Run autoreconf, ./configure, make sure the feature gets detected
      properly by looking at config.h.
      
      Reviewed By: andrewjcg@fb.com
      
      FB internal diff: D712192
      3a976a95
    • Tom Jackson's avatar
      Renaming flag in MemoryMapping · d059cdd4
      Tom Jackson authored
      Summary:
      This flag conflicts with the flag with the same purpose in
      `common/files/MemoryMappedFile.cpp`. Just renaming it for now.
      
      Test Plan: Build
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D717067
      d059cdd4
    • Tom Jackson's avatar
      MemoryMapping · 2b8ea381
      Tom Jackson authored
      Summary: MemoryMapping is a C++ wrapper object around mmap. It works with `folly::File`s, and provides bitwise-range access for reading and writing files.
      
      Test Plan: Unit test
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D452384
      2b8ea381
    • Lucian Grijincu's avatar
      folly: AsyncIO: add debuging helper · 88b49f3e
      Lucian Grijincu authored
      Summary: Change State to enum class, and add debugging helper to AsyncIOOp and AsyncIO.
      
      Test Plan: n/a
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D715676
      88b49f3e
    • Tom Jackson's avatar
      folly/{experimental => .}/File · feca2a76
      Tom Jackson authored
      Summary: Moving File into `/folly`.
      
      Test Plan: Same unit tests, rebuild affected code outside folly.
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D714462
      feca2a76
    • Mike Curtiss's avatar
      Fix SIGSEGV in StringPiece::find_first_of · 4f7a54f6
      Mike Curtiss authored
      Summary:
      Our SSE version of find_first_of was reading past the end of
      the StringPiece in some cases, which (very rarely) caused a seg-fault
      when we were reading outside of our allotted virtual address space.
      
      Modify the code to never read past the end of the underlying buffers
      except when we think it's "safe" because we're still within the same
      page. (ASSUMPTION: if a process is allowed to read a byte within a
      page, then it is allowed to read _all_ bytes within that page.)
      
      Test Plan:
      Added tests that verify we won't go across page boundaries.
      
      Sadly, this code hurts our benchmarks -- sometimes by up to 50% for
      smaller strings.
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D707923
      
      Blame Revision: D638500
      4f7a54f6
    • Tudor Bosman's avatar
      Rework folly::AsyncIO interface to make it easier for other classes to use Op · a8b4b5ea
      Tudor Bosman authored
      Summary:
      AsyncIOOp no longer requires derivation to be able to use callbacks; the
      callback is passed in.  This makes composition easier (see AsyncIOQueue, added
      in this diff).
      
      Test Plan: async_io_test, test added
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D709648
      a8b4b5ea
    • Tudor Bosman's avatar
      fix comment · cf583f13
      Tudor Bosman authored
      Test Plan: No
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D709795
      cf583f13
    • Rajat Goel's avatar
      value_ might be uninitialized · 3cc8d95a
      Rajat Goel authored
      Summary: Compilation is failing in 'opt' build
      
      Test Plan: compile
      
      Reviewed By: andrewjcg@fb.com
      
      FB internal diff: D707869
      3cc8d95a
    • Tudor Bosman's avatar
      Define ALLOCM_LG_ALIGN · 5fabcaa4
      Tudor Bosman authored
      Test Plan: No
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D707792
      5fabcaa4
    • Gaurav Jain's avatar
      Minor clang compiler fixes · 267e38a8
      Gaurav Jain authored
      Summary: Minor clang compiler fixes
      
      Test Plan: - fbmake runtest
      
      Reviewed By: andrewjcg@fb.com
      
      FB internal diff: D707663
      267e38a8
    • Sergey Doroshenko's avatar
      Make AsyncIO::capacity_ const · bae2dccf
      Sergey Doroshenko authored
      Summary: It is set once, and is never changed afterwards.
      
      Test Plan: compiled, unit tests
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D706125
      bae2dccf
    • Jordan DeLong's avatar
      Codemod time\(NULL\) to time(nullptr) · a449e4aa
      Jordan DeLong authored
      Summary: codemod with 'Yes to all'.
      
      Test Plan: None really.
      
      Reviewed By: abirchall@fb.com
      
      FB internal diff: D693769
      a449e4aa
    • Tudor Bosman's avatar
      Fix subtle double-free in trimEnd; optionally pack IOBufQueue after append · 794e35e5
      Tudor Bosman authored
      Test Plan: folly/io/test, both dbg and opt, standalone and in valgrind
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D702755
      794e35e5
    • Tom Jackson's avatar
      all(), better any() · 0e21224b
      Tom Jackson authored
      Summary: TSIA
      
      Test Plan: Unit tests
      
      Reviewed By: tulloch@fb.com
      
      FB internal diff: D701890
      0e21224b
    • Tudor Bosman's avatar
      fix typos · 04223d27
      Tudor Bosman authored
      Test Plan: async_io_test
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D699175
      04223d27
    • Peter Griess's avatar
      Add some CursorBase::operator-() implementations · 9547cef8
      Peter Griess authored
      Summary:
      - Add CursorBase::operator-() implementations for Cursor and BufType;
      useful for figuring out the distance between two objects
      
      Test Plan: - Used in some other code
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D690046
      9547cef8
    • Philip Pronin's avatar
      assert on self move assignment · 2a80dba7
      Philip Pronin authored
      Test Plan: ran tests in dbg
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D696964
      2a80dba7
    • Tudor Bosman's avatar
      AsyncIO: CHECK preconditions · ce80e19d
      Tudor Bosman authored
      Test Plan: async_io_test
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D698919
      ce80e19d
    • Tudor Bosman's avatar
      AsyncIO in folly · 8f45b8d5
      Tudor Bosman authored
      Summary:
      Interface extended and cleaned up.  Also, now
      actually allows you to retrieve IO errors.  Also moved some useful functions
      out of Subprocess.cpp into a separate header file.
      
      Test Plan: async_io_test, subprocess_test
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D698412
      8f45b8d5
    • Andrew Tulloch's avatar
      unsplit · 43300949
      Andrew Tulloch authored
      Summary:
      1. Incorporates @tjackson's offline comments.
      2. See docstrings and examples for basic usage.
      3. The usecase this covers (for me and others) was where I have some map or
      vector of elements, and I want to form a string representation of this (for
      logging, fb303 exported values, etc.). Various uses have existed in fbcode (e.g.
      UP2X shard representations), and this seemed like a useful utility.
      
      Test Plan: unit tests.
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D696794
      43300949
  2. 04 Feb, 2013 6 commits
    • Jordan DeLong's avatar
      Update example in folly::gen · b88cb304
      Jordan DeLong authored
      Summary: asVector() doesn't exist.
      
      Test Plan: Nope.
      
      Reviewed By: tjackson@fb.com
      
      FB internal diff: D697240
      b88cb304
    • Tom Jackson's avatar
      contains() · 482a5011
      Tom Jackson authored
      Summary: TSIA
      
      Test Plan: Unit tests
      
      Reviewed By: tulloch@fb.com
      
      FB internal diff: D680177
      482a5011
    • Andrew Gallagher's avatar
      folly/dynamic: fix explicit specializations after instantiation · a0d036e4
      Andrew Gallagher authored
      Summary:
      clang complains that the explicit specializations in dynamic.cpp
      come after references in dynamic-inl.h.
      
      Test Plan:
      - built dyamic.o with clang
      - built folly normally and ran unittests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D691081
      a0d036e4
    • Marcelo Juchem's avatar
      adding some missing remove_reference in make_stl_allocator and is_simple_allocator · e1df3470
      Marcelo Juchem authored
      Summary: adding some missing remove_reference in make_stl_allocator and is_simple_allocator
      
      Test Plan: unit tests
      
      Reviewed By: jon.coens@fb.com
      
      FB internal diff: D689524
      e1df3470
    • Jordan DeLong's avatar
      Remove a bit of debug code in folly::Range · d50ff184
      Jordan DeLong authored
      Summary:
      Seems like we can drop this, as the case that motivated
      adding it wouldn't have been caught by it.
      
      Test Plan: Compiled folly/test.
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D684200
      d50ff184
    • Xin Liu's avatar
      fixing rwspinlock test Summary: · a60c8646
      Xin Liu authored
      Summary:
      gcc seems to treat this as declaration:
      
      RWSpinLock::UpgradedHolder ug(
      RWSpinLock::WriteHolder(
      RWSpinLock::ReadHolder(&lock)));
      
      Test Plan: add LOG(INFO) to make sure the holder converstions did get executed.
      
      Reviewed By: marcelo.juchem@fb.com
      
      FB internal diff: D688748
      a60c8646