[Python-checkins] r60707 - in python/trunk: Include/intobject.h Include/longobject.h Objects/abstract.c Objects/intobject.c Objects/longobject.c

Eric Smith eric+python-dev at trueblade.com
Wed Feb 13 09:12:25 CET 2008


Neal Norwitz wrote:
>> +PyObject *
>> +PyNumber_ToBase(PyObject *n, int base)
>> +{
>> +       PyObject *res = NULL;
>> +       PyObject *index = PyNumber_Index(n);
>> +
>> +       if (!index)
>> +               return NULL;
>> +       if (PyLong_Check(index))
>> +               res = _PyLong_Format(index, base, 0, 1);
>> +       else if (PyInt_Check(index))
>> +               res = _PyInt_Format((PyIntObject*)index, base, 1);
>> +       else
>> +               assert("PyNumber_ToBase: not long or int");
> 
> The assert() should be changed to something like:
> 
>     PyErr_SetString(PyExc_ValueError, "arg not int or long");
> 
> Otherwise this will raise a SystemError in non-debug builds.
> 
>> +       Py_DECREF(index);
>> +       return res;
>> +}

I was going to change that, but this is copied from py3k's 
PyNumber_ToBase, which is:

PyObject *
PyNumber_ToBase(PyObject *n, int base)
{
         PyObject *res;
         PyObject *index = PyNumber_Index(n);

         if (!index)
                 return NULL;
         assert(PyLong_Check(index));
         res = _PyLong_Format(index, base);
         Py_DECREF(index);
         return res;
}


So I figured the assert was okay.  Should it be changed in both places? 
  I was thinking that it should be PyErr_BadInternalCall().


More information about the Python-checkins mailing list