Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/libexpr-c/nix_api_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ const char * nix_get_attr_name_byidx(nix_c_context * context, nix_value * value,
NIXC_CATCH_ERRS_NULL
}

nix_err nix_init_bool(nix_c_context * context, nix_value * value, bool b)
nix_err nix_init_bool(nix_c_context * context, EvalState * state, nix_value * value, bool b)
{
if (context)
context->last_err_code = NIX_OK;
Expand All @@ -497,7 +497,7 @@ nix_err nix_init_bool(nix_c_context * context, nix_value * value, bool b)
}

// todo string context
nix_err nix_init_string(nix_c_context * context, nix_value * value, const char * str)
nix_err nix_init_string(nix_c_context * context, EvalState * state, nix_value * value, const char * str)
{
if (context)
context->last_err_code = NIX_OK;
Expand All @@ -508,18 +508,18 @@ nix_err nix_init_string(nix_c_context * context, nix_value * value, const char *
NIXC_CATCH_ERRS
}

nix_err nix_init_path_string(nix_c_context * context, EvalState * s, nix_value * value, const char * str)
nix_err nix_init_path_string(nix_c_context * context, EvalState * state, nix_value * value, const char * str)
{
if (context)
context->last_err_code = NIX_OK;
try {
auto & v = check_value_out(value);
v.mkPath(s->state.rootPath(nix::CanonPath(str)));
v.mkPath(state->state.rootPath(nix::CanonPath(str)));
}
NIXC_CATCH_ERRS
}

nix_err nix_init_float(nix_c_context * context, nix_value * value, double d)
nix_err nix_init_float(nix_c_context * context, EvalState * state, nix_value * value, double d)
{
if (context)
context->last_err_code = NIX_OK;
Expand All @@ -530,7 +530,7 @@ nix_err nix_init_float(nix_c_context * context, nix_value * value, double d)
NIXC_CATCH_ERRS
}

nix_err nix_init_int(nix_c_context * context, nix_value * value, int64_t i)
nix_err nix_init_int(nix_c_context * context, EvalState * state, nix_value * value, int64_t i)
{
if (context)
context->last_err_code = NIX_OK;
Expand All @@ -541,7 +541,7 @@ nix_err nix_init_int(nix_c_context * context, nix_value * value, int64_t i)
NIXC_CATCH_ERRS
}

nix_err nix_init_null(nix_c_context * context, nix_value * value)
nix_err nix_init_null(nix_c_context * context, EvalState * state, nix_value * value)
{
if (context)
context->last_err_code = NIX_OK;
Expand All @@ -552,7 +552,7 @@ nix_err nix_init_null(nix_c_context * context, nix_value * value)
NIXC_CATCH_ERRS
}

nix_err nix_init_apply(nix_c_context * context, nix_value * value, nix_value * fn, nix_value * arg)
nix_err nix_init_apply(nix_c_context * context, EvalState * state, nix_value * value, nix_value * fn, nix_value * arg)
{
if (context)
context->last_err_code = NIX_OK;
Expand All @@ -565,7 +565,7 @@ nix_err nix_init_apply(nix_c_context * context, nix_value * value, nix_value * f
NIXC_CATCH_ERRS
}

nix_err nix_init_external(nix_c_context * context, nix_value * value, ExternalValue * val)
nix_err nix_init_external(nix_c_context * context, EvalState * state, nix_value * value, ExternalValue * val)
{
if (context)
context->last_err_code = NIX_OK;
Expand Down Expand Up @@ -624,7 +624,7 @@ nix_err nix_make_list(nix_c_context * context, ListBuilder * list_builder, nix_v
NIXC_CATCH_ERRS
}

nix_err nix_init_primop(nix_c_context * context, nix_value * value, PrimOp * p)
nix_err nix_init_primop(nix_c_context * context, EvalState * state, nix_value * value, PrimOp * p)
{
if (context)
context->last_err_code = NIX_OK;
Expand Down
26 changes: 17 additions & 9 deletions src/libexpr-c/nix_api_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,55 +507,61 @@ const char * nix_get_attr_name_byidx(nix_c_context * context, nix_value * value,
/** @brief Set boolean value
* @ingroup value_create
* @param[out] context Optional, stores error information
* @param[in] state nix evaluator state
* @param[out] value Nix value to modify
* @param[in] b the boolean value
* @return error code, NIX_OK on success.
*/
nix_err nix_init_bool(nix_c_context * context, nix_value * value, bool b);
nix_err nix_init_bool(nix_c_context * context, EvalState * state, nix_value * value, bool b);

/** @brief Set a string
* @ingroup value_create
* @param[out] context Optional, stores error information
* @param[in] state nix evaluator state
* @param[out] value Nix value to modify
* @param[in] str the string, copied
* @return error code, NIX_OK on success.
*/
nix_err nix_init_string(nix_c_context * context, nix_value * value, const char * str);
nix_err nix_init_string(nix_c_context * context, EvalState * state, nix_value * value, const char * str);

/** @brief Set a path
* @ingroup value_create
* @param[out] context Optional, stores error information
* @param[in] state nix evaluator state
* @param[out] value Nix value to modify
* @param[in] str the path string, copied
* @return error code, NIX_OK on success.
*/
nix_err nix_init_path_string(nix_c_context * context, EvalState * s, nix_value * value, const char * str);
nix_err nix_init_path_string(nix_c_context * context, EvalState * state, nix_value * value, const char * str);

/** @brief Set a float
* @ingroup value_create
* @param[out] context Optional, stores error information
* @param[in] state nix evaluator state
* @param[out] value Nix value to modify
* @param[in] d the float, 64-bits
* @return error code, NIX_OK on success.
*/
nix_err nix_init_float(nix_c_context * context, nix_value * value, double d);
nix_err nix_init_float(nix_c_context * context, EvalState * state, nix_value * value, double d);

/** @brief Set an int
* @ingroup value_create
* @param[out] context Optional, stores error information
* @param[in] state nix evaluator state
* @param[out] value Nix value to modify
* @param[in] i the int
* @return error code, NIX_OK on success.
*/

nix_err nix_init_int(nix_c_context * context, nix_value * value, int64_t i);
nix_err nix_init_int(nix_c_context * context, EvalState * state, nix_value * value, int64_t i);
/** @brief Set null
* @ingroup value_create
* @param[out] context Optional, stores error information
* @param[in] state nix evaluator state
* @param[out] value Nix value to modify
* @return error code, NIX_OK on success.
*/
nix_err nix_init_null(nix_c_context * context, nix_value * value);
nix_err nix_init_null(nix_c_context * context, EvalState * state, nix_value * value);

/** @brief Set the value to a thunk that will perform a function application when needed.
* @ingroup value_create
Expand All @@ -565,23 +571,25 @@ nix_err nix_init_null(nix_c_context * context, nix_value * value);
* In such cases, you may use nix_value_call() instead (but note the different argument order).
*
* @param[out] context Optional, stores error information
* @param[in] state nix evaluator state
* @param[out] value Nix value to modify
* @param[in] fn function to call
* @param[in] arg argument to pass
* @return error code, NIX_OK on successful initialization.
* @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, nix_value * value, nix_value * fn, nix_value * arg);
nix_err nix_init_apply(nix_c_context * context, EvalState * state, nix_value * value, nix_value * fn, nix_value * arg);

/** @brief Set an external value
* @ingroup value_create
* @param[out] context Optional, stores error information
* @param[in] state nix evaluator state
* @param[out] value Nix value to modify
* @param[in] val the external value to set. Will be GC-referenced by the value.
* @return error code, NIX_OK on success.
*/
nix_err nix_init_external(nix_c_context * context, nix_value * value, ExternalValue * val);
nix_err nix_init_external(nix_c_context * context, EvalState * state, nix_value * value, ExternalValue * val);

/** @brief Create a list from a list builder
* @ingroup value_create
Expand Down Expand Up @@ -645,7 +653,7 @@ nix_err nix_make_attrs(nix_c_context * context, nix_value * value, BindingsBuild
* @see nix_alloc_primop
* @return error code, NIX_OK on success.
*/
nix_err nix_init_primop(nix_c_context * context, nix_value * value, PrimOp * op);
nix_err nix_init_primop(nix_c_context * context, EvalState * s, nix_value * value, PrimOp * op);
/** @brief Copy from another value
* @ingroup value_create
* @param[out] context Optional, stores error information
Expand Down
36 changes: 18 additions & 18 deletions src/libexpr-tests/nix_api_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ primop_square(void * user_data, nix_c_context * context, EvalState * state, nix_
assert(state);
assert(user_data == SAMPLE_USER_DATA);
auto i = nix_get_int(context, args[0]);
nix_init_int(context, ret, i * i);
nix_init_int(context, state, ret, i * i);
}

TEST_F(nix_api_expr_test, nix_expr_primop)
Expand All @@ -251,12 +251,12 @@ TEST_F(nix_api_expr_test, nix_expr_primop)
assert_ctx_ok();
nix_value * primopValue = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_primop(ctx, primopValue, primop);
nix_init_primop(ctx, state, primopValue, primop);
assert_ctx_ok();

nix_value * three = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_int(ctx, three, 3);
nix_init_int(ctx, state, three, 3);
assert_ctx_ok();

nix_value * result = nix_alloc_value(ctx, state);
Expand Down Expand Up @@ -290,7 +290,7 @@ primop_repeat(void * user_data, nix_c_context * context, EvalState * state, nix_
for (int i = 0; i < n; ++i)
result += s;

nix_init_string(context, ret, result.c_str());
nix_init_string(context, state, ret, result.c_str());
}

TEST_F(nix_api_expr_test, nix_expr_primop_arity_2_multiple_calls)
Expand All @@ -300,17 +300,17 @@ TEST_F(nix_api_expr_test, nix_expr_primop_arity_2_multiple_calls)
assert_ctx_ok();
nix_value * primopValue = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_primop(ctx, primopValue, primop);
nix_init_primop(ctx, state, primopValue, primop);
assert_ctx_ok();

nix_value * hello = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_string(ctx, hello, "hello");
nix_init_string(ctx, state, hello, "hello");
assert_ctx_ok();

nix_value * three = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_int(ctx, three, 3);
nix_init_int(ctx, state, three, 3);
assert_ctx_ok();

nix_value * partial = nix_alloc_value(ctx, state);
Expand All @@ -335,17 +335,17 @@ TEST_F(nix_api_expr_test, nix_expr_primop_arity_2_single_call)
assert_ctx_ok();
nix_value * primopValue = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_primop(ctx, primopValue, primop);
nix_init_primop(ctx, state, primopValue, primop);
assert_ctx_ok();

nix_value * hello = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_string(ctx, hello, "hello");
nix_init_string(ctx, state, hello, "hello");
assert_ctx_ok();

nix_value * three = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_int(ctx, three, 3);
nix_init_int(ctx, state, three, 3);
assert_ctx_ok();

nix_value * result = nix_alloc_value(ctx, state);
Expand All @@ -372,12 +372,12 @@ TEST_F(nix_api_expr_test, nix_expr_primop_bad_no_return)
assert_ctx_ok();
nix_value * primopValue = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_primop(ctx, primopValue, primop);
nix_init_primop(ctx, state, primopValue, primop);
assert_ctx_ok();

nix_value * three = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_int(ctx, three, 3);
nix_init_int(ctx, state, three, 3);
assert_ctx_ok();

nix_value * result = nix_alloc_value(ctx, state);
Expand All @@ -393,7 +393,7 @@ TEST_F(nix_api_expr_test, nix_expr_primop_bad_no_return)
static void primop_bad_return_thunk(
void * user_data, nix_c_context * context, EvalState * state, nix_value ** args, nix_value * ret)
{
nix_init_apply(context, ret, args[0], args[1]);
nix_init_apply(context, state, ret, args[0], args[1]);
}

TEST_F(nix_api_expr_test, nix_expr_primop_bad_return_thunk)
Expand All @@ -403,7 +403,7 @@ TEST_F(nix_api_expr_test, nix_expr_primop_bad_return_thunk)
assert_ctx_ok();
nix_value * primopValue = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_primop(ctx, primopValue, primop);
nix_init_primop(ctx, state, primopValue, primop);
assert_ctx_ok();

nix_value * toString = nix_alloc_value(ctx, state);
Expand All @@ -413,7 +413,7 @@ TEST_F(nix_api_expr_test, nix_expr_primop_bad_return_thunk)

nix_value * four = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_int(ctx, four, 4);
nix_init_int(ctx, state, four, 4);
assert_ctx_ok();

nix_value * result = nix_alloc_value(ctx, state);
Expand Down Expand Up @@ -452,12 +452,12 @@ TEST_F(nix_api_expr_test, nix_expr_primop_nix_err_key_conversion)
assert_ctx_ok();
nix_value * primopValue = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_primop(ctx, primopValue, primop);
nix_init_primop(ctx, state, primopValue, primop);
assert_ctx_ok();

nix_value * arg = nix_alloc_value(ctx, state);
assert_ctx_ok();
nix_init_int(ctx, arg, 42);
nix_init_int(ctx, state, arg, 42);
assert_ctx_ok();

nix_value * result = nix_alloc_value(ctx, state);
Expand All @@ -479,7 +479,7 @@ TEST_F(nix_api_expr_test, nix_expr_primop_nix_err_key_conversion)
TEST_F(nix_api_expr_test, nix_value_call_multi_no_args)
{
nix_value * n = nix_alloc_value(ctx, state);
nix_init_int(ctx, n, 3);
nix_init_int(ctx, state, n, 3);
assert_ctx_ok();

nix_value * r = nix_alloc_value(ctx, state);
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr-tests/nix_api_external.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TEST_F(nix_api_expr_test, nix_expr_eval_external)
{
MyExternalValueDesc * external = new MyExternalValueDesc(42);
ExternalValue * val = nix_create_external_value(ctx, external, external);
nix_init_external(ctx, value, val);
nix_init_external(ctx, state, value, val);

EvalState * stateResult = nix_state_create(nullptr, nullptr, store);
nix_value * valueResult = nix_alloc_value(nullptr, stateResult);
Expand Down
Loading
Loading