[Issue 23385] New: Consider making currTime @nogc and nothrow
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Oct 4 14:49:56 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23385
Issue ID: 23385
Summary: Consider making currTime @nogc and nothrow
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: andrej.mitrovich at gmail.com
std.datetime.systime is an excellent abstraction over the OS-provided timers.
And yet we cannot check the current time in @nogc nothrow code.
With just a few changes we can make it @nogc, but it will probably take a bit
more care than that.
-----
diff --git a/std/datetime/systime.d b/std/datetime/systime.d
index fcb8184..0fb7b82 100755
--- a/std/datetime/systime.d
+++ b/std/datetime/systime.d
@@ -530,7 +530,7 @@ public:
given $(REF DateTime,std,datetime,date) is assumed to
be in the given time zone.
+/
- this(DateTime dateTime, return scope immutable TimeZone tz = null) return
scope @safe nothrow
+ this(DateTime dateTime, return scope immutable TimeZone tz = null) return
scope @safe nothrow @nogc
{
try
this(dateTime, Duration.zero, tz);
@@ -581,7 +581,7 @@ public:
$(REF DateTimeException,std,datetime,date) if `fracSecs` is
negative or if it's
greater than or equal to one second.
+/
- this(DateTime dateTime, Duration fracSecs, return scope immutable TimeZone
tz = null) return scope @safe
+ this(DateTime dateTime, Duration fracSecs, return scope immutable TimeZone
tz = null) return scope @safe @nogc
{
enforce(fracSecs >= Duration.zero, new DateTimeException("A SysTime
cannot have negative fractional seconds."));
enforce(fracSecs < seconds(1), new DateTimeException("Fractional
seconds must be less than one second."));
@@ -638,7 +638,7 @@ public:
given $(REF Date,std,datetime,date) is assumed to be in the
given time zone.
+/
- this(Date date, return scope immutable TimeZone tz = null) return scope
@safe nothrow
+ this(Date date, return scope immutable TimeZone tz = null) return scope
@safe nothrow @nogc
{
_timezone = tz is null ? LocalTime() : tz;
@@ -691,7 +691,7 @@ public:
$(LREF SysTime). If null,
$(REF LocalTime,std,datetime,timezone) will be used.
+/
- this(long stdTime, return scope immutable TimeZone tz = null) return scope
@safe pure nothrow
+ this(long stdTime, return scope immutable TimeZone tz = null) return scope
@safe pure nothrow @nogc
{
_stdTime = stdTime;
_timezone = tz is null ? LocalTime() : tz;
@@ -10101,15 +10101,14 @@ else version (Windows)
private enum hnsecsFrom1601 = 504_911_232_000_000_000L;
- long FILETIMEToStdTime(scope const FILETIME* ft) @safe
+ long FILETIMEToStdTime(scope const FILETIME* ft) @safe @nogc
{
ULARGE_INTEGER ul;
ul.HighPart = ft.dwHighDateTime;
ul.LowPart = ft.dwLowDateTime;
ulong tempHNSecs = ul.QuadPart;
- if (tempHNSecs > long.max - hnsecsFrom1601)
- throw new DateTimeException("The given FILETIME cannot be
represented as a stdTime value.");
+ assert(!(tempHNSecs > long.max - hnsecsFrom1601));
return cast(long) tempHNSecs + hnsecsFrom1601;
}
-----
For now we have to resort to hacks like
https://p0nce.github.io/d-idioms/#Bypassing-@nogc
--
More information about the Digitalmars-d-bugs
mailing list