[Python-3000-checkins] r66038 - in python/branches/py3k: Doc/c-api/bytes.rst Doc/c-api/object.rst Include/bytesobject.h Include/object.h Lib/test/test_bytes.py Misc/NEWS Objects/bytesobject.c Objects/object.c
Neal Norwitz
nnorwitz at gmail.com
Wed Aug 27 02:25:12 CEST 2008
On Tue, Aug 26, 2008 at 5:13 PM, Benjamin Peterson
<musiccomposition at gmail.com> wrote:
> On Tue, Aug 26, 2008 at 7:04 PM, Neal Norwitz <nnorwitz at gmail.com> wrote:
>> On Tue, Aug 26, 2008 at 5:02 PM, Benjamin Peterson
>> <musiccomposition at gmail.com> wrote:
>>> On Tue, Aug 26, 2008 at 6:53 PM, Neal Norwitz <nnorwitz at gmail.com> wrote:
>>>> On Tue, Aug 26, 2008 at 9:46 AM, benjamin.peterson
>>>> <python-3000-checkins at python.org> wrote:
>>>>> Modified: python/branches/py3k/Objects/bytesobject.c
>>>>> ==============================================================================
>>>>> --- python/branches/py3k/Objects/bytesobject.c (original)
>>>>> +++ python/branches/py3k/Objects/bytesobject.c Tue Aug 26 18:46:47 2008
>>>>> @@ -2924,6 +2923,14 @@
>>>>> "encoding or errors without a string argument");
>>>>> return NULL;
>>>>> }
>>>>> + return PyObject_Bytes(x);
>>>>> +}
>>>>> +
>>>>> +PyObject *
>>>>> +PyBytes_FromObject(PyObject *x)
>>>>> +{
>>>>> + PyObject *new, *it;
>>>>> + Py_ssize_t i, size;
>>>>>
>>>>> /* Is it an int? */
>>>>> size = PyNumber_AsSsize_t(x, PyExc_ValueError);
>>>>
>>>> What happens if x (the object passed in) is NULL?
>>>
>>> It segfaults, but this is ok because PyObject_Bytes checks for NULL.
>>
>> Since this is now a public API, anyone can pass NULL here. In general
>> we check for NULLs from most public APIs (I think). Though IIRC we
>> are pretty inconsistent.
>
> I wasn't under that impression. For example, a quick glance shows that
> none of the PyList API functions check for NULL.
Like I said, we're inconsistent. :-) We discussed this on python-dev
a while ago, but there wasn't really any resolution IIRC.
I generally prefer to be safe which is why I prefer to have checks
unless there's a good reason not to.
> Anyway, what should PyBytes_FromObject return for NULL anyway?
> Probably just another NULL.
Objects/dictobject.c has good examples. Something like:
if (x == NULL) {
PyErr_BadInternalCall();
return NULL;
}
n
More information about the Python-3000-checkins
mailing list