[perl-Glib-Object-Introspection] Use the correct allocator for caller-allocated boxed out-args
- From: Torsten SchÃnfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Glib-Object-Introspection] Use the correct allocator for caller-allocated boxed out-args
- Date: Thu, 16 Aug 2012 18:48:06 +0000 (UTC)
commit 1e4f04c1fea19e4d04b0ccf6d7bfc0b353e57562
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date: Tue Aug 14 21:23:35 2012 +0200
Use the correct allocator for caller-allocated boxed out-args
Previously, we simply always used malloc(). But for a boxed type, which has an
associated custom free function, this might not be the correct allocator. For
example, GtkTreeIter uses GSlice. Make an extra copy of the malloc()-ed block
to ensure consistency.
https://bugzilla.gnome.org/show_bug.cgi?id=680380
gperl-i11n-invoke-c.c | 22 ++++++++++++++++++++--
1 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/gperl-i11n-invoke-c.c b/gperl-i11n-invoke-c.c
index ba33609..bdced7e 100644
--- a/gperl-i11n-invoke-c.c
+++ b/gperl-i11n-invoke-c.c
@@ -282,10 +282,16 @@ allocate_out_mem (GITypeInfo *arg_type)
{
GIBaseInfo *interface_info;
GIInfoType type;
+ gboolean is_boxed = FALSE;
+ GType gtype = G_TYPE_INVALID;
interface_info = g_type_info_get_interface (arg_type);
g_assert (interface_info);
type = g_base_info_get_type (interface_info);
+ if (GI_IS_REGISTERED_TYPE_INFO (interface_info)) {
+ gtype = get_gtype (interface_info);
+ is_boxed = g_type_is_a (gtype, G_TYPE_BOXED);
+ }
g_base_info_unref (interface_info);
switch (type) {
@@ -293,8 +299,20 @@ allocate_out_mem (GITypeInfo *arg_type)
{
/* No plain g_struct_info_get_size (interface_info) here so
* that we get the GValue override. */
- gsize size = size_of_interface (arg_type);
- return g_malloc0 (size);
+ gsize size;
+ gpointer mem;
+ size = size_of_interface (arg_type);
+ mem = g_malloc0 (size);
+ if (is_boxed) {
+ /* For a boxed type, malloc() might not be the right
+ * allocator. For example, GtkTreeIter uses GSlice.
+ * So use g_boxed_copy() to make a copy of the newly
+ * allocated block using the correct allocator. */
+ gpointer real_mem = g_boxed_copy (gtype, mem);
+ g_free (mem);
+ mem = real_mem;
+ }
+ return mem;
}
default:
g_assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]