Skip to content

Commit 2157827

Browse files
committed
patch 8.2.2538: crash when using Python list iterator
Problem: Crash when using Python list iterator. Solution: Increment the list reference count. (closes #7886)
1 parent 027c4ab commit 2157827

3 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/if_py_both.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,6 +2815,7 @@ typedef struct
28152815
ListIterDestruct(listiterinfo_T *lii)
28162816
{
28172817
list_rem_watch(lii->list, &lii->lw);
2818+
list_unref(lii->list);
28182819
PyMem_Free(lii);
28192820
}
28202821

@@ -2850,6 +2851,7 @@ ListIter(ListObject *self)
28502851
list_add_watch(l, &lii->lw);
28512852
lii->lw.lw_item = l->lv_first;
28522853
lii->list = l;
2854+
++l->lv_refcount;
28532855

28542856
return IterNew(lii,
28552857
(destructorfun) ListIterDestruct, (nextfun) ListIterNext,

src/testdir/test_python3.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ func Test_python3_list()
574574
py3 ll[2] = 8
575575
call assert_equal([1, 2, 8], l)
576576

577+
" iterating over list from Python
578+
py3 print([x for x in vim.Function("getline")(1, 2)])
579+
577580
" Using dict as an index
578581
call AssertException(['py3 ll[{}] = 10'],
579582
\ 'Vim(py3):TypeError: index must be int or slice, not dict')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2538,
753755
/**/
754756
2537,
755757
/**/

0 commit comments

Comments
 (0)