aboutsummaryrefslogtreecommitdiff
path: root/libphobos/src/std
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2025-01-05 14:24:49 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2025-01-05 14:24:49 +0100
commita676a516701789730aa482bcef4adcb683ba0140 (patch)
tree6c5b56d13162e537bae0ed373a9addf9be73af56 /libphobos/src/std
parent3dfad340cb140d64b8c0ecab05fa329238ebd06b (diff)
downloadgcc-a676a516701789730aa482bcef4adcb683ba0140.zip
gcc-a676a516701789730aa482bcef4adcb683ba0140.tar.gz
gcc-a676a516701789730aa482bcef4adcb683ba0140.tar.bz2
d: Merge upstream dmd, druntime 07bc5b9b3c, phobos de1dea109
Synchronizing with the upstream release of v2.109.0. D front-end changes: - Import dmd v2.109.0. D runtime changes: - Import druntime v2.109.0. Phobos changes: - Import phobos v2.109.0. gcc/d/ChangeLog: * decl.cc (DeclVisitor::finish_vtable): Update for new front-end interface. * dmd/MERGE: Merge upstream dmd 07bc5b9b3c. * dmd/VERSION: Bump version to v2.109.0. libphobos/ChangeLog: * libdruntime/MERGE: Merge upstream druntime 07bc5b9b3c. * src/MERGE: Merge upstream phobos de1dea109.
Diffstat (limited to 'libphobos/src/std')
-rw-r--r--libphobos/src/std/algorithm/searching.d15
-rw-r--r--libphobos/src/std/bitmanip.d7
-rw-r--r--libphobos/src/std/experimental/allocator/mallocator.d137
-rw-r--r--libphobos/src/std/file.d20
-rw-r--r--libphobos/src/std/math/hardware.d4
-rw-r--r--libphobos/src/std/math/rounding.d17
-rw-r--r--libphobos/src/std/process.d34
-rw-r--r--libphobos/src/std/regex/internal/ir.d4
-rw-r--r--libphobos/src/std/stdio.d305
-rw-r--r--libphobos/src/std/string.d48
-rw-r--r--libphobos/src/std/typecons.d5
11 files changed, 124 insertions, 472 deletions
diff --git a/libphobos/src/std/algorithm/searching.d b/libphobos/src/std/algorithm/searching.d
index 2d89dea..42a9df5 100644
--- a/libphobos/src/std/algorithm/searching.d
+++ b/libphobos/src/std/algorithm/searching.d
@@ -3873,6 +3873,21 @@ if (isInputRange!Range && !isInfinite!Range &&
assert([BigInt(2), BigInt(3)].maxElement == BigInt(3));
}
+// https://issues.dlang.org/show_bug.cgi?id=24596
+@safe unittest
+{
+ static class A {
+ int i;
+ int getI() @safe => i;
+ this(int i) @safe { this.i = i; }
+ }
+ auto arr = [new A(2), new A(3)];
+
+ arr.maxElement!(a => a.getI);
+
+ assert(arr[0].getI == 2);
+}
+
// minPos
/**
Computes a subrange of `range` starting at the first occurrence of `range`'s
diff --git a/libphobos/src/std/bitmanip.d b/libphobos/src/std/bitmanip.d
index de2ff31..639b821 100644
--- a/libphobos/src/std/bitmanip.d
+++ b/libphobos/src/std/bitmanip.d
@@ -805,6 +805,7 @@ private struct FloatingPointRepresentation(T)
Allows manipulating the fraction, exponent, and sign parts of a
`float` separately. The definition is:
+$(RUNNABLE_EXAMPLE
----
struct FloatRep
{
@@ -819,6 +820,7 @@ struct FloatRep
enum uint bias = 127, fractionBits = 23, exponentBits = 8, signBits = 1;
}
----
+)
*/
alias FloatRep = FloatingPointRepresentation!float;
@@ -874,6 +876,7 @@ alias FloatRep = FloatingPointRepresentation!float;
Allows manipulating the fraction, exponent, and sign parts of a
`double` separately. The definition is:
+$(RUNNABLE_EXAMPLE
----
struct DoubleRep
{
@@ -888,6 +891,7 @@ struct DoubleRep
enum uint bias = 1023, signBits = 1, fractionBits = 52, exponentBits = 11;
}
----
+)
*/
alias DoubleRep = FloatingPointRepresentation!double;
@@ -1050,6 +1054,8 @@ public:
of a type different than `size_t`, firstly because its length should
be a multiple of `size_t.sizeof`, and secondly because how the bits
are mapped:
+
+ $(RUNNABLE_EXAMPLE
---
size_t[] source = [1, 2, 3, 3424234, 724398, 230947, 389492];
enum sbits = size_t.sizeof * 8;
@@ -1060,6 +1066,7 @@ public:
assert(ba[n] == nth_bit);
}
---
+ )
The least significant bit in any `size_t` unit is the starting bit of this
unit, and the most significant bit is the last bit of this unit. Therefore,
passing e.g. an array of `int`s may result in a different `BitArray`
diff --git a/libphobos/src/std/experimental/allocator/mallocator.d b/libphobos/src/std/experimental/allocator/mallocator.d
index 02d5cf8..3d4dc9a 100644
--- a/libphobos/src/std/experimental/allocator/mallocator.d
+++ b/libphobos/src/std/experimental/allocator/mallocator.d
@@ -116,93 +116,11 @@ struct Mallocator
test!Mallocator();
}
-version (Windows)
+version (CRuntime_Microsoft)
{
- // DMD Win 32 bit, DigitalMars C standard library misses the _aligned_xxx
- // functions family (snn.lib)
- version (CRuntime_DigitalMars)
- {
- // Helper to cast the infos written before the aligned pointer
- // this header keeps track of the size (required to realloc) and of
- // the base ptr (required to free).
- private struct AlignInfo
- {
- void* basePtr;
- size_t size;
-
- @nogc nothrow
- static AlignInfo* opCall(void* ptr)
- {
- return cast(AlignInfo*) (ptr - AlignInfo.sizeof);
- }
- }
-
- @nogc nothrow
- private void* _aligned_malloc(size_t size, size_t alignment)
- {
- import core.stdc.stdlib : malloc;
- size_t offset = alignment + size_t.sizeof * 2 - 1;
-
- // unaligned chunk
- void* basePtr = malloc(size + offset);
- if (!basePtr) return null;
-
- // get aligned location within the chunk
- void* alignedPtr = cast(void**)((cast(size_t)(basePtr) + offset)
- & ~(alignment - 1));
-
- // write the header before the aligned pointer
- AlignInfo* head = AlignInfo(alignedPtr);
- head.basePtr = basePtr;
- head.size = size;
-
- return alignedPtr;
- }
-
- @nogc nothrow
- private void* _aligned_realloc(void* ptr, size_t size, size_t alignment)
- {
- import core.stdc.stdlib : free;
- import core.stdc.string : memcpy;
-
- if (!ptr) return _aligned_malloc(size, alignment);
-
- // gets the header from the exising pointer
- AlignInfo* head = AlignInfo(ptr);
-
- // gets a new aligned pointer
- void* alignedPtr = _aligned_malloc(size, alignment);
- if (!alignedPtr)
- {
- //to https://msdn.microsoft.com/en-us/library/ms235462.aspx
- //see Return value: in this case the original block is unchanged
- return null;
- }
-
- // copy exising data
- memcpy(alignedPtr, ptr, head.size);
- free(head.basePtr);
-
- return alignedPtr;
- }
-
- @nogc nothrow
- private void _aligned_free(void *ptr)
- {
- import core.stdc.stdlib : free;
- if (!ptr) return;
- AlignInfo* head = AlignInfo(ptr);
- free(head.basePtr);
- }
-
- }
- // DMD Win 64 bit, uses microsoft standard C library which implements them
- else
- {
- @nogc nothrow private extern(C) void* _aligned_malloc(size_t, size_t);
- @nogc nothrow private extern(C) void _aligned_free(void *memblock);
- @nogc nothrow private extern(C) void* _aligned_realloc(void *, size_t, size_t);
- }
+ @nogc nothrow private extern(C) void* _aligned_malloc(size_t, size_t);
+ @nogc nothrow private extern(C) void _aligned_free(void *memblock);
+ @nogc nothrow private extern(C) void* _aligned_realloc(void *, size_t, size_t);
}
/**
@@ -399,50 +317,3 @@ version (Posix)
assert(!AlignedMallocator.instance.alignedReallocate(c, size_t.max, 4096));
AlignedMallocator.instance.deallocate(c);
}
-
-version (CRuntime_DigitalMars)
-@nogc @system nothrow unittest
-{
- void* m;
-
- size_t m_addr() { return cast(size_t) m; }
-
- m = _aligned_malloc(16, 0x10);
- if (m)
- {
- assert((m_addr & 0xF) == 0);
- _aligned_free(m);
- }
-
- m = _aligned_malloc(16, 0x100);
- if (m)
- {
- assert((m_addr & 0xFF) == 0);
- _aligned_free(m);
- }
-
- m = _aligned_malloc(16, 0x1000);
- if (m)
- {
- assert((m_addr & 0xFFF) == 0);
- _aligned_free(m);
- }
-
- m = _aligned_malloc(16, 0x10);
- if (m)
- {
- assert((cast(size_t) m & 0xF) == 0);
- m = _aligned_realloc(m, 32, 0x10000);
- if (m) assert((m_addr & 0xFFFF) == 0);
- _aligned_free(m);
- }
-
- m = _aligned_malloc(8, 0x10);
- if (m)
- {
- *cast(ulong*) m = 0X01234567_89ABCDEF;
- m = _aligned_realloc(m, 0x800, 0x1000);
- if (m) assert(*cast(ulong*) m == 0X01234567_89ABCDEF);
- _aligned_free(m);
- }
-}
diff --git a/libphobos/src/std/file.d b/libphobos/src/std/file.d
index 1db779b..2a0d139 100644
--- a/libphobos/src/std/file.d
+++ b/libphobos/src/std/file.d
@@ -4053,12 +4053,10 @@ else version (Posix)
+/
void _ensureStatDone() @trusted scope
{
- import std.exception : enforce;
-
if (_didStat)
return;
- enforce(stat(_name.tempCString(), &_statBuf) == 0,
+ cenforce(stat(_name.tempCString(), &_statBuf) == 0,
"Failed to stat file `" ~ _name ~ "'");
_didStat = true;
@@ -4095,13 +4093,11 @@ else version (Posix)
+/
void _ensureLStatDone() @trusted scope
{
- import std.exception : enforce;
-
if (_didLStat)
return;
stat_t statbuf = void;
- enforce(lstat(_name.tempCString(), &statbuf) == 0,
+ cenforce(lstat(_name.tempCString(), &statbuf) == 0,
"Failed to stat file `" ~ _name ~ "'");
_lstatMode = statbuf.st_mode;
@@ -4183,12 +4179,12 @@ else version (Posix)
assert(!de.isFile);
assert(!de.isDir);
assert(de.isSymlink);
- assertThrown(de.size);
- assertThrown(de.timeStatusChanged);
- assertThrown(de.timeLastAccessed);
- assertThrown(de.timeLastModified);
- assertThrown(de.attributes);
- assertThrown(de.statBuf);
+ assertThrown!FileException(de.size);
+ assertThrown!FileException(de.timeStatusChanged);
+ assertThrown!FileException(de.timeLastAccessed);
+ assertThrown!FileException(de.timeLastModified);
+ assertThrown!FileException(de.attributes);
+ assertThrown!FileException(de.statBuf);
assert(symfile.exists);
symfile.remove();
}
diff --git a/libphobos/src/std/math/hardware.d b/libphobos/src/std/math/hardware.d
index dec8fdd..03e5463 100644
--- a/libphobos/src/std/math/hardware.d
+++ b/libphobos/src/std/math/hardware.d
@@ -222,7 +222,7 @@ private:
uint result = void;
asm pure nothrow @nogc
{
- "movfcsr2gr %0,$r2" : "=r" (result);
+ "movfcsr2gr %0, $fcsr2" : "=r" (result);
}
return result & EXCEPTIONS_MASK;
}
@@ -1047,7 +1047,7 @@ private:
ControlState cont;
asm pure nothrow @nogc
{
- "movfcsr2gr %0,$r0" : "=r" (cont);
+ "movfcsr2gr %0, $fcsr0" : "=r" (cont);
}
cont &= (roundingMask | allExceptions);
return cont;
diff --git a/libphobos/src/std/math/rounding.d b/libphobos/src/std/math/rounding.d
index f6654fc..a65e393 100644
--- a/libphobos/src/std/math/rounding.d
+++ b/libphobos/src/std/math/rounding.d
@@ -776,27 +776,18 @@ version (Posix)
*
* If the fractional part of x is exactly 0.5, the return value is rounded
* away from zero.
- *
- * $(BLUE This function is not implemented for Digital Mars C runtime.)
*/
long lround(real x) @trusted nothrow @nogc
{
- version (CRuntime_DigitalMars)
- assert(0, "lround not implemented");
- else
- return core.stdc.math.llroundl(x);
+ return core.stdc.math.llroundl(x);
}
///
@safe nothrow @nogc unittest
{
- version (CRuntime_DigitalMars) {}
- else
- {
- assert(lround(0.49) == 0);
- assert(lround(0.5) == 1);
- assert(lround(1.5) == 2);
- }
+ assert(lround(0.49) == 0);
+ assert(lround(0.5) == 1);
+ assert(lround(1.5) == 2);
}
/**
diff --git a/libphobos/src/std/process.d b/libphobos/src/std/process.d
index 325689b..d178374 100644
--- a/libphobos/src/std/process.d
+++ b/libphobos/src/std/process.d
@@ -127,26 +127,19 @@ else version (WatchOS)
version = iOSDerived;
}
-// When the DMC runtime is used, we have to use some custom functions
-// to convert between Windows file handles and FILE*s.
-version (Win32) version (CRuntime_DigitalMars) version = DMC_RUNTIME;
-
// Some of the following should be moved to druntime.
private
{
// Microsoft Visual C Runtime (MSVCRT) declarations.
- version (Windows)
+ version (CRuntime_Microsoft)
{
- version (DMC_RUNTIME) { } else
+ import core.stdc.stdint;
+ enum
{
- import core.stdc.stdint;
- enum
- {
- STDIN_FILENO = 0,
- STDOUT_FILENO = 1,
- STDERR_FILENO = 2,
- }
+ STDIN_FILENO = 0,
+ STDOUT_FILENO = 1,
+ STDERR_FILENO = 2,
}
}
@@ -350,6 +343,8 @@ static:
*/
bool opBinaryRight(string op : "in")(scope const(char)[] name) @trusted
{
+ if (name is null)
+ return false;
version (Posix)
return core.sys.posix.stdlib.getenv(name.tempCString()) !is null;
else version (Windows)
@@ -451,6 +446,10 @@ private:
// doesn't exist.
void getImpl(scope const(char)[] name, scope void delegate(const(OSChar)[]) @safe sink) @trusted
{
+ // fix issue https://issues.dlang.org/show_bug.cgi?id=24549
+ if (name is null)
+ return sink(null);
+
version (Windows)
{
// first we ask windows how long the environment variable is,
@@ -600,6 +599,15 @@ private:
assert("std_process" !in environment);
}
+// https://issues.dlang.org/show_bug.cgi?id=24549
+@safe unittest
+{
+ import std.exception : assertThrown;
+ assert(environment.get(null) is null);
+ assertThrown(environment[null]);
+ assert(!(null in environment));
+}
+
// =============================================================================
// Functions and classes for process management.
// =============================================================================
diff --git a/libphobos/src/std/regex/internal/ir.d b/libphobos/src/std/regex/internal/ir.d
index 04b902f..25566d6 100644
--- a/libphobos/src/std/regex/internal/ir.d
+++ b/libphobos/src/std/regex/internal/ir.d
@@ -318,7 +318,7 @@ struct Bytecode
@property bool backreference() const
{
assert(code == IR.GroupStart || code == IR.GroupEnd);
- return cast(bool)(raw & 1 << 23);
+ return (raw & 1 << 23) != 0;
}
//mark as local reference (for backrefs in lookarounds)
@@ -332,7 +332,7 @@ struct Bytecode
@property bool localRef() const
{
assert(code == IR.Backref);
- return cast(bool)(raw & 1 << 23);
+ return (raw & 1 << 23) != 0;
}
//human readable name of instruction
diff --git a/libphobos/src/std/stdio.d b/libphobos/src/std/stdio.d
index 40dc854..8caa9b3 100644
--- a/libphobos/src/std/stdio.d
+++ b/libphobos/src/std/stdio.d
@@ -123,9 +123,6 @@ alias KeepTerminator = Flag!"keepTerminator";
version (CRuntime_Microsoft)
{
}
-else version (CRuntime_DigitalMars)
-{
-}
else version (CRuntime_Glibc)
{
}
@@ -215,54 +212,7 @@ version (Posix)
static import core.sys.posix.stdio; // getdelim, flockfile
}
-version (CRuntime_DigitalMars)
-{
- private alias _FPUTC = _fputc_nlock;
- private alias _FPUTWC = _fputwc_nlock;
- private alias _FGETC = _fgetc_nlock;
- private alias _FGETWC = _fgetwc_nlock;
- private alias _FLOCK = __fp_lock;
- private alias _FUNLOCK = __fp_unlock;
-
- // Alias for CRuntime_Microsoft compatibility.
- // @@@DEPRECATED_2.107@@@
- // Rename this back to _setmode once the deprecation phase has ended.
- private alias __setmode = setmode;
-
- // @@@DEPRECATED_2.107@@@
- deprecated("internal alias FPUTC was unintentionally available from "
- ~ "std.stdio and will be removed afer 2.107")
- alias FPUTC = _fputc_nlock;
- // @@@DEPRECATED_2.107@@@
- deprecated("internal alias FPUTWC was unintentionally available from "
- ~ "std.stdio and will be removed afer 2.107")
- alias FPUTWC = _fputwc_nlock;
- // @@@DEPRECATED_2.107@@@
- deprecated("internal alias FGETC was unintentionally available from "
- ~ "std.stdio and will be removed afer 2.107")
- alias FGETC = _fgetc_nlock;
- // @@@DEPRECATED_2.107@@@
- deprecated("internal alias FGETWC was unintentionally available from "
- ~ "std.stdio and will be removed afer 2.107")
- alias FGETWC = _fgetwc_nlock;
- // @@@DEPRECATED_2.107@@@
- deprecated("internal alias FLOCK was unintentionally available from "
- ~ "std.stdio and will be removed afer 2.107")
- alias FLOCK = __fp_lock;
- // @@@DEPRECATED_2.107@@@
- deprecated("internal alias FUNLOCK was unintentionally available from "
- ~ "std.stdio and will be removed afer 2.107")
- alias FUNLOCK = __fp_unlock;
- // @@@DEPRECATED_2.107@@@
- deprecated("internal alias _setmode was unintentionally available from "
- ~ "std.stdio and will be removed afer 2.107")
- alias _setmode = setmode;
- // @@@DEPRECATED_2.107@@@
- deprecated("internal function _fileno was unintentionally available from "
- ~ "std.stdio and will be removed afer 2.107")
- fileno_t _fileno(FILE* f) { return f._file; }
-}
-else version (CRuntime_Microsoft)
+version (CRuntime_Microsoft)
{
private alias _FPUTC = _fputc_nolock;
private alias _FPUTWC = _fputwc_nolock;
@@ -272,10 +222,6 @@ else version (CRuntime_Microsoft)
private alias _FUNLOCK = _unlock_file;
// @@@DEPRECATED_2.107@@@
- // Remove this once the deprecation phase for CRuntime_DigitalMars has ended.
- private alias __setmode = _setmode;
-
- // @@@DEPRECATED_2.107@@@
deprecated("internal alias FPUTC was unintentionally available from "
~ "std.stdio and will be removed afer 2.107")
alias FPUTC = _fputc_nolock;
@@ -413,11 +359,7 @@ else
private extern (C) @nogc nothrow
{
pragma(mangle, _FPUTC.mangleof) int trustedFPUTC(int ch, _iobuf* h) @trusted;
-
- version (CRuntime_DigitalMars)
- pragma(mangle, _FPUTWC.mangleof) int trustedFPUTWC(int ch, _iobuf* h) @trusted;
- else
- pragma(mangle, _FPUTWC.mangleof) int trustedFPUTWC(wchar_t ch, _iobuf* h) @trusted;
+ pragma(mangle, _FPUTWC.mangleof) int trustedFPUTWC(wchar_t ch, _iobuf* h) @trusted;
}
//------------------------------------------------------------------------------
@@ -829,7 +771,6 @@ Throws: `ErrnoException` in case of error.
f.close();
}
- version (CRuntime_DigitalMars) {} else // Not implemented
version (CRuntime_Microsoft) {} else // Not implemented
@safe unittest // Test changing mode
{
@@ -889,22 +830,7 @@ Params:
auto modez = stdioOpenmode.tempCString();
detach();
- version (CRuntime_DigitalMars)
- {
- // This is a re-implementation of DMC's fdopen, but without the
- // mucking with the file descriptor. POSIX standard requires the
- // new fdopen'd file to retain the given file descriptor's
- // position.
- auto fp = fopen("NUL", modez);
- errnoEnforce(fp, "Cannot open placeholder NUL stream");
- _FLOCK(fp);
- auto iob = cast(_iobuf*) fp;
- .close(iob._file);
- iob._file = fd;
- iob._flag &= ~_IOTRAN;
- _FUNLOCK(fp);
- }
- else version (CRuntime_Microsoft)
+ version (CRuntime_Microsoft)
{
auto fp = _fdopen(fd, modez);
errnoEnforce(fp);
@@ -943,26 +869,21 @@ Throws: `ErrnoException` in case of error.
import std.format : format;
// Create file descriptors from the handles
- version (CRuntime_DigitalMars)
- auto fd = _handleToFD(handle, FHND_DEVICE);
- else // MSVCRT
- {
- int mode;
- modeLoop:
- foreach (c; stdioOpenmode)
- switch (c)
- {
- case 'r': mode |= _O_RDONLY; break;
- case '+': mode &=~_O_RDONLY; break;
- case 'a': mode |= _O_APPEND; break;
- case 'b': mode |= _O_BINARY; break;
- case 't': mode |= _O_TEXT; break;
- case ',': break modeLoop;
- default: break;
- }
+ int mode;
+ modeLoop:
+ foreach (c; stdioOpenmode)
+ switch (c)
+ {
+ case 'r': mode |= _O_RDONLY; break;
+ case '+': mode &=~_O_RDONLY; break;
+ case 'a': mode |= _O_APPEND; break;
+ case 'b': mode |= _O_BINARY; break;
+ case 't': mode |= _O_TEXT; break;
+ case ',': break modeLoop;
+ default: break;
+ }
- auto fd = _open_osfhandle(cast(intptr_t) handle, mode);
- }
+ auto fd = _open_osfhandle(cast(intptr_t) handle, mode);
errnoEnforce(fd >= 0, "Cannot open Windows HANDLE");
fdopen(fd, stdioOpenmode, "HANDLE(%s)".format(handle));
@@ -1186,17 +1107,8 @@ Throws: `ErrnoException` if the file is not opened or the call to `fread` fails.
version (Windows)
{
immutable fileno_t fd = .fileno(_p.handle);
- immutable mode = .__setmode(fd, _O_BINARY);
- scope(exit) .__setmode(fd, mode);
- version (CRuntime_DigitalMars)
- {
- import core.atomic : atomicOp;
-
- // https://issues.dlang.org/show_bug.cgi?id=4243
- immutable info = __fhnd_info[fd];
- atomicOp!"&="(__fhnd_info[fd], ~FHND_TEXT);
- scope(exit) __fhnd_info[fd] = info;
- }
+ immutable mode = ._setmode(fd, _O_BINARY);
+ scope(exit) ._setmode(fd, mode);
}
immutable freadResult = trustedFread(_p.handle, buffer);
assert(freadResult <= buffer.length); // fread return guarantee
@@ -1276,24 +1188,14 @@ Throws: `ErrnoException` if the file is not opened or if the call to `fwrite` fa
version (Windows)
{
immutable fileno_t fd = .fileno(_p.handle);
- immutable oldMode = .__setmode(fd, _O_BINARY);
+ immutable oldMode = ._setmode(fd, _O_BINARY);
if (oldMode != _O_BINARY)
{
// need to flush the data that was written with the original mode
- .__setmode(fd, oldMode);
- flush(); // before changing translation mode .__setmode(fd, _O_BINARY);
- .__setmode(fd, _O_BINARY);
- }
-
- version (CRuntime_DigitalMars)
- {
- import core.atomic : atomicOp;
-
- // https://issues.dlang.org/show_bug.cgi?id=4243
- immutable info = __fhnd_info[fd];
- atomicOp!"&="(__fhnd_info[fd], ~FHND_TEXT);
- scope (exit) __fhnd_info[fd] = info;
+ ._setmode(fd, oldMode);
+ flush(); // before changing translation mode ._setmode(fd, _O_BINARY);
+ ._setmode(fd, _O_BINARY);
}
scope (exit)
@@ -1301,7 +1203,7 @@ Throws: `ErrnoException` if the file is not opened or if the call to `fwrite` fa
if (oldMode != _O_BINARY)
{
flush();
- .__setmode(fd, oldMode);
+ ._setmode(fd, oldMode);
}
}
}
@@ -1394,9 +1296,6 @@ Throws: `Exception` if the file is not opened.
f.seek(7);
assert(f.readln() == "hijklmnopqrstuvwxyz");
- version (CRuntime_DigitalMars)
- auto bigOffset = int.max - 100;
- else
version (CRuntime_Bionic)
auto bigOffset = int.max - 100;
else
@@ -2349,10 +2248,7 @@ Returns the underlying operating system `HANDLE` (Windows only).
version (Windows)
@property HANDLE windowsHandle()
{
- version (CRuntime_DigitalMars)
- return _fdToHandle(fileno);
- else
- return cast(HANDLE)_get_osfhandle(fileno);
+ return cast(HANDLE)_get_osfhandle(fileno);
}
@@ -3151,11 +3047,11 @@ is empty, throws an `Exception`. In case of an I/O error throws
// concept of ANSI/UNICODE mode. fputc doesn't work in UNICODE
// mode; fputwc has to be used. So that essentially means
// "wide-oriented" for us.
- immutable int mode = __setmode(f.fileno, _O_TEXT);
+ immutable int mode = _setmode(f.fileno, _O_TEXT);
// Set some arbitrary mode to obtain the previous one.
- if (mode != -1) // __setmode() succeeded
+ if (mode != -1) // _setmode() succeeded
{
- __setmode(f.fileno, mode); // Restore previous mode.
+ _setmode(f.fileno, mode); // Restore previous mode.
if (mode & (_O_WTEXT | _O_U16TEXT | _O_U8TEXT))
{
orientation_ = 1; // wide
@@ -3386,8 +3282,6 @@ is empty, throws an `Exception`. In case of an I/O error throws
{
fileno_t fd;
int oldMode;
- version (CRuntime_DigitalMars)
- ubyte oldInfo;
}
public:
@@ -3407,15 +3301,7 @@ is empty, throws an `Exception`. In case of an I/O error throws
{
.fflush(fps); // before changing translation mode
fd = .fileno(fps);
- oldMode = .__setmode(fd, _O_BINARY);
- version (CRuntime_DigitalMars)
- {
- import core.atomic : atomicOp;
-
- // https://issues.dlang.org/show_bug.cgi?id=4243
- oldInfo = __fhnd_info[fd];
- atomicOp!"&="(__fhnd_info[fd], ~FHND_TEXT);
- }
+ oldMode = ._setmode(fd, _O_BINARY);
}
}
@@ -3429,12 +3315,7 @@ is empty, throws an `Exception`. In case of an I/O error throws
version (Windows)
{
.fflush(fps); // before restoring translation mode
- version (CRuntime_DigitalMars)
- {
- // https://issues.dlang.org/show_bug.cgi?id=4243
- __fhnd_info[fd] = oldInfo;
- }
- .__setmode(fd, oldMode);
+ ._setmode(fd, oldMode);
}
_FUNLOCK(fps);
@@ -3887,19 +3768,12 @@ void main()
return setlocale(LC_CTYPE, loc.ptr).fromStringz.endsWith(loc);
});
scope(exit) () @trusted { setlocale(LC_CTYPE, oldCt); } ();
- version (CRuntime_DigitalMars) // DM can't handle Unicode above U+07FF.
- {
- alias strs = AliasSeq!("xä\u07FE", "yö\u07FF"w);
- }
- else
- {
- alias strs = AliasSeq!("xä\U0001F607", "yö\U0001F608"w);
- }
+ alias strs = AliasSeq!("xä\U0001F607", "yö\U0001F608"w);
{
auto f = File(deleteme, "w");
version (CRuntime_Microsoft)
{
- () @trusted { __setmode(fileno(f.getFP()), _O_U8TEXT); } ();
+ () @trusted { _setmode(fileno(f.getFP()), _O_U8TEXT); } ();
}
else
{
@@ -5537,120 +5411,7 @@ private struct LockedFile
// Private implementation of readln
private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orientation orientation) @safe
{
- version (CRuntime_DigitalMars)
- return () @trusted {
- auto lf = LockedFile(fps);
- ReadlnAppender app;
- app.initialize(buf);
-
- if (__fhnd_info[lf.fp._file] & FHND_WCHAR)
- { /* Stream is in wide characters.
- * Read them and convert to chars.
- */
- static assert(wchar_t.sizeof == 2);
- for (int c = void; (c = lf.fgetwc()) != -1; )
- {
- if ((c & ~0x7F) == 0)
- {
- app.putchar(cast(char) c);
- if (c == terminator)
- break;
- }
- else
- {
- if (c >= 0xD800 && c <= 0xDBFF)
- {
- int c2 = void;
- if ((c2 = lf.fgetwc()) != -1 ||
- c2 < 0xDC00 && c2 > 0xDFFF)
- {
- StdioException("unpaired UTF-16 surrogate");
- }
- c = ((c - 0xD7C0) << 10) + (c2 - 0xDC00);
- }
- app.putdchar(cast(dchar) c);
- }
- }
- if (ferror(fps))
- StdioException();
- }
- else if (lf.fp._flag & _IONBF)
- {
- /* Use this for unbuffered I/O, when running
- * across buffer boundaries, or for any but the common
- * cases.
- */
- L1:
- int c;
- while ((c = lf.fgetc()) != -1)
- {
- app.putchar(cast(char) c);
- if (c == terminator)
- {
- buf = app.data;
- return buf.length;
- }
-
- }
-
- if (ferror(fps))
- StdioException();
- }
- else
- {
- int u = lf.fp._cnt;
- char* p = lf.fp._ptr;
- int i;
- if (lf.fp._flag & _IOTRAN)
- { /* Translated mode ignores \r and treats ^Z as end-of-file
- */
- char c;
- while (1)
- {
- if (i == u) // if end of buffer
- goto L1; // give up
- c = p[i];
- i++;
- if (c != '\r')
- {
- if (c == terminator)
- break;
- if (c != 0x1A)
- continue;
- goto L1;
- }
- else
- { if (i != u && p[i] == terminator)
- break;
- goto L1;
- }
- }
- app.putonly(p[0 .. i]);
- app.buf[i - 1] = cast(char) terminator;
- if (terminator == '\n' && c == '\r')
- i++;
- }
- else
- {
- while (1)
- {
- if (i == u) // if end of buffer
- goto L1; // give up
- auto c = p[i];
- i++;
- if (c == terminator)
- break;
- }
- app.putonly(p[0 .. i]);
- }
- lf.fp._cnt -= i;
- lf.fp._ptr += i;
- }
-
- buf = app.data;
- return buf.length;
- }();
- else version (CRuntime_Microsoft)
+ version (CRuntime_Microsoft)
{
auto lf = LockedFile(fps);
diff --git a/libphobos/src/std/string.d b/libphobos/src/std/string.d
index ca14c23..b350d6b 100644
--- a/libphobos/src/std/string.d
+++ b/libphobos/src/std/string.d
@@ -5942,36 +5942,36 @@ C1[] tr(C1, C2, C3, C4 = immutable char)
n = 0; // consider it 'found' at position 0
Lfound:
-
- // Find the nth character in to[]
- dchar nextt;
- for (size_t i = 0; i < to.length; )
- {
- immutable t = decode(to, i);
- if (t == '-' && lastt != dchar.init && i < to.length)
+ { // create a new scope so that gotos don't skip of declaration of nextt
+ // Find the nth character in to[]
+ dchar nextt;
+ for (size_t i = 0; i < to.length; )
{
- nextt = decode(to, i);
- n -= nextt - lastt;
- if (n < 0)
+ immutable t = decode(to, i);
+ if (t == '-' && lastt != dchar.init && i < to.length)
{
- newc = nextt + n + 1;
+ nextt = decode(to, i);
+ n -= nextt - lastt;
+ if (n < 0)
+ {
+ newc = nextt + n + 1;
+ goto Lnewc;
+ }
+ lastt = dchar.init;
+ continue;
+ }
+ if (n == 0)
+ { newc = t;
goto Lnewc;
}
- lastt = dchar.init;
- continue;
- }
- if (n == 0)
- { newc = t;
- goto Lnewc;
+ lastt = t;
+ nextt = t;
+ n--;
}
- lastt = t;
- nextt = t;
- n--;
+ if (mod_d)
+ continue;
+ newc = nextt;
}
- if (mod_d)
- continue;
- newc = nextt;
-
Lnewc:
if (mod_s && modified && newc == lastc)
continue;
diff --git a/libphobos/src/std/typecons.d b/libphobos/src/std/typecons.d
index f5b4846..3c425c7 100644
--- a/libphobos/src/std/typecons.d
+++ b/libphobos/src/std/typecons.d
@@ -3125,7 +3125,10 @@ private:
}
// call possible struct destructors
- .destroy!(No.initialize)(*cast(T*) &this.data);
+ static if (is(T == struct))
+ {
+ .destroy!(No.initialize)(*cast(T*) &this.data);
+ }
}
}