digitalmars.D.bugs - [Issue 13878] New: Appending to an array block with modified flags
- via Digitalmars-d-bugs (36/36) Dec 19 2014 https://issues.dlang.org/show_bug.cgi?id=13878
https://issues.dlang.org/show_bug.cgi?id=13878 Issue ID: 13878 Summary: Appending to an array block with modified flags loses flag info Product: D Version: D2 Hardware: x86 OS: All Status: NEW Severity: major Priority: P1 Component: druntime Assignee: schveiguy yahoo.com Reporter: schveiguy yahoo.com This happens because the block info is cached, but when you set the flags for that block, the flags do not get back to the cache. We can half-solve the problem because the block info cache only uses base, size, and the APPENDABLE flag. The other flags are just bonus storage, but can deviate from the block info in the GC. For example, if you create a block like so: ubyte[] b = new ubyte[1000]; Then cast it to a void []: void[] v = cast(void[]) b; GC.setAttr(v.ptr, GC.BlkAttr.APPENDABLE) // remove NO_SCAN Now, if we append to v, once it reallocates, it will use the cached bits, which contain the "NO_SCAN" bit, and remove the change we made. If v now has pointers in it, those may be collected prematurely. We need to provide a way for the runtime to copy the flags from one block to another, and use that instead of the cache bits. Otherwise, we cannot support setting flags on an array. It shouldn't be too bad performance-wise, because at that point, we are already reallocating anyway. I say half-solve, because removing the APPENDABLE bit will not clear it out of the cache, and we may make incorrect assumptions about the block from it's cached APPENDABLE bit. I would caution anyone, however, to not ever clear the APPENDABLE bit. --
Dec 19 2014