Lookup a record value by its name. Return 0 on success, -2 if the * value was not found (with KeyError set), and -1 on all other errors. */
| 429 | * value was not found (with KeyError set), and -1 on all other errors. |
| 430 | */ |
| 431 | static item_by_name_result_t |
| 432 | record_item_by_name(ApgRecordObject *o, PyObject *item, PyObject **result) |
| 433 | { |
| 434 | PyObject *mapped; |
| 435 | PyObject *val; |
| 436 | Py_ssize_t i; |
| 437 | |
| 438 | mapped = PyObject_GetItem(o->desc->mapping, item); |
| 439 | if (mapped == NULL) { |
| 440 | goto noitem; |
| 441 | } |
| 442 | |
| 443 | if (!PyIndex_Check(mapped)) { |
| 444 | Py_DECREF(mapped); |
| 445 | goto error; |
| 446 | } |
| 447 | |
| 448 | i = PyNumber_AsSsize_t(mapped, PyExc_IndexError); |
| 449 | Py_DECREF(mapped); |
| 450 | |
| 451 | if (i < 0) { |
| 452 | if (PyErr_Occurred()) |
| 453 | PyErr_Clear(); |
| 454 | goto error; |
| 455 | } |
| 456 | |
| 457 | val = record_item(o, i); |
| 458 | if (val == NULL) { |
| 459 | PyErr_Clear(); |
| 460 | goto error; |
| 461 | } |
| 462 | |
| 463 | *result = val; |
| 464 | |
| 465 | return APG_ITEM_FOUND; |
| 466 | |
| 467 | noitem: |
| 468 | PyErr_SetObject(PyExc_KeyError, item); |
| 469 | return APG_ITEM_NOT_FOUND; |
| 470 | |
| 471 | error: |
| 472 | PyErr_SetString(PyExc_RuntimeError, "invalid record descriptor"); |
| 473 | return APG_ERROR; |
| 474 | } |
| 475 | |
| 476 | static PyObject * |
| 477 | record_subscript(PyObject *op, PyObject *item) |
no test coverage detected