* Return 0 if successful */
| 258 | * Return 0 if successful |
| 259 | */ |
| 260 | static int _PyArray_DescrHashImp(PyArray_Descr *descr, npy_hash_t *hash) |
| 261 | { |
| 262 | PyObject *l, *tl; |
| 263 | int st; |
| 264 | |
| 265 | l = PyList_New(0); |
| 266 | if (l == NULL) { |
| 267 | return -1; |
| 268 | } |
| 269 | |
| 270 | st = _array_descr_walk(descr, l); |
| 271 | if (st) { |
| 272 | Py_DECREF(l); |
| 273 | return -1; |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * Convert the list to tuple and compute the tuple hash using python |
| 278 | * builtin function |
| 279 | */ |
| 280 | tl = PyList_AsTuple(l); |
| 281 | Py_DECREF(l); |
| 282 | if (tl == NULL) |
| 283 | return -1; |
| 284 | |
| 285 | *hash = PyObject_Hash(tl); |
| 286 | Py_DECREF(tl); |
| 287 | if (*hash == -1) { |
| 288 | /* XXX: does PyObject_Hash set an exception on failure ? */ |
| 289 | #if 0 |
| 290 | PyErr_SetString(PyExc_SystemError, |
| 291 | "(Hash) Error while hashing final tuple"); |
| 292 | #endif |
| 293 | return -1; |
| 294 | } |
| 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | NPY_NO_EXPORT npy_hash_t |
| 300 | PyArray_DescrHash(PyObject* odescr) |
no test coverage detected