Bug 14870 – incorrect use of assert to detect environmental errors in core.time

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-04T23:44:00Z
Last change time
2015-10-04T18:19:09Z
Keywords
pull
Assigned to
schveiguy
Creator
bugzilla

Comments

Comment #0 by bugzilla — 2015-08-04T23:44:15Z
Note the use of asserts in the following code in core.time: ---- static @property MonoTimeImpl currTime() @trusted nothrow @nogc { if(ticksPerSecond == 0) { assert(0, "MonoTimeImpl!(ClockType." ~ _clockName ~ ") failed to get the frequency of the system's monotonic clock."); } version(Windows) { long ticks; if(QueryPerformanceCounter(&ticks) == 0) { // This probably cannot happen on Windows 95 or later assert(0, "Call to QueryPerformanceCounter failed."); } return MonoTimeImpl(ticks); } else version(OSX) return MonoTimeImpl(mach_absolute_time()); else version(Posix) { timespec ts; if(clock_gettime(clockArg, &ts) != 0) assert(0, "Call to clock_gettime failed."); return MonoTimeImpl(convClockFreq(ts.tv_sec * 1_000_000_000L + ts.tv_nsec, 1_000_000_000L, ticksPerSecond)); } } --- The user should never see assert failures. But apparently, these are happening on some systems. Environment issues should not be tested with assert's. Instead, the issue should be tested for, and if it fails, an error message printed and the program exited with an error status.
Comment #1 by schveiguy — 2015-08-05T00:45:28Z
PR: https://github.com/D-Programming-Language/druntime/pull/1337 If this should be done a different way, please let me know.
Comment #2 by github-bugzilla — 2015-09-10T19:20:28Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/3f9c4a6f3daa4e296e3404fe9714d1f03d73dc50 Fix issue 14870 - Add new "abort" internal module and function, which will always print a message to stderr, even in release mode. This can be used to replace assert(0, msg) which does not print the message. https://github.com/D-Programming-Language/druntime/commit/c68373a215050fea77820c73a2d2a18f3b93c36b Merge pull request #1337 from schveiguy/addabort Fix Issue 14870 Add new "abort" internal module and function
Comment #3 by github-bugzilla — 2015-10-04T18:19:09Z
Commits pushed to stable at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/3f9c4a6f3daa4e296e3404fe9714d1f03d73dc50 Fix issue 14870 - Add new "abort" internal module and function, which will always print a https://github.com/D-Programming-Language/druntime/commit/c68373a215050fea77820c73a2d2a18f3b93c36b Merge pull request #1337 from schveiguy/addabort