| 567 | } |
| 568 | |
| 569 | NPY_NO_EXPORT PyObject * |
| 570 | get_handler_name(PyObject *NPY_UNUSED(self), PyObject *args) |
| 571 | { |
| 572 | PyObject *arr=NULL; |
| 573 | if (!PyArg_ParseTuple(args, "|O:get_handler_name", &arr)) { |
| 574 | return NULL; |
| 575 | } |
| 576 | if (arr != NULL && !PyArray_Check(arr)) { |
| 577 | PyErr_SetString(PyExc_ValueError, "if supplied, argument must be an ndarray"); |
| 578 | return NULL; |
| 579 | } |
| 580 | PyObject *mem_handler; |
| 581 | PyDataMem_Handler *handler; |
| 582 | PyObject *name; |
| 583 | if (arr != NULL) { |
| 584 | mem_handler = PyArray_HANDLER((PyArrayObject *) arr); |
| 585 | if (mem_handler == NULL) { |
| 586 | Py_RETURN_NONE; |
| 587 | } |
| 588 | Py_INCREF(mem_handler); |
| 589 | } |
| 590 | else { |
| 591 | mem_handler = PyDataMem_GetHandler(); |
| 592 | if (mem_handler == NULL) { |
| 593 | return NULL; |
| 594 | } |
| 595 | } |
| 596 | handler = (PyDataMem_Handler *) PyCapsule_GetPointer(mem_handler, "mem_handler"); |
| 597 | if (handler == NULL) { |
| 598 | Py_DECREF(mem_handler); |
| 599 | return NULL; |
| 600 | } |
| 601 | name = PyUnicode_FromString(handler->name); |
| 602 | Py_DECREF(mem_handler); |
| 603 | return name; |
| 604 | } |
| 605 | |
| 606 | NPY_NO_EXPORT PyObject * |
| 607 | get_handler_version(PyObject *NPY_UNUSED(self), PyObject *args) |