Bug 15364 – BitArray.len should be private

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-19T13:13:00Z
Last change time
2018-11-01T17:59:01Z
Assigned to
No Owner
Creator
Basile-z

Comments

Comment #0 by b2.temp — 2015-11-19T13:13:00Z
--- import std.bitmanip; void main(string[] args) { BitArray a; a.len = 1; a[0] = 1; } --- crashes because len shouldnt be only set using the length() setter.
Comment #1 by github-bugzilla — 2015-11-19T15:51:02Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/74fbb79087c46ebde38ac3648b6a46b76f2a0a9e fix issue 15364 - BitArray.len should be private https://github.com/D-Programming-Language/phobos/commit/c254fecc4824a884024e7907e2185cfc95e4c64d Merge pull request #3822 from Blumerline/patch-privatearrayfield fix issue 15364 - BitArray.len should be private
Comment #2 by github-bugzilla — 2016-01-03T14:15:04Z
Comment #3 by b2.temp — 2016-01-11T06:42:06Z
If you land here because some code is broken in phobos 2.070 note that you can fix by using the copy constructor that takes a size_t & void* (len,ptr) as parameter.
Comment #4 by schveiguy — 2016-01-26T03:58:29Z
Has been "reverted", albeit with deprecations. Reopening so it doesn't get forgotten -- yes, you can once again mess up BitArray by writing directly to len and ptr. Reference: https://github.com/D-Programming-Language/phobos/pull/3950
Comment #5 by andrei — 2016-12-23T21:20:06Z
Current compilation result: /d498/f670.d(6): Error: no property 'len' for type 'BitArray', did you mean '_len
Comment #6 by schveiguy — 2016-12-23T21:56:00Z
Just as a matter of record, here is the commit that fixed this issue: https://github.com/dlang/phobos/commit/43227b12c462ab116539302570eeff1ed6dd8d74
Comment #7 by tmarplatt — 2018-11-01T17:59:01Z
The following commit related to this issue https://github.com/dlang/phobos/commit/74fbb79087c46ebde38ac3648b6a46b76f2a0a9e has apparently overreached when setting bitsPerSizeT as private state. The intended fix is successful in hiding .len and .ptr, but there is no explicit rationale (in this thread and in the commit message) for also encapsulating .bitsPerSizeT. Namely, the question is: why has BitArray.bitsPerSizeT been made a private member? It's an enum. It can't be accidentally nor intentionally rewritten. I've ran into "variable std.bitmanip.BitArray.bitsPerSizeT is not accessible from module" errors because my module imports from an (albeit old) library which implements certain bit setting algorithm that relies on BitArray.bitsPerSizeT being publicly accessible. (If you need to know, the library in question is artemisd:) https://github.com/elvisxzhou/artemisd After examining the problem, the commit and the issue that produced the problem, I believe that the mentioned commit introduces an unintended regression, and that it deserves to be reviewed.