Skip to content

Commit 6ccfe3b

Browse files
committed
libexpr: allocate ExprOpHasAttr's AttrPath in Exprs::alloc
1 parent 8d7a164 commit 6ccfe3b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/libexpr/include/nix/expr/nixexpr.hh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,16 @@ struct ExprSelect : Expr
342342
struct ExprOpHasAttr : Expr
343343
{
344344
Expr * e;
345-
AttrPath attrPath;
346-
ExprOpHasAttr(Expr * e, AttrPath attrPath)
345+
std::span<AttrName> attrPath;
346+
347+
ExprOpHasAttr(std::pmr::polymorphic_allocator<char> alloc, Expr * e, std::vector<AttrName> attrPath)
347348
: e(e)
348-
, attrPath(std::move(attrPath)) {};
349+
{
350+
auto nAttrPath = attrPath.size();
351+
auto attrPathStart = (AttrName *) alloc.allocate(nAttrPath * sizeof(AttrName));
352+
memcpy(attrPathStart, attrPath.data(), nAttrPath * sizeof(AttrName));
353+
this->attrPath = {attrPathStart, nAttrPath};
354+
};
349355

350356
PosIdx getPos() const override
351357
{

src/libexpr/parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ expr_op
261261
| expr_op OR expr_op { $$ = new ExprOpOr(state->at(@2), $1, $3); }
262262
| expr_op IMPL expr_op { $$ = new ExprOpImpl(state->at(@2), $1, $3); }
263263
| expr_op UPDATE expr_op { $$ = new ExprOpUpdate(state->at(@2), $1, $3); }
264-
| expr_op '?' attrpath { $$ = new ExprOpHasAttr($1, std::move(*$3)); delete $3; }
264+
| expr_op '?' attrpath { $$ = new ExprOpHasAttr(state->alloc, $1, std::move(*$3)); delete $3; }
265265
| expr_op '+' expr_op
266266
{ $$ = new ExprConcatStrings(state->at(@2), false, new std::vector<std::pair<PosIdx, Expr *> >({{state->at(@1), $1}, {state->at(@3), $3}})); }
267267
| expr_op '-' expr_op { $$ = new ExprCall(state->at(@2), new ExprVar(state->s.sub), {$1, $3}); }

0 commit comments

Comments
 (0)