Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std/path: make globMatch work with @nogc #9055

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions std/path.d
Original file line number Diff line number Diff line change
Expand Up @@ -3396,7 +3396,10 @@ do
}
else
{
import core.memory : pureMalloc, pureFree;
C[] pattmp;
scope(exit) if (pattmp !is null) (() @trusted => pureFree(pattmp.ptr))();

for (size_t pi = 0; pi < pattern.length; pi++)
{
const pc = pattern[pi];
Expand Down Expand Up @@ -3482,9 +3485,10 @@ do
* pattern[pi0 .. pi-1] ~ pattern[piRemain..$]
*/
if (pattmp is null)
{
// Allocate this only once per function invocation.
// Should do it with malloc/free, but that would make it impure.
pattmp = new C[pattern.length];
pattmp = (() @trusted => (cast(C*)pureMalloc(C.sizeof * pattern.length))[0 .. pattern.length])();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforce space after cast(...)
grep -nrE '[^"]cast\([^)]*?\)[[:alnum:]]' $(find etc std -name '*.d') ; test $? -eq 1
std/path.d:3490:                                pattmp = (() @trusted => (cast(C*)pureMalloc(C.sizeof * pattern.length))[0 .. pattern.length])();

}

const len1 = pi - 1 - pi0;
pattmp[0 .. len1] = pattern[pi0 .. pi - 1];
Expand Down Expand Up @@ -3518,7 +3522,7 @@ do
}

///
@safe unittest
@safe @nogc unittest
{
assert(globMatch("foo.bar", "*"));
assert(globMatch("foo.bar", "*.*"));
Expand Down
Loading