From 9545397540a80010def7b2d6028715faf1ec0506 Mon Sep 17 00:00:00 2001 From: mescalinum Date: Fri, 28 Aug 2009 16:46:43 +0000 Subject: use Tcl reference counters properly -- solved segfaults svn path=/trunk/externals/tclpd/; revision=12129 --- tcl.i | 10 ++++++++-- tcl_extras.cxx | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tcl.i b/tcl.i index a1d1af2..aef4c08 100644 --- a/tcl.i +++ b/tcl.i @@ -133,10 +133,12 @@ int tcl_to_pd(Tcl_Obj *input, t_atom *output) { int pd_to_tcl(t_atom *input, Tcl_Obj **output) { Tcl_Obj* tcl_t_atom[2]; - /*post("pd_to_tcl got an atom of type %d (%s)", +#ifdef DEBUG + post("pd_to_tcl: atom type = %d (%s)", input->a_type, input->a_type == A_FLOAT ? "A_FLOAT" : input->a_type == A_SYMBOL ? "A_SYMBOL" : - input->a_type == A_POINTER ? "A_POINTER" : "?");*/ + input->a_type == A_POINTER ? "A_POINTER" : "?"); +#endif switch (input->a_type) { case A_FLOAT: { tcl_t_atom[0] = Tcl_NewStringObj("float", -1); @@ -159,7 +161,11 @@ int pd_to_tcl(t_atom *input, Tcl_Obj **output) { break; } } +#ifdef DEBUG + post("pd_to_tcl: atom value = \"%s\"", Tcl_GetStringFromObj(tcl_t_atom[1], 0)); +#endif *output = Tcl_NewListObj(2, &tcl_t_atom[0]); + Tcl_IncrRefCount(*output); return TCL_OK; } diff --git a/tcl_extras.cxx b/tcl_extras.cxx index 1551c7f..e277e60 100644 --- a/tcl_extras.cxx +++ b/tcl_extras.cxx @@ -17,21 +17,22 @@ static void *tclpd_init (t_symbol *classsym, int ac, t_atom *at) { t_tcl *self = (t_tcl *)pd_new(qlass); char s[32]; sprintf(s,"pd%06lx",cereal++); - self->self = Tcl_NewStringObj(s,strlen(s)); - object_table[string(s)] = (t_pd*)self; + self->self = Tcl_NewStringObj(s, -1); Tcl_IncrRefCount(self->self); + object_table[string(s)] = (t_pd*)self; Tcl_Obj *av[ac+2]; - av[0] = Tcl_NewStringObj(name,strlen(name)); + av[0] = Tcl_NewStringObj(name, -1); + Tcl_IncrRefCount(av[0]); av[1] = self->self; for(int i=0; i outlet_number Tcl_AppendToObj(av[1],"_",1); Tcl_AppendToObj(av[1],s->s_name,strlen(s->s_name)); // selector + Tcl_IncrRefCount(av[1]); for(int i=0; i