Skip to content

Commit 07fe3de

Browse files
committed
fix(libexpr-c): nix_get_external should use check_value_in, not check_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. Also made the value parameter const to match all other getters.
1 parent b4f9970 commit 07fe3de

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/libexpr-c/nix_api_value.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,12 @@ int64_t nix_get_int(nix_c_context * context, const nix_value * value)
330330
NIXC_CATCH_ERRS_RES(0);
331331
}
332332

333-
ExternalValue * nix_get_external(nix_c_context * context, nix_value * value)
333+
ExternalValue * nix_get_external(nix_c_context * context, const nix_value * value)
334334
{
335335
if (context)
336336
context->last_err_code = NIX_OK;
337337
try {
338-
auto & v = check_value_out(value);
338+
auto & v = check_value_in(value);
339339
assert(v.type() == nix::nExternal);
340340
return (ExternalValue *) v.external();
341341
}

src/libexpr-c/nix_api_value.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ int64_t nix_get_int(nix_c_context * context, const nix_value * value);
351351
* @return reference valid while value is valid. Call nix_gc_incref() if you need it to live longer, then only in that
352352
* case call nix_gc_decref() when done. NULL in case of error
353353
*/
354-
ExternalValue * nix_get_external(nix_c_context * context, nix_value * value);
354+
ExternalValue * nix_get_external(nix_c_context * context, const nix_value * value);
355355

356356
/** @brief Get the ix'th element of a list
357357
* @ingroup value_extract

0 commit comments

Comments
 (0)