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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

C API: Add nix_init_apply #10537

Merged
merged 1 commit into from
Apr 18, 2024
Merged

Conversation

roberth
Copy link
Member

@roberth roberth commented Apr 17, 2024

Motivation

Thunks are relevant when initializing attrsets and lists, or passing arguments to functions that are lazy in those arguments. This is an important way to produce them.

Context

cc @jlesquembre

Also, the labeler worked :)

Priorities and Process

Add 馃憤 to pull requests you find important.

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

@roberth roberth added this to the Stable C API milestone Apr 17, 2024
@roberth roberth requested a review from edolstra as a code owner April 17, 2024 15:57
@github-actions github-actions bot added the c api Nix as a C library with a stable interface label Apr 17, 2024
Copy link
Member

@jlesquembre jlesquembre left a comment

Choose a reason for hiding this comment

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

Great to see the labeler work as expected :)

It looks good to me.聽
Just a minor thing, now that we have the .clang-format file in place, would you like to consider applying it to future changes for consistency?

@roberth
Copy link
Member Author

roberth commented Apr 18, 2024

Right! I didn't connect the dots. Will do now as well.

Thunks are relevant when initializing attrsets and lists, passing
arguments. This is an important way to produce them.
@roberth
Copy link
Member Author

roberth commented Apr 18, 2024

Thanks for the review.

I'll also revive my pre-commit hooks PR now that we have more files we can apply that to.

@roberth roberth merged commit 538eb26 into NixOS:master Apr 18, 2024
9 checks passed
* @see nix_value_call() for a similar function that performs the call immediately and only stores the return value.
* Note the different argument order.
*/
nix_err nix_init_apply(nix_c_context * context, Value * value, Value * fn, Value * arg);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not having an EvalState here restricts the implementation of the C API to implementations of Nix that have a global garbage collector or equivalent; there's no reason to not take an EvalState that isn't used in the API for future proofing.

And, ignoring that, having the distinct argument ordering feels like it's a bit of a footgun.

Copy link
Member Author

@roberth roberth Apr 21, 2024

Choose a reason for hiding this comment

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

Both issues follow from the format of the other initializers, but I'm not sure that it's a problem in this case, as the implementation doesn't allocate. Nonetheless, it's a risk, I suppose.

To be on the safe side, we could

  • Change the argument order to put the out parameter last
  • Add an EvalState *, which will be unused
  • s/nix_init/nix_value_init? This is extra breaking, but that's actually helpful I think. The API is still in development, so that's ok.

EDIT: added issue #10577

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c api Nix as a C library with a stable interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants