main: Temporary fix assertion error

This variant uses `fdopen()` which is not standard, but it fixes problem on my 
system. In next commit `scriptin` will use `FileDescriptor*` from os/fileio in 
place of `FILE*`.
This commit is contained in:
ZyX
2017-03-19 16:09:48 +03:00
parent d2268d5ebb
commit fdfa1ed578
4 changed files with 90 additions and 1 deletions

View File

@@ -1057,7 +1057,9 @@ scripterror:
mch_exit(2); mch_exit(2);
} }
if (STRCMP(argv[0], "-") == 0) { if (STRCMP(argv[0], "-") == 0) {
scriptin[0] = stdin; const int stdin_dup_fd = os_dup(STDIN_FILENO);
FILE *const stdin_dup = fdopen(stdin_dup_fd, "r");
scriptin[0] = stdin_dup;
} else if ((scriptin[0] = mch_fopen(argv[0], READBIN)) == NULL) { } else if ((scriptin[0] = mch_fopen(argv[0], READBIN)) == NULL) {
mch_errmsg(_("Cannot open for reading: \"")); mch_errmsg(_("Cannot open for reading: \""));
mch_errmsg(argv[0]); mch_errmsg(argv[0]);

View File

@@ -430,6 +430,29 @@ int os_close(const int fd)
return r; return r;
} }
/// Duplicate file descriptor
///
/// @param[in] fd File descriptor to duplicate.
///
/// @return New file descriptor or libuv error code (< 0).
int os_dup(const int fd)
FUNC_ATTR_WARN_UNUSED_RESULT
{
int ret;
os_dup_dup:
ret = dup(fd);
if (ret < 0) {
const int error = os_translate_sys_error(errno);
errno = 0;
if (error == UV_EINTR) {
goto os_dup_dup;
} else {
return error;
}
}
return ret;
}
/// Read from a file /// Read from a file
/// ///
/// Handles EINTR and ENOMEM, but not other errors. /// Handles EINTR and ENOMEM, but not other errors.

View File

@@ -1,7 +1,9 @@
local lfs = require('lfs') local lfs = require('lfs')
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local eq = helpers.eq local eq = helpers.eq
local feed = helpers.feed
local clear = helpers.clear local clear = helpers.clear
local funcs = helpers.funcs local funcs = helpers.funcs
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
@@ -53,5 +55,51 @@ describe('Command-line option', function()
local attrs = lfs.attributes(fname) local attrs = lfs.attributes(fname)
eq(#('100500\n'), attrs.size) eq(#('100500\n'), attrs.size)
end) end)
it('does not crash after reading from stdin in non-headless mode', function()
local screen = Screen.new(40, 8)
screen:attach()
eq(nil, lfs.attributes(fname))
funcs.termopen({
nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE',
'--cmd', 'set noswapfile shortmess+=IFW fileformats=unix',
'-s', '-'
})
screen:expect([[
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{2:[No Name] 0,0-1 All}|
|
|
]], {
[1] = {foreground = 4210943, special = Screen.colors.Grey0},
[2] = {special = Screen.colors.Grey0, bold = true, reverse = true}
})
feed('i:cq<CR><C-\\><C-n>')
screen:expect([[
^ |
[Process exited 1] |
|
|
|
|
|
|
]])
--[=[ Example of incorrect output:
screen:expect([[
^nvim: /var/tmp/portage/dev-libs/libuv-1.|
10.2/work/libuv-1.10.2/src/unix/core.c:5|
19: uv__close: Assertion `fd > STDERR_FI|
LENO' failed. |
|
[Process exited 6] |
|
|
]])
]=]
end)
end) end)
end) end)

View File

@@ -483,6 +483,22 @@ describe('fs function', function()
end) end)
end) end)
describe('os_dup', function()
itp('returns new file descriptor', function()
local dup0 = fs.os_dup(0)
local dup1 = fs.os_dup(1)
local dup2 = fs.os_dup(2)
local tbl = {[0]=true, [1]=true, [2]=true,
[tonumber(dup0)]=true, [tonumber(dup1)]=true,
[tonumber(dup2)]=true}
local i = 0
for _, _ in pairs(tbl) do
i = i + 1
end
eq(i, 6) -- All fds must be unique
end)
end)
describe('os_open', function() describe('os_open', function()
local new_file = 'test_new_file' local new_file = 'test_new_file'
local existing_file = 'unit-test-directory/test_existing.file' local existing_file = 'unit-test-directory/test_existing.file'