Mercurial > vim
comparison src/testdir/test_python3.vim @ 21977:d1a7088c6efe v8.2.1538
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Commit: https://github.com/vim/vim/commit/423a85a11a9d3d658906aea715fed7fe6aa83cd8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 29 12:57:16 2020 +0200
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Problem: Python: iteration over vim objects fails to keep reference.
Solution: Keep a reference for the object. (Paul Ollis, closes https://github.com/vim/vim/issues/6803,
closes #6806)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 29 Aug 2020 13:00:04 +0200 |
parents | 6a4806e326dd |
children | 2b6d696b063d |
comparison
equal
deleted
inserted
replaced
21976:262d7ee2992c | 21977:d1a7088c6efe |
---|---|
1 " Test for python 3 commands. | 1 " Test for python 3 commands. |
2 | 2 |
3 source check.vim | 3 source check.vim |
4 CheckFeature python3 | 4 CheckFeature python3 |
5 source shared.vim | 5 source shared.vim |
6 | |
7 func Create_vim_list() | |
8 return [1] | |
9 endfunction | |
10 | |
11 func Create_vim_dict() | |
12 return {'a': 1} | |
13 endfunction | |
14 | |
6 | 15 |
7 " This function should be called first. This sets up python functions used by | 16 " This function should be called first. This sets up python functions used by |
8 " the other tests. | 17 " the other tests. |
9 func Test_AAA_python3_setup() | 18 func Test_AAA_python3_setup() |
10 py3 << trim EOF | 19 py3 << trim EOF |
3942 call assert_equal(expected, getline(2, '$')) | 3951 call assert_equal(expected, getline(2, '$')) |
3943 call assert_equal('', output) | 3952 call assert_equal('', output) |
3944 close! | 3953 close! |
3945 endfunc | 3954 endfunc |
3946 | 3955 |
3956 " Regression: Iterator for a Vim object should hold a reference. | |
3957 func Test_python3_iter_ref() | |
3958 let g:list_iter_ref_count_increase = -1 | |
3959 let g:dict_iter_ref_count_increase = -1 | |
3960 let g:bufmap_iter_ref_count_increase = -1 | |
3961 let g:options_iter_ref_count_increase = -1 | |
3962 | |
3963 py3 << trim EOF | |
3964 import sys | |
3965 import vim | |
3966 | |
3967 def test_python3_iter_ref(): | |
3968 create_list = vim.Function('Create_vim_list') | |
3969 v = create_list() | |
3970 base_ref_count = sys.getrefcount(v) | |
3971 for el in v: | |
3972 vim.vars['list_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count | |
3973 | |
3974 create_dict = vim.Function('Create_vim_dict') | |
3975 v = create_dict() | |
3976 base_ref_count = sys.getrefcount(v) | |
3977 for el in v: | |
3978 vim.vars['dict_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count | |
3979 | |
3980 v = vim.buffers | |
3981 base_ref_count = sys.getrefcount(v) | |
3982 for el in v: | |
3983 vim.vars['bufmap_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count | |
3984 | |
3985 v = vim.options | |
3986 base_ref_count = sys.getrefcount(v) | |
3987 for el in v: | |
3988 vim.vars['options_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count | |
3989 | |
3990 test_python3_iter_ref() | |
3991 EOF | |
3992 | |
3993 call assert_equal(1, g:list_iter_ref_count_increase) | |
3994 call assert_equal(1, g:dict_iter_ref_count_increase) | |
3995 call assert_equal(1, g:bufmap_iter_ref_count_increase) | |
3996 call assert_equal(1, g:options_iter_ref_count_increase) | |
3997 endfunc | |
3998 | |
3947 " vim: shiftwidth=2 sts=2 expandtab | 3999 " vim: shiftwidth=2 sts=2 expandtab |