* This function is needed for supporting Pickles of * numpy scalar objects. */
| 2153 | * numpy scalar objects. |
| 2154 | */ |
| 2155 | static PyObject * |
| 2156 | array_scalar(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds) |
| 2157 | { |
| 2158 | |
| 2159 | static char *kwlist[] = {"dtype", "obj", NULL}; |
| 2160 | PyArray_Descr *typecode; |
| 2161 | PyObject *obj = NULL, *tmpobj = NULL; |
| 2162 | int alloc = 0; |
| 2163 | void *dptr; |
| 2164 | PyObject *ret; |
| 2165 | PyObject *base = NULL; |
| 2166 | |
| 2167 | if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|O:scalar", kwlist, |
| 2168 | &PyArrayDescr_Type, &typecode, &obj)) { |
| 2169 | return NULL; |
| 2170 | } |
| 2171 | if (PyDataType_FLAGCHK(typecode, NPY_LIST_PICKLE)) { |
| 2172 | if (typecode->type_num == NPY_OBJECT) { |
| 2173 | /* Deprecated 2020-11-24, NumPy 1.20 */ |
| 2174 | if (DEPRECATE( |
| 2175 | "Unpickling a scalar with object dtype is deprecated. " |
| 2176 | "Object scalars should never be created. If this was a " |
| 2177 | "properly created pickle, please open a NumPy issue. In " |
| 2178 | "a best effort this returns the original object.") < 0) { |
| 2179 | return NULL; |
| 2180 | } |
| 2181 | Py_INCREF(obj); |
| 2182 | return obj; |
| 2183 | } |
| 2184 | /* We store the full array to unpack it here: */ |
| 2185 | if (!PyArray_CheckExact(obj)) { |
| 2186 | /* We pickle structured voids as arrays currently */ |
| 2187 | PyErr_SetString(PyExc_RuntimeError, |
| 2188 | "Unpickling NPY_LIST_PICKLE (structured void) scalar " |
| 2189 | "requires an array. The pickle file may be corrupted?"); |
| 2190 | return NULL; |
| 2191 | } |
| 2192 | if (!PyArray_EquivTypes(PyArray_DESCR((PyArrayObject *)obj), typecode)) { |
| 2193 | PyErr_SetString(PyExc_RuntimeError, |
| 2194 | "Pickled array is not compatible with requested scalar " |
| 2195 | "dtype. The pickle file may be corrupted?"); |
| 2196 | return NULL; |
| 2197 | } |
| 2198 | base = obj; |
| 2199 | dptr = PyArray_BYTES((PyArrayObject *)obj); |
| 2200 | } |
| 2201 | |
| 2202 | else if (PyDataType_FLAGCHK(typecode, NPY_ITEM_IS_POINTER)) { |
| 2203 | if (obj == NULL) { |
| 2204 | obj = Py_None; |
| 2205 | } |
| 2206 | dptr = &obj; |
| 2207 | } |
| 2208 | else { |
| 2209 | if (obj == NULL) { |
| 2210 | if (typecode->elsize == 0) { |
| 2211 | typecode->elsize = 1; |
| 2212 | } |
nothing calls this directly
no test coverage detected