1/*[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, start=0, stop=sys.maxsize, /)\n"
43"--\n"
44"\n"
45"Return index of first occurrence of v in the array.\n"
46"\n"
47"Raise ValueError if the value is not present.");
48
49#define ARRAY_ARRAY_INDEX_METHODDEF \
50 {"index", (PyCFunction)(void(*)(void))array_array_index, METH_FASTCALL, array_array_index__doc__},
51
52static PyObject *
53array_array_index_impl(arrayobject *self, PyObject *v, Py_ssize_t start,
54 Py_ssize_t stop);
55
56static PyObject *
57array_array_index(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
58{
59 PyObject *return_value = NULL;
60 PyObject *v;
61 Py_ssize_t start = 0;
62 Py_ssize_t stop = PY_SSIZE_T_MAX;
63
64 if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
65 goto exit;
66 }
67 v = args[0];
68 if (nargs < 2) {
69 goto skip_optional;
70 }
71 if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
72 goto exit;
73 }
74 if (nargs < 3) {
75 goto skip_optional;
76 }
77 if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
78 goto exit;
79 }
80skip_optional:
81 return_value = array_array_index_impl(self, v, start, stop);
82
83exit:
84 return return_value;
85}
86
87PyDoc_STRVAR(array_array_remove__doc__,
88"remove($self, v, /)\n"
89"--\n"
90"\n"
91"Remove the first occurrence of v in the array.");
92
93#define ARRAY_ARRAY_REMOVE_METHODDEF \
94 {"remove", (PyCFunction)array_array_remove, METH_O, array_array_remove__doc__},
95
96PyDoc_STRVAR(array_array_pop__doc__,
97"pop($self, i=-1, /)\n"
98"--\n"
99"\n"
100"Return the i-th element and delete it from the array.\n"
101"\n"
102"i defaults to -1.");
103
104#define ARRAY_ARRAY_POP_METHODDEF \
105 {"pop", (PyCFunction)(void(*)(void))array_array_pop, METH_FASTCALL, array_array_pop__doc__},
106
107static PyObject *
108array_array_pop_impl(arrayobject *self, Py_ssize_t i);
109
110static PyObject *
111array_array_pop(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
112{
113 PyObject *return_value = NULL;
114 Py_ssize_t i = -1;
115
116 if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) {
117 goto exit;
118 }
119 if (nargs < 1) {
120 goto skip_optional;
121 }
122 {
123 Py_ssize_t ival = -1;
124 PyObject *iobj = _PyNumber_Index(args[0]);
125 if (iobj != NULL) {
126 ival = PyLong_AsSsize_t(iobj);
127 Py_DECREF(iobj);
128 }
129 if (ival == -1 && PyErr_Occurred()) {
130 goto exit;
131 }
132 i = ival;
133 }
134skip_optional:
135 return_value = array_array_pop_impl(self, i);
136
137exit:
138 return return_value;
139}
140
141PyDoc_STRVAR(array_array_extend__doc__,
142"extend($self, bb, /)\n"
143"--\n"
144"\n"
145"Append items to the end of the array.");
146
147#define ARRAY_ARRAY_EXTEND_METHODDEF \
148 {"extend", (PyCFunction)(void(*)(void))array_array_extend, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, array_array_extend__doc__},
149
150static PyObject *
151array_array_extend_impl(arrayobject *self, PyTypeObject *cls, PyObject *bb);
152
153static PyObject *
154array_array_extend(arrayobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
155{
156 PyObject *return_value = NULL;
157 static const char * const _keywords[] = {"", NULL};
158 static _PyArg_Parser _parser = {NULL, _keywords, "extend", 0};
159 PyObject *argsbuf[1];
160 PyObject *bb;
161
162 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
163 if (!args) {
164 goto exit;
165 }
166 bb = args[0];
167 return_value = array_array_extend_impl(self, cls, bb);
168
169exit:
170 return return_value;
171}
172
173PyDoc_STRVAR(array_array_insert__doc__,
174"insert($self, i, v, /)\n"
175"--\n"
176"\n"
177"Insert a new item v into the array before position i.");
178
179#define ARRAY_ARRAY_INSERT_METHODDEF \
180 {"insert", (PyCFunction)(void(*)(void))array_array_insert, METH_FASTCALL, array_array_insert__doc__},
181
182static PyObject *
183array_array_insert_impl(arrayobject *self, Py_ssize_t i, PyObject *v);
184
185static PyObject *
186array_array_insert(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
187{
188 PyObject *return_value = NULL;
189 Py_ssize_t i;
190 PyObject *v;
191
192 if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
193 goto exit;
194 }
195 {
196 Py_ssize_t ival = -1;
197 PyObject *iobj = _PyNumber_Index(args[0]);
198 if (iobj != NULL) {
199 ival = PyLong_AsSsize_t(iobj);
200 Py_DECREF(iobj);
201 }
202 if (ival == -1 && PyErr_Occurred()) {
203 goto exit;
204 }
205 i = ival;
206 }
207 v = args[1];
208 return_value = array_array_insert_impl(self, i, v);
209
210exit:
211 return return_value;
212}
213
214PyDoc_STRVAR(array_array_buffer_info__doc__,
215"buffer_info($self, /)\n"
216"--\n"
217"\n"
218"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"
219"\n"
220"The length should be multiplied by the itemsize attribute to calculate\n"
221"the buffer length in bytes.");
222
223#define ARRAY_ARRAY_BUFFER_INFO_METHODDEF \
224 {"buffer_info", (PyCFunction)array_array_buffer_info, METH_NOARGS, array_array_buffer_info__doc__},
225
226static PyObject *
227array_array_buffer_info_impl(arrayobject *self);
228
229static PyObject *
230array_array_buffer_info(arrayobject *self, PyObject *Py_UNUSED(ignored))
231{
232 return array_array_buffer_info_impl(self);
233}
234
235PyDoc_STRVAR(array_array_append__doc__,
236"append($self, v, /)\n"
237"--\n"
238"\n"
239"Append new value v to the end of the array.");
240
241#define ARRAY_ARRAY_APPEND_METHODDEF \
242 {"append", (PyCFunction)array_array_append, METH_O, array_array_append__doc__},
243
244PyDoc_STRVAR(array_array_byteswap__doc__,
245"byteswap($self, /)\n"
246"--\n"
247"\n"
248"Byteswap all items of the array.\n"
249"\n"
250"If the items in the array are not 1, 2, 4, or 8 bytes in size, RuntimeError is\n"
251"raised.");
252
253#define ARRAY_ARRAY_BYTESWAP_METHODDEF \
254 {"byteswap", (PyCFunction)array_array_byteswap, METH_NOARGS, array_array_byteswap__doc__},
255
256static PyObject *
257array_array_byteswap_impl(arrayobject *self);
258
259static PyObject *
260array_array_byteswap(arrayobject *self, PyObject *Py_UNUSED(ignored))
261{
262 return array_array_byteswap_impl(self);
263}
264
265PyDoc_STRVAR(array_array_reverse__doc__,
266"reverse($self, /)\n"
267"--\n"
268"\n"
269"Reverse the order of the items in the array.");
270
271#define ARRAY_ARRAY_REVERSE_METHODDEF \
272 {"reverse", (PyCFunction)array_array_reverse, METH_NOARGS, array_array_reverse__doc__},
273
274static PyObject *
275array_array_reverse_impl(arrayobject *self);
276
277static PyObject *
278array_array_reverse(arrayobject *self, PyObject *Py_UNUSED(ignored))
279{
280 return array_array_reverse_impl(self);
281}
282
283PyDoc_STRVAR(array_array_fromfile__doc__,
284"fromfile($self, f, n, /)\n"
285"--\n"
286"\n"
287"Read n objects from the file object f and append them to the end of the array.");
288
289#define ARRAY_ARRAY_FROMFILE_METHODDEF \
290 {"fromfile", (PyCFunction)(void(*)(void))array_array_fromfile, METH_FASTCALL, array_array_fromfile__doc__},
291
292static PyObject *
293array_array_fromfile_impl(arrayobject *self, PyObject *f, Py_ssize_t n);
294
295static PyObject *
296array_array_fromfile(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
297{
298 PyObject *return_value = NULL;
299 PyObject *f;
300 Py_ssize_t n;
301
302 if (!_PyArg_CheckPositional("fromfile", nargs, 2, 2)) {
303 goto exit;
304 }
305 f = args[0];
306 {
307 Py_ssize_t ival = -1;
308 PyObject *iobj = _PyNumber_Index(args[1]);
309 if (iobj != NULL) {
310 ival = PyLong_AsSsize_t(iobj);
311 Py_DECREF(iobj);
312 }
313 if (ival == -1 && PyErr_Occurred()) {
314 goto exit;
315 }
316 n = ival;
317 }
318 return_value = array_array_fromfile_impl(self, f, n);
319
320exit:
321 return return_value;
322}
323
324PyDoc_STRVAR(array_array_tofile__doc__,
325"tofile($self, f, /)\n"
326"--\n"
327"\n"
328"Write all items (as machine values) to the file object f.");
329
330#define ARRAY_ARRAY_TOFILE_METHODDEF \
331 {"tofile", (PyCFunction)array_array_tofile, METH_O, array_array_tofile__doc__},
332
333PyDoc_STRVAR(array_array_fromlist__doc__,
334"fromlist($self, list, /)\n"
335"--\n"
336"\n"
337"Append items to array from list.");
338
339#define ARRAY_ARRAY_FROMLIST_METHODDEF \
340 {"fromlist", (PyCFunction)array_array_fromlist, METH_O, array_array_fromlist__doc__},
341
342PyDoc_STRVAR(array_array_tolist__doc__,
343"tolist($self, /)\n"
344"--\n"
345"\n"
346"Convert array to an ordinary list with the same items.");
347
348#define ARRAY_ARRAY_TOLIST_METHODDEF \
349 {"tolist", (PyCFunction)array_array_tolist, METH_NOARGS, array_array_tolist__doc__},
350
351static PyObject *
352array_array_tolist_impl(arrayobject *self);
353
354static PyObject *
355array_array_tolist(arrayobject *self, PyObject *Py_UNUSED(ignored))
356{
357 return array_array_tolist_impl(self);
358}
359
360PyDoc_STRVAR(array_array_frombytes__doc__,
361"frombytes($self, buffer, /)\n"
362"--\n"
363"\n"
364"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.");
365
366#define ARRAY_ARRAY_FROMBYTES_METHODDEF \
367 {"frombytes", (PyCFunction)array_array_frombytes, METH_O, array_array_frombytes__doc__},
368
369static PyObject *
370array_array_frombytes_impl(arrayobject *self, Py_buffer *buffer);
371
372static PyObject *
373array_array_frombytes(arrayobject *self, PyObject *arg)
374{
375 PyObject *return_value = NULL;
376 Py_buffer buffer = {NULL, NULL};
377
378 if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
379 goto exit;
380 }
381 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
382 _PyArg_BadArgument("frombytes", "argument", "contiguous buffer", arg);
383 goto exit;
384 }
385 return_value = array_array_frombytes_impl(self, &buffer);
386
387exit:
388 /* Cleanup for buffer */
389 if (buffer.obj) {
390 PyBuffer_Release(&buffer);
391 }
392
393 return return_value;
394}
395
396PyDoc_STRVAR(array_array_tobytes__doc__,
397"tobytes($self, /)\n"
398"--\n"
399"\n"
400"Convert the array to an array of machine values and return the bytes representation.");
401
402#define ARRAY_ARRAY_TOBYTES_METHODDEF \
403 {"tobytes", (PyCFunction)array_array_tobytes, METH_NOARGS, array_array_tobytes__doc__},
404
405static PyObject *
406array_array_tobytes_impl(arrayobject *self);
407
408static PyObject *
409array_array_tobytes(arrayobject *self, PyObject *Py_UNUSED(ignored))
410{
411 return array_array_tobytes_impl(self);
412}
413
414PyDoc_STRVAR(array_array_fromunicode__doc__,
415"fromunicode($self, ustr, /)\n"
416"--\n"
417"\n"
418"Extends this array with data from the unicode string ustr.\n"
419"\n"
420"The array must be a unicode type array; otherwise a ValueError is raised.\n"
421"Use array.frombytes(ustr.encode(...)) to append Unicode data to an array of\n"
422"some other type.");
423
424#define ARRAY_ARRAY_FROMUNICODE_METHODDEF \
425 {"fromunicode", (PyCFunction)array_array_fromunicode, METH_O, array_array_fromunicode__doc__},
426
427static PyObject *
428array_array_fromunicode_impl(arrayobject *self, PyObject *ustr);
429
430static PyObject *
431array_array_fromunicode(arrayobject *self, PyObject *arg)
432{
433 PyObject *return_value = NULL;
434 PyObject *ustr;
435
436 if (!PyUnicode_Check(arg)) {
437 _PyArg_BadArgument("fromunicode", "argument", "str", arg);
438 goto exit;
439 }
440 if (PyUnicode_READY(arg) == -1) {
441 goto exit;
442 }
443 ustr = arg;
444 return_value = array_array_fromunicode_impl(self, ustr);
445
446exit:
447 return return_value;
448}
449
450PyDoc_STRVAR(array_array_tounicode__doc__,
451"tounicode($self, /)\n"
452"--\n"
453"\n"
454"Extends this array with data from the unicode string ustr.\n"
455"\n"
456"Convert the array to a unicode string. The array must be a unicode type array;\n"
457"otherwise a ValueError is raised. Use array.tobytes().decode() to obtain a\n"
458"unicode string from an array of some other type.");
459
460#define ARRAY_ARRAY_TOUNICODE_METHODDEF \
461 {"tounicode", (PyCFunction)array_array_tounicode, METH_NOARGS, array_array_tounicode__doc__},
462
463static PyObject *
464array_array_tounicode_impl(arrayobject *self);
465
466static PyObject *
467array_array_tounicode(arrayobject *self, PyObject *Py_UNUSED(ignored))
468{
469 return array_array_tounicode_impl(self);
470}
471
472PyDoc_STRVAR(array_array___sizeof____doc__,
473"__sizeof__($self, /)\n"
474"--\n"
475"\n"
476"Size of the array in memory, in bytes.");
477
478#define ARRAY_ARRAY___SIZEOF___METHODDEF \
479 {"__sizeof__", (PyCFunction)array_array___sizeof__, METH_NOARGS, array_array___sizeof____doc__},
480
481static PyObject *
482array_array___sizeof___impl(arrayobject *self);
483
484static PyObject *
485array_array___sizeof__(arrayobject *self, PyObject *Py_UNUSED(ignored))
486{
487 return array_array___sizeof___impl(self);
488}
489
490PyDoc_STRVAR(array__array_reconstructor__doc__,
491"_array_reconstructor($module, arraytype, typecode, mformat_code, items,\n"
492" /)\n"
493"--\n"
494"\n"
495"Internal. Used for pickling support.");
496
497#define ARRAY__ARRAY_RECONSTRUCTOR_METHODDEF \
498 {"_array_reconstructor", (PyCFunction)(void(*)(void))array__array_reconstructor, METH_FASTCALL, array__array_reconstructor__doc__},
499
500static PyObject *
501array__array_reconstructor_impl(PyObject *module, PyTypeObject *arraytype,
502 int typecode,
503 enum machine_format_code mformat_code,
504 PyObject *items);
505
506static PyObject *
507array__array_reconstructor(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
508{
509 PyObject *return_value = NULL;
510 PyTypeObject *arraytype;
511 int typecode;
512 enum machine_format_code mformat_code;
513 PyObject *items;
514
515 if (!_PyArg_CheckPositional("_array_reconstructor", nargs, 4, 4)) {
516 goto exit;
517 }
518 arraytype = (PyTypeObject *)args[0];
519 if (!PyUnicode_Check(args[1])) {
520 _PyArg_BadArgument("_array_reconstructor", "argument 2", "a unicode character", args[1]);
521 goto exit;
522 }
523 if (PyUnicode_READY(args[1])) {
524 goto exit;
525 }
526 if (PyUnicode_GET_LENGTH(args[1]) != 1) {
527 _PyArg_BadArgument("_array_reconstructor", "argument 2", "a unicode character", args[1]);
528 goto exit;
529 }
530 typecode = PyUnicode_READ_CHAR(args[1], 0);
531 mformat_code = _PyLong_AsInt(args[2]);
532 if (mformat_code == -1 && PyErr_Occurred()) {
533 goto exit;
534 }
535 items = args[3];
536 return_value = array__array_reconstructor_impl(module, arraytype, typecode, mformat_code, items);
537
538exit:
539 return return_value;
540}
541
542PyDoc_STRVAR(array_array___reduce_ex____doc__,
543"__reduce_ex__($self, value, /)\n"
544"--\n"
545"\n"
546"Return state information for pickling.");
547
548#define ARRAY_ARRAY___REDUCE_EX___METHODDEF \
549 {"__reduce_ex__", (PyCFunction)array_array___reduce_ex__, METH_O, array_array___reduce_ex____doc__},
550
551PyDoc_STRVAR(array_arrayiterator___reduce____doc__,
552"__reduce__($self, /)\n"
553"--\n"
554"\n"
555"Return state information for pickling.");
556
557#define ARRAY_ARRAYITERATOR___REDUCE___METHODDEF \
558 {"__reduce__", (PyCFunction)array_arrayiterator___reduce__, METH_NOARGS, array_arrayiterator___reduce____doc__},
559
560static PyObject *
561array_arrayiterator___reduce___impl(arrayiterobject *self);
562
563static PyObject *
564array_arrayiterator___reduce__(arrayiterobject *self, PyObject *Py_UNUSED(ignored))
565{
566 return array_arrayiterator___reduce___impl(self);
567}
568
569PyDoc_STRVAR(array_arrayiterator___setstate____doc__,
570"__setstate__($self, state, /)\n"
571"--\n"
572"\n"
573"Set state information for unpickling.");
574
575#define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \
576 {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__},
577/*[clinic end generated code: output=eb727e087d64f017 input=a9049054013a1b77]*/
578