From ec0ae81ea7599ec2378a08aa62f23422f42bc917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ferreira?= Date: Sun, 29 Sep 2024 09:52:07 +0100 Subject: [PATCH] std/path: make globMatch work with @nogc --- std/path.d | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/std/path.d b/std/path.d index a45865a9f18..ecd5bca4517 100644 --- a/std/path.d +++ b/std/path.d @@ -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]; @@ -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])(); + } const len1 = pi - 1 - pi0; pattmp[0 .. len1] = pattern[pi0 .. pi - 1]; @@ -3518,7 +3522,7 @@ do } /// -@safe unittest +@safe @nogc unittest { assert(globMatch("foo.bar", "*")); assert(globMatch("foo.bar", "*.*"));