blob: 6ffd4ff39ff91233e2a7adffaee0fb0908e95305 [file] [log] [blame]
Brett Cannon1eb32c22014-10-10 16:26:45 -04001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(array_array___copy____doc__,
6"__copy__($self, /)\n"
7"--\n"
8"\n"
9"Return a copy of the array.");
10
11#define ARRAY_ARRAY___COPY___METHODDEF \
12 {"__copy__", (PyCFunction)array_array___copy__, METH_NOARGS, array_array___copy____doc__},
13
14static PyObject *
15array_array___copy___impl(arrayobject *self);
16
17static PyObject *
18array_array___copy__(arrayobject *self, PyObject *Py_UNUSED(ignored))
19{
20 return array_array___copy___impl(self);
21}
22
23PyDoc_STRVAR(array_array___deepcopy____doc__,
24"__deepcopy__($self, unused, /)\n"
25"--\n"
26"\n"
27"Return a copy of the array.");
28
29#define ARRAY_ARRAY___DEEPCOPY___METHODDEF \
30 {"__deepcopy__", (PyCFunction)array_array___deepcopy__, METH_O, array_array___deepcopy____doc__},
31
32PyDoc_STRVAR(array_array_count__doc__,
33"count($self, v, /)\n"
34"--\n"
35"\n"
36"Return number of occurrences of v in the array.");
37
38#define ARRAY_ARRAY_COUNT_METHODDEF \
39 {"count", (PyCFunction)array_array_count, METH_O, array_array_count__doc__},
40
41PyDoc_STRVAR(array_array_index__doc__,
42"index($self, v, /)\n"
43"--\n"
44"\n"
45"Return index of first occurrence of v in the array.");
46
47#define ARRAY_ARRAY_INDEX_METHODDEF \
48 {"index", (PyCFunction)array_array_index, METH_O, array_array_index__doc__},
49
50PyDoc_STRVAR(array_array_remove__doc__,
51"remove($self, v, /)\n"
52"--\n"
53"\n"
54"Remove the first occurrence of v in the array.");
55
56#define ARRAY_ARRAY_REMOVE_METHODDEF \
57 {"remove", (PyCFunction)array_array_remove, METH_O, array_array_remove__doc__},
58
59PyDoc_STRVAR(array_array_pop__doc__,
60"pop($self, i=-1, /)\n"
61"--\n"
62"\n"
63"Return the i-th element and delete it from the array.\n"
64"\n"
65"i defaults to -1.");
66
67#define ARRAY_ARRAY_POP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +010068 {"pop", (PyCFunction)array_array_pop, METH_FASTCALL, array_array_pop__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -040069
70static PyObject *
71array_array_pop_impl(arrayobject *self, Py_ssize_t i);
72
73static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +010074array_array_pop(arrayobject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Brett Cannon1eb32c22014-10-10 16:26:45 -040075{
76 PyObject *return_value = NULL;
77 Py_ssize_t i = -1;
78
Sylvain74453812017-06-10 06:51:48 +020079 if (!_PyArg_NoStackKeywords("pop", kwnames)) {
Brett Cannon1eb32c22014-10-10 16:26:45 -040080 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030081 }
Victor Stinner259f0e42017-01-17 01:35:17 +010082
Sylvain74453812017-06-10 06:51:48 +020083 if (!_PyArg_ParseStack(args, nargs, "|n:pop",
84 &i)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010085 goto exit;
86 }
Brett Cannon1eb32c22014-10-10 16:26:45 -040087 return_value = array_array_pop_impl(self, i);
88
89exit:
90 return return_value;
91}
92
93PyDoc_STRVAR(array_array_extend__doc__,
94"extend($self, bb, /)\n"
95"--\n"
96"\n"
97"Append items to the end of the array.");
98
99#define ARRAY_ARRAY_EXTEND_METHODDEF \
100 {"extend", (PyCFunction)array_array_extend, METH_O, array_array_extend__doc__},
101
102PyDoc_STRVAR(array_array_insert__doc__,
103"insert($self, i, v, /)\n"
104"--\n"
105"\n"
106"Insert a new item v into the array before position i.");
107
108#define ARRAY_ARRAY_INSERT_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100109 {"insert", (PyCFunction)array_array_insert, METH_FASTCALL, array_array_insert__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400110
111static PyObject *
112array_array_insert_impl(arrayobject *self, Py_ssize_t i, PyObject *v);
113
114static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100115array_array_insert(arrayobject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400116{
117 PyObject *return_value = NULL;
118 Py_ssize_t i;
119 PyObject *v;
120
Sylvain74453812017-06-10 06:51:48 +0200121 if (!_PyArg_NoStackKeywords("insert", kwnames)) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400122 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300123 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100124
Sylvain74453812017-06-10 06:51:48 +0200125 if (!_PyArg_ParseStack(args, nargs, "nO:insert",
126 &i, &v)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100127 goto exit;
128 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400129 return_value = array_array_insert_impl(self, i, v);
130
131exit:
132 return return_value;
133}
134
135PyDoc_STRVAR(array_array_buffer_info__doc__,
136"buffer_info($self, /)\n"
137"--\n"
138"\n"
139"Return a tuple (address, length) giving the current memory address and the length in items of the buffer used to hold array\'s contents.\n"
140"\n"
141"The length should be multiplied by the itemsize attribute to calculate\n"
142"the buffer length in bytes.");
143
144#define ARRAY_ARRAY_BUFFER_INFO_METHODDEF \
145 {"buffer_info", (PyCFunction)array_array_buffer_info, METH_NOARGS, array_array_buffer_info__doc__},
146
147static PyObject *
148array_array_buffer_info_impl(arrayobject *self);
149
150static PyObject *
151array_array_buffer_info(arrayobject *self, PyObject *Py_UNUSED(ignored))
152{
153 return array_array_buffer_info_impl(self);
154}
155
156PyDoc_STRVAR(array_array_append__doc__,
157"append($self, v, /)\n"
158"--\n"
159"\n"
160"Append new value v to the end of the array.");
161
162#define ARRAY_ARRAY_APPEND_METHODDEF \
163 {"append", (PyCFunction)array_array_append, METH_O, array_array_append__doc__},
164
165PyDoc_STRVAR(array_array_byteswap__doc__,
166"byteswap($self, /)\n"
167"--\n"
168"\n"
169"Byteswap all items of the array.\n"
170"\n"
171"If the items in the array are not 1, 2, 4, or 8 bytes in size, RuntimeError is\n"
172"raised.");
173
174#define ARRAY_ARRAY_BYTESWAP_METHODDEF \
175 {"byteswap", (PyCFunction)array_array_byteswap, METH_NOARGS, array_array_byteswap__doc__},
176
177static PyObject *
178array_array_byteswap_impl(arrayobject *self);
179
180static PyObject *
181array_array_byteswap(arrayobject *self, PyObject *Py_UNUSED(ignored))
182{
183 return array_array_byteswap_impl(self);
184}
185
186PyDoc_STRVAR(array_array_reverse__doc__,
187"reverse($self, /)\n"
188"--\n"
189"\n"
190"Reverse the order of the items in the array.");
191
192#define ARRAY_ARRAY_REVERSE_METHODDEF \
193 {"reverse", (PyCFunction)array_array_reverse, METH_NOARGS, array_array_reverse__doc__},
194
195static PyObject *
196array_array_reverse_impl(arrayobject *self);
197
198static PyObject *
199array_array_reverse(arrayobject *self, PyObject *Py_UNUSED(ignored))
200{
201 return array_array_reverse_impl(self);
202}
203
204PyDoc_STRVAR(array_array_fromfile__doc__,
205"fromfile($self, f, n, /)\n"
206"--\n"
207"\n"
208"Read n objects from the file object f and append them to the end of the array.");
209
210#define ARRAY_ARRAY_FROMFILE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100211 {"fromfile", (PyCFunction)array_array_fromfile, METH_FASTCALL, array_array_fromfile__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400212
213static PyObject *
214array_array_fromfile_impl(arrayobject *self, PyObject *f, Py_ssize_t n);
215
216static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100217array_array_fromfile(arrayobject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400218{
219 PyObject *return_value = NULL;
220 PyObject *f;
221 Py_ssize_t n;
222
Sylvain74453812017-06-10 06:51:48 +0200223 if (!_PyArg_NoStackKeywords("fromfile", kwnames)) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400224 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300225 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100226
Sylvain74453812017-06-10 06:51:48 +0200227 if (!_PyArg_ParseStack(args, nargs, "On:fromfile",
228 &f, &n)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100229 goto exit;
230 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400231 return_value = array_array_fromfile_impl(self, f, n);
232
233exit:
234 return return_value;
235}
236
237PyDoc_STRVAR(array_array_tofile__doc__,
238"tofile($self, f, /)\n"
239"--\n"
240"\n"
241"Write all items (as machine values) to the file object f.");
242
243#define ARRAY_ARRAY_TOFILE_METHODDEF \
244 {"tofile", (PyCFunction)array_array_tofile, METH_O, array_array_tofile__doc__},
245
246PyDoc_STRVAR(array_array_fromlist__doc__,
247"fromlist($self, list, /)\n"
248"--\n"
249"\n"
250"Append items to array from list.");
251
252#define ARRAY_ARRAY_FROMLIST_METHODDEF \
253 {"fromlist", (PyCFunction)array_array_fromlist, METH_O, array_array_fromlist__doc__},
254
255PyDoc_STRVAR(array_array_tolist__doc__,
256"tolist($self, /)\n"
257"--\n"
258"\n"
259"Convert array to an ordinary list with the same items.");
260
261#define ARRAY_ARRAY_TOLIST_METHODDEF \
262 {"tolist", (PyCFunction)array_array_tolist, METH_NOARGS, array_array_tolist__doc__},
263
264static PyObject *
265array_array_tolist_impl(arrayobject *self);
266
267static PyObject *
268array_array_tolist(arrayobject *self, PyObject *Py_UNUSED(ignored))
269{
270 return array_array_tolist_impl(self);
271}
272
273PyDoc_STRVAR(array_array_fromstring__doc__,
274"fromstring($self, buffer, /)\n"
275"--\n"
276"\n"
277"Appends items from the string, interpreting it as an array of machine values, as if it had been read from a file using the fromfile() method).\n"
278"\n"
279"This method is deprecated. Use frombytes instead.");
280
281#define ARRAY_ARRAY_FROMSTRING_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300282 {"fromstring", (PyCFunction)array_array_fromstring, METH_O, array_array_fromstring__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400283
284static PyObject *
285array_array_fromstring_impl(arrayobject *self, Py_buffer *buffer);
286
287static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300288array_array_fromstring(arrayobject *self, PyObject *arg)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400289{
290 PyObject *return_value = NULL;
291 Py_buffer buffer = {NULL, NULL};
292
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300293 if (!PyArg_Parse(arg, "s*:fromstring", &buffer)) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400294 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300295 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400296 return_value = array_array_fromstring_impl(self, &buffer);
297
298exit:
299 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300300 if (buffer.obj) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400301 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300302 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400303
304 return return_value;
305}
306
307PyDoc_STRVAR(array_array_frombytes__doc__,
308"frombytes($self, buffer, /)\n"
309"--\n"
310"\n"
311"Appends items from the string, interpreting it as an array of machine values, as if it had been read from a file using the fromfile() method).");
312
313#define ARRAY_ARRAY_FROMBYTES_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300314 {"frombytes", (PyCFunction)array_array_frombytes, METH_O, array_array_frombytes__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400315
316static PyObject *
317array_array_frombytes_impl(arrayobject *self, Py_buffer *buffer);
318
319static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300320array_array_frombytes(arrayobject *self, PyObject *arg)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400321{
322 PyObject *return_value = NULL;
323 Py_buffer buffer = {NULL, NULL};
324
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300325 if (!PyArg_Parse(arg, "y*:frombytes", &buffer)) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400326 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300327 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400328 return_value = array_array_frombytes_impl(self, &buffer);
329
330exit:
331 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300332 if (buffer.obj) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400333 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300334 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400335
336 return return_value;
337}
338
339PyDoc_STRVAR(array_array_tobytes__doc__,
340"tobytes($self, /)\n"
341"--\n"
342"\n"
343"Convert the array to an array of machine values and return the bytes representation.");
344
345#define ARRAY_ARRAY_TOBYTES_METHODDEF \
346 {"tobytes", (PyCFunction)array_array_tobytes, METH_NOARGS, array_array_tobytes__doc__},
347
348static PyObject *
349array_array_tobytes_impl(arrayobject *self);
350
351static PyObject *
352array_array_tobytes(arrayobject *self, PyObject *Py_UNUSED(ignored))
353{
354 return array_array_tobytes_impl(self);
355}
356
357PyDoc_STRVAR(array_array_tostring__doc__,
358"tostring($self, /)\n"
359"--\n"
360"\n"
361"Convert the array to an array of machine values and return the bytes representation.\n"
362"\n"
363"This method is deprecated. Use tobytes instead.");
364
365#define ARRAY_ARRAY_TOSTRING_METHODDEF \
366 {"tostring", (PyCFunction)array_array_tostring, METH_NOARGS, array_array_tostring__doc__},
367
368static PyObject *
369array_array_tostring_impl(arrayobject *self);
370
371static PyObject *
372array_array_tostring(arrayobject *self, PyObject *Py_UNUSED(ignored))
373{
374 return array_array_tostring_impl(self);
375}
376
377PyDoc_STRVAR(array_array_fromunicode__doc__,
378"fromunicode($self, ustr, /)\n"
379"--\n"
380"\n"
381"Extends this array with data from the unicode string ustr.\n"
382"\n"
383"The array must be a unicode type array; otherwise a ValueError is raised.\n"
384"Use array.frombytes(ustr.encode(...)) to append Unicode data to an array of\n"
385"some other type.");
386
387#define ARRAY_ARRAY_FROMUNICODE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300388 {"fromunicode", (PyCFunction)array_array_fromunicode, METH_O, array_array_fromunicode__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400389
390static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400391array_array_fromunicode_impl(arrayobject *self, Py_UNICODE *ustr,
392 Py_ssize_clean_t ustr_length);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400393
394static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300395array_array_fromunicode(arrayobject *self, PyObject *arg)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400396{
397 PyObject *return_value = NULL;
398 Py_UNICODE *ustr;
399 Py_ssize_clean_t ustr_length;
400
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300401 if (!PyArg_Parse(arg, "u#:fromunicode", &ustr, &ustr_length)) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400402 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300403 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400404 return_value = array_array_fromunicode_impl(self, ustr, ustr_length);
405
406exit:
407 return return_value;
408}
409
410PyDoc_STRVAR(array_array_tounicode__doc__,
411"tounicode($self, /)\n"
412"--\n"
413"\n"
414"Extends this array with data from the unicode string ustr.\n"
415"\n"
416"Convert the array to a unicode string. The array must be a unicode type array;\n"
417"otherwise a ValueError is raised. Use array.tobytes().decode() to obtain a\n"
418"unicode string from an array of some other type.");
419
420#define ARRAY_ARRAY_TOUNICODE_METHODDEF \
421 {"tounicode", (PyCFunction)array_array_tounicode, METH_NOARGS, array_array_tounicode__doc__},
422
423static PyObject *
424array_array_tounicode_impl(arrayobject *self);
425
426static PyObject *
427array_array_tounicode(arrayobject *self, PyObject *Py_UNUSED(ignored))
428{
429 return array_array_tounicode_impl(self);
430}
431
432PyDoc_STRVAR(array_array___sizeof____doc__,
433"__sizeof__($self, /)\n"
434"--\n"
435"\n"
436"Size of the array in memory, in bytes.");
437
438#define ARRAY_ARRAY___SIZEOF___METHODDEF \
439 {"__sizeof__", (PyCFunction)array_array___sizeof__, METH_NOARGS, array_array___sizeof____doc__},
440
441static PyObject *
442array_array___sizeof___impl(arrayobject *self);
443
444static PyObject *
445array_array___sizeof__(arrayobject *self, PyObject *Py_UNUSED(ignored))
446{
447 return array_array___sizeof___impl(self);
448}
449
450PyDoc_STRVAR(array__array_reconstructor__doc__,
451"_array_reconstructor($module, arraytype, typecode, mformat_code, items,\n"
452" /)\n"
453"--\n"
454"\n"
455"Internal. Used for pickling support.");
456
457#define ARRAY__ARRAY_RECONSTRUCTOR_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100458 {"_array_reconstructor", (PyCFunction)array__array_reconstructor, METH_FASTCALL, array__array_reconstructor__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400459
460static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300461array__array_reconstructor_impl(PyObject *module, PyTypeObject *arraytype,
Larry Hastings89964c42015-04-14 18:07:59 -0400462 int typecode,
463 enum machine_format_code mformat_code,
464 PyObject *items);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400465
466static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100467array__array_reconstructor(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400468{
469 PyObject *return_value = NULL;
470 PyTypeObject *arraytype;
471 int typecode;
Larry Hastingsdfbeb162014-10-13 10:39:41 +0100472 enum machine_format_code mformat_code;
Brett Cannon1eb32c22014-10-10 16:26:45 -0400473 PyObject *items;
474
Sylvain74453812017-06-10 06:51:48 +0200475 if (!_PyArg_NoStackKeywords("_array_reconstructor", kwnames)) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400476 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300477 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100478
Sylvain74453812017-06-10 06:51:48 +0200479 if (!_PyArg_ParseStack(args, nargs, "OCiO:_array_reconstructor",
480 &arraytype, &typecode, &mformat_code, &items)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100481 goto exit;
482 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400483 return_value = array__array_reconstructor_impl(module, arraytype, typecode, mformat_code, items);
484
485exit:
486 return return_value;
487}
488
489PyDoc_STRVAR(array_array___reduce_ex____doc__,
490"__reduce_ex__($self, value, /)\n"
491"--\n"
492"\n"
493"Return state information for pickling.");
494
495#define ARRAY_ARRAY___REDUCE_EX___METHODDEF \
496 {"__reduce_ex__", (PyCFunction)array_array___reduce_ex__, METH_O, array_array___reduce_ex____doc__},
497
498PyDoc_STRVAR(array_arrayiterator___reduce____doc__,
499"__reduce__($self, /)\n"
500"--\n"
501"\n"
502"Return state information for pickling.");
503
504#define ARRAY_ARRAYITERATOR___REDUCE___METHODDEF \
505 {"__reduce__", (PyCFunction)array_arrayiterator___reduce__, METH_NOARGS, array_arrayiterator___reduce____doc__},
506
507static PyObject *
508array_arrayiterator___reduce___impl(arrayiterobject *self);
509
510static PyObject *
511array_arrayiterator___reduce__(arrayiterobject *self, PyObject *Py_UNUSED(ignored))
512{
513 return array_arrayiterator___reduce___impl(self);
514}
515
516PyDoc_STRVAR(array_arrayiterator___setstate____doc__,
517"__setstate__($self, state, /)\n"
518"--\n"
519"\n"
520"Set state information for unpickling.");
521
522#define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \
523 {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__},
Sylvain74453812017-06-10 06:51:48 +0200524/*[clinic end generated code: output=fb4a67e697d7c0b0 input=a9049054013a1b77]*/