| 651 | */ |
| 652 | |
| 653 | static PyObject * |
| 654 | array_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds) |
| 655 | { |
| 656 | int own; |
| 657 | PyObject *file; |
| 658 | char *sep = ""; |
| 659 | char *format = ""; |
| 660 | static char *kwlist[] = {"file", "sep", "format", NULL}; |
| 661 | |
| 662 | if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss:tofile", kwlist, |
| 663 | &file, |
| 664 | &sep, |
| 665 | &format)) { |
| 666 | return NULL; |
| 667 | } |
| 668 | |
| 669 | file = NpyPath_PathlikeToFspath(file); |
| 670 | if (file == NULL) { |
| 671 | return NULL; |
| 672 | } |
| 673 | if (PyBytes_Check(file) || PyUnicode_Check(file)) { |
| 674 | Py_SETREF(file, npy_PyFile_OpenFile(file, "wb")); |
| 675 | if (file == NULL) { |
| 676 | return NULL; |
| 677 | } |
| 678 | own = 1; |
| 679 | } |
| 680 | else { |
| 681 | own = 0; |
| 682 | } |
| 683 | |
| 684 | int file_ret = PyArray_ToFileObject(self, file, sep, format); |
| 685 | int close_ret = 0; |
| 686 | |
| 687 | if (own) { |
| 688 | PyObject *err_type, *err_value, *err_traceback; |
| 689 | PyErr_Fetch(&err_type, &err_value, &err_traceback); |
| 690 | close_ret = npy_PyFile_CloseFile(file); |
| 691 | npy_PyErr_ChainExceptions(err_type, err_value, err_traceback); |
| 692 | } |
| 693 | |
| 694 | Py_DECREF(file); |
| 695 | |
| 696 | if (file_ret || close_ret) { |
| 697 | return NULL; |
| 698 | } |
| 699 | Py_RETURN_NONE; |
| 700 | } |
| 701 | |
| 702 | static PyObject * |
| 703 | array_toscalar(PyArrayObject *self, PyObject *args) |
nothing calls this directly
no test coverage detected