[perl-Gtk2] Use Glib's infrastructure for attaching magic
- From: Florian Ragwitz <rafl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Gtk2] Use Glib's infrastructure for attaching magic
- Date: Tue, 7 Dec 2010 19:11:38 +0000 (UTC)
commit 3a0879b397cfa0ddf72734056852ce4a7d62ca85
Author: Florian Ragwitz <rafl debian org>
Date: Thu Nov 25 00:21:39 2010 +0100
Use Glib's infrastructure for attaching magic
Instead of doing it all manually and getting things wrong by allowing only one
PERL_MAGIC_ext at a time or de-referencing the attached structures as something
they aren't, just use the tools Glib provides.
xs/GdkPixbuf.xs | 7 ++++---
xs/GtkCellLayout.xs | 7 ++++---
xs/GtkTreeSortable.xs | 7 ++++---
3 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/xs/GdkPixbuf.xs b/xs/GdkPixbuf.xs
index f03e8fa..e247bea 100644
--- a/xs/GdkPixbuf.xs
+++ b/xs/GdkPixbuf.xs
@@ -85,7 +85,7 @@ newSVGdkPixbufFormat (GdkPixbufFormat * format)
/* Store the original format pointer in the hash so that
SvGdkPixbufFormat can retrieve and return it. */
- sv_magic ((SV*) hv, 0, PERL_MAGIC_ext, (const char *)format, 0);
+ _gperl_attach_mg ((SV*) hv, format);
stash = gv_stashpv ("Gtk2::Gdk::PixbufFormat", TRUE);
return sv_bless ((SV*) newRV_noinc ((SV*) hv), stash);
@@ -96,7 +96,8 @@ SvGdkPixbufFormat (SV * sv)
{
MAGIC *mg;
- if (!gperl_sv_is_defined (sv) || !SvROK (sv) || !(mg = mg_find (SvRV (sv), PERL_MAGIC_ext)))
+ if (!gperl_sv_is_defined (sv) || !SvROK (sv)
+ || !(mg = _gperl_find_mg (SvRV (sv))))
return NULL;
return (GdkPixbufFormat *) mg->mg_ptr;
@@ -1046,7 +1047,7 @@ void
DESTROY (sv)
SV *sv
CODE:
- sv_unmagic (sv, PERL_MAGIC_ext);
+ _gperl_remove_mg (SvRV (sv));
#endif /* 2.2.0 */
diff --git a/xs/GtkCellLayout.xs b/xs/GtkCellLayout.xs
index 8dbae40..9bae738 100644
--- a/xs/GtkCellLayout.xs
+++ b/xs/GtkCellLayout.xs
@@ -160,7 +160,7 @@ create_callback (GtkCellLayoutDataFunc func,
wrapper->destroy = destroy;
data_sv = newSViv (PTR2IV (wrapper));
- sv_magic ((SV *) dummy_cv, 0, PERL_MAGIC_ext, (const char *) data_sv, 0);
+ _gperl_attach_mg ((SV *) dummy_cv, data_sv);
*code_return = code_sv;
*data_return = data_sv;
@@ -506,13 +506,14 @@ DESTROY (SV *code)
MAGIC *mg;
Gtk2PerlCellLayoutDataFunc *wrapper;
CODE:
- if (!gperl_sv_is_defined (code) || !SvROK (code) || !(mg = mg_find (SvRV (code), PERL_MAGIC_ext)))
+ if (!gperl_sv_is_defined (code) || !SvROK (code)
+ || !(mg = _gperl_find_mg (SvRV (code))))
return;
wrapper = INT2PTR (Gtk2PerlCellLayoutDataFunc*, SvIV ((SV *) mg->mg_ptr));
if (wrapper && wrapper->destroy)
wrapper->destroy (wrapper->data);
- sv_unmagic (SvRV (code), PERL_MAGIC_ext);
+ _gperl_remove_mg (SvRV (code));
if (wrapper)
g_free (wrapper);
diff --git a/xs/GtkTreeSortable.xs b/xs/GtkTreeSortable.xs
index 1fd9520..1d377e6 100644
--- a/xs/GtkTreeSortable.xs
+++ b/xs/GtkTreeSortable.xs
@@ -144,7 +144,7 @@ create_callback (GtkTreeIterCompareFunc func,
stuff->destroy = destroy;
my_data = newSViv (PTR2IV (stuff));
- sv_magic ((SV *) dummy, 0, PERL_MAGIC_ext, (const char *) my_data, 0);
+ _gperl_attach_mg ((SV *) dummy, my_data);
*code_return = code;
*data_return = my_data;
@@ -449,13 +449,14 @@ DESTROY (code)
MAGIC *mg;
Gtk2PerlTreeIterCompareFunc *stuff;
CODE:
- if (!gperl_sv_is_defined (code) || !SvROK (code) || !(mg = mg_find (SvRV (code), PERL_MAGIC_ext)))
+ if (!gperl_sv_is_defined (code) || !SvROK (code)
+ || !(mg = _gperl_find_mg (SvRV (code))))
return;
stuff = INT2PTR (Gtk2PerlTreeIterCompareFunc*, SvIV ((SV *) mg->mg_ptr));
if (stuff && stuff->destroy)
stuff->destroy (stuff->data);
- sv_unmagic (SvRV (code), PERL_MAGIC_ext);
+ _gperl_remove_mg (SvRV (code));
if (stuff)
g_free (stuff);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]