@@ -18706,8 +18706,8 @@ static PyObject* match_get_starts_by_index(MatchObject* self, Py_ssize_t index)
18706
18706
if (!item)
18707
18707
goto error;
18708
18708
18709
- /* PyList_SET_ITEM borrows the reference. */
18710
- PyList_SET_ITEM (result, 0, item);
18709
+ /* PyList_SetItem borrows the reference. */
18710
+ PyList_SetItem (result, 0, item);
18711
18711
18712
18712
return result;
18713
18713
}
@@ -18726,8 +18726,8 @@ static PyObject* match_get_starts_by_index(MatchObject* self, Py_ssize_t index)
18726
18726
if (!item)
18727
18727
goto error;
18728
18728
18729
- /* PyList_SET_ITEM borrows the reference. */
18730
- PyList_SET_ITEM (result, i, item);
18729
+ /* PyList_SetItem borrows the reference. */
18730
+ PyList_SetItem (result, i, item);
18731
18731
}
18732
18732
18733
18733
return result;
@@ -18786,8 +18786,8 @@ static PyObject* match_get_ends_by_index(MatchObject* self, Py_ssize_t index) {
18786
18786
if (!item)
18787
18787
goto error;
18788
18788
18789
- /* PyList_SET_ITEM borrows the reference. */
18790
- PyList_SET_ITEM (result, 0, item);
18789
+ /* PyList_SetItem borrows the reference. */
18790
+ PyList_SetItem (result, 0, item);
18791
18791
18792
18792
return result;
18793
18793
}
@@ -18806,8 +18806,8 @@ static PyObject* match_get_ends_by_index(MatchObject* self, Py_ssize_t index) {
18806
18806
if (!item)
18807
18807
goto error;
18808
18808
18809
- /* PyList_SET_ITEM borrows the reference. */
18810
- PyList_SET_ITEM (result, i, item);
18809
+ /* PyList_SetItem borrows the reference. */
18810
+ PyList_SetItem (result, i, item);
18811
18811
}
18812
18812
18813
18813
return result;
@@ -18867,8 +18867,8 @@ static PyObject* match_get_spans_by_index(MatchObject* self, Py_ssize_t index)
18867
18867
if (!item)
18868
18868
goto error;
18869
18869
18870
- /* PyList_SET_ITEM borrows the reference. */
18871
- PyList_SET_ITEM (result, 0, item);
18870
+ /* PyList_SetItem borrows the reference. */
18871
+ PyList_SetItem (result, 0, item);
18872
18872
18873
18873
return result;
18874
18874
}
@@ -18888,8 +18888,8 @@ static PyObject* match_get_spans_by_index(MatchObject* self, Py_ssize_t index)
18888
18888
if (!item)
18889
18889
goto error;
18890
18890
18891
- /* PyList_SET_ITEM borrows the reference. */
18892
- PyList_SET_ITEM (result, i, item);
18891
+ /* PyList_SetItem borrows the reference. */
18892
+ PyList_SetItem (result, i, item);
18893
18893
}
18894
18894
18895
18895
return result;
@@ -18923,8 +18923,8 @@ static PyObject* match_get_captures_by_index(MatchObject* self, Py_ssize_t
18923
18923
if (!slice)
18924
18924
goto error;
18925
18925
18926
- /* PyList_SET_ITEM borrows the reference. */
18927
- PyList_SET_ITEM (result, 0, slice);
18926
+ /* PyList_SetItem borrows the reference. */
18927
+ PyList_SetItem (result, 0, slice);
18928
18928
18929
18929
return result;
18930
18930
}
@@ -18945,8 +18945,8 @@ static PyObject* match_get_captures_by_index(MatchObject* self, Py_ssize_t
18945
18945
if (!slice)
18946
18946
goto error;
18947
18947
18948
- /* PyList_SET_ITEM borrows the reference. */
18949
- PyList_SET_ITEM (result, i, slice);
18948
+ /* PyList_SetItem borrows the reference. */
18949
+ PyList_SetItem (result, i, slice);
18950
18950
}
18951
18951
18952
18952
return result;
@@ -19282,13 +19282,13 @@ static PyObject* match_groupdict(MatchObject* self, PyObject* args, PyObject*
19282
19282
if (!keys)
19283
19283
goto failed;
19284
19284
19285
- for (g = 0; g < PyList_GET_SIZE (keys); g++) {
19285
+ for (g = 0; g < PyList_Size (keys); g++) {
19286
19286
PyObject* key;
19287
19287
PyObject* value;
19288
19288
int status;
19289
19289
19290
- /* PyList_GET_ITEM borrows a reference. */
19291
- key = PyList_GET_ITEM (keys, g);
19290
+ /* PyList_GetItem borrows a reference. */
19291
+ key = PyList_GetItem (keys, g);
19292
19292
if (!key)
19293
19293
goto failed;
19294
19294
@@ -19326,14 +19326,14 @@ static PyObject* match_capturesdict(MatchObject* self) {
19326
19326
if (!keys)
19327
19327
goto failed;
19328
19328
19329
- for (g = 0; g < PyList_GET_SIZE (keys); g++) {
19329
+ for (g = 0; g < PyList_Size (keys); g++) {
19330
19330
PyObject* key;
19331
19331
Py_ssize_t group;
19332
19332
PyObject* captures;
19333
19333
int status;
19334
19334
19335
- /* PyList_GET_ITEM borrows a reference. */
19336
- key = PyList_GET_ITEM (keys, g);
19335
+ /* PyList_GetItem borrows a reference. */
19336
+ key = PyList_GetItem (keys, g);
19337
19337
if (!key)
19338
19338
goto failed;
19339
19339
@@ -19509,12 +19509,12 @@ Py_LOCAL_INLINE(int) add_to_join_list(RE_JoinInfo* join_info, PyObject* item) {
19509
19509
goto error;
19510
19510
}
19511
19511
19512
- /* PyList_SET_ITEM borrows the reference. */
19513
- PyList_SET_ITEM (join_info->list, 0, join_info->item);
19512
+ /* PyList_SetItem borrows the reference. */
19513
+ PyList_SetItem (join_info->list, 0, join_info->item);
19514
19514
join_info->item = NULL;
19515
19515
19516
- /* PyList_SET_ITEM borrows the reference. */
19517
- PyList_SET_ITEM (join_info->list, 1, new_item);
19516
+ /* PyList_SetItem borrows the reference. */
19517
+ PyList_SetItem (join_info->list, 1, new_item);
19518
19518
return 0;
19519
19519
}
19520
19520
@@ -19535,38 +19535,78 @@ Py_LOCAL_INLINE(void) clear_join_list(RE_JoinInfo* join_info) {
19535
19535
Py_XDECREF(join_info->item);
19536
19536
}
19537
19537
19538
+ /* Joins a list of bytestrings. */
19539
+ Py_LOCAL_INLINE(PyObject*) join_bytestrings(PyObject* list) {
19540
+ Py_ssize_t count;
19541
+ Py_ssize_t length;
19542
+ Py_ssize_t i;
19543
+ PyObject *result;
19544
+ char* to_bytes;
19545
+
19546
+ count = PyList_Size(list);
19547
+
19548
+ /* How long will the result be? */
19549
+ length = 0;
19550
+
19551
+ for (i = 0; i < count; i++)
19552
+ length += PyBytes_Size(PyList_GetItem(list, i));
19553
+
19554
+ /* Create the resulting bytestring, but uninitialised. */
19555
+ result = PyBytes_FromStringAndSize(NULL, length);
19556
+ if (!result)
19557
+ return NULL;
19558
+
19559
+ /* Fill the resulting bytestring. */
19560
+ to_bytes = PyBytes_AsString(result);
19561
+ length = 0;
19562
+
19563
+ for (i = 0; i < count; i++) {
19564
+ PyObject* bytestring;
19565
+ char* from_bytes;
19566
+ Py_ssize_t from_length;
19567
+
19568
+ bytestring = PyList_GetItem(list, i);
19569
+ from_bytes = PyBytes_AsString(bytestring);
19570
+ from_length = PyBytes_Size(bytestring);
19571
+ memmove(to_bytes + length, from_bytes, from_length);
19572
+ length += from_length;
19573
+ }
19574
+
19575
+ return result;
19576
+ }
19577
+
19578
+ /* Joins a list of strings. */
19579
+ Py_LOCAL_INLINE(PyObject*) join_strings(PyObject* list) {
19580
+ PyObject* joiner;
19581
+ PyObject* result;
19582
+
19583
+ joiner = PyUnicode_FromString("");
19584
+ if (!joiner)
19585
+ return NULL;
19586
+
19587
+ result = PyUnicode_Join(joiner, list);
19588
+ Py_DECREF(joiner);
19589
+
19590
+ return result;
19591
+ }
19592
+
19538
19593
/* Joins together a list of strings for pattern_subx. */
19539
19594
Py_LOCAL_INLINE(PyObject*) join_list_info(RE_JoinInfo* join_info) {
19540
19595
/* If the list already exists then just do the join. */
19541
19596
if (join_info->list) {
19542
- PyObject* joiner;
19543
19597
PyObject* result;
19544
19598
19545
19599
if (join_info->reversed)
19546
19600
/* The list needs to be reversed before being joined. */
19547
19601
PyList_Reverse(join_info->list);
19548
19602
19549
- if (join_info->is_unicode) {
19603
+ if (join_info->is_unicode)
19550
19604
/* Concatenate the Unicode strings. */
19551
- joiner = PyUnicode_New(0, 0);
19552
- if (!joiner) {
19553
- clear_join_list(join_info);
19554
- return NULL;
19555
- }
19556
-
19557
- result = PyUnicode_Join(joiner, join_info->list);
19558
- } else {
19559
- joiner = PyBytes_FromString("");
19560
- if (!joiner) {
19561
- clear_join_list(join_info);
19562
- return NULL;
19563
- }
19564
-
19605
+ result = join_strings(join_info->list);
19606
+ else
19565
19607
/* Concatenate the bytestrings. */
19566
- result = _PyBytes_Join(joiner, join_info->list);
19567
- }
19608
+ result = join_bytestrings(join_info->list);
19568
19609
19569
- Py_DECREF(joiner);
19570
19610
clear_join_list(join_info);
19571
19611
19572
19612
return result;
@@ -19651,13 +19691,13 @@ static PyObject* match_expand(MatchObject* self, PyObject* str_template) {
19651
19691
init_join_list(&join_info, FALSE, PyUnicode_Check(self->string));
19652
19692
19653
19693
/* Add each part of the template to the list. */
19654
- size = PyList_GET_SIZE (replacement);
19694
+ size = PyList_Size (replacement);
19655
19695
for (i = 0; i < size; i++) {
19656
19696
PyObject* item;
19657
19697
PyObject* str_item;
19658
19698
19659
- /* PyList_GET_ITEM borrows a reference. */
19660
- item = PyList_GET_ITEM (replacement, i);
19699
+ /* PyList_GetItem borrows a reference. */
19700
+ item = PyList_GetItem (replacement, i);
19661
19701
str_item = get_match_replacement(self, item, self->group_count);
19662
19702
if (!str_item)
19663
19703
goto error;
@@ -19727,19 +19767,19 @@ Py_LOCAL_INLINE(PyObject*) make_capture_dict(MatchObject* match, MatchObject**
19727
19767
if (!values)
19728
19768
goto failed;
19729
19769
19730
- for (g = 0; g < PyList_GET_SIZE (keys); g++) {
19770
+ for (g = 0; g < PyList_Size (keys); g++) {
19731
19771
PyObject* key;
19732
19772
PyObject* value;
19733
19773
Py_ssize_t v;
19734
19774
int status;
19735
19775
19736
- /* PyList_GET_ITEM borrows a reference. */
19737
- key = PyList_GET_ITEM (keys, g);
19776
+ /* PyList_GetItem borrows a reference. */
19777
+ key = PyList_GetItem (keys, g);
19738
19778
if (!key)
19739
19779
goto failed;
19740
19780
19741
- /* PyList_GET_ITEM borrows a reference. */
19742
- value = PyList_GET_ITEM (values, g);
19781
+ /* PyList_GetItem borrows a reference. */
19782
+ value = PyList_GetItem (values, g);
19743
19783
if (!value)
19744
19784
goto failed;
19745
19785
@@ -21742,7 +21782,7 @@ Py_LOCAL_INLINE(PyObject*) pattern_subx(PatternObject* self, PyObject*
21742
21782
Py_ssize_t step;
21743
21783
21744
21784
/* Add each part of the template to the list. */
21745
- count = PyList_GET_SIZE (replacement);
21785
+ count = PyList_Size (replacement);
21746
21786
if (join_info.reversed) {
21747
21787
/* We're searching backwards, so we'll be reversing the list
21748
21788
* when it's complete. Therefore, we need to add the items of
@@ -21761,8 +21801,8 @@ Py_LOCAL_INLINE(PyObject*) pattern_subx(PatternObject* self, PyObject*
21761
21801
PyObject* item;
21762
21802
PyObject* str_item;
21763
21803
21764
- /* PyList_GET_ITEM borrows a reference. */
21765
- item = PyList_GET_ITEM (replacement, index);
21804
+ /* PyList_GetItem borrows a reference. */
21805
+ item = PyList_GetItem (replacement, index);
21766
21806
str_item = get_sub_replacement(item, string, &state,
21767
21807
self->public_group_count);
21768
21808
if (!str_item)
@@ -25719,7 +25759,7 @@ static PyObject* re_compile(PyObject* self_, PyObject* args) {
25719
25759
unpacked = FALSE;
25720
25760
25721
25761
/* Read the regex code. */
25722
- code_len = PyList_GET_SIZE (code_list);
25762
+ code_len = PyList_Size (code_list);
25723
25763
code = (RE_CODE*)re_alloc((size_t)code_len * sizeof(RE_CODE));
25724
25764
if (!code) {
25725
25765
if (unpacked) {
@@ -25733,8 +25773,8 @@ static PyObject* re_compile(PyObject* self_, PyObject* args) {
25733
25773
PyObject* o;
25734
25774
size_t value;
25735
25775
25736
- /* PyList_GET_ITEM borrows a reference. */
25737
- o = PyList_GET_ITEM (code_list, i);
25776
+ /* PyList_GetItem borrows a reference. */
25777
+ o = PyList_GetItem (code_list, i);
25738
25778
25739
25779
value = PyLong_AsUnsignedLong(o);
25740
25780
if ((Py_ssize_t)value == -1 && PyErr_Occurred())
0 commit comments