GDB (xrefs)
/tmp/gdb-7.10/gdb/registry.c
Go to the documentation of this file.
1 /* Support functions for general registry objects.
2 
3  Copyright (C) 2011-2015 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "defs.h"
21 #include "registry.h"
22 const struct registry_data *
26 {
27  struct registry_data_registration **curr;
28 
29  /* Append new registration. */
30  for (curr = &registry->registrations;
31  *curr != NULL;
32  curr = &(*curr)->next)
33  ;
34 
35  *curr = XNEW (struct registry_data_registration);
36  (*curr)->next = NULL;
37  (*curr)->data = XNEW (struct registry_data);
38  (*curr)->data->index = registry->num_registrations++;
39  (*curr)->data->save = save;
40  (*curr)->data->free = free;
41 
42  return (*curr)->data;
43 }
44 
45 void
47  struct registry_fields *fields)
48 {
49  gdb_assert (fields->data == NULL);
50  fields->num_data = registry->num_registrations;
51  fields->data = XCNEWVEC (void *, fields->num_data);
52 }
53 
54 void
57  struct registry_container *container,
58  struct registry_fields *fields)
59 {
60  struct registry_data_registration *registration;
61  int i;
62 
63  gdb_assert (fields->data != NULL);
64 
65  /* Process all the save handlers. */
66 
67  for (registration = data_registry->registrations, i = 0;
68  i < fields->num_data;
69  registration = registration->next, i++)
70  if (fields->data[i] != NULL && registration->data->save != NULL)
71  adaptor (registration->data->save, container, fields->data[i]);
72 
73  /* Now process all the free handlers. */
74 
75  for (registration = data_registry->registrations, i = 0;
76  i < fields->num_data;
77  registration = registration->next, i++)
78  if (fields->data[i] != NULL && registration->data->free != NULL)
79  adaptor (registration->data->free, container, fields->data[i]);
80 
81  memset (fields->data, 0, fields->num_data * sizeof (void *));
82 }
83 
84 void
87  struct registry_container *container,
88  struct registry_fields *fields)
89 {
90  void ***rdata = &fields->data;
91  gdb_assert (*rdata != NULL);
92  registry_clear_data (data_registry, adaptor, container, fields);
93  xfree (*rdata);
94  *rdata = NULL;
95 }
96 
97 void
99  const struct registry_data *data,
100  void *value)
101 {
102  gdb_assert (data->index < fields->num_data);
103  fields->data[data->index] = value;
104 }
105 
106 void *
108  const struct registry_data *data)
109 {
110  gdb_assert (data->index < fields->num_data);
111  return fields->data[data->index];
112 }
void registry_container_free_data(struct registry_data_registry *data_registry, registry_callback_adaptor adaptor, struct registry_container *container, struct registry_fields *fields)
Definition: registry.c:85
void registry_clear_data(struct registry_data_registry *data_registry, registry_callback_adaptor adaptor, struct registry_container *container, struct registry_fields *fields)
Definition: registry.c:55
void xfree(void *)
Definition: common-utils.c:97
struct registry_data_registration * next
Definition: registry.h:109
unsigned num_registrations
Definition: registry.h:115
void registry_set_data(struct registry_fields *fields, const struct registry_data *data, void *value)
Definition: registry.c:98
struct registry_data_registration * registrations
Definition: registry.h:114
unsigned num_data
Definition: registry.h:72
struct registry_data * data
Definition: registry.h:108
void ** data
Definition: registry.h:71
registry_data_callback save
Definition: registry.h:102
#define gdb_assert(expr)
Definition: gdb_assert.h:33
void registry_alloc_data(struct registry_data_registry *registry, struct registry_fields *fields)
Definition: registry.c:46
void(* registry_callback_adaptor)(registry_data_callback func, struct registry_container *container, void *data)
Definition: registry.h:131
void * registry_data(struct registry_fields *fields, const struct registry_data *data)
Definition: registry.c:107
Definition: value.c:172
unsigned index
Definition: registry.h:101
const struct registry_data * register_data_with_cleanup(struct registry_data_registry *registry, registry_data_callback save, registry_data_callback free)
Definition: registry.c:23
registry_data_callback free
Definition: registry.h:103
void(* registry_data_callback)(struct registry_container *, void *)
Definition: registry.h:97