changeset 15104:53f7a4a8ad2a

[gaim-migrate @ 17889] Fix some leakage in the perl loader bindings by using a special typedef to handle functions that return g_malloc()-ed values. Thanks to the Gtk-Perl folks for any easy way to do this. Fix gaim_gtk_sound_get_event_label() to correctly indicate that the retval is a constant. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 04 Dec 2006 03:49:34 +0000
parents 37a792fc9800
children cb7eef7bf550
files gtk/gtksound.c gtk/gtksound.h gtk/plugins/perl/common/GtkIMHtml.xs gtk/plugins/perl/common/GtkSound.xs gtk/plugins/perl/common/GtkStatusBox.xs gtk/plugins/perl/common/GtkUtils.xs libgaim/plugins/perl/common/Log.xs libgaim/plugins/perl/common/Util.xs libgaim/plugins/perl/common/XMLNode.xs libgaim/plugins/perl/common/module.h libgaim/plugins/perl/common/typemap
diffstat 11 files changed, 44 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/gtksound.c	Mon Dec 04 03:44:42 2006 +0000
+++ b/gtk/gtksound.c	Mon Dec 04 03:49:34 2006 +0000
@@ -242,7 +242,7 @@
 	return sounds[event].pref;
 }
 
-char *
+const char *
 gaim_gtk_sound_get_event_label(GaimSoundEventID event)
 {
 	if(event >= GAIM_NUM_SOUNDS)
--- a/gtk/gtksound.h	Mon Dec 04 03:44:42 2006 +0000
+++ b/gtk/gtksound.h	Mon Dec 04 03:49:34 2006 +0000
@@ -46,7 +46,7 @@
  * @param event The event.
  * @return The label.
  */
-char *gaim_gtk_sound_get_event_label(GaimSoundEventID event);
+const char *gaim_gtk_sound_get_event_label(GaimSoundEventID event);
 
 /**
  * Gets GTK+ sound UI ops.
--- a/gtk/plugins/perl/common/GtkIMHtml.xs	Mon Dec 04 03:44:42 2006 +0000
+++ b/gtk/plugins/perl/common/GtkIMHtml.xs	Mon Dec 04 03:49:34 2006 +0000
@@ -60,7 +60,7 @@
 /* This can't work at the moment since I don't have a typemap for Gtk::Widget.
  * I thought about using the one from libgtk2-perl but wasn't sure how to go
  * about doing that.
-char *
+gchar_own *
 gtk_imhtml_get_markup_range(imhtml, start, end)
 	Gaim::GtkUI::IMHtml imhtml
 	Gtk::TextIter start
@@ -70,7 +70,7 @@
 /* This can't work at the moment since I don't have a typemap for Gtk::Widget.
  * I thought about using the one from libgtk2-perl but wasn't sure how to go
  * about doing that.
-char *
+gchar_own *
 gtk_imhtml_get_text(imhtml, start, end)
 	Gaim::GtkUI::IMHtml imhtml
 	Gtk::TextIter start
@@ -215,19 +215,19 @@
 gtk_imhtml_get_format_functions(imhtml)
 	Gaim::GtkUI::IMHtml imhtml
 
-char *
+gchar_own *
 gtk_imhtml_get_current_fontface(imhtml)
 	Gaim::GtkUI::IMHtml imhtml
 
-char *
+gchar_own *
 gtk_imhtml_get_current_forecolor(imhtml)
 	Gaim::GtkUI::IMHtml imhtml
 
-char *
+gchar_own *
 gtk_imhtml_get_current_backcolor(imhtml)
 	Gaim::GtkUI::IMHtml imhtml
 
-char *
+gchar_own *
 gtk_imhtml_get_current_background(imhtml)
 	Gaim::GtkUI::IMHtml imhtml
 
@@ -303,7 +303,7 @@
 gtk_imhtml_font_grow(imhtml)
 	Gaim::GtkUI::IMHtml imhtml
 
-char *
+gchar_own *
 gtk_imhtml_get_markup(imhtml)
 	Gaim::GtkUI::IMHtml imhtml
 
--- a/gtk/plugins/perl/common/GtkSound.xs	Mon Dec 04 03:44:42 2006 +0000
+++ b/gtk/plugins/perl/common/GtkSound.xs	Mon Dec 04 03:49:34 2006 +0000
@@ -7,7 +7,7 @@
 gaim_gtk_sound_get_event_option(event)
 	Gaim::SoundEventID event
 
-char *
+const char *
 gaim_gtk_sound_get_event_label(event)
 	Gaim::SoundEventID event
 
--- a/gtk/plugins/perl/common/GtkStatusBox.xs	Mon Dec 04 03:44:42 2006 +0000
+++ b/gtk/plugins/perl/common/GtkStatusBox.xs	Mon Dec 04 03:49:34 2006 +0000
@@ -45,6 +45,6 @@
 gtk_gaim_status_box_get_buddy_icon(status_box)
 	Gaim::GtkUI::StatusBox status_box
 
-char *
+gchar_own *
 gtk_gaim_status_box_get_message(status_box)
 	Gaim::GtkUI::StatusBox status_box
--- a/gtk/plugins/perl/common/GtkUtils.xs	Mon Dec 04 03:44:42 2006 +0000
+++ b/gtk/plugins/perl/common/GtkUtils.xs	Mon Dec 04 03:49:34 2006 +0000
@@ -10,7 +10,7 @@
 void
 gaim_gtk_load_accels()
 
-char *
+gchar_own *
 gaim_gtk_convert_buddy_icon(plugin, path)
 	Gaim::Plugin plugin
 	const char * path
--- a/libgaim/plugins/perl/common/Log.xs	Mon Dec 04 03:44:42 2006 +0000
+++ b/libgaim/plugins/perl/common/Log.xs	Mon Dec 04 03:49:34 2006 +0000
@@ -21,7 +21,7 @@
 gaim_log_free(log)
 	Gaim::Log log
 
-char *
+gchar_own *
 gaim_log_get_log_dir(type, name, account)
 	Gaim::LogType type
 	const char *name
@@ -83,7 +83,7 @@
 		XPUSHs(sv_2mortal(gaim_perl_bless_object(l->data, "Gaim::ListEntry")));
 	}
 
-char *
+gchar_own *
 gaim_log_read(log, flags)
 	Gaim::Log log
 	Gaim::Log::ReadFlags flags
--- a/libgaim/plugins/perl/common/Util.xs	Mon Dec 04 03:44:42 2006 +0000
+++ b/libgaim/plugins/perl/common/Util.xs	Mon Dec 04 03:49:34 2006 +0000
@@ -74,7 +74,7 @@
 gaim_escape_filename(str)
 	const char *str
 
-char *
+gchar_own *
 gaim_fd_get_ip(fd)
 	int fd
 
@@ -104,7 +104,7 @@
 	const char **end
 	GData **attributes
 
-char *
+gchar_own *
 gaim_markup_get_tag_name(tag)
 	const char *tag
 
@@ -114,17 +114,17 @@
 	char **dest_xhtml
 	char **dest_plain
 
-char *
+gchar_own *
 gaim_markup_linkify(str)
 	const char *str
 
-char *
+gchar_own *
 gaim_markup_slice(str, x, y)
 	const char *str
 	guint x
 	guint y
 
-char *
+gchar_own *
 gaim_markup_strip_html(str)
 	const char *str
 
@@ -147,11 +147,11 @@
 gaim_program_is_valid(program)
 	const char *program
 
-char *
+gchar_own *
 gaim_str_add_cr(str)
 	const char *str
 
-char *
+gchar_own *
 gaim_str_binary_to_ascii(binary, len)
 	const unsigned char *binary
 	guint len
@@ -166,11 +166,11 @@
 	const char *s
 	const char *x
 
-char *
+gchar_own *
 gaim_str_seconds_to_string(sec)
 	guint sec
 
-char *
+gchar_own *
 gaim_str_size_to_units(size)
 	size_t size
 
@@ -187,7 +187,7 @@
 	long *tz_off
 	const char **rest
 
-gchar *
+gchar_own *
 gaim_strcasereplace(string, delimiter, replacement)
 	const char *string
 	const char *delimiter
@@ -198,17 +198,17 @@
 	const char *haystack
 	const char *needle
 
-gchar *
+gchar_own *
 gaim_strdup_withhtml(src)
 	const gchar *src
 
-gchar *
+gchar_own *
 gaim_strreplace(string, delimiter, replacement)
 	const char *string
 	const char *delimiter
 	const char *replacement
 
-char *
+gchar_own *
 gaim_text_strip_mnemonic(in)
 	const char *in
 
@@ -229,7 +229,7 @@
 gaim_unescape_filename(str)
 	const char *str
 
-char *
+gchar_own *
 gaim_unescape_html(html)
 	const char *html
 
--- a/libgaim/plugins/perl/common/XMLNode.xs	Mon Dec 04 03:44:42 2006 +0000
+++ b/libgaim/plugins/perl/common/XMLNode.xs	Mon Dec 04 03:49:34 2006 +0000
@@ -36,7 +36,7 @@
 	const char *name
 	const char *xmlns
 
-char *
+gchar_own *
 xmlnode_get_data(node)
 	Gaim::XMLNode node
 
@@ -77,12 +77,12 @@
 	const char *attr
 	const char *value
 
-char *
+gchar_own *
 xmlnode_to_formatted_str(node, len)
 	Gaim::XMLNode node
 	int *len
 
-char *
+gchar_own *
 xmlnode_to_str(node, len)
 	Gaim::XMLNode node
 	int *len
--- a/libgaim/plugins/perl/common/module.h	Mon Dec 04 03:44:42 2006 +0000
+++ b/libgaim/plugins/perl/common/module.h	Mon Dec 04 03:49:34 2006 +0000
@@ -271,3 +271,6 @@
 
 /* other */
 typedef void *				Gaim__Handle;
+
+typedef gchar gchar_own;
+
--- a/libgaim/plugins/perl/common/typemap	Mon Dec 04 03:44:42 2006 +0000
+++ b/libgaim/plugins/perl/common/typemap	Mon Dec 04 03:49:34 2006 +0000
@@ -16,6 +16,7 @@
 char **					T_PTR
 gchar					T_IV
 gchar *					T_PV
+gchar_own *				T_GCHAR_OWN
 guchar					T_IV
 guchar *				T_PTR
 guchar **				T_PTR
@@ -195,3 +196,12 @@
 
 T_GaimObj
 	$arg = gaim_perl_bless_object($var, \"$type\");
+
+T_GCHAR_OWN
+	/* used when we can directly own the returned string. */
+	/* we have to copy in the case when perl's malloc != gtk's malloc,
+	 * so best copy all the time. */
+	sv_setpv ((SV*)$arg, $var);
+	SvUTF8_on ($arg);
+	g_free ($var);
+