[issue14203] bytearray_getbuffer: unnecessary code

Stefan Krah report at bugs.python.org
Mon Mar 5 19:32:49 CET 2012

New submission from Stefan Krah <stefan-usenet at bytereef.org>:

bytearray_getbuffer() checks for view==NULL. But this has never been

PEP: "The second argument is the address to a bufferinfo structure.
      Both arguments must never be NULL."

DOCS (3.2): "view must point to an existing Py_buffer structure
             allocated by the caller".

A quick grep through the source tree shows no instances where
the middle argument of either PyObject_GetBuffer of bf_getbuffer
is NULL or 0.

Patch attached, all tests pass. I wouldn't be comfortable to
commit it without review though (it's just too strange).

BTW, the next conditional in bytearray_getbuffer ...

    if (ret >= 0) {

is also superfluous, since PyBuffer_FillInfo() cannot fail
if readonly==0.

components: Interpreter Core
files: bytearray_getbuffer.diff
keywords: needs review, patch
messages: 154969
nosy: ncoghlan, pitrou, skrah
priority: normal
severity: normal
stage: patch review
status: open
title: bytearray_getbuffer: unnecessary code
type: resource usage
versions: Python 3.3
Added file: http://bugs.python.org/file24738/bytearray_getbuffer.diff

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list