diff options
10 files changed, 71 insertions, 39 deletions
diff --git a/searchlib/src/tests/sortspec/multilevelsort.cpp b/searchlib/src/tests/sortspec/multilevelsort.cpp index 4d81cf303d7..84f67a041b0 100644 --- a/searchlib/src/tests/sortspec/multilevelsort.cpp +++ b/searchlib/src/tests/sortspec/multilevelsort.cpp @@ -241,7 +241,7 @@ MultilevelSortTest::sortAndCheck(const std::vector<Spec> &spec, uint32_t num, } vespalib::Clock clock; - vespalib::Doom doom(clock, std::numeric_limits<long>::max()); + vespalib::Doom doom(clock, std::numeric_limits<fastos::TimeStamp::TimeT>::max()); search::uca::UcaConverterFactory ucaFactory; FastS_SortSpec sorter(7, doom, ucaFactory, _sortMethod); // init sorter with sort data diff --git a/searchlib/src/tests/util/statebuf/statebuf_test.cpp b/searchlib/src/tests/util/statebuf/statebuf_test.cpp index 61f1194bcb6..40abf942fa1 100644 --- a/searchlib/src/tests/util/statebuf/statebuf_test.cpp +++ b/searchlib/src/tests/util/statebuf/statebuf_test.cpp @@ -52,10 +52,16 @@ TEST_F("keys can be appended to stream", Fixture) } -TEST_F("integers can be appended to stream", Fixture) +TEST_F("positive integers can be appended to stream", Fixture) { - f << (UINT64_C(1) << 63) << " " << -42l << " " << 0l; - EXPECT_EQUAL("9223372036854775808 -42 0", f.str()); + f << (1ull << 63) << " " << 42l << " " << 21 << " " << 0; + EXPECT_EQUAL("9223372036854775808 42 21 0", f.str()); +} + +TEST_F("negative integers can be appended to stream", Fixture) +{ + f << (1ll << 63) << " " << -42l << " " << -21; + EXPECT_EQUAL("-9223372036854775808 -42 -21", f.str()); } TEST_F("struct timespec can be appended to stream", Fixture) diff --git a/searchlib/src/vespa/searchlib/common/bitvector.cpp b/searchlib/src/vespa/searchlib/common/bitvector.cpp index ddc4f7af944..2c45bc8f69a 100644 --- a/searchlib/src/vespa/searchlib/common/bitvector.cpp +++ b/searchlib/src/vespa/searchlib/common/bitvector.cpp @@ -385,9 +385,9 @@ MMappedBitVector::read(Index numberOfElements, FastOS_FileInterface &file, nbostream & operator<<(nbostream &out, const BitVector &bv) { - size_t size = bv.size(); - size_t cachedHits = bv.countTrueBits(); - size_t fileBytes = bv.getFileBytes(); + uint64_t size = bv.size(); + uint64_t cachedHits = bv.countTrueBits(); + uint64_t fileBytes = bv.getFileBytes(); assert(size <= std::numeric_limits<BitVector::Index>::max()); assert(cachedHits <= size || ! bv.isValidCount(cachedHits)); assert(bv.testBit(size)); @@ -400,9 +400,9 @@ operator<<(nbostream &out, const BitVector &bv) nbostream & operator>>(nbostream &in, BitVector &bv) { - size_t size; - size_t cachedHits; - size_t fileBytes; + uint64_t size; + uint64_t cachedHits; + uint64_t fileBytes; in >> size >> cachedHits >> fileBytes; assert(size <= std::numeric_limits<BitVector::Index>::max()); assert(cachedHits <= size || ! bv.isValidCount(cachedHits)); diff --git a/searchlib/src/vespa/searchlib/common/packets.cpp b/searchlib/src/vespa/searchlib/common/packets.cpp index e7ec0ffc9b9..9862e221610 100644 --- a/searchlib/src/vespa/searchlib/common/packets.cpp +++ b/searchlib/src/vespa/searchlib/common/packets.cpp @@ -1312,7 +1312,7 @@ uint32_t FS4Packet::readUInt32(FNET_DataBuffer & buf, uint32_t & len, const char void FS4Packet_GETDOCSUMSX::setTimeout(const fastos::TimeStamp & timeout) { - _timeout = std::max(0l, timeout.ms()); + _timeout = std::max(INT64_C(0), timeout.ms()); } fastos::TimeStamp @@ -1324,7 +1324,7 @@ FS4Packet_GETDOCSUMSX::getTimeout() const void FS4Packet_QUERYX::setTimeout(const fastos::TimeStamp & timeout) { - _timeout = std::max(0l, timeout.ms()); + _timeout = std::max(INT64_C(0), timeout.ms()); } fastos::TimeStamp diff --git a/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp b/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp index 78ed12ac8da..2f59bb30847 100644 --- a/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp +++ b/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.cpp @@ -77,7 +77,7 @@ SimpleQueryStackDumpIterator::next() uint64_t tmp(0); if (ParseItem::GetFeature_Weight(typefield)) { - long tmpLong; + int64_t tmpLong; if (p >= _bufEnd) return false; p += vespalib::compress::Integer::decompress(tmpLong, p); _currWeight.setPercent(tmpLong); diff --git a/searchlib/src/vespa/searchlib/util/statebuf.cpp b/searchlib/src/vespa/searchlib/util/statebuf.cpp index 12d18599a41..af1c7dda30d 100644 --- a/searchlib/src/vespa/searchlib/util/statebuf.cpp +++ b/searchlib/src/vespa/searchlib/util/statebuf.cpp @@ -72,7 +72,7 @@ StateBuf::appendKey(const char *s) noexcept StateBuf & -StateBuf::operator<<(unsigned long val) noexcept +StateBuf::operator<<(unsigned long long val) noexcept { char buf[22]; char *p = buf; @@ -92,21 +92,37 @@ StateBuf::operator<<(unsigned long val) noexcept StateBuf & -StateBuf::operator<<(long val) noexcept +StateBuf::operator<<(long long val) noexcept { if (val < 0) { - *this << '-' << static_cast<unsigned long>(- val); + *this << '-' << static_cast<unsigned long long>(- val); } else { - *this << static_cast<unsigned long>(val); + *this << static_cast<unsigned long long>(val); } return *this; } StateBuf & +StateBuf::operator<<(unsigned long val) noexcept +{ + *this << static_cast<unsigned long long>(val); + return *this; +} + + +StateBuf & +StateBuf::operator<<(long val) noexcept +{ + *this << static_cast<long long>(val); + return *this; +} + + +StateBuf & StateBuf::operator<<(unsigned int val) noexcept { - *this << static_cast<unsigned long>(val); + *this << static_cast<unsigned long long>(val); return *this; } @@ -114,7 +130,7 @@ StateBuf::operator<<(unsigned int val) noexcept StateBuf & StateBuf::operator<<(int val) noexcept { - *this << static_cast<long>(val); + *this << static_cast<long long>(val); return *this; } diff --git a/searchlib/src/vespa/searchlib/util/statebuf.h b/searchlib/src/vespa/searchlib/util/statebuf.h index 6f847e82c66..3dbf8beaf16 100644 --- a/searchlib/src/vespa/searchlib/util/statebuf.h +++ b/searchlib/src/vespa/searchlib/util/statebuf.h @@ -59,6 +59,12 @@ public: appendAddr(void *addr) noexcept; StateBuf & + operator<<(unsigned long long val) noexcept; + + StateBuf & + operator<<(long long val) noexcept; + + StateBuf & operator<<(unsigned long val) noexcept; StateBuf & diff --git a/staging_vespalib/src/tests/json/json.cpp b/staging_vespalib/src/tests/json/json.cpp index d7d9d0ac332..79709c6f8b9 100644 --- a/staging_vespalib/src/tests/json/json.cpp +++ b/staging_vespalib/src/tests/json/json.cpp @@ -276,22 +276,22 @@ namespace { struct Builder : public vespalib::JsonStreamTypes { void build(JsonStream& s) { s << Object() << "k1" << Object() - << "k1.1" << 1l + << "k1.1" << 1 << "k1.2" << Array() - << 2l << 3l << End() + << 2l << 3ll << End() << End() << "k2" << Object() << "k2.1" << Object() - << "k2.1.1" << 4l + << "k2.1.1" << 4u << "k2.1.2" << Array() - << 5l << 6l << End() + << 5ul << 6ull << End() << End() << End() << "k3" << Array() << Object() - << "k3.1" << 7l + << "k3.1" << -7 << "k3.2" << Array() - << 8l << 9l << End() + << -8l << -9ll << End() << End() << Object() << "k3.1" << 10l @@ -312,7 +312,7 @@ JSONTest::testJsonStream() Builder b; b.build(stream); stream.finalize(); - EXPECT_EQUAL(as.str(), "{\"k1\":{\"k1.1\":1,\"k1.2\":[2,3]},\"k2\":{\"k2.1\":{\"k2.1.1\":4,\"k2.1.2\":[5,6]}},\"k3\":[{\"k3.1\":7,\"k3.2\":[8,9]},{\"k3.1\":10,\"k3.2\":[11,12]}]}"); + EXPECT_EQUAL(as.str(), "{\"k1\":{\"k1.1\":1,\"k1.2\":[2,3]},\"k2\":{\"k2.1\":{\"k2.1.1\":4,\"k2.1.2\":[5,6]}},\"k3\":[{\"k3.1\":-7,\"k3.2\":[-8,-9]},{\"k3.1\":10,\"k3.2\":[11,12]}]}"); } void @@ -397,14 +397,14 @@ JSONTest::testJsonStreamErrors() vespalib::JsonStream stream(as); stream << Object() << End() << 13; } catch (vespalib::JsonStreamException& e) { - EXPECT_EQUAL("Invalid state on call: Stream already finalized. Can't add an int64_t value. (Finalized)", e.getReason()); + EXPECT_EQUAL("Invalid state on call: Stream already finalized. Can't add a long long value. (Finalized)", e.getReason()); } try{ vespalib::asciistream as; vespalib::JsonStream stream(as); - stream << Object() << End() << uint64_t(13); + stream << Object() << End() << 13u; } catch (vespalib::JsonStreamException& e) { - EXPECT_EQUAL("Invalid state on call: Stream already finalized. Can't add a uint64_t value. (Finalized)", e.getReason()); + EXPECT_EQUAL("Invalid state on call: Stream already finalized. Can't add an unsigned long long value. (Finalized)", e.getReason()); } try{ vespalib::asciistream as; diff --git a/staging_vespalib/src/vespa/vespalib/util/jsonstream.cpp b/staging_vespalib/src/vespa/vespalib/util/jsonstream.cpp index d2fae8f62a7..1feeca489eb 100644 --- a/staging_vespalib/src/vespa/vespalib/util/jsonstream.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/jsonstream.cpp @@ -150,10 +150,10 @@ JsonStream::operator<<(float value) } JsonStream& -JsonStream::operator<<(int64_t value) +JsonStream::operator<<(long long value) { if (_state.empty()) { - fail("Stream already finalized. Can't add an int64_t value."); + fail("Stream already finalized. Can't add a long long value."); } switch (top().state) { case State::OBJECT_EXPECTING_KEY: { @@ -180,10 +180,10 @@ JsonStream::operator<<(int64_t value) } JsonStream& -JsonStream::operator<<(uint64_t value) +JsonStream::operator<<(unsigned long long value) { if (_state.empty()) { - fail("Stream already finalized. Can't add a uint64_t value."); + fail("Stream already finalized. Can't add an unsigned long long value."); } switch (top().state) { case State::OBJECT_EXPECTING_KEY: { diff --git a/staging_vespalib/src/vespa/vespalib/util/jsonstream.h b/staging_vespalib/src/vespa/vespalib/util/jsonstream.h index 8dfde992e4d..872e6f8ee0f 100644 --- a/staging_vespalib/src/vespa/vespalib/util/jsonstream.h +++ b/staging_vespalib/src/vespa/vespalib/util/jsonstream.h @@ -69,18 +69,22 @@ public: JsonStream& operator<<(bool); JsonStream& operator<<(double); JsonStream& operator<<(float); // Less precision that double - JsonStream& operator<<(int64_t); - JsonStream& operator<<(uint64_t); + JsonStream& operator<<(long long); + JsonStream& operator<<(unsigned long long); JsonStream& operator<<(const Object&); JsonStream& operator<<(const Array&); JsonStream& operator<<(const End&); // Additional functions provided to let compiler work out correct // function without requiring user to cast their value - JsonStream& operator<<(uint32_t v) - { return operator<<(static_cast<int64_t>(v)); } - JsonStream& operator<<(int32_t v) - { return operator<<(static_cast<int64_t>(v)); } + JsonStream& operator<<(unsigned long v) + { return operator<<(static_cast<unsigned long long>(v)); } + JsonStream& operator<<(unsigned int v) + { return operator<<(static_cast<unsigned long long>(v)); } + JsonStream& operator<<(long v) + { return operator<<(static_cast<long long>(v)); } + JsonStream& operator<<(int v) + { return operator<<(static_cast<long long>(v)); } JsonStream& operator<<(const char* c) { return operator<<(stringref(c)); } |