mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-27 04:52:05 +08:00
fc270c357a
This removes XCALLOC and replaces it either with XCNEWVEC, or, if the number of elements being requested was 1, with XCNEW. 2014-01-13 Tom Tromey <tromey@redhat.com> * defs.h (XCALLOC): Remove. * bcache.c (bcache_xmalloc): Use XCNEW, not XCALLOC. (print_bcache_statistics): Use XCNEWVEC, not XCALLOC. * dwarf2loc.c (allocate_piece_closure): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_symfile_segments): Likewise. * gdbtypes.c (copy_type_recursive): Likewise. * i386-tdep.c (i386_gdbarch_init): Use XCNEW, not XCALLOC. * jit.c (jit_frame_sniffer): Use XCNEWVEC, not XCALLOC. * minsyms.c (prim_record_minimal_symbol_full): Use XCNEW, not XCALLOC. * mt-tdep.c (mt_gdbarch_init): Likewise. * opencl-lang.c (allocate_lval_closure): Use XCNEWVEC, not XCALLOC. * psymtab.c (psymbol_compare): Use XCNEW, not XCALLOC. * regcache.c (regcache_xmalloc_1): Use XCNEWVEC, not XCALLOC. * registry.c (registry_alloc_data): Likewise. * rs6000-tdep.c (rs6000_gdbarch_init): Use XCNEW, not XCALLOC. * s390-linux-tdep.c (s390_gdbarch_init): Likewise. * serial.c (serial_fdopen_ops): Likewise. * solib-aix.c (solib_aix_get_section_offsets): Use XCNEWVEC, not XCALLOC. * spu-tdep.c (spu_gdbarch_init): Use XCNEW, not XCALLOC. * symfile.c (default_symfile_segments): Use XCNEW and XCNEWVEC, not XCALLOC.
116 lines
3.4 KiB
C
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 = ®istry->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 = XCNEWVEC (void *, fields->num_data);
|
|
}
|
|
|
|
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];
|
|
}
|