[Numpy-discussion] fromiter + dtype='S' -> Python crash

Zbyszek Szmek zbyszek at in.waw.pl
Fri Mar 14 09:45:18 EDT 2008


On Thu, Mar 13, 2008 at 05:44:54PM -0400, Alan G Isaac wrote:
> Looks like I misunderstood your question:
> you want an **array** of strings?
> In principle you should be able to use ``fromiter``,
> I believe, but it does not work.  BUG? (Crasher.)
> 
> >>> import numpy as N
> >>> x = [1,2,3]
> >>> fmt="%03d"
> >>> N.fromiter([xi for xi in x],dtype='S')
> Python crashes.

It crashes indeed. The problem seems to be with dtype, the element size is taken to be
  elsize = dtype->elsize
which is 0 when called with dtype='S'!

Afterwards, in the line:
    if (elcount <= (intp)((~(size_t)0) / elsize))
a 'Floating point exception' is generated. 

Two questions:
1. why is is it a _floating point_ exception? The variables in question are ints,
   and the relevant line in disassembly looks like:
   0xb7b7a413 <PyArray_FromIter+451>:	divl   0xffffffd8(%ebp)

   The string 'Floating point exception' comes from libc, I think, but it is imprecise.

   A simple program:
   int main(void){ return 3/0; };
   gives the same message.

2. what does dtype with dtype.elsize==0 mean? Should it be allowed at all?
   If it is sometimes valid, then PyArray_FromIter should be fixed.


Cheers,
Zbyszek



More information about the NumPy-Discussion mailing list