diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-08-29 12:57:16 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-08-29 12:57:16 +0200 |
commit | 423a85a11a9d3d658906aea715fed7fe6aa83cd8 (patch) | |
tree | e37cd64de2c0662552bba8ded601ebc3b00db093 /src/testdir | |
parent | b06a6d59d12dbd67d55b3c46f6e5547e9103c931 (diff) | |
download | vim-git-423a85a11a9d3d658906aea715fed7fe6aa83cd8.tar.gz |
patch 8.2.1538: Python: iteration over vim objects fails to keep referencev8.2.1538
Problem: Python: iteration over vim objects fails to keep reference.
Solution: Keep a reference for the object. (Paul Ollis, closes #6803,
closes #6806)
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/test_python3.vim | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/testdir/test_python3.vim b/src/testdir/test_python3.vim index 830fbba50..0885c9698 100644 --- a/src/testdir/test_python3.vim +++ b/src/testdir/test_python3.vim @@ -4,6 +4,15 @@ source check.vim CheckFeature python3 source shared.vim +func Create_vim_list() + return [1] +endfunction + +func Create_vim_dict() + return {'a': 1} +endfunction + + " This function should be called first. This sets up python functions used by " the other tests. func Test_AAA_python3_setup() @@ -3944,4 +3953,47 @@ func Test_python3_keyboard_interrupt() close! endfunc +" Regression: Iterator for a Vim object should hold a reference. +func Test_python3_iter_ref() + let g:list_iter_ref_count_increase = -1 + let g:dict_iter_ref_count_increase = -1 + let g:bufmap_iter_ref_count_increase = -1 + let g:options_iter_ref_count_increase = -1 + + py3 << trim EOF + import sys + import vim + + def test_python3_iter_ref(): + create_list = vim.Function('Create_vim_list') + v = create_list() + base_ref_count = sys.getrefcount(v) + for el in v: + vim.vars['list_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count + + create_dict = vim.Function('Create_vim_dict') + v = create_dict() + base_ref_count = sys.getrefcount(v) + for el in v: + vim.vars['dict_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count + + v = vim.buffers + base_ref_count = sys.getrefcount(v) + for el in v: + vim.vars['bufmap_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count + + v = vim.options + base_ref_count = sys.getrefcount(v) + for el in v: + vim.vars['options_iter_ref_count_increase'] = sys.getrefcount(v) - base_ref_count + + test_python3_iter_ref() + EOF + + call assert_equal(1, g:list_iter_ref_count_increase) + call assert_equal(1, g:dict_iter_ref_count_increase) + call assert_equal(1, g:bufmap_iter_ref_count_increase) + call assert_equal(1, g:options_iter_ref_count_increase) +endfunc + " vim: shiftwidth=2 sts=2 expandtab |