diff options
author | Tom Tromey <tom@tromey.com> | 2020-09-23 09:32:54 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2020-09-23 09:32:54 -0600 |
commit | ebe824f5dcf96c8f70e07affb44c3a1679849e28 (patch) | |
tree | 483baf4a5fab305c7a9cd3750c215b13243af0e0 /gdb/compile | |
parent | c4694f172b51a2168b8cc15109ab1b97fc0bcb9c (diff) | |
download | gdb-ebe824f5dcf96c8f70e07affb44c3a1679849e28.zip gdb-ebe824f5dcf96c8f70e07affb44c3a1679849e28.tar.gz gdb-ebe824f5dcf96c8f70e07affb44c3a1679849e28.tar.bz2 |
Remove some manual memory management from compile interface
This changes gdb's compile code to use std::vector in a couple of
places, rather than manual memory management.
gdb/ChangeLog
2020-09-23 Tom Tromey <tom@tromey.com>
* compile/compile-cplus-types.c
(compile_cplus_convert_struct_or_union): Use std::vector.
(compile_cplus_convert_func): Likewise.
* compile/compile-c-types.c (convert_func): Use std::vector.
Diffstat (limited to 'gdb/compile')
-rw-r--r-- | gdb/compile/compile-c-types.c | 4 | ||||
-rw-r--r-- | gdb/compile/compile-cplus-types.c | 39 |
2 files changed, 19 insertions, 24 deletions
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c index 585f6c8..82c9af3 100644 --- a/gdb/compile/compile-c-types.c +++ b/gdb/compile/compile-c-types.c @@ -176,13 +176,13 @@ convert_func (compile_c_instance *context, struct type *type) return_type = context->convert_type (target_type); array.n_elements = type->num_fields (); - array.elements = XNEWVEC (gcc_type, type->num_fields ()); + std::vector<gcc_type> elements (array.n_elements); + array.elements = elements.data (); for (i = 0; i < type->num_fields (); ++i) array.elements[i] = context->convert_type (type->field (i).type ()); result = context->plugin ().build_function_type (return_type, &array, is_varargs); - xfree (array.elements); return result; } diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c index a094568..f92091a 100644 --- a/gdb/compile/compile-cplus-types.c +++ b/gdb/compile/compile-cplus-types.c @@ -848,33 +848,29 @@ compile_cplus_convert_struct_or_union (compile_cplus_instance *instance, gcc_type result; if (type->code () == TYPE_CODE_STRUCT) { - struct gcc_vbase_array bases; int num_baseclasses = TYPE_N_BASECLASSES (type); + std::vector<gcc_type> elements (num_baseclasses); + std::vector<enum gcc_cp_symbol_kind> flags (num_baseclasses); - memset (&bases, 0, sizeof (bases)); + struct gcc_vbase_array bases {}; + bases.elements = elements.data (); + bases.flags = flags.data (); + bases.n_elements = num_baseclasses; - if (num_baseclasses > 0) + for (int i = 0; i < num_baseclasses; ++i) { - bases.elements = XNEWVEC (gcc_type, num_baseclasses); - bases.flags = XNEWVEC (enum gcc_cp_symbol_kind, num_baseclasses); - bases.n_elements = num_baseclasses; - for (int i = 0; i < num_baseclasses; ++i) - { - struct type *base_type = TYPE_BASECLASS (type, i); - - bases.flags[i] = GCC_CP_SYMBOL_BASECLASS - | get_field_access_flag (type, i) - | (BASETYPE_VIA_VIRTUAL (type, i) - ? GCC_CP_FLAG_BASECLASS_VIRTUAL - : GCC_CP_FLAG_BASECLASS_NOFLAG); - bases.elements[i] = instance->convert_type (base_type); - } + struct type *base_type = TYPE_BASECLASS (type, i); + + bases.flags[i] = (GCC_CP_SYMBOL_BASECLASS + | get_field_access_flag (type, i) + | (BASETYPE_VIA_VIRTUAL (type, i) + ? GCC_CP_FLAG_BASECLASS_VIRTUAL + : GCC_CP_FLAG_BASECLASS_NOFLAG)); + bases.elements[i] = instance->convert_type (base_type); } result = instance->plugin ().start_class_type (name.get (), resuld, &bases, filename, line); - xfree (bases.flags); - xfree (bases.elements); } else { @@ -985,8 +981,8 @@ compile_cplus_convert_func (compile_cplus_instance *instance, types. Those are impossible in C, though. */ gcc_type return_type = instance->convert_type (target_type); - struct gcc_type_array array = - { type->num_fields (), XNEWVEC (gcc_type, type->num_fields ()) }; + std::vector<gcc_type> elements (type->num_fields ()); + struct gcc_type_array array = { type->num_fields (), elements.data () }; int artificials = 0; for (int i = 0; i < type->num_fields (); ++i) { @@ -1006,7 +1002,6 @@ compile_cplus_convert_func (compile_cplus_instance *instance, with some minsyms like printf (compile-cplus.exp has examples). */ gcc_type result = instance->plugin ().build_function_type (return_type, &array, is_varargs); - xfree (array.elements); return result; } |