[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH 2/2] gobject: Turn FBuffer into a GByteArray *



On Fri, Jan 20, 2012 at 05:58:38PM +0000, Matthew Booth wrote:
> This change is intended to improve language bindings by turning <field> and
> <field>_size in a struct into a single array object. I had wanted to just turn
> it into a GByteArray embedded in the struct, but this caused gjs to segfault.
> The docs suggest a GByteArray should be allocated with g_byte_array_new(), so I
> did that and it worked fine. I guess something somewhere assumes it's an
> allocated object.
> 
> Incidentally, the perl bindings segfault attempting to access the array either
> way. At this stage I suspect the perl bindings rather than my code. Valgrind
> shows nothing untoward happening before the crash, and the memory when inspected
> with gdb contains exactly what is expected.
> ---
>  generator/generator_gobject.ml |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/generator/generator_gobject.ml b/generator/generator_gobject.ml
> index 2b151c6..4779f23 100644
> --- a/generator/generator_gobject.ml
> +++ b/generator/generator_gobject.ml
> @@ -204,8 +204,7 @@ let generate_gobject_header_structs () =
>          | n, FString ->
>            pr "  gchar *%s;\n" n
>          | n, FBuffer ->
> -          pr "  guint8 *%s;\n" n;
> -          pr "  guint32 %s_size;\n" n
> +          pr "  GByteArray *%s;\n" n
>          | n, FUUID ->
>            pr "  /* The next field is NOT nul-terminated, be careful when printing it: */\n";
>            pr "  gchar %s[32];\n" n
> @@ -811,9 +810,10 @@ let generate_gobject_c_methods () =
>                indent src n dst n src n
>            | n, FBuffer ->
>              pr "%sif (%s%s) {\n" indent src n;
> -            pr "%s  memcpy(%s%s, %s%s, %s%s_len);\n"
> +            pr "%s  %s%s = g_byte_array_sized_new(%s%s_len);\n"
> +              indent dst n src n;
> +            pr "%s  g_byte_array_append(%s%s, %s%s, %s%s_len);\n"
>                indent dst n src n src n;
> -            pr "%s  %s%s_size = %s%s_len;\n" indent dst n src n;
>              pr "%s}\n" indent
>          ) (cols_of_struct typ)
>        in
> -- 
> 1.7.7.5

ACK.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]