util: Use an opaque type for linear context
authorCaio Oliveira <caio.oliveira@intel.com>
Mon, 18 Sep 2023 08:51:13 +0000 (01:51 -0700)
committerMarge Bot <emma+marge@anholt.net>
Mon, 25 Sep 2023 17:26:17 +0000 (17:26 +0000)
In the linear allocation only the parent (context) can be used
to allocate new children, so let's use an opaque type to identify
the linear context.  This is similar to what's done in GC allocator.

Update the documentation and a couple of function names to
refer to linear context instead of linear parent.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25280>

17 files changed:
src/compiler/glsl/ast_type.cpp
src/compiler/glsl/glcpp/glcpp-lex.l
src/compiler/glsl/glcpp/glcpp-parse.y
src/compiler/glsl/glcpp/glcpp.h
src/compiler/glsl/glsl_lexer.ll
src/compiler/glsl/glsl_parser.yy
src/compiler/glsl/glsl_parser_extras.cpp
src/compiler/glsl/glsl_parser_extras.h
src/compiler/glsl/glsl_symbol_table.cpp
src/compiler/glsl/glsl_symbol_table.h
src/compiler/glsl/opt_dead_code_local.cpp
src/compiler/glsl_types.cpp
src/compiler/nir/nir_opt_combine_stores.c
src/compiler/nir/nir_opt_copy_prop_vars.c
src/compiler/nir/tests/vars_tests.cpp
src/util/ralloc.c
src/util/ralloc.h

index ec287dad9e440a15f74a1df381dbb760b820490b..6abccc4d164803205e0c8b7a6f42992719f1590c 100644 (file)
@@ -692,7 +692,7 @@ ast_type_qualifier::merge_into_in_qualifier(YYLTYPE *loc,
                                             ast_node* &node)
 {
    bool r = true;
-   void *lin_ctx = state->linalloc;
+   linear_ctx *lin_ctx = state->linalloc;
 
    /* We create the gs_input_layout node before merging so, in the future, no
     * more repeated nodes will be created as we will have the flag set.
index e07739b657c32d5a8e85492730e6b7420e427e92..9f103e5e2bee688ea7dc462a8a0cab0021c41cda 100644 (file)
@@ -105,7 +105,7 @@ void glcpp_set_column (int  column_no , yyscan_t yyscanner);
                         * an implicit call on strlen() for the length  \
                         * of the string, as this is already found by   \
                         * flex and stored in yyleng */                 \
-                       void *mem_ctx = yyextra->linalloc;              \
+                       linear_ctx *mem_ctx = yyextra->linalloc;        \
                        yylval->str = linear_alloc_child(mem_ctx,       \
                                                         yyleng + 1);   \
                        memcpy(yylval->str, yytext, yyleng + 1);        \
index 15dcc146bc3d76e8fe34ee7eecb665ef77bac1b1..68308ea6dafb1310c90aa281f042a6e33da5df47 100644 (file)
@@ -1497,7 +1497,7 @@ glcpp_parser_create(struct gl_context *gl_ctx,
    glcpp_lex_init_extra (parser, &parser->scanner);
    parser->defines = _mesa_hash_table_create(NULL, _mesa_hash_string,
                                              _mesa_key_string_equal);
-   parser->linalloc = linear_alloc_parent(parser);
+   parser->linalloc = linear_context(parser);
    parser->active = NULL;
    parser->lexing_directive = 0;
    parser->lexing_version_directive = 0;
index d1d22274f2918cfee6aeb8b60629c3e6f823786e..7f55cd7897b43ee7cac816a358ebceaf27880b7e 100644 (file)
@@ -187,7 +187,7 @@ typedef void (*glcpp_extension_iterator)(
                bool es);
 
 struct glcpp_parser {
-       void *linalloc;
+       linear_ctx *linalloc;
        yyscan_t scanner;
        struct hash_table *defines;
        active_list_t *active;
index ad109b3d112d98ae4e52436245a865759c36fb62..81667b2d2941010ea89ad55f04bd0ae05b0a3f5c 100644 (file)
@@ -308,7 +308,7 @@ PATH                ["][./ _A-Za-z0-9]*["]
 
                                    char *end = strrchr(ptr, '"');
                                    int path_len = (end - ptr) + 1;
-                                   void *mem_ctx = yyextra->linalloc;
+                                   linear_ctx *mem_ctx = yyextra->linalloc;
                                    yylloc->path = (char *) linear_alloc_child(mem_ctx, path_len);
                                    memcpy(yylloc->path, ptr, path_len);
                                    yylloc->path[path_len - 1] = '\0';
@@ -376,7 +376,7 @@ PATH                ["][./ _A-Za-z0-9]*["]
                                    * on strlen() for the length of the string, as this is already
                                    * found by flex and stored in yyleng
                                    */
-                                    void *mem_ctx = yyextra->linalloc;
+                                    linear_ctx *mem_ctx = yyextra->linalloc;
                                     char *id = (char *) linear_alloc_child(mem_ctx, yyleng + 1);
                                     memcpy(id, yytext, yyleng + 1);
                                     yylval->identifier = id;
index e1dc7a99a8c298e3b828eefefb789b5a1ce9509b..77e7a9b01c6302d9173be7cb37ab3ac1913b3dfd 100644 (file)
@@ -364,12 +364,12 @@ pragma_statement:
    }
    | PRAGMA_WARNING_ON EOL
    {
-      void *mem_ctx = state->linalloc;
+      linear_ctx *mem_ctx = state->linalloc;
       $$ = new(mem_ctx) ast_warnings_toggle(true);
    }
    | PRAGMA_WARNING_OFF EOL
    {
-      void *mem_ctx = state->linalloc;
+      linear_ctx *mem_ctx = state->linalloc;
       $$ = new(mem_ctx) ast_warnings_toggle(false);
    }
    ;
@@ -429,56 +429,56 @@ variable_identifier:
 primary_expression:
    variable_identifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
       $$->set_location(@1);
       $$->primary_expression.identifier = $1;
    }
    | INTCONSTANT
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
       $$->set_location(@1);
       $$->primary_expression.int_constant = $1;
    }
    | UINTCONSTANT
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
       $$->set_location(@1);
       $$->primary_expression.uint_constant = $1;
    }
    | INT64CONSTANT
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_int64_constant, NULL, NULL, NULL);
       $$->set_location(@1);
       $$->primary_expression.int64_constant = $1;
    }
    | UINT64CONSTANT
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_uint64_constant, NULL, NULL, NULL);
       $$->set_location(@1);
       $$->primary_expression.uint64_constant = $1;
    }
    | FLOATCONSTANT
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
       $$->set_location(@1);
       $$->primary_expression.float_constant = $1;
    }
    | DOUBLECONSTANT
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
       $$->set_location(@1);
       $$->primary_expression.double_constant = $1;
    }
    | BOOLCONSTANT
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
       $$->set_location(@1);
       $$->primary_expression.bool_constant = $1;
@@ -493,7 +493,7 @@ postfix_expression:
    primary_expression
    | postfix_expression '[' integer_expression ']'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
       $$->set_location_range(@1, @4);
    }
@@ -503,20 +503,20 @@ postfix_expression:
    }
    | postfix_expression DOT_TOK FIELD_SELECTION
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
       $$->set_location_range(@1, @3);
       $$->primary_expression.identifier = $3;
    }
    | postfix_expression INC_OP
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
       $$->set_location_range(@1, @2);
    }
    | postfix_expression DEC_OP
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
       $$->set_location_range(@1, @2);
    }
@@ -569,13 +569,13 @@ function_call_header:
 function_identifier:
    type_specifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_function_expression($1);
       $$->set_location(@1);
       }
    | postfix_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_function_expression($1);
       $$->set_location(@1);
       }
@@ -590,19 +590,19 @@ unary_expression:
    postfix_expression
    | INC_OP unary_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
       $$->set_location(@1);
    }
    | DEC_OP unary_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
       $$->set_location(@1);
    }
    | unary_operator unary_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
       $$->set_location_range(@1, @2);
    }
@@ -620,19 +620,19 @@ multiplicative_expression:
    unary_expression
    | multiplicative_expression '*' unary_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
       $$->set_location_range(@1, @3);
    }
    | multiplicative_expression '/' unary_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
       $$->set_location_range(@1, @3);
    }
    | multiplicative_expression '%' unary_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
       $$->set_location_range(@1, @3);
    }
@@ -642,13 +642,13 @@ additive_expression:
    multiplicative_expression
    | additive_expression '+' multiplicative_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
       $$->set_location_range(@1, @3);
    }
    | additive_expression '-' multiplicative_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
       $$->set_location_range(@1, @3);
    }
@@ -658,13 +658,13 @@ shift_expression:
    additive_expression
    | shift_expression LEFT_OP additive_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
       $$->set_location_range(@1, @3);
    }
    | shift_expression RIGHT_OP additive_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
       $$->set_location_range(@1, @3);
    }
@@ -674,25 +674,25 @@ relational_expression:
    shift_expression
    | relational_expression '<' shift_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
       $$->set_location_range(@1, @3);
    }
    | relational_expression '>' shift_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
       $$->set_location_range(@1, @3);
    }
    | relational_expression LE_OP shift_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
       $$->set_location_range(@1, @3);
    }
    | relational_expression GE_OP shift_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
       $$->set_location_range(@1, @3);
    }
@@ -702,13 +702,13 @@ equality_expression:
    relational_expression
    | equality_expression EQ_OP relational_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
       $$->set_location_range(@1, @3);
    }
    | equality_expression NE_OP relational_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
       $$->set_location_range(@1, @3);
    }
@@ -718,7 +718,7 @@ and_expression:
    equality_expression
    | and_expression '&' equality_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
       $$->set_location_range(@1, @3);
    }
@@ -728,7 +728,7 @@ exclusive_or_expression:
    and_expression
    | exclusive_or_expression '^' and_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
       $$->set_location_range(@1, @3);
    }
@@ -738,7 +738,7 @@ inclusive_or_expression:
    exclusive_or_expression
    | inclusive_or_expression '|' exclusive_or_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
       $$->set_location_range(@1, @3);
    }
@@ -748,7 +748,7 @@ logical_and_expression:
    inclusive_or_expression
    | logical_and_expression AND_OP inclusive_or_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
       $$->set_location_range(@1, @3);
    }
@@ -758,7 +758,7 @@ logical_xor_expression:
    logical_and_expression
    | logical_xor_expression XOR_OP logical_and_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
       $$->set_location_range(@1, @3);
    }
@@ -768,7 +768,7 @@ logical_or_expression:
    logical_xor_expression
    | logical_or_expression OR_OP logical_xor_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
       $$->set_location_range(@1, @3);
    }
@@ -778,7 +778,7 @@ conditional_expression:
    logical_or_expression
    | logical_or_expression '?' expression ':' assignment_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
       $$->set_location_range(@1, @5);
    }
@@ -788,7 +788,7 @@ assignment_expression:
    conditional_expression
    | unary_expression assignment_operator assignment_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression($2, $1, $3, NULL);
       $$->set_location_range(@1, @3);
    }
@@ -815,7 +815,7 @@ expression:
    }
    | expression ',' assignment_expression
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       if ($1->oper != ast_sequence) {
          $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
          $$->set_location_range(@1, @3);
@@ -888,7 +888,7 @@ function_header_with_parameters:
 function_header:
    fully_specified_type variable_identifier '('
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_function();
       $$->set_location(@2);
       $$->return_type = $1;
@@ -906,7 +906,7 @@ function_header:
 parameter_declarator:
    type_specifier any_identifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_parameter_declarator();
       $$->set_location_range(@1, @2);
       $$->type = new(ctx) ast_fully_specified_type();
@@ -922,7 +922,7 @@ parameter_declarator:
    }
    | type_specifier any_identifier array_specifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_parameter_declarator();
       $$->set_location_range(@1, @3);
       $$->type = new(ctx) ast_fully_specified_type();
@@ -945,7 +945,7 @@ parameter_declaration:
    }
    | parameter_qualifier parameter_type_specifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_parameter_declarator();
       $$->set_location(@2);
       $$->type = new(ctx) ast_fully_specified_type();
@@ -1036,7 +1036,7 @@ init_declarator_list:
    single_declaration
    | init_declarator_list ',' any_identifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
       decl->set_location(@3);
 
@@ -1046,7 +1046,7 @@ init_declarator_list:
    }
    | init_declarator_list ',' any_identifier array_specifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
       decl->set_location_range(@3, @4);
 
@@ -1056,7 +1056,7 @@ init_declarator_list:
    }
    | init_declarator_list ',' any_identifier array_specifier '=' initializer
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
       decl->set_location_range(@3, @4);
 
@@ -1066,7 +1066,7 @@ init_declarator_list:
    }
    | init_declarator_list ',' any_identifier '=' initializer
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
       decl->set_location(@3);
 
@@ -1080,14 +1080,14 @@ init_declarator_list:
 single_declaration:
    fully_specified_type
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       /* Empty declaration list is valid. */
       $$ = new(ctx) ast_declarator_list($1);
       $$->set_location(@1);
    }
    | fully_specified_type any_identifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
       decl->set_location(@2);
 
@@ -1098,7 +1098,7 @@ single_declaration:
    }
    | fully_specified_type any_identifier array_specifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
       decl->set_location_range(@2, @3);
 
@@ -1109,7 +1109,7 @@ single_declaration:
    }
    | fully_specified_type any_identifier array_specifier '=' initializer
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
       decl->set_location_range(@2, @3);
 
@@ -1120,7 +1120,7 @@ single_declaration:
    }
    | fully_specified_type any_identifier '=' initializer
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
       decl->set_location(@2);
 
@@ -1131,7 +1131,7 @@ single_declaration:
    }
    | INVARIANT variable_identifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
       decl->set_location(@2);
 
@@ -1143,7 +1143,7 @@ single_declaration:
    }
    | PRECISE variable_identifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
       decl->set_location(@2);
 
@@ -1158,14 +1158,14 @@ single_declaration:
 fully_specified_type:
    type_specifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_fully_specified_type();
       $$->set_location(@1);
       $$->specifier = $1;
    }
    | type_qualifier type_specifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_fully_specified_type();
       $$->set_location_range(@1, @2);
       $$->qualifier = $1;
@@ -1725,7 +1725,7 @@ layout_qualifier_id:
    | any_identifier '=' constant_expression
    {
       memset(& $$, 0, sizeof($$));
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
 
       if ($3->oper != ast_int_constant &&
           $3->oper != ast_uint_constant &&
@@ -1947,7 +1947,7 @@ subroutine_qualifier:
 subroutine_type_list:
    any_identifier
    {
-        void *ctx = state->linalloc;
+        linear_ctx *ctx = state->linalloc;
         ast_declaration *decl = new(ctx)  ast_declaration($1, NULL, NULL);
         decl->set_location(@1);
 
@@ -1956,7 +1956,7 @@ subroutine_type_list:
    }
    | subroutine_type_list ',' any_identifier
    {
-        void *ctx = state->linalloc;
+        linear_ctx *ctx = state->linalloc;
         ast_declaration *decl = new(ctx)  ast_declaration($3, NULL, NULL);
         decl->set_location(@3);
 
@@ -2279,7 +2279,7 @@ memory_qualifier:
 array_specifier:
    '[' ']'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
                                                   ast_unsized_array_dim, NULL,
                                                   NULL, NULL));
@@ -2287,13 +2287,13 @@ array_specifier:
    }
    | '[' constant_expression ']'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_array_specifier(@1, $2);
       $$->set_location_range(@1, @3);
    }
    | array_specifier '[' ']'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = $1;
 
       if (state->check_arrays_of_arrays_allowed(& @1)) {
@@ -2323,19 +2323,19 @@ type_specifier:
 type_specifier_nonarray:
    basic_type_specifier_nonarray
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_type_specifier($1);
       $$->set_location(@1);
    }
    | struct_specifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_type_specifier($1);
       $$->set_location(@1);
    }
    | TYPE_IDENTIFIER
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_type_specifier($1);
       $$->set_location(@1);
    }
@@ -2376,14 +2376,14 @@ precision_qualifier:
 struct_specifier:
    STRUCT any_identifier '{' struct_declaration_list '}'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_struct_specifier($2, $4);
       $$->set_location_range(@2, @5);
       state->symbols->add_type($2, glsl_type::void_type);
    }
    | STRUCT '{' struct_declaration_list '}'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
 
       /* All anonymous structs have the same name. This simplifies matching of
        * globals whose type is an unnamed struct.
@@ -2413,7 +2413,7 @@ struct_declaration_list:
 struct_declaration:
    fully_specified_type struct_declarator_list ';'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_fully_specified_type *const type = $1;
       type->set_location(@1);
 
@@ -2464,13 +2464,13 @@ struct_declarator_list:
 struct_declarator:
    any_identifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_declaration($1, NULL, NULL);
       $$->set_location(@1);
    }
    | any_identifier array_specifier
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_declaration($1, $2, NULL);
       $$->set_location_range(@1, @2);
    }
@@ -2491,7 +2491,7 @@ initializer:
 initializer_list:
    initializer
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_aggregate_initializer();
       $$->set_location(@1);
       $$->expressions.push_tail(& $1->link);
@@ -2526,7 +2526,7 @@ simple_statement:
 compound_statement:
    '{' '}'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_compound_statement(true, NULL);
       $$->set_location_range(@1, @2);
    }
@@ -2536,7 +2536,7 @@ compound_statement:
    }
    statement_list '}'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_compound_statement(true, $3);
       $$->set_location_range(@1, @4);
       state->symbols->pop_scope();
@@ -2551,13 +2551,13 @@ statement_no_new_scope:
 compound_statement_no_new_scope:
    '{' '}'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_compound_statement(false, NULL);
       $$->set_location_range(@1, @2);
    }
    | '{' statement_list '}'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_compound_statement(false, $2);
       $$->set_location_range(@1, @3);
    }
@@ -2597,13 +2597,13 @@ statement_list:
 expression_statement:
    ';'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_statement(NULL);
       $$->set_location(@1);
    }
    | expression ';'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_expression_statement($1);
       $$->set_location(@1);
    }
@@ -2638,7 +2638,7 @@ condition:
    }
    | fully_specified_type any_identifier '=' initializer
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
       ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
       decl->set_location_range(@2, @4);
@@ -2738,21 +2738,21 @@ case_statement_list:
 iteration_statement:
    WHILE '(' condition ')' statement_no_new_scope
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
                                             NULL, $3, NULL, $5);
       $$->set_location_range(@1, @4);
    }
    | DO statement_no_new_scope WHILE '(' expression ')' ';'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
                                             NULL, $5, NULL, $2);
       $$->set_location_range(@1, @6);
    }
    | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
                                             $3, $4.cond, $4.rest, $6);
       $$->set_location_range(@1, @6);
@@ -2789,31 +2789,31 @@ for_rest_statement:
 jump_statement:
    CONTINUE ';'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
       $$->set_location(@1);
    }
    | BREAK ';'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
       $$->set_location(@1);
    }
    | RETURN ';'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
       $$->set_location(@1);
    }
    | RETURN expression ';'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
       $$->set_location_range(@1, @2);
    }
    | DISCARD ';' // Fragment shader only.
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
       $$->set_location(@1);
    }
@@ -2822,7 +2822,7 @@ jump_statement:
 demote_statement:
    DEMOTE ';'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_demote_statement();
       $$->set_location(@1);
    }
@@ -2839,7 +2839,7 @@ external_declaration:
 function_definition:
    function_prototype compound_statement_no_new_scope
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       $$ = new(ctx) ast_function_definition();
       $$->set_location_range(@1, @2);
       $$->prototype = $1;
@@ -2971,7 +2971,7 @@ member_list:
 member_declaration:
    fully_specified_type struct_declarator_list ';'
    {
-      void *ctx = state->linalloc;
+      linear_ctx *ctx = state->linalloc;
       ast_fully_specified_type *type = $1;
       type->set_location(@1);
 
index bade333cc58c4eff82810127d77fca7cdaed8f68..048c719444ba605b267b3eaf37db3559b766ce3c 100644 (file)
@@ -71,7 +71,7 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
    this->translation_unit.make_empty();
    this->symbols = new(mem_ctx) glsl_symbol_table;
 
-   this->linalloc = linear_alloc_parent(this);
+   this->linalloc = linear_context(this);
 
    this->info_log = ralloc_strdup(mem_ctx, "");
    this->error = false;
index fcda94353bcdafedcc50fec70ef84dfaf42a5fa5..d6505eecd0395409525d6729802a5c822ff5488c 100644 (file)
@@ -388,7 +388,7 @@ struct _mesa_glsl_parse_state {
    exec_list translation_unit;
    glsl_symbol_table *symbols;
 
-   void *linalloc;
+   linear_ctx *linalloc;
 
    unsigned num_supported_versions;
    struct {
index 7dc965d04eb9974f7905177221d657448d818096..d92b3e7b38e0a9d3266b1f0e4fbbe45255d3495b 100644 (file)
@@ -106,7 +106,7 @@ glsl_symbol_table::glsl_symbol_table()
    this->separate_function_namespace = false;
    this->table = _mesa_symbol_table_ctor();
    this->mem_ctx = ralloc_context(NULL);
-   this->linalloc = linear_alloc_parent(this->mem_ctx);
+   this->linalloc = linear_context(this->mem_ctx);
 }
 
 glsl_symbol_table::~glsl_symbol_table()
index c8ab690eb519398f2e813b630597787d27595c4f..4f19d415dbf9afd936d7c0f93097e542653c6dce 100644 (file)
@@ -107,7 +107,7 @@ private:
 
    struct _mesa_symbol_table *table;
    void *mem_ctx;
-   void *linalloc;
+   linear_ctx *linalloc;
 };
 
 #endif /* GLSL_SYMBOL_TABLE */
index afb242c2a535da2b4035ff663e1acfbd255e096f..40736ce170e0fc2f105da4e95041776aff47ca83 100644 (file)
@@ -169,7 +169,7 @@ public:
  * of a variable to a variable.
  */
 static bool
-process_assignment(void *lin_ctx, ir_assignment *ir, exec_list *assignments)
+process_assignment(linear_ctx *lin_ctx, ir_assignment *ir, exec_list *assignments)
 {
    ir_variable *var = NULL;
    bool progress = false;
@@ -310,7 +310,7 @@ dead_code_local_basic_block(ir_instruction *first,
    bool progress = false;
 
    void *ctx = ralloc_context(NULL);
-   void *lin_ctx = linear_alloc_parent(ctx);
+   linear_ctx *lin_ctx = linear_context(ctx);
 
    /* Safe looping, since process_assignment */
    for (ir = first, ir_next = (ir_instruction *)first->next;;
index aa048556dba6be164998a712facc924cd44413ed..e9871d2b3a49d6b2878303c6860fe9432274ec5b 100644 (file)
@@ -41,7 +41,7 @@ static struct {
    /* Use a linear (arena) allocator for all the new types, since
     * they are not meant to be deallocated individually.
     */
-   void *lin_ctx;
+   linear_ctx *lin_ctx;
 
    /* There might be multiple users for types (e.g. application using OpenGL
     * and Vulkan simultaneously or app using multiple Vulkan instances). Counter
@@ -57,7 +57,7 @@ static struct {
 } glsl_type_cache;
 
 static const glsl_type *
-make_vector_matrix_type(void *lin_ctx, uint32_t gl_type,
+make_vector_matrix_type(linear_ctx *lin_ctx, uint32_t gl_type,
                         glsl_base_type base_type, unsigned vector_elements,
                         unsigned matrix_columns, const char *name,
                         unsigned explicit_stride, bool row_major,
@@ -99,7 +99,7 @@ fill_struct_type(glsl_type *t, const glsl_struct_field *fields, unsigned num_fie
 }
 
 static const glsl_type *
-make_struct_type(void *lin_ctx, const glsl_struct_field *fields, unsigned num_fields,
+make_struct_type(linear_ctx *lin_ctx, const glsl_struct_field *fields, unsigned num_fields,
                  const char *name, bool packed,
                  unsigned explicit_alignment)
 {
@@ -137,7 +137,7 @@ fill_interface_type(glsl_type *t, const glsl_struct_field *fields, unsigned num_
 }
 
 static const glsl_type *
-make_interface_type(void *lin_ctx, const glsl_struct_field *fields, unsigned num_fields,
+make_interface_type(linear_ctx *lin_ctx, const glsl_struct_field *fields, unsigned num_fields,
                     enum glsl_interface_packing packing,
                     bool row_major, const char *name)
 {
@@ -161,7 +161,7 @@ make_interface_type(void *lin_ctx, const glsl_struct_field *fields, unsigned num
 }
 
 static const glsl_type *
-make_subroutine_type(void *lin_ctx, const char *subroutine_name)
+make_subroutine_type(linear_ctx *lin_ctx, const char *subroutine_name)
 {
    assert(lin_ctx != NULL);
    assert(subroutine_name != NULL);
@@ -455,7 +455,7 @@ glsl_type_singleton_init_or_ref()
    simple_mtx_lock(&glsl_type_cache_mutex);
    if (glsl_type_cache.users == 0) {
       glsl_type_cache.mem_ctx = ralloc_context(NULL);
-      glsl_type_cache.lin_ctx = linear_alloc_parent(glsl_type_cache.mem_ctx);
+      glsl_type_cache.lin_ctx = linear_context(glsl_type_cache.mem_ctx);
    }
    glsl_type_cache.users++;
    simple_mtx_unlock(&glsl_type_cache_mutex);
@@ -480,7 +480,7 @@ glsl_type_singleton_decref()
 }
 
 static const glsl_type *
-make_array_type(void *lin_ctx, const glsl_type *element_type, unsigned length,
+make_array_type(linear_ctx *lin_ctx, const glsl_type *element_type, unsigned length,
                 unsigned explicit_stride)
 {
    assert(lin_ctx != NULL);
@@ -754,7 +754,7 @@ glsl_type::get_explicit_matrix_instance(unsigned int base_type, unsigned int row
       snprintf(name, sizeof(name), "%sx%ua%uB%s", glsl_get_type_name(bare_type),
                explicit_stride, explicit_alignment, row_major ? "RM" : "");
 
-      void *lin_ctx = glsl_type_cache.lin_ctx;
+      linear_ctx *lin_ctx = glsl_type_cache.lin_ctx;
       const glsl_type *t =
          make_vector_matrix_type(lin_ctx, bare_type->gl_type,
                                  (glsl_base_type)base_type,
@@ -1230,7 +1230,7 @@ glsl_type::get_array_instance(const glsl_type *element,
 
    const struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(array_types, key_hash, &key);
    if (entry == NULL) {
-      void *lin_ctx = glsl_type_cache.lin_ctx;
+      linear_ctx *lin_ctx = glsl_type_cache.lin_ctx;
       const glsl_type *t = make_array_type(lin_ctx, element, array_size, explicit_stride);
       struct array_key *stored_key = linear_zalloc(lin_ctx, struct array_key);
       memcpy(stored_key, &key, sizeof(key));
index 42e3b0fd1af3ef72b0f8203d45a964ed722143b2..2acb2b54077fee6e13c8cf96ac6117b7424988a5 100644 (file)
@@ -75,7 +75,7 @@ struct combine_stores_state {
    bool progress;
 
    /* Allocator and freelist to reuse structs between functions. */
-   void *lin_ctx;
+   linear_ctx *lin_ctx;
    struct list_head freelist;
 };
 
@@ -417,7 +417,7 @@ nir_opt_combine_stores(nir_shader *shader, nir_variable_mode modes)
    void *mem_ctx = ralloc_context(NULL);
    struct combine_stores_state state = {
       .modes = modes,
-      .lin_ctx = linear_alloc_parent(mem_ctx),
+      .lin_ctx = linear_context(mem_ctx),
    };
 
    list_inithead(&state.pending);
index fd58b87d9ac3beb9d0e2faace3316e92b1ac1acd..06ebd30b2b89a4943eba9f927c41360d7e58d7cd 100644 (file)
@@ -110,7 +110,7 @@ struct copy_prop_var_state {
    nir_function_impl *impl;
 
    void *mem_ctx;
-   void *lin_ctx;
+   linear_ctx *lin_ctx;
 
    /* Maps nodes to vars_written.  Used to invalidate copy entries when
     * visiting each node.
@@ -1482,7 +1482,7 @@ nir_copy_prop_vars_impl(nir_function_impl *impl)
    struct copy_prop_var_state state = {
       .impl = impl,
       .mem_ctx = mem_ctx,
-      .lin_ctx = linear_alloc_parent(mem_ctx),
+      .lin_ctx = linear_context(mem_ctx),
 
       .vars_written_map = _mesa_pointer_hash_table_create(mem_ctx),
    };
index ee85208027f66904491337d4cecce7bdb3b46816..3ff1cc43bd7eb13156b58349ca5ea1ebd8a6cd62 100644 (file)
@@ -90,13 +90,13 @@ protected:
 
    nir_deref_instr *get_deref(nir_deref_type deref_type,
                               unsigned index);
-   void *lin_ctx;
+   linear_ctx *lin_ctx;
 };
 
 nir_vars_test::nir_vars_test()
    : nir_test::nir_test("nir_vars_test")
 {
-   lin_ctx = linear_alloc_parent(b->shader);
+   lin_ctx = linear_context(b->shader);
 }
 
 nir_vars_test::~nir_vars_test()
index d6892855de55747042dfcb8907a84397d1fa84a1..9a59ec678879d12be8523c58347820c1d2108eab 100644 (file)
@@ -983,6 +983,10 @@ struct linear_header {
     */
 };
 
+struct linear_ctx {
+   struct linear_header header;
+};
+
 struct linear_size_chunk {
    unsigned size; /* for realloc */
    unsigned _padding;
@@ -1016,9 +1020,9 @@ create_linear_node(void *ralloc_ctx, unsigned min_size)
 }
 
 void *
-linear_alloc_child(void *parent, unsigned size)
+linear_alloc_child(linear_ctx *ctx, unsigned size)
 {
-   linear_header *first = parent;
+   linear_header *first = &ctx->header;
    linear_header *latest = first->latest;
    linear_header *new_node;
    linear_size_chunk *ptr;
@@ -1049,8 +1053,8 @@ linear_alloc_child(void *parent, unsigned size)
    return &ptr[1];
 }
 
-void *
-linear_alloc_parent(void *ralloc_ctx)
+linear_ctx *
+linear_context(void *ralloc_ctx)
 {
    linear_header *node;
 
@@ -1061,13 +1065,13 @@ linear_alloc_parent(void *ralloc_ctx)
    if (unlikely(!node))
       return NULL;
 
-   return node;
+   return (linear_ctx *)node;
 }
 
 void *
-linear_zalloc_child(void *parent, unsigned size)
+linear_zalloc_child(linear_ctx *ctx, unsigned size)
 {
-   void *ptr = linear_alloc_child(parent, size);
+   void *ptr = linear_alloc_child(ctx, size);
 
    if (likely(ptr))
       memset(ptr, 0, size);
@@ -1075,46 +1079,46 @@ linear_zalloc_child(void *parent, unsigned size)
 }
 
 void
-linear_free_parent(void *ptr)
+linear_free_context(linear_ctx *ctx)
 {
-   if (unlikely(!ptr))
+   if (unlikely(!ctx))
       return;
 
-   linear_header *first = ptr;
+   linear_header *first = &ctx->header;
    assert(first->magic == LMAGIC);
 
    /* Other nodes are ralloc children of the first node. */
-   ralloc_free(first);
+   ralloc_free(ctx);
 }
 
 void
-ralloc_steal_linear_parent(void *new_ralloc_ctx, void *ptr)
+ralloc_steal_linear_context(void *new_ralloc_ctx, linear_ctx *ctx)
 {
-   if (unlikely(!ptr))
+   if (unlikely(!ctx))
       return;
 
-   linear_header *first = ptr;
+   linear_header *first = &ctx->header;
    assert(first->magic == LMAGIC);
 
    /* Other nodes are ralloc children of the first node. */
-   ralloc_steal(new_ralloc_ctx, first);
+   ralloc_steal(new_ralloc_ctx, ctx);
 }
 
 void *
-ralloc_parent_of_linear_parent(void *ptr)
+ralloc_parent_of_linear_context(linear_ctx *ctx)
 {
-   linear_header *node = ptr;
+   linear_header *node = &ctx->header;
    assert(node->magic == LMAGIC);
    return PTR_FROM_HEADER(get_header(node)->parent);
 }
 
 void *
-linear_realloc(void *parent, void *old, unsigned new_size)
+linear_realloc(linear_ctx *ctx, void *old, unsigned new_size)
 {
    unsigned old_size = 0;
    ralloc_header *new_ptr;
 
-   new_ptr = linear_alloc_child(parent, new_size);
+   new_ptr = linear_alloc_child(ctx, new_size);
 
    if (unlikely(!old))
       return new_ptr;
@@ -1132,7 +1136,7 @@ linear_realloc(void *parent, void *old, unsigned new_size)
  */
 
 char *
-linear_strdup(void *parent, const char *str)
+linear_strdup(linear_ctx *ctx, const char *str)
 {
    unsigned n;
    char *ptr;
@@ -1141,7 +1145,7 @@ linear_strdup(void *parent, const char *str)
       return NULL;
 
    n = strlen(str);
-   ptr = linear_alloc_child(parent, n + 1);
+   ptr = linear_alloc_child(ctx, n + 1);
    if (unlikely(!ptr))
       return NULL;
 
@@ -1151,22 +1155,22 @@ linear_strdup(void *parent, const char *str)
 }
 
 char *
-linear_asprintf(void *parent, const char *fmt, ...)
+linear_asprintf(linear_ctx *ctx, const char *fmt, ...)
 {
    char *ptr;
    va_list args;
    va_start(args, fmt);
-   ptr = linear_vasprintf(parent, fmt, args);
+   ptr = linear_vasprintf(ctx, fmt, args);
    va_end(args);
    return ptr;
 }
 
 char *
-linear_vasprintf(void *parent, const char *fmt, va_list args)
+linear_vasprintf(linear_ctx *ctx, const char *fmt, va_list args)
 {
    unsigned size = u_printf_length(fmt, args) + 1;
 
-   char *ptr = linear_alloc_child(parent, size);
+   char *ptr = linear_alloc_child(ctx, size);
    if (ptr != NULL)
       vsnprintf(ptr, size, fmt, args);
 
@@ -1174,39 +1178,39 @@ linear_vasprintf(void *parent, const char *fmt, va_list args)
 }
 
 bool
-linear_asprintf_append(void *parent, char **str, const char *fmt, ...)
+linear_asprintf_append(linear_ctx *ctx, char **str, const char *fmt, ...)
 {
    bool success;
    va_list args;
    va_start(args, fmt);
-   success = linear_vasprintf_append(parent, str, fmt, args);
+   success = linear_vasprintf_append(ctx, str, fmt, args);
    va_end(args);
    return success;
 }
 
 bool
-linear_vasprintf_append(void *parent, char **str, const char *fmt, va_list args)
+linear_vasprintf_append(linear_ctx *ctx, char **str, const char *fmt, va_list args)
 {
    size_t existing_length;
    assert(str != NULL);
    existing_length = *str ? strlen(*str) : 0;
-   return linear_vasprintf_rewrite_tail(parent, str, &existing_length, fmt, args);
+   return linear_vasprintf_rewrite_tail(ctx, str, &existing_length, fmt, args);
 }
 
 bool
-linear_asprintf_rewrite_tail(void *parent, char **str, size_t *start,
+linear_asprintf_rewrite_tail(linear_ctx *ctx, char **str, size_t *start,
                              const char *fmt, ...)
 {
    bool success;
    va_list args;
    va_start(args, fmt);
-   success = linear_vasprintf_rewrite_tail(parent, str, start, fmt, args);
+   success = linear_vasprintf_rewrite_tail(ctx, str, start, fmt, args);
    va_end(args);
    return success;
 }
 
 bool
-linear_vasprintf_rewrite_tail(void *parent, char **str, size_t *start,
+linear_vasprintf_rewrite_tail(linear_ctx *ctx, char **str, size_t *start,
                               const char *fmt, va_list args)
 {
    size_t new_length;
@@ -1215,14 +1219,14 @@ linear_vasprintf_rewrite_tail(void *parent, char **str, size_t *start,
    assert(str != NULL);
 
    if (unlikely(*str == NULL)) {
-      *str = linear_vasprintf(parent, fmt, args);
+      *str = linear_vasprintf(ctx, fmt, args);
       *start = strlen(*str);
       return true;
    }
 
    new_length = u_printf_length(fmt, args);
 
-   ptr = linear_realloc(parent, *str, *start + new_length + 1);
+   ptr = linear_realloc(ctx, *str, *start + new_length + 1);
    if (unlikely(ptr == NULL))
       return false;
 
@@ -1234,14 +1238,14 @@ linear_vasprintf_rewrite_tail(void *parent, char **str, size_t *start,
 
 /* helper routine for strcat/strncat - n is the exact amount to copy */
 static bool
-linear_cat(void *parent, char **dest, const char *str, unsigned n)
+linear_cat(linear_ctx *ctx, char **dest, const char *str, unsigned n)
 {
    char *both;
    unsigned existing_length;
    assert(dest != NULL && *dest != NULL);
 
    existing_length = strlen(*dest);
-   both = linear_realloc(parent, *dest, existing_length + n + 1);
+   both = linear_realloc(ctx, *dest, existing_length + n + 1);
    if (unlikely(both == NULL))
       return false;
 
@@ -1253,25 +1257,25 @@ linear_cat(void *parent, char **dest, const char *str, unsigned n)
 }
 
 bool
-linear_strcat(void *parent, char **dest, const char *str)
+linear_strcat(linear_ctx *ctx, char **dest, const char *str)
 {
-   return linear_cat(parent, dest, str, strlen(str));
+   return linear_cat(ctx, dest, str, strlen(str));
 }
 
 void *
-linear_alloc_child_array(void *parent, size_t size, unsigned count)
+linear_alloc_child_array(linear_ctx *ctx, size_t size, unsigned count)
 {
    if (count > SIZE_MAX/size)
       return NULL;
 
-   return linear_alloc_child(parent, size * count);
+   return linear_alloc_child(ctx, size * count);
 }
 
 void *
-linear_zalloc_child_array(void *parent, size_t size, unsigned count)
+linear_zalloc_child_array(linear_ctx *ctx, size_t size, unsigned count)
 {
    if (count > SIZE_MAX/size)
       return NULL;
 
-   return linear_zalloc_child(parent, size * count);
+   return linear_zalloc_child(ctx, size * count);
 }
index 1759692aa3978428e1aa9d2776ec31a769845236..54084a2a8c1285f57b0fd3f5b40012017780d481 100644 (file)
@@ -553,9 +553,9 @@ public:                                                                  \
 
 #define DECLARE_LINEAR_ALLOC_CXX_OPERATORS_TEMPLATE(TYPE, ALLOC_FUNC)    \
 public:                                                                  \
-   static void* operator new(size_t size, void *mem_ctx)                 \
+   static void* operator new(size_t size, linear_ctx *ctx)               \
    {                                                                     \
-      void *p = ALLOC_FUNC(mem_ctx, size);                               \
+      void *p = ALLOC_FUNC(ctx, size);                                   \
       assert(p != NULL);                                                 \
       static_assert(HAS_TRIVIAL_DESTRUCTOR(TYPE));                       \
       return p;                                                          \
@@ -567,44 +567,47 @@ public:                                                                  \
 #define DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(type) \
    DECLARE_LINEAR_ALLOC_CXX_OPERATORS_TEMPLATE(type, linear_zalloc_child)
 
+typedef struct linear_ctx linear_ctx;
+
 /**
- * Do a fast allocation from the linear buffer, also known as the child node
+ * Do a fast allocation from the linear context, also known as the child node
  * from the allocator's point of view. It can't be freed directly. You have
- * to free the parent or the ralloc parent.
+ * to free the linear context or the ralloc parent.
  *
- * \param parent   parent node of the linear allocator
+ * \param ctx      linear context of the allocator
  * \param size     size to allocate (max 32 bits)
  */
-void *linear_alloc_child(void *parent, unsigned size) MALLOCLIKE;
+void *linear_alloc_child(linear_ctx *ctx, unsigned size);
 
 /**
- * Allocate a parent node that will hold linear buffers.
+ * Allocate a linear context that will internally hold linear buffers.
  * Use it for all child node allocations.
  *
  * \param ralloc_ctx  ralloc context, must not be NULL
  */
-void *linear_alloc_parent(void *ralloc_ctx);
+linear_ctx *linear_context(void *ralloc_ctx);
 
 /**
  * Same as linear_alloc_child, but also clears memory.
  */
-void *linear_zalloc_child(void *parent, unsigned size) MALLOCLIKE;
+void *linear_zalloc_child(linear_ctx *ctx, unsigned size) MALLOCLIKE;
 
 /**
- * Free the linear parent node. This will free all child nodes too.
- * Freeing the ralloc parent will also free this.
+ * Free a linear context. This will free all child nodes too.
+ * Alternatively, freeing the ralloc parent will also free
+ * the linear context.
  */
-void linear_free_parent(void *ptr);
+void linear_free_context(linear_ctx *ctx);
 
 /**
- * Same as ralloc_steal, but steals the linear parent node.
+ * Same as ralloc_steal, but steals the entire linear context.
  */
-void ralloc_steal_linear_parent(void *new_ralloc_ctx, void *ptr);
+void ralloc_steal_linear_context(void *new_ralloc_ctx, linear_ctx *ctx);
 
 /**
- * Return the ralloc parent of the linear parent node.
+ * Return the ralloc parent of the linear context.
  */
-void *ralloc_parent_of_linear_parent(void *ptr);
+void *ralloc_parent_of_linear_context(linear_ctx *ctx);
 
 /**
  * Same as realloc except that the linear allocator doesn't free child nodes,
@@ -612,68 +615,68 @@ void *ralloc_parent_of_linear_parent(void *ptr);
  * reallocation is required. Don't use it often. It's much slower than
  * realloc.
  */
-void *linear_realloc(void *parent, void *old, unsigned new_size);
+void *linear_realloc(linear_ctx *ctx, void *old, unsigned new_size);
 
 /**
- * Do a fast allocation of an array from the linear buffer and initialize it to zero.
+ * Do a fast allocation of an array from the linear context and initialize it to zero.
  *
  * Similar to \c calloc, but does not initialize the memory to zero.
  *
  * More than a convenience function, this also checks for integer overflow when
  * multiplying \p size and \p count.  This is necessary for security.
  */
-void *linear_alloc_child_array(void *parent, size_t size, unsigned count) MALLOCLIKE;
+void *linear_alloc_child_array(linear_ctx *ctx, size_t size, unsigned count) MALLOCLIKE;
 
 /**
- * Do a fast allocation of an array from the linear buffer.
+ * Do a fast allocation of an array from the linear context.
  *
  * Similar to \c calloc.
  *
  * More than a convenience function, this also checks for integer overflow when
  * multiplying \p size and \p count.  This is necessary for security.
  */
-void *linear_zalloc_child_array(void *parent, size_t size, unsigned count) MALLOCLIKE;
+void *linear_zalloc_child_array(linear_ctx *ctx, size_t size, unsigned count) MALLOCLIKE;
 
 /* The functions below have the same semantics as their ralloc counterparts,
  * except that they always allocate a linear child node.
  */
-char *linear_strdup(void *parent, const char *str) MALLOCLIKE;
-char *linear_asprintf(void *parent, const char *fmt, ...) PRINTFLIKE(2, 3) MALLOCLIKE;
-char *linear_vasprintf(void *parent, const char *fmt, va_list args) MALLOCLIKE;
-bool linear_asprintf_append(void *parent, char **str, const char *fmt, ...) PRINTFLIKE(3, 4);
-bool linear_vasprintf_append(void *parent, char **str, const char *fmt,
+char *linear_strdup(linear_ctx *ctx, const char *str) MALLOCLIKE;
+char *linear_asprintf(linear_ctx *ctx, const char *fmt, ...) PRINTFLIKE(2, 3) MALLOCLIKE;
+char *linear_vasprintf(linear_ctx *ctx, const char *fmt, va_list args) MALLOCLIKE;
+bool linear_asprintf_append(linear_ctx *ctx, char **str, const char *fmt, ...) PRINTFLIKE(3, 4);
+bool linear_vasprintf_append(linear_ctx *ctx, char **str, const char *fmt,
                              va_list args);
-bool linear_asprintf_rewrite_tail(void *parent, char **str, size_t *start,
+bool linear_asprintf_rewrite_tail(linear_ctx *ctx, char **str, size_t *start,
                                   const char *fmt, ...) PRINTFLIKE(4, 5);
-bool linear_vasprintf_rewrite_tail(void *parent, char **str, size_t *start,
+bool linear_vasprintf_rewrite_tail(linear_ctx *ctx, char **str, size_t *start,
                                    const char *fmt, va_list args);
-bool linear_strcat(void *parent, char **dest, const char *str);
+bool linear_strcat(linear_ctx *ctx, char **dest, const char *str);
 
 /**
- * \def linear_alloc(parent, type)
- * Do a fast allocation from the linear buffer.
+ * \def linear_alloc(ctx, type)
+ * Do a fast allocation from the linear context.
  *
  * This is equivalent to:
  * \code
- * ((type *) linear_alloc_child(parent, sizeof(type))
+ * ((type *) linear_alloc_child(ctx, sizeof(type))
  * \endcode
  */
-#define linear_alloc(parent, type)  ((type *) linear_alloc_child(parent, sizeof(type)))
+#define linear_alloc(ctx, type)  ((type *) linear_alloc_child(ctx, sizeof(type)))
 
 /**
- * \def linear_zalloc(parent, type)
- * Do a fast allocation from the linear buffer and initialize it to zero.
+ * \def linear_zalloc(ctx, type)
+ * Do a fast allocation from the linear context and initialize it to zero.
  *
  * This is equivalent to:
  * \code
- * ((type *) linear_zalloc_child(parent, sizeof(type))
+ * ((type *) linear_zalloc_child(ctx, sizeof(type))
  * \endcode
  */
-#define linear_zalloc(parent, type) ((type *) linear_zalloc_child(parent, sizeof(type)))
+#define linear_zalloc(ctx, type) ((type *) linear_zalloc_child(ctx, sizeof(type)))
 
 /**
- * \def linear_alloc_array(parent, type, count)
- * Do a fast allocation of an array from the linear buffer.
+ * \def linear_alloc_array(ctx, type, count)
+ * Do a fast allocation of an array from the linear context.
  *
  * Similar to \c calloc, but does not initialize the memory to zero.
  *
@@ -682,15 +685,15 @@ bool linear_strcat(void *parent, char **dest, const char *str);
  *
  * This is equivalent to:
  * \code
- * ((type *) linear_alloc_child_array(parent, sizeof(type), count)
+ * ((type *) linear_alloc_child_array(ctx, sizeof(type), count)
  * \endcode
  */
-#define linear_alloc_array(parent, type, count) \
-   ((type *) linear_alloc_child_array(parent, sizeof(type), count))
+#define linear_alloc_array(ctx, type, count) \
+   ((type *) linear_alloc_child_array(ctx, sizeof(type), count))
 
 /**
- * \def linear_zalloc_array(parent, type, count)
- * Do a fast allocation of an array from the linear buffer and initialize it to zero
+ * \def linear_zalloc_array(ctx, type, count)
+ * Do a fast allocation of an array from the linear context and initialize it to zero
  *
  * Similar to \c calloc.
  *
@@ -699,11 +702,11 @@ bool linear_strcat(void *parent, char **dest, const char *str);
  *
  * This is equivalent to:
  * \code
- * ((type *) linear_zalloc_child_array(parent, sizeof(type), count)
+ * ((type *) linear_zalloc_child_array(ctx, sizeof(type), count)
  * \endcode
  */
-#define linear_zalloc_array(parent, type, count) \
-   ((type *) linear_zalloc_child_array(parent, sizeof(type), count))
+#define linear_zalloc_array(ctx, type, count) \
+   ((type *) linear_zalloc_child_array(ctx, sizeof(type), count))
 
 #ifdef __cplusplus
 } /* end of extern "C" */