blob: 300cd1397101e85156c05689c5f181a9ec5eb196 [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 \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020068 {"pop", (PyCFunction)(void(*)(void))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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020074array_array_pop(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
Brett Cannon1eb32c22014-10-10 16:26:45 -040075{
76 PyObject *return_value = NULL;
77 Py_ssize_t i = -1;
78
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020079 if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010080 goto exit;
81 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020082 if (nargs < 1) {
83 goto skip_optional;
84 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020085 {
86 Py_ssize_t ival = -1;
Serhiy Storchaka5f4b229d2020-05-28 10:33:45 +030087 PyObject *iobj = _PyNumber_Index(args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020088 if (iobj != NULL) {
89 ival = PyLong_AsSsize_t(iobj);
90 Py_DECREF(iobj);
91 }
92 if (ival == -1 && PyErr_Occurred()) {
93 goto exit;
94 }
95 i = ival;
96 }
97skip_optional:
Brett Cannon1eb32c22014-10-10 16:26:45 -040098 return_value = array_array_pop_impl(self, i);
99
100exit:
101 return return_value;
102}
103
104PyDoc_STRVAR(array_array_extend__doc__,
105"extend($self, bb, /)\n"
106"--\n"
107"\n"
108"Append items to the end of the array.");
109
110#define ARRAY_ARRAY_EXTEND_METHODDEF \
111 {"extend", (PyCFunction)array_array_extend, METH_O, array_array_extend__doc__},
112
113PyDoc_STRVAR(array_array_insert__doc__,
114"insert($self, i, v, /)\n"
115"--\n"
116"\n"
117"Insert a new item v into the array before position i.");
118
119#define ARRAY_ARRAY_INSERT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200120 {"insert", (PyCFunction)(void(*)(void))array_array_insert, METH_FASTCALL, array_array_insert__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400121
122static PyObject *
123array_array_insert_impl(arrayobject *self, Py_ssize_t i, PyObject *v);
124
125static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200126array_array_insert(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400127{
128 PyObject *return_value = NULL;
129 Py_ssize_t i;
130 PyObject *v;
131
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200132 if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100133 goto exit;
134 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200135 {
136 Py_ssize_t ival = -1;
Serhiy Storchaka5f4b229d2020-05-28 10:33:45 +0300137 PyObject *iobj = _PyNumber_Index(args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200138 if (iobj != NULL) {
139 ival = PyLong_AsSsize_t(iobj);
140 Py_DECREF(iobj);
141 }
142 if (ival == -1 && PyErr_Occurred()) {
143 goto exit;
144 }
145 i = ival;
146 }
147 v = args[1];
Brett Cannon1eb32c22014-10-10 16:26:45 -0400148 return_value = array_array_insert_impl(self, i, v);
149
150exit:
151 return return_value;
152}
153
154PyDoc_STRVAR(array_array_buffer_info__doc__,
155"buffer_info($self, /)\n"
156"--\n"
157"\n"
158"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"
159"\n"
160"The length should be multiplied by the itemsize attribute to calculate\n"
161"the buffer length in bytes.");
162
163#define ARRAY_ARRAY_BUFFER_INFO_METHODDEF \
164 {"buffer_info", (PyCFunction)array_array_buffer_info, METH_NOARGS, array_array_buffer_info__doc__},
165
166static PyObject *
167array_array_buffer_info_impl(arrayobject *self);
168
169static PyObject *
170array_array_buffer_info(arrayobject *self, PyObject *Py_UNUSED(ignored))
171{
172 return array_array_buffer_info_impl(self);
173}
174
175PyDoc_STRVAR(array_array_append__doc__,
176"append($self, v, /)\n"
177"--\n"
178"\n"
179"Append new value v to the end of the array.");
180
181#define ARRAY_ARRAY_APPEND_METHODDEF \
182 {"append", (PyCFunction)array_array_append, METH_O, array_array_append__doc__},
183
184PyDoc_STRVAR(array_array_byteswap__doc__,
185"byteswap($self, /)\n"
186"--\n"
187"\n"
188"Byteswap all items of the array.\n"
189"\n"
190"If the items in the array are not 1, 2, 4, or 8 bytes in size, RuntimeError is\n"
191"raised.");
192
193#define ARRAY_ARRAY_BYTESWAP_METHODDEF \
194 {"byteswap", (PyCFunction)array_array_byteswap, METH_NOARGS, array_array_byteswap__doc__},
195
196static PyObject *
197array_array_byteswap_impl(arrayobject *self);
198
199static PyObject *
200array_array_byteswap(arrayobject *self, PyObject *Py_UNUSED(ignored))
201{
202 return array_array_byteswap_impl(self);
203}
204
205PyDoc_STRVAR(array_array_reverse__doc__,
206"reverse($self, /)\n"
207"--\n"
208"\n"
209"Reverse the order of the items in the array.");
210
211#define ARRAY_ARRAY_REVERSE_METHODDEF \
212 {"reverse", (PyCFunction)array_array_reverse, METH_NOARGS, array_array_reverse__doc__},
213
214static PyObject *
215array_array_reverse_impl(arrayobject *self);
216
217static PyObject *
218array_array_reverse(arrayobject *self, PyObject *Py_UNUSED(ignored))
219{
220 return array_array_reverse_impl(self);
221}
222
223PyDoc_STRVAR(array_array_fromfile__doc__,
224"fromfile($self, f, n, /)\n"
225"--\n"
226"\n"
227"Read n objects from the file object f and append them to the end of the array.");
228
229#define ARRAY_ARRAY_FROMFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200230 {"fromfile", (PyCFunction)(void(*)(void))array_array_fromfile, METH_FASTCALL, array_array_fromfile__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400231
232static PyObject *
233array_array_fromfile_impl(arrayobject *self, PyObject *f, Py_ssize_t n);
234
235static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200236array_array_fromfile(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400237{
238 PyObject *return_value = NULL;
239 PyObject *f;
240 Py_ssize_t n;
241
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200242 if (!_PyArg_CheckPositional("fromfile", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100243 goto exit;
244 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200245 f = args[0];
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200246 {
247 Py_ssize_t ival = -1;
Serhiy Storchaka5f4b229d2020-05-28 10:33:45 +0300248 PyObject *iobj = _PyNumber_Index(args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200249 if (iobj != NULL) {
250 ival = PyLong_AsSsize_t(iobj);
251 Py_DECREF(iobj);
252 }
253 if (ival == -1 && PyErr_Occurred()) {
254 goto exit;
255 }
256 n = ival;
257 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400258 return_value = array_array_fromfile_impl(self, f, n);
259
260exit:
261 return return_value;
262}
263
264PyDoc_STRVAR(array_array_tofile__doc__,
265"tofile($self, f, /)\n"
266"--\n"
267"\n"
268"Write all items (as machine values) to the file object f.");
269
270#define ARRAY_ARRAY_TOFILE_METHODDEF \
271 {"tofile", (PyCFunction)array_array_tofile, METH_O, array_array_tofile__doc__},
272
273PyDoc_STRVAR(array_array_fromlist__doc__,
274"fromlist($self, list, /)\n"
275"--\n"
276"\n"
277"Append items to array from list.");
278
279#define ARRAY_ARRAY_FROMLIST_METHODDEF \
280 {"fromlist", (PyCFunction)array_array_fromlist, METH_O, array_array_fromlist__doc__},
281
282PyDoc_STRVAR(array_array_tolist__doc__,
283"tolist($self, /)\n"
284"--\n"
285"\n"
286"Convert array to an ordinary list with the same items.");
287
288#define ARRAY_ARRAY_TOLIST_METHODDEF \
289 {"tolist", (PyCFunction)array_array_tolist, METH_NOARGS, array_array_tolist__doc__},
290
291static PyObject *
292array_array_tolist_impl(arrayobject *self);
293
294static PyObject *
295array_array_tolist(arrayobject *self, PyObject *Py_UNUSED(ignored))
296{
297 return array_array_tolist_impl(self);
298}
299
Brett Cannon1eb32c22014-10-10 16:26:45 -0400300PyDoc_STRVAR(array_array_frombytes__doc__,
301"frombytes($self, buffer, /)\n"
302"--\n"
303"\n"
304"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).");
305
306#define ARRAY_ARRAY_FROMBYTES_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300307 {"frombytes", (PyCFunction)array_array_frombytes, METH_O, array_array_frombytes__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400308
309static PyObject *
310array_array_frombytes_impl(arrayobject *self, Py_buffer *buffer);
311
312static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300313array_array_frombytes(arrayobject *self, PyObject *arg)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400314{
315 PyObject *return_value = NULL;
316 Py_buffer buffer = {NULL, NULL};
317
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200318 if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
319 goto exit;
320 }
321 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200322 _PyArg_BadArgument("frombytes", "argument", "contiguous buffer", arg);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400323 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300324 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400325 return_value = array_array_frombytes_impl(self, &buffer);
326
327exit:
328 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300329 if (buffer.obj) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400330 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300331 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400332
333 return return_value;
334}
335
336PyDoc_STRVAR(array_array_tobytes__doc__,
337"tobytes($self, /)\n"
338"--\n"
339"\n"
340"Convert the array to an array of machine values and return the bytes representation.");
341
342#define ARRAY_ARRAY_TOBYTES_METHODDEF \
343 {"tobytes", (PyCFunction)array_array_tobytes, METH_NOARGS, array_array_tobytes__doc__},
344
345static PyObject *
346array_array_tobytes_impl(arrayobject *self);
347
348static PyObject *
349array_array_tobytes(arrayobject *self, PyObject *Py_UNUSED(ignored))
350{
351 return array_array_tobytes_impl(self);
352}
353
Brett Cannon1eb32c22014-10-10 16:26:45 -0400354PyDoc_STRVAR(array_array_fromunicode__doc__,
355"fromunicode($self, ustr, /)\n"
356"--\n"
357"\n"
358"Extends this array with data from the unicode string ustr.\n"
359"\n"
360"The array must be a unicode type array; otherwise a ValueError is raised.\n"
361"Use array.frombytes(ustr.encode(...)) to append Unicode data to an array of\n"
362"some other type.");
363
364#define ARRAY_ARRAY_FROMUNICODE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300365 {"fromunicode", (PyCFunction)array_array_fromunicode, METH_O, array_array_fromunicode__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400366
367static PyObject *
Inada Naokid5d9a712020-05-11 15:37:25 +0900368array_array_fromunicode_impl(arrayobject *self, PyObject *ustr);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400369
370static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300371array_array_fromunicode(arrayobject *self, PyObject *arg)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400372{
373 PyObject *return_value = NULL;
Inada Naokid5d9a712020-05-11 15:37:25 +0900374 PyObject *ustr;
Brett Cannon1eb32c22014-10-10 16:26:45 -0400375
Inada Naokid5d9a712020-05-11 15:37:25 +0900376 if (!PyUnicode_Check(arg)) {
377 _PyArg_BadArgument("fromunicode", "argument", "str", arg);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400378 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300379 }
Inada Naokid5d9a712020-05-11 15:37:25 +0900380 if (PyUnicode_READY(arg) == -1) {
381 goto exit;
382 }
383 ustr = arg;
384 return_value = array_array_fromunicode_impl(self, ustr);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400385
386exit:
387 return return_value;
388}
389
390PyDoc_STRVAR(array_array_tounicode__doc__,
391"tounicode($self, /)\n"
392"--\n"
393"\n"
394"Extends this array with data from the unicode string ustr.\n"
395"\n"
396"Convert the array to a unicode string. The array must be a unicode type array;\n"
397"otherwise a ValueError is raised. Use array.tobytes().decode() to obtain a\n"
398"unicode string from an array of some other type.");
399
400#define ARRAY_ARRAY_TOUNICODE_METHODDEF \
401 {"tounicode", (PyCFunction)array_array_tounicode, METH_NOARGS, array_array_tounicode__doc__},
402
403static PyObject *
404array_array_tounicode_impl(arrayobject *self);
405
406static PyObject *
407array_array_tounicode(arrayobject *self, PyObject *Py_UNUSED(ignored))
408{
409 return array_array_tounicode_impl(self);
410}
411
412PyDoc_STRVAR(array_array___sizeof____doc__,
413"__sizeof__($self, /)\n"
414"--\n"
415"\n"
416"Size of the array in memory, in bytes.");
417
418#define ARRAY_ARRAY___SIZEOF___METHODDEF \
419 {"__sizeof__", (PyCFunction)array_array___sizeof__, METH_NOARGS, array_array___sizeof____doc__},
420
421static PyObject *
422array_array___sizeof___impl(arrayobject *self);
423
424static PyObject *
425array_array___sizeof__(arrayobject *self, PyObject *Py_UNUSED(ignored))
426{
427 return array_array___sizeof___impl(self);
428}
429
430PyDoc_STRVAR(array__array_reconstructor__doc__,
431"_array_reconstructor($module, arraytype, typecode, mformat_code, items,\n"
432" /)\n"
433"--\n"
434"\n"
435"Internal. Used for pickling support.");
436
437#define ARRAY__ARRAY_RECONSTRUCTOR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200438 {"_array_reconstructor", (PyCFunction)(void(*)(void))array__array_reconstructor, METH_FASTCALL, array__array_reconstructor__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400439
440static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300441array__array_reconstructor_impl(PyObject *module, PyTypeObject *arraytype,
Larry Hastings89964c42015-04-14 18:07:59 -0400442 int typecode,
443 enum machine_format_code mformat_code,
444 PyObject *items);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400445
446static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200447array__array_reconstructor(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400448{
449 PyObject *return_value = NULL;
450 PyTypeObject *arraytype;
451 int typecode;
Larry Hastingsdfbeb162014-10-13 10:39:41 +0100452 enum machine_format_code mformat_code;
Brett Cannon1eb32c22014-10-10 16:26:45 -0400453 PyObject *items;
454
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200455 if (!_PyArg_CheckPositional("_array_reconstructor", nargs, 4, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100456 goto exit;
457 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200458 arraytype = (PyTypeObject *)args[0];
459 if (!PyUnicode_Check(args[1])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200460 _PyArg_BadArgument("_array_reconstructor", "argument 2", "a unicode character", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200461 goto exit;
462 }
463 if (PyUnicode_READY(args[1])) {
464 goto exit;
465 }
466 if (PyUnicode_GET_LENGTH(args[1]) != 1) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200467 _PyArg_BadArgument("_array_reconstructor", "argument 2", "a unicode character", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200468 goto exit;
469 }
470 typecode = PyUnicode_READ_CHAR(args[1], 0);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200471 mformat_code = _PyLong_AsInt(args[2]);
472 if (mformat_code == -1 && PyErr_Occurred()) {
473 goto exit;
474 }
475 items = args[3];
Brett Cannon1eb32c22014-10-10 16:26:45 -0400476 return_value = array__array_reconstructor_impl(module, arraytype, typecode, mformat_code, items);
477
478exit:
479 return return_value;
480}
481
482PyDoc_STRVAR(array_array___reduce_ex____doc__,
483"__reduce_ex__($self, value, /)\n"
484"--\n"
485"\n"
486"Return state information for pickling.");
487
488#define ARRAY_ARRAY___REDUCE_EX___METHODDEF \
489 {"__reduce_ex__", (PyCFunction)array_array___reduce_ex__, METH_O, array_array___reduce_ex____doc__},
490
491PyDoc_STRVAR(array_arrayiterator___reduce____doc__,
492"__reduce__($self, /)\n"
493"--\n"
494"\n"
495"Return state information for pickling.");
496
497#define ARRAY_ARRAYITERATOR___REDUCE___METHODDEF \
498 {"__reduce__", (PyCFunction)array_arrayiterator___reduce__, METH_NOARGS, array_arrayiterator___reduce____doc__},
499
500static PyObject *
501array_arrayiterator___reduce___impl(arrayiterobject *self);
502
503static PyObject *
504array_arrayiterator___reduce__(arrayiterobject *self, PyObject *Py_UNUSED(ignored))
505{
506 return array_arrayiterator___reduce___impl(self);
507}
508
509PyDoc_STRVAR(array_arrayiterator___setstate____doc__,
510"__setstate__($self, state, /)\n"
511"--\n"
512"\n"
513"Set state information for unpickling.");
514
515#define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \
516 {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__},
Serhiy Storchaka5f4b229d2020-05-28 10:33:45 +0300517/*[clinic end generated code: output=91c1cded65a1285f input=a9049054013a1b77]*/