annotate Objects/bufferobject.c @ 47787:b32101c19bf8 legacy-trunk

Grammar fixes
author Andrew M. Kuchling <amk@amk.ca>
date Fri, 20 Jun 2008 23:14:32 +0000
parents 1c964ed35ef9
children c4d24fc8ba8a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Buffer object implementation */
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #include "Python.h"
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 typedef struct {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 PyObject_HEAD
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 PyObject *b_base;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 void *b_ptr;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
11 Py_ssize_t b_size;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
12 Py_ssize_t b_offset;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 int b_readonly;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 long b_hash;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 } PyBufferObject;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
18 enum buffer_t {
38693
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
19 READ_BUFFER,
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
20 WRITE_BUFFER,
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
21 CHAR_BUFFER,
41996
1bbcd392417d Bug #1733488: Fix compilation of bufferobject.c on AIX.
Martin v. Löwis <martin@v.loewis.de>
parents: 39395
diff changeset
22 ANY_BUFFER
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
23 };
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
24
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
25 static int
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
26 get_buf(PyBufferObject *self, void **ptr, Py_ssize_t *size,
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
27 enum buffer_t buffer_type)
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
28 {
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
29 if (self->b_base == NULL) {
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
30 assert (ptr != NULL);
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
31 *ptr = self->b_ptr;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
32 *size = self->b_size;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
33 }
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
34 else {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
35 Py_ssize_t count, offset;
38731
0b3fe2b734a1 Suppress warning on MacOSX about possible use before set of proc.
Skip Montanaro <skip@pobox.com>
parents: 38693
diff changeset
36 readbufferproc proc = 0;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
37 PyBufferProcs *bp = self->b_base->ob_type->tp_as_buffer;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
38 if ((*bp->bf_getsegcount)(self->b_base, NULL) != 1) {
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
39 PyErr_SetString(PyExc_TypeError,
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
40 "single-segment buffer object expected");
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
41 return 0;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
42 }
38693
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
43 if ((buffer_type == READ_BUFFER) ||
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
44 ((buffer_type == ANY_BUFFER) && self->b_readonly))
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
45 proc = bp->bf_getreadbuffer;
38693
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
46 else if ((buffer_type == WRITE_BUFFER) ||
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
47 (buffer_type == ANY_BUFFER))
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
48 proc = (readbufferproc)bp->bf_getwritebuffer;
38693
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
49 else if (buffer_type == CHAR_BUFFER) {
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
50 if (!PyType_HasFeature(self->ob_type,
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
51 Py_TPFLAGS_HAVE_GETCHARBUFFER)) {
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
52 PyErr_SetString(PyExc_TypeError,
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
53 "Py_TPFLAGS_HAVE_GETCHARBUFFER needed");
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
54 return 0;
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
55 }
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
56 proc = (readbufferproc)bp->bf_getcharbuffer;
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
57 }
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
58 if (!proc) {
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
59 char *buffer_type_name;
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
60 switch (buffer_type) {
38693
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
61 case READ_BUFFER:
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
62 buffer_type_name = "read";
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
63 break;
38693
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
64 case WRITE_BUFFER:
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
65 buffer_type_name = "write";
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
66 break;
38693
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
67 case CHAR_BUFFER:
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
68 buffer_type_name = "char";
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
69 break;
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
70 default:
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
71 buffer_type_name = "no";
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
72 break;
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
73 }
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
74 PyErr_Format(PyExc_TypeError,
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
75 "%s buffer type not available",
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
76 buffer_type_name);
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
77 return 0;
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
78 }
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
79 if ((count = (*proc)(self->b_base, 0, ptr)) < 0)
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
80 return 0;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
81 /* apply constraints to the start/end */
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
82 if (self->b_offset > count)
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
83 offset = count;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
84 else
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
85 offset = self->b_offset;
31810
7a120400888a Correct code to advance ptr to be well-formed C.
Martin v. Löwis <martin@v.loewis.de>
parents: 31640
diff changeset
86 *(char **)ptr = *(char **)ptr + offset;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
87 if (self->b_size == Py_END_OF_BUFFER)
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
88 *size = count;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
89 else
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
90 *size = self->b_size;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
91 if (offset + *size > count)
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
92 *size = count - offset;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
93 }
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
94 return 1;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
95 }
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
96
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
97
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 static PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
99 buffer_from_memory(PyObject *base, Py_ssize_t size, Py_ssize_t offset, void *ptr,
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
100 int readonly)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 PyBufferObject * b;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
104 if (size < 0 && size != Py_END_OF_BUFFER) {
10427
e6799a855af7 Added check for negative offset for PyBuffer_FromObject and check for
Guido van Rossum <guido@python.org>
parents: 9305
diff changeset
105 PyErr_SetString(PyExc_ValueError,
e6799a855af7 Added check for negative offset for PyBuffer_FromObject and check for
Guido van Rossum <guido@python.org>
parents: 9305
diff changeset
106 "size must be zero or positive");
e6799a855af7 Added check for negative offset for PyBuffer_FromObject and check for
Guido van Rossum <guido@python.org>
parents: 9305
diff changeset
107 return NULL;
e6799a855af7 Added check for negative offset for PyBuffer_FromObject and check for
Guido van Rossum <guido@python.org>
parents: 9305
diff changeset
108 }
33559
be8cff4a1eca Fix buffer offset calculation (need to compute it before changing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31810
diff changeset
109 if (offset < 0) {
be8cff4a1eca Fix buffer offset calculation (need to compute it before changing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31810
diff changeset
110 PyErr_SetString(PyExc_ValueError,
be8cff4a1eca Fix buffer offset calculation (need to compute it before changing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31810
diff changeset
111 "offset must be zero or positive");
be8cff4a1eca Fix buffer offset calculation (need to compute it before changing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31810
diff changeset
112 return NULL;
be8cff4a1eca Fix buffer offset calculation (need to compute it before changing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31810
diff changeset
113 }
10427
e6799a855af7 Added check for negative offset for PyBuffer_FromObject and check for
Guido van Rossum <guido@python.org>
parents: 9305
diff changeset
114
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 b = PyObject_NEW(PyBufferObject, &PyBuffer_Type);
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 if ( b == NULL )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 return NULL;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 Py_XINCREF(base);
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 b->b_base = base;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 b->b_ptr = ptr;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 b->b_size = size;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
123 b->b_offset = offset;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 b->b_readonly = readonly;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 b->b_hash = -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 return (PyObject *) b;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 static PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
131 buffer_from_object(PyObject *base, Py_ssize_t size, Py_ssize_t offset, int readonly)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 {
33560
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
133 if (offset < 0) {
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
134 PyErr_SetString(PyExc_ValueError,
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
135 "offset must be zero or positive");
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
136 return NULL;
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
137 }
33559
be8cff4a1eca Fix buffer offset calculation (need to compute it before changing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31810
diff changeset
138 if ( PyBuffer_Check(base) && (((PyBufferObject *)base)->b_base) ) {
be8cff4a1eca Fix buffer offset calculation (need to compute it before changing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31810
diff changeset
139 /* another buffer, refer to the base object */
33560
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
140 PyBufferObject *b = (PyBufferObject *)base;
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
141 if (b->b_size != Py_END_OF_BUFFER) {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
142 Py_ssize_t base_size = b->b_size - offset;
33560
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
143 if (base_size < 0)
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
144 base_size = 0;
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
145 if (size == Py_END_OF_BUFFER || size > base_size)
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
146 size = base_size;
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
147 }
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
148 offset += b->b_offset;
97cb9eea212e Ensure negative offsets cannot be passed to buffer(). When composing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 33559
diff changeset
149 base = b->b_base;
10427
e6799a855af7 Added check for negative offset for PyBuffer_FromObject and check for
Guido van Rossum <guido@python.org>
parents: 9305
diff changeset
150 }
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
151 return buffer_from_memory(base, size, offset, NULL, readonly);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
156 PyBuffer_FromObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 PyBufferProcs *pb = base->ob_type->tp_as_buffer;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 if ( pb == NULL ||
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 pb->bf_getreadbuffer == NULL ||
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 pb->bf_getsegcount == NULL )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 PyErr_SetString(PyExc_TypeError, "buffer object expected");
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 return NULL;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
168 return buffer_from_object(base, size, offset, 1);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
172 PyBuffer_FromReadWriteObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 PyBufferProcs *pb = base->ob_type->tp_as_buffer;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 if ( pb == NULL ||
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 pb->bf_getwritebuffer == NULL ||
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 pb->bf_getsegcount == NULL )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 PyErr_SetString(PyExc_TypeError, "buffer object expected");
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 return NULL;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
183
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
184 return buffer_from_object(base, size, offset, 0);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
186
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
188 PyBuffer_FromMemory(void *ptr, Py_ssize_t size)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 {
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
190 return buffer_from_memory(NULL, size, 0, ptr, 1);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
194 PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 {
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
196 return buffer_from_memory(NULL, size, 0, ptr, 0);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
200 PyBuffer_New(Py_ssize_t size)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 {
13861
f3d5f71ccbb4 Removing warnings found by gcc -Wall
Moshe Zadka <moshez@math.huji.ac.il>
parents: 13449
diff changeset
202 PyObject *o;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 PyBufferObject * b;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204
11175
fab81df566d0 PyBuffer_New(): Raise ValueError if size is negative (the other
Fred Drake <fdrake@acm.org>
parents: 10460
diff changeset
205 if (size < 0) {
fab81df566d0 PyBuffer_New(): Raise ValueError if size is negative (the other
Fred Drake <fdrake@acm.org>
parents: 10460
diff changeset
206 PyErr_SetString(PyExc_ValueError,
fab81df566d0 PyBuffer_New(): Raise ValueError if size is negative (the other
Fred Drake <fdrake@acm.org>
parents: 10460
diff changeset
207 "size must be zero or positive");
fab81df566d0 PyBuffer_New(): Raise ValueError if size is negative (the other
Fred Drake <fdrake@acm.org>
parents: 10460
diff changeset
208 return NULL;
fab81df566d0 PyBuffer_New(): Raise ValueError if size is negative (the other
Fred Drake <fdrake@acm.org>
parents: 10460
diff changeset
209 }
47587
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
210 if (sizeof(*b) > PY_SSIZE_T_MAX - size) {
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
211 /* unlikely */
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
212 return PyErr_NoMemory();
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
213 }
24898
a869d2de536f Call me anal, but there was a particular phrase that was speading to
Guido van Rossum <guido@python.org>
parents: 23972
diff changeset
214 /* Inline PyObject_New */
37589
aeee85b6a5dd More C++-compliance. Note especially listobject.c - to get C++ to accept the
Anthony Baxter <anthonybaxter@gmail.com>
parents: 36533
diff changeset
215 o = (PyObject *)PyObject_MALLOC(sizeof(*b) + size);
13861
f3d5f71ccbb4 Removing warnings found by gcc -Wall
Moshe Zadka <moshez@math.huji.ac.il>
parents: 13449
diff changeset
216 if ( o == NULL )
11175
fab81df566d0 PyBuffer_New(): Raise ValueError if size is negative (the other
Fred Drake <fdrake@acm.org>
parents: 10460
diff changeset
217 return PyErr_NoMemory();
13861
f3d5f71ccbb4 Removing warnings found by gcc -Wall
Moshe Zadka <moshez@math.huji.ac.il>
parents: 13449
diff changeset
218 b = (PyBufferObject *) PyObject_INIT(o, &PyBuffer_Type);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
219
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 b->b_base = NULL;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 b->b_ptr = (void *)(b + 1);
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 b->b_size = size;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
223 b->b_offset = 0;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 b->b_readonly = 0;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 b->b_hash = -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
226
13861
f3d5f71ccbb4 Removing warnings found by gcc -Wall
Moshe Zadka <moshez@math.huji.ac.il>
parents: 13449
diff changeset
227 return o;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 /* Methods */
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231
23868
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
232 static PyObject *
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
233 buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
234 {
46080
2a866ea66509 Move declarations to block start.
Georg Brandl <georg@python.org>
parents: 46075
diff changeset
235 PyObject *ob;
2a866ea66509 Move declarations to block start.
Georg Brandl <georg@python.org>
parents: 46075
diff changeset
236 Py_ssize_t offset = 0;
2a866ea66509 Move declarations to block start.
Georg Brandl <georg@python.org>
parents: 46075
diff changeset
237 Py_ssize_t size = Py_END_OF_BUFFER;
2a866ea66509 Move declarations to block start.
Georg Brandl <georg@python.org>
parents: 46075
diff changeset
238
46573
aef3501d8e77 Use PyErr_WarnPy3k throughout
Benjamin Peterson <benjamin@python.org>
parents: 46080
diff changeset
239 if (PyErr_WarnPy3k("buffer() not supported in 3.x; "
46075
84bb7701efba Make Py3k warnings consistent w.r.t. punctuation; also respect the
Georg Brandl <georg@python.org>
parents: 46074
diff changeset
240 "use memoryview()", 1) < 0)
46074
9b3f0fa5d8ca #2355: py3k warning for buffer().
Georg Brandl <georg@python.org>
parents: 43464
diff changeset
241 return NULL;
9b3f0fa5d8ca #2355: py3k warning for buffer().
Georg Brandl <georg@python.org>
parents: 43464
diff changeset
242
35450
97c97194e64b Disallow keyword arguments for type constructors that don't use them
Georg Brandl <georg@python.org>
parents: 33560
diff changeset
243 if (!_PyArg_NoKeywords("buffer()", kw))
97c97194e64b Disallow keyword arguments for type constructors that don't use them
Georg Brandl <georg@python.org>
parents: 33560
diff changeset
244 return NULL;
97c97194e64b Disallow keyword arguments for type constructors that don't use them
Georg Brandl <georg@python.org>
parents: 33560
diff changeset
245
36533
ed07c1a5e24c Use proper PyArg_Parse format char for Py_ssize_t, instead of 'l', in
Thomas Wouters <thomas@python.org>
parents: 36511
diff changeset
246 if (!PyArg_ParseTuple(args, "O|nn:buffer", &ob, &offset, &size))
23868
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
247 return NULL;
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
248 return PyBuffer_FromObject(ob, offset, size);
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
249 }
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
250
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
251 PyDoc_STRVAR(buffer_doc,
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
252 "buffer(object [, offset[, size]])\n\
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
253 \n\
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
254 Create a new buffer object which references the given object.\n\
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
255 The buffer will reference a slice of the target object from the\n\
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
256 start of the object (or at the specified offset). The slice will\n\
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
257 extend to the end of the target object (or with the specified size).");
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
258
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
259
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 static void
13449
0409a98cd582 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
261 buffer_dealloc(PyBufferObject *self)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 Py_XDECREF(self->b_base);
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 11175
diff changeset
264 PyObject_DEL(self);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
266
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 static int
13449
0409a98cd582 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
268 buffer_compare(PyBufferObject *self, PyBufferObject *other)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 {
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
270 void *p1, *p2;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
271 Py_ssize_t len_self, len_other, min_len;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
272 int cmp;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
273
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
274 if (!get_buf(self, &p1, &len_self, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
275 return -1;
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
276 if (!get_buf(other, &p2, &len_other, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
277 return -1;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
278 min_len = (len_self < len_other) ? len_self : len_other;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
279 if (min_len > 0) {
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
280 cmp = memcmp(p1, p2, min_len);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 if (cmp != 0)
39395
997788de8667 memcmp() can return values other than -1, 0, and +1 but tp_compare
Thomas Heller <theller@ctypes.org>
parents: 38731
diff changeset
282 return cmp < 0 ? -1 : 1;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 return (len_self < len_other) ? -1 : (len_self > len_other) ? 1 : 0;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
286
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 static PyObject *
13449
0409a98cd582 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
288 buffer_repr(PyBufferObject *self)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
290 const char *status = self->b_readonly ? "read-only" : "read-write";
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
291
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 if ( self->b_base == NULL )
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
293 return PyString_FromFormat("<%s buffer ptr %p, size %zd at %p>",
19476
0e70df98424e repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents: 18933
diff changeset
294 status,
0e70df98424e repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents: 18933
diff changeset
295 self->b_ptr,
36511
1596ff5c79b5 Revert 42400.
Martin v. Löwis <martin@v.loewis.de>
parents: 36510
diff changeset
296 self->b_size,
19476
0e70df98424e repr's converted to using PyString_FromFormat() instead of sprintf'ing
Barry Warsaw <barry@python.org>
parents: 18933
diff changeset
297 self);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 else
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
299 return PyString_FromFormat(
36510
0f3894bb2ada Support %zd in PyErr_Format and PyString_FromFormat.
Martin v. Löwis <martin@v.loewis.de>
parents: 36509
diff changeset
300 "<%s buffer for %p, size %zd, offset %zd at %p>",
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 status,
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
302 self->b_base,
36511
1596ff5c79b5 Revert 42400.
Martin v. Löwis <martin@v.loewis.de>
parents: 36510
diff changeset
303 self->b_size,
1596ff5c79b5 Revert 42400.
Martin v. Löwis <martin@v.loewis.de>
parents: 36510
diff changeset
304 self->b_offset,
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
305 self);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
307
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
308 static long
13449
0409a98cd582 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
309 buffer_hash(PyBufferObject *self)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 {
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
311 void *ptr;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
312 Py_ssize_t size;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
313 register Py_ssize_t len;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 register unsigned char *p;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 register long x;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
316
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 if ( self->b_hash != -1 )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
318 return self->b_hash;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
319
31639
047148089c35 Document one of the many problems with the buffer object.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31638
diff changeset
320 /* XXX potential bugs here, a readonly buffer does not imply that the
047148089c35 Document one of the many problems with the buffer object.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31638
diff changeset
321 * underlying memory is immutable. b_readonly is a necessary but not
047148089c35 Document one of the many problems with the buffer object.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31638
diff changeset
322 * sufficient condition for a buffer to be hashable. Perhaps it would
047148089c35 Document one of the many problems with the buffer object.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31638
diff changeset
323 * be better to only allow hashing if the underlying object is known to
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
324 * be immutable (e.g. PyString_Check() is true). Another idea would
31639
047148089c35 Document one of the many problems with the buffer object.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31638
diff changeset
325 * be to call tp_hash on the underlying object and see if it raises
047148089c35 Document one of the many problems with the buffer object.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31638
diff changeset
326 * an error. */
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 if ( !self->b_readonly )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 {
31639
047148089c35 Document one of the many problems with the buffer object.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31638
diff changeset
329 PyErr_SetString(PyExc_TypeError,
047148089c35 Document one of the many problems with the buffer object.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31638
diff changeset
330 "writable buffers are not hashable");
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
333
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
334 if (!get_buf(self, &ptr, &size, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
335 return -1;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
336 p = (unsigned char *) ptr;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
337 len = size;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 x = *p << 7;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 while (--len >= 0)
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 x = (1000003*x) ^ *p++;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
341 x ^= size;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 if (x == -1)
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 x = -2;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 self->b_hash = x;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 return x;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
347
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 static PyObject *
13449
0409a98cd582 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
349 buffer_str(PyBufferObject *self)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 {
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
351 void *ptr;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
352 Py_ssize_t size;
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
353 if (!get_buf(self, &ptr, &size, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
354 return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
355 return PyString_FromStringAndSize((const char *)ptr, size);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
357
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 /* Sequence methods */
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
359
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
360 static Py_ssize_t
13449
0409a98cd582 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
361 buffer_length(PyBufferObject *self)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 {
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
363 void *ptr;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
364 Py_ssize_t size;
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
365 if (!get_buf(self, &ptr, &size, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
366 return -1;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
367 return size;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
369
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 static PyObject *
13449
0409a98cd582 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
371 buffer_concat(PyBufferObject *self, PyObject *other)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 PyBufferProcs *pb = other->ob_type->tp_as_buffer;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
374 void *ptr1, *ptr2;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
375 char *p;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 PyObject *ob;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
377 Py_ssize_t size, count;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
378
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 if ( pb == NULL ||
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 pb->bf_getreadbuffer == NULL ||
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 pb->bf_getsegcount == NULL )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 PyErr_BadArgument();
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 return NULL;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 if ( (*pb->bf_getsegcount)(other, NULL) != 1 )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
388 /* ### use a different exception type/message? */
10460
62781914fadb Folded long lines.
Guido van Rossum <guido@python.org>
parents: 10427
diff changeset
389 PyErr_SetString(PyExc_TypeError,
62781914fadb Folded long lines.
Guido van Rossum <guido@python.org>
parents: 10427
diff changeset
390 "single-segment buffer object expected");
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 return NULL;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
393
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
394 if (!get_buf(self, &ptr1, &size, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
395 return NULL;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
396
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 /* optimize special case */
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
398 if ( size == 0 )
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 Py_INCREF(other);
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
401 return other;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
403
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
404 if ( (count = (*pb->bf_getreadbuffer)(other, 0, &ptr2)) < 0 )
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 return NULL;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
406
47587
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
407 assert(count <= PY_SIZE_MAX - size);
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
408
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
409 ob = PyString_FromStringAndSize(NULL, size + count);
36082
3f358afbb3d3 Check return result for error
Neal Norwitz <nnorwitz@gmail.com>
parents: 35450
diff changeset
410 if ( ob == NULL )
3f358afbb3d3 Check return result for error
Neal Norwitz <nnorwitz@gmail.com>
parents: 35450
diff changeset
411 return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
412 p = PyString_AS_STRING(ob);
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
413 memcpy(p, ptr1, size);
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
414 memcpy(p + size, ptr2, count);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
415
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
416 /* there is an extra byte in the string object, so this is safe */
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
417 p[size + count] = '\0';
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
418
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
419 return ob;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
420 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
421
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 static PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
423 buffer_repeat(PyBufferObject *self, Py_ssize_t count)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 PyObject *ob;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 register char *p;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
427 void *ptr;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
428 Py_ssize_t size;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
429
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
430 if ( count < 0 )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 count = 0;
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
432 if (!get_buf(self, &ptr, &size, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
433 return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
434 ob = PyString_FromStringAndSize(NULL, size * count);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 if ( ob == NULL )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
436 return NULL;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
437
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
438 p = PyString_AS_STRING(ob);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
439 while ( count-- )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
440 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 memcpy(p, ptr, size);
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
442 p += size;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
444
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
445 /* there is an extra byte in the string object, so this is safe */
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
446 *p = '\0';
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
447
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 return ob;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
450
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
451 static PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
452 buffer_item(PyBufferObject *self, Py_ssize_t idx)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
453 {
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
454 void *ptr;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
455 Py_ssize_t size;
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
456 if (!get_buf(self, &ptr, &size, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
457 return NULL;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
458 if ( idx < 0 || idx >= size ) {
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 PyErr_SetString(PyExc_IndexError, "buffer index out of range");
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
460 return NULL;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
461 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
462 return PyString_FromStringAndSize((char *)ptr + idx, 1);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
463 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
464
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
465 static PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
466 buffer_slice(PyBufferObject *self, Py_ssize_t left, Py_ssize_t right)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
467 {
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
468 void *ptr;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
469 Py_ssize_t size;
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
470 if (!get_buf(self, &ptr, &size, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
471 return NULL;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
472 if ( left < 0 )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
473 left = 0;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
474 if ( right < 0 )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
475 right = 0;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
476 if ( right > size )
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
477 right = size;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
478 if ( right < left )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
479 right = left;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
480 return PyString_FromStringAndSize((char *)ptr + left,
10460
62781914fadb Folded long lines.
Guido van Rossum <guido@python.org>
parents: 10427
diff changeset
481 right - left);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
482 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
483
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
484 static PyObject *
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
485 buffer_subscript(PyBufferObject *self, PyObject *item)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
486 {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
487 void *p;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
488 Py_ssize_t size;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
489
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
490 if (!get_buf(self, &p, &size, ANY_BUFFER))
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
491 return NULL;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
492 if (PyIndex_Check(item)) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
493 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
494 if (i == -1 && PyErr_Occurred())
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
495 return NULL;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
496 if (i < 0)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
497 i += size;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
498 return buffer_item(self, i);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
499 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
500 else if (PySlice_Check(item)) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
501 Py_ssize_t start, stop, step, slicelength, cur, i;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
502
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
503 if (PySlice_GetIndicesEx((PySliceObject*)item, size,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
504 &start, &stop, &step, &slicelength) < 0) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
505 return NULL;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
506 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
507
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
508 if (slicelength <= 0)
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
509 return PyString_FromStringAndSize("", 0);
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
510 else if (step == 1)
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
511 return PyString_FromStringAndSize((char *)p + start,
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
512 stop - start);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
513 else {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
514 PyObject *result;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
515 char *source_buf = (char *)p;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
516 char *result_buf = (char *)PyMem_Malloc(slicelength);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
517
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
518 if (result_buf == NULL)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
519 return PyErr_NoMemory();
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
520
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
521 for (cur = start, i = 0; i < slicelength;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
522 cur += step, i++) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
523 result_buf[i] = source_buf[cur];
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
524 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
525
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
526 result = PyString_FromStringAndSize(result_buf,
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
527 slicelength);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
528 PyMem_Free(result_buf);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
529 return result;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
530 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
531 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
532 else {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
533 PyErr_SetString(PyExc_TypeError,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
534 "sequence index must be integer");
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
535 return NULL;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
536 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
537 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
538
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
539 static int
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
540 buffer_ass_item(PyBufferObject *self, Py_ssize_t idx, PyObject *other)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
541 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
542 PyBufferProcs *pb;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
543 void *ptr1, *ptr2;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
544 Py_ssize_t size;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
545 Py_ssize_t count;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
546
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
547 if ( self->b_readonly ) {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
548 PyErr_SetString(PyExc_TypeError,
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
549 "buffer is read-only");
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
550 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
551 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
552
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
553 if (!get_buf(self, &ptr1, &size, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
554 return -1;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
555
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
556 if (idx < 0 || idx >= size) {
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
557 PyErr_SetString(PyExc_IndexError,
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
558 "buffer assignment index out of range");
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
559 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
560 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
561
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
562 pb = other ? other->ob_type->tp_as_buffer : NULL;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
563 if ( pb == NULL ||
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
564 pb->bf_getreadbuffer == NULL ||
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
565 pb->bf_getsegcount == NULL )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
566 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
567 PyErr_BadArgument();
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
568 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
569 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
570 if ( (*pb->bf_getsegcount)(other, NULL) != 1 )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
571 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
572 /* ### use a different exception type/message? */
10460
62781914fadb Folded long lines.
Guido van Rossum <guido@python.org>
parents: 10427
diff changeset
573 PyErr_SetString(PyExc_TypeError,
62781914fadb Folded long lines.
Guido van Rossum <guido@python.org>
parents: 10427
diff changeset
574 "single-segment buffer object expected");
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
575 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
576 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
577
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
578 if ( (count = (*pb->bf_getreadbuffer)(other, 0, &ptr2)) < 0 )
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
579 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
580 if ( count != 1 ) {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
581 PyErr_SetString(PyExc_TypeError,
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
582 "right operand must be a single byte");
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
583 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
584 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
585
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
586 ((char *)ptr1)[idx] = *(char *)ptr2;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
587 return 0;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
588 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
589
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
590 static int
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
591 buffer_ass_slice(PyBufferObject *self, Py_ssize_t left, Py_ssize_t right, PyObject *other)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
592 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
593 PyBufferProcs *pb;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
594 void *ptr1, *ptr2;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
595 Py_ssize_t size;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
596 Py_ssize_t slice_len;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
597 Py_ssize_t count;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
598
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
599 if ( self->b_readonly ) {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
600 PyErr_SetString(PyExc_TypeError,
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
601 "buffer is read-only");
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
602 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
603 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
604
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
605 pb = other ? other->ob_type->tp_as_buffer : NULL;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
606 if ( pb == NULL ||
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
607 pb->bf_getreadbuffer == NULL ||
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
608 pb->bf_getsegcount == NULL )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
609 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
610 PyErr_BadArgument();
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
611 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
612 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
613 if ( (*pb->bf_getsegcount)(other, NULL) != 1 )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
614 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
615 /* ### use a different exception type/message? */
10460
62781914fadb Folded long lines.
Guido van Rossum <guido@python.org>
parents: 10427
diff changeset
616 PyErr_SetString(PyExc_TypeError,
62781914fadb Folded long lines.
Guido van Rossum <guido@python.org>
parents: 10427
diff changeset
617 "single-segment buffer object expected");
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
618 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
619 }
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
620 if (!get_buf(self, &ptr1, &size, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
621 return -1;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
622 if ( (count = (*pb->bf_getreadbuffer)(other, 0, &ptr2)) < 0 )
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
623 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
624
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
625 if ( left < 0 )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
626 left = 0;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
627 else if ( left > size )
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
628 left = size;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
629 if ( right < left )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
630 right = left;
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
631 else if ( right > size )
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
632 right = size;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
633 slice_len = right - left;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
634
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
635 if ( count != slice_len ) {
10460
62781914fadb Folded long lines.
Guido van Rossum <guido@python.org>
parents: 10427
diff changeset
636 PyErr_SetString(
62781914fadb Folded long lines.
Guido van Rossum <guido@python.org>
parents: 10427
diff changeset
637 PyExc_TypeError,
62781914fadb Folded long lines.
Guido van Rossum <guido@python.org>
parents: 10427
diff changeset
638 "right operand length must match slice length");
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
639 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
640 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
641
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
642 if ( slice_len )
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
643 memcpy((char *)ptr1 + left, ptr2, slice_len);
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
644
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
645 return 0;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
646 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
647
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
648 static int
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
649 buffer_ass_subscript(PyBufferObject *self, PyObject *item, PyObject *value)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
650 {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
651 PyBufferProcs *pb;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
652 void *ptr1, *ptr2;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
653 Py_ssize_t selfsize;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
654 Py_ssize_t othersize;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
655
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
656 if ( self->b_readonly ) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
657 PyErr_SetString(PyExc_TypeError,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
658 "buffer is read-only");
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
659 return -1;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
660 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
661
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
662 pb = value ? value->ob_type->tp_as_buffer : NULL;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
663 if ( pb == NULL ||
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
664 pb->bf_getreadbuffer == NULL ||
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
665 pb->bf_getsegcount == NULL )
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
666 {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
667 PyErr_BadArgument();
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
668 return -1;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
669 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
670 if ( (*pb->bf_getsegcount)(value, NULL) != 1 )
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
671 {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
672 /* ### use a different exception type/message? */
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
673 PyErr_SetString(PyExc_TypeError,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
674 "single-segment buffer object expected");
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
675 return -1;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
676 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
677 if (!get_buf(self, &ptr1, &selfsize, ANY_BUFFER))
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
678 return -1;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
679 if (PyIndex_Check(item)) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
680 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
681 if (i == -1 && PyErr_Occurred())
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
682 return -1;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
683 if (i < 0)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
684 i += selfsize;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
685 return buffer_ass_item(self, i, value);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
686 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
687 else if (PySlice_Check(item)) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
688 Py_ssize_t start, stop, step, slicelength;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
689
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
690 if (PySlice_GetIndicesEx((PySliceObject *)item, selfsize,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
691 &start, &stop, &step, &slicelength) < 0)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
692 return -1;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
693
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
694 if ((othersize = (*pb->bf_getreadbuffer)(value, 0, &ptr2)) < 0)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
695 return -1;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
696
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
697 if (othersize != slicelength) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
698 PyErr_SetString(
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
699 PyExc_TypeError,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
700 "right operand length must match slice length");
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
701 return -1;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
702 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
703
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
704 if (slicelength == 0)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
705 return 0;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
706 else if (step == 1) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
707 memcpy((char *)ptr1 + start, ptr2, slicelength);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
708 return 0;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
709 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
710 else {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
711 Py_ssize_t cur, i;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
712
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
713 for (cur = start, i = 0; i < slicelength;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
714 cur += step, i++) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
715 ((char *)ptr1)[cur] = ((char *)ptr2)[i];
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
716 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
717
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
718 return 0;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
719 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
720 } else {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
721 PyErr_SetString(PyExc_TypeError,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
722 "buffer indices must be integers");
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
723 return -1;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
724 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
725 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
726
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
727 /* Buffer methods */
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
728
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
729 static Py_ssize_t
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
730 buffer_getreadbuf(PyBufferObject *self, Py_ssize_t idx, void **pp)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
731 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
732 Py_ssize_t size;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
733 if ( idx != 0 ) {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
734 PyErr_SetString(PyExc_SystemError,
9305
083efa076366 Greg Stein: Implement the new bf_getcharbuffer function, indicating
Guido van Rossum <guido@python.org>
parents: 9286
diff changeset
735 "accessing non-existent buffer segment");
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
736 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
737 }
38693
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
738 if (!get_buf(self, pp, &size, READ_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
739 return -1;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
740 return size;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
741 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
742
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
743 static Py_ssize_t
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
744 buffer_getwritebuf(PyBufferObject *self, Py_ssize_t idx, void **pp)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
745 {
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
746 Py_ssize_t size;
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
747
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
748 if ( self->b_readonly )
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
749 {
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
750 PyErr_SetString(PyExc_TypeError, "buffer is read-only");
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
751 return -1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
752 }
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
753
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
754 if ( idx != 0 ) {
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
755 PyErr_SetString(PyExc_SystemError,
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
756 "accessing non-existent buffer segment");
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
757 return -1;
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
758 }
38693
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
759 if (!get_buf(self, pp, &size, WRITE_BUFFER))
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
760 return -1;
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
761 return size;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
762 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
763
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
764 static Py_ssize_t
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
765 buffer_getsegcount(PyBufferObject *self, Py_ssize_t *lenp)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
766 {
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
767 void *ptr;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
768 Py_ssize_t size;
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
769 if (!get_buf(self, &ptr, &size, ANY_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
770 return -1;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
771 if (lenp)
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
772 *lenp = size;
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
773 return 1;
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
774 }
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
775
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
776 static Py_ssize_t
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
777 buffer_getcharbuf(PyBufferObject *self, Py_ssize_t idx, const char **pp)
9305
083efa076366 Greg Stein: Implement the new bf_getcharbuffer function, indicating
Guido van Rossum <guido@python.org>
parents: 9286
diff changeset
778 {
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
779 void *ptr;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
780 Py_ssize_t size;
9305
083efa076366 Greg Stein: Implement the new bf_getcharbuffer function, indicating
Guido van Rossum <guido@python.org>
parents: 9286
diff changeset
781 if ( idx != 0 ) {
083efa076366 Greg Stein: Implement the new bf_getcharbuffer function, indicating
Guido van Rossum <guido@python.org>
parents: 9286
diff changeset
782 PyErr_SetString(PyExc_SystemError,
083efa076366 Greg Stein: Implement the new bf_getcharbuffer function, indicating
Guido van Rossum <guido@python.org>
parents: 9286
diff changeset
783 "accessing non-existent buffer segment");
083efa076366 Greg Stein: Implement the new bf_getcharbuffer function, indicating
Guido van Rossum <guido@python.org>
parents: 9286
diff changeset
784 return -1;
083efa076366 Greg Stein: Implement the new bf_getcharbuffer function, indicating
Guido van Rossum <guido@python.org>
parents: 9286
diff changeset
785 }
38693
72e37ada4170 Fix inconsistency in naming within an enum.
Brett Cannon <bcannon@gmail.com>
parents: 38676
diff changeset
786 if (!get_buf(self, &ptr, &size, CHAR_BUFFER))
31640
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
787 return -1;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
788 *pp = (const char *)ptr;
42f8820686c9 Make buffer objects based on mutable objects (like array) safe.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 31639
diff changeset
789 return size;
9305
083efa076366 Greg Stein: Implement the new bf_getcharbuffer function, indicating
Guido van Rossum <guido@python.org>
parents: 9286
diff changeset
790 }
083efa076366 Greg Stein: Implement the new bf_getcharbuffer function, indicating
Guido van Rossum <guido@python.org>
parents: 9286
diff changeset
791
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
792 static PySequenceMethods buffer_as_sequence = {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
793 (lenfunc)buffer_length, /*sq_length*/
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
794 (binaryfunc)buffer_concat, /*sq_concat*/
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
795 (ssizeargfunc)buffer_repeat, /*sq_repeat*/
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
796 (ssizeargfunc)buffer_item, /*sq_item*/
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
797 (ssizessizeargfunc)buffer_slice, /*sq_slice*/
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
798 (ssizeobjargproc)buffer_ass_item, /*sq_ass_item*/
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
799 (ssizessizeobjargproc)buffer_ass_slice, /*sq_ass_slice*/
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
800 };
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
801
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
802 static PyMappingMethods buffer_as_mapping = {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
803 (lenfunc)buffer_length,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
804 (binaryfunc)buffer_subscript,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
805 (objobjargproc)buffer_ass_subscript,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
806 };
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
807
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
808 static PyBufferProcs buffer_as_buffer = {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
809 (readbufferproc)buffer_getreadbuf,
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
810 (writebufferproc)buffer_getwritebuf,
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
811 (segcountproc)buffer_getsegcount,
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36082
diff changeset
812 (charbufferproc)buffer_getcharbuf,
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
813 };
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
814
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
815 PyTypeObject PyBuffer_Type = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 41996
diff changeset
816 PyVarObject_HEAD_INIT(&PyType_Type, 0)
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
817 "buffer",
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
818 sizeof(PyBufferObject),
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
819 0,
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
820 (destructor)buffer_dealloc, /* tp_dealloc */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
821 0, /* tp_print */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
822 0, /* tp_getattr */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
823 0, /* tp_setattr */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
824 (cmpfunc)buffer_compare, /* tp_compare */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
825 (reprfunc)buffer_repr, /* tp_repr */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
826 0, /* tp_as_number */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
827 &buffer_as_sequence, /* tp_as_sequence */
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
828 &buffer_as_mapping, /* tp_as_mapping */
18933
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
829 (hashfunc)buffer_hash, /* tp_hash */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
830 0, /* tp_call */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
831 (reprfunc)buffer_str, /* tp_str */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
832 PyObject_GenericGetAttr, /* tp_getattro */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
833 0, /* tp_setattro */
09df3254b49d Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
834 &buffer_as_buffer, /* tp_as_buffer */
38676
5bc7272b81e5 Buffer objects would return the read or write buffer for a wrapped object when
Brett Cannon <bcannon@gmail.com>
parents: 37589
diff changeset
835 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GETCHARBUFFER, /* tp_flags */
23868
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
836 buffer_doc, /* tp_doc */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
837 0, /* tp_traverse */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
838 0, /* tp_clear */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
839 0, /* tp_richcompare */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
840 0, /* tp_weaklistoffset */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
841 0, /* tp_iter */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
842 0, /* tp_iternext */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
843 0, /* tp_methods */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
844 0, /* tp_members */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
845 0, /* tp_getset */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
846 0, /* tp_base */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
847 0, /* tp_dict */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
848 0, /* tp_descr_get */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
849 0, /* tp_descr_set */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
850 0, /* tp_dictoffset */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
851 0, /* tp_init */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
852 0, /* tp_alloc */
8e6760bf1884 SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents: 22651
diff changeset
853 buffer_new, /* tp_new */
9278
c39218a68df1 Add Greg Stein's buffer object API.
Guido van Rossum <guido@python.org>
parents:
diff changeset
854 };