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 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 85 | { |
| 86 | Py_ssize_t ival = -1; |
Serhiy Storchaka | 5f4b229d | 2020-05-28 10:33:45 +0300 | [diff] [blame] | 87 | PyObject *iobj = _PyNumber_Index(args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 88 | if (iobj != NULL) { |
| 89 | ival = PyLong_AsSsize_t(iobj); |
| 90 | Py_DECREF(iobj); |
| 91 | } |
| 92 | if (ival == -1 && PyErr_Occurred()) { |
| 93 | goto exit; |
| 94 | } |
| 95 | i = ival; |
| 96 | } |
| 97 | skip_optional: |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 98 | return_value = array_array_pop_impl(self, i); |
| 99 | |
| 100 | exit: |
| 101 | return return_value; |
| 102 | } |
| 103 | |
| 104 | PyDoc_STRVAR(array_array_extend__doc__, |
| 105 | "extend($self, bb, /)\n" |
| 106 | "--\n" |
| 107 | "\n" |
| 108 | "Append items to the end of the array."); |
| 109 | |
| 110 | #define ARRAY_ARRAY_EXTEND_METHODDEF \ |
| 111 | {"extend", (PyCFunction)array_array_extend, METH_O, array_array_extend__doc__}, |
| 112 | |
| 113 | PyDoc_STRVAR(array_array_insert__doc__, |
| 114 | "insert($self, i, v, /)\n" |
| 115 | "--\n" |
| 116 | "\n" |
| 117 | "Insert a new item v into the array before position i."); |
| 118 | |
| 119 | #define ARRAY_ARRAY_INSERT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 120 | {"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] | 121 | |
| 122 | static PyObject * |
| 123 | array_array_insert_impl(arrayobject *self, Py_ssize_t i, PyObject *v); |
| 124 | |
| 125 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 126 | array_array_insert(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 127 | { |
| 128 | PyObject *return_value = NULL; |
| 129 | Py_ssize_t i; |
| 130 | PyObject *v; |
| 131 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 132 | if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 133 | goto exit; |
| 134 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 135 | { |
| 136 | Py_ssize_t ival = -1; |
Serhiy Storchaka | 5f4b229d | 2020-05-28 10:33:45 +0300 | [diff] [blame] | 137 | PyObject *iobj = _PyNumber_Index(args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 138 | if (iobj != NULL) { |
| 139 | ival = PyLong_AsSsize_t(iobj); |
| 140 | Py_DECREF(iobj); |
| 141 | } |
| 142 | if (ival == -1 && PyErr_Occurred()) { |
| 143 | goto exit; |
| 144 | } |
| 145 | i = ival; |
| 146 | } |
| 147 | v = args[1]; |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 148 | return_value = array_array_insert_impl(self, i, v); |
| 149 | |
| 150 | exit: |
| 151 | return return_value; |
| 152 | } |
| 153 | |
| 154 | PyDoc_STRVAR(array_array_buffer_info__doc__, |
| 155 | "buffer_info($self, /)\n" |
| 156 | "--\n" |
| 157 | "\n" |
| 158 | "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" |
| 159 | "\n" |
| 160 | "The length should be multiplied by the itemsize attribute to calculate\n" |
| 161 | "the buffer length in bytes."); |
| 162 | |
| 163 | #define ARRAY_ARRAY_BUFFER_INFO_METHODDEF \ |
| 164 | {"buffer_info", (PyCFunction)array_array_buffer_info, METH_NOARGS, array_array_buffer_info__doc__}, |
| 165 | |
| 166 | static PyObject * |
| 167 | array_array_buffer_info_impl(arrayobject *self); |
| 168 | |
| 169 | static PyObject * |
| 170 | array_array_buffer_info(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 171 | { |
| 172 | return array_array_buffer_info_impl(self); |
| 173 | } |
| 174 | |
| 175 | PyDoc_STRVAR(array_array_append__doc__, |
| 176 | "append($self, v, /)\n" |
| 177 | "--\n" |
| 178 | "\n" |
| 179 | "Append new value v to the end of the array."); |
| 180 | |
| 181 | #define ARRAY_ARRAY_APPEND_METHODDEF \ |
| 182 | {"append", (PyCFunction)array_array_append, METH_O, array_array_append__doc__}, |
| 183 | |
| 184 | PyDoc_STRVAR(array_array_byteswap__doc__, |
| 185 | "byteswap($self, /)\n" |
| 186 | "--\n" |
| 187 | "\n" |
| 188 | "Byteswap all items of the array.\n" |
| 189 | "\n" |
| 190 | "If the items in the array are not 1, 2, 4, or 8 bytes in size, RuntimeError is\n" |
| 191 | "raised."); |
| 192 | |
| 193 | #define ARRAY_ARRAY_BYTESWAP_METHODDEF \ |
| 194 | {"byteswap", (PyCFunction)array_array_byteswap, METH_NOARGS, array_array_byteswap__doc__}, |
| 195 | |
| 196 | static PyObject * |
| 197 | array_array_byteswap_impl(arrayobject *self); |
| 198 | |
| 199 | static PyObject * |
| 200 | array_array_byteswap(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 201 | { |
| 202 | return array_array_byteswap_impl(self); |
| 203 | } |
| 204 | |
| 205 | PyDoc_STRVAR(array_array_reverse__doc__, |
| 206 | "reverse($self, /)\n" |
| 207 | "--\n" |
| 208 | "\n" |
| 209 | "Reverse the order of the items in the array."); |
| 210 | |
| 211 | #define ARRAY_ARRAY_REVERSE_METHODDEF \ |
| 212 | {"reverse", (PyCFunction)array_array_reverse, METH_NOARGS, array_array_reverse__doc__}, |
| 213 | |
| 214 | static PyObject * |
| 215 | array_array_reverse_impl(arrayobject *self); |
| 216 | |
| 217 | static PyObject * |
| 218 | array_array_reverse(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 219 | { |
| 220 | return array_array_reverse_impl(self); |
| 221 | } |
| 222 | |
| 223 | PyDoc_STRVAR(array_array_fromfile__doc__, |
| 224 | "fromfile($self, f, n, /)\n" |
| 225 | "--\n" |
| 226 | "\n" |
| 227 | "Read n objects from the file object f and append them to the end of the array."); |
| 228 | |
| 229 | #define ARRAY_ARRAY_FROMFILE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 230 | {"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] | 231 | |
| 232 | static PyObject * |
| 233 | array_array_fromfile_impl(arrayobject *self, PyObject *f, Py_ssize_t n); |
| 234 | |
| 235 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 236 | array_array_fromfile(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 237 | { |
| 238 | PyObject *return_value = NULL; |
| 239 | PyObject *f; |
| 240 | Py_ssize_t n; |
| 241 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 242 | if (!_PyArg_CheckPositional("fromfile", nargs, 2, 2)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 243 | goto exit; |
| 244 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 245 | f = args[0]; |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 246 | { |
| 247 | Py_ssize_t ival = -1; |
Serhiy Storchaka | 5f4b229d | 2020-05-28 10:33:45 +0300 | [diff] [blame] | 248 | PyObject *iobj = _PyNumber_Index(args[1]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 249 | if (iobj != NULL) { |
| 250 | ival = PyLong_AsSsize_t(iobj); |
| 251 | Py_DECREF(iobj); |
| 252 | } |
| 253 | if (ival == -1 && PyErr_Occurred()) { |
| 254 | goto exit; |
| 255 | } |
| 256 | n = ival; |
| 257 | } |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 258 | return_value = array_array_fromfile_impl(self, f, n); |
| 259 | |
| 260 | exit: |
| 261 | return return_value; |
| 262 | } |
| 263 | |
| 264 | PyDoc_STRVAR(array_array_tofile__doc__, |
| 265 | "tofile($self, f, /)\n" |
| 266 | "--\n" |
| 267 | "\n" |
| 268 | "Write all items (as machine values) to the file object f."); |
| 269 | |
| 270 | #define ARRAY_ARRAY_TOFILE_METHODDEF \ |
| 271 | {"tofile", (PyCFunction)array_array_tofile, METH_O, array_array_tofile__doc__}, |
| 272 | |
| 273 | PyDoc_STRVAR(array_array_fromlist__doc__, |
| 274 | "fromlist($self, list, /)\n" |
| 275 | "--\n" |
| 276 | "\n" |
| 277 | "Append items to array from list."); |
| 278 | |
| 279 | #define ARRAY_ARRAY_FROMLIST_METHODDEF \ |
| 280 | {"fromlist", (PyCFunction)array_array_fromlist, METH_O, array_array_fromlist__doc__}, |
| 281 | |
| 282 | PyDoc_STRVAR(array_array_tolist__doc__, |
| 283 | "tolist($self, /)\n" |
| 284 | "--\n" |
| 285 | "\n" |
| 286 | "Convert array to an ordinary list with the same items."); |
| 287 | |
| 288 | #define ARRAY_ARRAY_TOLIST_METHODDEF \ |
| 289 | {"tolist", (PyCFunction)array_array_tolist, METH_NOARGS, array_array_tolist__doc__}, |
| 290 | |
| 291 | static PyObject * |
| 292 | array_array_tolist_impl(arrayobject *self); |
| 293 | |
| 294 | static PyObject * |
| 295 | array_array_tolist(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 296 | { |
| 297 | return array_array_tolist_impl(self); |
| 298 | } |
| 299 | |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 300 | PyDoc_STRVAR(array_array_frombytes__doc__, |
| 301 | "frombytes($self, buffer, /)\n" |
| 302 | "--\n" |
| 303 | "\n" |
| 304 | "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)."); |
| 305 | |
| 306 | #define ARRAY_ARRAY_FROMBYTES_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 307 | {"frombytes", (PyCFunction)array_array_frombytes, METH_O, array_array_frombytes__doc__}, |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 308 | |
| 309 | static PyObject * |
| 310 | array_array_frombytes_impl(arrayobject *self, Py_buffer *buffer); |
| 311 | |
| 312 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 313 | array_array_frombytes(arrayobject *self, PyObject *arg) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 314 | { |
| 315 | PyObject *return_value = NULL; |
| 316 | Py_buffer buffer = {NULL, NULL}; |
| 317 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 318 | if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) { |
| 319 | goto exit; |
| 320 | } |
| 321 | if (!PyBuffer_IsContiguous(&buffer, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 322 | _PyArg_BadArgument("frombytes", "argument", "contiguous buffer", arg); |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 323 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 324 | } |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 325 | return_value = array_array_frombytes_impl(self, &buffer); |
| 326 | |
| 327 | exit: |
| 328 | /* Cleanup for buffer */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 329 | if (buffer.obj) { |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 330 | PyBuffer_Release(&buffer); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 331 | } |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 332 | |
| 333 | return return_value; |
| 334 | } |
| 335 | |
| 336 | PyDoc_STRVAR(array_array_tobytes__doc__, |
| 337 | "tobytes($self, /)\n" |
| 338 | "--\n" |
| 339 | "\n" |
| 340 | "Convert the array to an array of machine values and return the bytes representation."); |
| 341 | |
| 342 | #define ARRAY_ARRAY_TOBYTES_METHODDEF \ |
| 343 | {"tobytes", (PyCFunction)array_array_tobytes, METH_NOARGS, array_array_tobytes__doc__}, |
| 344 | |
| 345 | static PyObject * |
| 346 | array_array_tobytes_impl(arrayobject *self); |
| 347 | |
| 348 | static PyObject * |
| 349 | array_array_tobytes(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 350 | { |
| 351 | return array_array_tobytes_impl(self); |
| 352 | } |
| 353 | |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 354 | PyDoc_STRVAR(array_array_fromunicode__doc__, |
| 355 | "fromunicode($self, ustr, /)\n" |
| 356 | "--\n" |
| 357 | "\n" |
| 358 | "Extends this array with data from the unicode string ustr.\n" |
| 359 | "\n" |
| 360 | "The array must be a unicode type array; otherwise a ValueError is raised.\n" |
| 361 | "Use array.frombytes(ustr.encode(...)) to append Unicode data to an array of\n" |
| 362 | "some other type."); |
| 363 | |
| 364 | #define ARRAY_ARRAY_FROMUNICODE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 365 | {"fromunicode", (PyCFunction)array_array_fromunicode, METH_O, array_array_fromunicode__doc__}, |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 366 | |
| 367 | static PyObject * |
Inada Naoki | d5d9a71 | 2020-05-11 15:37:25 +0900 | [diff] [blame] | 368 | array_array_fromunicode_impl(arrayobject *self, PyObject *ustr); |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 369 | |
| 370 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 371 | array_array_fromunicode(arrayobject *self, PyObject *arg) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 372 | { |
| 373 | PyObject *return_value = NULL; |
Inada Naoki | d5d9a71 | 2020-05-11 15:37:25 +0900 | [diff] [blame] | 374 | PyObject *ustr; |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 375 | |
Inada Naoki | d5d9a71 | 2020-05-11 15:37:25 +0900 | [diff] [blame] | 376 | if (!PyUnicode_Check(arg)) { |
| 377 | _PyArg_BadArgument("fromunicode", "argument", "str", arg); |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 378 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 379 | } |
Inada Naoki | d5d9a71 | 2020-05-11 15:37:25 +0900 | [diff] [blame] | 380 | if (PyUnicode_READY(arg) == -1) { |
| 381 | goto exit; |
| 382 | } |
| 383 | ustr = arg; |
| 384 | return_value = array_array_fromunicode_impl(self, ustr); |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 385 | |
| 386 | exit: |
| 387 | return return_value; |
| 388 | } |
| 389 | |
| 390 | PyDoc_STRVAR(array_array_tounicode__doc__, |
| 391 | "tounicode($self, /)\n" |
| 392 | "--\n" |
| 393 | "\n" |
| 394 | "Extends this array with data from the unicode string ustr.\n" |
| 395 | "\n" |
| 396 | "Convert the array to a unicode string. The array must be a unicode type array;\n" |
| 397 | "otherwise a ValueError is raised. Use array.tobytes().decode() to obtain a\n" |
| 398 | "unicode string from an array of some other type."); |
| 399 | |
| 400 | #define ARRAY_ARRAY_TOUNICODE_METHODDEF \ |
| 401 | {"tounicode", (PyCFunction)array_array_tounicode, METH_NOARGS, array_array_tounicode__doc__}, |
| 402 | |
| 403 | static PyObject * |
| 404 | array_array_tounicode_impl(arrayobject *self); |
| 405 | |
| 406 | static PyObject * |
| 407 | array_array_tounicode(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 408 | { |
| 409 | return array_array_tounicode_impl(self); |
| 410 | } |
| 411 | |
| 412 | PyDoc_STRVAR(array_array___sizeof____doc__, |
| 413 | "__sizeof__($self, /)\n" |
| 414 | "--\n" |
| 415 | "\n" |
| 416 | "Size of the array in memory, in bytes."); |
| 417 | |
| 418 | #define ARRAY_ARRAY___SIZEOF___METHODDEF \ |
| 419 | {"__sizeof__", (PyCFunction)array_array___sizeof__, METH_NOARGS, array_array___sizeof____doc__}, |
| 420 | |
| 421 | static PyObject * |
| 422 | array_array___sizeof___impl(arrayobject *self); |
| 423 | |
| 424 | static PyObject * |
| 425 | array_array___sizeof__(arrayobject *self, PyObject *Py_UNUSED(ignored)) |
| 426 | { |
| 427 | return array_array___sizeof___impl(self); |
| 428 | } |
| 429 | |
| 430 | PyDoc_STRVAR(array__array_reconstructor__doc__, |
| 431 | "_array_reconstructor($module, arraytype, typecode, mformat_code, items,\n" |
| 432 | " /)\n" |
| 433 | "--\n" |
| 434 | "\n" |
| 435 | "Internal. Used for pickling support."); |
| 436 | |
| 437 | #define ARRAY__ARRAY_RECONSTRUCTOR_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 438 | {"_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] | 439 | |
| 440 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 441 | array__array_reconstructor_impl(PyObject *module, PyTypeObject *arraytype, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 442 | int typecode, |
| 443 | enum machine_format_code mformat_code, |
| 444 | PyObject *items); |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 445 | |
| 446 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 447 | array__array_reconstructor(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 448 | { |
| 449 | PyObject *return_value = NULL; |
| 450 | PyTypeObject *arraytype; |
| 451 | int typecode; |
Larry Hastings | dfbeb16 | 2014-10-13 10:39:41 +0100 | [diff] [blame] | 452 | enum machine_format_code mformat_code; |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 453 | PyObject *items; |
| 454 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 455 | if (!_PyArg_CheckPositional("_array_reconstructor", nargs, 4, 4)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 456 | goto exit; |
| 457 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 458 | arraytype = (PyTypeObject *)args[0]; |
| 459 | if (!PyUnicode_Check(args[1])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 460 | _PyArg_BadArgument("_array_reconstructor", "argument 2", "a unicode character", args[1]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 461 | goto exit; |
| 462 | } |
| 463 | if (PyUnicode_READY(args[1])) { |
| 464 | goto exit; |
| 465 | } |
| 466 | if (PyUnicode_GET_LENGTH(args[1]) != 1) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 467 | _PyArg_BadArgument("_array_reconstructor", "argument 2", "a unicode character", args[1]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 468 | goto exit; |
| 469 | } |
| 470 | typecode = PyUnicode_READ_CHAR(args[1], 0); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 471 | mformat_code = _PyLong_AsInt(args[2]); |
| 472 | if (mformat_code == -1 && PyErr_Occurred()) { |
| 473 | goto exit; |
| 474 | } |
| 475 | items = args[3]; |
Brett Cannon | 1eb32c2 | 2014-10-10 16:26:45 -0400 | [diff] [blame] | 476 | return_value = array__array_reconstructor_impl(module, arraytype, typecode, mformat_code, items); |
| 477 | |
| 478 | exit: |
| 479 | return return_value; |
| 480 | } |
| 481 | |
| 482 | PyDoc_STRVAR(array_array___reduce_ex____doc__, |
| 483 | "__reduce_ex__($self, value, /)\n" |
| 484 | "--\n" |
| 485 | "\n" |
| 486 | "Return state information for pickling."); |
| 487 | |
| 488 | #define ARRAY_ARRAY___REDUCE_EX___METHODDEF \ |
| 489 | {"__reduce_ex__", (PyCFunction)array_array___reduce_ex__, METH_O, array_array___reduce_ex____doc__}, |
| 490 | |
| 491 | PyDoc_STRVAR(array_arrayiterator___reduce____doc__, |
| 492 | "__reduce__($self, /)\n" |
| 493 | "--\n" |
| 494 | "\n" |
| 495 | "Return state information for pickling."); |
| 496 | |
| 497 | #define ARRAY_ARRAYITERATOR___REDUCE___METHODDEF \ |
| 498 | {"__reduce__", (PyCFunction)array_arrayiterator___reduce__, METH_NOARGS, array_arrayiterator___reduce____doc__}, |
| 499 | |
| 500 | static PyObject * |
| 501 | array_arrayiterator___reduce___impl(arrayiterobject *self); |
| 502 | |
| 503 | static PyObject * |
| 504 | array_arrayiterator___reduce__(arrayiterobject *self, PyObject *Py_UNUSED(ignored)) |
| 505 | { |
| 506 | return array_arrayiterator___reduce___impl(self); |
| 507 | } |
| 508 | |
| 509 | PyDoc_STRVAR(array_arrayiterator___setstate____doc__, |
| 510 | "__setstate__($self, state, /)\n" |
| 511 | "--\n" |
| 512 | "\n" |
| 513 | "Set state information for unpickling."); |
| 514 | |
| 515 | #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \ |
| 516 | {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__}, |
Serhiy Storchaka | 5f4b229d | 2020-05-28 10:33:45 +0300 | [diff] [blame] | 517 | /*[clinic end generated code: output=91c1cded65a1285f input=a9049054013a1b77]*/ |