Skip to content

Commit 6b071af

Browse files
authored
Merge pull request #16407 from noib3/fix/c-api-null-primop-doc
libexpr-c: allow null primop docs
2 parents 5438b85 + 53440e1 commit 6b071af

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/libexpr-c/nix_api_value.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ PrimOp * nix_alloc_primop(
121121
.name = name,
122122
.args = {},
123123
.arity = (size_t) arity,
124-
.doc = doc,
124+
.doc = doc ? std::optional<std::string>{doc} : std::nullopt,
125125
.impl = std::bind(nix_c_primop_wrapper, fun, user_data, arity, _1, _2, _3, _4)};
126126
if (args)
127127
for (size_t i = 0; args[i]; i++)

src/libexpr-tests/nix_api_expr.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@ primop_square(void * user_data, nix_c_context * context, EvalState * state, nix_
299299
nix_init_int(context, ret, i * i);
300300
}
301301

302+
TEST_F(nix_api_expr_test, nix_alloc_primop_without_doc)
303+
{
304+
PrimOp * primop = nix_alloc_primop(ctx, primop_square, 1, "undocumented", nullptr, nullptr, nullptr);
305+
assert_ctx_ok();
306+
ASSERT_NE(nullptr, primop);
307+
308+
nix_gc_decref(ctx, primop);
309+
assert_ctx_ok();
310+
}
311+
302312
TEST_F(nix_api_expr_test, nix_expr_primop)
303313
{
304314
PrimOp * primop = nix_alloc_primop(

0 commit comments

Comments
 (0)