blob: e1f4b0397b9cb5b9a3cc1f45ff3516fc281b6bef [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 *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200383array_array_fromunicode_impl(arrayobject *self, const Py_UNICODE *ustr,
Larry Hastings89964c42015-04-14 18:07:59 -0400384 Py_ssize_clean_t ustr_length);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400385
386static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300387array_array_fromunicode(arrayobject *self, PyObject *arg)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400388{
389 PyObject *return_value = NULL;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200390 const Py_UNICODE *ustr;
Brett Cannon1eb32c22014-10-10 16:26:45 -0400391 Py_ssize_clean_t ustr_length;
392
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300393 if (!PyArg_Parse(arg, "u#:fromunicode", &ustr, &ustr_length)) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400394 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300395 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400396 return_value = array_array_fromunicode_impl(self, ustr, ustr_length);
397
398exit:
399 return return_value;
400}
401
402PyDoc_STRVAR(array_array_tounicode__doc__,
403"tounicode($self, /)\n"
404"--\n"
405"\n"
406"Extends this array with data from the unicode string ustr.\n"
407"\n"
408"Convert the array to a unicode string. The array must be a unicode type array;\n"
409"otherwise a ValueError is raised. Use array.tobytes().decode() to obtain a\n"
410"unicode string from an array of some other type.");
411
412#define ARRAY_ARRAY_TOUNICODE_METHODDEF \
413 {"tounicode", (PyCFunction)array_array_tounicode, METH_NOARGS, array_array_tounicode__doc__},
414
415static PyObject *
416array_array_tounicode_impl(arrayobject *self);
417
418static PyObject *
419array_array_tounicode(arrayobject *self, PyObject *Py_UNUSED(ignored))
420{
421 return array_array_tounicode_impl(self);
422}
423
424PyDoc_STRVAR(array_array___sizeof____doc__,
425"__sizeof__($self, /)\n"
426"--\n"
427"\n"
428"Size of the array in memory, in bytes.");
429
430#define ARRAY_ARRAY___SIZEOF___METHODDEF \
431 {"__sizeof__", (PyCFunction)array_array___sizeof__, METH_NOARGS, array_array___sizeof____doc__},
432
433static PyObject *
434array_array___sizeof___impl(arrayobject *self);
435
436static PyObject *
437array_array___sizeof__(arrayobject *self, PyObject *Py_UNUSED(ignored))
438{
439 return array_array___sizeof___impl(self);
440}
441
442PyDoc_STRVAR(array__array_reconstructor__doc__,
443"_array_reconstructor($module, arraytype, typecode, mformat_code, items,\n"
444" /)\n"
445"--\n"
446"\n"
447"Internal. Used for pickling support.");
448
449#define ARRAY__ARRAY_RECONSTRUCTOR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200450 {"_array_reconstructor", (PyCFunction)(void(*)(void))array__array_reconstructor, METH_FASTCALL, array__array_reconstructor__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400451
452static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300453array__array_reconstructor_impl(PyObject *module, PyTypeObject *arraytype,
Larry Hastings89964c42015-04-14 18:07:59 -0400454 int typecode,
455 enum machine_format_code mformat_code,
456 PyObject *items);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400457
458static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200459array__array_reconstructor(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400460{
461 PyObject *return_value = NULL;
462 PyTypeObject *arraytype;
463 int typecode;
Larry Hastingsdfbeb162014-10-13 10:39:41 +0100464 enum machine_format_code mformat_code;
Brett Cannon1eb32c22014-10-10 16:26:45 -0400465 PyObject *items;
466
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200467 if (!_PyArg_CheckPositional("_array_reconstructor", nargs, 4, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100468 goto exit;
469 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200470 arraytype = (PyTypeObject *)args[0];
471 if (!PyUnicode_Check(args[1])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200472 _PyArg_BadArgument("_array_reconstructor", "argument 2", "a unicode character", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200473 goto exit;
474 }
475 if (PyUnicode_READY(args[1])) {
476 goto exit;
477 }
478 if (PyUnicode_GET_LENGTH(args[1]) != 1) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200479 _PyArg_BadArgument("_array_reconstructor", "argument 2", "a unicode character", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200480 goto exit;
481 }
482 typecode = PyUnicode_READ_CHAR(args[1], 0);
483 if (PyFloat_Check(args[2])) {
484 PyErr_SetString(PyExc_TypeError,
485 "integer argument expected, got float" );
486 goto exit;
487 }
488 mformat_code = _PyLong_AsInt(args[2]);
489 if (mformat_code == -1 && PyErr_Occurred()) {
490 goto exit;
491 }
492 items = args[3];
Brett Cannon1eb32c22014-10-10 16:26:45 -0400493 return_value = array__array_reconstructor_impl(module, arraytype, typecode, mformat_code, items);
494
495exit:
496 return return_value;
497}
498
499PyDoc_STRVAR(array_array___reduce_ex____doc__,
500"__reduce_ex__($self, value, /)\n"
501"--\n"
502"\n"
503"Return state information for pickling.");
504
505#define ARRAY_ARRAY___REDUCE_EX___METHODDEF \
506 {"__reduce_ex__", (PyCFunction)array_array___reduce_ex__, METH_O, array_array___reduce_ex____doc__},
507
508PyDoc_STRVAR(array_arrayiterator___reduce____doc__,
509"__reduce__($self, /)\n"
510"--\n"
511"\n"
512"Return state information for pickling.");
513
514#define ARRAY_ARRAYITERATOR___REDUCE___METHODDEF \
515 {"__reduce__", (PyCFunction)array_arrayiterator___reduce__, METH_NOARGS, array_arrayiterator___reduce____doc__},
516
517static PyObject *
518array_arrayiterator___reduce___impl(arrayiterobject *self);
519
520static PyObject *
521array_arrayiterator___reduce__(arrayiterobject *self, PyObject *Py_UNUSED(ignored))
522{
523 return array_arrayiterator___reduce___impl(self);
524}
525
526PyDoc_STRVAR(array_arrayiterator___setstate____doc__,
527"__setstate__($self, state, /)\n"
528"--\n"
529"\n"
530"Set state information for unpickling.");
531
532#define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \
533 {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__},
Victor Stinner0131aba2019-12-09 14:09:14 +0100534/*[clinic end generated code: output=f649fc0bc9f6b13a input=a9049054013a1b77]*/