summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-08-17 15:55:51 +0100
committerBram Moolenaar <Bram@vim.org>2022-08-17 15:55:51 +0100
commit4875d6ab068f09df88d24d81de40dcd8d56e243d (patch)
tree6f5030128980ebdb9e61141621759b5540c45708
parent5fd6ab820b4a0aaa5c6020852f39d118375fab49 (diff)
patch 9.0.0224: Using NULL pointer when skipping compiled codev9.0.0224
Problem: Using NULL pointer when skipping compiled code. Solution: Check for skipping.
-rw-r--r--src/testdir/test_vim9_script.vim13
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c14
3 files changed, 25 insertions, 4 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 3199ac3953..56a39efcf7 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -2097,6 +2097,19 @@ def Test_for_skipped_block()
v9.CheckDefAndScriptSuccess(lines)
enddef
+def Test_skipped_redir()
+ var lines =<< trim END
+ def T()
+ if 0
+ redir =>l[0]
+ redir END
+ endif
+ enddef
+ defcompile
+ END
+ v9.CheckScriptSuccess(lines)
+enddef
+
def Test_for_loop()
var lines =<< trim END
var result = ''
diff --git a/src/version.c b/src/version.c
index 1566e4dfcf..e477f9e315 100644
--- a/src/version.c
+++ b/src/version.c
@@ -732,6 +732,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 224,
+/**/
223,
/**/
222,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index d1e2c87fd8..d8596e99ef 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1165,11 +1165,14 @@ generate_loadvar(
generate_LOADV(cctx, name + 2);
break;
case dest_local:
- if (lvar->lv_from_outer > 0)
- generate_LOADOUTER(cctx, lvar->lv_idx, lvar->lv_from_outer,
+ if (cctx->ctx_skip != SKIP_YES)
+ {
+ if (lvar->lv_from_outer > 0)
+ generate_LOADOUTER(cctx, lvar->lv_idx, lvar->lv_from_outer,
type);
- else
- generate_LOAD(cctx, ISN_LOAD, lvar->lv_idx, NULL, type);
+ else
+ generate_LOAD(cctx, ISN_LOAD, lvar->lv_idx, NULL, type);
+ }
break;
case dest_expr:
// list or dict value should already be on the stack.
@@ -1952,6 +1955,9 @@ compile_assign_unlet(
}
}
+ if (cctx->ctx_skip == SKIP_YES)
+ return OK;
+
// Load the dict or list. On the stack we then have:
// - value (for assignment, not for :unlet)
// - index
bal scope dictionary
vim.VAR_SCOPE Other scope dictionary
2. if expression evaluates to a function reference, then it returns
- callable vimfunction object. Use self keyword argument to assign
+ callable vim.Function object. Use self keyword argument to assign
|self| object for dictionary functions.
Note: this function has the same behavior as |lua-eval| (except that
@@ -205,6 +207,10 @@ vim.bindeval(str) *python-bindeval*
relying on outputs of vim.eval() being a copy of original or
vim.eval("1") returning a string.
+ You can use "List", "Dictionary" and "Function" vim module attributes
+ to test whether object has given type. These types are currently not
+ subclassable, neither they contain constructors, so you can use them
+ only for checks like `isinstance(obj, vim.List)`.
Error object of the "vim" module
@@ -302,6 +308,9 @@ vim.options *python-options*
buffer-local options and |python-window| objects to access to
window-local options.
+ Type of this object is available via "Options" attribute of vim
+ module.
+
Output from Python *python-output*
Vim displays all Python code output in the Vim message area. Normal
output appears as information messages, and error output appears as
@@ -371,6 +380,8 @@ Note that when adding a line it must not contain a line break character '\n'.
A trailing '\n' is allowed and ignored, so that you can do: >
:py b.append(f.readlines())
+Buffer object type is available using "Buffer" attribute of vim module.
+
Examples (assume b is the current buffer) >
:py print b.name # write the buffer file name
:py b[0] = "hello!!!" # replace the top line
@@ -412,6 +423,8 @@ The range object methods are:
for Python's built-in list objects.
r.append(list, nr) Idem, after line "nr"
+Range object type is available using "Range" attribute of vim module.
+
Example (assume r is the current range):
# Send all lines in a range to the default printer
vim.command("%d,%dhardcopy!" % (r.start+1,r.end+1))
@@ -456,6 +469,8 @@ Window attributes are:
The height attribute is writable only if the screen is split horizontally.
The width attribute is writable only if the screen is split vertically.
+Window object type is available using "Window" attribute of vim module.
+
==============================================================================
6. Tab page objects *python-tabpage*
@@ -474,14 +489,16 @@ Tab page attributes are:
vars The tab page |t:| variables.
window Current tabpage window.
+TabPage object type is available using "TabPage" attribute of vim module.
+
==============================================================================
-6. pyeval() and py3eval() Vim functions *python-pyeval*
+7. pyeval() and py3eval() Vim functions *python-pyeval*
To facilitate bi-directional interface, you can use |pyeval()| and |py3eval()|
functions to evaluate Python expressions and pass their values to VimL.
==============================================================================
-7. Dynamic loading *python-dynamic*
+8. Dynamic loading *python-dynamic*
On MS-Windows the Python library can be loaded dynamically. The |:version|
output then includes |+python/dyn|.
@@ -498,7 +515,7 @@ Currently the name is "python24.dll". That is for Python 2.4. To know for
sure edit "gvim.exe" and search for "python\d*.dll\c".
==============================================================================
-8. Python 3 *python3*
+9. Python 3 *python3*
*:py3* *:python3*
The `:py3` and `:python3` commands work similar to `:python`. A simple check
diff --git a/src/if_py_both.h b/src/if_py_both.h
index 09bb0c060e..957d6d5cd8 100644
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -4245,6 +4245,15 @@ static struct object_constant {
{"windows", (PyObject *)(void *)&TheWindowList},
{"tabpages", (PyObject *)(void *)&TheTabPageList},
{"current", (PyObject *)(void *)&TheCurrent},
+
+ {"Buffer", (PyObject *)&BufferType},
+ {"Range", (PyObject *)&RangeType},
+ {"Window", (PyObject *)&WindowType},
+ {"TabPage", (PyObject *)&TabPageType},
+ {"Dictionary", (PyObject *)&DictionaryType},
+ {"List", (PyObject *)&ListType},
+ {"Function", (PyObject *)&FunctionType},
+ {"Options", (PyObject *)&OptionsType},
};
typedef int (*object_adder)(PyObject *, const char *, PyObject *);
diff --git a/src/testdir/test86.in b/src/testdir/test86.in
index 6a10bd7c20..c49eb3bade 100644
--- a/src/testdir/test86.in
+++ b/src/testdir/test86.in
@@ -631,10 +631,26 @@ cb.append('Current buffer: ' + repr(vim.current.buffer))
cb.append('Current line: ' + repr(vim.current.line))
for b in vim.buffers:
if b is not cb:
- vim.command('bwipeout! ' + b.number)
+ vim.command('bwipeout! ' + str(b.number))
EOF
:tabonly!
:only!
+:"
+:" Test types
+py << EOF
+for expr, attr in (
+ ('vim.vars', 'Dictionary'),
+ ('vim.options', 'Options'),
+ ('vim.bindeval("{}")', 'Dictionary'),
+ ('vim.bindeval("[]")', 'List'),
+ ('vim.bindeval("function(\'tr\')")', 'Function'),
+ ('vim.current.buffer', 'Buffer'),
+ ('vim.current.range', 'Range'),
+ ('vim.current.window', 'Window'),
+ ('vim.current.tabpage', 'TabPage'),
+):
+ cb.append(expr + ':' + attr + ':' + repr(type(eval(expr)) is getattr(vim, attr)))
+EOF
:endfun
:"
:call Test()
diff --git a/src/testdir/test86.ok b/src/testdir/test86.ok
index 8defc5a0c7..c91f741a05 100644
--- a/src/testdir/test86.ok
+++ b/src/testdir/test86.ok
@@ -333,7 +333,7 @@ Number of tabs: 4
Current tab pages:
<tabpage 0>(1): 1 windows, current is <window object (unknown)>
Windows:
- <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor is at (954, 0)
+ <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor is at (970, 0)
<tabpage 1>(2): 1 windows, current is <window object (unknown)>
Windows:
<window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
@@ -359,3 +359,12 @@ Current tab page: <tabpage 2>
Current window: <window 0>
Current buffer: <buffer test86.in>
Current line: 'Type error at assigning None to vim.current.buffer'
+vim.vars:Dictionary:True
+vim.options:Options:True
+vim.bindeval("{}"):Dictionary:True
+vim.bindeval("[]"):List:True
+vim.bindeval("function('tr')"):Function:True
+vim.current.buffer:Buffer:True
+vim.current.range:Range:True
+vim.current.window:Window:True
+vim.current.tabpage:TabPage:True
diff --git a/src/testdir/test87.in b/src/testdir/test87.in
index c7f092040d..94c1ab5357 100644
--- a/src/testdir/test87.in
+++ b/src/testdir/test87.in
@@ -622,6 +622,22 @@ for b in vim.buffers:
EOF
:tabonly!
:only!
+:"
+:" Test types
+py3 << EOF
+for expr, attr in (
+ ('vim.vars', 'Dictionary'),
+ ('vim.options', 'Options'),
+ ('vim.bindeval("{}")', 'Dictionary'),
+ ('vim.bindeval("[]")', 'List'),
+ ('vim.bindeval("function(\'tr\')")', 'Function'),
+ ('vim.current.buffer', 'Buffer'),
+ ('vim.current.range', 'Range'),
+ ('vim.current.window', 'Window'),
+ ('vim.current.tabpage', 'TabPage'),
+):
+ cb.append(expr + ':' + attr + ':' + repr(type(eval(expr)) is getattr(vim, attr)))
+EOF
:endfun
:"
:call Test()
diff --git a/src/testdir/test87.ok b/src/testdir/test87.ok
index bee93f9fa3..08cd590e24 100644
--- a/src/testdir/test87.ok
+++ b/src/testdir/test87.ok
@@ -322,7 +322,7 @@ Number of tabs: 4
Current tab pages:
<tabpage 0>(1): 1 windows, current is <window object (unknown)>
Windows:
- <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor is at (930, 0)
+ <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor is at (946, 0)
<tabpage 1>(2): 1 windows, current is <window object (unknown)>
Windows:
<window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
@@ -348,3 +348,12 @@ Current tab page: <tabpage 2>
Current window: <window 0>
Current buffer: <buffer test87.in>
Current line: 'Type error at assigning None to vim.current.buffer'
+vim.vars:Dictionary:True
+vim.options:Options:True
+vim.bindeval("{}"):Dictionary:True
+vim.bindeval("[]"):List:True
+vim.bindeval("function('tr')"):Function:True
+vim.current.buffer:Buffer:True
+vim.current.range:Range:True
+vim.current.window:Window:True
+vim.current.tabpage:TabPage:True
diff --git a/src/version.c b/src/version.c
index 2349425f45..8171124272 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 996,
+/**/
995,
/**/
994,