Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions compiler/src/dmd/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,23 @@ private int tryMain(size_t argc, const(char)** argv, out Param params)

foreach (entry; imppath)
{
int sink(const(char)* p) nothrow
struct SinkContext
{
ImportPathInfo temp = entry;
ImportPathInfo* entry;
Array!ImportPathInfo* array;
}

static int sink(const(char)* p, void* ctx) nothrow
{
auto c = cast(SinkContext*)ctx;
ImportPathInfo temp = *c.entry;
temp.path = p;
array.push(temp);
c.array.push(temp);
return 0;
}

FileName.splitPath(&sink, entry.path);
SinkContext context = SinkContext(&entry, &array);
FileName.splitPath(&sink, entry.path, &context);
FileName.appendSplitPath(entry.path, pathsOnlyArray);
}

Expand Down
37 changes: 22 additions & 15 deletions compiler/src/dmd/root/filename.d
Original file line number Diff line number Diff line change
Expand Up @@ -471,23 +471,26 @@
// Split a path and append the results to `array`
extern (C++) static void appendSplitPath(const(char)* path, ref Strings array)
{
int sink(const(char)* p) nothrow
static int sink(const(char)* p, void* ctx) nothrow
{
array.push(p);
auto arr = cast(Strings*)ctx;
arr.push(p);
return 0;
}
splitPath(&sink, path);
splitPath(&sink, path, &array);
}


/****
* Split path (such as that returned by `getenv("PATH")`) into pieces, each piece is mem.xmalloc'd
* Handle double quotes and ~.
* Pass the pieces to sink()
* Params:
* sink = send the path pieces here, end when sink() returns !=0
* path = the path to split up.
* ctx = pointer to context passed to sink
*/
static void splitPath(int delegate(const(char)*) nothrow sink, const(char)* path)
static void splitPath(int function(const(char)*, void*) nothrow sink, const(char)* path, void* ctx)
{
if (!path)
return;
Expand Down Expand Up @@ -561,8 +564,8 @@
}
if (buf.length) // if path is not empty
{
if (sink(buf.extractChars()))
break;
if (sink(buf.extractChars(), ctx))
break;

Check warning on line 568 in compiler/src/dmd/root/filename.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/root/filename.d#L568

Added line #L568 was not covered by tests
}
} while (c);
}
Expand Down Expand Up @@ -712,31 +715,35 @@
extern (D) static const(char)[] searchPath(const char* path, const char[] name, bool cwd)
{
if (absolute(name))
{
return exists(name) ? name : null;
}
if (cwd)
{
if (exists(name))
return name;
}
if (path && *path)
{
const(char)[] result;

int sink(const(char)* p) nothrow
struct SinkContext
{
const(char)[] name;
const(char)[]* resultSlot;
}
SinkContext ctx = { name, &result };

Check warning on line 731 in compiler/src/dmd/root/filename.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/root/filename.d#L731

Added line #L731 was not covered by tests

static int sink(const(char)* p, void* vctx) nothrow
{
auto n = combine(p.toDString, name);
auto ctx = cast(SinkContext*)vctx;
auto n = combine(p.toDString, ctx.name);

Check warning on line 736 in compiler/src/dmd/root/filename.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/root/filename.d#L735-L736

Added lines #L735 - L736 were not covered by tests
mem.xfree(cast(void*)p);
if (exists(n))
{
result = n;
return 1; // done with splitPath() call
*ctx.resultSlot = n;
return 1;

Check warning on line 741 in compiler/src/dmd/root/filename.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/root/filename.d#L740-L741

Added lines #L740 - L741 were not covered by tests
}
return 0;
}

splitPath(&sink, path);
splitPath(&sink, path, &ctx);

Check warning on line 746 in compiler/src/dmd/root/filename.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/root/filename.d#L746

Added line #L746 was not covered by tests
return result;
}
return null;
Expand Down
Loading