]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libphobos: Merge with upstream phobos 35977c802
authorIain Buclaw <ibuclaw@gdcproject.org>
Tue, 8 Apr 2025 14:41:10 +0000 (16:41 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Tue, 8 Apr 2025 14:41:10 +0000 (16:41 +0200)
Synchronizes recent bug fixes targeted for v2.111.1.

libphobos/ChangeLog:

* src/MERGE: Merge upstream phobos 35977c802.
* src/Makefile.am (PHOBOS_DSOURCES): Add
std/internal/windows/bcrypt.d.
* src/Makefile.in: Regenerate.

libphobos/src/MERGE
libphobos/src/Makefile.am
libphobos/src/Makefile.in
libphobos/src/std/file.d
libphobos/src/std/internal/windows/bcrypt.d [new file with mode: 0644]
libphobos/src/std/random.d

index 3dfe00877913cb7b597941575a849f38dbdd71f3..d870a91ba963d86e64e6f9ac1cf1ad036c7c1410 100644 (file)
@@ -1,4 +1,4 @@
-60034b56e2a036a66fa78cbc0ec0290956423684
+35977c8029e7bb4dbe1b887688dabebe04ebea02
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/phobos repository.
index 94e28f3d175d71c81f274c2195590fe1b41b4919..5d690dddf2bdfe500c1b97ac8e15783458251eee 100644 (file)
@@ -144,14 +144,15 @@ PHOBOS_DSOURCES = etc/c/curl.d etc/c/odbc/odbc32.d etc/c/odbc/odbc64.d \
        std/internal/unicode_comp.d std/internal/unicode_decomp.d \
        std/internal/unicode_grapheme.d std/internal/unicode_norm.d \
        std/internal/unicode_tables.d std/internal/windows/advapi32.d \
-       std/json.d std/logger/core.d std/logger/filelogger.d \
-       std/logger/multilogger.d std/logger/nulllogger.d std/logger/package.d \
-       std/math/algebraic.d std/math/constants.d std/math/exponential.d \
-       std/math/hardware.d std/math/operations.d std/math/package.d \
-       std/math/remainder.d std/math/rounding.d std/math/traits.d \
-       std/math/trigonometry.d std/mathspecial.d std/meta.d std/mmfile.d \
-       std/net/curl.d std/net/isemail.d std/numeric.d std/outbuffer.d \
-       std/package.d std/parallelism.d std/path.d std/process.d std/random.d \
+       std/internal/windows/bcrypt.d std/json.d std/logger/core.d \
+       std/logger/filelogger.d std/logger/multilogger.d \
+       std/logger/nulllogger.d std/logger/package.d std/math/algebraic.d \
+       std/math/constants.d std/math/exponential.d std/math/hardware.d \
+       std/math/operations.d std/math/package.d std/math/remainder.d \
+       std/math/rounding.d std/math/traits.d std/math/trigonometry.d \
+       std/mathspecial.d std/meta.d std/mmfile.d std/net/curl.d \
+       std/net/isemail.d std/numeric.d std/outbuffer.d std/package.d \
+       std/parallelism.d std/path.d std/process.d std/random.d \
        std/range/interfaces.d std/range/package.d std/range/primitives.d \
        std/regex/internal/backtracking.d std/regex/internal/generator.d \
        std/regex/internal/ir.d std/regex/internal/kickstart.d \
index d052aa805c2c0373826cf06ff6df995009cc1010..2bf7e3f28747b4ade9349a3d8f17f6a37505c836 100644 (file)
@@ -252,6 +252,7 @@ am__dirstamp = $(am__leading_dot)dirstamp
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/internal/unicode_norm.lo \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/internal/unicode_tables.lo \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/internal/windows/advapi32.lo \
+@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/internal/windows/bcrypt.lo \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/json.lo std/logger/core.lo \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/logger/filelogger.lo \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/logger/multilogger.lo \
@@ -612,14 +613,15 @@ libgphobos_la_LINK = $(LIBTOOL) --tag=D $(libgphobos_la_LIBTOOLFLAGS) \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/internal/unicode_comp.d std/internal/unicode_decomp.d \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/internal/unicode_grapheme.d std/internal/unicode_norm.d \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/internal/unicode_tables.d std/internal/windows/advapi32.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/json.d std/logger/core.d std/logger/filelogger.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/logger/multilogger.d std/logger/nulllogger.d std/logger/package.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/math/algebraic.d std/math/constants.d std/math/exponential.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/math/hardware.d std/math/operations.d std/math/package.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/math/remainder.d std/math/rounding.d std/math/traits.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/math/trigonometry.d std/mathspecial.d std/meta.d std/mmfile.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/net/curl.d std/net/isemail.d std/numeric.d std/outbuffer.d \
-@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/package.d std/parallelism.d std/path.d std/process.d std/random.d \
+@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/internal/windows/bcrypt.d std/json.d std/logger/core.d \
+@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/logger/filelogger.d std/logger/multilogger.d \
+@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/logger/nulllogger.d std/logger/package.d std/math/algebraic.d \
+@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/math/constants.d std/math/exponential.d std/math/hardware.d \
+@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/math/operations.d std/math/package.d std/math/remainder.d \
+@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/math/rounding.d std/math/traits.d std/math/trigonometry.d \
+@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/mathspecial.d std/meta.d std/mmfile.d std/net/curl.d \
+@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/net/isemail.d std/numeric.d std/outbuffer.d std/package.d \
+@ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/parallelism.d std/path.d std/process.d std/random.d \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/range/interfaces.d std/range/package.d std/range/primitives.d \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/regex/internal/backtracking.d std/regex/internal/generator.d \
 @ENABLE_LIBDRUNTIME_ONLY_FALSE@        std/regex/internal/ir.d std/regex/internal/kickstart.d \
@@ -901,6 +903,7 @@ std/internal/windows/$(am__dirstamp):
        @: > std/internal/windows/$(am__dirstamp)
 std/internal/windows/advapi32.lo:  \
        std/internal/windows/$(am__dirstamp)
+std/internal/windows/bcrypt.lo: std/internal/windows/$(am__dirstamp)
 std/json.lo: std/$(am__dirstamp)
 std/logger/$(am__dirstamp):
        @$(MKDIR_P) std/logger
index c3466acc05539f94a2d3a586bd923ad984c2244f..0b8da501d3f5e11115a2fd731c1c59e4fb610599 100644 (file)
@@ -983,10 +983,10 @@ private void renameImpl(scope const(char)[] f, scope const(char)[] t,
             import std.conv : to, text;
 
             if (!f)
-                f = to!(typeof(f))(fromz[0 .. wcslen(fromz)]);
+                f = fromz ? to!(typeof(f))(fromz[0 .. wcslen(fromz)]) : "(null)";
 
             if (!t)
-                t = to!(typeof(t))(toz[0 .. wcslen(toz)]);
+                t = toz ? to!(typeof(t))(toz[0 .. wcslen(toz)]) : "(null)";
 
             enforce(false,
                 new FileException(
diff --git a/libphobos/src/std/internal/windows/bcrypt.d b/libphobos/src/std/internal/windows/bcrypt.d
new file mode 100644 (file)
index 0000000..239dcd5
--- /dev/null
@@ -0,0 +1,65 @@
+module std.internal.windows.bcrypt;
+
+version (Windows):
+
+import core.sys.windows.bcrypt : BCryptGenRandom, BCRYPT_USE_SYSTEM_PREFERRED_RNG;
+import core.sys.windows.windef : HMODULE, PUCHAR, ULONG;
+import core.sys.windows.ntdef : NT_SUCCESS;
+
+pragma(lib, "Bcrypt.lib");
+
+package(std) bool bcryptGenRandom(T)(out T result) @trusted
+{
+    loadBcrypt();
+
+    const gotRandom = ptrBCryptGenRandom(
+        null,
+        cast(PUCHAR) &result,
+        ULONG(T.sizeof),
+        BCRYPT_USE_SYSTEM_PREFERRED_RNG,
+    );
+
+    return NT_SUCCESS(gotRandom);
+}
+
+private
+{
+    HMODULE hBcrypt = null;
+    typeof(BCryptGenRandom)* ptrBCryptGenRandom;
+}
+
+private void loadBcrypt() @nogc nothrow
+{
+    import core.sys.windows.winbase : GetProcAddress, LoadLibraryA;
+
+    if (!hBcrypt)
+    {
+        hBcrypt = LoadLibraryA("Bcrypt.dll");
+        if (!hBcrypt)
+            assert(false, `LoadLibraryA("Bcrypt.dll") failed.`); // `@nogc`
+
+        ptrBCryptGenRandom = cast(typeof(ptrBCryptGenRandom)) GetProcAddress(hBcrypt , "BCryptGenRandom");
+        if (!ptrBCryptGenRandom)
+            assert(false, `GetProcAddress(hBcrypt , "BCryptGenRandom") failed.`); // `@nogc`
+    }
+}
+
+// Will free `Bcrypt.dll`.
+private void freeBcrypt() @nogc nothrow
+{
+    import core.sys.windows.winbase : FreeLibrary;
+
+    if (hBcrypt)
+    {
+        if (!FreeLibrary(hBcrypt))
+            assert(false, `FreeLibrary("Bcrypt.dll") failed.`); // `@nogc`
+
+        hBcrypt = null;
+        ptrBCryptGenRandom = null;
+    }
+}
+
+static ~this()
+{
+    freeBcrypt();
+}
index fb4e5469088f3eff13a7eaa125091c6e4c0e7d5b..dc1763cf71c3a14d4cf329ad52af055d7d50e609 100644 (file)
@@ -1792,23 +1792,7 @@ version (linux)
 
 version (Windows)
 {
-    pragma(lib, "Bcrypt.lib");
-
-    private bool bcryptGenRandom(T)(out T result) @trusted
-    {
-        import core.sys.windows.windef : PUCHAR, ULONG;
-        import core.sys.windows.ntdef : NT_SUCCESS;
-        import core.sys.windows.bcrypt : BCryptGenRandom, BCRYPT_USE_SYSTEM_PREFERRED_RNG;
-
-        const gotRandom = BCryptGenRandom(
-            null,
-            cast(PUCHAR) &result,
-            ULONG(T.sizeof),
-            BCRYPT_USE_SYSTEM_PREFERRED_RNG,
-        );
-
-        return NT_SUCCESS(gotRandom);
-    }
+    import std.internal.windows.bcrypt : bcryptGenRandom;
 }
 
 /**