mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-14 02:06:16 +02:00
nix_api_expr: remove bindingsbuilder refcounting
This commit is contained in:
parent
aa85f7d917
commit
022b918db1
3 changed files with 27 additions and 21 deletions
|
@ -4,7 +4,8 @@
|
||||||
// forward declaration
|
// forward declaration
|
||||||
namespace nix {
|
namespace nix {
|
||||||
class EvalState;
|
class EvalState;
|
||||||
};
|
class BindingsBuilder;
|
||||||
|
}; // namespace nix
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
nix::EvalState state;
|
nix::EvalState state;
|
||||||
|
@ -14,4 +15,8 @@ struct GCRef {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BindingsBuilder {
|
||||||
|
nix::BindingsBuilder builder;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // NIX_API_EXPR_INTERNAL_H
|
#endif // NIX_API_EXPR_INTERNAL_H
|
||||||
|
|
|
@ -386,16 +386,13 @@ nix_err nix_copy_value(nix_c_context *context, Value *value, Value *source) {
|
||||||
NIXC_CATCH_ERRS
|
NIXC_CATCH_ERRS
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::shared_ptr<nix::BindingsBuilder> BindingsBuilder_Inner;
|
|
||||||
|
|
||||||
nix_err nix_make_attrs(nix_c_context *context, Value *value,
|
nix_err nix_make_attrs(nix_c_context *context, Value *value,
|
||||||
BindingsBuilder *b) {
|
BindingsBuilder *b) {
|
||||||
if (context)
|
if (context)
|
||||||
context->last_err_code = NIX_OK;
|
context->last_err_code = NIX_OK;
|
||||||
try {
|
try {
|
||||||
auto &v = check_value_not_null(value);
|
auto &v = check_value_not_null(value);
|
||||||
nix::BindingsBuilder &builder = **(BindingsBuilder_Inner *)b;
|
v.mkAttrs(b->builder);
|
||||||
v.mkAttrs(builder);
|
|
||||||
}
|
}
|
||||||
NIXC_CATCH_ERRS
|
NIXC_CATCH_ERRS
|
||||||
}
|
}
|
||||||
|
@ -406,10 +403,11 @@ BindingsBuilder *nix_make_bindings_builder(nix_c_context *context, State *state,
|
||||||
context->last_err_code = NIX_OK;
|
context->last_err_code = NIX_OK;
|
||||||
try {
|
try {
|
||||||
auto bb = state->state.buildBindings(capacity);
|
auto bb = state->state.buildBindings(capacity);
|
||||||
auto res = new BindingsBuilder_Inner();
|
return new
|
||||||
*res = std::allocate_shared<nix::BindingsBuilder>(
|
#if HAVE_BOEHMGC
|
||||||
traceable_allocator<nix::BindingsBuilder>(), bb);
|
(NoGC)
|
||||||
return res;
|
#endif
|
||||||
|
BindingsBuilder{std::move(bb)};
|
||||||
}
|
}
|
||||||
NIXC_CATCH_ERRS_NULL
|
NIXC_CATCH_ERRS_NULL
|
||||||
}
|
}
|
||||||
|
@ -419,14 +417,17 @@ nix_err nix_bindings_builder_insert(nix_c_context *context, BindingsBuilder *b,
|
||||||
if (context)
|
if (context)
|
||||||
context->last_err_code = NIX_OK;
|
context->last_err_code = NIX_OK;
|
||||||
try {
|
try {
|
||||||
nix::BindingsBuilder &builder = **(BindingsBuilder_Inner *)b;
|
|
||||||
auto &v = check_value_not_null(value);
|
auto &v = check_value_not_null(value);
|
||||||
nix::Symbol s = builder.state.symbols.create(name);
|
nix::Symbol s = b->builder.state.symbols.create(name);
|
||||||
builder.insert(s, &v);
|
b->builder.insert(s, &v);
|
||||||
}
|
}
|
||||||
NIXC_CATCH_ERRS
|
NIXC_CATCH_ERRS
|
||||||
}
|
}
|
||||||
|
|
||||||
void nix_bindings_builder_unref(BindingsBuilder *bb) {
|
void nix_bindings_builder_free(BindingsBuilder *bb) {
|
||||||
delete (BindingsBuilder_Inner *)bb;
|
#if HAVE_BOEHMGC
|
||||||
|
GC_FREE((nix::BindingsBuilder *)bb);
|
||||||
|
#else
|
||||||
|
delete (nix::BindingsBuilder *)bb;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,12 @@ typedef struct State State;
|
||||||
typedef struct GCRef GCRef;
|
typedef struct GCRef GCRef;
|
||||||
// type defs
|
// type defs
|
||||||
/** @brief Stores an under-construction set of bindings
|
/** @brief Stores an under-construction set of bindings
|
||||||
* Reference-counted
|
*
|
||||||
* @see nix_make_bindings_builder, nix_bindings_builder_unref, nix_make_attrs
|
* Do not reuse.
|
||||||
|
* @see nix_make_bindings_builder, nix_bindings_builder_free, nix_make_attrs
|
||||||
* @see nix_bindings_builder_insert
|
* @see nix_bindings_builder_insert
|
||||||
*/
|
*/
|
||||||
typedef void BindingsBuilder;
|
typedef struct BindingsBuilder BindingsBuilder;
|
||||||
|
|
||||||
/** @brief PrimOp function
|
/** @brief PrimOp function
|
||||||
*
|
*
|
||||||
|
@ -328,13 +329,12 @@ BindingsBuilder *nix_make_bindings_builder(nix_c_context *context, State *state,
|
||||||
nix_err nix_bindings_builder_insert(nix_c_context *context,
|
nix_err nix_bindings_builder_insert(nix_c_context *context,
|
||||||
BindingsBuilder *builder, const char *name,
|
BindingsBuilder *builder, const char *name,
|
||||||
Value *value);
|
Value *value);
|
||||||
/** @brief Unref a bindings builder
|
/** @brief Free a bindings builder
|
||||||
*
|
*
|
||||||
* Does not fail.
|
* Does not fail.
|
||||||
* It'll be deallocated when all references are gone.
|
* @param[in] builder the builder to free
|
||||||
* @param[in] builder the builder to unref
|
|
||||||
*/
|
*/
|
||||||
void nix_bindings_builder_unref(BindingsBuilder *builder);
|
void nix_bindings_builder_free(BindingsBuilder *builder);
|
||||||
|
|
||||||
// cffi end
|
// cffi end
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Reference in a new issue