Skip to content

Commit 08858e0

Browse files
std/path: make globMatch work with @nogc (#9055)
1 parent b6245b4 commit 08858e0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

std/path.d

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,7 +3395,10 @@ do
33953395
}
33963396
else
33973397
{
3398+
import core.memory : pureMalloc, pureFree;
33983399
C[] pattmp;
3400+
scope(exit) if (pattmp !is null) (() @trusted => pureFree(pattmp.ptr))();
3401+
33993402
for (size_t pi = 0; pi < pattern.length; pi++)
34003403
{
34013404
const pc = pattern[pi];
@@ -3481,9 +3484,12 @@ do
34813484
* pattern[pi0 .. pi-1] ~ pattern[piRemain..$]
34823485
*/
34833486
if (pattmp is null)
3487+
{
34843488
// Allocate this only once per function invocation.
3485-
// Should do it with malloc/free, but that would make it impure.
3486-
pattmp = new C[pattern.length];
3489+
pattmp = (() @trusted =>
3490+
(cast(C*) pureMalloc(C.sizeof * pattern.length))[0 .. pattern.length])
3491+
();
3492+
}
34873493

34883494
const len1 = pi - 1 - pi0;
34893495
pattmp[0 .. len1] = pattern[pi0 .. pi - 1];
@@ -3517,7 +3523,7 @@ do
35173523
}
35183524

35193525
///
3520-
@safe unittest
3526+
@safe @nogc unittest
35213527
{
35223528
assert(globMatch("foo.bar", "*"));
35233529
assert(globMatch("foo.bar", "*.*"));

0 commit comments

Comments
 (0)