2009/9/6 Pekka Enberg <penb...@cs.helsinki.fi>:

> OK, so why is that better than using calloc()? Here's an alternative
> patch that fixes the problem as well.
>
>                        Pekka
>
> >From 2f0fef1b8cc3c9b9b14a2470195d088c41e60e73 Mon Sep 17 00:00:00 2001
> From: Pekka Enberg <penb...@cs.helsinki.fi>
> Date: Sun, 6 Sep 2009 11:27:24 +0300
> Subject: [PATCH] vm: Initialize interface methods properly
>
> Signed-off-by: Pekka Enberg <penb...@cs.helsinki.fi>
> ---
>  vm/method.c |   20 ++++++++++++++------
>  1 files changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/vm/method.c b/vm/method.c
> index e6512c2..bfb8948 100644
> --- a/vm/method.c
> +++ b/vm/method.c
> @@ -18,6 +18,16 @@
>  #include "jit/args.h"
>  #include "jit/cu-mapping.h"
>
> +static void init_abstract_method(struct vm_method *vmm)
> +{
> +       /* Hm, we're now modifying a cafebabe structure. */
> +       vmm->code_attribute.max_stack = 0;
> +       vmm->code_attribute.max_locals = vmm->args_count;
> +
> +       vmm->line_number_table_attribute.line_number_table_length = 0;
> +       vmm->line_number_table_attribute.line_number_table = NULL;
> +}
> +
>  int vm_method_init(struct vm_method *vmm,
>        struct vm_class *vmc, unsigned int method_index)
>  {
> @@ -88,12 +98,7 @@ int vm_method_init(struct vm_method *vmm,
>         * with loading attributes which native and abstract methods don't 
> have.
>         */
>        if (vm_method_is_native(vmm) || vm_method_is_abstract(vmm)) {
> -               /* Hm, we're now modifying a cafebabe structure. */
> -               vmm->code_attribute.max_stack = 0;
> -               vmm->code_attribute.max_locals = vmm->args_count;
> -
> -               vmm->line_number_table_attribute.line_number_table_length = 0;
> -               vmm->line_number_table_attribute.line_number_table = NULL;
> +               init_abstract_method(vmm);
>                return 0;
>        }
>
> @@ -158,6 +163,9 @@ int vm_method_init_from_interface(struct vm_method *vmm, 
> struct vm_class *vmc,
>
>        vmm->args_count = interface_method->args_count;
>        vmm->is_vm_native = false;
> +
> +       init_abstract_method(vmm);
> +
>        return 0;
>  }

ACK!

Acked-by: Vegard Nossum <vegard.nos...@gmail.com>

It's better because we don't initialize the same fields over and over.
Perhaps this is premature optimization, but it's just much more
elegant to not do more than we really need. Calloc() is a big
sledgehammer which can actually obscure other bugs in the future
(because valgrind thinks it's been initialized "properly" -- what if
we didn't want zero there?)


Vegard

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to