Skip to content

Commit

Permalink
Disable use of folly::resizeWithoutInitialization() under Visual Stud…
Browse files Browse the repository at this point in the history
…io 2019 and later until supported
  • Loading branch information
traceon committed Mar 2, 2020
1 parent ed05c65 commit 94e40eb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion driver/format/ODBCDriver2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void ODBCDriver2ResultSet::readValue(std::string & dest, bool * is_null) {
readSize(size);

if (size >= 0) {
folly::resizeWithoutInitialization(dest, size);
resize_without_initialization(dest, size);

if (is_null)
*is_null = false;
Expand Down
3 changes: 2 additions & 1 deletion driver/format/RowBinaryWithNamesAndTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ void RowBinaryWithNamesAndTypesResultSet::readValue(std::string & res) {
}

void RowBinaryWithNamesAndTypesResultSet::readValue(std::string & dest, const std::uint64_t size) {
folly::resizeWithoutInitialization(dest, size);
resize_without_initialization(dest, size);

try {
stream.read(dest.data(), dest.size());
}
Expand Down
17 changes: 11 additions & 6 deletions driver/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# include "driver/utils/iostream_debug_helpers.h"
#endif

#include <folly/memory/UninitializedMemoryHacks.h>

#include <Poco/NumberParser.h>
#include <Poco/String.h>
#include <Poco/UTF8String.h>
Expand All @@ -35,6 +33,13 @@

#include <cstring>

#if defined(_MSC_VER) && _MSC_VER > 1916 // Not supported yet for Visual Studio 2019 and later.
# define resize_without_initialization(container, size) container.resize(size)
#else
# include <folly/memory/UninitializedMemoryHacks.h>
# define resize_without_initialization(container, size) folly::resizeWithoutInitialization(container, size)
#endif

class Environment;
class Connection;
class Descriptor;
Expand Down Expand Up @@ -230,23 +235,23 @@ class AmortizedIStreamReader
if (free_capacity < to_read) { // Reallocation is unavoidable. Compact the buffer while doing it.
if (avail > 0) {
decltype(buffer_) tmp;
folly::resizeWithoutInitialization(tmp, avail + to_read);
resize_without_initialization(tmp, avail + to_read);
std::memcpy(&tmp[0], &buffer_[offset_], avail);
buffer_.swap(tmp);
}
else {
buffer_.clear();
folly::resizeWithoutInitialization(buffer_, to_read);
resize_without_initialization(buffer_, to_read);
}
}
else { // Compacting the buffer is enough.
std::memmove(&buffer_[0], &buffer_[offset_], avail);
folly::resizeWithoutInitialization(buffer_, avail + to_read);
resize_without_initialization(buffer_, avail + to_read);
}
offset_ = 0;
}
else {
folly::resizeWithoutInitialization(buffer_, buffer_.size() + to_read);
resize_without_initialization(buffer_, buffer_.size() + to_read);
}

raw_stream_.read(&buffer_[offset_ + avail], to_read);
Expand Down

0 comments on commit 94e40eb

Please sign in to comment.