Skip to content

Commit aeb6cee

Browse files
committed
Issue python#10293: Remove obsolete field in the PyMemoryView structure,
unused undocumented value PyBUF_SHADOW, and strangely-looking code in PyMemoryView_GetContiguous.
1 parent 8f2e07b commit aeb6cee

File tree

5 files changed

+6
-47
lines changed

5 files changed

+6
-47
lines changed

Include/memoryobject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info);
6363
and functions instead! */
6464
typedef struct {
6565
PyObject_HEAD
66-
PyObject *base;
6766
Py_buffer view;
6867
} PyMemoryViewObject;
6968

Include/object.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
189189

190190
#define PyBUF_READ 0x100
191191
#define PyBUF_WRITE 0x200
192-
#define PyBUF_SHADOW 0x400
193192

194193
/* End buffer interface */
195194

Lib/test/test_sys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ def get_gen(): yield 1
759759
check(int(PyLong_BASE**2-1), size(vh) + 2*self.longdigit)
760760
check(int(PyLong_BASE**2), size(vh) + 3*self.longdigit)
761761
# memory
762-
check(memoryview(b''), size(h + 'P PP2P2i7P'))
762+
check(memoryview(b''), size(h + 'PP2P2i7P'))
763763
# module
764764
check(unittest, size(h + '3P'))
765765
# None

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 3.2 Beta 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #10293: Remove obsolete field in the PyMemoryView structure,
14+
unused undocumented value PyBUF_SHADOW, and strangely-looking code in
15+
PyMemoryView_GetContiguous.
16+
1317
- Issue #6081: Add str.format_map, similar to str.format(**mapping).
1418

1519
- If FileIO.__init__ fails, close the file descriptor.

Objects/memoryobject.c

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ PyMemoryView_FromBuffer(Py_buffer *info)
8282
PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type);
8383
if (mview == NULL)
8484
return NULL;
85-
mview->base = NULL;
8685
dup_buffer(&mview->view, info);
8786
/* NOTE: mview->view.obj should already have been incref'ed as
8887
part of PyBuffer_FillInfo(). */
@@ -112,8 +111,6 @@ PyMemoryView_FromObject(PyObject *base)
112111
return NULL;
113112
}
114113

115-
mview->base = base;
116-
Py_INCREF(base);
117114
return (PyObject *)mview;
118115
}
119116

@@ -291,8 +288,6 @@ PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char fort)
291288

292289
if (PyBuffer_IsContiguous(view, fort)) {
293290
/* no copy needed */
294-
Py_INCREF(obj);
295-
mem->base = obj;
296291
_PyObject_GC_TRACK(mem);
297292
return (PyObject *)mem;
298293
}
@@ -324,21 +319,7 @@ PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char fort)
324319
Py_DECREF(mem);
325320
return NULL;
326321
}
327-
}
328-
if (buffertype == PyBUF_SHADOW) {
329-
/* return a shadowed memory-view object */
330-
view->buf = dest;
331-
mem->base = PyTuple_Pack(2, obj, bytes);
332-
Py_DECREF(bytes);
333-
if (mem->base == NULL) {
334-
Py_DECREF(mem);
335-
return NULL;
336-
}
337-
}
338-
else {
339322
PyBuffer_Release(view); /* XXX ? */
340-
/* steal the reference */
341-
mem->base = bytes;
342323
}
343324
_PyObject_GC_TRACK(mem);
344325
return (PyObject *)mem;
@@ -481,28 +462,7 @@ static void
481462
do_release(PyMemoryViewObject *self)
482463
{
483464
if (self->view.obj != NULL) {
484-
if (self->base && PyTuple_Check(self->base)) {
485-
/* Special case when first element is generic object
486-
with buffer interface and the second element is a
487-
contiguous "shadow" that must be copied back into
488-
the data areay of the first tuple element before
489-
releasing the buffer on the first element.
490-
*/
491-
492-
PyObject_CopyData(PyTuple_GET_ITEM(self->base,0),
493-
PyTuple_GET_ITEM(self->base,1));
494-
495-
/* The view member should have readonly == -1 in
496-
this instance indicating that the memory can
497-
be "locked" and was locked and will be unlocked
498-
again after this call.
499-
*/
500-
PyBuffer_Release(&(self->view));
501-
}
502-
else {
503-
PyBuffer_Release(&(self->view));
504-
}
505-
Py_CLEAR(self->base);
465+
PyBuffer_Release(&(self->view));
506466
}
507467
self->view.obj = NULL;
508468
self->view.buf = NULL;
@@ -819,8 +779,6 @@ memory_richcompare(PyObject *v, PyObject *w, int op)
819779
static int
820780
memory_traverse(PyMemoryViewObject *self, visitproc visit, void *arg)
821781
{
822-
if (self->base != NULL)
823-
Py_VISIT(self->base);
824782
if (self->view.obj != NULL)
825783
Py_VISIT(self->view.obj);
826784
return 0;
@@ -829,7 +787,6 @@ memory_traverse(PyMemoryViewObject *self, visitproc visit, void *arg)
829787
static int
830788
memory_clear(PyMemoryViewObject *self)
831789
{
832-
Py_CLEAR(self->base);
833790
PyBuffer_Release(&self->view);
834791
return 0;
835792
}

0 commit comments

Comments
 (0)