refactor(3p/nix/libexpr): Store nix::Env values in a std::vector
This has several advantages: * we can ensure that the vector is traced by the GC * we don't need to unsafely allocate memory to make an Env Note that there was previously a check about the size of the environment, but it's unclear why this was the case (git history yielded nothing interesting) and it seems to have no effect. Change-Id: I4998b879a728a6fb68e1bd187c521e2304e5047e Reviewed-on: https://cl.tvl.fyi/c/depot/+/1265 Tested-by: BuildkiteCI Reviewed-by: isomer <isomer@tvl.fyi> Reviewed-by: Kane York <rikingcoding@gmail.com> Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
parent
effbb277c3
commit
56614c75e4
2 changed files with 11 additions and 9 deletions
12
third_party/nix/src/libexpr/eval.hh
vendored
12
third_party/nix/src/libexpr/eval.hh
vendored
|
|
@ -3,6 +3,10 @@
|
|||
#include <map>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <gc/gc_allocator.h>
|
||||
#include <gc/gc_cpp.h>
|
||||
|
||||
#include "libexpr/attr-set.hh"
|
||||
#include "libexpr/nixexpr.hh"
|
||||
|
|
@ -28,12 +32,16 @@ struct PrimOp {
|
|||
: fun(fun), arity(arity), name(name) {}
|
||||
};
|
||||
|
||||
struct Env {
|
||||
struct Env : public gc {
|
||||
Env(unsigned short size) : size(size) {
|
||||
values = std::vector<Value*, traceable_allocator<Value*>>(size);
|
||||
}
|
||||
|
||||
Env* up;
|
||||
unsigned short size; // used by ‘valueSize’
|
||||
unsigned short prevWith : 14; // nr of levels up to next `with' environment
|
||||
enum { Plain = 0, HasWithExpr, HasWithAttrs } type : 2;
|
||||
Value* values[0];
|
||||
std::vector<Value*, traceable_allocator<Value*>> values;
|
||||
};
|
||||
|
||||
Value& mkString(Value& v, const std::string& s,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue