diff options
author | Kane York <kanepyork@gmail.com> | 2020-08-10T05·42-0700 |
---|---|---|
committer | kanepyork <rikingcoding@gmail.com> | 2020-08-10T22·16+0000 |
commit | 906f5c1d2d442b1d34621b97950c38c659b729a6 (patch) | |
tree | 48b663ee52e56f8471539afece70de67a0144622 /third_party/nix/src/libexpr/parser.y | |
parent | 42bdaacca62ad5760e5d46315f1e6dc2bcc3fd96 (diff) |
fix(3p/nix): inherit Expr from gc, make parser state traceable r/1633
The parser contained vectors, and the primary parser state, that were not participating in GC tracing. Change-Id: Ie198592cd7acffd390e3e2ae9595138b56416838 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1706 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in> Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/src/libexpr/parser.y')
-rw-r--r-- | third_party/nix/src/libexpr/parser.y | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/third_party/nix/src/libexpr/parser.y b/third_party/nix/src/libexpr/parser.y index 999872148895..b47d96b1e10b 100644 --- a/third_party/nix/src/libexpr/parser.y +++ b/third_party/nix/src/libexpr/parser.y @@ -14,6 +14,29 @@ %code requires { #define YY_NO_INPUT 1 // disable unused yyinput features #include "libexpr/parser.hh" + +// Allow GC tracing of YY-allocated structures +#define YYMALLOC GC_MALLOC_UNCOLLECTABLE +#define YYFREE GC_FREE +#define YYREALLOC GC_REALLOC + +struct YYSTYPE : public gc { + union { + nix::Expr * e; + nix::ExprList * list; + nix::ExprAttrs * attrs; + nix::Formals * formals; + nix::Formal * formal; + nix::NixInt n; + nix::NixFloat nf; + const char * id; // !!! -> Symbol + char * path; + char * uri; + nix::AttrNameVector * attrNames; + nix::VectorExprs * string_parts; + }; +}; + } %{ @@ -40,22 +63,6 @@ void yyerror(YYLTYPE* loc, yyscan_t scanner, ParseData* data, %} -%union { - // !!! We're probably leaking stuff here. - nix::Expr * e; - nix::ExprList * list; - nix::ExprAttrs * attrs; - nix::Formals * formals; - nix::Formal * formal; - nix::NixInt n; - nix::NixFloat nf; - const char * id; // !!! -> Symbol - char * path; - char * uri; - std::vector<nix::AttrName> * attrNames; - std::vector<nix::Expr *> * string_parts; -} - %type <e> start expr expr_function expr_if expr_op %type <e> expr_app expr_select expr_simple %type <list> expr_list @@ -138,7 +145,7 @@ expr_op | expr_op UPDATE expr_op { $$ = new ExprOpUpdate(CUR_POS, $1, $3); } | expr_op '?' attrpath { $$ = new ExprOpHasAttr($1, *$3); } | expr_op '+' expr_op - { $$ = new ExprConcatStrings(CUR_POS, false, new std::vector<Expr *>({$1, $3})); } + { $$ = new ExprConcatStrings(CUR_POS, false, new nix::VectorExprs({$1, $3})); } | expr_op '-' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__sub")), $1), $3); } | expr_op '*' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__mul")), $1), $3); } | expr_op '/' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__div")), $1), $3); } @@ -208,9 +215,9 @@ string_parts string_parts_interpolated : string_parts_interpolated STR { $$ = $1; $1->push_back($2); } | string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = $1; $1->push_back($3); } - | DOLLAR_CURLY expr '}' { $$ = new std::vector<Expr *>; $$->push_back($2); } + | DOLLAR_CURLY expr '}' { $$ = new nix::VectorExprs; $$->push_back($2); } | STR DOLLAR_CURLY expr '}' { - $$ = new std::vector<Expr *>; + $$ = new nix::VectorExprs; $$->push_back($1); $$->push_back($3); } @@ -219,7 +226,7 @@ string_parts_interpolated ind_string_parts : ind_string_parts IND_STR { $$ = $1; $1->push_back($2); } | ind_string_parts DOLLAR_CURLY expr '}' { $$ = $1; $1->push_back($3); } - | { $$ = new std::vector<Expr *>; } + | { $$ = new nix::VectorExprs; } ; binds @@ -276,9 +283,9 @@ attrpath $$->push_back(AttrName($3)); } } - | attr { $$ = new std::vector<AttrName>; $$->push_back(AttrName(data->symbols.Create($1))); } + | attr { $$ = new nix::AttrNameVector; $$->push_back(AttrName(data->symbols.Create($1))); } | string_attr - { $$ = new std::vector<AttrName>; + { $$ = new nix::AttrNameVector; ExprString *str = dynamic_cast<ExprString *>($1); if (str) { $$->push_back(AttrName(str->s)); |