| 1 |
/*[clinic input] |
| 2 |
preserve |
| 3 |
[clinic start generated code]*/ |
| 4 |
|
| 5 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 6 |
# include "pycore_runtime.h" // _Py_SINGLETON() |
| 7 |
#endif |
| 8 |
#include "pycore_abstract.h" // _PyNumber_Index() |
| 9 |
#include "pycore_modsupport.h" // _PyArg_CheckPositional() |
| 10 |
|
| 11 |
PyDoc_STRVAR(array_array_clear__doc__, |
| 12 |
"clear($self, /)\n" |
| 13 |
"--\n" |
| 14 |
"\n" |
| 15 |
"Remove all items from the array."); |
| 16 |
|
| 17 |
#define ARRAY_ARRAY_CLEAR_METHODDEF \ |
| 18 |
{"clear", (PyCFunction)array_array_clear, METH_NOARGS, array_array_clear__doc__}, |
| 19 |
|
| 20 |
static PyObject * |
| 21 |
array_array_clear_impl(arrayobject *self); |
| 22 |
|
| 23 |
static PyObject * |
| 24 |
array_array_clear(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 25 |
{ |
| 26 |
return array_array_clear_impl((arrayobject *)self); |
| 27 |
} |
| 28 |
|
| 29 |
PyDoc_STRVAR(array_array___copy____doc__, |
| 30 |
"__copy__($self, /)\n" |
| 31 |
"--\n" |
| 32 |
"\n" |
| 33 |
"Return a copy of the array."); |
| 34 |
|
| 35 |
#define ARRAY_ARRAY___COPY___METHODDEF \ |
| 36 |
{"__copy__", (PyCFunction)array_array___copy__, METH_NOARGS, array_array___copy____doc__}, |
| 37 |
|
| 38 |
static PyObject * |
| 39 |
array_array___copy___impl(arrayobject *self); |
| 40 |
|
| 41 |
static PyObject * |
| 42 |
array_array___copy__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 43 |
{ |
| 44 |
return array_array___copy___impl((arrayobject *)self); |
| 45 |
} |
| 46 |
|
| 47 |
PyDoc_STRVAR(array_array___deepcopy____doc__, |
| 48 |
"__deepcopy__($self, unused, /)\n" |
| 49 |
"--\n" |
| 50 |
"\n" |
| 51 |
"Return a copy of the array."); |
| 52 |
|
| 53 |
#define ARRAY_ARRAY___DEEPCOPY___METHODDEF \ |
| 54 |
{"__deepcopy__", (PyCFunction)array_array___deepcopy__, METH_O, array_array___deepcopy____doc__}, |
| 55 |
|
| 56 |
static PyObject * |
| 57 |
array_array___deepcopy___impl(arrayobject *self, PyObject *unused); |
| 58 |
|
| 59 |
static PyObject * |
| 60 |
array_array___deepcopy__(PyObject *self, PyObject *unused) |
| 61 |
{ |
| 62 |
PyObject *return_value = NULL; |
| 63 |
|
| 64 |
return_value = array_array___deepcopy___impl((arrayobject *)self, unused); |
| 65 |
|
| 66 |
return return_value; |
| 67 |
} |
| 68 |
|
| 69 |
PyDoc_STRVAR(array_array_count__doc__, |
| 70 |
"count($self, v, /)\n" |
| 71 |
"--\n" |
| 72 |
"\n" |
| 73 |
"Return number of occurrences of v in the array."); |
| 74 |
|
| 75 |
#define ARRAY_ARRAY_COUNT_METHODDEF \ |
| 76 |
{"count", (PyCFunction)array_array_count, METH_O, array_array_count__doc__}, |
| 77 |
|
| 78 |
static PyObject * |
| 79 |
array_array_count_impl(arrayobject *self, PyObject *v); |
| 80 |
|
| 81 |
static PyObject * |
| 82 |
array_array_count(PyObject *self, PyObject *v) |
| 83 |
{ |
| 84 |
PyObject *return_value = NULL; |
| 85 |
|
| 86 |
return_value = array_array_count_impl((arrayobject *)self, v); |
| 87 |
|
| 88 |
return return_value; |
| 89 |
} |
| 90 |
|
| 91 |
PyDoc_STRVAR(array_array_index__doc__, |
| 92 |
"index($self, v, start=0, stop=sys.maxsize, /)\n" |
| 93 |
"--\n" |
| 94 |
"\n" |
| 95 |
"Return index of first occurrence of v in the array.\n" |
| 96 |
"\n" |
| 97 |
"Raise ValueError if the value is not present."); |
| 98 |
|
| 99 |
#define ARRAY_ARRAY_INDEX_METHODDEF \ |
| 100 |
{"index", _PyCFunction_CAST(array_array_index), METH_FASTCALL, array_array_index__doc__}, |
| 101 |
|
| 102 |
static PyObject * |
| 103 |
array_array_index_impl(arrayobject *self, PyObject *v, Py_ssize_t start, |
| 104 |
Py_ssize_t stop); |
| 105 |
|
| 106 |
static PyObject * |
| 107 |
array_array_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 108 |
{ |
| 109 |
PyObject *return_value = NULL; |
| 110 |
PyObject *v; |
| 111 |
Py_ssize_t start = 0; |
| 112 |
Py_ssize_t stop = PY_SSIZE_T_MAX; |
| 113 |
|
| 114 |
if (!_PyArg_CheckPositional("index", nargs, 1, 3)) { |
| 115 |
goto exit; |
| 116 |
} |
| 117 |
v = args[0]; |
| 118 |
if (nargs < 2) { |
| 119 |
goto skip_optional; |
| 120 |
} |
| 121 |
if (!_PyEval_SliceIndexNotNone(args[1], &start)) { |
| 122 |
goto exit; |
| 123 |
} |
| 124 |
if (nargs < 3) { |
| 125 |
goto skip_optional; |
| 126 |
} |
| 127 |
if (!_PyEval_SliceIndexNotNone(args[2], &stop)) { |
| 128 |
goto exit; |
| 129 |
} |
| 130 |
skip_optional: |
| 131 |
return_value = array_array_index_impl((arrayobject *)self, v, start, stop); |
| 132 |
|
| 133 |
exit: |
| 134 |
return return_value; |
| 135 |
} |
| 136 |
|
| 137 |
PyDoc_STRVAR(array_array_remove__doc__, |
| 138 |
"remove($self, v, /)\n" |
| 139 |
"--\n" |
| 140 |
"\n" |
| 141 |
"Remove the first occurrence of v in the array."); |
| 142 |
|
| 143 |
#define ARRAY_ARRAY_REMOVE_METHODDEF \ |
| 144 |
{"remove", (PyCFunction)array_array_remove, METH_O, array_array_remove__doc__}, |
| 145 |
|
| 146 |
static PyObject * |
| 147 |
array_array_remove_impl(arrayobject *self, PyObject *v); |
| 148 |
|
| 149 |
static PyObject * |
| 150 |
array_array_remove(PyObject *self, PyObject *v) |
| 151 |
{ |
| 152 |
PyObject *return_value = NULL; |
| 153 |
|
| 154 |
return_value = array_array_remove_impl((arrayobject *)self, v); |
| 155 |
|
| 156 |
return return_value; |
| 157 |
} |
| 158 |
|
| 159 |
PyDoc_STRVAR(array_array_pop__doc__, |
| 160 |
"pop($self, i=-1, /)\n" |
| 161 |
"--\n" |
| 162 |
"\n" |
| 163 |
"Return the i-th element and delete it from the array.\n" |
| 164 |
"\n" |
| 165 |
"i defaults to -1."); |
| 166 |
|
| 167 |
#define ARRAY_ARRAY_POP_METHODDEF \ |
| 168 |
{"pop", _PyCFunction_CAST(array_array_pop), METH_FASTCALL, array_array_pop__doc__}, |
| 169 |
|
| 170 |
static PyObject * |
| 171 |
array_array_pop_impl(arrayobject *self, Py_ssize_t i); |
| 172 |
|
| 173 |
static PyObject * |
| 174 |
array_array_pop(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 175 |
{ |
| 176 |
PyObject *return_value = NULL; |
| 177 |
Py_ssize_t i = -1; |
| 178 |
|
| 179 |
if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) { |
| 180 |
goto exit; |
| 181 |
} |
| 182 |
if (nargs < 1) { |
| 183 |
goto skip_optional; |
| 184 |
} |
| 185 |
{ |
| 186 |
Py_ssize_t ival = -1; |
| 187 |
PyObject *iobj = _PyNumber_Index(args[0]); |
| 188 |
if (iobj != NULL) { |
| 189 |
ival = PyLong_AsSsize_t(iobj); |
| 190 |
Py_DECREF(iobj); |
| 191 |
} |
| 192 |
if (ival == -1 && PyErr_Occurred()) { |
| 193 |
goto exit; |
| 194 |
} |
| 195 |
i = ival; |
| 196 |
} |
| 197 |
skip_optional: |
| 198 |
return_value = array_array_pop_impl((arrayobject *)self, i); |
| 199 |
|
| 200 |
exit: |
| 201 |
return return_value; |
| 202 |
} |
| 203 |
|
| 204 |
PyDoc_STRVAR(array_array_extend__doc__, |
| 205 |
"extend($self, bb, /)\n" |
| 206 |
"--\n" |
| 207 |
"\n" |
| 208 |
"Append items to the end of the array."); |
| 209 |
|
| 210 |
#define ARRAY_ARRAY_EXTEND_METHODDEF \ |
| 211 |
{"extend", _PyCFunction_CAST(array_array_extend), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, array_array_extend__doc__}, |
| 212 |
|
| 213 |
static PyObject * |
| 214 |
array_array_extend_impl(arrayobject *self, PyTypeObject *cls, PyObject *bb); |
| 215 |
|
| 216 |
static PyObject * |
| 217 |
array_array_extend(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 218 |
{ |
| 219 |
PyObject *return_value = NULL; |
| 220 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 221 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 222 |
#else |
| 223 |
# define KWTUPLE NULL |
| 224 |
#endif |
| 225 |
|
| 226 |
static const char * const _keywords[] = {"", NULL}; |
| 227 |
static _PyArg_Parser _parser = { |
| 228 |
.keywords = _keywords, |
| 229 |
.fname = "extend", |
| 230 |
.kwtuple = KWTUPLE, |
| 231 |
}; |
| 232 |
#undef KWTUPLE |
| 233 |
PyObject *argsbuf[1]; |
| 234 |
PyObject *bb; |
| 235 |
|
| 236 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 237 |
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 238 |
if (!args) { |
| 239 |
goto exit; |
| 240 |
} |
| 241 |
bb = args[0]; |
| 242 |
return_value = array_array_extend_impl((arrayobject *)self, cls, bb); |
| 243 |
|
| 244 |
exit: |
| 245 |
return return_value; |
| 246 |
} |
| 247 |
|
| 248 |
PyDoc_STRVAR(array_array_insert__doc__, |
| 249 |
"insert($self, i, v, /)\n" |
| 250 |
"--\n" |
| 251 |
"\n" |
| 252 |
"Insert a new item v into the array before position i."); |
| 253 |
|
| 254 |
#define ARRAY_ARRAY_INSERT_METHODDEF \ |
| 255 |
{"insert", _PyCFunction_CAST(array_array_insert), METH_FASTCALL, array_array_insert__doc__}, |
| 256 |
|
| 257 |
static PyObject * |
| 258 |
array_array_insert_impl(arrayobject *self, Py_ssize_t i, PyObject *v); |
| 259 |
|
| 260 |
static PyObject * |
| 261 |
array_array_insert(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 262 |
{ |
| 263 |
PyObject *return_value = NULL; |
| 264 |
Py_ssize_t i; |
| 265 |
PyObject *v; |
| 266 |
|
| 267 |
if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { |
| 268 |
goto exit; |
| 269 |
} |
| 270 |
{ |
| 271 |
Py_ssize_t ival = -1; |
| 272 |
PyObject *iobj = _PyNumber_Index(args[0]); |
| 273 |
if (iobj != NULL) { |
| 274 |
ival = PyLong_AsSsize_t(iobj); |
| 275 |
Py_DECREF(iobj); |
| 276 |
} |
| 277 |
if (ival == -1 && PyErr_Occurred()) { |
| 278 |
goto exit; |
| 279 |
} |
| 280 |
i = ival; |
| 281 |
} |
| 282 |
v = args[1]; |
| 283 |
return_value = array_array_insert_impl((arrayobject *)self, i, v); |
| 284 |
|
| 285 |
exit: |
| 286 |
return return_value; |
| 287 |
} |
| 288 |
|
| 289 |
PyDoc_STRVAR(array_array_buffer_info__doc__, |
| 290 |
"buffer_info($self, /)\n" |
| 291 |
"--\n" |
| 292 |
"\n" |
| 293 |
"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" |
| 294 |
"\n" |
| 295 |
"The length should be multiplied by the itemsize attribute to calculate\n" |
| 296 |
"the buffer length in bytes."); |
| 297 |
|
| 298 |
#define ARRAY_ARRAY_BUFFER_INFO_METHODDEF \ |
| 299 |
{"buffer_info", (PyCFunction)array_array_buffer_info, METH_NOARGS, array_array_buffer_info__doc__}, |
| 300 |
|
| 301 |
static PyObject * |
| 302 |
array_array_buffer_info_impl(arrayobject *self); |
| 303 |
|
| 304 |
static PyObject * |
| 305 |
array_array_buffer_info(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 306 |
{ |
| 307 |
return array_array_buffer_info_impl((arrayobject *)self); |
| 308 |
} |
| 309 |
|
| 310 |
PyDoc_STRVAR(array_array_append__doc__, |
| 311 |
"append($self, v, /)\n" |
| 312 |
"--\n" |
| 313 |
"\n" |
| 314 |
"Append new value v to the end of the array."); |
| 315 |
|
| 316 |
#define ARRAY_ARRAY_APPEND_METHODDEF \ |
| 317 |
{"append", (PyCFunction)array_array_append, METH_O, array_array_append__doc__}, |
| 318 |
|
| 319 |
static PyObject * |
| 320 |
array_array_append_impl(arrayobject *self, PyObject *v); |
| 321 |
|
| 322 |
static PyObject * |
| 323 |
array_array_append(PyObject *self, PyObject *v) |
| 324 |
{ |
| 325 |
PyObject *return_value = NULL; |
| 326 |
|
| 327 |
return_value = array_array_append_impl((arrayobject *)self, v); |
| 328 |
|
| 329 |
return return_value; |
| 330 |
} |
| 331 |
|
| 332 |
PyDoc_STRVAR(array_array_byteswap__doc__, |
| 333 |
"byteswap($self, /)\n" |
| 334 |
"--\n" |
| 335 |
"\n" |
| 336 |
"Byteswap all items of the array.\n" |
| 337 |
"\n" |
| 338 |
"If the items in the array are not 1, 2, 4, or 8 bytes in size, RuntimeError is\n" |
| 339 |
"raised."); |
| 340 |
|
| 341 |
#define ARRAY_ARRAY_BYTESWAP_METHODDEF \ |
| 342 |
{"byteswap", (PyCFunction)array_array_byteswap, METH_NOARGS, array_array_byteswap__doc__}, |
| 343 |
|
| 344 |
static PyObject * |
| 345 |
array_array_byteswap_impl(arrayobject *self); |
| 346 |
|
| 347 |
static PyObject * |
| 348 |
array_array_byteswap(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 349 |
{ |
| 350 |
return array_array_byteswap_impl((arrayobject *)self); |
| 351 |
} |
| 352 |
|
| 353 |
PyDoc_STRVAR(array_array_reverse__doc__, |
| 354 |
"reverse($self, /)\n" |
| 355 |
"--\n" |
| 356 |
"\n" |
| 357 |
"Reverse the order of the items in the array."); |
| 358 |
|
| 359 |
#define ARRAY_ARRAY_REVERSE_METHODDEF \ |
| 360 |
{"reverse", (PyCFunction)array_array_reverse, METH_NOARGS, array_array_reverse__doc__}, |
| 361 |
|
| 362 |
static PyObject * |
| 363 |
array_array_reverse_impl(arrayobject *self); |
| 364 |
|
| 365 |
static PyObject * |
| 366 |
array_array_reverse(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 367 |
{ |
| 368 |
return array_array_reverse_impl((arrayobject *)self); |
| 369 |
} |
| 370 |
|
| 371 |
PyDoc_STRVAR(array_array_fromfile__doc__, |
| 372 |
"fromfile($self, f, n, /)\n" |
| 373 |
"--\n" |
| 374 |
"\n" |
| 375 |
"Read n objects from the file object f and append them to the end of the array."); |
| 376 |
|
| 377 |
#define ARRAY_ARRAY_FROMFILE_METHODDEF \ |
| 378 |
{"fromfile", _PyCFunction_CAST(array_array_fromfile), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, array_array_fromfile__doc__}, |
| 379 |
|
| 380 |
static PyObject * |
| 381 |
array_array_fromfile_impl(arrayobject *self, PyTypeObject *cls, PyObject *f, |
| 382 |
Py_ssize_t n); |
| 383 |
|
| 384 |
static PyObject * |
| 385 |
array_array_fromfile(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 386 |
{ |
| 387 |
PyObject *return_value = NULL; |
| 388 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 389 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 390 |
#else |
| 391 |
# define KWTUPLE NULL |
| 392 |
#endif |
| 393 |
|
| 394 |
static const char * const _keywords[] = {"", "", NULL}; |
| 395 |
static _PyArg_Parser _parser = { |
| 396 |
.keywords = _keywords, |
| 397 |
.fname = "fromfile", |
| 398 |
.kwtuple = KWTUPLE, |
| 399 |
}; |
| 400 |
#undef KWTUPLE |
| 401 |
PyObject *argsbuf[2]; |
| 402 |
PyObject *f; |
| 403 |
Py_ssize_t n; |
| 404 |
|
| 405 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 406 |
/*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 407 |
if (!args) { |
| 408 |
goto exit; |
| 409 |
} |
| 410 |
f = args[0]; |
| 411 |
{ |
| 412 |
Py_ssize_t ival = -1; |
| 413 |
PyObject *iobj = _PyNumber_Index(args[1]); |
| 414 |
if (iobj != NULL) { |
| 415 |
ival = PyLong_AsSsize_t(iobj); |
| 416 |
Py_DECREF(iobj); |
| 417 |
} |
| 418 |
if (ival == -1 && PyErr_Occurred()) { |
| 419 |
goto exit; |
| 420 |
} |
| 421 |
n = ival; |
| 422 |
} |
| 423 |
return_value = array_array_fromfile_impl((arrayobject *)self, cls, f, n); |
| 424 |
|
| 425 |
exit: |
| 426 |
return return_value; |
| 427 |
} |
| 428 |
|
| 429 |
PyDoc_STRVAR(array_array_tofile__doc__, |
| 430 |
"tofile($self, f, /)\n" |
| 431 |
"--\n" |
| 432 |
"\n" |
| 433 |
"Write all items (as machine values) to the file object f."); |
| 434 |
|
| 435 |
#define ARRAY_ARRAY_TOFILE_METHODDEF \ |
| 436 |
{"tofile", _PyCFunction_CAST(array_array_tofile), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, array_array_tofile__doc__}, |
| 437 |
|
| 438 |
static PyObject * |
| 439 |
array_array_tofile_impl(arrayobject *self, PyTypeObject *cls, PyObject *f); |
| 440 |
|
| 441 |
static PyObject * |
| 442 |
array_array_tofile(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 443 |
{ |
| 444 |
PyObject *return_value = NULL; |
| 445 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 446 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 447 |
#else |
| 448 |
# define KWTUPLE NULL |
| 449 |
#endif |
| 450 |
|
| 451 |
static const char * const _keywords[] = {"", NULL}; |
| 452 |
static _PyArg_Parser _parser = { |
| 453 |
.keywords = _keywords, |
| 454 |
.fname = "tofile", |
| 455 |
.kwtuple = KWTUPLE, |
| 456 |
}; |
| 457 |
#undef KWTUPLE |
| 458 |
PyObject *argsbuf[1]; |
| 459 |
PyObject *f; |
| 460 |
|
| 461 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 462 |
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 463 |
if (!args) { |
| 464 |
goto exit; |
| 465 |
} |
| 466 |
f = args[0]; |
| 467 |
return_value = array_array_tofile_impl((arrayobject *)self, cls, f); |
| 468 |
|
| 469 |
exit: |
| 470 |
return return_value; |
| 471 |
} |
| 472 |
|
| 473 |
PyDoc_STRVAR(array_array_fromlist__doc__, |
| 474 |
"fromlist($self, list, /)\n" |
| 475 |
"--\n" |
| 476 |
"\n" |
| 477 |
"Append items to array from list."); |
| 478 |
|
| 479 |
#define ARRAY_ARRAY_FROMLIST_METHODDEF \ |
| 480 |
{"fromlist", (PyCFunction)array_array_fromlist, METH_O, array_array_fromlist__doc__}, |
| 481 |
|
| 482 |
static PyObject * |
| 483 |
array_array_fromlist_impl(arrayobject *self, PyObject *list); |
| 484 |
|
| 485 |
static PyObject * |
| 486 |
array_array_fromlist(PyObject *self, PyObject *list) |
| 487 |
{ |
| 488 |
PyObject *return_value = NULL; |
| 489 |
|
| 490 |
return_value = array_array_fromlist_impl((arrayobject *)self, list); |
| 491 |
|
| 492 |
return return_value; |
| 493 |
} |
| 494 |
|
| 495 |
PyDoc_STRVAR(array_array_tolist__doc__, |
| 496 |
"tolist($self, /)\n" |
| 497 |
"--\n" |
| 498 |
"\n" |
| 499 |
"Convert array to an ordinary list with the same items."); |
| 500 |
|
| 501 |
#define ARRAY_ARRAY_TOLIST_METHODDEF \ |
| 502 |
{"tolist", (PyCFunction)array_array_tolist, METH_NOARGS, array_array_tolist__doc__}, |
| 503 |
|
| 504 |
static PyObject * |
| 505 |
array_array_tolist_impl(arrayobject *self); |
| 506 |
|
| 507 |
static PyObject * |
| 508 |
array_array_tolist(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 509 |
{ |
| 510 |
return array_array_tolist_impl((arrayobject *)self); |
| 511 |
} |
| 512 |
|
| 513 |
PyDoc_STRVAR(array_array_frombytes__doc__, |
| 514 |
"frombytes($self, buffer, /)\n" |
| 515 |
"--\n" |
| 516 |
"\n" |
| 517 |
"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."); |
| 518 |
|
| 519 |
#define ARRAY_ARRAY_FROMBYTES_METHODDEF \ |
| 520 |
{"frombytes", (PyCFunction)array_array_frombytes, METH_O, array_array_frombytes__doc__}, |
| 521 |
|
| 522 |
static PyObject * |
| 523 |
array_array_frombytes_impl(arrayobject *self, Py_buffer *buffer); |
| 524 |
|
| 525 |
static PyObject * |
| 526 |
array_array_frombytes(PyObject *self, PyObject *arg) |
| 527 |
{ |
| 528 |
PyObject *return_value = NULL; |
| 529 |
Py_buffer buffer = {NULL, NULL}; |
| 530 |
|
| 531 |
if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) { |
| 532 |
goto exit; |
| 533 |
} |
| 534 |
return_value = array_array_frombytes_impl((arrayobject *)self, &buffer); |
| 535 |
|
| 536 |
exit: |
| 537 |
/* Cleanup for buffer */ |
| 538 |
if (buffer.obj) { |
| 539 |
PyBuffer_Release(&buffer); |
| 540 |
} |
| 541 |
|
| 542 |
return return_value; |
| 543 |
} |
| 544 |
|
| 545 |
PyDoc_STRVAR(array_array_tobytes__doc__, |
| 546 |
"tobytes($self, /)\n" |
| 547 |
"--\n" |
| 548 |
"\n" |
| 549 |
"Convert the array to an array of machine values and return the bytes representation."); |
| 550 |
|
| 551 |
#define ARRAY_ARRAY_TOBYTES_METHODDEF \ |
| 552 |
{"tobytes", (PyCFunction)array_array_tobytes, METH_NOARGS, array_array_tobytes__doc__}, |
| 553 |
|
| 554 |
static PyObject * |
| 555 |
array_array_tobytes_impl(arrayobject *self); |
| 556 |
|
| 557 |
static PyObject * |
| 558 |
array_array_tobytes(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 559 |
{ |
| 560 |
return array_array_tobytes_impl((arrayobject *)self); |
| 561 |
} |
| 562 |
|
| 563 |
PyDoc_STRVAR(array_array_fromunicode__doc__, |
| 564 |
"fromunicode($self, ustr, /)\n" |
| 565 |
"--\n" |
| 566 |
"\n" |
| 567 |
"Extends this array with data from the unicode string ustr.\n" |
| 568 |
"\n" |
| 569 |
"The array must be a unicode type array; otherwise a ValueError is raised.\n" |
| 570 |
"Use array.frombytes(ustr.encode(...)) to append Unicode data to an array of\n" |
| 571 |
"some other type."); |
| 572 |
|
| 573 |
#define ARRAY_ARRAY_FROMUNICODE_METHODDEF \ |
| 574 |
{"fromunicode", (PyCFunction)array_array_fromunicode, METH_O, array_array_fromunicode__doc__}, |
| 575 |
|
| 576 |
static PyObject * |
| 577 |
array_array_fromunicode_impl(arrayobject *self, PyObject *ustr); |
| 578 |
|
| 579 |
static PyObject * |
| 580 |
array_array_fromunicode(PyObject *self, PyObject *arg) |
| 581 |
{ |
| 582 |
PyObject *return_value = NULL; |
| 583 |
PyObject *ustr; |
| 584 |
|
| 585 |
if (!PyUnicode_Check(arg)) { |
| 586 |
_PyArg_BadArgument("fromunicode", "argument", "str", arg); |
| 587 |
goto exit; |
| 588 |
} |
| 589 |
ustr = arg; |
| 590 |
return_value = array_array_fromunicode_impl((arrayobject *)self, ustr); |
| 591 |
|
| 592 |
exit: |
| 593 |
return return_value; |
| 594 |
} |
| 595 |
|
| 596 |
PyDoc_STRVAR(array_array_tounicode__doc__, |
| 597 |
"tounicode($self, /)\n" |
| 598 |
"--\n" |
| 599 |
"\n" |
| 600 |
"Extends this array with data from the unicode string ustr.\n" |
| 601 |
"\n" |
| 602 |
"Convert the array to a unicode string. The array must be a unicode type array;\n" |
| 603 |
"otherwise a ValueError is raised. Use array.tobytes().decode() to obtain a\n" |
| 604 |
"unicode string from an array of some other type."); |
| 605 |
|
| 606 |
#define ARRAY_ARRAY_TOUNICODE_METHODDEF \ |
| 607 |
{"tounicode", (PyCFunction)array_array_tounicode, METH_NOARGS, array_array_tounicode__doc__}, |
| 608 |
|
| 609 |
static PyObject * |
| 610 |
array_array_tounicode_impl(arrayobject *self); |
| 611 |
|
| 612 |
static PyObject * |
| 613 |
array_array_tounicode(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 614 |
{ |
| 615 |
return array_array_tounicode_impl((arrayobject *)self); |
| 616 |
} |
| 617 |
|
| 618 |
PyDoc_STRVAR(array_array___sizeof____doc__, |
| 619 |
"__sizeof__($self, /)\n" |
| 620 |
"--\n" |
| 621 |
"\n" |
| 622 |
"Size of the array in memory, in bytes."); |
| 623 |
|
| 624 |
#define ARRAY_ARRAY___SIZEOF___METHODDEF \ |
| 625 |
{"__sizeof__", (PyCFunction)array_array___sizeof__, METH_NOARGS, array_array___sizeof____doc__}, |
| 626 |
|
| 627 |
static PyObject * |
| 628 |
array_array___sizeof___impl(arrayobject *self); |
| 629 |
|
| 630 |
static PyObject * |
| 631 |
array_array___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 632 |
{ |
| 633 |
return array_array___sizeof___impl((arrayobject *)self); |
| 634 |
} |
| 635 |
|
| 636 |
PyDoc_STRVAR(array__array_reconstructor__doc__, |
| 637 |
"_array_reconstructor($module, arraytype, typecode, mformat_code, items,\n" |
| 638 |
" /)\n" |
| 639 |
"--\n" |
| 640 |
"\n" |
| 641 |
"Internal. Used for pickling support."); |
| 642 |
|
| 643 |
#define ARRAY__ARRAY_RECONSTRUCTOR_METHODDEF \ |
| 644 |
{"_array_reconstructor", _PyCFunction_CAST(array__array_reconstructor), METH_FASTCALL, array__array_reconstructor__doc__}, |
| 645 |
|
| 646 |
static PyObject * |
| 647 |
array__array_reconstructor_impl(PyObject *module, PyTypeObject *arraytype, |
| 648 |
int typecode, |
| 649 |
enum machine_format_code mformat_code, |
| 650 |
PyObject *items); |
| 651 |
|
| 652 |
static PyObject * |
| 653 |
array__array_reconstructor(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 654 |
{ |
| 655 |
PyObject *return_value = NULL; |
| 656 |
PyTypeObject *arraytype; |
| 657 |
int typecode; |
| 658 |
enum machine_format_code mformat_code; |
| 659 |
PyObject *items; |
| 660 |
|
| 661 |
if (!_PyArg_CheckPositional("_array_reconstructor", nargs, 4, 4)) { |
| 662 |
goto exit; |
| 663 |
} |
| 664 |
arraytype = (PyTypeObject *)args[0]; |
| 665 |
if (!PyUnicode_Check(args[1])) { |
| 666 |
_PyArg_BadArgument("_array_reconstructor", "argument 2", "a unicode character", args[1]); |
| 667 |
goto exit; |
| 668 |
} |
| 669 |
if (PyUnicode_GET_LENGTH(args[1]) != 1) { |
| 670 |
PyErr_Format(PyExc_TypeError, |
| 671 |
"_array_reconstructor(): argument 2 must be a unicode character, " |
| 672 |
"not a string of length %zd", |
| 673 |
PyUnicode_GET_LENGTH(args[1])); |
| 674 |
goto exit; |
| 675 |
} |
| 676 |
typecode = PyUnicode_READ_CHAR(args[1], 0); |
| 677 |
mformat_code = PyLong_AsInt(args[2]); |
| 678 |
if (mformat_code == -1 && PyErr_Occurred()) { |
| 679 |
goto exit; |
| 680 |
} |
| 681 |
items = args[3]; |
| 682 |
return_value = array__array_reconstructor_impl(module, arraytype, typecode, mformat_code, items); |
| 683 |
|
| 684 |
exit: |
| 685 |
return return_value; |
| 686 |
} |
| 687 |
|
| 688 |
PyDoc_STRVAR(array_array___reduce_ex____doc__, |
| 689 |
"__reduce_ex__($self, value, /)\n" |
| 690 |
"--\n" |
| 691 |
"\n" |
| 692 |
"Return state information for pickling."); |
| 693 |
|
| 694 |
#define ARRAY_ARRAY___REDUCE_EX___METHODDEF \ |
| 695 |
{"__reduce_ex__", _PyCFunction_CAST(array_array___reduce_ex__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, array_array___reduce_ex____doc__}, |
| 696 |
|
| 697 |
static PyObject * |
| 698 |
array_array___reduce_ex___impl(arrayobject *self, PyTypeObject *cls, |
| 699 |
PyObject *value); |
| 700 |
|
| 701 |
static PyObject * |
| 702 |
array_array___reduce_ex__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 703 |
{ |
| 704 |
PyObject *return_value = NULL; |
| 705 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 706 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 707 |
#else |
| 708 |
# define KWTUPLE NULL |
| 709 |
#endif |
| 710 |
|
| 711 |
static const char * const _keywords[] = {"", NULL}; |
| 712 |
static _PyArg_Parser _parser = { |
| 713 |
.keywords = _keywords, |
| 714 |
.fname = "__reduce_ex__", |
| 715 |
.kwtuple = KWTUPLE, |
| 716 |
}; |
| 717 |
#undef KWTUPLE |
| 718 |
PyObject *argsbuf[1]; |
| 719 |
PyObject *value; |
| 720 |
|
| 721 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 722 |
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 723 |
if (!args) { |
| 724 |
goto exit; |
| 725 |
} |
| 726 |
value = args[0]; |
| 727 |
return_value = array_array___reduce_ex___impl((arrayobject *)self, cls, value); |
| 728 |
|
| 729 |
exit: |
| 730 |
return return_value; |
| 731 |
} |
| 732 |
|
| 733 |
PyDoc_STRVAR(array_arrayiterator___reduce____doc__, |
| 734 |
"__reduce__($self, /)\n" |
| 735 |
"--\n" |
| 736 |
"\n" |
| 737 |
"Return state information for pickling."); |
| 738 |
|
| 739 |
#define ARRAY_ARRAYITERATOR___REDUCE___METHODDEF \ |
| 740 |
{"__reduce__", _PyCFunction_CAST(array_arrayiterator___reduce__), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, array_arrayiterator___reduce____doc__}, |
| 741 |
|
| 742 |
static PyObject * |
| 743 |
array_arrayiterator___reduce___impl(arrayiterobject *self, PyTypeObject *cls); |
| 744 |
|
| 745 |
static PyObject * |
| 746 |
array_arrayiterator___reduce__(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 747 |
{ |
| 748 |
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
| 749 |
PyErr_SetString(PyExc_TypeError, "__reduce__() takes no arguments"); |
| 750 |
return NULL; |
| 751 |
} |
| 752 |
return array_arrayiterator___reduce___impl((arrayiterobject *)self, cls); |
| 753 |
} |
| 754 |
|
| 755 |
PyDoc_STRVAR(array_arrayiterator___setstate____doc__, |
| 756 |
"__setstate__($self, state, /)\n" |
| 757 |
"--\n" |
| 758 |
"\n" |
| 759 |
"Set state information for unpickling."); |
| 760 |
|
| 761 |
#define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \ |
| 762 |
{"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__}, |
| 763 |
|
| 764 |
static PyObject * |
| 765 |
array_arrayiterator___setstate___impl(arrayiterobject *self, PyObject *state); |
| 766 |
|
| 767 |
static PyObject * |
| 768 |
array_arrayiterator___setstate__(PyObject *self, PyObject *state) |
| 769 |
{ |
| 770 |
PyObject *return_value = NULL; |
| 771 |
|
| 772 |
return_value = array_arrayiterator___setstate___impl((arrayiterobject *)self, state); |
| 773 |
|
| 774 |
return return_value; |
| 775 |
} |
| 776 |
/*[clinic end generated code: output=dd49451ac1cc3f39 input=a9049054013a1b77]*/ |