Mercurial > cpython-lru_cache-weakref
diff Objects/bufferobject.c @ 82813:6b3217b96a77 2.7
Issue #10211 : Buffer object should support the new buffer interface.
| author | Kristján Valur Jónsson <sweskman@gmail.com> |
|---|---|
| date | Tue, 19 Mar 2013 16:50:51 -0700 |
| parents | 6b7704fe1be1 |
| children |
line wrap: on
line diff
--- a/Objects/bufferobject.c Tue Mar 19 17:30:30 2013 -0700 +++ b/Objects/bufferobject.c Tue Mar 19 16:50:51 2013 -0700 @@ -802,6 +802,16 @@ return size; } +static int buffer_getbuffer(PyBufferObject *self, Py_buffer *buf, int flags) +{ + void *ptr; + Py_ssize_t size; + if (!get_buf(self, &ptr, &size, ANY_BUFFER)) + return -1; + return PyBuffer_FillInfo(buf, (PyObject*)self, ptr, size, + self->b_readonly, flags); +} + static PySequenceMethods buffer_as_sequence = { (lenfunc)buffer_length, /*sq_length*/ (binaryfunc)buffer_concat, /*sq_concat*/ @@ -823,6 +833,7 @@ (writebufferproc)buffer_getwritebuf, (segcountproc)buffer_getsegcount, (charbufferproc)buffer_getcharbuf, + (getbufferproc)buffer_getbuffer, }; PyTypeObject PyBuffer_Type = { @@ -845,7 +856,7 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ &buffer_as_buffer, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GETCHARBUFFER, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GETCHARBUFFER | Py_TPFLAGS_HAVE_NEWBUFFER, /* tp_flags */ buffer_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ @@ -864,4 +875,4 @@ 0, /* tp_init */ 0, /* tp_alloc */ buffer_new, /* tp_new */ -}; +}; \ No newline at end of file
