[Numpy-discussion] fromfile() -- aarrgg!

Christopher Barker Chris.Barker at noaa.gov
Tue Jan 12 13:32:10 EST 2010

Pauli Virtanen wrote:
> ma, 2010-01-11 kello 16:11 -0800, Christopher Barker kirjoitti:
> [clip]
>> "If no conversion is performed, zero is returned and the value of nptr 
>> is stored in the location referenced by endptr."
>> off do do some more testing, but I guess that means that those pointers 
>> need to be checked after the call, to see if a conversion was generated.
>> Am I right?
> Yes, that's how strtod() is typically used.
> NumPyOS_ascii_ftolf already checks that,

no, I don't' think it does, but it does pass the nifo through, so its 
API should be the same as PyOS_ascii_ftolf which is the same as 
strftolf(), which makes sense.

> but it seems to me that
> fromstr_next_element or possibly fromstr does not.

The problem is fromstr -- it changes the symantics, assigning the value 
to a pointer passed in, and returning an error code -- except it doesn't 
actually check for an error -- it always returns 0:

static int
@fname at _fromstr(char *str, @type@ *ip, char **endptr, PyArray_Descr 
     double result;
     result = NumPyOS_ascii_strtod(str, endptr);
     *ip = (@type@) result;
     return 0;

so the errors are getting lost in the shuffle: This implies that 
fromstring/fromfile are the only things using it -- unless someone has 
seen similar bad behaviour anywhere else.

> Welcome to the wonderful world of C ;)

yup -- which is why I haven't worked out a fix yet...



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the NumPy-Discussion mailing list