D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13619 - std.container.array capacity not updated when length increases
Summary: std.container.array capacity not updated when length increases
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 trivial
Assignee: No Owner
URL:
Keywords: trivial
Depends on:
Blocks:
 
Reported: 2014-10-15 08:23 UTC by thedeemon
Modified: 2018-01-05 13:27 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description thedeemon 2014-10-15 08:23:41 UTC
import std.container;

void main() {
  Array!int a; // empty Array
  a.length = 10; 
  // now payload is allocated, length is set to 10, but capacity is still 0!

  // try to append a value
  a ~= 1; // runtime error (assertion: capacity < length !)
}

Fix is trivial, Array.Payload.length setter must update _capacity field when it reallocates data.
Comment 1 monarchdodra 2014-10-18 17:42:21 UTC
That's not fixed yet !?
Comment 2 safety0ff.bugz 2014-10-21 08:33:02 UTC
I think the bug you reported is not valid.
However, there is a bug when using length to shorten the array:

import std.container;

void main() {
  Array!int a; // empty Array
  a.length = 10; // a contains 10 default ints
  a.length = 9; // Remove one, should have capacity > 0
  assert(a.capacity > 0);
}
Comment 3 thedeemon 2014-10-21 11:02:26 UTC
Why do you think it's not valid?

It does throw runtime error and capacity is wrong after setting the length.
http://dpaste.dzfl.pl/b10858af2a56
Comment 4 safety0ff.bugz 2014-10-22 01:23:46 UTC
Ah, I misinterpreted the meaning of the capacity (unused capacity vs total capacity.)

Perhaps the title should be "std.container.array capacity not updated when changing length" or something like that since it's not specific to increasing length.
Comment 5 github-bugzilla 2017-03-11 20:00:27 UTC
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9
Fix issue 13619 - array capacity not updated when changing length

https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f
Merge pull request #5267 from byebye/issue_13619

Fix issue 13619 - array capacity not updated when changing length
merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
Comment 6 github-bugzilla 2017-03-22 12:22:34 UTC
Commits pushed to stable at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9
Fix issue 13619 - array capacity not updated when changing length

https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f
Merge pull request #5267 from byebye/issue_13619
Comment 7 github-bugzilla 2017-08-07 12:26:26 UTC
Commits pushed to newCTFE at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9
Fix issue 13619 - array capacity not updated when changing length

https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f
Merge pull request #5267 from byebye/issue_13619
Comment 8 github-bugzilla 2018-01-05 13:27:46 UTC
Commits pushed to dmd-cxx at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9
Fix issue 13619 - array capacity not updated when changing length

https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f
Merge pull request #5267 from byebye/issue_13619