2023-07-14 09:53:30 -04:00
|
|
|
#include "attr-set.hh"
|
|
|
|
#include "config.hh"
|
|
|
|
#include "eval.hh"
|
|
|
|
#include "gc/gc.h"
|
|
|
|
#include "globals.hh"
|
2023-08-07 09:33:07 -04:00
|
|
|
#include "primops.hh"
|
2023-07-14 09:53:30 -04:00
|
|
|
#include "value.hh"
|
|
|
|
|
|
|
|
#include "nix_api_expr.h"
|
|
|
|
#include "nix_api_expr_internal.h"
|
|
|
|
#include "nix_api_util.h"
|
|
|
|
#include "nix_api_util_internal.h"
|
|
|
|
#include "nix_api_value.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_BOEHMGC
|
|
|
|
#define GC_INCLUDE_NEW 1
|
|
|
|
#include "gc_cpp.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Helper function to throw an exception if value is null
|
2023-08-28 10:45:02 -04:00
|
|
|
static const nix::Value & check_value_not_null(const Value * value)
|
|
|
|
{
|
|
|
|
if (!value) {
|
|
|
|
throw std::runtime_error("Value is null");
|
|
|
|
}
|
|
|
|
return *((const nix::Value *) value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static nix::Value & check_value_not_null(Value * value)
|
|
|
|
{
|
|
|
|
if (!value) {
|
|
|
|
throw std::runtime_error("Value is null");
|
|
|
|
}
|
|
|
|
return *((nix::Value *) value);
|
|
|
|
}
|
|
|
|
|
2023-08-28 12:20:52 -04:00
|
|
|
/**
|
|
|
|
* Helper function to convert calls from nix into C API.
|
|
|
|
*
|
|
|
|
* Deals with errors and converts arguments from C++ into C types.
|
|
|
|
*/
|
|
|
|
static void nix_c_primop_wrapper(
|
|
|
|
PrimOpFun f, void * userdata, nix::EvalState & state, const nix::PosIdx pos, nix::Value ** args, nix::Value & v)
|
|
|
|
{
|
2023-08-28 16:19:28 -04:00
|
|
|
nix_c_context ctx;
|
2024-01-10 05:58:35 -05:00
|
|
|
f(userdata, &ctx, (EvalState *) &state, (Value **) args, (Value *) &v);
|
2023-08-28 16:19:28 -04:00
|
|
|
/* TODO: In the future, this should throw different errors depending on the error code */
|
|
|
|
if (ctx.last_err_code != NIX_OK)
|
2024-02-24 18:26:36 -05:00
|
|
|
state.error<nix::EvalError>("Error from builtin function: %s", *ctx.last_err).atPos(pos).debugThrow();
|
2023-08-28 12:20:52 -04:00
|
|
|
}
|
|
|
|
|
2023-08-28 10:45:02 -04:00
|
|
|
PrimOp * nix_alloc_primop(
|
2023-08-28 12:20:52 -04:00
|
|
|
nix_c_context * context,
|
|
|
|
PrimOpFun fun,
|
|
|
|
int arity,
|
|
|
|
const char * name,
|
|
|
|
const char ** args,
|
|
|
|
const char * doc,
|
|
|
|
void * user_data)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
2023-08-28 17:17:43 -04:00
|
|
|
using namespace std::placeholders;
|
2023-08-28 10:45:02 -04:00
|
|
|
auto p = new
|
2023-07-14 09:53:30 -04:00
|
|
|
#ifdef HAVE_BOEHMGC
|
2023-08-28 10:45:02 -04:00
|
|
|
(GC)
|
2023-07-14 09:53:30 -04:00
|
|
|
#endif
|
2023-08-28 12:20:52 -04:00
|
|
|
nix::PrimOp{
|
|
|
|
.name = name,
|
|
|
|
.args = {},
|
|
|
|
.arity = (size_t) arity,
|
|
|
|
.doc = doc,
|
2023-08-28 17:17:43 -04:00
|
|
|
.fun = std::bind(nix_c_primop_wrapper, fun, user_data, _1, _2, _3, _4)};
|
2023-08-28 10:45:02 -04:00
|
|
|
if (args)
|
|
|
|
for (size_t i = 0; args[i]; i++)
|
|
|
|
p->args.emplace_back(*args);
|
|
|
|
nix_gc_incref(nullptr, p);
|
|
|
|
return (PrimOp *) p;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL
|
|
|
|
}
|
|
|
|
|
|
|
|
nix_err nix_register_primop(nix_c_context * context, PrimOp * primOp)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
nix::RegisterPrimOp r(std::move(*((nix::PrimOp *) primOp)));
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
2024-01-10 05:58:35 -05:00
|
|
|
Value * nix_alloc_value(nix_c_context * context, EvalState * state)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
Value * res = state->state.allocValue();
|
|
|
|
nix_gc_incref(nullptr, res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueType nix_get_type(nix_c_context * context, const Value * value)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
using namespace nix;
|
|
|
|
switch (v.type()) {
|
|
|
|
case nThunk:
|
|
|
|
return NIX_TYPE_THUNK;
|
|
|
|
case nInt:
|
|
|
|
return NIX_TYPE_INT;
|
|
|
|
case nFloat:
|
|
|
|
return NIX_TYPE_FLOAT;
|
|
|
|
case nBool:
|
|
|
|
return NIX_TYPE_BOOL;
|
|
|
|
case nString:
|
|
|
|
return NIX_TYPE_STRING;
|
|
|
|
case nPath:
|
|
|
|
return NIX_TYPE_PATH;
|
|
|
|
case nNull:
|
|
|
|
return NIX_TYPE_NULL;
|
|
|
|
case nAttrs:
|
|
|
|
return NIX_TYPE_ATTRS;
|
|
|
|
case nList:
|
|
|
|
return NIX_TYPE_LIST;
|
|
|
|
case nFunction:
|
|
|
|
return NIX_TYPE_FUNCTION;
|
|
|
|
case nExternal:
|
|
|
|
return NIX_TYPE_EXTERNAL;
|
|
|
|
}
|
|
|
|
return NIX_TYPE_NULL;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_RES(NIX_TYPE_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * nix_get_typename(nix_c_context * context, const Value * value)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
auto s = nix::showType(v);
|
|
|
|
return strdup(s.c_str());
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nix_get_bool(nix_c_context * context, const Value * value)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
assert(v.type() == nix::nBool);
|
|
|
|
return v.boolean;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_RES(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * nix_get_string(nix_c_context * context, const Value * value)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
assert(v.type() == nix::nString);
|
2023-11-28 09:05:04 -05:00
|
|
|
return v.c_str();
|
2023-08-28 10:45:02 -04:00
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * nix_get_path_string(nix_c_context * context, const Value * value)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
assert(v.type() == nix::nPath);
|
2023-12-06 09:54:23 -05:00
|
|
|
// NOTE (from @yorickvP)
|
|
|
|
// v._path.path should work but may not be how Eelco intended it.
|
|
|
|
// Long-term this function should be rewritten to copy some data into a
|
|
|
|
// user-allocated string.
|
|
|
|
// We could use v.path().to_string().c_str(), but I'm concerned this
|
|
|
|
// crashes. Looks like .path() allocates a CanonPath with a copy of the
|
|
|
|
// string, then it gets the underlying data from that.
|
|
|
|
return v._path.path;
|
2023-08-28 10:45:02 -04:00
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int nix_get_list_size(nix_c_context * context, const Value * value)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
assert(v.type() == nix::nList);
|
|
|
|
return v.listSize();
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_RES(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int nix_get_attrs_size(nix_c_context * context, const Value * value)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
assert(v.type() == nix::nAttrs);
|
|
|
|
return v.attrs->size();
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_RES(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
double nix_get_float(nix_c_context * context, const Value * value)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
assert(v.type() == nix::nFloat);
|
|
|
|
return v.fpoint;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_RES(NAN);
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t nix_get_int(nix_c_context * context, const Value * value)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
assert(v.type() == nix::nInt);
|
|
|
|
return v.integer;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_RES(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExternalValue * nix_get_external(nix_c_context * context, Value * value)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
assert(v.type() == nix::nExternal);
|
|
|
|
return (ExternalValue *) v.external;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL;
|
|
|
|
}
|
|
|
|
|
2024-01-10 05:58:35 -05:00
|
|
|
Value * nix_get_list_byidx(nix_c_context * context, const Value * value, EvalState * state, unsigned int ix)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
assert(v.type() == nix::nList);
|
|
|
|
auto * p = v.listElems()[ix];
|
|
|
|
nix_gc_incref(nullptr, p);
|
|
|
|
state->state.forceValue(*p, nix::noPos);
|
|
|
|
return (Value *) p;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL
|
|
|
|
}
|
|
|
|
|
2024-01-10 05:58:35 -05:00
|
|
|
Value * nix_get_attr_byname(nix_c_context * context, const Value * value, EvalState * state, const char * name)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
assert(v.type() == nix::nAttrs);
|
|
|
|
nix::Symbol s = state->state.symbols.create(name);
|
|
|
|
auto attr = v.attrs->get(s);
|
|
|
|
if (attr) {
|
|
|
|
nix_gc_incref(nullptr, attr->value);
|
|
|
|
state->state.forceValue(*attr->value, nix::noPos);
|
|
|
|
return attr->value;
|
|
|
|
}
|
|
|
|
nix_set_err_msg(context, NIX_ERR_KEY, "missing attribute");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL
|
|
|
|
}
|
|
|
|
|
2024-01-10 05:58:35 -05:00
|
|
|
bool nix_has_attr_byname(nix_c_context * context, const Value * value, EvalState * state, const char * name)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
assert(v.type() == nix::nAttrs);
|
|
|
|
nix::Symbol s = state->state.symbols.create(name);
|
|
|
|
auto attr = v.attrs->get(s);
|
|
|
|
if (attr)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_RES(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *
|
2024-01-10 05:58:35 -05:00
|
|
|
nix_get_attr_byidx(nix_c_context * context, const Value * value, EvalState * state, unsigned int i, const char ** name)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
const nix::Attr & a = (*v.attrs)[i];
|
|
|
|
*name = ((const std::string &) (state->state.symbols[a.name])).c_str();
|
|
|
|
nix_gc_incref(nullptr, a.value);
|
|
|
|
state->state.forceValue(*a.value, nix::noPos);
|
|
|
|
return a.value;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL
|
|
|
|
}
|
|
|
|
|
2024-01-10 05:58:35 -05:00
|
|
|
const char * nix_get_attr_name_byidx(nix_c_context * context, const Value * value, EvalState * state, unsigned int i)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
const nix::Attr & a = (*v.attrs)[i];
|
|
|
|
return ((const std::string &) (state->state.symbols[a.name])).c_str();
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL
|
|
|
|
}
|
|
|
|
|
2024-02-21 18:09:15 -05:00
|
|
|
nix_err nix_init_bool(nix_c_context * context, Value * value, bool b)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
v.mkBool(b);
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
2023-07-14 09:53:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// todo string context
|
2024-02-21 18:09:15 -05:00
|
|
|
nix_err nix_init_string(nix_c_context * context, Value * value, const char * str)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
v.mkString(std::string_view(str));
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
2024-02-25 15:21:05 -05:00
|
|
|
nix_err nix_init_path_string(nix_c_context * context, EvalState * s, Value * value, const char * str)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
2024-02-25 15:21:05 -05:00
|
|
|
v.mkPath(s->state.rootPath(nix::CanonPath(str)));
|
2023-08-28 10:45:02 -04:00
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
2024-02-21 18:09:15 -05:00
|
|
|
nix_err nix_init_float(nix_c_context * context, Value * value, double d)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
v.mkFloat(d);
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
2024-02-21 18:09:15 -05:00
|
|
|
nix_err nix_init_int(nix_c_context * context, Value * value, int64_t i)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
v.mkInt(i);
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
2024-02-21 18:09:15 -05:00
|
|
|
nix_err nix_init_null(nix_c_context * context, Value * value)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
v.mkNull();
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
2024-02-21 18:09:15 -05:00
|
|
|
nix_err nix_init_external(nix_c_context * context, Value * value, ExternalValue * val)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
auto r = (nix::ExternalValueBase *) val;
|
|
|
|
v.mkExternal(r);
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
2024-02-21 18:09:15 -05:00
|
|
|
ListBuilder * nix_make_list_builder(nix_c_context * context, EvalState * state, size_t capacity)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
2024-02-27 16:08:00 -05:00
|
|
|
auto builder = CListBuilder(capacity);
|
2024-02-21 18:09:15 -05:00
|
|
|
return new
|
|
|
|
#if HAVE_BOEHMGC
|
|
|
|
(NoGC)
|
|
|
|
#endif
|
|
|
|
ListBuilder{std::move(builder)};
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL
|
|
|
|
}
|
|
|
|
|
2024-02-27 16:08:00 -05:00
|
|
|
nix_err nix_list_builder_insert(nix_c_context * context, ListBuilder * list_builder, Value * value)
|
2024-02-21 18:09:15 -05:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
2024-02-27 16:08:00 -05:00
|
|
|
list_builder->builder.push_back((nix::Value *) value);
|
2023-08-28 10:45:02 -04:00
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
2024-02-21 18:09:15 -05:00
|
|
|
void nix_list_builder_free(ListBuilder * bb)
|
|
|
|
{
|
|
|
|
#if HAVE_BOEHMGC
|
|
|
|
GC_FREE(bb);
|
|
|
|
#else
|
|
|
|
delete bb;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2024-02-27 16:08:00 -05:00
|
|
|
nix_err nix_make_list(nix_c_context * context, EvalState * s, ListBuilder * list_builder, Value * value)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
2024-02-27 16:08:00 -05:00
|
|
|
list_builder->builder.finish(&(s->state), &v);
|
2023-08-28 10:45:02 -04:00
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
2024-02-21 18:09:15 -05:00
|
|
|
nix_err nix_init_primop(nix_c_context * context, Value * value, PrimOp * p)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
v.mkPrimOp((nix::PrimOp *) p);
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
|
|
|
nix_err nix_copy_value(nix_c_context * context, Value * value, Value * source)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
auto & s = check_value_not_null(source);
|
|
|
|
v = s;
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
|
|
|
nix_err nix_make_attrs(nix_c_context * context, Value * value, BindingsBuilder * b)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
|
|
|
v.mkAttrs(b->builder);
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
|
|
|
}
|
|
|
|
|
2024-01-10 05:58:35 -05:00
|
|
|
BindingsBuilder * nix_make_bindings_builder(nix_c_context * context, EvalState * state, size_t capacity)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto bb = state->state.buildBindings(capacity);
|
|
|
|
return new
|
2023-07-27 09:58:18 -04:00
|
|
|
#if HAVE_BOEHMGC
|
2023-08-28 10:45:02 -04:00
|
|
|
(NoGC)
|
2023-07-27 09:58:18 -04:00
|
|
|
#endif
|
2023-08-28 10:45:02 -04:00
|
|
|
BindingsBuilder{std::move(bb)};
|
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS_NULL
|
2023-07-14 09:53:30 -04:00
|
|
|
}
|
|
|
|
|
2024-02-21 18:09:15 -05:00
|
|
|
nix_err nix_bindings_builder_insert(nix_c_context * context, BindingsBuilder * bb, const char * name, Value * value)
|
2023-08-28 10:45:02 -04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
context->last_err_code = NIX_OK;
|
|
|
|
try {
|
|
|
|
auto & v = check_value_not_null(value);
|
2024-02-21 18:09:15 -05:00
|
|
|
nix::Symbol s = bb->builder.state.symbols.create(name);
|
|
|
|
bb->builder.insert(s, &v);
|
2023-08-28 10:45:02 -04:00
|
|
|
}
|
|
|
|
NIXC_CATCH_ERRS
|
2023-07-14 09:53:30 -04:00
|
|
|
}
|
|
|
|
|
2023-08-28 10:45:02 -04:00
|
|
|
void nix_bindings_builder_free(BindingsBuilder * bb)
|
|
|
|
{
|
2023-07-27 09:58:18 -04:00
|
|
|
#if HAVE_BOEHMGC
|
2023-08-28 10:45:02 -04:00
|
|
|
GC_FREE((nix::BindingsBuilder *) bb);
|
2023-07-27 09:58:18 -04:00
|
|
|
#else
|
2023-08-28 10:45:02 -04:00
|
|
|
delete (nix::BindingsBuilder *) bb;
|
2023-07-27 09:58:18 -04:00
|
|
|
#endif
|
2023-07-14 09:53:30 -04:00
|
|
|
}
|