]> granicus.if.org Git - vim/commitdiff
patch 8.2.2538: crash when using Python list iterator v8.2.2538
authorBram Moolenaar <Bram@vim.org>
Sun, 21 Feb 2021 18:12:47 +0000 (19:12 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 21 Feb 2021 18:12:47 +0000 (19:12 +0100)
Problem:    Crash when using Python list iterator.
Solution:   Increment the list reference count. (closes #7886)

src/if_py_both.h
src/testdir/test_python3.vim
src/version.c

index 2903b0ba9a1f42c3e8a5572d66acf0b9f8bb297b..9dbff1cbfb7fcf16d2b64174904c94087cdbc3f4 100644 (file)
@@ -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,
index 6afb76d9a17e003cda7791ec2e4f6fe0b2e2122f..58b6427f3ecf0e0254b37121dfdb5ba72713a623 100644 (file)
@@ -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')
index 8d29d52181691b6418f96dbad6e79b4db75316fa..a64037d4ca747d46f7f2d2391a1adbbb39487ba1 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2538,
 /**/
     2537,
 /**/