From 327e91681765e1928d1d5dcc3bb8e2762e389cdc Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 31 Jul 2026 12:42:18 +0300 Subject: [PATCH 01/29] core.system.Mem.reallocate alias added and used in registerGCFactory() --- druntime/src/core/gc/registry.d | 4 ++-- druntime/src/core/system.d | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 druntime/src/core/system.d diff --git a/druntime/src/core/gc/registry.d b/druntime/src/core/gc/registry.d index 2e6edf09c3e7..83e732c5f58f 100644 --- a/druntime/src/core/gc/registry.d +++ b/druntime/src/core/gc/registry.d @@ -60,9 +60,9 @@ alias GCThreadInitFunction = void function(ThreadBase base) nothrow @nogc; void registerGCFactory(string name, GCFactory factory, GCThreadInitFunction threadInit = null) nothrow @nogc { - import core.stdc.stdlib : realloc; + import core.system : Mem; - auto ptr = cast(Entry*)realloc(entries.ptr, (entries.length + 1) * Entry.sizeof); + auto ptr = cast(Entry*) Mem.reallocate(entries.ptr, (entries.length + 1) * Entry.sizeof); entries = ptr[0 .. entries.length + 1]; entries[$ - 1] = Entry(name, factory, threadInit); } diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d new file mode 100644 index 000000000000..994dd7efb18f --- /dev/null +++ b/druntime/src/core/system.d @@ -0,0 +1,11 @@ +/// +module core.system; + +package: + +static struct Mem +{ + import core.stdc.stdlib; + + alias reallocate = realloc; +} From 2cb303cb913fd3d78eb5f69e104d8243464390c2 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 31 Jul 2026 12:51:48 +0300 Subject: [PATCH 02/29] core.system.Mem: allocate and free aliases added and used in Runtime.loadLibrary() --- druntime/src/core/runtime.d | 10 +++++----- druntime/src/core/system.d | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/druntime/src/core/runtime.d b/druntime/src/core/runtime.d index 8cdb999c92fd..524cc3ca9ad7 100644 --- a/druntime/src/core/runtime.d +++ b/druntime/src/core/runtime.d @@ -209,7 +209,7 @@ struct Runtime */ static void* loadLibrary()(const scope char[] name) { - import core.stdc.stdlib : free, malloc; + import core.system : Mem; version (Windows) { import core.sys.windows.winnls : CP_UTF8, MultiByteToWideChar; @@ -222,9 +222,9 @@ struct Runtime if (len == 0) return null; - auto buf = cast(WCHAR*)malloc((len+1) * WCHAR.sizeof); + auto buf = cast(WCHAR*) Mem.allocate((len+1) * WCHAR.sizeof); if (buf is null) return null; - scope (exit) free(buf); + scope (exit) Mem.free(buf); len = MultiByteToWideChar( CP_UTF8, 0, name.ptr, cast(int)name.length, buf, len); @@ -240,9 +240,9 @@ struct Runtime /* Need a 0-terminated C string for the dll name */ immutable len = name.length; - auto buf = cast(char*)malloc(len + 1); + auto buf = cast(char*) Mem.allocate(len + 1); if (!buf) return null; - scope (exit) free(buf); + scope (exit) Mem.free(buf); buf[0 .. len] = name[]; buf[len] = 0; diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d index 994dd7efb18f..f21d3bcb0fb4 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system.d @@ -7,5 +7,7 @@ static struct Mem { import core.stdc.stdlib; + alias allocate = malloc; alias reallocate = realloc; + alias free = core.stdc.stdlib.free; } From 90237dccf9588c9d7e8917fb3089124ceea7203d Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 31 Jul 2026 13:14:58 +0300 Subject: [PATCH 03/29] Mem.allocateBlank() added --- druntime/mak/COPY | 1 + druntime/mak/SRCS | 1 + druntime/src/core/system.d | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/druntime/mak/COPY b/druntime/mak/COPY index 90dc5e23f599..3ed916ff8cd3 100644 --- a/druntime/mak/COPY +++ b/druntime/mak/COPY @@ -23,6 +23,7 @@ COPY=\ $(IMPDIR)\core\memory.d \ $(IMPDIR)\core\runtime.d \ $(IMPDIR)\core\simd.d \ + $(IMPDIR)\core\system.d \ $(IMPDIR)\core\time.d \ $(IMPDIR)\core\vararg.d \ $(IMPDIR)\core\volatile.d \ diff --git a/druntime/mak/SRCS b/druntime/mak/SRCS index eff0ab33b62c..b345ad10a842 100644 --- a/druntime/mak/SRCS +++ b/druntime/mak/SRCS @@ -17,6 +17,7 @@ SRCS=\ src\core\memory.d \ src\core\runtime.d \ src\core\simd.d \ + src\core\system.d \ src\core\time.d \ src\core\vararg.d \ src\core\volatile.d \ diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d index f21d3bcb0fb4..81fdfc4eeb01 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system.d @@ -3,11 +3,18 @@ module core.system; package: -static struct Mem +struct Mem { import core.stdc.stdlib; alias allocate = malloc; alias reallocate = realloc; alias free = core.stdc.stdlib.free; + + static void* allocateBlank(size_t size) nothrow @nogc + { + ubyte* p = cast(ubyte*) allocate(size); + p[0 .. size] = 0; + return cast(void*) p; + } } From c8e5b4e18349eb95da6a26af321f6223ff7624f5 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 31 Jul 2026 13:15:30 +0300 Subject: [PATCH 04/29] calloc() and free() replaced by Mem in core.internal.gc.os module --- druntime/src/core/internal/gc/bits.d | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/druntime/src/core/internal/gc/bits.d b/druntime/src/core/internal/gc/bits.d index 8aabf9e393d7..d9607967cad5 100644 --- a/druntime/src/core/internal/gc/bits.d +++ b/druntime/src/core/internal/gc/bits.d @@ -11,7 +11,7 @@ import core.internal.gc.os; import core.bitop; import core.exception : onOutOfMemoryError; -import core.stdc.stdlib : calloc, free; +import core.system : Mem; import core.stdc.string : memcpy, memset; // use version gcbitsSingleBitOperation to disable optimizations that use @@ -38,7 +38,7 @@ struct GCBits if (data) { if (!AllocSupportsShared || !share) - free(data); + Mem.free(data); else static if (AllocSupportsShared) os_mem_unmap_shared(data, nwords * data[0].sizeof); else @@ -51,7 +51,7 @@ struct GCBits { this.nbits = nbits; if (!AllocSupportsShared || !share) - data = cast(typeof(data[0])*)calloc(nwords, data[0].sizeof); + data = cast(typeof(data[0])*) Mem.allocateBlank(nwords * data[0].sizeof); else static if (AllocSupportsShared) data = cast(typeof(data[0])*)os_mem_map_shared(nwords * data[0].sizeof); // Allocate as MAP_SHARED else From f17cea962ea0504604260ab00f0d6ccae3d77396 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 31 Jul 2026 14:44:55 +0300 Subject: [PATCH 05/29] Mem.allocateBlank() on Posix uses calloc() --- druntime/src/core/system.d | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d index 81fdfc4eeb01..4c6fb42d80f5 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system.d @@ -11,10 +11,14 @@ struct Mem alias reallocate = realloc; alias free = core.stdc.stdlib.free; + static void* allocateBlank(size_t size) nothrow @nogc => calloc(1, size); + + /+ static void* allocateBlank(size_t size) nothrow @nogc { ubyte* p = cast(ubyte*) allocate(size); p[0 .. size] = 0; return cast(void*) p; } + +/ } From 6c6908364beea9f9c9a870cec61137baadea243c Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 31 Jul 2026 15:09:22 +0300 Subject: [PATCH 06/29] module rt.minfo now uses core.system.Mem --- druntime/src/core/system.d | 3 +- druntime/src/rt/minfo.d | 58 +++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d index 4c6fb42d80f5..67d9fab93b84 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system.d @@ -1,7 +1,8 @@ /// module core.system; -package: +//TODO: package +//package: struct Mem { diff --git a/druntime/src/rt/minfo.d b/druntime/src/rt/minfo.d index a70aabbeb648..cc72831f5fd6 100644 --- a/druntime/src/rt/minfo.d +++ b/druntime/src/rt/minfo.d @@ -13,7 +13,7 @@ module rt.minfo; import core.stdc.stdio : fprintf, stderr; -import core.stdc.stdlib : free, malloc, realloc; +import core.system : Mem; import core.stdc.string : memcpy, memset; import rt.sections; @@ -66,11 +66,11 @@ struct ModuleGroup import core.bitop : bt, btc, bts; // set up all the arrays. - size_t[] cyclePath = (cast(size_t*)malloc(size_t.sizeof * _modules.length * 2))[0 .. _modules.length * 2]; + size_t[] cyclePath = (cast(size_t*) Mem.allocate(size_t.sizeof * _modules.length * 2))[0 .. _modules.length * 2]; size_t totalMods; - int[] distance = (cast(int*)malloc(int.sizeof * _modules.length))[0 .. _modules.length]; + int[] distance = (cast(int*) Mem.allocate(int.sizeof * _modules.length))[0 .. _modules.length]; scope(exit) - .free(distance.ptr); + Mem.free(distance.ptr); // determine the shortest path between two modules. Uses dijkstra // without a priority queue. (we can be a bit slow here, in order to @@ -221,14 +221,14 @@ struct ModuleGroup // allocate some stack arrays that will be used throughout the process. immutable nwords = (len + 8 * size_t.sizeof - 1) / (8 * size_t.sizeof); immutable flagbytes = nwords * size_t.sizeof; - auto ctorstart = cast(size_t*) malloc(flagbytes); // ctor/dtor seen - auto ctordone = cast(size_t*) malloc(flagbytes); // ctor/dtor processed - auto relevant = cast(size_t*) malloc(flagbytes); // has ctors/dtors + auto ctorstart = cast(size_t*) Mem.allocate(flagbytes); // ctor/dtor seen + auto ctordone = cast(size_t*) Mem.allocate(flagbytes); // ctor/dtor processed + auto relevant = cast(size_t*) Mem.allocate(flagbytes); // has ctors/dtors scope (exit) { - .free(ctorstart); - .free(ctordone); - .free(relevant); + Mem.free(ctorstart); + Mem.free(ctordone); + Mem.free(relevant); } void clearFlags(size_t* flags) @@ -239,15 +239,15 @@ struct ModuleGroup // build the edges between each module. We may need this for printing, // and also allows avoiding keeping a hash around for module lookups. - int[][] edges = (cast(int[]*)malloc((int[]).sizeof * _modules.length))[0 .. _modules.length]; + int[][] edges = (cast(int[]*) Mem.allocate((int[]).sizeof * _modules.length))[0 .. _modules.length]; { HashTab!(immutable(ModuleInfo)*, int) modIndexes; foreach (i, m; _modules) modIndexes[m] = cast(int) i; - auto reachable = cast(size_t*) malloc(flagbytes); + auto reachable = cast(size_t*) Mem.allocate(flagbytes); scope(exit) - .free(reachable); + Mem.free(reachable); foreach (i, m; _modules) { @@ -255,7 +255,7 @@ struct ModuleGroup // https://issues.dlang.org/show_bug.cgi?id=16208 clearFlags(reachable); // preallocate enough space to store all the indexes - int *edge = cast(int*)malloc(int.sizeof * _modules.length); + int *edge = cast(int*) Mem.allocate(int.sizeof * _modules.length); size_t nEdges = 0; foreach (imp; m.importedModules) { @@ -270,12 +270,12 @@ struct ModuleGroup if (nEdges > 0) { // trim space to what is needed - edges[i] = (cast(int*)realloc(edge, int.sizeof * nEdges))[0 .. nEdges]; + edges[i] = (cast(int*) Mem.reallocate(edge, int.sizeof * nEdges))[0 .. nEdges]; } else { edges[i] = null; - .free(edge); + Mem.free(edge); } } } @@ -285,8 +285,8 @@ struct ModuleGroup { foreach (e; edges) if (e.ptr) - .free(e.ptr); - .free(edges.ptr); + Mem.free(e.ptr); + Mem.free(edges.ptr); } void buildCycleMessage(size_t sourceIdx, size_t cycleIdx, scope void delegate(string) nothrow sink) @@ -302,7 +302,7 @@ struct ModuleGroup sink(_modules[cycleIdx].name); sink(EOL); auto cyclePath = genCyclePath(sourceIdx, cycleIdx, edges); - scope(exit) .free(cyclePath.ptr); + scope(exit) Mem.free(cyclePath.ptr); sink(_modules[sourceIdx].name); sink("* ->" ~ EOL); @@ -330,9 +330,9 @@ struct ModuleGroup } // initialize "stack" - auto stack = cast(stackFrame*) malloc(stackFrame.sizeof * len); + auto stack = cast(stackFrame*) Mem.allocate(stackFrame.sizeof * len); scope (exit) - .free(stack); + Mem.free(stack); auto stacktop = stack + len; auto sp = stack; sp.curMod = cast(int) idx; @@ -423,9 +423,9 @@ struct ModuleGroup immutable ModuleInfo* current = _modules[curidx]; // First, determine what modules are reachable. - auto reachable = cast(size_t*) malloc(flagbytes); + auto reachable = cast(size_t*) Mem.allocate(flagbytes); scope (exit) - .free(reachable); + Mem.free(reachable); if (!findDeps(curidx, reachable)) return false; // deprecated cycle error @@ -468,7 +468,7 @@ struct ModuleGroup clearFlags(ctordone); // pre-allocate enough space to hold all modules. - ctors = (cast(immutable(ModuleInfo)**).malloc(len * (void*).sizeof)); + ctors = cast(immutable(ModuleInfo)**) Mem.allocate(len * (void*).sizeof); ctoridx = 0; foreach (idx, m; _modules) { @@ -493,7 +493,7 @@ struct ModuleGroup { if (!processMod(idx)) { - .free(ctors); + Mem.free(ctors); return false; } } @@ -502,11 +502,11 @@ struct ModuleGroup if (ctoridx == 0) { // no ctors in the list. - .free(ctors); + Mem.free(ctors); } else { - ctors = cast(immutable(ModuleInfo)**).realloc(ctors, ctoridx * (void*).sizeof); + ctors = cast(immutable(ModuleInfo)**) Mem.reallocate(ctors, ctoridx * (void*).sizeof); if (ctors is null) assert(0); result = ctors[0 .. ctoridx]; @@ -561,10 +561,10 @@ struct ModuleGroup void free() { if (_ctors.ptr) - .free(_ctors.ptr); + Mem.free(_ctors.ptr); _ctors = null; if (_tlsctors.ptr) - .free(_tlsctors.ptr); + Mem.free(_tlsctors.ptr); _tlsctors = null; // _modules = null; // let the owner free it } From afb47cc2ca223a7a2cac521697e3fc07986734c2 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 31 Jul 2026 15:23:46 +0300 Subject: [PATCH 07/29] core.internal.gc.impl.manual.gc uses core.system.Mem --- druntime/src/core/internal/gc/impl/manual/gc.d | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/druntime/src/core/internal/gc/impl/manual/gc.d b/druntime/src/core/internal/gc/impl/manual/gc.d index 5f9c04187ed9..48e0fbdca764 100644 --- a/druntime/src/core/internal/gc/impl/manual/gc.d +++ b/druntime/src/core/internal/gc/impl/manual/gc.d @@ -25,7 +25,7 @@ import core.internal.container.array; import core.thread.threadbase : ThreadBase; -import cstdlib = core.stdc.stdlib : calloc, free, malloc, realloc; +import core.system: Mem; static import core.memory; extern (C) noreturn onOutOfMemoryError(void* pretend_sideffect = null, string file = __FILE__, size_t line = __LINE__) @trusted pure nothrow @nogc; /* dmd @@@BUG11461@@@ */ @@ -46,7 +46,7 @@ private GC initialize() { import core.lifetime : emplace; - auto gc = cast(ManualGC) cstdlib.malloc(__traits(classInstanceSize, ManualGC)); + auto gc = cast(ManualGC) Mem.allocate(__traits(classInstanceSize, ManualGC)); if (!gc) onOutOfMemoryError(); @@ -102,7 +102,7 @@ class ManualGC : GC void* malloc(size_t size, uint bits, const TypeInfo ti) nothrow { - void* p = cstdlib.malloc(size); + void* p = Mem.allocate(size); if (size && p is null) onOutOfMemoryError(); @@ -120,7 +120,7 @@ class ManualGC : GC void* calloc(size_t size, uint bits, const TypeInfo ti) nothrow { - void* p = cstdlib.calloc(1, size); + void* p = Mem.allocateBlank(size); if (size && p is null) onOutOfMemoryError(); @@ -129,7 +129,7 @@ class ManualGC : GC void* realloc(void* p, size_t size, uint bits, const TypeInfo ti) nothrow { - p = cstdlib.realloc(p, size); + p = Mem.reallocate(p, size); if (size && p is null) onOutOfMemoryError(); @@ -148,7 +148,7 @@ class ManualGC : GC void free(void* p) nothrow @nogc { - cstdlib.free(p); + Mem.free(p); } /** From 80eff15656c5d1efbc155b252820b3197fd0c5f6 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 31 Jul 2026 15:29:30 +0300 Subject: [PATCH 08/29] module core.runtime uses core.system.Mem --- druntime/src/core/runtime.d | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/druntime/src/core/runtime.d b/druntime/src/core/runtime.d index 524cc3ca9ad7..0269b6501b97 100644 --- a/druntime/src/core/runtime.d +++ b/druntime/src/core/runtime.d @@ -10,6 +10,8 @@ module core.runtime; +import core.system : Mem; + version (OSX) version = Darwin; else version (iOS) @@ -743,8 +745,7 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null ) // @nogc static T allocate(T, Args...)(auto ref Args args) @nogc { import core.lifetime : emplace; - import core.stdc.stdlib : malloc; - auto result = cast(T)malloc(__traits(classInstanceSize, T)); + auto result = cast(T) Mem.allocate(__traits(classInstanceSize, T)); return emplace(result, args); } version (Windows) @@ -803,8 +804,7 @@ void defaultTraceDeallocator(Throwable.TraceInfo info) nothrow return; auto obj = cast(Object)info; destroy(obj); - import core.stdc.stdlib : free; - free(cast(void *)obj); + Mem.free(cast(void *)obj); } /// Default implementation for most POSIX systems @@ -812,7 +812,6 @@ version (WASI) {} else version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo { import core.demangle; - import core.stdc.stdlib : free; import core.stdc.string : strlen, memchr, memmove; this() @nogc @@ -879,7 +878,7 @@ else version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo static if (hasExecinfo) { const framelist = backtrace_symbols( callstack.ptr, numframes ); - scope(exit) free(cast(void*) framelist); + scope(exit) Mem.free(cast(void*) framelist); static if (enableDwarf) { From 95a13a7a42d8dcf972c47e863b460c9a82a9a593 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 31 Jul 2026 15:31:52 +0300 Subject: [PATCH 09/29] core.gc.registry uses core.system.Mem --- druntime/src/core/gc/registry.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/druntime/src/core/gc/registry.d b/druntime/src/core/gc/registry.d index 83e732c5f58f..ff4c20fbf4ba 100644 --- a/druntime/src/core/gc/registry.d +++ b/druntime/src/core/gc/registry.d @@ -77,7 +77,7 @@ void registerGCFactory(string name, GCFactory factory, */ GC createGCInstance(string name) { - import core.stdc.stdlib : free; + import core.system : Mem; foreach (entry; entries) { @@ -85,7 +85,7 @@ GC createGCInstance(string name) continue; auto instance = entry.factory(); // only one GC at a time for now, so free the registry to not leak - free(entries.ptr); + Mem.free(entries.ptr); entries = null; return instance; } From f121ab970d6c61fddd1ec1fbb55d5221c716745b Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 31 Jul 2026 22:22:19 +0300 Subject: [PATCH 10/29] rt.dmain2: core.stdc.stdlib.alloca() replaced by Mem.allocateOnStack --- druntime/src/core/system.d | 2 ++ druntime/src/rt/dmain2.d | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d index 67d9fab93b84..4583a2e42f73 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system.d @@ -22,4 +22,6 @@ struct Mem return cast(void*) p; } +/ + + alias allocateOnStack = alloca; } diff --git a/druntime/src/rt/dmain2.d b/druntime/src/rt/dmain2.d index 2a4d9beb80af..464539cd5803 100644 --- a/druntime/src/rt/dmain2.d +++ b/druntime/src/rt/dmain2.d @@ -15,11 +15,12 @@ import core.atomic; import core.internal.parseoptions : rt_parseOption; import core.stdc.errno : errno; import core.stdc.stdio : fflush, fprintf, fwrite, stderr, stdout; -import core.stdc.stdlib : alloca, EXIT_FAILURE, EXIT_SUCCESS, free, malloc, realloc; +import core.stdc.stdlib : EXIT_FAILURE, EXIT_SUCCESS, free, malloc, realloc; import core.stdc.string : strerror; import rt.config : rt_cmdline_enabled, rt_configOption; import rt.memory; import rt.sections; +import core.system : Mem; version (Windows) { @@ -49,7 +50,7 @@ else version (WASI) } version (DigitalMars) version (AArch64) - version = UseMalloc; // cuz alloca() is not implemented yet + version = UseMalloc; // cuz Mem.allocateOnStack is not implemented yet // not sure why we can't define this in one place, but this is to keep this // module from importing core.runtime. @@ -294,7 +295,7 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) scope (exit) free(args.ptr); } else - char[][] args = (cast(char[]*) alloca(wargc * (char[]).sizeof))[0 .. wargc]; + char[][] args = (cast(char[]*) Mem.allocateOnStack(wargc * (char[]).sizeof))[0 .. wargc]; // This is required because WideCharToMultiByte requires int as input. assert(wCommandLineLength <= cast(size_t) int.max, "Wide char command line length must not exceed int.max"); @@ -309,7 +310,7 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) scope (exit) free(totalArgsBuff); } else - char* totalArgsBuff = cast(char*) alloca(totalArgsLength); + char* totalArgsBuff = cast(char*) Mem.allocateOnStack(totalArgsLength); size_t j = 0; foreach (i; 0 .. wargc) { @@ -339,7 +340,7 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) scope (exit) free(args.ptr); } else - char[][] args = (cast(char[]*) alloca(argc * (char[]).sizeof))[0 .. argc]; + char[][] args = (cast(char[]*) Mem.allocateOnStack(argc * (char[]).sizeof))[0 .. argc]; size_t totalArgsLength = 0; foreach (i, ref arg; args) @@ -351,7 +352,7 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) else version (WASI) { // Allocate args[] on the stack - char[][] args = (cast(char[]*) alloca(argc * (char[]).sizeof))[0 .. argc]; + char[][] args = (cast(char[]*) Mem.allocateOnStack(argc * (char[]).sizeof))[0 .. argc]; size_t totalArgsLength = 0; foreach (i, ref arg; args) @@ -376,7 +377,7 @@ version (Windows) extern (C) int _d_wrun_main(int argc, wchar** wargv, MainFunc mainFunc) { // Allocate args[] on the stack - char[][] args = (cast(char[]*) alloca(argc * (char[]).sizeof))[0 .. argc]; + char[][] args = (cast(char[]*) Mem.allocateOnStack(argc * (char[]).sizeof))[0 .. argc]; // 1st pass: compute each argument's length as UTF-16 and UTF-8 size_t totalArgsLength = 0; @@ -391,7 +392,7 @@ extern (C) int _d_wrun_main(int argc, wchar** wargv, MainFunc mainFunc) } // Allocate a single buffer for all (null-terminated) argument strings in UTF-8 on the stack - char* utf8Buffer = cast(char*) alloca(totalArgsLength); + char* utf8Buffer = cast(char*) Mem.allocateOnStack(totalArgsLength); // 2nd pass: convert to UTF-8 and finalize `args` char* utf8 = utf8Buffer; @@ -405,7 +406,7 @@ extern (C) int _d_wrun_main(int argc, wchar** wargv, MainFunc mainFunc) } // Set C argc/argv; argv is a new stack-allocated array of UTF-8 C strings - char*[] argv = (cast(char**) alloca(argc * (char*).sizeof))[0 .. argc]; + char*[] argv = (cast(char**) Mem.allocateOnStack(argc * (char*).sizeof))[0 .. argc]; foreach (i, ref arg; argv) arg = args[i].ptr; _cArgs.argc = argc; @@ -487,7 +488,7 @@ private extern (C) int _d_run_main2(char[][] args, size_t totalArgsLength, MainF //scope (exit) buff; } else - auto buff = cast(char[]*) alloca(length); + auto buff = cast(char[]*) Mem.allocateOnStack(length); char[][] argsCopy = buff[0 .. args.length]; auto argBuff = cast(char*) (buff + args.length); From 6f8d22b1a6070bb0341a446cbb44d296e1960476 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 31 Jul 2026 22:26:01 +0300 Subject: [PATCH 11/29] rt.dmain2: free, malloc, realloc replaced by Mem.* calls --- druntime/src/rt/dmain2.d | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/druntime/src/rt/dmain2.d b/druntime/src/rt/dmain2.d index 464539cd5803..303944a34b70 100644 --- a/druntime/src/rt/dmain2.d +++ b/druntime/src/rt/dmain2.d @@ -15,7 +15,7 @@ import core.atomic; import core.internal.parseoptions : rt_parseOption; import core.stdc.errno : errno; import core.stdc.stdio : fflush, fprintf, fwrite, stderr, stdout; -import core.stdc.stdlib : EXIT_FAILURE, EXIT_SUCCESS, free, malloc, realloc; +import core.stdc.stdlib : EXIT_FAILURE, EXIT_SUCCESS; import core.stdc.string : strerror; import rt.config : rt_cmdline_enabled, rt_configOption; import rt.memory; @@ -289,7 +289,7 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) // Allocate args[] on the stack - use wargc version (UseMalloc) { - char[][] args = (cast(char[]*) malloc(wargc * (char[]).sizeof))[0 .. wargc]; + char[][] args = (cast(char[]*) Mem.allocate(wargc * (char[]).sizeof))[0 .. wargc]; if (wargc) assert(args.ptr); scope (exit) free(args.ptr); @@ -304,7 +304,7 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) { version (UseMalloc) { - char* totalArgsBuff = cast(char*) malloc(totalArgsLength); + char* totalArgsBuff = cast(char*) Mem.allocate(totalArgsLength); if (totalArgsLength) assert(totalArgsBuff); scope (exit) free(totalArgsBuff); @@ -334,7 +334,7 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) // Allocate args[] on the stack version (UseMalloc) { - char[][] args = (cast(char[]*) malloc(argc * (char[]).sizeof))[0 .. argc]; + char[][] args = (cast(char[]*) Mem.allocate(argc * (char[]).sizeof))[0 .. argc]; if (argc) assert(args.ptr); scope (exit) free(args.ptr); @@ -482,7 +482,7 @@ private extern (C) int _d_run_main2(char[][] args, size_t totalArgsLength, MainF auto length = args.length * (char[]).sizeof + totalArgsLength; version (UseMalloc) { - auto buff = cast(char[]*) malloc(length); + auto buff = cast(char[]*) Mem.allocate(length); if (length) assert(buff); //scope (exit) buff; @@ -661,7 +661,7 @@ extern (C) void _d_print_throwable(Throwable t) CP_UTF8, 0, s.ptr, cast(int)s.length, null, 0); if (!swlen) return; - auto newPtr = cast(WCHAR*)realloc(ptr, + auto newPtr = cast(WCHAR*) Mem.reallocate(ptr, (this.len + swlen + 1) * WCHAR.sizeof); if (!newPtr) return; ptr = newPtr; @@ -672,7 +672,7 @@ extern (C) void _d_print_throwable(Throwable t) typeof(ptr) get() { if (ptr) ptr[len] = 0; return ptr; } - void free() { .free(ptr); } + void free() { Mem.free(ptr); } } HANDLE windowsHandle(int fd) @@ -721,12 +721,12 @@ extern (C) void _d_print_throwable(Throwable t) uint codepage = GetConsoleOutputCP(); const slen = WideCharToMultiByte(codepage, 0, buf.ptr, cast(int)buf.len, null, 0, null, null); - if (auto sptr = cast(char*)malloc(slen * char.sizeof)) + if (auto sptr = cast(char*) Mem.allocate(slen * char.sizeof)) { WideCharToMultiByte(codepage, 0, buf.ptr, cast(int)buf.len, sptr, slen, null, null); WriteFile(hStdErr, sptr, slen, null, null); - free(sptr); + Mem.free(sptr); } buf.free(); } From 8ae2a8f879f93b7c9a0ca31e0d3c36ea6c349f11 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 1 Aug 2026 12:08:31 +0300 Subject: [PATCH 12/29] allocateBlank() commented-out code removed --- druntime/src/core/system.d | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d index 4583a2e42f73..8fff44810b1c 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system.d @@ -11,17 +11,7 @@ struct Mem alias allocate = malloc; alias reallocate = realloc; alias free = core.stdc.stdlib.free; - static void* allocateBlank(size_t size) nothrow @nogc => calloc(1, size); - /+ - static void* allocateBlank(size_t size) nothrow @nogc - { - ubyte* p = cast(ubyte*) allocate(size); - p[0 .. size] = 0; - return cast(void*) p; - } - +/ - alias allocateOnStack = alloca; } From 01dc1040dae4b9bf01777b04614d6d0d154f6b79 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 1 Aug 2026 12:14:53 +0300 Subject: [PATCH 13/29] Mem.allocate -> Mem.allocateOne --- .../src/core/internal/gc/impl/manual/gc.d | 4 ++-- druntime/src/core/runtime.d | 6 ++--- druntime/src/core/system.d | 2 +- druntime/src/rt/dmain2.d | 10 ++++----- druntime/src/rt/minfo.d | 22 +++++++++---------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/druntime/src/core/internal/gc/impl/manual/gc.d b/druntime/src/core/internal/gc/impl/manual/gc.d index 48e0fbdca764..2d31b5121d56 100644 --- a/druntime/src/core/internal/gc/impl/manual/gc.d +++ b/druntime/src/core/internal/gc/impl/manual/gc.d @@ -46,7 +46,7 @@ private GC initialize() { import core.lifetime : emplace; - auto gc = cast(ManualGC) Mem.allocate(__traits(classInstanceSize, ManualGC)); + auto gc = cast(ManualGC) Mem.allocateOne(__traits(classInstanceSize, ManualGC)); if (!gc) onOutOfMemoryError(); @@ -102,7 +102,7 @@ class ManualGC : GC void* malloc(size_t size, uint bits, const TypeInfo ti) nothrow { - void* p = Mem.allocate(size); + void* p = Mem.allocateOne(size); if (size && p is null) onOutOfMemoryError(); diff --git a/druntime/src/core/runtime.d b/druntime/src/core/runtime.d index 0269b6501b97..234af8444958 100644 --- a/druntime/src/core/runtime.d +++ b/druntime/src/core/runtime.d @@ -224,7 +224,7 @@ struct Runtime if (len == 0) return null; - auto buf = cast(WCHAR*) Mem.allocate((len+1) * WCHAR.sizeof); + auto buf = cast(WCHAR*) Mem.allocateOne((len+1) * WCHAR.sizeof); if (buf is null) return null; scope (exit) Mem.free(buf); @@ -242,7 +242,7 @@ struct Runtime /* Need a 0-terminated C string for the dll name */ immutable len = name.length; - auto buf = cast(char*) Mem.allocate(len + 1); + auto buf = cast(char*) Mem.allocateOne(len + 1); if (!buf) return null; scope (exit) Mem.free(buf); @@ -745,7 +745,7 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null ) // @nogc static T allocate(T, Args...)(auto ref Args args) @nogc { import core.lifetime : emplace; - auto result = cast(T) Mem.allocate(__traits(classInstanceSize, T)); + auto result = cast(T) Mem.allocateOne(__traits(classInstanceSize, T)); return emplace(result, args); } version (Windows) diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d index 8fff44810b1c..c595a140b257 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system.d @@ -8,7 +8,7 @@ struct Mem { import core.stdc.stdlib; - alias allocate = malloc; + alias allocateOne = malloc; alias reallocate = realloc; alias free = core.stdc.stdlib.free; static void* allocateBlank(size_t size) nothrow @nogc => calloc(1, size); diff --git a/druntime/src/rt/dmain2.d b/druntime/src/rt/dmain2.d index 303944a34b70..2efe24fc3e90 100644 --- a/druntime/src/rt/dmain2.d +++ b/druntime/src/rt/dmain2.d @@ -289,7 +289,7 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) // Allocate args[] on the stack - use wargc version (UseMalloc) { - char[][] args = (cast(char[]*) Mem.allocate(wargc * (char[]).sizeof))[0 .. wargc]; + char[][] args = (cast(char[]*) Mem.allocateOne(wargc * (char[]).sizeof))[0 .. wargc]; if (wargc) assert(args.ptr); scope (exit) free(args.ptr); @@ -304,7 +304,7 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) { version (UseMalloc) { - char* totalArgsBuff = cast(char*) Mem.allocate(totalArgsLength); + char* totalArgsBuff = cast(char*) Mem.allocateOne(totalArgsLength); if (totalArgsLength) assert(totalArgsBuff); scope (exit) free(totalArgsBuff); @@ -334,7 +334,7 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) // Allocate args[] on the stack version (UseMalloc) { - char[][] args = (cast(char[]*) Mem.allocate(argc * (char[]).sizeof))[0 .. argc]; + char[][] args = (cast(char[]*) Mem.allocateOne(argc * (char[]).sizeof))[0 .. argc]; if (argc) assert(args.ptr); scope (exit) free(args.ptr); @@ -482,7 +482,7 @@ private extern (C) int _d_run_main2(char[][] args, size_t totalArgsLength, MainF auto length = args.length * (char[]).sizeof + totalArgsLength; version (UseMalloc) { - auto buff = cast(char[]*) Mem.allocate(length); + auto buff = cast(char[]*) Mem.allocateOne(length); if (length) assert(buff); //scope (exit) buff; @@ -721,7 +721,7 @@ extern (C) void _d_print_throwable(Throwable t) uint codepage = GetConsoleOutputCP(); const slen = WideCharToMultiByte(codepage, 0, buf.ptr, cast(int)buf.len, null, 0, null, null); - if (auto sptr = cast(char*) Mem.allocate(slen * char.sizeof)) + if (auto sptr = cast(char*) Mem.allocateOne(slen * char.sizeof)) { WideCharToMultiByte(codepage, 0, buf.ptr, cast(int)buf.len, sptr, slen, null, null); diff --git a/druntime/src/rt/minfo.d b/druntime/src/rt/minfo.d index cc72831f5fd6..0002e62bbd13 100644 --- a/druntime/src/rt/minfo.d +++ b/druntime/src/rt/minfo.d @@ -66,9 +66,9 @@ struct ModuleGroup import core.bitop : bt, btc, bts; // set up all the arrays. - size_t[] cyclePath = (cast(size_t*) Mem.allocate(size_t.sizeof * _modules.length * 2))[0 .. _modules.length * 2]; + size_t[] cyclePath = (cast(size_t*) Mem.allocateOne(size_t.sizeof * _modules.length * 2))[0 .. _modules.length * 2]; size_t totalMods; - int[] distance = (cast(int*) Mem.allocate(int.sizeof * _modules.length))[0 .. _modules.length]; + int[] distance = (cast(int*) Mem.allocateOne(int.sizeof * _modules.length))[0 .. _modules.length]; scope(exit) Mem.free(distance.ptr); @@ -221,9 +221,9 @@ struct ModuleGroup // allocate some stack arrays that will be used throughout the process. immutable nwords = (len + 8 * size_t.sizeof - 1) / (8 * size_t.sizeof); immutable flagbytes = nwords * size_t.sizeof; - auto ctorstart = cast(size_t*) Mem.allocate(flagbytes); // ctor/dtor seen - auto ctordone = cast(size_t*) Mem.allocate(flagbytes); // ctor/dtor processed - auto relevant = cast(size_t*) Mem.allocate(flagbytes); // has ctors/dtors + auto ctorstart = cast(size_t*) Mem.allocateOne(flagbytes); // ctor/dtor seen + auto ctordone = cast(size_t*) Mem.allocateOne(flagbytes); // ctor/dtor processed + auto relevant = cast(size_t*) Mem.allocateOne(flagbytes); // has ctors/dtors scope (exit) { Mem.free(ctorstart); @@ -239,13 +239,13 @@ struct ModuleGroup // build the edges between each module. We may need this for printing, // and also allows avoiding keeping a hash around for module lookups. - int[][] edges = (cast(int[]*) Mem.allocate((int[]).sizeof * _modules.length))[0 .. _modules.length]; + int[][] edges = (cast(int[]*) Mem.allocateOne((int[]).sizeof * _modules.length))[0 .. _modules.length]; { HashTab!(immutable(ModuleInfo)*, int) modIndexes; foreach (i, m; _modules) modIndexes[m] = cast(int) i; - auto reachable = cast(size_t*) Mem.allocate(flagbytes); + auto reachable = cast(size_t*) Mem.allocateOne(flagbytes); scope(exit) Mem.free(reachable); @@ -255,7 +255,7 @@ struct ModuleGroup // https://issues.dlang.org/show_bug.cgi?id=16208 clearFlags(reachable); // preallocate enough space to store all the indexes - int *edge = cast(int*) Mem.allocate(int.sizeof * _modules.length); + int *edge = cast(int*) Mem.allocateOne(int.sizeof * _modules.length); size_t nEdges = 0; foreach (imp; m.importedModules) { @@ -330,7 +330,7 @@ struct ModuleGroup } // initialize "stack" - auto stack = cast(stackFrame*) Mem.allocate(stackFrame.sizeof * len); + auto stack = cast(stackFrame*) Mem.allocateOne(stackFrame.sizeof * len); scope (exit) Mem.free(stack); auto stacktop = stack + len; @@ -423,7 +423,7 @@ struct ModuleGroup immutable ModuleInfo* current = _modules[curidx]; // First, determine what modules are reachable. - auto reachable = cast(size_t*) Mem.allocate(flagbytes); + auto reachable = cast(size_t*) Mem.allocateOne(flagbytes); scope (exit) Mem.free(reachable); if (!findDeps(curidx, reachable)) @@ -468,7 +468,7 @@ struct ModuleGroup clearFlags(ctordone); // pre-allocate enough space to hold all modules. - ctors = cast(immutable(ModuleInfo)**) Mem.allocate(len * (void*).sizeof); + ctors = cast(immutable(ModuleInfo)**) Mem.allocateOne(len * (void*).sizeof); ctoridx = 0; foreach (idx, m; _modules) { From 417361aa85e6880a4428c0da8d3803d205ab55f9 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 1 Aug 2026 12:17:16 +0300 Subject: [PATCH 14/29] allocateBlank() -> allocateOneBlank() --- druntime/src/core/internal/gc/bits.d | 2 +- druntime/src/core/internal/gc/impl/manual/gc.d | 2 +- druntime/src/core/system.d | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/druntime/src/core/internal/gc/bits.d b/druntime/src/core/internal/gc/bits.d index d9607967cad5..1b0b1f8e043b 100644 --- a/druntime/src/core/internal/gc/bits.d +++ b/druntime/src/core/internal/gc/bits.d @@ -51,7 +51,7 @@ struct GCBits { this.nbits = nbits; if (!AllocSupportsShared || !share) - data = cast(typeof(data[0])*) Mem.allocateBlank(nwords * data[0].sizeof); + data = cast(typeof(data[0])*) Mem.allocateOneBlank(nwords * data[0].sizeof); else static if (AllocSupportsShared) data = cast(typeof(data[0])*)os_mem_map_shared(nwords * data[0].sizeof); // Allocate as MAP_SHARED else diff --git a/druntime/src/core/internal/gc/impl/manual/gc.d b/druntime/src/core/internal/gc/impl/manual/gc.d index 2d31b5121d56..ee7eeae97f78 100644 --- a/druntime/src/core/internal/gc/impl/manual/gc.d +++ b/druntime/src/core/internal/gc/impl/manual/gc.d @@ -120,7 +120,7 @@ class ManualGC : GC void* calloc(size_t size, uint bits, const TypeInfo ti) nothrow { - void* p = Mem.allocateBlank(size); + void* p = Mem.allocateOneBlank(size); if (size && p is null) onOutOfMemoryError(); diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d index c595a140b257..05ddc3f040ef 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system.d @@ -11,7 +11,7 @@ struct Mem alias allocateOne = malloc; alias reallocate = realloc; alias free = core.stdc.stdlib.free; - static void* allocateBlank(size_t size) nothrow @nogc => calloc(1, size); + static void* allocateOneBlank(size_t size) nothrow @nogc => calloc(1, size); alias allocateOnStack = alloca; } From 85de307380045005e59b49e2875a7dfb747486c9 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 1 Aug 2026 12:29:34 +0300 Subject: [PATCH 15/29] allocateFew() and allocateFewBlank() added --- druntime/src/core/system.d | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d index 05ddc3f040ef..ef933dee4f7d 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system.d @@ -9,9 +9,11 @@ struct Mem import core.stdc.stdlib; alias allocateOne = malloc; + alias allocateFew = (size_t num, size_t size) => allocateOne(num * size); + static void* allocateOneBlank(size_t size) nothrow @nogc => allocateFewBlank(1, size); + alias allocateFewBlank = calloc; alias reallocate = realloc; alias free = core.stdc.stdlib.free; - static void* allocateOneBlank(size_t size) nothrow @nogc => calloc(1, size); alias allocateOnStack = alloca; } From 76191c4d9e115ee14558f1ccb03d96ca802024d9 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 1 Aug 2026 13:21:59 +0300 Subject: [PATCH 16/29] GC Config: initialization method does not need access to the outer scope --- druntime/src/core/gc/config.d | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/druntime/src/core/gc/config.d b/druntime/src/core/gc/config.d index c3b79e0926b5..d386165beb2a 100644 --- a/druntime/src/core/gc/config.d +++ b/druntime/src/core/gc/config.d @@ -14,6 +14,14 @@ __gshared Config config; private __gshared bool _initialized; +package(core) bool initialize(ref Config cfg) nothrow @nogc +{ + if (!_initialized) + _initialized = cfg.tryToInitialize(); + + return _initialized; +} + struct Config { bool disable; // start disabled @@ -37,11 +45,9 @@ struct Config @nogc nothrow: - bool initialize() + private bool tryToInitialize() { - if (!_initialized) - _initialized = initConfigOptions(this, "gcopt"); - return _initialized; + return initConfigOptions(this, "gcopt"); } void help() @nogc nothrow From f20ede31a32b2f4de13d80e1ba4d2ab5cba2d937 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 1 Aug 2026 13:37:40 +0300 Subject: [PATCH 17/29] GC Config defined in core.system.Opt --- druntime/src/core/gc/config.d | 5 ++++- druntime/src/core/system.d | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/druntime/src/core/gc/config.d b/druntime/src/core/gc/config.d index d386165beb2a..479e78d4d716 100644 --- a/druntime/src/core/gc/config.d +++ b/druntime/src/core/gc/config.d @@ -9,6 +9,9 @@ module core.gc.config; import core.internal.parseoptions; import core.stdc.stdio : printf; +import core.system : Opt; + +alias Config = Opt.Config; __gshared Config config; @@ -22,7 +25,7 @@ package(core) bool initialize(ref Config cfg) nothrow @nogc return _initialized; } -struct Config +struct ConfigT() { bool disable; // start disabled bool fork = false; // optional concurrent behaviour diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d index ef933dee4f7d..c8c03de4e593 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system.d @@ -17,3 +17,10 @@ struct Mem alias allocateOnStack = alloca; } + +struct Opt +{ + import core.gc.config: ConfigT; + + alias Config = ConfigT!(); +} From 7075d9f4676bbd7d4eab850cc359611b9f7df43e Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 1 Aug 2026 13:53:14 +0300 Subject: [PATCH 18/29] Opt.Config -> Opt.GcConfig --- druntime/src/core/gc/config.d | 2 +- druntime/src/core/system.d | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/druntime/src/core/gc/config.d b/druntime/src/core/gc/config.d index 479e78d4d716..3e640cdd2d8b 100644 --- a/druntime/src/core/gc/config.d +++ b/druntime/src/core/gc/config.d @@ -11,7 +11,7 @@ import core.internal.parseoptions; import core.stdc.stdio : printf; import core.system : Opt; -alias Config = Opt.Config; +alias Config = Opt.GcConfig; __gshared Config config; diff --git a/druntime/src/core/system.d b/druntime/src/core/system.d index c8c03de4e593..8c8c0ed75117 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system.d @@ -22,5 +22,5 @@ struct Opt { import core.gc.config: ConfigT; - alias Config = ConfigT!(); + alias GcConfig = ConfigT!(); } From 21fb5a17c4aab1ee043f45b3ab28c3b8b4b1d4f8 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sat, 1 Aug 2026 14:14:40 +0300 Subject: [PATCH 19/29] Attempt to fix build fo Windows by adding module core.system.opt --- druntime/mak/COPY | 3 ++- druntime/mak/SRCS | 3 ++- druntime/src/core/gc/config.d | 2 +- druntime/src/core/system/opt.d | 11 +++++++++++ druntime/src/core/{system.d => system/package.d} | 7 ------- 5 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 druntime/src/core/system/opt.d rename druntime/src/core/{system.d => system/package.d} (83%) diff --git a/druntime/mak/COPY b/druntime/mak/COPY index 3ed916ff8cd3..f2e790da5632 100644 --- a/druntime/mak/COPY +++ b/druntime/mak/COPY @@ -23,7 +23,8 @@ COPY=\ $(IMPDIR)\core\memory.d \ $(IMPDIR)\core\runtime.d \ $(IMPDIR)\core\simd.d \ - $(IMPDIR)\core\system.d \ + $(IMPDIR)\core\system\opt.d \ + $(IMPDIR)\core\system\package.d \ $(IMPDIR)\core\time.d \ $(IMPDIR)\core\vararg.d \ $(IMPDIR)\core\volatile.d \ diff --git a/druntime/mak/SRCS b/druntime/mak/SRCS index b345ad10a842..5fb674c196bd 100644 --- a/druntime/mak/SRCS +++ b/druntime/mak/SRCS @@ -17,7 +17,8 @@ SRCS=\ src\core\memory.d \ src\core\runtime.d \ src\core\simd.d \ - src\core\system.d \ + src\core\system\opt.d \ + src\core\system\package.d \ src\core\time.d \ src\core\vararg.d \ src\core\volatile.d \ diff --git a/druntime/src/core/gc/config.d b/druntime/src/core/gc/config.d index 3e640cdd2d8b..daeebec0f5d0 100644 --- a/druntime/src/core/gc/config.d +++ b/druntime/src/core/gc/config.d @@ -9,7 +9,7 @@ module core.gc.config; import core.internal.parseoptions; import core.stdc.stdio : printf; -import core.system : Opt; +import core.system.opt : Opt; alias Config = Opt.GcConfig; diff --git a/druntime/src/core/system/opt.d b/druntime/src/core/system/opt.d new file mode 100644 index 000000000000..38dd2e2a6a5c --- /dev/null +++ b/druntime/src/core/system/opt.d @@ -0,0 +1,11 @@ +/// +module core.system.opt; + +package(core): + +struct Opt +{ + import core.gc.config: ConfigT; + + alias GcConfig = ConfigT!(); +} diff --git a/druntime/src/core/system.d b/druntime/src/core/system/package.d similarity index 83% rename from druntime/src/core/system.d rename to druntime/src/core/system/package.d index 8c8c0ed75117..ef933dee4f7d 100644 --- a/druntime/src/core/system.d +++ b/druntime/src/core/system/package.d @@ -17,10 +17,3 @@ struct Mem alias allocateOnStack = alloca; } - -struct Opt -{ - import core.gc.config: ConfigT; - - alias GcConfig = ConfigT!(); -} From 4b9b386b69909ac9b33365aa6b6687082067145a Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sun, 2 Aug 2026 12:31:35 +0300 Subject: [PATCH 20/29] druntime: -debug=PRINTF compilation fix --- druntime/src/core/internal/array/utils.d | 1 + 1 file changed, 1 insertion(+) diff --git a/druntime/src/core/internal/array/utils.d b/druntime/src/core/internal/array/utils.d index 103a87bcd278..1020f3984373 100644 --- a/druntime/src/core/internal/array/utils.d +++ b/druntime/src/core/internal/array/utils.d @@ -11,6 +11,7 @@ module core.internal.array.utils; import core.internal.traits : Parameters; import core.memory : GC; +debug(PRINTF) import core.stdc.stdio : printf; alias BlkAttr = GC.BlkAttr; From b426febbde03c6d9895a0e940f6a715d8fd99b08 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sun, 2 Aug 2026 12:44:01 +0300 Subject: [PATCH 21/29] core.system: Sys.abort() and printf() added --- druntime/src/core/system/package.d | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/druntime/src/core/system/package.d b/druntime/src/core/system/package.d index ef933dee4f7d..a7d852662ba9 100644 --- a/druntime/src/core/system/package.d +++ b/druntime/src/core/system/package.d @@ -17,3 +17,23 @@ struct Mem alias allocateOnStack = alloca; } + +struct Sys +{ + static import core.stdc.stdlib; + + alias abort = core.stdc.stdlib.abort; +} + +debug(PRINTF) +{ + static import core.stdc.stdio; + + void printf(T...)(scope const(char*) fmt, T vals) nothrow @nogc + { + int r = core.stdc.stdio.printf(fmt, vals); + + if(r < 0) + Sys.abort(); + } +} From 43eb8f8f47bd83488808b7a5056e4b83b2d1b835 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sun, 2 Aug 2026 13:19:23 +0300 Subject: [PATCH 22/29] core.system comment about debugging added, aliases added --- druntime/src/core/system/package.d | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/druntime/src/core/system/package.d b/druntime/src/core/system/package.d index a7d852662ba9..f56b88c05e8c 100644 --- a/druntime/src/core/system/package.d +++ b/druntime/src/core/system/package.d @@ -25,10 +25,15 @@ struct Sys alias abort = core.stdc.stdlib.abort; } -debug(PRINTF) +// Special case: we don't have resources to implement formatting functionality +// for now just for the sake of using it at debugging +debug { static import core.stdc.stdio; + alias sprintf = core.stdc.stdio.sprintf; + alias snprintf = core.stdc.stdio.snprintf; + void printf(T...)(scope const(char*) fmt, T vals) nothrow @nogc { int r = core.stdc.stdio.printf(fmt, vals); From ec6e2ecbb7323d72dab65d8e9009c7848a867412 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sun, 2 Aug 2026 17:50:30 +0300 Subject: [PATCH 23/29] more correct printf result value check --- druntime/src/core/system/package.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/druntime/src/core/system/package.d b/druntime/src/core/system/package.d index f56b88c05e8c..a84faf6c6093 100644 --- a/druntime/src/core/system/package.d +++ b/druntime/src/core/system/package.d @@ -38,7 +38,7 @@ debug { int r = core.stdc.stdio.printf(fmt, vals); - if(r < 0) + if(r < fmt.length) Sys.abort(); } } From e79d4d26d0c03cbfa41ddba3c37da62ea889eff2 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sun, 2 Aug 2026 18:28:29 +0300 Subject: [PATCH 24/29] Sys.print() added --- druntime/src/core/system/package.d | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/druntime/src/core/system/package.d b/druntime/src/core/system/package.d index a84faf6c6093..334d7fae991d 100644 --- a/druntime/src/core/system/package.d +++ b/druntime/src/core/system/package.d @@ -21,12 +21,31 @@ struct Mem struct Sys { static import core.stdc.stdlib; + import core.stdc.stdio; alias abort = core.stdc.stdlib.abort; + + // Assumes str is null-terminated string + static void print(scope const char[] str) nothrow @nogc + { + auto r = fputs(str.ptr, stdout); + if(r < 0) + Sys.abort(); + } + + //~ void print(T)(scope const char[] str, T vals) nothrow @nogc + //~ { + //~ // Assume str is null-terminated string + //~ auto r = fputs(str.ptr, stdout); + //~ if(r < 0) + //~ Sys.abort(); + //~ } + + //~ alias format = snprintf } -// Special case: we don't have resources to implement formatting functionality -// for now just for the sake of using it at debugging +// Special case: we don't have resources to implement mature formatting +// functionality for now just for the sake of using it at debugging debug { static import core.stdc.stdio; From f82da6f36827e0184637ba5b2fc760253b5e7424 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sun, 2 Aug 2026 18:58:16 +0300 Subject: [PATCH 25/29] core.system.Sys.printf() implemented (depends on libc version) and used --- druntime/src/core/gc/config.d | 13 +++++++------ druntime/src/core/system/package.d | 26 ++++---------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/druntime/src/core/gc/config.d b/druntime/src/core/gc/config.d index daeebec0f5d0..b2d86a8890b9 100644 --- a/druntime/src/core/gc/config.d +++ b/druntime/src/core/gc/config.d @@ -9,6 +9,7 @@ module core.gc.config; import core.internal.parseoptions; import core.stdc.stdio : printf; +import core.system : Sys; import core.system.opt : Opt; alias Config = Opt.GcConfig; @@ -57,21 +58,21 @@ struct ConfigT() { import core.gc.registry : registeredGCFactories; - printf("GC options are specified as white space separated assignments: + Sys.printf("GC options are specified as white space separated assignments: disable:0|1 - start disabled (%d) fork:0|1 - set fork behaviour (%d) profile:0|1|2 - enable profiling with summary when terminating program (%d) - gc:".ptr, disable, fork, profile); + gc:", disable, fork, profile); foreach (i, entry; registeredGCFactories) { - if (i) printf("|"); - printf("%.*s", cast(int) entry.name.length, entry.name.ptr); + if (i) Sys.print("|"); + Sys.printf("%.*s", cast(int) entry.name.length, entry.name.ptr); } auto _initReserve = initReserve.bytes2prettyStruct; auto _minPoolSize = minPoolSize.bytes2prettyStruct; auto _maxPoolSize = maxPoolSize.bytes2prettyStruct; auto _incPoolSize = incPoolSize.bytes2prettyStruct; - printf(" - select gc implementation (default = conservative) + Sys.printf(" - select gc implementation (default = conservative) initReserve:N - initial memory to reserve in MB (%lld%c) minPoolSize:N - initial and minimum pool size in MB (%lld%c) @@ -82,7 +83,7 @@ struct ConfigT() cleanup:none|collect|finalize - how to treat live objects when terminating (collect) Memory-related values can use B, K, M or G suffixes. -".ptr, +", _initReserve.v, _initReserve.u, _minPoolSize.v, _minPoolSize.u, _maxPoolSize.v, _maxPoolSize.u, diff --git a/druntime/src/core/system/package.d b/druntime/src/core/system/package.d index 334d7fae991d..bc941d5ec1d9 100644 --- a/druntime/src/core/system/package.d +++ b/druntime/src/core/system/package.d @@ -33,30 +33,12 @@ struct Sys Sys.abort(); } - //~ void print(T)(scope const char[] str, T vals) nothrow @nogc - //~ { - //~ // Assume str is null-terminated string - //~ auto r = fputs(str.ptr, stdout); - //~ if(r < 0) - //~ Sys.abort(); - //~ } - - //~ alias format = snprintf -} - -// Special case: we don't have resources to implement mature formatting -// functionality for now just for the sake of using it at debugging -debug -{ - static import core.stdc.stdio; - - alias sprintf = core.stdc.stdio.sprintf; - alias snprintf = core.stdc.stdio.snprintf; - - void printf(T...)(scope const(char*) fmt, T vals) nothrow @nogc + /// C-formatted print + static void printf(T...)(scope const char[] fmt, T vals) nothrow @nogc { - int r = core.stdc.stdio.printf(fmt, vals); + static assert(T.length > 0); + int r = core.stdc.stdio.printf(fmt.ptr, vals); if(r < fmt.length) Sys.abort(); } From b8d39b906191eba3ea9c5aeb410ba5fb272ef50f Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Sun, 2 Aug 2026 23:23:15 +0300 Subject: [PATCH 26/29] Sys.print() can print non-null-terminated strings --- druntime/src/core/system/package.d | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/druntime/src/core/system/package.d b/druntime/src/core/system/package.d index bc941d5ec1d9..8ddec160afb6 100644 --- a/druntime/src/core/system/package.d +++ b/druntime/src/core/system/package.d @@ -25,12 +25,16 @@ struct Sys alias abort = core.stdc.stdlib.abort; - // Assumes str is null-terminated string static void print(scope const char[] str) nothrow @nogc { - auto r = fputs(str.ptr, stdout); - if(r < 0) - Sys.abort(); + // This is a silly approach, but it's a simple way to print non-null-terminated strings + // TODO: implement using write() or so + foreach(c; str) + { + auto r = fputc(c, stdout); + if(r == EOF) + Sys.abort(); + } } /// C-formatted print From c188f6ca849de14765fdd2b8b9e4b7b28485b859 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Mon, 3 Aug 2026 10:27:14 +0300 Subject: [PATCH 27/29] free() -> freeMem() --- druntime/src/core/gc/registry.d | 2 +- druntime/src/core/internal/gc/bits.d | 2 +- .../src/core/internal/gc/impl/manual/gc.d | 2 +- druntime/src/core/runtime.d | 8 ++--- druntime/src/core/system/package.d | 2 +- druntime/src/rt/dmain2.d | 4 +-- druntime/src/rt/minfo.d | 30 +++++++++---------- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/druntime/src/core/gc/registry.d b/druntime/src/core/gc/registry.d index ff4c20fbf4ba..fde461ae2982 100644 --- a/druntime/src/core/gc/registry.d +++ b/druntime/src/core/gc/registry.d @@ -85,7 +85,7 @@ GC createGCInstance(string name) continue; auto instance = entry.factory(); // only one GC at a time for now, so free the registry to not leak - Mem.free(entries.ptr); + Mem.freeMem(entries.ptr); entries = null; return instance; } diff --git a/druntime/src/core/internal/gc/bits.d b/druntime/src/core/internal/gc/bits.d index 1b0b1f8e043b..47d8f0a6621a 100644 --- a/druntime/src/core/internal/gc/bits.d +++ b/druntime/src/core/internal/gc/bits.d @@ -38,7 +38,7 @@ struct GCBits if (data) { if (!AllocSupportsShared || !share) - Mem.free(data); + Mem.freeMem(data); else static if (AllocSupportsShared) os_mem_unmap_shared(data, nwords * data[0].sizeof); else diff --git a/druntime/src/core/internal/gc/impl/manual/gc.d b/druntime/src/core/internal/gc/impl/manual/gc.d index ee7eeae97f78..cd0accf765d9 100644 --- a/druntime/src/core/internal/gc/impl/manual/gc.d +++ b/druntime/src/core/internal/gc/impl/manual/gc.d @@ -148,7 +148,7 @@ class ManualGC : GC void free(void* p) nothrow @nogc { - Mem.free(p); + Mem.freeMem(p); } /** diff --git a/druntime/src/core/runtime.d b/druntime/src/core/runtime.d index 234af8444958..fa6155734a0b 100644 --- a/druntime/src/core/runtime.d +++ b/druntime/src/core/runtime.d @@ -226,7 +226,7 @@ struct Runtime auto buf = cast(WCHAR*) Mem.allocateOne((len+1) * WCHAR.sizeof); if (buf is null) return null; - scope (exit) Mem.free(buf); + scope (exit) Mem.freeMem(buf); len = MultiByteToWideChar( CP_UTF8, 0, name.ptr, cast(int)name.length, buf, len); @@ -244,7 +244,7 @@ struct Runtime immutable len = name.length; auto buf = cast(char*) Mem.allocateOne(len + 1); if (!buf) return null; - scope (exit) Mem.free(buf); + scope (exit) Mem.freeMem(buf); buf[0 .. len] = name[]; buf[len] = 0; @@ -804,7 +804,7 @@ void defaultTraceDeallocator(Throwable.TraceInfo info) nothrow return; auto obj = cast(Object)info; destroy(obj); - Mem.free(cast(void *)obj); + Mem.freeMem(cast(void *)obj); } /// Default implementation for most POSIX systems @@ -878,7 +878,7 @@ else version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo static if (hasExecinfo) { const framelist = backtrace_symbols( callstack.ptr, numframes ); - scope(exit) Mem.free(cast(void*) framelist); + scope(exit) Mem.freeMem(cast(void*) framelist); static if (enableDwarf) { diff --git a/druntime/src/core/system/package.d b/druntime/src/core/system/package.d index 8ddec160afb6..b6d683ddbeb3 100644 --- a/druntime/src/core/system/package.d +++ b/druntime/src/core/system/package.d @@ -13,7 +13,7 @@ struct Mem static void* allocateOneBlank(size_t size) nothrow @nogc => allocateFewBlank(1, size); alias allocateFewBlank = calloc; alias reallocate = realloc; - alias free = core.stdc.stdlib.free; + alias freeMem = core.stdc.stdlib.free; alias allocateOnStack = alloca; } diff --git a/druntime/src/rt/dmain2.d b/druntime/src/rt/dmain2.d index 2efe24fc3e90..89c2a64e0981 100644 --- a/druntime/src/rt/dmain2.d +++ b/druntime/src/rt/dmain2.d @@ -672,7 +672,7 @@ extern (C) void _d_print_throwable(Throwable t) typeof(ptr) get() { if (ptr) ptr[len] = 0; return ptr; } - void free() { Mem.free(ptr); } + void free() { Mem.freeMem(ptr); } } HANDLE windowsHandle(int fd) @@ -726,7 +726,7 @@ extern (C) void _d_print_throwable(Throwable t) WideCharToMultiByte(codepage, 0, buf.ptr, cast(int)buf.len, sptr, slen, null, null); WriteFile(hStdErr, sptr, slen, null, null); - Mem.free(sptr); + Mem.freeMem(sptr); } buf.free(); } diff --git a/druntime/src/rt/minfo.d b/druntime/src/rt/minfo.d index 0002e62bbd13..164a924c0c49 100644 --- a/druntime/src/rt/minfo.d +++ b/druntime/src/rt/minfo.d @@ -70,7 +70,7 @@ struct ModuleGroup size_t totalMods; int[] distance = (cast(int*) Mem.allocateOne(int.sizeof * _modules.length))[0 .. _modules.length]; scope(exit) - Mem.free(distance.ptr); + Mem.freeMem(distance.ptr); // determine the shortest path between two modules. Uses dijkstra // without a priority queue. (we can be a bit slow here, in order to @@ -226,9 +226,9 @@ struct ModuleGroup auto relevant = cast(size_t*) Mem.allocateOne(flagbytes); // has ctors/dtors scope (exit) { - Mem.free(ctorstart); - Mem.free(ctordone); - Mem.free(relevant); + Mem.freeMem(ctorstart); + Mem.freeMem(ctordone); + Mem.freeMem(relevant); } void clearFlags(size_t* flags) @@ -247,7 +247,7 @@ struct ModuleGroup auto reachable = cast(size_t*) Mem.allocateOne(flagbytes); scope(exit) - Mem.free(reachable); + Mem.freeMem(reachable); foreach (i, m; _modules) { @@ -275,7 +275,7 @@ struct ModuleGroup else { edges[i] = null; - Mem.free(edge); + Mem.freeMem(edge); } } } @@ -285,8 +285,8 @@ struct ModuleGroup { foreach (e; edges) if (e.ptr) - Mem.free(e.ptr); - Mem.free(edges.ptr); + Mem.freeMem(e.ptr); + Mem.freeMem(edges.ptr); } void buildCycleMessage(size_t sourceIdx, size_t cycleIdx, scope void delegate(string) nothrow sink) @@ -302,7 +302,7 @@ struct ModuleGroup sink(_modules[cycleIdx].name); sink(EOL); auto cyclePath = genCyclePath(sourceIdx, cycleIdx, edges); - scope(exit) Mem.free(cyclePath.ptr); + scope(exit) Mem.freeMem(cyclePath.ptr); sink(_modules[sourceIdx].name); sink("* ->" ~ EOL); @@ -332,7 +332,7 @@ struct ModuleGroup // initialize "stack" auto stack = cast(stackFrame*) Mem.allocateOne(stackFrame.sizeof * len); scope (exit) - Mem.free(stack); + Mem.freeMem(stack); auto stacktop = stack + len; auto sp = stack; sp.curMod = cast(int) idx; @@ -425,7 +425,7 @@ struct ModuleGroup // First, determine what modules are reachable. auto reachable = cast(size_t*) Mem.allocateOne(flagbytes); scope (exit) - Mem.free(reachable); + Mem.freeMem(reachable); if (!findDeps(curidx, reachable)) return false; // deprecated cycle error @@ -493,7 +493,7 @@ struct ModuleGroup { if (!processMod(idx)) { - Mem.free(ctors); + Mem.freeMem(ctors); return false; } } @@ -502,7 +502,7 @@ struct ModuleGroup if (ctoridx == 0) { // no ctors in the list. - Mem.free(ctors); + Mem.freeMem(ctors); } else { @@ -561,10 +561,10 @@ struct ModuleGroup void free() { if (_ctors.ptr) - Mem.free(_ctors.ptr); + Mem.freeMem(_ctors.ptr); _ctors = null; if (_tlsctors.ptr) - Mem.free(_tlsctors.ptr); + Mem.freeMem(_tlsctors.ptr); _tlsctors = null; // _modules = null; // let the owner free it } From 3755f544d1734a7f94caeb38888cd5c5b5a2776c Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Mon, 3 Aug 2026 10:46:27 +0300 Subject: [PATCH 28/29] core.system.Mem code moved to new core.system.memory module It turned out that it was convenient to be able to import only certain functions, so I had to get rid of Mem structure --- druntime/mak/COPY | 1 + druntime/mak/SRCS | 1 + druntime/src/core/gc/registry.d | 8 +-- druntime/src/core/internal/gc/bits.d | 6 +- .../src/core/internal/gc/impl/manual/gc.d | 12 ++-- druntime/src/core/runtime.d | 17 +++--- druntime/src/core/system/memory.d | 17 ++++++ druntime/src/core/system/package.d | 17 ------ druntime/src/rt/dmain2.d | 36 ++++++------ druntime/src/rt/minfo.d | 58 +++++++++---------- 10 files changed, 87 insertions(+), 86 deletions(-) create mode 100644 druntime/src/core/system/memory.d diff --git a/druntime/mak/COPY b/druntime/mak/COPY index f2e790da5632..b0c9a4df353e 100644 --- a/druntime/mak/COPY +++ b/druntime/mak/COPY @@ -23,6 +23,7 @@ COPY=\ $(IMPDIR)\core\memory.d \ $(IMPDIR)\core\runtime.d \ $(IMPDIR)\core\simd.d \ + $(IMPDIR)\core\system\memory.d \ $(IMPDIR)\core\system\opt.d \ $(IMPDIR)\core\system\package.d \ $(IMPDIR)\core\time.d \ diff --git a/druntime/mak/SRCS b/druntime/mak/SRCS index 5fb674c196bd..7559e93c09f0 100644 --- a/druntime/mak/SRCS +++ b/druntime/mak/SRCS @@ -17,6 +17,7 @@ SRCS=\ src\core\memory.d \ src\core\runtime.d \ src\core\simd.d \ + src\core\system\memory.d \ src\core\system\opt.d \ src\core\system\package.d \ src\core\time.d \ diff --git a/druntime/src/core/gc/registry.d b/druntime/src/core/gc/registry.d index fde461ae2982..7b5e28e01a8c 100644 --- a/druntime/src/core/gc/registry.d +++ b/druntime/src/core/gc/registry.d @@ -60,9 +60,9 @@ alias GCThreadInitFunction = void function(ThreadBase base) nothrow @nogc; void registerGCFactory(string name, GCFactory factory, GCThreadInitFunction threadInit = null) nothrow @nogc { - import core.system : Mem; + import core.system.memory : reallocate; - auto ptr = cast(Entry*) Mem.reallocate(entries.ptr, (entries.length + 1) * Entry.sizeof); + auto ptr = cast(Entry*) reallocate(entries.ptr, (entries.length + 1) * Entry.sizeof); entries = ptr[0 .. entries.length + 1]; entries[$ - 1] = Entry(name, factory, threadInit); } @@ -77,7 +77,7 @@ void registerGCFactory(string name, GCFactory factory, */ GC createGCInstance(string name) { - import core.system : Mem; + import core.system.memory : freeMem; foreach (entry; entries) { @@ -85,7 +85,7 @@ GC createGCInstance(string name) continue; auto instance = entry.factory(); // only one GC at a time for now, so free the registry to not leak - Mem.freeMem(entries.ptr); + freeMem(entries.ptr); entries = null; return instance; } diff --git a/druntime/src/core/internal/gc/bits.d b/druntime/src/core/internal/gc/bits.d index 47d8f0a6621a..a6f47d384e1e 100644 --- a/druntime/src/core/internal/gc/bits.d +++ b/druntime/src/core/internal/gc/bits.d @@ -11,7 +11,7 @@ import core.internal.gc.os; import core.bitop; import core.exception : onOutOfMemoryError; -import core.system : Mem; +import core.system.memory : allocateOneBlank, freeMem; import core.stdc.string : memcpy, memset; // use version gcbitsSingleBitOperation to disable optimizations that use @@ -38,7 +38,7 @@ struct GCBits if (data) { if (!AllocSupportsShared || !share) - Mem.freeMem(data); + freeMem(data); else static if (AllocSupportsShared) os_mem_unmap_shared(data, nwords * data[0].sizeof); else @@ -51,7 +51,7 @@ struct GCBits { this.nbits = nbits; if (!AllocSupportsShared || !share) - data = cast(typeof(data[0])*) Mem.allocateOneBlank(nwords * data[0].sizeof); + data = cast(typeof(data[0])*) allocateOneBlank(nwords * data[0].sizeof); else static if (AllocSupportsShared) data = cast(typeof(data[0])*)os_mem_map_shared(nwords * data[0].sizeof); // Allocate as MAP_SHARED else diff --git a/druntime/src/core/internal/gc/impl/manual/gc.d b/druntime/src/core/internal/gc/impl/manual/gc.d index cd0accf765d9..1541a2a0bdcd 100644 --- a/druntime/src/core/internal/gc/impl/manual/gc.d +++ b/druntime/src/core/internal/gc/impl/manual/gc.d @@ -25,7 +25,7 @@ import core.internal.container.array; import core.thread.threadbase : ThreadBase; -import core.system: Mem; +import core.system.memory; static import core.memory; extern (C) noreturn onOutOfMemoryError(void* pretend_sideffect = null, string file = __FILE__, size_t line = __LINE__) @trusted pure nothrow @nogc; /* dmd @@@BUG11461@@@ */ @@ -46,7 +46,7 @@ private GC initialize() { import core.lifetime : emplace; - auto gc = cast(ManualGC) Mem.allocateOne(__traits(classInstanceSize, ManualGC)); + auto gc = cast(ManualGC) allocateOne(__traits(classInstanceSize, ManualGC)); if (!gc) onOutOfMemoryError(); @@ -102,7 +102,7 @@ class ManualGC : GC void* malloc(size_t size, uint bits, const TypeInfo ti) nothrow { - void* p = Mem.allocateOne(size); + void* p = allocateOne(size); if (size && p is null) onOutOfMemoryError(); @@ -120,7 +120,7 @@ class ManualGC : GC void* calloc(size_t size, uint bits, const TypeInfo ti) nothrow { - void* p = Mem.allocateOneBlank(size); + void* p = allocateOneBlank(size); if (size && p is null) onOutOfMemoryError(); @@ -129,7 +129,7 @@ class ManualGC : GC void* realloc(void* p, size_t size, uint bits, const TypeInfo ti) nothrow { - p = Mem.reallocate(p, size); + p = reallocate(p, size); if (size && p is null) onOutOfMemoryError(); @@ -148,7 +148,7 @@ class ManualGC : GC void free(void* p) nothrow @nogc { - Mem.freeMem(p); + freeMem(p); } /** diff --git a/druntime/src/core/runtime.d b/druntime/src/core/runtime.d index fa6155734a0b..ade1e03910a3 100644 --- a/druntime/src/core/runtime.d +++ b/druntime/src/core/runtime.d @@ -10,7 +10,7 @@ module core.runtime; -import core.system : Mem; +import core.system.memory : allocateOne, freeMem; version (OSX) version = Darwin; @@ -211,7 +211,6 @@ struct Runtime */ static void* loadLibrary()(const scope char[] name) { - import core.system : Mem; version (Windows) { import core.sys.windows.winnls : CP_UTF8, MultiByteToWideChar; @@ -224,9 +223,9 @@ struct Runtime if (len == 0) return null; - auto buf = cast(WCHAR*) Mem.allocateOne((len+1) * WCHAR.sizeof); + auto buf = cast(WCHAR*) allocateOne((len+1) * WCHAR.sizeof); if (buf is null) return null; - scope (exit) Mem.freeMem(buf); + scope (exit) freeMem(buf); len = MultiByteToWideChar( CP_UTF8, 0, name.ptr, cast(int)name.length, buf, len); @@ -242,9 +241,9 @@ struct Runtime /* Need a 0-terminated C string for the dll name */ immutable len = name.length; - auto buf = cast(char*) Mem.allocateOne(len + 1); + auto buf = cast(char*) allocateOne(len + 1); if (!buf) return null; - scope (exit) Mem.freeMem(buf); + scope (exit) freeMem(buf); buf[0 .. len] = name[]; buf[len] = 0; @@ -745,7 +744,7 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null ) // @nogc static T allocate(T, Args...)(auto ref Args args) @nogc { import core.lifetime : emplace; - auto result = cast(T) Mem.allocateOne(__traits(classInstanceSize, T)); + auto result = cast(T) allocateOne(__traits(classInstanceSize, T)); return emplace(result, args); } version (Windows) @@ -804,7 +803,7 @@ void defaultTraceDeallocator(Throwable.TraceInfo info) nothrow return; auto obj = cast(Object)info; destroy(obj); - Mem.freeMem(cast(void *)obj); + freeMem(cast(void *)obj); } /// Default implementation for most POSIX systems @@ -878,7 +877,7 @@ else version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo static if (hasExecinfo) { const framelist = backtrace_symbols( callstack.ptr, numframes ); - scope(exit) Mem.freeMem(cast(void*) framelist); + scope(exit) freeMem(cast(void*) framelist); static if (enableDwarf) { diff --git a/druntime/src/core/system/memory.d b/druntime/src/core/system/memory.d new file mode 100644 index 000000000000..385a440bd411 --- /dev/null +++ b/druntime/src/core/system/memory.d @@ -0,0 +1,17 @@ +/// +module core.system.memory; + +// libc version +version (all) +{ + import core.stdc.stdlib; + + alias allocateOne = malloc; + alias allocateFew = (size_t num, size_t size) nothrow @nogc => allocateOne(num * size); + void* allocateOneBlank(size_t size) nothrow @nogc => allocateFewBlank(1, size); + alias allocateFewBlank = calloc; + alias reallocate = realloc; + alias freeMem = core.stdc.stdlib.free; + + alias allocateOnStack = alloca; +} diff --git a/druntime/src/core/system/package.d b/druntime/src/core/system/package.d index b6d683ddbeb3..53096b1704c6 100644 --- a/druntime/src/core/system/package.d +++ b/druntime/src/core/system/package.d @@ -1,23 +1,6 @@ /// module core.system; -//TODO: package -//package: - -struct Mem -{ - import core.stdc.stdlib; - - alias allocateOne = malloc; - alias allocateFew = (size_t num, size_t size) => allocateOne(num * size); - static void* allocateOneBlank(size_t size) nothrow @nogc => allocateFewBlank(1, size); - alias allocateFewBlank = calloc; - alias reallocate = realloc; - alias freeMem = core.stdc.stdlib.free; - - alias allocateOnStack = alloca; -} - struct Sys { static import core.stdc.stdlib; diff --git a/druntime/src/rt/dmain2.d b/druntime/src/rt/dmain2.d index 89c2a64e0981..9e15b821707b 100644 --- a/druntime/src/rt/dmain2.d +++ b/druntime/src/rt/dmain2.d @@ -20,7 +20,7 @@ import core.stdc.string : strerror; import rt.config : rt_cmdline_enabled, rt_configOption; import rt.memory; import rt.sections; -import core.system : Mem; +import core.system.memory; version (Windows) { @@ -50,7 +50,7 @@ else version (WASI) } version (DigitalMars) version (AArch64) - version = UseMalloc; // cuz Mem.allocateOnStack is not implemented yet + version = UseMalloc; // cuz allocateOnStack is not implemented yet // not sure why we can't define this in one place, but this is to keep this // module from importing core.runtime. @@ -289,13 +289,13 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) // Allocate args[] on the stack - use wargc version (UseMalloc) { - char[][] args = (cast(char[]*) Mem.allocateOne(wargc * (char[]).sizeof))[0 .. wargc]; + char[][] args = (cast(char[]*) allocateOne(wargc * (char[]).sizeof))[0 .. wargc]; if (wargc) assert(args.ptr); scope (exit) free(args.ptr); } else - char[][] args = (cast(char[]*) Mem.allocateOnStack(wargc * (char[]).sizeof))[0 .. wargc]; + char[][] args = (cast(char[]*) allocateOnStack(wargc * (char[]).sizeof))[0 .. wargc]; // This is required because WideCharToMultiByte requires int as input. assert(wCommandLineLength <= cast(size_t) int.max, "Wide char command line length must not exceed int.max"); @@ -304,13 +304,13 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) { version (UseMalloc) { - char* totalArgsBuff = cast(char*) Mem.allocateOne(totalArgsLength); + char* totalArgsBuff = cast(char*) allocateOne(totalArgsLength); if (totalArgsLength) assert(totalArgsBuff); scope (exit) free(totalArgsBuff); } else - char* totalArgsBuff = cast(char*) Mem.allocateOnStack(totalArgsLength); + char* totalArgsBuff = cast(char*) allocateOnStack(totalArgsLength); size_t j = 0; foreach (i; 0 .. wargc) { @@ -334,13 +334,13 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) // Allocate args[] on the stack version (UseMalloc) { - char[][] args = (cast(char[]*) Mem.allocateOne(argc * (char[]).sizeof))[0 .. argc]; + char[][] args = (cast(char[]*) allocateOne(argc * (char[]).sizeof))[0 .. argc]; if (argc) assert(args.ptr); scope (exit) free(args.ptr); } else - char[][] args = (cast(char[]*) Mem.allocateOnStack(argc * (char[]).sizeof))[0 .. argc]; + char[][] args = (cast(char[]*) allocateOnStack(argc * (char[]).sizeof))[0 .. argc]; size_t totalArgsLength = 0; foreach (i, ref arg; args) @@ -352,7 +352,7 @@ extern (C) int _d_run_main(int argc, char** argv, MainFunc mainFunc) else version (WASI) { // Allocate args[] on the stack - char[][] args = (cast(char[]*) Mem.allocateOnStack(argc * (char[]).sizeof))[0 .. argc]; + char[][] args = (cast(char[]*) allocateOnStack(argc * (char[]).sizeof))[0 .. argc]; size_t totalArgsLength = 0; foreach (i, ref arg; args) @@ -377,7 +377,7 @@ version (Windows) extern (C) int _d_wrun_main(int argc, wchar** wargv, MainFunc mainFunc) { // Allocate args[] on the stack - char[][] args = (cast(char[]*) Mem.allocateOnStack(argc * (char[]).sizeof))[0 .. argc]; + char[][] args = (cast(char[]*) allocateOnStack(argc * (char[]).sizeof))[0 .. argc]; // 1st pass: compute each argument's length as UTF-16 and UTF-8 size_t totalArgsLength = 0; @@ -392,7 +392,7 @@ extern (C) int _d_wrun_main(int argc, wchar** wargv, MainFunc mainFunc) } // Allocate a single buffer for all (null-terminated) argument strings in UTF-8 on the stack - char* utf8Buffer = cast(char*) Mem.allocateOnStack(totalArgsLength); + char* utf8Buffer = cast(char*) allocateOnStack(totalArgsLength); // 2nd pass: convert to UTF-8 and finalize `args` char* utf8 = utf8Buffer; @@ -406,7 +406,7 @@ extern (C) int _d_wrun_main(int argc, wchar** wargv, MainFunc mainFunc) } // Set C argc/argv; argv is a new stack-allocated array of UTF-8 C strings - char*[] argv = (cast(char**) Mem.allocateOnStack(argc * (char*).sizeof))[0 .. argc]; + char*[] argv = (cast(char**) allocateOnStack(argc * (char*).sizeof))[0 .. argc]; foreach (i, ref arg; argv) arg = args[i].ptr; _cArgs.argc = argc; @@ -482,13 +482,13 @@ private extern (C) int _d_run_main2(char[][] args, size_t totalArgsLength, MainF auto length = args.length * (char[]).sizeof + totalArgsLength; version (UseMalloc) { - auto buff = cast(char[]*) Mem.allocateOne(length); + auto buff = cast(char[]*) allocateOne(length); if (length) assert(buff); //scope (exit) buff; } else - auto buff = cast(char[]*) Mem.allocateOnStack(length); + auto buff = cast(char[]*) allocateOnStack(length); char[][] argsCopy = buff[0 .. args.length]; auto argBuff = cast(char*) (buff + args.length); @@ -661,7 +661,7 @@ extern (C) void _d_print_throwable(Throwable t) CP_UTF8, 0, s.ptr, cast(int)s.length, null, 0); if (!swlen) return; - auto newPtr = cast(WCHAR*) Mem.reallocate(ptr, + auto newPtr = cast(WCHAR*) reallocate(ptr, (this.len + swlen + 1) * WCHAR.sizeof); if (!newPtr) return; ptr = newPtr; @@ -672,7 +672,7 @@ extern (C) void _d_print_throwable(Throwable t) typeof(ptr) get() { if (ptr) ptr[len] = 0; return ptr; } - void free() { Mem.freeMem(ptr); } + void free() { freeMem(ptr); } } HANDLE windowsHandle(int fd) @@ -721,12 +721,12 @@ extern (C) void _d_print_throwable(Throwable t) uint codepage = GetConsoleOutputCP(); const slen = WideCharToMultiByte(codepage, 0, buf.ptr, cast(int)buf.len, null, 0, null, null); - if (auto sptr = cast(char*) Mem.allocateOne(slen * char.sizeof)) + if (auto sptr = cast(char*) allocateOne(slen * char.sizeof)) { WideCharToMultiByte(codepage, 0, buf.ptr, cast(int)buf.len, sptr, slen, null, null); WriteFile(hStdErr, sptr, slen, null, null); - Mem.freeMem(sptr); + freeMem(sptr); } buf.free(); } diff --git a/druntime/src/rt/minfo.d b/druntime/src/rt/minfo.d index 164a924c0c49..8b4998350be7 100644 --- a/druntime/src/rt/minfo.d +++ b/druntime/src/rt/minfo.d @@ -13,7 +13,7 @@ module rt.minfo; import core.stdc.stdio : fprintf, stderr; -import core.system : Mem; +import core.system.memory : freeMem, allocateOne, reallocate; import core.stdc.string : memcpy, memset; import rt.sections; @@ -66,11 +66,11 @@ struct ModuleGroup import core.bitop : bt, btc, bts; // set up all the arrays. - size_t[] cyclePath = (cast(size_t*) Mem.allocateOne(size_t.sizeof * _modules.length * 2))[0 .. _modules.length * 2]; + size_t[] cyclePath = (cast(size_t*) allocateOne(size_t.sizeof * _modules.length * 2))[0 .. _modules.length * 2]; size_t totalMods; - int[] distance = (cast(int*) Mem.allocateOne(int.sizeof * _modules.length))[0 .. _modules.length]; + int[] distance = (cast(int*) allocateOne(int.sizeof * _modules.length))[0 .. _modules.length]; scope(exit) - Mem.freeMem(distance.ptr); + freeMem(distance.ptr); // determine the shortest path between two modules. Uses dijkstra // without a priority queue. (we can be a bit slow here, in order to @@ -221,14 +221,14 @@ struct ModuleGroup // allocate some stack arrays that will be used throughout the process. immutable nwords = (len + 8 * size_t.sizeof - 1) / (8 * size_t.sizeof); immutable flagbytes = nwords * size_t.sizeof; - auto ctorstart = cast(size_t*) Mem.allocateOne(flagbytes); // ctor/dtor seen - auto ctordone = cast(size_t*) Mem.allocateOne(flagbytes); // ctor/dtor processed - auto relevant = cast(size_t*) Mem.allocateOne(flagbytes); // has ctors/dtors + auto ctorstart = cast(size_t*) allocateOne(flagbytes); // ctor/dtor seen + auto ctordone = cast(size_t*) allocateOne(flagbytes); // ctor/dtor processed + auto relevant = cast(size_t*) allocateOne(flagbytes); // has ctors/dtors scope (exit) { - Mem.freeMem(ctorstart); - Mem.freeMem(ctordone); - Mem.freeMem(relevant); + freeMem(ctorstart); + freeMem(ctordone); + freeMem(relevant); } void clearFlags(size_t* flags) @@ -239,15 +239,15 @@ struct ModuleGroup // build the edges between each module. We may need this for printing, // and also allows avoiding keeping a hash around for module lookups. - int[][] edges = (cast(int[]*) Mem.allocateOne((int[]).sizeof * _modules.length))[0 .. _modules.length]; + int[][] edges = (cast(int[]*) allocateOne((int[]).sizeof * _modules.length))[0 .. _modules.length]; { HashTab!(immutable(ModuleInfo)*, int) modIndexes; foreach (i, m; _modules) modIndexes[m] = cast(int) i; - auto reachable = cast(size_t*) Mem.allocateOne(flagbytes); + auto reachable = cast(size_t*) allocateOne(flagbytes); scope(exit) - Mem.freeMem(reachable); + freeMem(reachable); foreach (i, m; _modules) { @@ -255,7 +255,7 @@ struct ModuleGroup // https://issues.dlang.org/show_bug.cgi?id=16208 clearFlags(reachable); // preallocate enough space to store all the indexes - int *edge = cast(int*) Mem.allocateOne(int.sizeof * _modules.length); + int *edge = cast(int*) allocateOne(int.sizeof * _modules.length); size_t nEdges = 0; foreach (imp; m.importedModules) { @@ -270,12 +270,12 @@ struct ModuleGroup if (nEdges > 0) { // trim space to what is needed - edges[i] = (cast(int*) Mem.reallocate(edge, int.sizeof * nEdges))[0 .. nEdges]; + edges[i] = (cast(int*) reallocate(edge, int.sizeof * nEdges))[0 .. nEdges]; } else { edges[i] = null; - Mem.freeMem(edge); + freeMem(edge); } } } @@ -285,8 +285,8 @@ struct ModuleGroup { foreach (e; edges) if (e.ptr) - Mem.freeMem(e.ptr); - Mem.freeMem(edges.ptr); + freeMem(e.ptr); + freeMem(edges.ptr); } void buildCycleMessage(size_t sourceIdx, size_t cycleIdx, scope void delegate(string) nothrow sink) @@ -302,7 +302,7 @@ struct ModuleGroup sink(_modules[cycleIdx].name); sink(EOL); auto cyclePath = genCyclePath(sourceIdx, cycleIdx, edges); - scope(exit) Mem.freeMem(cyclePath.ptr); + scope(exit) freeMem(cyclePath.ptr); sink(_modules[sourceIdx].name); sink("* ->" ~ EOL); @@ -330,9 +330,9 @@ struct ModuleGroup } // initialize "stack" - auto stack = cast(stackFrame*) Mem.allocateOne(stackFrame.sizeof * len); + auto stack = cast(stackFrame*) allocateOne(stackFrame.sizeof * len); scope (exit) - Mem.freeMem(stack); + freeMem(stack); auto stacktop = stack + len; auto sp = stack; sp.curMod = cast(int) idx; @@ -423,9 +423,9 @@ struct ModuleGroup immutable ModuleInfo* current = _modules[curidx]; // First, determine what modules are reachable. - auto reachable = cast(size_t*) Mem.allocateOne(flagbytes); + auto reachable = cast(size_t*) allocateOne(flagbytes); scope (exit) - Mem.freeMem(reachable); + freeMem(reachable); if (!findDeps(curidx, reachable)) return false; // deprecated cycle error @@ -468,7 +468,7 @@ struct ModuleGroup clearFlags(ctordone); // pre-allocate enough space to hold all modules. - ctors = cast(immutable(ModuleInfo)**) Mem.allocateOne(len * (void*).sizeof); + ctors = cast(immutable(ModuleInfo)**) allocateOne(len * (void*).sizeof); ctoridx = 0; foreach (idx, m; _modules) { @@ -493,7 +493,7 @@ struct ModuleGroup { if (!processMod(idx)) { - Mem.freeMem(ctors); + freeMem(ctors); return false; } } @@ -502,11 +502,11 @@ struct ModuleGroup if (ctoridx == 0) { // no ctors in the list. - Mem.freeMem(ctors); + freeMem(ctors); } else { - ctors = cast(immutable(ModuleInfo)**) Mem.reallocate(ctors, ctoridx * (void*).sizeof); + ctors = cast(immutable(ModuleInfo)**) reallocate(ctors, ctoridx * (void*).sizeof); if (ctors is null) assert(0); result = ctors[0 .. ctoridx]; @@ -561,10 +561,10 @@ struct ModuleGroup void free() { if (_ctors.ptr) - Mem.freeMem(_ctors.ptr); + freeMem(_ctors.ptr); _ctors = null; if (_tlsctors.ptr) - Mem.freeMem(_tlsctors.ptr); + freeMem(_tlsctors.ptr); _tlsctors = null; // _modules = null; // let the owner free it } From 5de3953b1359bb75f50dd21ee1624b2db7fc8f5a Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Wed, 5 Aug 2026 15:59:26 +0300 Subject: [PATCH 29/29] modules renamed: core.system.* -> core.internal.config.* --- druntime/mak/COPY | 6 +++--- druntime/mak/SRCS | 6 +++--- druntime/src/core/gc/config.d | 4 ++-- druntime/src/core/gc/registry.d | 4 ++-- druntime/src/core/{system => internal/config}/memory.d | 2 +- druntime/src/core/{system => internal/config}/opt.d | 4 +--- druntime/src/core/{system => internal/config}/package.d | 2 +- druntime/src/core/internal/gc/bits.d | 2 +- druntime/src/core/internal/gc/impl/manual/gc.d | 2 +- druntime/src/core/runtime.d | 2 +- druntime/src/rt/dmain2.d | 2 +- druntime/src/rt/minfo.d | 2 +- 12 files changed, 18 insertions(+), 20 deletions(-) rename druntime/src/core/{system => internal/config}/memory.d (92%) rename druntime/src/core/{system => internal/config}/opt.d (69%) rename druntime/src/core/{system => internal/config}/package.d (96%) diff --git a/druntime/mak/COPY b/druntime/mak/COPY index a6f93a9c69c9..29846cbffe5a 100644 --- a/druntime/mak/COPY +++ b/druntime/mak/COPY @@ -25,9 +25,6 @@ COPY=\ $(IMPDIR)\core\memory.d \ $(IMPDIR)\core\runtime.d \ $(IMPDIR)\core\simd.d \ - $(IMPDIR)\core\system\memory.d \ - $(IMPDIR)\core\system\opt.d \ - $(IMPDIR)\core\system\package.d \ $(IMPDIR)\core\time.d \ $(IMPDIR)\core\vararg.d \ $(IMPDIR)\core\volatile.d \ @@ -36,6 +33,9 @@ COPY=\ $(IMPDIR)\core\internal\atomic.d \ $(IMPDIR)\core\internal\attributes.d \ $(IMPDIR)\core\internal\cast_.d \ + $(IMPDIR)\core\internal\config\memory.d \ + $(IMPDIR)\core\internal\config\opt.d \ + $(IMPDIR)\core\internal\config\package.d \ $(IMPDIR)\core\internal\convert.d \ $(IMPDIR)\core\internal\dassert.d \ $(IMPDIR)\core\internal\destruction.d \ diff --git a/druntime/mak/SRCS b/druntime/mak/SRCS index 971e187725c1..6b6604058150 100644 --- a/druntime/mak/SRCS +++ b/druntime/mak/SRCS @@ -18,9 +18,6 @@ SRCS=\ src\core\memory.d \ src\core\runtime.d \ src\core\simd.d \ - src\core\system\memory.d \ - src\core\system\opt.d \ - src\core\system\package.d \ src\core\time.d \ src\core\vararg.d \ src\core\volatile.d \ @@ -33,6 +30,9 @@ SRCS=\ src\core\internal\atomic.d \ src\core\internal\attributes.d \ src\core\internal\cast_.d \ + src\core\internal\config\memory.d \ + src\core\internal\config\opt.d \ + src\core\internal\config\package.d \ src\core\internal\convert.d \ src\core\internal\dassert.d \ src\core\internal\destruction.d \ diff --git a/druntime/src/core/gc/config.d b/druntime/src/core/gc/config.d index b2d86a8890b9..b0b9e54c8090 100644 --- a/druntime/src/core/gc/config.d +++ b/druntime/src/core/gc/config.d @@ -9,8 +9,8 @@ module core.gc.config; import core.internal.parseoptions; import core.stdc.stdio : printf; -import core.system : Sys; -import core.system.opt : Opt; +import core.internal.config : Sys; +import core.internal.config.opt : Opt; alias Config = Opt.GcConfig; diff --git a/druntime/src/core/gc/registry.d b/druntime/src/core/gc/registry.d index 7b5e28e01a8c..64c7f89869ea 100644 --- a/druntime/src/core/gc/registry.d +++ b/druntime/src/core/gc/registry.d @@ -60,7 +60,7 @@ alias GCThreadInitFunction = void function(ThreadBase base) nothrow @nogc; void registerGCFactory(string name, GCFactory factory, GCThreadInitFunction threadInit = null) nothrow @nogc { - import core.system.memory : reallocate; + import core.internal.config.memory : reallocate; auto ptr = cast(Entry*) reallocate(entries.ptr, (entries.length + 1) * Entry.sizeof); entries = ptr[0 .. entries.length + 1]; @@ -77,7 +77,7 @@ void registerGCFactory(string name, GCFactory factory, */ GC createGCInstance(string name) { - import core.system.memory : freeMem; + import core.internal.config.memory : freeMem; foreach (entry; entries) { diff --git a/druntime/src/core/system/memory.d b/druntime/src/core/internal/config/memory.d similarity index 92% rename from druntime/src/core/system/memory.d rename to druntime/src/core/internal/config/memory.d index 385a440bd411..0c3d107cbf1a 100644 --- a/druntime/src/core/system/memory.d +++ b/druntime/src/core/internal/config/memory.d @@ -1,5 +1,5 @@ /// -module core.system.memory; +module core.internal.config.memory; // libc version version (all) diff --git a/druntime/src/core/system/opt.d b/druntime/src/core/internal/config/opt.d similarity index 69% rename from druntime/src/core/system/opt.d rename to druntime/src/core/internal/config/opt.d index 38dd2e2a6a5c..16f6db1041b2 100644 --- a/druntime/src/core/system/opt.d +++ b/druntime/src/core/internal/config/opt.d @@ -1,7 +1,5 @@ /// -module core.system.opt; - -package(core): +module core.internal.config.opt; struct Opt { diff --git a/druntime/src/core/system/package.d b/druntime/src/core/internal/config/package.d similarity index 96% rename from druntime/src/core/system/package.d rename to druntime/src/core/internal/config/package.d index 53096b1704c6..0b004bd907f0 100644 --- a/druntime/src/core/system/package.d +++ b/druntime/src/core/internal/config/package.d @@ -1,5 +1,5 @@ /// -module core.system; +module core.internal.config; struct Sys { diff --git a/druntime/src/core/internal/gc/bits.d b/druntime/src/core/internal/gc/bits.d index a6f47d384e1e..82f1c1660ff4 100644 --- a/druntime/src/core/internal/gc/bits.d +++ b/druntime/src/core/internal/gc/bits.d @@ -11,7 +11,7 @@ import core.internal.gc.os; import core.bitop; import core.exception : onOutOfMemoryError; -import core.system.memory : allocateOneBlank, freeMem; +import core.internal.config.memory : allocateOneBlank, freeMem; import core.stdc.string : memcpy, memset; // use version gcbitsSingleBitOperation to disable optimizations that use diff --git a/druntime/src/core/internal/gc/impl/manual/gc.d b/druntime/src/core/internal/gc/impl/manual/gc.d index 1541a2a0bdcd..0a8ba42bf4a6 100644 --- a/druntime/src/core/internal/gc/impl/manual/gc.d +++ b/druntime/src/core/internal/gc/impl/manual/gc.d @@ -25,7 +25,7 @@ import core.internal.container.array; import core.thread.threadbase : ThreadBase; -import core.system.memory; +import core.internal.config.memory; static import core.memory; extern (C) noreturn onOutOfMemoryError(void* pretend_sideffect = null, string file = __FILE__, size_t line = __LINE__) @trusted pure nothrow @nogc; /* dmd @@@BUG11461@@@ */ diff --git a/druntime/src/core/runtime.d b/druntime/src/core/runtime.d index ade1e03910a3..5ff94fd7fd38 100644 --- a/druntime/src/core/runtime.d +++ b/druntime/src/core/runtime.d @@ -10,7 +10,7 @@ module core.runtime; -import core.system.memory : allocateOne, freeMem; +import core.internal.config.memory : allocateOne, freeMem; version (OSX) version = Darwin; diff --git a/druntime/src/rt/dmain2.d b/druntime/src/rt/dmain2.d index 9e15b821707b..d895b51598a4 100644 --- a/druntime/src/rt/dmain2.d +++ b/druntime/src/rt/dmain2.d @@ -20,7 +20,7 @@ import core.stdc.string : strerror; import rt.config : rt_cmdline_enabled, rt_configOption; import rt.memory; import rt.sections; -import core.system.memory; +import core.internal.config.memory; version (Windows) { diff --git a/druntime/src/rt/minfo.d b/druntime/src/rt/minfo.d index 8b4998350be7..b7f12e50936a 100644 --- a/druntime/src/rt/minfo.d +++ b/druntime/src/rt/minfo.d @@ -13,7 +13,7 @@ module rt.minfo; import core.stdc.stdio : fprintf, stderr; -import core.system.memory : freeMem, allocateOne, reallocate; +import core.internal.config.memory : freeMem, allocateOne, reallocate; import core.stdc.string : memcpy, memset; import rt.sections;