Convert a bytestring specification into a dtype */
| 1722 | |
| 1723 | /** Convert a bytestring specification into a dtype */ |
| 1724 | static PyArray_Descr * |
| 1725 | _convert_from_str(PyObject *obj, int align) |
| 1726 | { |
| 1727 | /* Check for a string typecode. */ |
| 1728 | Py_ssize_t len = 0; |
| 1729 | char const *type = PyUnicode_AsUTF8AndSize(obj, &len); |
| 1730 | if (type == NULL) { |
| 1731 | return NULL; |
| 1732 | } |
| 1733 | |
| 1734 | /* Empty string is invalid */ |
| 1735 | if (len == 0) { |
| 1736 | goto fail; |
| 1737 | } |
| 1738 | |
| 1739 | /* check for commas present or first (or second) element a digit */ |
| 1740 | if (_check_for_commastring(type, len)) { |
| 1741 | return _convert_from_commastring(obj, align); |
| 1742 | } |
| 1743 | |
| 1744 | /* Process the endian character. '|' is replaced by '='*/ |
| 1745 | char endian = '='; |
| 1746 | switch (type[0]) { |
| 1747 | case '>': |
| 1748 | case '<': |
| 1749 | case '=': |
| 1750 | endian = type[0]; |
| 1751 | ++type; |
| 1752 | --len; |
| 1753 | break; |
| 1754 | |
| 1755 | case '|': |
| 1756 | endian = '='; |
| 1757 | ++type; |
| 1758 | --len; |
| 1759 | break; |
| 1760 | } |
| 1761 | |
| 1762 | /* Just an endian character is invalid */ |
| 1763 | if (len == 0) { |
| 1764 | goto fail; |
| 1765 | } |
| 1766 | |
| 1767 | /* Check for datetime format */ |
| 1768 | if (is_datetime_typestr(type, len)) { |
| 1769 | PyArray_Descr *ret = parse_dtype_from_datetime_typestr(type, len); |
| 1770 | if (ret == NULL) { |
| 1771 | return NULL; |
| 1772 | } |
| 1773 | /* ret has byte order '=' at this point */ |
| 1774 | if (!PyArray_ISNBO(endian)) { |
| 1775 | ret->byteorder = endian; |
| 1776 | } |
| 1777 | return ret; |
| 1778 | } |
| 1779 | |
| 1780 | int check_num = NPY_NOTYPE + 10; |
| 1781 | int elsize = 0; |
no test coverage detected