Skip to content

Commit

Permalink
C API: source argument to nix_copy_value should be const
Browse files Browse the repository at this point in the history
  • Loading branch information
jlesquembre committed Apr 21, 2024
1 parent 8d70db3 commit 6acf02b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/libexpr-c/nix_api_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ nix_err nix_init_primop(nix_c_context * context, Value * value, PrimOp * p)
NIXC_CATCH_ERRS
}

nix_err nix_copy_value(nix_c_context * context, Value * value, Value * source)
nix_err nix_copy_value(nix_c_context * context, Value * value, const Value * source)
{
if (context)
context->last_err_code = NIX_OK;
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr-c/nix_api_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ nix_err nix_init_primop(nix_c_context * context, Value * value, PrimOp * op);
* @param[in] source value to copy from
* @return error code, NIX_OK on success.
*/
nix_err nix_copy_value(nix_c_context * context, Value * value, Value * source);
nix_err nix_copy_value(nix_c_context * context, Value * value, const Value * source);
/**@}*/

/** @brief Create a bindings builder
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/libexpr/nix_api_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,17 @@ TEST_F(nix_api_expr_test, nix_value_init_apply_lazy_arg)
nix_gc_decref(ctx, e);
}

TEST_F(nix_api_expr_test, nix_copy_value)
{
Value * source = nix_alloc_value(ctx, state);

nix_init_int(ctx, source, 42);
nix_copy_value(ctx, value, source);

ASSERT_EQ(42, nix_get_int(ctx, value));

// Clean up
nix_gc_decref(ctx, source);
}

}

0 comments on commit 6acf02b

Please sign in to comment.