diff options
| author | George Hazan <ghazan@miranda.im> | 2018-06-19 19:29:34 +0300 |
|---|---|---|
| committer | George Hazan <ghazan@miranda.im> | 2018-06-19 19:29:34 +0300 |
| commit | 4a2f58413213da8393ea049f5df2f4694b2e0c35 (patch) | |
| tree | 4e73b0c8d7cc1ae31f074c0d4e485e87c3ae2130 /plugins/Dbx_mdbx/src/libmdbx/test | |
| parent | 98166ec48d49755c8915d0cc7fa87fdf3084a15c (diff) | |
merge of libmdbx 1.5
Diffstat (limited to 'plugins/Dbx_mdbx/src/libmdbx/test')
| -rw-r--r-- | plugins/Dbx_mdbx/src/libmdbx/test/base.h | 8 | ||||
| -rw-r--r-- | plugins/Dbx_mdbx/src/libmdbx/test/log.cc | 2 | ||||
| -rw-r--r-- | plugins/Dbx_mdbx/src/libmdbx/test/log.h | 2 | ||||
| -rw-r--r-- | plugins/Dbx_mdbx/src/libmdbx/test/main.cc | 5 | ||||
| -rw-r--r-- | plugins/Dbx_mdbx/src/libmdbx/test/osal-windows.cc | 87 | ||||
| -rw-r--r-- | plugins/Dbx_mdbx/src/libmdbx/test/test.cc | 6 |
6 files changed, 97 insertions, 13 deletions
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/base.h b/plugins/Dbx_mdbx/src/libmdbx/test/base.h index f0c6043220..bc82ff26c0 100644 --- a/plugins/Dbx_mdbx/src/libmdbx/test/base.h +++ b/plugins/Dbx_mdbx/src/libmdbx/test/base.h @@ -32,10 +32,10 @@ #endif /* _MSC_VER (warnings) */ /* If you wish to build your application for a previous Windows platform, -* include WinSDKVer.h and set the _WIN32_WINNT macro to the platform you -* wish to support before including SDKDDKVer.h. -* -* TODO: #define _WIN32_WINNT WIN32_MUSTDIE */ + * include WinSDKVer.h and set the _WIN32_WINNT macro to the platform you + * wish to support before including SDKDDKVer.h. + * + * TODO: #define _WIN32_WINNT WIN32_MUSTDIE */ #include <SDKDDKVer.h> #endif /* WINDOWS */ diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/log.cc b/plugins/Dbx_mdbx/src/libmdbx/test/log.cc index 6ad33ced35..521e1d6900 100644 --- a/plugins/Dbx_mdbx/src/libmdbx/test/log.cc +++ b/plugins/Dbx_mdbx/src/libmdbx/test/log.cc @@ -206,7 +206,7 @@ void local_suffix::pop() { local_suffix::~local_suffix() { suffix.erase(trim_pos); } -} /* namespace log */ +} // namespace logging void log_extra(const char *msg, ...) { if (logging::extra >= logging::level) { diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/log.h b/plugins/Dbx_mdbx/src/libmdbx/test/log.h index 81eaf2ca91..e97e954cea 100644 --- a/plugins/Dbx_mdbx/src/libmdbx/test/log.h +++ b/plugins/Dbx_mdbx/src/libmdbx/test/log.h @@ -70,7 +70,7 @@ public: ~local_suffix(); }; -} /* namespace log */ +} // namespace logging void __printf_args(1, 2) log_extra(const char *msg, ...); void __printf_args(1, 2) log_trace(const char *msg, ...); diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/main.cc b/plugins/Dbx_mdbx/src/libmdbx/test/main.cc index 98461a245d..bc3198ed3a 100644 --- a/plugins/Dbx_mdbx/src/libmdbx/test/main.cc +++ b/plugins/Dbx_mdbx/src/libmdbx/test/main.cc @@ -122,9 +122,8 @@ int main(int argc, char *const argv[]) { if (argc < 2) failure("No parameters given\n"); - if (argc == 2 && - strncmp(argv[1], global::thunk_param_prefix, - strlen(global::thunk_param_prefix)) == 0) + if (argc == 2 && strncmp(argv[1], global::thunk_param_prefix, + strlen(global::thunk_param_prefix)) == 0) return test_execute( actor_config(argv[1] + strlen(global::thunk_param_prefix))) ? EXIT_SUCCESS diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/osal-windows.cc b/plugins/Dbx_mdbx/src/libmdbx/test/osal-windows.cc index 5d2e51a66d..109c835a96 100644 --- a/plugins/Dbx_mdbx/src/libmdbx/test/osal-windows.cc +++ b/plugins/Dbx_mdbx/src/libmdbx/test/osal-windows.cc @@ -168,6 +168,90 @@ bool actor_config::osal_deserialize(const char *str, const char *end, typedef std::pair<HANDLE, actor_status> child; static std::unordered_map<mdbx_pid_t, child> childs; +static void ArgvQuote(std::string &CommandLine, const std::string &Argument, + bool Force = false) + +/*++ + +https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/ + +Routine Description: + + This routine appends the given argument to a command line such + that CommandLineToArgvW will return the argument string unchanged. + Arguments in a command line should be separated by spaces; this + function does not add these spaces. + +Arguments: + + Argument - Supplies the argument to encode. + + CommandLine - Supplies the command line to which we append the encoded +argument string. + + Force - Supplies an indication of whether we should quote + the argument even if it does not contain any characters that would + ordinarily require quoting. + +Return Value: + + None. + +Environment: + + Arbitrary. + +--*/ + +{ + // + // Unless we're told otherwise, don't quote unless we actually + // need to do so --- hopefully avoid problems if programs won't + // parse quotes properly + // + + if (Force == false && Argument.empty() == false && + Argument.find_first_of(" \t\n\v\"") == Argument.npos) { + CommandLine.append(Argument); + } else { + CommandLine.push_back('"'); + + for (auto It = Argument.begin();; ++It) { + unsigned NumberBackslashes = 0; + + while (It != Argument.end() && *It == '\\') { + ++It; + ++NumberBackslashes; + } + + if (It == Argument.end()) { + // + // Escape all backslashes, but let the terminating + // double quotation mark we add below be interpreted + // as a metacharacter. + // + CommandLine.append(NumberBackslashes * 2, '\\'); + break; + } else if (*It == L'"') { + // + // Escape all backslashes and the following + // double quotation mark. + // + CommandLine.append(NumberBackslashes * 2 + 1, '\\'); + CommandLine.push_back(*It); + } else { + // + // Backslashes aren't special here. + // + CommandLine.append(NumberBackslashes, '\\'); + CommandLine.push_back(*It); + } + } + + CommandLine.push_back('"'); + } +} + int osal_actor_start(const actor_config &config, mdbx_pid_t &pid) { if (childs.size() == MAXIMUM_WAIT_OBJECTS) failure("Could't manage more that %u actors on Windows\n", @@ -184,7 +268,8 @@ int osal_actor_start(const actor_config &config, mdbx_pid_t &pid) { &exename_size)) failure_perror("QueryFullProcessImageName()", GetLastError()); - std::string cmdline = "test_mdbx.child " + thunk_param(config); + std::string cmdline = "test_mdbx.child "; + ArgvQuote(cmdline, thunk_param(config)); PROCESS_INFORMATION ProcessInformation; if (!CreateProcessA(exename, const_cast<char *>(cmdline.c_str()), diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/test.cc b/plugins/Dbx_mdbx/src/libmdbx/test/test.cc index 02986b3d1a..3750af525f 100644 --- a/plugins/Dbx_mdbx/src/libmdbx/test/test.cc +++ b/plugins/Dbx_mdbx/src/libmdbx/test/test.cc @@ -85,9 +85,9 @@ static void mdbx_logger(int type, const char *function, int line, level = logging::failure; } - if (logging::output(level, strncmp(function, "mdbx_", 5) == 0 ? "%s: " - : "mdbx: %s: ", - function)) + if (logging::output( + level, + strncmp(function, "mdbx_", 5) == 0 ? "%s: " : "mdbx: %s: ", function)) logging::feed(msg, args); if (type & MDBX_DBG_ASSERT) abort(); |
