RE: generic refcounted object perl binding

Another question about wrapper design, in function gperl_new_object() where an new wrapper is newly created:

obj = (SV *)g_object_get_qdata (object, wrapper_quark);

if (!obj) {
    // created a hash
    obj = (SV *)newHV () ;
    _gperl_attach_mg (obj, object);
    g_object_ref (object);

    // created a SV wrapper for the hash
    sv = newRV_noinc (obj);
    sv_bless (sv, stash);

Why don't bless the HV directly, but instead creating another SV wrapping the HV, and bless that SV instead?
Why use noinc to create the wrapper? Shouldn't the SV wrapper holding a reference for HV?


> Date: Tue, 18 Oct 2011 09:35:43 +0200
> From: kaffeetisch gmx de
> To: gtk-perl-list gnome org
> Subject: Re: generic refcounted object perl binding
> On 18.10.2011 04:49, YangXi wrote:
> > Why the SV wrapper for a GObject keeps alive until both are freed?
> This is so that we always hand out an SV referencing the same HV for the
> same GObject. Glib::Object allows you to store your own data directly
> in the referenced hash, and this mechanism makes sure that you will find
> this data again when you look at the same GObject later, with no need to
> store the SV in between.
> _______________________________________________
> gtk-perl-list mailing list
> gtk-perl-list gnome org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]