Include config file path in JSON output

Required for dmd-testsuite's compilable/json2.d.

Also fixes a bug regarding ConfigFile::path() with a null config file
path (e.g., when disabled explicitly via `-conf=`) - the
std::string(const char *) ctor segfaults for a null pointer arg,
whereas llvm::StringRef handles null pointers gracefully.
This commit is contained in:
Martin 2018-03-30 23:56:37 +02:00
parent 426555f354
commit 32b7637528
4 changed files with 14 additions and 8 deletions

View file

@ -18,11 +18,14 @@
namespace opts {
char *dupPathString(const std::string &src) {
char *r = mem.xstrdup(src.c_str());
char *dupPathString(llvm::StringRef src) {
const auto length = src.size();
char *r = static_cast<char *>(mem.xmalloc(length + 1));
memcpy(r, src.data(), length);
#if _WIN32
std::replace(r, r + src.length(), '/', '\\');
std::replace(r, r + length, '/', '\\');
#endif
r[length] = '\0';
return r;
}