Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve the std.fs.Dir API to not require an allocator #2885

Closed
andrewrk opened this issue Jul 13, 2019 · 1 comment
Closed

improve the std.fs.Dir API to not require an allocator #2885

andrewrk opened this issue Jul 13, 2019 · 1 comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@andrewrk
Copy link
Member

Extracted from a TODO comment:

zig/std/fs.zig

Lines 430 to 431 in bdfb314

/// TODO remove the allocator requirement from this API
pub fn open(allocator: *Allocator, dir_path: []const u8) OpenError!Dir {

Iterating over a directory does not fundamentally require an allocator. Let's remove the allocator requirement from this function.

This will remove one of the ways that this API can fail, making it more robust.

@andrewrk andrewrk added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. breaking Implementing this issue could cause existing code to no longer compile or have different behavior. standard library This issue involves writing Zig code for the standard library. labels Jul 13, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Jul 13, 2019
@ghost
Copy link

ghost commented Sep 13, 2019

I've been trying my hand at this and I ended up frustrated each time I've tried a different approach. The challenge comes from Dir methods such as nextDarwin(), nextLinux() and nextBsd() where they all contain a side-effect of reallocating the buffer and thus doubling the len each time that side-effect happens. I don't know how it can get anymore robust than this without having it be not be dynamic without allocating and avoiding segfaults due to a lack of memory safety from the same allocation. I would love to solve this issue but I need some advice and direction, otherwise I feel lost and disappointed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant