From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7025 invoked by alias); 30 Jan 2002 22:37:32 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 6945 invoked from network); 30 Jan 2002 22:37:31 -0000 Received: from unknown (HELO nevyn.them.org) (128.2.145.6) by sources.redhat.com with SMTP; 30 Jan 2002 22:37:31 -0000 Received: from drow by nevyn.them.org with local (Exim 3.34 #1 (Debian)) id 16W3MF-0002R2-00; Wed, 30 Jan 2002 17:37:35 -0500 Date: Wed, 30 Jan 2002 14:37:00 -0000 From: Daniel Jacobowitz To: Syd Polk Cc: gdb-patches@sources.redhat.com, insight@sources.redhat.com, keiths@cygnus.com, Elena Zannoni Subject: Re: [RFA] Sorting symbols. Again. Message-ID: <20020130173735.A9126@nevyn.them.org> Mail-Followup-To: Syd Polk , gdb-patches@sources.redhat.com, insight@sources.redhat.com, keiths@cygnus.com, Elena Zannoni References: <20020130005430.A28900@nevyn.them.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.23i X-SW-Source: 2002-01/txt/msg00787.txt.bz2 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