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