Bug 21250 – dirEntries on non-existent directory causes assert error

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-09-15T21:57:19Z
Last change time
2020-10-18T23:50:59Z
Keywords
industry, pull
Assigned to
No Owner
Creator
John Colvin

Comments

Comment #0 by john.loughran.colvin — 2020-09-15T21:57:19Z
% cat simple.d void main() { import std.file : dirEntries, SpanMode; auto binDir = "/hist"; dirEntries(binDir, "*.bin", SpanMode.depth); } % dmd -run simple.d core.exception.AssertError@/home/john/dlang/dmd-2.094.0-beta.1/linux/bin64/../../src/phobos/std/typecons.d(6450): Assertion failure ---------------- ??:? _d_assertp [0x564f99e8c949] ??:? void std.typecons.RefCounted!(std.file.DirIteratorImpl, 0).RefCounted.__dtor() [0x564f99e8ba18] ??:? void std.file.DirIterator.__fieldDtor() [0x564f99e904b4] ??:? ref @trusted std.file.DirIterator std.file.DirIterator.__ctor(immutable(char)[], std.file.SpanMode, bool) [0x564f99e90404] ??:? std.algorithm.iteration.FilterResult!(std.file.dirEntries(immutable(char)[], immutable(char)[], std.file.SpanMode, bool).f(std.file.DirEntry), std.file.DirIterator).FilterResult std.file.dirEntries(immutable(char)[], immutable(char)[], std.file.SpanMode, bool) [0x564f99e905c3] ??:? _Dmain [0x564f99e8b95e] % dmd --version DMD64 D Compiler v2.094.0-beta.1
Comment #1 by uplink.coder — 2020-09-16T15:34:32Z
What happens here is a ctor dtor mismatch. A temporary of a Refcounted is created inside a function where the file not found exception is thrown. The dtor is called on that temporary, which is basically a ref of the refcounted since the refcounted has ref semantics on the count. when the execption passes up a level the destructor of the actual refcouted value is called. which tries to decrement the refcount again.
Comment #2 by uplink.coder — 2020-09-16T15:52:00Z
Comment #3 by andrei — 2020-09-30T18:37:45Z
Comment #4 by dlang-bot — 2020-09-30T19:50:32Z
@andralex created dlang/phobos pull request #7646 "Andralex patch 3" fixing this issue: - Fix Issue 21250 - dirEntries on non-existent directory causes assert error https://github.com/dlang/phobos/pull/7646
Comment #5 by dlang-bot — 2020-10-02T14:49:15Z
dlang/phobos pull request #7646 "Issue 21250 - dirEntries on non-existent directory causes assert error" was merged into stable: - b9e20a58953950e92fb19a397f77fa90e1461395 by Andrei Alexandrescu: Fix Issue 21250 - dirEntries on non-existent directory causes assert error https://github.com/dlang/phobos/pull/7646
Comment #6 by dlang-bot — 2020-10-18T23:50:59Z
dlang/phobos pull request #7664 "merge stable" was merged into master: - c5e6213dde8fc0949c39ec2364abfe2070a67b2b by Andrei Alexandrescu: Issue 21250 - dirEntries on non-existent directory causes assert error (#7646) Issue 21250 - dirEntries on non-existent directory causes assert error merged-on-behalf-of: Andrei Alexandrescu <[email protected]> https://github.com/dlang/phobos/pull/7664