public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
From: Syd Polk <spolk@apple.com>
To: Daniel Jacobowitz <drow@mvista.com>
Cc: gdb-patches@sources.redhat.com, insight@sources.redhat.com,
	keiths@cygnus.com, Elena Zannoni <ezannoni@cygnus.com>
Subject: Re: [RFA] Sorting symbols.  Again.
Date: Wed, 30 Jan 2002 14:53:00 -0000	[thread overview]
Message-ID: <2626D7DE-15D4-11D6-99A6-0050E4C09301@apple.com> (raw)
In-Reply-To: <20020130173735.A9126@nevyn.them.org>


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

  reply	other threads:[~2002-01-30 22:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-29 21:54 Daniel Jacobowitz
2002-01-30 14:01 ` Syd Polk
2002-01-30 14:37   ` Daniel Jacobowitz
2002-01-30 14:53     ` Syd Polk [this message]
2002-01-30 20:54 ` Daniel Jacobowitz
2002-01-31 10:19   ` Syd Polk
2002-02-10 19:17     ` Elena Zannoni
2002-02-06 10:27   ` Keith Seitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2626D7DE-15D4-11D6-99A6-0050E4C09301@apple.com \
    --to=spolk@apple.com \
    --cc=drow@mvista.com \
    --cc=ezannoni@cygnus.com \
    --cc=gdb-patches@sources.redhat.com \
    --cc=insight@sources.redhat.com \
    --cc=keiths@cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).