[C++-sig] Re: vector_indexing_suite too defensive ...

Raoul Gough RaoulGough at yahoo.co.uk
Tue Sep 30 13:08:45 CEST 2003


"Joel de Guzman" <djowel at gmx.co.uk> writes:

> Raoul Gough <RaoulGough at yahoo.co.uk> wrote:
>> "Joel de Guzman" <djowel at gmx.co.uk> writes:
>> 
>>> Mike Thompson <mike.thompson at day8.com.au> wrote:
>> [snip]
>>>> The IndexError arises because vector_indexing_suite defends against
>>>> an slice index being too big, rather than the python list approach
>>>> which regards a slice index > len(L) as equal to len(L).  So, the
>>>> line of padOrChop() which says:
>>>> 
>>>>     lst[size:] = [padValue] * diff
>>>> 
>>>> causes an exception when size > len(lst).
>>>> 
>>>> Should vector_indexing_suite be altered to give behaviour more like
>>>> that of lists in this regard?
>>> 
>>> It should. I think you uncovered a vector_indexing_suite bug. I'll
>>> correct this as soon as I can.
>> 
>> Hi Joel,
>> 
>> You might find the PySlice_GetIndices function useful - it take a
>> Python slice object and a container length and returns normalized
>> start and stop values (even handling negative indices, IIRC). At a
>> guess, this is probably how the Python list works internally too.
>
> I *was* using PySlice_GetIndices. The problem was (if I'm not mistaken),
> is that it does not handle non-integer inteces. Correct me if I'm wrong.
> For example, I have a case where the indexes are dates that I must convert
> to a valid index.

Well, it only works for slices, which (AFAIK) rules out non-integer
values anyway. I'm confused now about what the original problem was,
because I think using PySlice_GetIndices would already rule out any
problems with lst[99999:] and so on. Problems with lst[99999]
(i.e. not a slice) are a different matter, and even Python lists barf
on indexes out of range here.

-- 
Raoul Gough.
(setq dabbrev-case-fold-search nil)





More information about the Cplusplus-sig mailing list