[LIB]: Optionally pass a new name for the class in class__clone

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2007-02-01 14:09:48 -02:00
parent aab506fdcc
commit e4ad9bb2e8
3 changed files with 10 additions and 5 deletions

View File

@ -1300,7 +1300,7 @@ static struct class *class__new(Dwarf_Die *die)
return self;
}
static void class__delete(struct class *self)
void class__delete(struct class *self)
{
struct class_member *pos;
@ -1334,16 +1334,19 @@ static int type__clone_members(struct type *self, const struct type *from)
return 0;
}
struct class *class__clone(const struct class *from)
struct class *class__clone(const struct class *from,
const char *new_class_name)
{
struct class *self = zalloc(sizeof(*self));
if (self != NULL) {
if (self != NULL) {
memcpy(self, from, sizeof(*self));
if (type__clone_members(&self->type, &from->type) != 0) {
class__delete(self);
self = NULL;
}
if (new_class_name != NULL)
self->type.name = strings__add(new_class_name);
}
return self;

View File

@ -91,7 +91,9 @@ static inline struct tag *class__tag(const struct class *self)
return (struct tag *)self;
}
extern struct class *class__clone(const struct class *from);
extern struct class *class__clone(const struct class *from,
const char *new_class_name);
extern void class__delete(struct class *self);
static inline const char *class__name(const struct class *self)
{

View File

@ -495,7 +495,7 @@ int main(int argc, char *argv[])
size_t savings;
const uint8_t reorg_verbose =
show_reorg_steps ? 2 : global_verbose;
struct class *clone = class__clone(s->class);
struct class *clone = class__clone(s->class, NULL);
if (clone == NULL) {
printf("pahole: out of memory!\n");
return EXIT_FAILURE;