gdb/registry.c - gdb
Functions defined
Source code
- #include "defs.h"
- #include "registry.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;
-
- 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);
-
- 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]);
-
- 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];
- }