| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent aba24ff commit a6fdddb
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + Fixed error messages for :c:func:`PySequence_Size`, | ||
| 2 | + :c:func:`PySequence_GetItem`, :c:func:`PySequence_SetItem` and | ||
| 3 | + :c:func:`PySequence_DelItem` called with a mapping and | ||
| 4 | + :c:func:`PyMapping_Size` called with a sequence. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1531,6 +1531,10 @@ PySequence_Size(PyObject *s) | |||
| 1531 | 1531 | return len; | |
| 1532 | 1532 | } | |
| 1533 | 1533 | ||
| 1534 | + if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_length) { | ||
| 1535 | + type_error("%.200s is not a sequence", s); | ||
| 1536 | + return -1; | ||
| 1537 | + } | ||
| 1534 | 1538 | type_error("object of type '%.200s' has no len()", s); | |
| 1535 | 1539 | return -1; | |
| 1536 | 1540 | } | |
@@ -1677,6 +1681,9 @@ PySequence_GetItem(PyObject *s, Py_ssize_t i) | |||
| 1677 | 1681 | return m->sq_item(s, i); | |
| 1678 | 1682 | } | |
| 1679 | 1683 | ||
| 1684 | + if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_subscript) { | ||
| 1685 | + return type_error("%.200s is not a sequence", s); | ||
| 1686 | + } | ||
| 1680 | 1687 | return type_error("'%.200s' object does not support indexing", s); | |
| 1681 | 1688 | } | |
| 1682 | 1689 | ||
@@ -1728,6 +1735,10 @@ PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o) | |||
| 1728 | 1735 | return m->sq_ass_item(s, i, o); | |
| 1729 | 1736 | } | |
| 1730 | 1737 | ||
| 1738 | + if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_ass_subscript) { | ||
| 1739 | + type_error("%.200s is not a sequence", s); | ||
| 1740 | + return -1; | ||
| 1741 | + } | ||
| 1731 | 1742 | type_error("'%.200s' object does not support item assignment", s); | |
| 1732 | 1743 | return -1; | |
| 1733 | 1744 | } | |
@@ -1757,6 +1768,10 @@ PySequence_DelItem(PyObject *s, Py_ssize_t i) | |||
| 1757 | 1768 | return m->sq_ass_item(s, i, (PyObject *)NULL); | |
| 1758 | 1769 | } | |
| 1759 | 1770 | ||
| 1771 | + if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_ass_subscript) { | ||
| 1772 | + type_error("%.200s is not a sequence", s); | ||
| 1773 | + return -1; | ||
| 1774 | + } | ||
| 1760 | 1775 | type_error("'%.200s' object doesn't support item deletion", s); | |
| 1761 | 1776 | return -1; | |
| 1762 | 1777 | } | |
@@ -2093,6 +2108,11 @@ PyMapping_Size(PyObject *o) | |||
| 2093 | 2108 | return len; | |
| 2094 | 2109 | } | |
| 2095 | 2110 | ||
| 2111 | + if (o->ob_type->tp_as_sequence && o->ob_type->tp_as_sequence->sq_length) { | ||
| 2112 | + type_error("%.200s is not a mapping", o); | ||
| 2113 | + return -1; | ||
| 2114 | + } | ||
| 2115 | + /* PyMapping_Size() can be called from PyObject_Size(). */ | ||
| 2096 | 2116 | type_error("object of type '%.200s' has no len()", o); | |
| 2097 | 2117 | return -1; | |
| 2098 | 2118 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments