Skip to content

Commit fe9bed0

Browse files
committed
Fix problems with memoryview object. There is still more to do to finish PEP 3118. The memory-view object needs to be fleshed out and the struct module needs to be modified.
1 parent 9b30784 commit fe9bed0

File tree

4 files changed

+408
-389
lines changed

4 files changed

+408
-389
lines changed

Include/memoryobject.h

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ extern "C" {
88
#endif
99

1010
typedef struct {
11-
PyObject_HEAD
12-
PyObject *base;
13-
Py_buffer view;
11+
PyObject_HEAD
12+
PyObject *base;
13+
Py_buffer view;
1414
} PyMemoryViewObject;
1515

1616

@@ -21,39 +21,40 @@ PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
2121

2222
#define Py_END_OF_MEMORY (-1)
2323

24-
PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, int buffertype,
25-
char fort);
24+
PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base,
25+
int buffertype,
26+
char fort);
2627

2728
/* Return a contiguous chunk of memory representing the buffer
2829
from an object in a memory view object. If a copy is made then the
29-
base object for the memory view will be a *new* bytes object.
30-
31-
Otherwise, the base-object will be the object itself and no
32-
data-copying will be done.
30+
base object for the memory view will be a *new* bytes object.
31+
32+
Otherwise, the base-object will be the object itself and no
33+
data-copying will be done.
3334
34-
The buffertype argument can be PyBUF_READ, PyBUF_WRITE,
35-
PyBUF_UPDATEIFCOPY to determine whether the returned buffer
36-
should be READONLY, WRITABLE, or set to update the
37-
original buffer if a copy must be made. If buffertype is
38-
PyBUF_WRITE and the buffer is not contiguous an error will
39-
be raised. In this circumstance, the user can use
40-
PyBUF_UPDATEIFCOPY to ensure that a a writable temporary
41-
contiguous buffer is returned. The contents of this
42-
contiguous buffer will be copied back into the original
43-
object after the memoryview object is deleted as long as
44-
the original object is writable and allows setting its
45-
memory to "readonly". If this is not allowed by the
46-
original object, then a BufferError is raised.
35+
The buffertype argument can be PyBUF_READ, PyBUF_WRITE,
36+
PyBUF_SHADOW to determine whether the returned buffer
37+
should be READONLY, WRITABLE, or set to update the
38+
original buffer if a copy must be made. If buffertype is
39+
PyBUF_WRITE and the buffer is not contiguous an error will
40+
be raised. In this circumstance, the user can use
41+
PyBUF_SHADOW to ensure that a a writable temporary
42+
contiguous buffer is returned. The contents of this
43+
contiguous buffer will be copied back into the original
44+
object after the memoryview object is deleted as long as
45+
the original object is writable and allows setting an
46+
exclusive write lock. If this is not allowed by the
47+
original object, then a BufferError is raised.
4748
48-
If the object is multi-dimensional and if fortran is 'F',
49-
the first dimension of the underlying array will vary the
50-
fastest in the buffer. If fortran is 'C', then the last
51-
dimension will vary the fastest (C-style contiguous). If
52-
fortran is 'A', then it does not matter and you will get
53-
whatever the object decides is more efficient.
49+
If the object is multi-dimensional and if fortran is 'F',
50+
the first dimension of the underlying array will vary the
51+
fastest in the buffer. If fortran is 'C', then the last
52+
dimension will vary the fastest (C-style contiguous). If
53+
fortran is 'A', then it does not matter and you will get
54+
whatever the object decides is more efficient.
5455
55-
A new reference is returned that must be DECREF'd when finished.
56-
*/
56+
A new reference is returned that must be DECREF'd when finished.
57+
*/
5758

5859
PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
5960

Include/object.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
164164
#define PyBUF_WRITABLE 0x0002
165165
/* we used to include an E, backwards compatible alias */
166166
#define PyBUF_WRITEABLE PyBUF_WRITABLE
167-
#define PyBUF_LOCKDATA 0x0004
167+
#define PyBUF_LOCK 0x0004
168168
#define PyBUF_FORMAT 0x0008
169169
#define PyBUF_ND 0x0010
170170
#define PyBUF_STRIDES (0x0020 | PyBUF_ND)
@@ -175,19 +175,25 @@ typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
175175

176176
#define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)
177177
#define PyBUF_CONTIG_RO (PyBUF_ND)
178-
#define PyBUF_CONTIG_LCK (PyBUF_ND | PyBUF_LOCKDATA)
178+
#define PyBUF_CONTIG_LCK (PyBUF_ND | PyBUF_LOCK)
179+
#define PyBUF_CONTIG_XLCK (PyBUF_ND | PyBUF_LOCK | PyBUF_WRITABLE)
179180

180181
#define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)
181182
#define PyBUF_STRIDED_RO (PyBUF_STRIDES)
182-
#define PyBUF_STRIDED_LCK (PyBUF_STRIDES | PyBUF_LOCKDATA)
183+
#define PyBUF_STRIDED_LCK (PyBUF_STRIDES | PyBUF_LOCK)
184+
#define PyBUF_STRIDED_XLCK (PyBUF_STRIDES | PyBUF_LOCK | PyBUF_WRITABLE)
183185

184186
#define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)
185187
#define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)
186-
#define PyBUF_RECORDS_LCK (PyBUF_STRIDES | PyBUF_LOCKDATA | PyBUF_FORMAT)
188+
#define PyBUF_RECORDS_LCK (PyBUF_STRIDES | PyBUF_LOCK | PyBUF_FORMAT)
189+
#define PyBUF_RECORDS_XLCK (PyBUF_STRIDES | PyBUF_LOCK | PyBUF_WRITABLE \
190+
| PyBUF_FORMAT)
187191

188192
#define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)
189193
#define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)
190-
#define PyBUF_FULL_LCK (PyBUF_INDIRECT | PyBUF_LOCKDATA | PyBUF_FORMAT)
194+
#define PyBUF_FULL_LCK (PyBUF_INDIRECT | PyBUF_LOCK | PyBUF_FORMAT)
195+
#define PyBUF_FULL_XLCK (PyBUF_INDIRECT | PyBUF_LOCK | PyBUF_WRITABLE \
196+
| PyBUF_FORMAT)
191197

192198

193199
#define PyBUF_READ 0x100

0 commit comments

Comments
 (0)