libexpr-c: fix nix_get_external #15954
Open
Lillecarl wants to merge 2 commits into
Open
Conversation
Contributor
|
Can we have a unit test for this? |
xokdvium
reviewed
Jun 1, 2026
07fe3de to
56a0565
Compare
Author
|
@xokdvium I replicated the test from python-nix and cloned some existing getter value tests |
xokdvium
approved these changes
Jun 1, 2026
Contributor
|
cc @roberth |
900beac to
01e6907
Compare
…_value_out nix_get_external reads from an already-initialized nix_value (set via nix_init_external). Every other getter in the file (nix_get_bool, nix_get_int, nix_get_float, nix_get_string, nix_get_path_string) uses check_value_in, which asserts the value IS initialized. nix_get_external was the sole getter using check_value_out, which asserts the value is UNinitialized and throws "nix_value already initialized" for any valid external value — making the function always fail.
Regression test for the check_value_out → check_value_in fix: nix_get_external reads from an already-initialized value and must use check_value_in, not check_value_out (which asserts the value is NOT initialized). Added: - nix_get_external_roundtrip: create external → init → force → get back - nix_get_external_invalid: null and uninitialized value error paths - nix_get_external_value_content_null: null ExternalValue* gracefully
01e6907 to
35396d0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI Disclamier
This change is made in China ™️
Change explanation
nix_get_external reads from an already-initialized nix_value (set via nix_init_external). Every other getter in the file (nix_get_bool, nix_get_int, nix_get_float, nix_get_string, nix_get_path_string) uses check_value_in, which asserts the value IS initialized. nix_get_external was the sole getter using check_value_out, which asserts the value is UNinitialized and throws "nix_value already initialized" for any valid external value — making the function always fail.
Also made the value parameter const to match all other getters.
Motivation
I'm working on updating the cffi Python bindings from tweag so we can have the Nix we deserve in Python 😄
https://github.com/NixOS/nix/milestone/52
Context
I found this when creating unit tests at https://github.com/lillecarl/python-nix to cover the entire API surface and the external value tests just wouldn't pass.
@yorickvP