| OLD | NEW |
| 1 /* bytes object implementation */ | 1 /* bytes object implementation */ |
| 2 | 2 |
| 3 #define PY_SSIZE_T_CLEAN | 3 #define PY_SSIZE_T_CLEAN |
| 4 | 4 |
| 5 #include "Python.h" | 5 #include "Python.h" |
| 6 | 6 |
| 7 #include "bytes_methods.h" | 7 #include "bytes_methods.h" |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 static Py_ssize_t | 10 static Py_ssize_t |
| (...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1560 *start = 0; | 1560 *start = 0; |
| 1561 } | 1561 } |
| 1562 | 1562 |
| 1563 Py_LOCAL_INLINE(Py_ssize_t) | 1563 Py_LOCAL_INLINE(Py_ssize_t) |
| 1564 bytes_find_internal(PyBytesObject *self, PyObject *args, int dir) | 1564 bytes_find_internal(PyBytesObject *self, PyObject *args, int dir) |
| 1565 { | 1565 { |
| 1566 PyObject *subobj; | 1566 PyObject *subobj; |
| 1567 const char *sub; | 1567 const char *sub; |
| 1568 Py_ssize_t sub_len; | 1568 Py_ssize_t sub_len; |
| 1569 Py_ssize_t start=0, end=PY_SSIZE_T_MAX; | 1569 Py_ssize_t start=0, end=PY_SSIZE_T_MAX; |
| 1570 PyObject *obj_start=Py_None, *obj_end=Py_None; | |
| 1571 | 1570 |
| 1572 if (!PyArg_ParseTuple(args, "O|OO:find/rfind/index/rindex", &subobj, | 1571 if (!stringlib_parse_args_finds("find/rfind/index/rindex", |
| 1573 &obj_start, &obj_end)) | 1572 args, &subobj, &start, &end)) |
| 1574 return -2; | |
| 1575 /* To support None in "start" and "end" arguments, meaning | |
| 1576 the same as if they were not passed. | |
| 1577 */ | |
| 1578 if (obj_start != Py_None) | |
| 1579 if (!_PyEval_SliceIndex(obj_start, &start)) | |
| 1580 return -2; | |
| 1581 if (obj_end != Py_None) | |
| 1582 if (!_PyEval_SliceIndex(obj_end, &end)) | |
| 1583 return -2; | 1573 return -2; |
| 1584 | 1574 |
| 1585 if (PyBytes_Check(subobj)) { | 1575 if (PyBytes_Check(subobj)) { |
| 1586 sub = PyBytes_AS_STRING(subobj); | 1576 sub = PyBytes_AS_STRING(subobj); |
| 1587 sub_len = PyBytes_GET_SIZE(subobj); | 1577 sub_len = PyBytes_GET_SIZE(subobj); |
| 1588 } | 1578 } |
| 1589 else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len)) | 1579 else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len)) |
| 1590 /* XXX - the "expected a character buffer object" is pretty | 1580 /* XXX - the "expected a character buffer object" is pretty |
| 1591 confusing for a non-expert. remap to something else ? */ | 1581 confusing for a non-expert. remap to something else ? */ |
| 1592 return -2; | 1582 return -2; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1819 as in slice notation."); | 1809 as in slice notation."); |
| 1820 | 1810 |
| 1821 static PyObject * | 1811 static PyObject * |
| 1822 bytes_count(PyBytesObject *self, PyObject *args) | 1812 bytes_count(PyBytesObject *self, PyObject *args) |
| 1823 { | 1813 { |
| 1824 PyObject *sub_obj; | 1814 PyObject *sub_obj; |
| 1825 const char *str = PyBytes_AS_STRING(self), *sub; | 1815 const char *str = PyBytes_AS_STRING(self), *sub; |
| 1826 Py_ssize_t sub_len; | 1816 Py_ssize_t sub_len; |
| 1827 Py_ssize_t start = 0, end = PY_SSIZE_T_MAX; | 1817 Py_ssize_t start = 0, end = PY_SSIZE_T_MAX; |
| 1828 | 1818 |
| 1829 if (!PyArg_ParseTuple(args, "O|O&O&:count", &sub_obj, | 1819 if (!stringlib_parse_args_finds("count", args, &sub_obj, &start, &end)) |
| 1830 _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) | |
| 1831 return NULL; | 1820 return NULL; |
| 1832 | 1821 |
| 1833 if (PyBytes_Check(sub_obj)) { | 1822 if (PyBytes_Check(sub_obj)) { |
| 1834 sub = PyBytes_AS_STRING(sub_obj); | 1823 sub = PyBytes_AS_STRING(sub_obj); |
| 1835 sub_len = PyBytes_GET_SIZE(sub_obj); | 1824 sub_len = PyBytes_GET_SIZE(sub_obj); |
| 1836 } | 1825 } |
| 1837 else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len)) | 1826 else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len)) |
| 1838 return NULL; | 1827 return NULL; |
| 1839 | 1828 |
| 1840 bytes_adjust_indices(&start, &end, PyBytes_GET_SIZE(self)); | 1829 bytes_adjust_indices(&start, &end, PyBytes_GET_SIZE(self)); |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2641 prefix can also be a tuple of bytes to try."); | 2630 prefix can also be a tuple of bytes to try."); |
| 2642 | 2631 |
| 2643 static PyObject * | 2632 static PyObject * |
| 2644 bytes_startswith(PyBytesObject *self, PyObject *args) | 2633 bytes_startswith(PyBytesObject *self, PyObject *args) |
| 2645 { | 2634 { |
| 2646 Py_ssize_t start = 0; | 2635 Py_ssize_t start = 0; |
| 2647 Py_ssize_t end = PY_SSIZE_T_MAX; | 2636 Py_ssize_t end = PY_SSIZE_T_MAX; |
| 2648 PyObject *subobj; | 2637 PyObject *subobj; |
| 2649 int result; | 2638 int result; |
| 2650 | 2639 |
| 2651 if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &subobj, | 2640 if (!stringlib_parse_args_finds("startswith", args, &subobj, &start, &end)) |
| 2652 _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) | |
| 2653 return NULL; | 2641 return NULL; |
| 2654 if (PyTuple_Check(subobj)) { | 2642 if (PyTuple_Check(subobj)) { |
| 2655 Py_ssize_t i; | 2643 Py_ssize_t i; |
| 2656 for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { | 2644 for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { |
| 2657 result = _bytes_tailmatch(self, | 2645 result = _bytes_tailmatch(self, |
| 2658 PyTuple_GET_ITEM(subobj, i), | 2646 PyTuple_GET_ITEM(subobj, i), |
| 2659 start, end, -1); | 2647 start, end, -1); |
| 2660 if (result == -1) | 2648 if (result == -1) |
| 2661 return NULL; | 2649 return NULL; |
| 2662 else if (result) { | 2650 else if (result) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2682 suffix can also be a tuple of bytes to try."); | 2670 suffix can also be a tuple of bytes to try."); |
| 2683 | 2671 |
| 2684 static PyObject * | 2672 static PyObject * |
| 2685 bytes_endswith(PyBytesObject *self, PyObject *args) | 2673 bytes_endswith(PyBytesObject *self, PyObject *args) |
| 2686 { | 2674 { |
| 2687 Py_ssize_t start = 0; | 2675 Py_ssize_t start = 0; |
| 2688 Py_ssize_t end = PY_SSIZE_T_MAX; | 2676 Py_ssize_t end = PY_SSIZE_T_MAX; |
| 2689 PyObject *subobj; | 2677 PyObject *subobj; |
| 2690 int result; | 2678 int result; |
| 2691 | 2679 |
| 2692 if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &subobj, | 2680 if (!stringlib_parse_args_finds("endswith", args, &subobj, &start, &end)) |
| 2693 _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) | |
| 2694 return NULL; | 2681 return NULL; |
| 2695 if (PyTuple_Check(subobj)) { | 2682 if (PyTuple_Check(subobj)) { |
| 2696 Py_ssize_t i; | 2683 Py_ssize_t i; |
| 2697 for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { | 2684 for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { |
| 2698 result = _bytes_tailmatch(self, | 2685 result = _bytes_tailmatch(self, |
| 2699 PyTuple_GET_ITEM(subobj, i), | 2686 PyTuple_GET_ITEM(subobj, i), |
| 2700 start, end, +1); | 2687 start, end, +1); |
| 2701 if (result == -1) | 2688 if (result == -1) |
| 2702 return NULL; | 2689 return NULL; |
| 2703 else if (result) { | 2690 else if (result) { |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3467 } | 3454 } |
| 3468 it = PyObject_GC_New(striterobject, &PyBytesIter_Type); | 3455 it = PyObject_GC_New(striterobject, &PyBytesIter_Type); |
| 3469 if (it == NULL) | 3456 if (it == NULL) |
| 3470 return NULL; | 3457 return NULL; |
| 3471 it->it_index = 0; | 3458 it->it_index = 0; |
| 3472 Py_INCREF(seq); | 3459 Py_INCREF(seq); |
| 3473 it->it_seq = (PyBytesObject *)seq; | 3460 it->it_seq = (PyBytesObject *)seq; |
| 3474 _PyObject_GC_TRACK(it); | 3461 _PyObject_GC_TRACK(it); |
| 3475 return (PyObject *)it; | 3462 return (PyObject *)it; |
| 3476 } | 3463 } |
| OLD | NEW |