blob: b9245ca91d5fa9ca98ff96785aa11571dc04e3e7 [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 }
85 if (PyFloat_Check(args[0])) {
86 PyErr_SetString(PyExc_TypeError,
87 "integer argument expected, got float" );
88 goto exit;
89 }
90 {
91 Py_ssize_t ival = -1;
92 PyObject *iobj = PyNumber_Index(args[0]);
93 if (iobj != NULL) {
94 ival = PyLong_AsSsize_t(iobj);
95 Py_DECREF(iobj);
96 }
97 if (ival == -1 && PyErr_Occurred()) {
98 goto exit;
99 }
100 i = ival;
101 }
102skip_optional:
Brett Cannon1eb32c22014-10-10 16:26:45 -0400103 return_value = array_array_pop_impl(self, i);
104
105exit:
106 return return_value;
107}
108
109PyDoc_STRVAR(array_array_extend__doc__,
110"extend($self, bb, /)\n"
111"--\n"
112"\n"
113"Append items to the end of the array.");
114
115#define ARRAY_ARRAY_EXTEND_METHODDEF \
116 {"extend", (PyCFunction)array_array_extend, METH_O, array_array_extend__doc__},
117
118PyDoc_STRVAR(array_array_insert__doc__,
119"insert($self, i, v, /)\n"
120"--\n"
121"\n"
122"Insert a new item v into the array before position i.");
123
124#define ARRAY_ARRAY_INSERT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200125 {"insert", (PyCFunction)(void(*)(void))array_array_insert, METH_FASTCALL, array_array_insert__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400126
127static PyObject *
128array_array_insert_impl(arrayobject *self, Py_ssize_t i, PyObject *v);
129
130static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200131array_array_insert(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400132{
133 PyObject *return_value = NULL;
134 Py_ssize_t i;
135 PyObject *v;
136
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200137 if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100138 goto exit;
139 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200140 if (PyFloat_Check(args[0])) {
141 PyErr_SetString(PyExc_TypeError,
142 "integer argument expected, got float" );
143 goto exit;
144 }
145 {
146 Py_ssize_t ival = -1;
147 PyObject *iobj = PyNumber_Index(args[0]);
148 if (iobj != NULL) {
149 ival = PyLong_AsSsize_t(iobj);
150 Py_DECREF(iobj);
151 }
152 if (ival == -1 && PyErr_Occurred()) {
153 goto exit;
154 }
155 i = ival;
156 }
157 v = args[1];
Brett Cannon1eb32c22014-10-10 16:26:45 -0400158 return_value = array_array_insert_impl(self, i, v);
159
160exit:
161 return return_value;
162}
163
164PyDoc_STRVAR(array_array_buffer_info__doc__,
165"buffer_info($self, /)\n"
166"--\n"
167"\n"
168"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"
169"\n"
170"The length should be multiplied by the itemsize attribute to calculate\n"
171"the buffer length in bytes.");
172
173#define ARRAY_ARRAY_BUFFER_INFO_METHODDEF \
174 {"buffer_info", (PyCFunction)array_array_buffer_info, METH_NOARGS, array_array_buffer_info__doc__},
175
176static PyObject *
177array_array_buffer_info_impl(arrayobject *self);
178
179static PyObject *
180array_array_buffer_info(arrayobject *self, PyObject *Py_UNUSED(ignored))
181{
182 return array_array_buffer_info_impl(self);
183}
184
185PyDoc_STRVAR(array_array_append__doc__,
186"append($self, v, /)\n"
187"--\n"
188"\n"
189"Append new value v to the end of the array.");
190
191#define ARRAY_ARRAY_APPEND_METHODDEF \
192 {"append", (PyCFunction)array_array_append, METH_O, array_array_append__doc__},
193
194PyDoc_STRVAR(array_array_byteswap__doc__,
195"byteswap($self, /)\n"
196"--\n"
197"\n"
198"Byteswap all items of the array.\n"
199"\n"
200"If the items in the array are not 1, 2, 4, or 8 bytes in size, RuntimeError is\n"
201"raised.");
202
203#define ARRAY_ARRAY_BYTESWAP_METHODDEF \
204 {"byteswap", (PyCFunction)array_array_byteswap, METH_NOARGS, array_array_byteswap__doc__},
205
206static PyObject *
207array_array_byteswap_impl(arrayobject *self);
208
209static PyObject *
210array_array_byteswap(arrayobject *self, PyObject *Py_UNUSED(ignored))
211{
212 return array_array_byteswap_impl(self);
213}
214
215PyDoc_STRVAR(array_array_reverse__doc__,
216"reverse($self, /)\n"
217"--\n"
218"\n"
219"Reverse the order of the items in the array.");
220
221#define ARRAY_ARRAY_REVERSE_METHODDEF \
222 {"reverse", (PyCFunction)array_array_reverse, METH_NOARGS, array_array_reverse__doc__},
223
224static PyObject *
225array_array_reverse_impl(arrayobject *self);
226
227static PyObject *
228array_array_reverse(arrayobject *self, PyObject *Py_UNUSED(ignored))
229{
230 return array_array_reverse_impl(self);
231}
232
233PyDoc_STRVAR(array_array_fromfile__doc__,
234"fromfile($self, f, n, /)\n"
235"--\n"
236"\n"
237"Read n objects from the file object f and append them to the end of the array.");
238
239#define ARRAY_ARRAY_FROMFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200240 {"fromfile", (PyCFunction)(void(*)(void))array_array_fromfile, METH_FASTCALL, array_array_fromfile__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400241
242static PyObject *
243array_array_fromfile_impl(arrayobject *self, PyObject *f, Py_ssize_t n);
244
245static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200246array_array_fromfile(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400247{
248 PyObject *return_value = NULL;
249 PyObject *f;
250 Py_ssize_t n;
251
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200252 if (!_PyArg_CheckPositional("fromfile", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100253 goto exit;
254 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200255 f = args[0];
256 if (PyFloat_Check(args[1])) {
257 PyErr_SetString(PyExc_TypeError,
258 "integer argument expected, got float" );
259 goto exit;
260 }
261 {
262 Py_ssize_t ival = -1;
263 PyObject *iobj = PyNumber_Index(args[1]);
264 if (iobj != NULL) {
265 ival = PyLong_AsSsize_t(iobj);
266 Py_DECREF(iobj);
267 }
268 if (ival == -1 && PyErr_Occurred()) {
269 goto exit;
270 }
271 n = ival;
272 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400273 return_value = array_array_fromfile_impl(self, f, n);
274
275exit:
276 return return_value;
277}
278
279PyDoc_STRVAR(array_array_tofile__doc__,
280"tofile($self, f, /)\n"
281"--\n"
282"\n"
283"Write all items (as machine values) to the file object f.");
284
285#define ARRAY_ARRAY_TOFILE_METHODDEF \
286 {"tofile", (PyCFunction)array_array_tofile, METH_O, array_array_tofile__doc__},
287
288PyDoc_STRVAR(array_array_fromlist__doc__,
289"fromlist($self, list, /)\n"
290"--\n"
291"\n"
292"Append items to array from list.");
293
294#define ARRAY_ARRAY_FROMLIST_METHODDEF \
295 {"fromlist", (PyCFunction)array_array_fromlist, METH_O, array_array_fromlist__doc__},
296
297PyDoc_STRVAR(array_array_tolist__doc__,
298"tolist($self, /)\n"
299"--\n"
300"\n"
301"Convert array to an ordinary list with the same items.");
302
303#define ARRAY_ARRAY_TOLIST_METHODDEF \
304 {"tolist", (PyCFunction)array_array_tolist, METH_NOARGS, array_array_tolist__doc__},
305
306static PyObject *
307array_array_tolist_impl(arrayobject *self);
308
309static PyObject *
310array_array_tolist(arrayobject *self, PyObject *Py_UNUSED(ignored))
311{
312 return array_array_tolist_impl(self);
313}
314
Brett Cannon1eb32c22014-10-10 16:26:45 -0400315PyDoc_STRVAR(array_array_frombytes__doc__,
316"frombytes($self, buffer, /)\n"
317"--\n"
318"\n"
319"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).");
320
321#define ARRAY_ARRAY_FROMBYTES_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300322 {"frombytes", (PyCFunction)array_array_frombytes, METH_O, array_array_frombytes__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400323
324static PyObject *
325array_array_frombytes_impl(arrayobject *self, Py_buffer *buffer);
326
327static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300328array_array_frombytes(arrayobject *self, PyObject *arg)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400329{
330 PyObject *return_value = NULL;
331 Py_buffer buffer = {NULL, NULL};
332
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200333 if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
334 goto exit;
335 }
336 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200337 _PyArg_BadArgument("frombytes", "argument", "contiguous buffer", arg);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400338 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300339 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400340 return_value = array_array_frombytes_impl(self, &buffer);
341
342exit:
343 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300344 if (buffer.obj) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400345 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300346 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400347
348 return return_value;
349}
350
351PyDoc_STRVAR(array_array_tobytes__doc__,
352"tobytes($self, /)\n"
353"--\n"
354"\n"
355"Convert the array to an array of machine values and return the bytes representation.");
356
357#define ARRAY_ARRAY_TOBYTES_METHODDEF \
358 {"tobytes", (PyCFunction)array_array_tobytes, METH_NOARGS, array_array_tobytes__doc__},
359
360static PyObject *
361array_array_tobytes_impl(arrayobject *self);
362
363static PyObject *
364array_array_tobytes(arrayobject *self, PyObject *Py_UNUSED(ignored))
365{
366 return array_array_tobytes_impl(self);
367}
368
Brett Cannon1eb32c22014-10-10 16:26:45 -0400369PyDoc_STRVAR(array_array_fromunicode__doc__,
370"fromunicode($self, ustr, /)\n"
371"--\n"
372"\n"
373"Extends this array with data from the unicode string ustr.\n"
374"\n"
375"The array must be a unicode type array; otherwise a ValueError is raised.\n"
376"Use array.frombytes(ustr.encode(...)) to append Unicode data to an array of\n"
377"some other type.");
378
379#define ARRAY_ARRAY_FROMUNICODE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300380 {"fromunicode", (PyCFunction)array_array_fromunicode, METH_O, array_array_fromunicode__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400381
382static PyObject *
Inada Naokid5d9a712020-05-11 15:37:25 +0900383array_array_fromunicode_impl(arrayobject *self, PyObject *ustr);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400384
385static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300386array_array_fromunicode(arrayobject *self, PyObject *arg)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400387{
388 PyObject *return_value = NULL;
Inada Naokid5d9a712020-05-11 15:37:25 +0900389 PyObject *ustr;
Brett Cannon1eb32c22014-10-10 16:26:45 -0400390
Inada Naokid5d9a712020-05-11 15:37:25 +0900391 if (!PyUnicode_Check(arg)) {
392 _PyArg_BadArgument("fromunicode", "argument", "str", arg);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400393 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300394 }
Inada Naokid5d9a712020-05-11 15:37:25 +0900395 if (PyUnicode_READY(arg) == -1) {
396 goto exit;
397 }
398 ustr = arg;
399 return_value = array_array_fromunicode_impl(self, ustr);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400400
401exit:
402 return return_value;
403}
404
405PyDoc_STRVAR(array_array_tounicode__doc__,
406"tounicode($self, /)\n"
407"--\n"
408"\n"
409"Extends this array with data from the unicode string ustr.\n"
410"\n"
411"Convert the array to a unicode string. The array must be a unicode type array;\n"
412"otherwise a ValueError is raised. Use array.tobytes().decode() to obtain a\n"
413"unicode string from an array of some other type.");
414
415#define ARRAY_ARRAY_TOUNICODE_METHODDEF \
416 {"tounicode", (PyCFunction)array_array_tounicode, METH_NOARGS, array_array_tounicode__doc__},
417
418static PyObject *
419array_array_tounicode_impl(arrayobject *self);
420
421static PyObject *
422array_array_tounicode(arrayobject *self, PyObject *Py_UNUSED(ignored))
423{
424 return array_array_tounicode_impl(self);
425}
426
427PyDoc_STRVAR(array_array___sizeof____doc__,
428"__sizeof__($self, /)\n"
429"--\n"
430"\n"
431"Size of the array in memory, in bytes.");
432
433#define ARRAY_ARRAY___SIZEOF___METHODDEF \
434 {"__sizeof__", (PyCFunction)array_array___sizeof__, METH_NOARGS, array_array___sizeof____doc__},
435
436static PyObject *
437array_array___sizeof___impl(arrayobject *self);
438
439static PyObject *
440array_array___sizeof__(arrayobject *self, PyObject *Py_UNUSED(ignored))
441{
442 return array_array___sizeof___impl(self);
443}
444
445PyDoc_STRVAR(array__array_reconstructor__doc__,
446"_array_reconstructor($module, arraytype, typecode, mformat_code, items,\n"
447" /)\n"
448"--\n"
449"\n"
450"Internal. Used for pickling support.");
451
452#define ARRAY__ARRAY_RECONSTRUCTOR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200453 {"_array_reconstructor", (PyCFunction)(void(*)(void))array__array_reconstructor, METH_FASTCALL, array__array_reconstructor__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400454
455static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300456array__array_reconstructor_impl(PyObject *module, PyTypeObject *arraytype,
Larry Hastings89964c42015-04-14 18:07:59 -0400457 int typecode,
458 enum machine_format_code mformat_code,
459 PyObject *items);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400460
461static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200462array__array_reconstructor(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400463{
464 PyObject *return_value = NULL;
465 PyTypeObject *arraytype;
466 int typecode;
Larry Hastingsdfbeb162014-10-13 10:39:41 +0100467 enum machine_format_code mformat_code;
Brett Cannon1eb32c22014-10-10 16:26:45 -0400468 PyObject *items;
469
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200470 if (!_PyArg_CheckPositional("_array_reconstructor", nargs, 4, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100471 goto exit;
472 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200473 arraytype = (PyTypeObject *)args[0];
474 if (!PyUnicode_Check(args[1])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200475 _PyArg_BadArgument("_array_reconstructor", "argument 2", "a unicode character", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200476 goto exit;
477 }
478 if (PyUnicode_READY(args[1])) {
479 goto exit;
480 }
481 if (PyUnicode_GET_LENGTH(args[1]) != 1) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200482 _PyArg_BadArgument("_array_reconstructor", "argument 2", "a unicode character", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200483 goto exit;
484 }
485 typecode = PyUnicode_READ_CHAR(args[1], 0);
486 if (PyFloat_Check(args[2])) {
487 PyErr_SetString(PyExc_TypeError,
488 "integer argument expected, got float" );
489 goto exit;
490 }
491 mformat_code = _PyLong_AsInt(args[2]);
492 if (mformat_code == -1 && PyErr_Occurred()) {
493 goto exit;
494 }
495 items = args[3];
Brett Cannon1eb32c22014-10-10 16:26:45 -0400496 return_value = array__array_reconstructor_impl(module, arraytype, typecode, mformat_code, items);
497
498exit:
499 return return_value;
500}
501
502PyDoc_STRVAR(array_array___reduce_ex____doc__,
503"__reduce_ex__($self, value, /)\n"
504"--\n"
505"\n"
506"Return state information for pickling.");
507
508#define ARRAY_ARRAY___REDUCE_EX___METHODDEF \
509 {"__reduce_ex__", (PyCFunction)array_array___reduce_ex__, METH_O, array_array___reduce_ex____doc__},
510
511PyDoc_STRVAR(array_arrayiterator___reduce____doc__,
512"__reduce__($self, /)\n"
513"--\n"
514"\n"
515"Return state information for pickling.");
516
517#define ARRAY_ARRAYITERATOR___REDUCE___METHODDEF \
518 {"__reduce__", (PyCFunction)array_arrayiterator___reduce__, METH_NOARGS, array_arrayiterator___reduce____doc__},
519
520static PyObject *
521array_arrayiterator___reduce___impl(arrayiterobject *self);
522
523static PyObject *
524array_arrayiterator___reduce__(arrayiterobject *self, PyObject *Py_UNUSED(ignored))
525{
526 return array_arrayiterator___reduce___impl(self);
527}
528
529PyDoc_STRVAR(array_arrayiterator___setstate____doc__,
530"__setstate__($self, state, /)\n"
531"--\n"
532"\n"
533"Set state information for unpickling.");
534
535#define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \
536 {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__},
Inada Naokid5d9a712020-05-11 15:37:25 +0900537/*[clinic end generated code: output=9f70748dd3bc532f input=a9049054013a1b77]*/