Skip to content

Commit

Permalink
vendor: Update vendored sources to duckdb/duckdb@d707b44 (#998)
Browse files Browse the repository at this point in the history
Not using Random Device in DuckDB Core (duckdb/duckdb#15540)

Co-authored-by: krlmlr <[email protected]>
  • Loading branch information
github-actions[bot] and krlmlr authored Jan 9, 2025
1 parent 1189fa7 commit d732c12
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
18 changes: 17 additions & 1 deletion src/duckdb/src/common/random_engine.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#include "duckdb/common/random_engine.hpp"
#include "duckdb/common/numeric_utils.hpp"
#include "pcg_random.hpp"
#include <random>

#ifdef __linux__
#include <sys/syscall.h>
#include <unistd.h>
#else
#include <random>
#endif
namespace duckdb {

struct RandomState {
Expand All @@ -14,7 +19,18 @@ struct RandomState {

RandomEngine::RandomEngine(int64_t seed) : random_state(make_uniq<RandomState>()) {
if (seed < 0) {
#ifdef __linux__
idx_t random_seed;
auto result = syscall(SYS_getrandom, &random_seed, sizeof(random_seed), 0);
if (result == -1) {
// Something went wrong with the syscall, we use chrono
const auto now = std::chrono::high_resolution_clock::now();
random_seed = now.time_since_epoch().count();
}
random_state->pcg.seed(random_seed);
#else
random_state->pcg.seed(pcg_extras::seed_seq_from<std::random_device>());
#endif
} else {
random_state->pcg.seed(NumericCast<uint64_t>(seed));
}
Expand Down
9 changes: 3 additions & 6 deletions src/duckdb/src/common/string_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "duckdb/common/to_string.hpp"
#include "duckdb/common/helper.hpp"
#include "duckdb/common/exception/parser_exception.hpp"
#include "duckdb/common/random_engine.hpp"
#include "jaro_winkler.hpp"
#include "utf8proc_wrapper.hpp"

Expand All @@ -16,7 +17,6 @@
#include <sstream>
#include <stdarg.h>
#include <string.h>
#include <random>
#include <stack>

#include "yyjson.hpp"
Expand All @@ -26,13 +26,10 @@ using namespace duckdb_yyjson; // NOLINT
namespace duckdb {

string StringUtil::GenerateRandomName(idx_t length) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 15);

RandomEngine engine;
std::stringstream ss;
for (idx_t i = 0; i < length; i++) {
ss << "0123456789abcdef"[dis(gen)];
ss << "0123456789abcdef"[engine.NextRandomInteger(0, 15)];
}
return ss.str();
}
Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/src/function/table/version/pragma_version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DUCKDB_PATCH_VERSION
#define DUCKDB_PATCH_VERSION "4-dev4255"
#define DUCKDB_PATCH_VERSION "4-dev4271"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 1
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.1.4-dev4255"
#define DUCKDB_VERSION "v1.1.4-dev4271"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "d3444ef141"
#define DUCKDB_SOURCE_ID "d707b4432b"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
17 changes: 3 additions & 14 deletions src/duckdb/third_party/httplib/httplib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ using socket_t = int;
#include <map>
#include <memory>
#include <mutex>
#include <random>
#include <regex>
#include <set>
#include <sstream>
Expand All @@ -246,9 +245,8 @@ using socket_t = int;
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <utility>

#include "duckdb/common/re2_regex.hpp"
#include "duckdb/common/random_engine.hpp"

#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
#ifdef _WIN32
Expand Down Expand Up @@ -4646,19 +4644,10 @@ inline std::string make_multipart_data_boundary() {
static const char data[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

// std::random_device might actually be deterministic on some
// platforms, but due to lack of support in the c++ standard library,
// doing better requires either some ugly hacks or breaking portability.
std::random_device seed_gen;

// Request 128 bits of entropy for initialization
std::seed_seq seed_sequence{seed_gen(), seed_gen(), seed_gen(), seed_gen()};
std::mt19937 engine(seed_sequence);

std::string result = "--cpp-httplib-multipart-data-";

duckdb::RandomEngine engine;
for (auto i = 0; i < 16; i++) {
result += data[engine() % (sizeof(data) - 1)];
result += data[engine.NextRandomInteger32(0,sizeof(data) - 1)];
}

return result;
Expand Down
1 change: 0 additions & 1 deletion src/duckdb/third_party/skiplist/SkipList.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@
#include <vector>
#include <set> // Used for HeadNode::_lacksIntegrityNodeReferencesNotInList()
#include <string> // Used for class Exception
#include <random>
#include "pcg_random.hpp"

#ifdef DEBUG
Expand Down

0 comments on commit d732c12

Please sign in to comment.