| OLD | NEW |
| 1 /* PyByteArray (bytearray) implementation */ | 1 /* PyByteArray (bytearray) implementation */ |
| 2 | 2 |
| 3 #define PY_SSIZE_T_CLEAN | 3 #define PY_SSIZE_T_CLEAN |
| 4 #include "Python.h" | 4 #include "Python.h" |
| 5 #include "structmember.h" | 5 #include "structmember.h" |
| 6 #include "bytes_methods.h" | 6 #include "bytes_methods.h" |
| 7 | 7 |
| 8 static PyByteArrayObject *nullbytes = NULL; | 8 static PyByteArrayObject *nullbytes = NULL; |
| 9 char _PyByteArray_empty_string[] = ""; | 9 char _PyByteArray_empty_string[] = ""; |
| 10 | 10 |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 | 1075 |
| 1076 | 1076 |
| 1077 Py_LOCAL_INLINE(Py_ssize_t) | 1077 Py_LOCAL_INLINE(Py_ssize_t) |
| 1078 bytearray_find_internal(PyByteArrayObject *self, PyObject *args, int dir) | 1078 bytearray_find_internal(PyByteArrayObject *self, PyObject *args, int dir) |
| 1079 { | 1079 { |
| 1080 PyObject *subobj; | 1080 PyObject *subobj; |
| 1081 Py_buffer subbuf; | 1081 Py_buffer subbuf; |
| 1082 Py_ssize_t start=0, end=PY_SSIZE_T_MAX; | 1082 Py_ssize_t start=0, end=PY_SSIZE_T_MAX; |
| 1083 Py_ssize_t res; | 1083 Py_ssize_t res; |
| 1084 | 1084 |
| 1085 if (!PyArg_ParseTuple(args, "O|O&O&:find/rfind/index/rindex", &subobj, | 1085 if (!stringlib_parse_args_finds("find/rfind/index/rindex", |
| 1086 _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) | 1086 args, &subobj, &start, &end)) |
| 1087 return -2; | 1087 return -2; |
| 1088 if (_getbuffer(subobj, &subbuf) < 0) | 1088 if (_getbuffer(subobj, &subbuf) < 0) |
| 1089 return -2; | 1089 return -2; |
| 1090 if (dir > 0) | 1090 if (dir > 0) |
| 1091 res = stringlib_find_slice( | 1091 res = stringlib_find_slice( |
| 1092 PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), | 1092 PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), |
| 1093 subbuf.buf, subbuf.len, start, end); | 1093 subbuf.buf, subbuf.len, start, end); |
| 1094 else | 1094 else |
| 1095 res = stringlib_rfind_slice( | 1095 res = stringlib_rfind_slice( |
| 1096 PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), | 1096 PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1126 | 1126 |
| 1127 static PyObject * | 1127 static PyObject * |
| 1128 bytearray_count(PyByteArrayObject *self, PyObject *args) | 1128 bytearray_count(PyByteArrayObject *self, PyObject *args) |
| 1129 { | 1129 { |
| 1130 PyObject *sub_obj; | 1130 PyObject *sub_obj; |
| 1131 const char *str = PyByteArray_AS_STRING(self); | 1131 const char *str = PyByteArray_AS_STRING(self); |
| 1132 Py_ssize_t start = 0, end = PY_SSIZE_T_MAX; | 1132 Py_ssize_t start = 0, end = PY_SSIZE_T_MAX; |
| 1133 Py_buffer vsub; | 1133 Py_buffer vsub; |
| 1134 PyObject *count_obj; | 1134 PyObject *count_obj; |
| 1135 | 1135 |
| 1136 if (!PyArg_ParseTuple(args, "O|O&O&:count", &sub_obj, | 1136 if (!stringlib_parse_args_finds("count", args, &sub_obj, &start, &end)) |
| 1137 _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) | |
| 1138 return NULL; | 1137 return NULL; |
| 1139 | 1138 |
| 1140 if (_getbuffer(sub_obj, &vsub) < 0) | 1139 if (_getbuffer(sub_obj, &vsub) < 0) |
| 1141 return NULL; | 1140 return NULL; |
| 1142 | 1141 |
| 1143 _adjust_indices(&start, &end, PyByteArray_GET_SIZE(self)); | 1142 _adjust_indices(&start, &end, PyByteArray_GET_SIZE(self)); |
| 1144 | 1143 |
| 1145 count_obj = PyLong_FromSsize_t( | 1144 count_obj = PyLong_FromSsize_t( |
| 1146 stringlib_count(str + start, end - start, vsub.buf, vsub.len) | 1145 stringlib_count(str + start, end - start, vsub.buf, vsub.len) |
| 1147 ); | 1146 ); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 prefix can also be a tuple of strings to try."); | 1284 prefix can also be a tuple of strings to try."); |
| 1286 | 1285 |
| 1287 static PyObject * | 1286 static PyObject * |
| 1288 bytearray_startswith(PyByteArrayObject *self, PyObject *args) | 1287 bytearray_startswith(PyByteArrayObject *self, PyObject *args) |
| 1289 { | 1288 { |
| 1290 Py_ssize_t start = 0; | 1289 Py_ssize_t start = 0; |
| 1291 Py_ssize_t end = PY_SSIZE_T_MAX; | 1290 Py_ssize_t end = PY_SSIZE_T_MAX; |
| 1292 PyObject *subobj; | 1291 PyObject *subobj; |
| 1293 int result; | 1292 int result; |
| 1294 | 1293 |
| 1295 if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &subobj, | 1294 if (!stringlib_parse_args_finds("startswith", args, &subobj, &start, &end)) |
| 1296 _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) | |
| 1297 return NULL; | 1295 return NULL; |
| 1298 if (PyTuple_Check(subobj)) { | 1296 if (PyTuple_Check(subobj)) { |
| 1299 Py_ssize_t i; | 1297 Py_ssize_t i; |
| 1300 for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { | 1298 for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { |
| 1301 result = _bytearray_tailmatch(self, | 1299 result = _bytearray_tailmatch(self, |
| 1302 PyTuple_GET_ITEM(subobj, i), | 1300 PyTuple_GET_ITEM(subobj, i), |
| 1303 start, end, -1); | 1301 start, end, -1); |
| 1304 if (result == -1) | 1302 if (result == -1) |
| 1305 return NULL; | 1303 return NULL; |
| 1306 else if (result) { | 1304 else if (result) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1325 suffix can also be a tuple of strings to try."); | 1323 suffix can also be a tuple of strings to try."); |
| 1326 | 1324 |
| 1327 static PyObject * | 1325 static PyObject * |
| 1328 bytearray_endswith(PyByteArrayObject *self, PyObject *args) | 1326 bytearray_endswith(PyByteArrayObject *self, PyObject *args) |
| 1329 { | 1327 { |
| 1330 Py_ssize_t start = 0; | 1328 Py_ssize_t start = 0; |
| 1331 Py_ssize_t end = PY_SSIZE_T_MAX; | 1329 Py_ssize_t end = PY_SSIZE_T_MAX; |
| 1332 PyObject *subobj; | 1330 PyObject *subobj; |
| 1333 int result; | 1331 int result; |
| 1334 | 1332 |
| 1335 if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &subobj, | 1333 if (!stringlib_parse_args_finds("endswith", args, &subobj, &start, &end)) |
| 1336 _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) | |
| 1337 return NULL; | 1334 return NULL; |
| 1338 if (PyTuple_Check(subobj)) { | 1335 if (PyTuple_Check(subobj)) { |
| 1339 Py_ssize_t i; | 1336 Py_ssize_t i; |
| 1340 for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { | 1337 for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { |
| 1341 result = _bytearray_tailmatch(self, | 1338 result = _bytearray_tailmatch(self, |
| 1342 PyTuple_GET_ITEM(subobj, i), | 1339 PyTuple_GET_ITEM(subobj, i), |
| 1343 start, end, +1); | 1340 start, end, +1); |
| 1344 if (result == -1) | 1341 if (result == -1) |
| 1345 return NULL; | 1342 return NULL; |
| 1346 else if (result) { | 1343 else if (result) { |
| (...skipping 1996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3343 } | 3340 } |
| 3344 it = PyObject_GC_New(bytesiterobject, &PyByteArrayIter_Type); | 3341 it = PyObject_GC_New(bytesiterobject, &PyByteArrayIter_Type); |
| 3345 if (it == NULL) | 3342 if (it == NULL) |
| 3346 return NULL; | 3343 return NULL; |
| 3347 it->it_index = 0; | 3344 it->it_index = 0; |
| 3348 Py_INCREF(seq); | 3345 Py_INCREF(seq); |
| 3349 it->it_seq = (PyByteArrayObject *)seq; | 3346 it->it_seq = (PyByteArrayObject *)seq; |
| 3350 _PyObject_GC_TRACK(it); | 3347 _PyObject_GC_TRACK(it); |
| 3351 return (PyObject *)it; | 3348 return (PyObject *)it; |
| 3352 } | 3349 } |
| OLD | NEW |