[perl-Glib] Ensure timely destruction of initial wrapper of custom subclasses
- From: Torsten SchÃnfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Glib] Ensure timely destruction of initial wrapper of custom subclasses
- Date: Thu, 7 Feb 2013 23:56:58 +0000 (UTC)
commit eb6ff1b1e6e7fb5dcef4aa131cae9d95d2049460
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date: Fri Feb 8 00:56:27 2013 +0100
Ensure timely destruction of initial wrapper of custom subclasses
Alter the init function for custom subclasses (the one which invokes the sub
INIT_INSTANCE) so that the initial SV wrapper is destroyed as soon as it is not
needed anymore, rather than when the next FREETMPS happens. This makes the ref
counting more predictable but should otherwise not be observable.
GType.xs | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/GType.xs b/GType.xs
index fdaad68..d59ee18 100644
--- a/GType.xs
+++ b/GType.xs
@@ -1756,7 +1756,8 @@ gperl_type_instance_init (GObject * instance)
SV **slot;
g_assert (stash != NULL);
- obj = sv_2mortal (gperl_new_object (instance, FALSE));
+ /* this SV will be freed below either via sv_2mortal or explicitly. */
+ obj = gperl_new_object (instance, FALSE);
/* we need to re-bless the wrapper because classes change
* during construction of an object. */
sv_bless (obj, stash);
@@ -1775,11 +1776,13 @@ gperl_type_instance_init (GObject * instance)
ENTER;
SAVETMPS;
PUSHMARK (SP);
- XPUSHs (obj);
+ XPUSHs (sv_2mortal (obj)); /* mortalize the SV */
PUTBACK;
call_sv ((SV *)GvCV (*slot), G_VOID|G_DISCARD);
FREETMPS;
LEAVE;
+ } else {
+ SvREFCNT_dec (obj); /* free the SV explicitly */
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]