mirror of
https://github.com/neovim/neovim.git
synced 2025-10-06 09:56:31 +00:00
refactor(exit): pass error message to preserve_exit() (#22097)
Problem: 1. Some calls to preserve_exit() don't put a message in IObuff, so the IObuff printed by preserve_exit() contains unrelated information. 2. If a TUI client runs out of memory or receives a deadly signal, the error message is shown on alternate screen and cannot be easily seen because the TUI exits alternate screen soon afterwards. Solution: Pass error message to preserve_exit() and exit alternate screen before printing it. Note that this doesn't fix the problem that server error messages cannot be easily seen on exit. This is tracked in #21608 and #21843.
This commit is contained in:
@@ -121,9 +121,7 @@ void *xmalloc(size_t size)
|
||||
{
|
||||
void *ret = try_malloc(size);
|
||||
if (!ret) {
|
||||
os_errmsg(e_outofmem);
|
||||
os_errmsg("\n");
|
||||
preserve_exit();
|
||||
preserve_exit(e_outofmem);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -152,9 +150,7 @@ void *xcalloc(size_t count, size_t size)
|
||||
try_to_free_memory();
|
||||
ret = calloc(allocated_count, allocated_size);
|
||||
if (!ret) {
|
||||
os_errmsg(e_outofmem);
|
||||
os_errmsg("\n");
|
||||
preserve_exit();
|
||||
preserve_exit(e_outofmem);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@@ -174,9 +170,7 @@ void *xrealloc(void *ptr, size_t size)
|
||||
try_to_free_memory();
|
||||
ret = realloc(ptr, allocated_size);
|
||||
if (!ret) {
|
||||
os_errmsg(e_outofmem);
|
||||
os_errmsg("\n");
|
||||
preserve_exit();
|
||||
preserve_exit(e_outofmem);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@@ -194,8 +188,7 @@ void *xmallocz(size_t size)
|
||||
{
|
||||
size_t total_size = size + 1;
|
||||
if (total_size < size) {
|
||||
os_errmsg(_("Vim: Data too large to fit into virtual memory space\n"));
|
||||
preserve_exit();
|
||||
preserve_exit(_("Vim: Data too large to fit into virtual memory space\n"));
|
||||
}
|
||||
|
||||
void *ret = xmalloc(total_size);
|
||||
|
Reference in New Issue
Block a user