From c87bf3d9569cb2b40cd449fe19757fa7a5ce4bc5 Mon Sep 17 00:00:00 2001 From: mescalinum Date: Thu, 13 Oct 2011 19:16:25 +0000 Subject: add comments to clarify weird handling of reference counts svn path=/trunk/externals/loaders/tclpd/; revision=15584 --- tcl_class.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'tcl_class.c') diff --git a/tcl_class.c b/tcl_class.c index 307f4bf..c94952a 100644 --- a/tcl_class.c +++ b/tcl_class.c @@ -193,16 +193,18 @@ t_tcl* tclpd_new(t_symbol* classsym, int ac, t_atom* at) { t_tcl* x = (t_tcl*)pd_new(qlass); x->ninlets = 1 /* qlass->c_firstin ??? */; + x->x_glist = (t_glist*)canvas_getcurrent(); x->classname = Tcl_NewStringObj(name, -1); - Tcl_IncrRefCount(x->classname); - char s[64]; snprintf(s, 64, "tclpd:%s:x%lx", name, objectSequentialId++); x->self = Tcl_NewStringObj(s, -1); - Tcl_IncrRefCount(x->self); - x->x_glist = (t_glist*)canvas_getcurrent(); + // the lifetime of x->classname and x->self is greater than this + // function, hence they get an extra Tcl_IncrRefCount here: + // (see tclpd_free()) + Tcl_IncrRefCount(x->classname); + Tcl_IncrRefCount(x->self); // store in object table (for later lookup) if(!object_table_get(s)) @@ -215,18 +217,23 @@ t_tcl* tclpd_new(t_symbol* classsym, int ac, t_atom* at) { av[1] = x->self; Tcl_IncrRefCount(av[1]); for(int i=0; iclassname and x->self Tcl_DecrRefCount(x->self); Tcl_DecrRefCount(x->classname); #ifdef DEBUG -- cgit v1.2.1