mirror of
https://github.com/neovim/neovim.git
synced 2025-10-12 04:46:10 +00:00
vim-patch:8.2.2343: Vim9: return type of readfile() is any (#20896)
Problem: Vim9: return type of readfile() is any.
Solution: Add readblob() so that readfile() can be expected to always
return a list of strings. (closes vim/vim#7671)
c423ad77ed
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -291,6 +291,7 @@ return {
|
||||
perleval={args=1, base=1},
|
||||
rand={args={0, 1}, base=1},
|
||||
range={args={1, 3}, base=1},
|
||||
readblob={args=1, base=1},
|
||||
readdir={args={1, 2}, base=1},
|
||||
readfile={args={1, 3}, base=1},
|
||||
reduce={args={2, 3}, base=1},
|
||||
|
@@ -5872,11 +5872,11 @@ static void f_readdir(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
ga_clear_strings(&ga);
|
||||
}
|
||||
|
||||
/// "readfile()" function
|
||||
static void f_readfile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
/// "readfile()" or "readblob()" function
|
||||
static void read_file_or_blob(typval_T *argvars, typval_T *rettv, bool always_blob)
|
||||
{
|
||||
bool binary = false;
|
||||
bool blob = false;
|
||||
bool blob = always_blob;
|
||||
FILE *fd;
|
||||
char buf[(IOSIZE/256) * 256]; // rounded to avoid odd + 1
|
||||
int io_size = sizeof(buf);
|
||||
@@ -6011,8 +6011,8 @@ static void f_readfile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
int adjust_prevlen = 0;
|
||||
|
||||
if (dest < buf) { // -V782
|
||||
adjust_prevlen = (int)(buf - dest); // -V782
|
||||
// adjust_prevlen must be 1 or 2.
|
||||
adjust_prevlen = (int)(buf - dest); // -V782
|
||||
dest = buf;
|
||||
}
|
||||
if (readlen > p - buf + 1) {
|
||||
@@ -6055,6 +6055,18 @@ static void f_readfile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
/// "readblob()" function
|
||||
static void f_readblob(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
read_file_or_blob(argvars, rettv, true);
|
||||
}
|
||||
|
||||
/// "readfile()" function
|
||||
static void f_readfile(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
read_file_or_blob(argvars, rettv, false);
|
||||
}
|
||||
|
||||
/// "getreginfo()" function
|
||||
static void f_getreginfo(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
|
@@ -851,9 +851,7 @@ func Test_mksession_shortmess_with_A()
|
||||
edit Xtestfile
|
||||
write
|
||||
let fname = swapname('%')
|
||||
" readblob() needs patch 8.2.2343
|
||||
" let cont = readblob(fname)
|
||||
let cont = readfile(fname, 'B')
|
||||
let cont = readblob(fname)
|
||||
set sessionoptions-=options
|
||||
mksession Xtestsession
|
||||
bwipe!
|
||||
|
Reference in New Issue
Block a user