| 1813 | |
| 1814 | |
| 1815 | static PyObject * |
| 1816 | array_reduce(PyArrayObject *self, PyObject *NPY_UNUSED(args)) |
| 1817 | { |
| 1818 | /* version number of this pickle type. Increment if we need to |
| 1819 | change the format. Be sure to handle the old versions in |
| 1820 | array_setstate. */ |
| 1821 | const int version = 1; |
| 1822 | PyObject *ret = NULL, *state = NULL, *obj = NULL, *mod = NULL; |
| 1823 | PyObject *mybool, *thestr = NULL; |
| 1824 | PyArray_Descr *descr; |
| 1825 | |
| 1826 | /* Return a tuple of (callable object, arguments, object's state) */ |
| 1827 | /* We will put everything in the object's state, so that on UnPickle |
| 1828 | it can use the string object as memory without a copy */ |
| 1829 | |
| 1830 | ret = PyTuple_New(3); |
| 1831 | if (ret == NULL) { |
| 1832 | return NULL; |
| 1833 | } |
| 1834 | mod = PyImport_ImportModule("numpy.core._multiarray_umath"); |
| 1835 | if (mod == NULL) { |
| 1836 | Py_DECREF(ret); |
| 1837 | return NULL; |
| 1838 | } |
| 1839 | obj = PyObject_GetAttrString(mod, "_reconstruct"); |
| 1840 | Py_DECREF(mod); |
| 1841 | PyTuple_SET_ITEM(ret, 0, obj); |
| 1842 | PyTuple_SET_ITEM(ret, 1, |
| 1843 | Py_BuildValue("ONc", |
| 1844 | (PyObject *)Py_TYPE(self), |
| 1845 | Py_BuildValue("(N)", |
| 1846 | PyLong_FromLong(0)), |
| 1847 | /* dummy data-type */ |
| 1848 | 'b')); |
| 1849 | |
| 1850 | /* Now fill in object's state. This is a tuple with |
| 1851 | 5 arguments |
| 1852 | |
| 1853 | 1) an integer with the pickle version. |
| 1854 | 2) a Tuple giving the shape |
| 1855 | 3) a PyArray_Descr Object (with correct bytorder set) |
| 1856 | 4) a npy_bool stating if Fortran or not |
| 1857 | 5) a Python object representing the data (a string, or |
| 1858 | a list or any user-defined object). |
| 1859 | |
| 1860 | Notice because Python does not describe a mechanism to write |
| 1861 | raw data to the pickle, this performs a copy to a string first |
| 1862 | This issue is now addressed in protocol 5, where a buffer is serialized |
| 1863 | instead of a string, |
| 1864 | */ |
| 1865 | |
| 1866 | state = PyTuple_New(5); |
| 1867 | if (state == NULL) { |
| 1868 | Py_DECREF(ret); |
| 1869 | return NULL; |
| 1870 | } |
| 1871 | PyTuple_SET_ITEM(state, 0, PyLong_FromLong(version)); |
| 1872 | PyTuple_SET_ITEM(state, 1, PyObject_GetAttrString((PyObject *)self, |
nothing calls this directly
no test coverage detected