Checks safety of getfield for object arrays. As in _view_is_safe, we need to check that memory containing objects is not reinterpreted as a non-object datatype and vice versa. Parameters ---------- oldtype : data-type Data type of the original ndarray. newtype : da
(oldtype, newtype, offset)
| 491 | |
| 492 | |
| 493 | def _getfield_is_safe(oldtype, newtype, offset): |
| 494 | """ Checks safety of getfield for object arrays. |
| 495 | |
| 496 | As in _view_is_safe, we need to check that memory containing objects is not |
| 497 | reinterpreted as a non-object datatype and vice versa. |
| 498 | |
| 499 | Parameters |
| 500 | ---------- |
| 501 | oldtype : data-type |
| 502 | Data type of the original ndarray. |
| 503 | newtype : data-type |
| 504 | Data type of the field being accessed by ndarray.getfield |
| 505 | offset : int |
| 506 | Offset of the field being accessed by ndarray.getfield |
| 507 | |
| 508 | Raises |
| 509 | ------ |
| 510 | TypeError |
| 511 | If the field access is invalid |
| 512 | |
| 513 | """ |
| 514 | if newtype.hasobject or oldtype.hasobject: |
| 515 | if offset == 0 and newtype == oldtype: |
| 516 | return |
| 517 | if oldtype.names is not None: |
| 518 | for name in oldtype.names: |
| 519 | if (oldtype.fields[name][1] == offset and |
| 520 | oldtype.fields[name][0] == newtype): |
| 521 | return |
| 522 | raise TypeError("Cannot get/set field of an object array") |
| 523 | return |
| 524 | |
| 525 | def _view_is_safe(oldtype, newtype): |
| 526 | """ Checks safety of a view involving object arrays, for example when |
nothing calls this directly
no outgoing calls
no test coverage detected