Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 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 * |
| 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, /)\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 | |
| 50 | PyDoc_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 | |
| 59 | PyDoc_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 Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 68 | {"pop", (PyCFunction)(void(*)(void))array_array_pop, METH_FASTCALL, array_array_pop__doc__}, |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 69 | |
| 70 | static PyObject * |
| 71 | array_array_pop_impl(arrayobject *self, Py_ssize_t i); |
| 72 | |
| 73 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 74 | array_array_pop(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 75 | { |
| 76 | PyObject *return_value = NULL; |
| 77 | Py_ssize_t i = -1; |
| 78 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 79 | if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 80 | goto exit; |
| 81 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 82 | 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 | } |
| 102 | skip_optional: |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 103 | return_value = array_array_pop_impl(self, i); |
| 104 | |
| 105 | exit: |
| 106 | return return_value; |
| 107 | } |
| 108 | |
| 109 | PyDoc_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 | |
| 118 | PyDoc_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 Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 125 | {"insert", (PyCFunction)(void(*)(void))array_array_insert, METH_FASTCALL, array_array_insert__doc__}, |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 126 | |
| 127 | static PyObject * |
| 128 | array_array_insert_impl(arrayobject *self, Py_ssize_t i, PyObject *v); |
| 129 | |
| 130 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 131 | array_array_insert(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 132 | { |
| 133 | PyObject *return_value = NULL; |
| 134 | Py_ssize_t i; |
| 135 | PyObject *v; |
| 136 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 137 | if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 138 | goto exit; |
| 139 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 140 | 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 Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 158 | return_value = array_array_insert_impl(self, i, v); |
| 159 | |
| 160 | exit: |
| 161 | return return_value; |
| 162 | } |
| 163 | |
| 164 | PyDoc_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 | |
| 176 | static PyObject * |
| 177 | array_array_buffer_info_impl(arrayobject *self); |
| 178 | |
| 179 | static PyObject * |
| 180 | array_array_buffer_info(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 181 | { |
| 182 | return array_array_buffer_info_impl(self); |
| 183 | } |
| 184 | |
| 185 | PyDoc_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 | |
| 194 | PyDoc_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 | |
| 206 | static PyObject * |
| 207 | array_array_byteswap_impl(arrayobject *self); |
| 208 | |
| 209 | static PyObject * |
| 210 | array_array_byteswap(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 211 | { |
| 212 | return array_array_byteswap_impl(self); |
| 213 | } |
| 214 | |
| 215 | PyDoc_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 | |
| 224 | static PyObject * |
| 225 | array_array_reverse_impl(arrayobject *self); |
| 226 | |
| 227 | static PyObject * |
| 228 | array_array_reverse(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 229 | { |
| 230 | return array_array_reverse_impl(self); |
| 231 | } |
| 232 | |
| 233 | PyDoc_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 Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 240 | {"fromfile", (PyCFunction)(void(*)(void))array_array_fromfile, METH_FASTCALL, array_array_fromfile__doc__}, |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 241 | |
| 242 | static PyObject * |
| 243 | array_array_fromfile_impl(arrayobject *self, PyObject *f, Py_ssize_t n); |
| 244 | |
| 245 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 246 | array_array_fromfile(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 247 | { |
| 248 | PyObject *return_value = NULL; |
| 249 | PyObject *f; |
| 250 | Py_ssize_t n; |
| 251 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 252 | if (!_PyArg_CheckPositional("fromfile", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 253 | goto exit; |
| 254 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 255 | 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 Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 273 | return_value = array_array_fromfile_impl(self, f, n); |
| 274 | |
| 275 | exit: |
| 276 | return return_value; |
| 277 | } |
| 278 | |
| 279 | PyDoc_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 | |
| 288 | PyDoc_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 | |
| 297 | PyDoc_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 | |
| 306 | static PyObject * |
| 307 | array_array_tolist_impl(arrayobject *self); |
| 308 | |
| 309 | static PyObject * |
| 310 | array_array_tolist(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 311 | { |
| 312 | return array_array_tolist_impl(self); |
| 313 | } |
| 314 | |
| 315 | PyDoc_STRVAR(array_array_fromstring__doc__, |
| 316 | "fromstring($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).\n" |
| 320 | "\n" |
| 321 | "This method is deprecated. Use frombytes instead."); |
| 322 | |
| 323 | #define ARRAY_ARRAY_FROMSTRING_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 324 | {"fromstring", (PyCFunction)array_array_fromstring, METH_O, array_array_fromstring__doc__}, |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 325 | |
| 326 | static PyObject * |
| 327 | array_array_fromstring_impl(arrayobject *self, Py_buffer *buffer); |
| 328 | |
| 329 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 330 | array_array_fromstring(arrayobject *self, PyObject *arg) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 331 | { |
| 332 | PyObject *return_value = NULL; |
| 333 | Py_buffer buffer = {NULL, NULL}; |
| 334 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 335 | if (PyUnicode_Check(arg)) { |
| 336 | Py_ssize_t len; |
| 337 | const char *ptr = PyUnicode_AsUTF8AndSize(arg, &len); |
| 338 | if (ptr == NULL) { |
| 339 | goto exit; |
| 340 | } |
| 341 | PyBuffer_FillInfo(&buffer, arg, (void *)ptr, len, 1, 0); |
| 342 | } |
| 343 | else { /* any bytes-like object */ |
| 344 | if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) { |
| 345 | goto exit; |
| 346 | } |
| 347 | if (!PyBuffer_IsContiguous(&buffer, 'C')) { |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 348 | _PyArg_BadArgument("fromstring", 0, "contiguous buffer", arg); |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 349 | goto exit; |
| 350 | } |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 351 | } |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 352 | return_value = array_array_fromstring_impl(self, &buffer); |
| 353 | |
| 354 | exit: |
| 355 | /* Cleanup for buffer */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 356 | if (buffer.obj) { |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 357 | PyBuffer_Release(&buffer); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 358 | } |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 359 | |
| 360 | return return_value; |
| 361 | } |
| 362 | |
| 363 | PyDoc_STRVAR(array_array_frombytes__doc__, |
| 364 | "frombytes($self, buffer, /)\n" |
| 365 | "--\n" |
| 366 | "\n" |
| 367 | "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)."); |
| 368 | |
| 369 | #define ARRAY_ARRAY_FROMBYTES_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 370 | {"frombytes", (PyCFunction)array_array_frombytes, METH_O, array_array_frombytes__doc__}, |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 371 | |
| 372 | static PyObject * |
| 373 | array_array_frombytes_impl(arrayobject *self, Py_buffer *buffer); |
| 374 | |
| 375 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 376 | array_array_frombytes(arrayobject *self, PyObject *arg) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 377 | { |
| 378 | PyObject *return_value = NULL; |
| 379 | Py_buffer buffer = {NULL, NULL}; |
| 380 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 381 | if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) { |
| 382 | goto exit; |
| 383 | } |
| 384 | if (!PyBuffer_IsContiguous(&buffer, 'C')) { |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 385 | _PyArg_BadArgument("frombytes", 0, "contiguous buffer", arg); |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 386 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 387 | } |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 388 | return_value = array_array_frombytes_impl(self, &buffer); |
| 389 | |
| 390 | exit: |
| 391 | /* Cleanup for buffer */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 392 | if (buffer.obj) { |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 393 | PyBuffer_Release(&buffer); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 394 | } |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 395 | |
| 396 | return return_value; |
| 397 | } |
| 398 | |
| 399 | PyDoc_STRVAR(array_array_tobytes__doc__, |
| 400 | "tobytes($self, /)\n" |
| 401 | "--\n" |
| 402 | "\n" |
| 403 | "Convert the array to an array of machine values and return the bytes representation."); |
| 404 | |
| 405 | #define ARRAY_ARRAY_TOBYTES_METHODDEF \ |
| 406 | {"tobytes", (PyCFunction)array_array_tobytes, METH_NOARGS, array_array_tobytes__doc__}, |
| 407 | |
| 408 | static PyObject * |
| 409 | array_array_tobytes_impl(arrayobject *self); |
| 410 | |
| 411 | static PyObject * |
| 412 | array_array_tobytes(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 413 | { |
| 414 | return array_array_tobytes_impl(self); |
| 415 | } |
| 416 | |
| 417 | PyDoc_STRVAR(array_array_tostring__doc__, |
| 418 | "tostring($self, /)\n" |
| 419 | "--\n" |
| 420 | "\n" |
| 421 | "Convert the array to an array of machine values and return the bytes representation.\n" |
| 422 | "\n" |
| 423 | "This method is deprecated. Use tobytes instead."); |
| 424 | |
| 425 | #define ARRAY_ARRAY_TOSTRING_METHODDEF \ |
| 426 | {"tostring", (PyCFunction)array_array_tostring, METH_NOARGS, array_array_tostring__doc__}, |
| 427 | |
| 428 | static PyObject * |
| 429 | array_array_tostring_impl(arrayobject *self); |
| 430 | |
| 431 | static PyObject * |
| 432 | array_array_tostring(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 433 | { |
| 434 | return array_array_tostring_impl(self); |
| 435 | } |
| 436 | |
| 437 | PyDoc_STRVAR(array_array_fromunicode__doc__, |
| 438 | "fromunicode($self, ustr, /)\n" |
| 439 | "--\n" |
| 440 | "\n" |
| 441 | "Extends this array with data from the unicode string ustr.\n" |
| 442 | "\n" |
| 443 | "The array must be a unicode type array; otherwise a ValueError is raised.\n" |
| 444 | "Use array.frombytes(ustr.encode(...)) to append Unicode data to an array of\n" |
| 445 | "some other type."); |
| 446 | |
| 447 | #define ARRAY_ARRAY_FROMUNICODE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 448 | {"fromunicode", (PyCFunction)array_array_fromunicode, METH_O, array_array_fromunicode__doc__}, |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 449 | |
| 450 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 451 | array_array_fromunicode_impl(arrayobject *self, const Py_UNICODE *ustr, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 452 | Py_ssize_clean_t ustr_length); |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 453 | |
| 454 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 455 | array_array_fromunicode(arrayobject *self, PyObject *arg) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 456 | { |
| 457 | PyObject *return_value = NULL; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 458 | const Py_UNICODE *ustr; |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 459 | Py_ssize_clean_t ustr_length; |
| 460 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 461 | if (!PyArg_Parse(arg, "u#:fromunicode", &ustr, &ustr_length)) { |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 462 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 463 | } |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 464 | return_value = array_array_fromunicode_impl(self, ustr, ustr_length); |
| 465 | |
| 466 | exit: |
| 467 | return return_value; |
| 468 | } |
| 469 | |
| 470 | PyDoc_STRVAR(array_array_tounicode__doc__, |
| 471 | "tounicode($self, /)\n" |
| 472 | "--\n" |
| 473 | "\n" |
| 474 | "Extends this array with data from the unicode string ustr.\n" |
| 475 | "\n" |
| 476 | "Convert the array to a unicode string. The array must be a unicode type array;\n" |
| 477 | "otherwise a ValueError is raised. Use array.tobytes().decode() to obtain a\n" |
| 478 | "unicode string from an array of some other type."); |
| 479 | |
| 480 | #define ARRAY_ARRAY_TOUNICODE_METHODDEF \ |
| 481 | {"tounicode", (PyCFunction)array_array_tounicode, METH_NOARGS, array_array_tounicode__doc__}, |
| 482 | |
| 483 | static PyObject * |
| 484 | array_array_tounicode_impl(arrayobject *self); |
| 485 | |
| 486 | static PyObject * |
| 487 | array_array_tounicode(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 488 | { |
| 489 | return array_array_tounicode_impl(self); |
| 490 | } |
| 491 | |
| 492 | PyDoc_STRVAR(array_array___sizeof____doc__, |
| 493 | "__sizeof__($self, /)\n" |
| 494 | "--\n" |
| 495 | "\n" |
| 496 | "Size of the array in memory, in bytes."); |
| 497 | |
| 498 | #define ARRAY_ARRAY___SIZEOF___METHODDEF \ |
| 499 | {"__sizeof__", (PyCFunction)array_array___sizeof__, METH_NOARGS, array_array___sizeof____doc__}, |
| 500 | |
| 501 | static PyObject * |
| 502 | array_array___sizeof___impl(arrayobject *self); |
| 503 | |
| 504 | static PyObject * |
| 505 | array_array___sizeof__(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 506 | { |
| 507 | return array_array___sizeof___impl(self); |
| 508 | } |
| 509 | |
| 510 | PyDoc_STRVAR(array__array_reconstructor__doc__, |
| 511 | "_array_reconstructor($module, arraytype, typecode, mformat_code, items,\n" |
| 512 | " /)\n" |
| 513 | "--\n" |
| 514 | "\n" |
| 515 | "Internal. Used for pickling support."); |
| 516 | |
| 517 | #define ARRAY__ARRAY_RECONSTRUCTOR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 518 | {"_array_reconstructor", (PyCFunction)(void(*)(void))array__array_reconstructor, METH_FASTCALL, array__array_reconstructor__doc__}, |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 519 | |
| 520 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 521 | array__array_reconstructor_impl(PyObject *module, PyTypeObject *arraytype, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 522 | int typecode, |
| 523 | enum machine_format_code mformat_code, |
| 524 | PyObject *items); |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 525 | |
| 526 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 527 | array__array_reconstructor(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 528 | { |
| 529 | PyObject *return_value = NULL; |
| 530 | PyTypeObject *arraytype; |
| 531 | int typecode; |
Larry Hastings | dfbeb16 | 2014-10-13 10:39:41 +0100 | [diff] [blame] | 532 | enum machine_format_code mformat_code; |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 533 | PyObject *items; |
| 534 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 535 | if (!_PyArg_CheckPositional("_array_reconstructor", nargs, 4, 4)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 536 | goto exit; |
| 537 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 538 | arraytype = (PyTypeObject *)args[0]; |
| 539 | if (!PyUnicode_Check(args[1])) { |
| 540 | _PyArg_BadArgument("_array_reconstructor", 2, "a unicode character", args[1]); |
| 541 | goto exit; |
| 542 | } |
| 543 | if (PyUnicode_READY(args[1])) { |
| 544 | goto exit; |
| 545 | } |
| 546 | if (PyUnicode_GET_LENGTH(args[1]) != 1) { |
| 547 | _PyArg_BadArgument("_array_reconstructor", 2, "a unicode character", args[1]); |
| 548 | goto exit; |
| 549 | } |
| 550 | typecode = PyUnicode_READ_CHAR(args[1], 0); |
| 551 | if (PyFloat_Check(args[2])) { |
| 552 | PyErr_SetString(PyExc_TypeError, |
| 553 | "integer argument expected, got float" ); |
| 554 | goto exit; |
| 555 | } |
| 556 | mformat_code = _PyLong_AsInt(args[2]); |
| 557 | if (mformat_code == -1 && PyErr_Occurred()) { |
| 558 | goto exit; |
| 559 | } |
| 560 | items = args[3]; |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 561 | return_value = array__array_reconstructor_impl(module, arraytype, typecode, mformat_code, items); |
| 562 | |
| 563 | exit: |
| 564 | return return_value; |
| 565 | } |
| 566 | |
| 567 | PyDoc_STRVAR(array_array___reduce_ex____doc__, |
| 568 | "__reduce_ex__($self, value, /)\n" |
| 569 | "--\n" |
| 570 | "\n" |
| 571 | "Return state information for pickling."); |
| 572 | |
| 573 | #define ARRAY_ARRAY___REDUCE_EX___METHODDEF \ |
| 574 | {"__reduce_ex__", (PyCFunction)array_array___reduce_ex__, METH_O, array_array___reduce_ex____doc__}, |
| 575 | |
| 576 | PyDoc_STRVAR(array_arrayiterator___reduce____doc__, |
| 577 | "__reduce__($self, /)\n" |
| 578 | "--\n" |
| 579 | "\n" |
| 580 | "Return state information for pickling."); |
| 581 | |
| 582 | #define ARRAY_ARRAYITERATOR___REDUCE___METHODDEF \ |
| 583 | {"__reduce__", (PyCFunction)array_arrayiterator___reduce__, METH_NOARGS, array_arrayiterator___reduce____doc__}, |
| 584 | |
| 585 | static PyObject * |
| 586 | array_arrayiterator___reduce___impl(arrayiterobject *self); |
| 587 | |
| 588 | static PyObject * |
| 589 | array_arrayiterator___reduce__(arrayiterobject *self, PyObject *Py_UNUSED(ignored)) |
| 590 | { |
| 591 | return array_arrayiterator___reduce___impl(self); |
| 592 | } |
| 593 | |
| 594 | PyDoc_STRVAR(array_arrayiterator___setstate____doc__, |
| 595 | "__setstate__($self, state, /)\n" |
| 596 | "--\n" |
| 597 | "\n" |
| 598 | "Set state information for unpickling."); |
| 599 | |
| 600 | #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \ |
| 601 | {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__}, |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 602 | /*[clinic end generated code: output=c9a40f11f1a866fb input=a9049054013a1b77]*/ |