From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14469 invoked by alias); 30 Jan 2002 22:53:19 -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 14406 invoked from network); 30 Jan 2002 22:53:18 -0000 Received: from unknown (HELO mail-out1.apple.com) (17.254.0.52) by sources.redhat.com with SMTP; 30 Jan 2002 22:53:18 -0000 Received: from mailgate2.apple.com (A17-129-100-225.apple.com [17.129.100.225]) by mail-out1.apple.com (8.11.3/8.11.3) with ESMTP id g0UMrIQ18674; Wed, 30 Jan 2002 14:53:18 -0800 (PST) Received: from scv3.apple.com (scv3.apple.com) by mailgate2.apple.com (Content Technologies SMTPRS 4.2.1) with ESMTP id ; Wed, 30 Jan 2002 14:53:18 -0800 Received: from saxophone (saxophone.apple.com [17.202.41.155]) by scv3.apple.com (8.11.3/8.11.3) with ESMTP id g0UMrH602789; Wed, 30 Jan 2002 14:53:17 -0800 (PST) Date: Wed, 30 Jan 2002 14:53:00 -0000 Subject: Re: [RFA] Sorting symbols. Again. Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v480) Cc: gdb-patches@sources.redhat.com, insight@sources.redhat.com, keiths@cygnus.com, Elena Zannoni To: Daniel Jacobowitz From: Syd Polk In-Reply-To: <20020130173735.A9126@nevyn.them.org> Message-Id: <2626D7DE-15D4-11D6-99A6-0050E4C09301@apple.com> Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.480) X-SW-Source: 2002-01/txt/msg00789.txt.bz2 On Wednesday, January 30, 2002, at 02:37 , Daniel Jacobowitz wrote: > On Wed, Jan 30, 2002 at 02:01:10PM -0800, Syd Polk wrote: > >> 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 :) > + Tcl_ListObjGetElements (NULL, result_ptr->obj_ptr, &list_objc, &list_objv); + new_objv = (Tcl_Obj **) malloc (sizeof (Tcl_Obj *) * list_objc); + memcpy (new_objv, list_objv, sizeof (Tcl_Obj *) * list_objc); This memcpy duplicates Tcl_Obj's without going through approved API. This can screw up refcounting of the individual Tcl_Obj's in the list. > Thanks for the helpful comments. > > -- > Daniel Jacobowitz Carnegie Mellon University > MontaVista Software Debian GNU/Linux Developer > > Syd Polk QA and Integration Manager, Mac OS X Development Tools +1 408 974-0577