blob: eb081ad0718e48c41209a63fb65eecb927f36348 [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
Sylvain74453812017-06-10 06:51:48 +020079 if (!_PyArg_ParseStack(args, nargs, "|n:pop",
80 &i)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010081 goto exit;
82 }
Brett Cannon1eb32c22014-10-10 16:26:45 -040083 return_value = array_array_pop_impl(self, i);
84
85exit:
86 return return_value;
87}
88
89PyDoc_STRVAR(array_array_extend__doc__,
90"extend($self, bb, /)\n"
91"--\n"
92"\n"
93"Append items to the end of the array.");
94
95#define ARRAY_ARRAY_EXTEND_METHODDEF \
96 {"extend", (PyCFunction)array_array_extend, METH_O, array_array_extend__doc__},
97
98PyDoc_STRVAR(array_array_insert__doc__,
99"insert($self, i, v, /)\n"
100"--\n"
101"\n"
102"Insert a new item v into the array before position i.");
103
104#define ARRAY_ARRAY_INSERT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200105 {"insert", (PyCFunction)(void(*)(void))array_array_insert, METH_FASTCALL, array_array_insert__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400106
107static PyObject *
108array_array_insert_impl(arrayobject *self, Py_ssize_t i, PyObject *v);
109
110static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200111array_array_insert(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400112{
113 PyObject *return_value = NULL;
114 Py_ssize_t i;
115 PyObject *v;
116
Sylvain74453812017-06-10 06:51:48 +0200117 if (!_PyArg_ParseStack(args, nargs, "nO:insert",
118 &i, &v)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100119 goto exit;
120 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400121 return_value = array_array_insert_impl(self, i, v);
122
123exit:
124 return return_value;
125}
126
127PyDoc_STRVAR(array_array_buffer_info__doc__,
128"buffer_info($self, /)\n"
129"--\n"
130"\n"
131"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"
132"\n"
133"The length should be multiplied by the itemsize attribute to calculate\n"
134"the buffer length in bytes.");
135
136#define ARRAY_ARRAY_BUFFER_INFO_METHODDEF \
137 {"buffer_info", (PyCFunction)array_array_buffer_info, METH_NOARGS, array_array_buffer_info__doc__},
138
139static PyObject *
140array_array_buffer_info_impl(arrayobject *self);
141
142static PyObject *
143array_array_buffer_info(arrayobject *self, PyObject *Py_UNUSED(ignored))
144{
145 return array_array_buffer_info_impl(self);
146}
147
148PyDoc_STRVAR(array_array_append__doc__,
149"append($self, v, /)\n"
150"--\n"
151"\n"
152"Append new value v to the end of the array.");
153
154#define ARRAY_ARRAY_APPEND_METHODDEF \
155 {"append", (PyCFunction)array_array_append, METH_O, array_array_append__doc__},
156
157PyDoc_STRVAR(array_array_byteswap__doc__,
158"byteswap($self, /)\n"
159"--\n"
160"\n"
161"Byteswap all items of the array.\n"
162"\n"
163"If the items in the array are not 1, 2, 4, or 8 bytes in size, RuntimeError is\n"
164"raised.");
165
166#define ARRAY_ARRAY_BYTESWAP_METHODDEF \
167 {"byteswap", (PyCFunction)array_array_byteswap, METH_NOARGS, array_array_byteswap__doc__},
168
169static PyObject *
170array_array_byteswap_impl(arrayobject *self);
171
172static PyObject *
173array_array_byteswap(arrayobject *self, PyObject *Py_UNUSED(ignored))
174{
175 return array_array_byteswap_impl(self);
176}
177
178PyDoc_STRVAR(array_array_reverse__doc__,
179"reverse($self, /)\n"
180"--\n"
181"\n"
182"Reverse the order of the items in the array.");
183
184#define ARRAY_ARRAY_REVERSE_METHODDEF \
185 {"reverse", (PyCFunction)array_array_reverse, METH_NOARGS, array_array_reverse__doc__},
186
187static PyObject *
188array_array_reverse_impl(arrayobject *self);
189
190static PyObject *
191array_array_reverse(arrayobject *self, PyObject *Py_UNUSED(ignored))
192{
193 return array_array_reverse_impl(self);
194}
195
196PyDoc_STRVAR(array_array_fromfile__doc__,
197"fromfile($self, f, n, /)\n"
198"--\n"
199"\n"
200"Read n objects from the file object f and append them to the end of the array.");
201
202#define ARRAY_ARRAY_FROMFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200203 {"fromfile", (PyCFunction)(void(*)(void))array_array_fromfile, METH_FASTCALL, array_array_fromfile__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400204
205static PyObject *
206array_array_fromfile_impl(arrayobject *self, PyObject *f, Py_ssize_t n);
207
208static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200209array_array_fromfile(arrayobject *self, PyObject *const *args, Py_ssize_t nargs)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400210{
211 PyObject *return_value = NULL;
212 PyObject *f;
213 Py_ssize_t n;
214
Sylvain74453812017-06-10 06:51:48 +0200215 if (!_PyArg_ParseStack(args, nargs, "On:fromfile",
216 &f, &n)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100217 goto exit;
218 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400219 return_value = array_array_fromfile_impl(self, f, n);
220
221exit:
222 return return_value;
223}
224
225PyDoc_STRVAR(array_array_tofile__doc__,
226"tofile($self, f, /)\n"
227"--\n"
228"\n"
229"Write all items (as machine values) to the file object f.");
230
231#define ARRAY_ARRAY_TOFILE_METHODDEF \
232 {"tofile", (PyCFunction)array_array_tofile, METH_O, array_array_tofile__doc__},
233
234PyDoc_STRVAR(array_array_fromlist__doc__,
235"fromlist($self, list, /)\n"
236"--\n"
237"\n"
238"Append items to array from list.");
239
240#define ARRAY_ARRAY_FROMLIST_METHODDEF \
241 {"fromlist", (PyCFunction)array_array_fromlist, METH_O, array_array_fromlist__doc__},
242
243PyDoc_STRVAR(array_array_tolist__doc__,
244"tolist($self, /)\n"
245"--\n"
246"\n"
247"Convert array to an ordinary list with the same items.");
248
249#define ARRAY_ARRAY_TOLIST_METHODDEF \
250 {"tolist", (PyCFunction)array_array_tolist, METH_NOARGS, array_array_tolist__doc__},
251
252static PyObject *
253array_array_tolist_impl(arrayobject *self);
254
255static PyObject *
256array_array_tolist(arrayobject *self, PyObject *Py_UNUSED(ignored))
257{
258 return array_array_tolist_impl(self);
259}
260
261PyDoc_STRVAR(array_array_fromstring__doc__,
262"fromstring($self, buffer, /)\n"
263"--\n"
264"\n"
265"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).\n"
266"\n"
267"This method is deprecated. Use frombytes instead.");
268
269#define ARRAY_ARRAY_FROMSTRING_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300270 {"fromstring", (PyCFunction)array_array_fromstring, METH_O, array_array_fromstring__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400271
272static PyObject *
273array_array_fromstring_impl(arrayobject *self, Py_buffer *buffer);
274
275static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300276array_array_fromstring(arrayobject *self, PyObject *arg)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400277{
278 PyObject *return_value = NULL;
279 Py_buffer buffer = {NULL, NULL};
280
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200281 if (PyUnicode_Check(arg)) {
282 Py_ssize_t len;
283 const char *ptr = PyUnicode_AsUTF8AndSize(arg, &len);
284 if (ptr == NULL) {
285 goto exit;
286 }
287 PyBuffer_FillInfo(&buffer, arg, (void *)ptr, len, 1, 0);
288 }
289 else { /* any bytes-like object */
290 if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
291 goto exit;
292 }
293 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
294 _PyArg_BadArgument("fromstring", "contiguous buffer", arg);
295 goto exit;
296 }
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300297 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400298 return_value = array_array_fromstring_impl(self, &buffer);
299
300exit:
301 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300302 if (buffer.obj) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400303 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300304 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400305
306 return return_value;
307}
308
309PyDoc_STRVAR(array_array_frombytes__doc__,
310"frombytes($self, buffer, /)\n"
311"--\n"
312"\n"
313"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).");
314
315#define ARRAY_ARRAY_FROMBYTES_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300316 {"frombytes", (PyCFunction)array_array_frombytes, METH_O, array_array_frombytes__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400317
318static PyObject *
319array_array_frombytes_impl(arrayobject *self, Py_buffer *buffer);
320
321static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300322array_array_frombytes(arrayobject *self, PyObject *arg)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400323{
324 PyObject *return_value = NULL;
325 Py_buffer buffer = {NULL, NULL};
326
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200327 if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
328 goto exit;
329 }
330 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
331 _PyArg_BadArgument("frombytes", "contiguous buffer", arg);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400332 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300333 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400334 return_value = array_array_frombytes_impl(self, &buffer);
335
336exit:
337 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300338 if (buffer.obj) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400339 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300340 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400341
342 return return_value;
343}
344
345PyDoc_STRVAR(array_array_tobytes__doc__,
346"tobytes($self, /)\n"
347"--\n"
348"\n"
349"Convert the array to an array of machine values and return the bytes representation.");
350
351#define ARRAY_ARRAY_TOBYTES_METHODDEF \
352 {"tobytes", (PyCFunction)array_array_tobytes, METH_NOARGS, array_array_tobytes__doc__},
353
354static PyObject *
355array_array_tobytes_impl(arrayobject *self);
356
357static PyObject *
358array_array_tobytes(arrayobject *self, PyObject *Py_UNUSED(ignored))
359{
360 return array_array_tobytes_impl(self);
361}
362
363PyDoc_STRVAR(array_array_tostring__doc__,
364"tostring($self, /)\n"
365"--\n"
366"\n"
367"Convert the array to an array of machine values and return the bytes representation.\n"
368"\n"
369"This method is deprecated. Use tobytes instead.");
370
371#define ARRAY_ARRAY_TOSTRING_METHODDEF \
372 {"tostring", (PyCFunction)array_array_tostring, METH_NOARGS, array_array_tostring__doc__},
373
374static PyObject *
375array_array_tostring_impl(arrayobject *self);
376
377static PyObject *
378array_array_tostring(arrayobject *self, PyObject *Py_UNUSED(ignored))
379{
380 return array_array_tostring_impl(self);
381}
382
383PyDoc_STRVAR(array_array_fromunicode__doc__,
384"fromunicode($self, ustr, /)\n"
385"--\n"
386"\n"
387"Extends this array with data from the unicode string ustr.\n"
388"\n"
389"The array must be a unicode type array; otherwise a ValueError is raised.\n"
390"Use array.frombytes(ustr.encode(...)) to append Unicode data to an array of\n"
391"some other type.");
392
393#define ARRAY_ARRAY_FROMUNICODE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300394 {"fromunicode", (PyCFunction)array_array_fromunicode, METH_O, array_array_fromunicode__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400395
396static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200397array_array_fromunicode_impl(arrayobject *self, const Py_UNICODE *ustr,
Larry Hastings89964c42015-04-14 18:07:59 -0400398 Py_ssize_clean_t ustr_length);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400399
400static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300401array_array_fromunicode(arrayobject *self, PyObject *arg)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400402{
403 PyObject *return_value = NULL;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200404 const Py_UNICODE *ustr;
Brett Cannon1eb32c22014-10-10 16:26:45 -0400405 Py_ssize_clean_t ustr_length;
406
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300407 if (!PyArg_Parse(arg, "u#:fromunicode", &ustr, &ustr_length)) {
Brett Cannon1eb32c22014-10-10 16:26:45 -0400408 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300409 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400410 return_value = array_array_fromunicode_impl(self, ustr, ustr_length);
411
412exit:
413 return return_value;
414}
415
416PyDoc_STRVAR(array_array_tounicode__doc__,
417"tounicode($self, /)\n"
418"--\n"
419"\n"
420"Extends this array with data from the unicode string ustr.\n"
421"\n"
422"Convert the array to a unicode string. The array must be a unicode type array;\n"
423"otherwise a ValueError is raised. Use array.tobytes().decode() to obtain a\n"
424"unicode string from an array of some other type.");
425
426#define ARRAY_ARRAY_TOUNICODE_METHODDEF \
427 {"tounicode", (PyCFunction)array_array_tounicode, METH_NOARGS, array_array_tounicode__doc__},
428
429static PyObject *
430array_array_tounicode_impl(arrayobject *self);
431
432static PyObject *
433array_array_tounicode(arrayobject *self, PyObject *Py_UNUSED(ignored))
434{
435 return array_array_tounicode_impl(self);
436}
437
438PyDoc_STRVAR(array_array___sizeof____doc__,
439"__sizeof__($self, /)\n"
440"--\n"
441"\n"
442"Size of the array in memory, in bytes.");
443
444#define ARRAY_ARRAY___SIZEOF___METHODDEF \
445 {"__sizeof__", (PyCFunction)array_array___sizeof__, METH_NOARGS, array_array___sizeof____doc__},
446
447static PyObject *
448array_array___sizeof___impl(arrayobject *self);
449
450static PyObject *
451array_array___sizeof__(arrayobject *self, PyObject *Py_UNUSED(ignored))
452{
453 return array_array___sizeof___impl(self);
454}
455
456PyDoc_STRVAR(array__array_reconstructor__doc__,
457"_array_reconstructor($module, arraytype, typecode, mformat_code, items,\n"
458" /)\n"
459"--\n"
460"\n"
461"Internal. Used for pickling support.");
462
463#define ARRAY__ARRAY_RECONSTRUCTOR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200464 {"_array_reconstructor", (PyCFunction)(void(*)(void))array__array_reconstructor, METH_FASTCALL, array__array_reconstructor__doc__},
Brett Cannon1eb32c22014-10-10 16:26:45 -0400465
466static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300467array__array_reconstructor_impl(PyObject *module, PyTypeObject *arraytype,
Larry Hastings89964c42015-04-14 18:07:59 -0400468 int typecode,
469 enum machine_format_code mformat_code,
470 PyObject *items);
Brett Cannon1eb32c22014-10-10 16:26:45 -0400471
472static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200473array__array_reconstructor(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Brett Cannon1eb32c22014-10-10 16:26:45 -0400474{
475 PyObject *return_value = NULL;
476 PyTypeObject *arraytype;
477 int typecode;
Larry Hastingsdfbeb162014-10-13 10:39:41 +0100478 enum machine_format_code mformat_code;
Brett Cannon1eb32c22014-10-10 16:26:45 -0400479 PyObject *items;
480
Sylvain74453812017-06-10 06:51:48 +0200481 if (!_PyArg_ParseStack(args, nargs, "OCiO:_array_reconstructor",
482 &arraytype, &typecode, &mformat_code, &items)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100483 goto exit;
484 }
Brett Cannon1eb32c22014-10-10 16:26:45 -0400485 return_value = array__array_reconstructor_impl(module, arraytype, typecode, mformat_code, items);
486
487exit:
488 return return_value;
489}
490
491PyDoc_STRVAR(array_array___reduce_ex____doc__,
492"__reduce_ex__($self, value, /)\n"
493"--\n"
494"\n"
495"Return state information for pickling.");
496
497#define ARRAY_ARRAY___REDUCE_EX___METHODDEF \
498 {"__reduce_ex__", (PyCFunction)array_array___reduce_ex__, METH_O, array_array___reduce_ex____doc__},
499
500PyDoc_STRVAR(array_arrayiterator___reduce____doc__,
501"__reduce__($self, /)\n"
502"--\n"
503"\n"
504"Return state information for pickling.");
505
506#define ARRAY_ARRAYITERATOR___REDUCE___METHODDEF \
507 {"__reduce__", (PyCFunction)array_arrayiterator___reduce__, METH_NOARGS, array_arrayiterator___reduce____doc__},
508
509static PyObject *
510array_arrayiterator___reduce___impl(arrayiterobject *self);
511
512static PyObject *
513array_arrayiterator___reduce__(arrayiterobject *self, PyObject *Py_UNUSED(ignored))
514{
515 return array_arrayiterator___reduce___impl(self);
516}
517
518PyDoc_STRVAR(array_arrayiterator___setstate____doc__,
519"__setstate__($self, state, /)\n"
520"--\n"
521"\n"
522"Set state information for unpickling.");
523
524#define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \
525 {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__},
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200526/*[clinic end generated code: output=15da19d2ece09d22 input=a9049054013a1b77]*/