aboutsummaryrefslogtreecommitdiff
path: root/tcl_class.c
diff options
context:
space:
mode:
authormescalinum <mescalinum@users.sourceforge.net>2011-10-13 19:16:25 +0000
committermescalinum <mescalinum@users.sourceforge.net>2011-10-13 19:16:25 +0000
commitc87bf3d9569cb2b40cd449fe19757fa7a5ce4bc5 (patch)
tree6fc1f7c9b80bb3f85cdb060079e59179a72d4fc8 /tcl_class.c
parent60745f7898be9a36bda18f94ad98a592f4b3fce9 (diff)
add comments to clarify weird handling of reference counts
svn path=/trunk/externals/loaders/tclpd/; revision=15584
Diffstat (limited to 'tcl_class.c')
-rw-r--r--tcl_class.c18
1 files changed, 13 insertions, 5 deletions
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; i<ac; i++) {
+ // NOTE: pd_to_tcl already calls Tcl_IncrRefCount
+ // so there is no need to call it here:
+
if(pd_to_tcl(&at[i], &av[2+i]) == TCL_ERROR) {
#ifdef DEBUG
- post("pd_to_tcl: tclpd_new: failed during conversion. check memory leaks!");
+ post("tclpd_new: failed conversion (pd_to_tcl)");
#endif
goto error;
}
}
+
// call constructor
if(Tcl_EvalObjv(tcl_for_pd, ac+2, av, 0) != TCL_OK) {
goto error;
}
+ // decrement reference counter
for(int i = 0; i < (ac+2); i++)
Tcl_DecrRefCount(av[i]);
@@ -260,6 +267,7 @@ void tclpd_free(t_tcl* x) {
Tcl_DecrRefCount(av[0]);
Tcl_DecrRefCount(av[1]);
+ // here ends the lifetime of x->classname and x->self
Tcl_DecrRefCount(x->self);
Tcl_DecrRefCount(x->classname);
#ifdef DEBUG