[Python-Dev] various unix platform build/test issues

Neil Schemenauer nas@python.ca
Tue, 18 Feb 2003 08:21:49 -0800


Tim Peters wrote:
> The code in question doesn't invoke PyNumber_Check(), so changing that
> wouldn't change behavior here.  The code in question could be changed to
> start invoking PyNumber_Check, though.

PyNumber_Check is pretty useless.  Don't blame me, it was useless before
I got to it. :-)

> Looks like, in the core, PyNumber_Check is used only by select_select and
> poll_pool.  Try passing a string as the timeout arg to a select() call!
> Looks to me like it will end up segfaulting here in PyFloat_AsDouble:
> 
> 	fo = (PyFloatObject*) (*nb->nb_float) (op);

You are thinking of PyFloat_AS_DOUBLE, I think.


    Python 2.3a1 (#6, Feb  4 2003, 15:46:59)
    [GCC 2.95.4 20011002 (Debian prerelease)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import select
    >>> select.select([], [], [], "ha ha")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    TypeError: a float is required

It's unclear what PyNumber_Check should be replaced with.  Perhaps a
test that determined if an object could be turned into a float or an
int.  Something like:

    PyNumber_AsIntegerCheck(o)
    {
        if PyFloat_Check(o)
            return false; /* truncating a float is not acceptable */
        else
            return true of nb_int exists
    }

    PyNumber_AsFloatCheck(o)
    {
        return true if nb_float exists
    }

PyNumber_Check could perhaps be changed to look for nb_float or nb_int.
I'm not sure if that breaks more or less extension modules. :-(

  Neil