# HG changeset patch # User Bram Moolenaar # Date 1613931303 -3600 # Node ID faca24acb37f67f89c5090a3a1055c6e30cb0ca2 # Parent 88faa03cdc6f13ddc54594cd15ace835f63907f5 patch 8.2.2538: crash when using Python list iterator Commit: https://github.com/vim/vim/commit/21578271bb717f7ab7b8728e9efa54c3b60ee7e4 Author: Bram Moolenaar Date: Sun Feb 21 19:12:47 2021 +0100 patch 8.2.2538: crash when using Python list iterator Problem: Crash when using Python list iterator. Solution: Increment the list reference count. (closes https://github.com/vim/vim/issues/7886) diff --git a/src/if_py_both.h b/src/if_py_both.h --- a/src/if_py_both.h +++ b/src/if_py_both.h @@ -2815,6 +2815,7 @@ typedef struct ListIterDestruct(listiterinfo_T *lii) { list_rem_watch(lii->list, &lii->lw); + list_unref(lii->list); PyMem_Free(lii); } @@ -2850,6 +2851,7 @@ ListIter(ListObject *self) list_add_watch(l, &lii->lw); lii->lw.lw_item = l->lv_first; lii->list = l; + ++l->lv_refcount; return IterNew(lii, (destructorfun) ListIterDestruct, (nextfun) ListIterNext, diff --git a/src/testdir/test_python3.vim b/src/testdir/test_python3.vim --- a/src/testdir/test_python3.vim +++ b/src/testdir/test_python3.vim @@ -574,6 +574,9 @@ func Test_python3_list() py3 ll[2] = 8 call assert_equal([1, 2, 8], l) + " iterating over list from Python + py3 print([x for x in vim.Function("getline")(1, 2)]) + " Using dict as an index call AssertException(['py3 ll[{}] = 10'], \ 'Vim(py3):TypeError: index must be int or slice, not dict') diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2538, +/**/ 2537, /**/ 2536,