Bug 15809 – Putting std.stdio.File.ByLine in a class causes Invalid memory operation upon exit

Status
RESOLVED
Resolution
DUPLICATE
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-03-18T19:04:00Z
Last change time
2016-03-23T08:29:49Z
Assigned to
nobody
Creator
hsteoh

Comments

Comment #0 by hsteoh — 2016-03-18T19:04:24Z
Reduced code: ------ import std.stdio; class Wrapper { typeof(stdin.byLine()) src; } void main() { auto x = new Wrapper(); x.src = stdin.byLine(); } ------ Compiled with git HEAD, upon program exit, the following error is triggered: ------ core.exception.InvalidMemoryOperationError@src/core/exception.d(693): Invalid memory operation ------ Commenting out the second line in main() makes the problem go away. Works with older releases of dmd toolchain.
Comment #1 by ag0aep6g — 2016-03-22T16:00:26Z
See also issue 15821. It's very similar which suggests that there's a dmd/druntime bug beneath.
Comment #2 by ag0aep6g — 2016-03-22T17:35:11Z
It boils down to this: ---- alias T = void*; struct RefCounted { T* _store; this(int dummy) { import core.memory : GC; import core.stdc.stdlib : malloc; _store = cast(T*)malloc(T.sizeof); GC.addRange(&_store, T.sizeof); } ~this() { assert(_store !is null); import core.memory : GC; GC.removeRange(&_store); } } void main() { auto a = new RefCounted(0); } ---- I don't know if there's anything wrong with this usage of GC.addRange/GC.removeRange. If there is, this is a bug in std.typecons.RefCounted. If there's not, it's a druntime/dmd issue.
Comment #3 by code — 2016-03-23T08:29:49Z
*** This issue has been marked as a duplicate of issue 15822 ***