Skip to content

libexpr: Make Bindings::iterator a proper strong type instead of pointer#13983

Merged
Ericson2314 merged 2 commits intoNixOS:masterfrom
xokdvium:bindings-fixes
Sep 14, 2025
Merged

libexpr: Make Bindings::iterator a proper strong type instead of pointer#13983
Ericson2314 merged 2 commits intoNixOS:masterfrom
xokdvium:bindings-fixes

Conversation

@xokdvium
Copy link
Copy Markdown
Contributor

Motivation

As evident from the number of tests that were holding this API completely
wrong (the end() iterator returned from find() is NEVER nullptr) we should
not have this footgun. A proper strong type guarantees that this confusion
will not happen again.

Also this will be helpful down the road when Bindings becomes something
smarter than an array of Attr.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@xokdvium
Copy link
Copy Markdown
Contributor Author

Nevermind, this will pessimise the binary search a bunch. Will fix

@xokdvium xokdvium marked this pull request as draft September 14, 2025 19:45
As evident from the number of tests that were holding this API completely
wrong (the end() iterator returned from find() is NEVER nullptr) we should
not have this footgun. A proper strong type guarantees that this confusion
will not happen again.

Also this will be helpful down the road when Bindings becomes something
smarter than an array of Attr.
Comment on lines 140 to 149
const_iterator find(Symbol name) const
{
Attr key(name, 0);
const_iterator i = std::lower_bound(begin(), end(), key);
if (i != end() && i->name == name)
return i;
auto first = attrs;
auto last = attrs + size_;
const Attr * i = std::lower_bound(first, last, key);
if (i != last && i->name == name)
return const_iterator{i};
return end();
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function will get removed in a follow-up commit anyway, so code duplication is not a concern.

@xokdvium xokdvium marked this pull request as ready for review September 14, 2025 19:58
@xokdvium xokdvium requested a review from roberth September 14, 2025 20:11
@Ericson2314 Ericson2314 merged commit ffc14ac into NixOS:master Sep 14, 2025
14 checks passed
@xokdvium xokdvium deleted the bindings-fixes branch September 14, 2025 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants