* Initialize a new BoundArrayMethodObject from slots. Slots which are * not provided may be filled with defaults. * * @param res The new PyBoundArrayMethodObject to be filled. * @param spec The specification list passed by the user. * @param private Private flag to limit certain slots to use in NumPy. * @return -1 on error 0 on success */
| 242 | * @return -1 on error 0 on success |
| 243 | */ |
| 244 | static int |
| 245 | fill_arraymethod_from_slots( |
| 246 | PyBoundArrayMethodObject *res, PyArrayMethod_Spec *spec, |
| 247 | int private) |
| 248 | { |
| 249 | PyArrayMethodObject *meth = res->method; |
| 250 | |
| 251 | /* Set the defaults */ |
| 252 | meth->get_strided_loop = &npy_default_get_strided_loop; |
| 253 | meth->resolve_descriptors = &default_resolve_descriptors; |
| 254 | meth->get_reduction_initial = NULL; /* no initial/identity by default */ |
| 255 | |
| 256 | /* Fill in the slots passed by the user */ |
| 257 | /* |
| 258 | * TODO: This is reasonable for now, but it would be nice to find a |
| 259 | * shorter solution, and add some additional error checking (e.g. |
| 260 | * the same slot used twice). Python uses an array of slot offsets. |
| 261 | */ |
| 262 | for (PyType_Slot *slot = &spec->slots[0]; slot->slot != 0; slot++) { |
| 263 | switch (slot->slot) { |
| 264 | case NPY_METH_resolve_descriptors: |
| 265 | meth->resolve_descriptors = slot->pfunc; |
| 266 | continue; |
| 267 | case _NPY_METH_get_loop: |
| 268 | /* |
| 269 | * NOTE: get_loop is considered "unstable" in the public API, |
| 270 | * I do not like the signature, and the `move_references` |
| 271 | * parameter must NOT be used. |
| 272 | * (as in: we should not worry about changing it, but of |
| 273 | * course that would not break it immediately.) |
| 274 | */ |
| 275 | /* Only allow override for private functions initially */ |
| 276 | meth->get_strided_loop = slot->pfunc; |
| 277 | continue; |
| 278 | /* "Typical" loops, supported used by the default `get_loop` */ |
| 279 | case NPY_METH_strided_loop: |
| 280 | meth->strided_loop = slot->pfunc; |
| 281 | continue; |
| 282 | case NPY_METH_contiguous_loop: |
| 283 | meth->contiguous_loop = slot->pfunc; |
| 284 | continue; |
| 285 | case NPY_METH_unaligned_strided_loop: |
| 286 | meth->unaligned_strided_loop = slot->pfunc; |
| 287 | continue; |
| 288 | case NPY_METH_unaligned_contiguous_loop: |
| 289 | meth->unaligned_contiguous_loop = slot->pfunc; |
| 290 | continue; |
| 291 | case NPY_METH_get_reduction_initial: |
| 292 | meth->get_reduction_initial = slot->pfunc; |
| 293 | continue; |
| 294 | case NPY_METH_contiguous_indexed_loop: |
| 295 | meth->contiguous_indexed_loop = slot->pfunc; |
| 296 | continue; |
| 297 | default: |
| 298 | break; |
| 299 | } |
| 300 | PyErr_Format(PyExc_RuntimeError, |
| 301 | "invalid slot number %d to ArrayMethod: %s", |
no outgoing calls
no test coverage detected