diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-02-03 19:01:32 +0100 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-02-03 22:06:42 +0100 |
commit | b1a207c6df0a9c5555017f65f8731acf8d4c14c2 (patch) | |
tree | fca99fd7efdcdf6fc71b042be6df26de755c9468 /libphobos/src/std/datetime | |
parent | b52a1dfe12a6303c7649f3ff5b8dac6c1001d49a (diff) | |
download | gcc-b1a207c6df0a9c5555017f65f8731acf8d4c14c2.zip gcc-b1a207c6df0a9c5555017f65f8731acf8d4c14c2.tar.gz gcc-b1a207c6df0a9c5555017f65f8731acf8d4c14c2.tar.bz2 |
libphobos: Merge upstream druntime 9d0c8364, phobos 9d575282e.
Druntime changes:
- Add platform-specific bindings for stdlib.h and sys/syctl.h.
- Add darwin bindings for mach/dyld.h.
- Fix solaris bindings for locale.h (PR98910).
- Remove deprecated bindings from the module headers.
Phobos changes:
- Backport platform-specific fixes for std.conv, std.datetime,
std.exception, std.experimental.allocator, std.file, std.math,
std.parallelism, std.socket, std.stdio, and std.system.
Reviewed-on: https://github.com/dlang/druntime/pull/3363
https://github.com/dlang/phobos/pull/7784
libphobos/ChangeLog:
PR d/98910
* libdruntime/MERGE: Merge upstream druntime 9d0c8364.
* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add
core/internal/attributes.d
(DRUNTIME_DSOURCES_BIONIC): Add core/sys/bionic/stdlib.d.
(DRUNTIME_DSOURCES_DARWIN): Add core/sys/darwin/stdlib.d, and
core/sys/darwin/sys/sysctl.d.
(DRUNTIME_DSOURCES_DRAGONFLYBSD): Add
core/sys/dragonflybsd/stdlib.d, and
core/sys/dragonflybsd/sys/sysctl.d.
(DRUNTIME_DSOURCES_FREEBSD): Add core/sys/freebsd/stdlib.d, and
core/sys/freebsd/sys/sysctl.d.
(DRUNTIME_DSOURCES_NETBSD): Add core/sys/netbsd/stdlib.d, and
core/sys/netbsd/sys/sysctl.d.
(DRUNTIME_DSOURCES_OPENBSD): Add core/sys/openbsd/stdlib.d, and
core/sys/openbsd/sys/sysctl.d.
(DRUNTIME_DSOURCES_SOLARIS): Add core/sys/solaris/stdlib.d.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos 9d575282e.
Diffstat (limited to 'libphobos/src/std/datetime')
-rw-r--r-- | libphobos/src/std/datetime/systime.d | 110 | ||||
-rw-r--r-- | libphobos/src/std/datetime/timezone.d | 17 |
2 files changed, 102 insertions, 25 deletions
diff --git a/libphobos/src/std/datetime/systime.d b/libphobos/src/std/datetime/systime.d index 0b11ed9..b229191 100644 --- a/libphobos/src/std/datetime/systime.d +++ b/libphobos/src/std/datetime/systime.d @@ -7,6 +7,15 @@ +/ module std.datetime.systime; +version (OSX) + version = Darwin; +else version (iOS) + version = Darwin; +else version (TVOS) + version = Darwin; +else version (WatchOS) + version = Darwin; + import core.time; import std.datetime.date; import std.datetime.timezone; @@ -161,18 +170,19 @@ public: static import core.stdc.time; enum hnsecsToUnixEpoch = unixTimeToStdTime(0); - version (OSX) + version (Darwin) { static if (clockType == ClockType.second) return unixTimeToStdTime(core.stdc.time.time(null)); else { import core.sys.posix.sys.time : gettimeofday, timeval; - timeval tv; - if (gettimeofday(&tv, null) != 0) - throw new TimeException("Call to gettimeofday() failed"); + timeval tv = void; + // Posix gettimeofday called with a valid timeval address + // and a null second parameter doesn't fail. + gettimeofday(&tv, null); return convert!("seconds", "hnsecs")(tv.tv_sec) + - convert!("usecs", "hnsecs")(tv.tv_usec) + + tv.tv_usec * 10 + hnsecsToUnixEpoch; } } @@ -188,9 +198,16 @@ public: else static if (clockType == ClockType.normal) alias clockArg = CLOCK_REALTIME; else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME; else static assert(0, "Previous static if is wrong."); - timespec ts; - if (clock_gettime(clockArg, &ts) != 0) - throw new TimeException("Call to clock_gettime() failed"); + timespec ts = void; + immutable error = clock_gettime(clockArg, &ts); + // Posix clock_gettime called with a valid address and valid clock_id is only + // permitted to fail if the number of seconds does not fit in time_t. If tv_sec + // is long or larger overflow won't happen before 292 billion years A.D. + static if (ts.tv_sec.max < long.max) + { + if (error) + throw new TimeException("Call to clock_gettime() failed"); + } return convert!("seconds", "hnsecs")(ts.tv_sec) + ts.tv_nsec / 100 + hnsecsToUnixEpoch; @@ -205,9 +222,16 @@ public: else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME_PRECISE; else static if (clockType == ClockType.second) alias clockArg = CLOCK_SECOND; else static assert(0, "Previous static if is wrong."); - timespec ts; - if (clock_gettime(clockArg, &ts) != 0) - throw new TimeException("Call to clock_gettime() failed"); + timespec ts = void; + immutable error = clock_gettime(clockArg, &ts); + // Posix clock_gettime called with a valid address and valid clock_id is only + // permitted to fail if the number of seconds does not fit in time_t. If tv_sec + // is long or larger overflow won't happen before 292 billion years A.D. + static if (ts.tv_sec.max < long.max) + { + if (error) + throw new TimeException("Call to clock_gettime() failed"); + } return convert!("seconds", "hnsecs")(ts.tv_sec) + ts.tv_nsec / 100 + hnsecsToUnixEpoch; @@ -218,12 +242,38 @@ public: return unixTimeToStdTime(core.stdc.time.time(null)); else { - import core.sys.posix.sys.time : gettimeofday, timeval; - timeval tv; - if (gettimeofday(&tv, null) != 0) - throw new TimeException("Call to gettimeofday() failed"); - return convert!("seconds", "hnsecs")(tv.tv_sec) + - convert!("usecs", "hnsecs")(tv.tv_usec) + + import core.sys.netbsd.time : clock_gettime, CLOCK_REALTIME; + timespec ts = void; + immutable error = clock_gettime(CLOCK_REALTIME, &ts); + // Posix clock_gettime called with a valid address and valid clock_id is only + // permitted to fail if the number of seconds does not fit in time_t. If tv_sec + // is long or larger overflow won't happen before 292 billion years A.D. + static if (ts.tv_sec.max < long.max) + { + if (error) + throw new TimeException("Call to clock_gettime() failed"); + } + return convert!("seconds", "hnsecs")(ts.tv_sec) + + ts.tv_nsec / 100 + + hnsecsToUnixEpoch; + } + } + else version (OpenBSD) + { + static if (clockType == ClockType.second) + return unixTimeToStdTime(core.stdc.time.time(null)); + else + { + import core.sys.openbsd.time : clock_gettime, CLOCK_REALTIME; + static if (clockType == ClockType.coarse) alias clockArg = CLOCK_REALTIME; + else static if (clockType == ClockType.normal) alias clockArg = CLOCK_REALTIME; + else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME; + else static assert(0, "Previous static if is wrong."); + timespec ts; + if (clock_gettime(clockArg, &ts) != 0) + throw new TimeException("Call to clock_gettime() failed"); + return convert!("seconds", "hnsecs")(ts.tv_sec) + + ts.tv_nsec / 100 + hnsecsToUnixEpoch; } } @@ -236,9 +286,16 @@ public: else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME_PRECISE; else static if (clockType == ClockType.second) alias clockArg = CLOCK_SECOND; else static assert(0, "Previous static if is wrong."); - timespec ts; - if (clock_gettime(clockArg, &ts) != 0) - throw new TimeException("Call to clock_gettime() failed"); + timespec ts = void; + immutable error = clock_gettime(clockArg, &ts); + // Posix clock_gettime called with a valid address and valid clock_id is only + // permitted to fail if the number of seconds does not fit in time_t. If tv_sec + // is long or larger overflow won't happen before 292 billion years A.D. + static if (ts.tv_sec.max < long.max) + { + if (error) + throw new TimeException("Call to clock_gettime() failed"); + } return convert!("seconds", "hnsecs")(ts.tv_sec) + ts.tv_nsec / 100 + hnsecsToUnixEpoch; @@ -254,9 +311,16 @@ public: else static if (clockType == ClockType.normal) alias clockArg = CLOCK_REALTIME; else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME; else static assert(0, "Previous static if is wrong."); - timespec ts; - if (clock_gettime(clockArg, &ts) != 0) - throw new TimeException("Call to clock_gettime() failed"); + timespec ts = void; + immutable error = clock_gettime(clockArg, &ts); + // Posix clock_gettime called with a valid address and valid clock_id is only + // permitted to fail if the number of seconds does not fit in time_t. If tv_sec + // is long or larger overflow won't happen before 292 billion years A.D. + static if (ts.tv_sec.max < long.max) + { + if (error) + throw new TimeException("Call to clock_gettime() failed"); + } return convert!("seconds", "hnsecs")(ts.tv_sec) + ts.tv_nsec / 100 + hnsecsToUnixEpoch; diff --git a/libphobos/src/std/datetime/timezone.d b/libphobos/src/std/datetime/timezone.d index 7ae1902..9b744ff 100644 --- a/libphobos/src/std/datetime/timezone.d +++ b/libphobos/src/std/datetime/timezone.d @@ -14,6 +14,15 @@ import std.exception : enforce; import std.range.primitives; import std.traits : isIntegral, isSomeString, Unqual; +version (OSX) + version = Darwin; +else version (iOS) + version = Darwin; +else version (TVOS) + version = Darwin; +else version (WatchOS) + version = Darwin; + version (Windows) { import core.stdc.time : time_t; @@ -296,7 +305,7 @@ public: else version (NetBSD) enum utcZone = "UTC"; else version (DragonFlyBSD) enum utcZone = "UTC"; else version (linux) enum utcZone = "UTC"; - else version (OSX) enum utcZone = "UTC"; + else version (Darwin) enum utcZone = "UTC"; else version (Solaris) enum utcZone = "UTC"; else static assert(0, "The location of the UTC timezone file on this Posix platform must be set."); @@ -671,7 +680,11 @@ public: @safe unittest { - assert(LocalTime().dstName !is null); + // tzname, called from dstName, isn't set by default for Musl. + version (CRuntime_Musl) + assert(LocalTime().dstName is null); + else + assert(LocalTime().dstName !is null); version (Posix) { |