perf annotate: Introduce ->free() method in ins_ops
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 12 May 2012 16:26:20 +0000 (13:26 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 12 May 2012 16:26:20 +0000 (13:26 -0300)
So that we don't special case disasm_line__free, allowing each
instruction class to provide an specialized destructor, like is needed
for 'lock'.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-xxw4vs5n077tf35jsvjzylhb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/annotate.c
tools/perf/util/annotate.h

index 1dce09874d9388ff316b3d3ad0c7ea3823bd4522..8069dfb5ba7774bd89afd8e78b36f3faea15e907 100644 (file)
@@ -21,6 +21,14 @@ const char   *disassembler_style;
 static struct ins *ins__find(const char *name);
 static int disasm_line__parse(char *line, char **namep, char **rawp);
 
+static void ins__delete(struct ins_operands *ops)
+{
+       free(ops->source.raw);
+       free(ops->source.name);
+       free(ops->target.raw);
+       free(ops->target.name);
+}
+
 static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size,
                              struct ins_operands *ops)
 {
@@ -192,7 +200,15 @@ static int lock__scnprintf(struct ins *ins, char *bf, size_t size,
                                        size - printed, ops->locked.ops);
 }
 
+static void lock__delete(struct ins_operands *ops)
+{
+       free(ops->locked.ops);
+       free(ops->target.raw);
+       free(ops->target.name);
+}
+
 static struct ins_ops lock_ops = {
+       .free      = lock__delete,
        .parse     = lock__parse,
        .scnprintf = lock__scnprintf,
 };
@@ -542,14 +558,10 @@ void disasm_line__free(struct disasm_line *dl)
 {
        free(dl->line);
        free(dl->name);
-       if (dl->ins && dl->ins->ops == &lock_ops) {
-               free(dl->ops.locked.ops);
-       } else {
-               free(dl->ops.source.raw);
-               free(dl->ops.source.name);
-       }
-       free(dl->ops.target.raw);
-       free(dl->ops.target.name);
+       if (dl->ins && dl->ins->ops->free)
+               dl->ins->ops->free(&dl->ops);
+       else
+               ins__delete(&dl->ops);
        free(dl);
 }
 
index b79d3260647c6d9a25d64bb372a77e1575777050..78a5692dd718d46e7e1b4b8e453cb19659850d20 100644 (file)
@@ -32,6 +32,7 @@ struct ins_operands {
 };
 
 struct ins_ops {
+       void (*free)(struct ins_operands *ops);
        int (*parse)(struct ins_operands *ops);
        int (*scnprintf)(struct ins *ins, char *bf, size_t size,
                         struct ins_operands *ops);