This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] Sorting symbols. Again.


On Wed, Jan 30, 2002 at 02:01:10PM -0800, Syd Polk wrote:
> 
> Where is sort_funcVals called from? It it called pretty close to the Tcl 
> layer? If so, you might want to use "lsort -command foo" from the tcl 
> level and implement the comparison command in C. Given that the sort 
> command you are using pares down to a simple strcmp, this would be much 
> cleaner than doing what you are doing.

It's called from gdb_listfuncs.  Are the TCL functions exported by
insight generally available to some kind of user scripts, or can I
change callers?

In fact, I see that one of the two callers already sorts the list
itself.

> You should not have to loop through the objects in list_objv to Incr or 
> Decr their refCounts. Tcl_SetListObj does that automatically. They are 
> created with a refCount of 0; Tcl_SetListObj incrs them to 1. What you 
> are doing is creating them, setting them to 1, calling Tcl_SetListObj 
> (which incrs them to 2), and the decrementing them back to 1.
> 
> Also, it is really, really slimy to create Tcl_Objs without going 
> through Tcl_New*Obj.
> 
> I would much prefer that you duplicate the list, and then call "lsort". 
> Pseudo-code:
> 
> 	Tcl_Obj *commandArray[2];
> 
> 	Tcl_ListObjGetElements (NULL, result_ptr->obj_ptr, &list_objc, 
> &list_objv);
> 	newList = Tcl_NewListObj(list_objc, list_objv);
> 	commandArray[1] = newList;
> 	Tcl_IncrRefCount(newList);
> 	commandArray[0] = Tcl_NewObjFromString("lsort");
> 	Tcl_IncrRefCount(commandArray[0]);
> 	result = Tcl_EvalObjv(interp, 2, commandArray);
> 	Tcl_DecrRefCount(commandArray[0]);
> 	
> 	/* newList now has sorted list. */
> 
> I am not a maintainer, but I worked in the core of Tcl for a couple of 
> years for John O., and doing block allocates of Tcl_Objs is just asking 
> for trouble, and will lead to problems if insight is ever compiled to 
> TCL_MEM_DEBUG, or other things.

I don't think I did anything of the sort; but perhaps I misunderstood
Tcl_SetListObj.  The documentation doesn't say anything about how to
allocate the objv.  The refcount mess was because of using SetListObj,
but I suppose I understand now that creating a new object and then
destroying the old one would have worked out cleaner.  Hopefully the
above will be accepted and I can delete the sort entirely :)

Thanks for the helpful comments.

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]