This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 4/7] [python] API for macros: Add methods to get a gdb.Macro.
- From: Matt Rice <ratmice at gmail dot com>
- To: pmuldoon at redhat dot com
- Cc: Tom Tromey <tromey at redhat dot com>, gdb-patches at sourceware dot org
- Date: Thu, 1 Sep 2011 15:56:48 -0700
- Subject: Re: [PATCH 4/7] [python] API for macros: Add methods to get a gdb.Macro.
- References: <1314198654-9008-1-git-send-email-ratmice@gmail.com> <1314198654-9008-5-git-send-email-ratmice@gmail.com> <m3k49vt5jc.fsf@redhat.com> <m3pqjmbxvu.fsf@fleche.redhat.com> <m3d3fmr6e4.fsf@redhat.com> <m34o0yr63g.fsf@redhat.com>
On Tue, Aug 30, 2011 at 1:34 PM, Phil Muldoon <pmuldoon@redhat.com> wrote:
> Phil Muldoon <pmuldoon@redhat.com> writes:
>
>> Tom Tromey <tromey@redhat.com> writes:
>>
>>>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
>>>
>>> Phil> I think this should return a Tuple. ?Tuples are immutable, and unless
>>> Phil> you for see a use for the user to manipulate the List, we should guard
>>> Phil> against it. ?If you agree, please alter stpy_macros too.
>>>
>>> Using a tuple means you have to iterate twice -- once to count the
>>> objects and once to make the tuple.
>>
>> You can use a list, and then convert it to a tuple:
>>
>> PyList_AsTuple
>>
>> We already use the above.
>>
>> If you wanted to, you could use PyTuple_Ruse, as long as there is
>> one reference to the tuple.
>
> Apologies for the typos, but the above should read:
>
> ?If you wanted too, you could use PyTuple_Resize, as long as there is
> ?only one reference to the tuple.
I will try these out, (convert list->tuple and PyTuple_Resize()),
but PyTuple_Resize is going to use realloc, which could end up moving it...
As Tom mentioned, we create a new list every time, so really its not
going to foul us up if the user does modify it.
What would be preferred is an immutable list with a constant time
append only exposed to the c api.
but python doesn't really have one of these.
I'll give it a shot and see how it performs, but my gut says list.