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