File: 0001-Use-the-correct-allocator-for-caller-allocated-boxed.patch

package info (click to toggle)
libglib-object-introspection-perl 0.009-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 376 kB
  • sloc: ansic: 2,361; perl: 716; makefile: 5
file content (62 lines) | stat: -rw-r--r-- 2,243 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
From: Torsten Schönfeld <kaffeetisch@gmx.de>
Date: Tue, 14 Aug 2012 21:23:35 +0200
Origin: upstream, https://git.gnome.org/browse/perl-Glib-Object-Introspection/commit/?id=1e4f04c1fea19e4d04b0ccf6d7bfc0b353e57562
Bug-Debian: https://bugs.debian.org/736254
Bug-GNOME: https://bugzilla.gnome.org/show_bug.cgi?id=680380
Applied-Upstream: 0.012
Subject: 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 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/gperl-i11n-invoke-c.c b/gperl-i11n-invoke-c.c
index 1b3d57f..6ff6478 100644
--- a/gperl-i11n-invoke-c.c
+++ b/gperl-i11n-invoke-c.c
@@ -284,10 +284,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) {
@@ -295,8 +301,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 ();