Issue 19259 - std.array.Appender needs a way to set/get the length
Summary: std.array.Appender needs a way to set/get the length
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2018-09-22 22:25 UTC by Jonathan Marler
Modified: 2024-12-01 16:34 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan Marler 2018-09-22 22:25:15 UTC
std.array.Appender needs a way to extend/add to the length of `data`.  See the following use case:

```
uint tryAppendFullPathNameImpl(const(wchar)* nullTerminatedPath, Appender!(wchar[]) builder)
{
    import core.sys.windows.winbase : GetFullPathNameW;
    auto prefixLength = builder.data.length;
    for (;;)
    {
        const result = GetFullPathNameW(nullTerminatedPath, builder.capacity - prefixLength,
            builder.data.ptr + prefixLength, null);
        if (result <= (builder.capacity - prefixLength))
        {
            // NO WAY TO DO THIS:
            //builder.overrideDataLength(prefixLength + result);
            return result;
        }
        builder.reserve(prefixLength + result);
    }
}
```

What's happening here is we are passing the Appender array to a C function that populates the array with our resuling "full path".  Note that this implementation is taken from .NET CoreFX:

https://github.com/dotnet/corefx/blob/1bff7880bfa949e8c5e46039808ec412640bbb5e/src/Common/src/CoreLib/System/IO/PathHelper.Windows.cs#L72

The problem is that once it's populated, we have no way of extending the length of the array after it was populated by the C function.
Comment 1 Dlang Bot 2022-04-16 14:09:39 UTC
@ljmf00 updated dlang/phobos pull request #8432 "feat(array): add .length property" fixing this issue:

- feat(array): add .length property
  
  This patch adds a .length property to either get and set the length of the
  managed array.
  
  Fix issue 19259.
  
  Reference: https://issues.dlang.org/show_bug.cgi?id=19259
  Signed-off-by: Luís Ferreira <contact@lsferreira.net>

https://github.com/dlang/phobos/pull/8432
Comment 2 dlangBugzillaToGithub 2024-12-01 16:34:12 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10351

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB