binutils-gdb/gdb/registry.c
Tom Tromey 70ba0933ad replace XMALLOC with XNEW
This replaces XMALLOC with XNEW, and removes XMALLOC.  The only
non-mechanical bit here was remembering to edit gdbarch.sh.

2014-01-13  Tom Tromey  <tromey@redhat.com>

	* defs.h (XMALLOC): Remove.
	* avr-tdep.c (avr_gdbarch_init): Use XNEW, not XMALLOC.
	* bfin-tdep.c (bfin_gdbarch_init): Likewise.
	* cli-out.c (struct ui_out *): Likewise.
	* cli/cli-dump.c (add_dump_command): Likewise.
	(add_dump_command): Likewise.
	* complaints.c (get_complaints): Likewise.
	(find_complaint): Likewise.
	* dwarf2-frame.c (execute_cfa_program): Likewise.
	* dwarf2read.c (abbrev_table_read_table): Likewise.
	* gdbarch.sh: Likewise.
	* gdbarch.c: Rebuild.
	* inf-ttrace.c (inf_ttrace_add_page): Likewise.
	* interps.c (interp_new): Likewise.
	* lm32-tdep.c (lm32_gdbarch_init): Likewise.
	* m32r-tdep.c (m32r_gdbarch_init): Likewise.
	* mi/mi-console.c (mi_console_file_new): Likewise.
	* mi/mi-interp.c (mi_interpreter_init): Likewise.
	* mi/mi-out.c (mi_out_new): Likewise.
	* mi/mi-parse.c (mi_parse): Likewise.
	* microblaze-tdep.c (microblaze_gdbarch_init): Likewise.
	* moxie-tdep.c (moxie_gdbarch_init): Likewise.
	* observer.c (xalloc_observer_list_node): Likewise.
	* regcache.c (regcache_xmalloc_1): Likewise.
	* reggroups.c (reggroup_new): Likewise.
	(_initialize_reggroup): Likewise.
	* registry.c (register_data_with_cleanup): Likewise.
	* remote.c (remote_notif_stop_alloc_reply): Likewise.
	* ser-base.c (serial_ttystate): Likewise.
	* ser-mingw.c (make_pipe_state): Likewise.
	* ser-pipe.c (pipe_open): Likewise.
	* serial.c (serial_open): Likewise.
	* sh64-tdep.c (sh64_gdbarch_init): Likewise.
	* tui/tui-data.c (tui_alloc_generic_win_info): Likewise.
	(tui_alloc_win_info): Likewise.
	(tui_add_content_elements): Likewise.
	* tui/tui-file.c (tui_file_new): Likewise.
	* tui/tui-out.c (tui_out_new): Likewise.
	* ui-file.c (mem_file_new): Likewise.
	* ui-out.c (push_level): Likewise.
	(make_cleanup_ui_out_end): Likewise.
	(append_header_to_list): Likewise.
	(ui_out_new): Likewise.
	* user-regs.c (user_reg_add_builtin): Likewise.
2014-01-13 07:31:28 -07:00

116 lines
3.4 KiB
C

/* Support functions for general registry objects.
Copyright (C) 2011-2014 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "registry.h"
#include "gdb_assert.h"
#include <string.h>
const struct registry_data *
register_data_with_cleanup (struct registry_data_registry *registry,
registry_data_callback save,
registry_data_callback free)
{
struct registry_data_registration **curr;
/* Append new registration. */
for (curr = &registry->registrations;
*curr != NULL;
curr = &(*curr)->next)
;
*curr = XNEW (struct registry_data_registration);
(*curr)->next = NULL;
(*curr)->data = XNEW (struct registry_data);
(*curr)->data->index = registry->num_registrations++;
(*curr)->data->save = save;
(*curr)->data->free = free;
return (*curr)->data;
}
void
registry_alloc_data (struct registry_data_registry *registry,
struct registry_fields *fields)
{
gdb_assert (fields->data == NULL);
fields->num_data = registry->num_registrations;
fields->data = XCALLOC (fields->num_data, void *);
}
void
registry_clear_data (struct registry_data_registry *data_registry,
registry_callback_adaptor adaptor,
struct registry_container *container,
struct registry_fields *fields)
{
struct registry_data_registration *registration;
int i;
gdb_assert (fields->data != NULL);
/* Process all the save handlers. */
for (registration = data_registry->registrations, i = 0;
i < fields->num_data;
registration = registration->next, i++)
if (fields->data[i] != NULL && registration->data->save != NULL)
adaptor (registration->data->save, container, fields->data[i]);
/* Now process all the free handlers. */
for (registration = data_registry->registrations, i = 0;
i < fields->num_data;
registration = registration->next, i++)
if (fields->data[i] != NULL && registration->data->free != NULL)
adaptor (registration->data->free, container, fields->data[i]);
memset (fields->data, 0, fields->num_data * sizeof (void *));
}
void
registry_container_free_data (struct registry_data_registry *data_registry,
registry_callback_adaptor adaptor,
struct registry_container *container,
struct registry_fields *fields)
{
void ***rdata = &fields->data;
gdb_assert (*rdata != NULL);
registry_clear_data (data_registry, adaptor, container, fields);
xfree (*rdata);
*rdata = NULL;
}
void
registry_set_data (struct registry_fields *fields,
const struct registry_data *data,
void *value)
{
gdb_assert (data->index < fields->num_data);
fields->data[data->index] = value;
}
void *
registry_data (struct registry_fields *fields,
const struct registry_data *data)
{
gdb_assert (data->index < fields->num_data);
return fields->data[data->index];
}