On Apr 16, 2009, at 10:21 PM, Kurt Smith wrote:

> On Thu, Apr 16, 2009 at 11:54 PM, Kurt Smith <[email protected]>  
> wrote:
>
>
>>
>> See
>>
>> http://trac.cython.org/cython_trac/ticket/284
>>
>
> Here's a testcase.
>
> diff -r 6fc636aebe32 -r 1097ad309db6 tests/run/cdef_setitem_T284.pyx
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/tests/run/cdef_setitem_T284.pyx   Fri Apr 17 00:15:48 2009 -0500
> @@ -0,0 +1,17 @@
> +__doc__ = u'''
> +>>> no_cdef()
> +>>> with_cdef()
> +'''
> +def no_cdef():
> +    lst = range(11)
> +    ob = 10L
> +    lst[ob] = -10
> +    dd = {}
> +    dd[ob] = -10
> +
> +def with_cdef():
> +    cdef list lst = range(11)
> +    ob = 10L
> +    lst[ob] = -10
> +    cdef dict dd = {}
> +    dd[ob] = -10
>

Thanks.

> And here's a trivial fix -- it seems hacky and if there's a better way
> to do it please say so...
>
> diff -r 6fc636aebe32 -r 1097ad309db6 Cython/Compiler/ExprNodes.py
> --- a/Cython/Compiler/ExprNodes.py      Thu Apr 16 19:10:51 2009 -0700
> +++ b/Cython/Compiler/ExprNodes.py      Fri Apr 17 00:15:48 2009 -0500
> @@ -1858,6 +1858,7 @@ class IndexNode(ExprNode):
>                  function = "PyDict_SetItem"
>              elif self.base.type is list_type:
>                  function = "PyList_SetItem"
> +                index_code = "PyInt_AsSsize_t(%s)" % index_code
>              # don't use PyTuple_SetItem(), as we'd normally get a
>              # TypeError when changing a tuple, while  
> PyTuple_SetItem()
>              # would allow updates

This will actually raise the wrong kind of error for non-int objects-- 
perhaps we should just remove the entire line? Optimized setting/ 
getting still happens with int indices.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to