| 2018 | } |
| 2019 | |
| 2020 | static PyObject * |
| 2021 | array_setstate(PyArrayObject *self, PyObject *args) |
| 2022 | { |
| 2023 | PyObject *shape; |
| 2024 | PyArray_Descr *typecode; |
| 2025 | int version = 1; |
| 2026 | int is_f_order; |
| 2027 | PyObject *rawdata = NULL; |
| 2028 | char *datastr; |
| 2029 | Py_ssize_t len; |
| 2030 | npy_intp dimensions[NPY_MAXDIMS]; |
| 2031 | int nd; |
| 2032 | npy_intp nbytes; |
| 2033 | int overflowed; |
| 2034 | |
| 2035 | PyArrayObject_fields *fa = (PyArrayObject_fields *)self; |
| 2036 | |
| 2037 | /* This will free any memory associated with a and |
| 2038 | use the string in setstate as the (writeable) memory. |
| 2039 | */ |
| 2040 | if (!PyArg_ParseTuple(args, "(iO!O!iO):__setstate__", |
| 2041 | &version, |
| 2042 | &PyTuple_Type, &shape, |
| 2043 | &PyArrayDescr_Type, &typecode, |
| 2044 | &is_f_order, |
| 2045 | &rawdata)) { |
| 2046 | PyErr_Clear(); |
| 2047 | version = 0; |
| 2048 | if (!PyArg_ParseTuple(args, "(O!O!iO):__setstate__", |
| 2049 | &PyTuple_Type, &shape, |
| 2050 | &PyArrayDescr_Type, &typecode, |
| 2051 | &is_f_order, |
| 2052 | &rawdata)) { |
| 2053 | return NULL; |
| 2054 | } |
| 2055 | } |
| 2056 | |
| 2057 | /* If we ever need another pickle format, increment the version |
| 2058 | number. But we should still be able to handle the old versions. |
| 2059 | We've only got one right now. */ |
| 2060 | if (version != 1 && version != 0) { |
| 2061 | PyErr_Format(PyExc_ValueError, |
| 2062 | "can't handle version %d of numpy.ndarray pickle", |
| 2063 | version); |
| 2064 | return NULL; |
| 2065 | } |
| 2066 | |
| 2067 | /* |
| 2068 | * Reassigning fa->descr messes with the reallocation strategy, |
| 2069 | * since fa could be a 0-d or scalar, and then |
| 2070 | * PyDataMem_UserFREE will be confused |
| 2071 | */ |
| 2072 | size_t n_tofree = PyArray_NBYTES(self); |
| 2073 | if (n_tofree == 0) { |
| 2074 | n_tofree = 1; |
| 2075 | } |
| 2076 | Py_XDECREF(PyArray_DESCR(self)); |
| 2077 | fa->descr = typecode; |
nothing calls this directly
no test coverage detected