Re-integrate FEAT_FILTERPIPE code

This feature was accidentally removed when doing the initial import from vim. It
makes vim use pipes instead of temporary files for filtering buffers through
shell commands.

I found that this was missing when looking for references of
SHELL_READ/SHELL_WRITE outside mch_call_shell`.

When `mch_call_shell` is reimplemented on top of libuv process management
facilities, pipes will always be used for communication with child processes so
it makes sense to enable the feature permanently.
This commit is contained in:
Thiago de Arruda
2014-03-27 13:35:36 -03:00
parent 1e8eb4e2c6
commit e995b21567
5 changed files with 47 additions and 18 deletions

1
.gitignore vendored
View File

@@ -29,6 +29,7 @@
/src/testdir/*.failed /src/testdir/*.failed
/src/testdir/X* /src/testdir/X*
/src/testdir/valgrind.* /src/testdir/valgrind.*
/src/testdir/.gdbinit
# Folder generated by the unit tests # Folder generated by the unit tests
/test/includes/post/ /test/includes/post/

View File

@@ -10252,6 +10252,7 @@ static void f_has(typval_T *argvars, typval_T *rettv)
"extra_search", "extra_search",
"farsi", "farsi",
"file_in_path", "file_in_path",
"filterpipe",
"find_in_path", "find_in_path",
"float", "float",
"folding", "folding",

View File

@@ -1024,7 +1024,23 @@ do_filter (
if (do_out) if (do_out)
shell_flags |= SHELL_DOOUT; shell_flags |= SHELL_DOOUT;
if ((do_in && (itmp = vim_tempname('i')) == NULL) if (!do_in && do_out && !p_stmp) {
// Use a pipe to fetch stdout of the command, do not use a temp file.
shell_flags |= SHELL_READ;
curwin->w_cursor.lnum = line2;
} else if (do_in && !do_out && !p_stmp) {
// Use a pipe to write stdin of the command, do not use a temp file.
shell_flags |= SHELL_WRITE;
curbuf->b_op_start.lnum = line1;
curbuf->b_op_end.lnum = line2;
} else if (do_in && do_out && !p_stmp) {
// Use a pipe to write stdin and fetch stdout of the command, do not
// use a temp file.
shell_flags |= SHELL_READ|SHELL_WRITE;
curbuf->b_op_start.lnum = line1;
curbuf->b_op_end.lnum = line2;
curwin->w_cursor.lnum = line2;
} else if ((do_in && (itmp = vim_tempname('i')) == NULL)
|| (do_out && (otmp = vim_tempname('o')) == NULL)) { || (do_out && (otmp = vim_tempname('o')) == NULL)) {
EMSG(_(e_notmp)); EMSG(_(e_notmp));
goto filterend; goto filterend;

View File

@@ -6,8 +6,10 @@
#include "os/event.h" #include "os/event.h"
#include "os/input.h" #include "os/input.h"
static uv_timer_t timer_req; static uv_timer_t timer;
static uv_prepare_t timer_prepare;
static void timer_cb(uv_timer_t *handle, int); static void timer_cb(uv_timer_t *handle, int);
static void timer_prepare_cb(uv_prepare_t *, int);
void event_init() void event_init()
{ {
@@ -15,7 +17,9 @@ void event_init()
input_init(); input_init();
/* Timer to wake the event loop if a timeout argument is passed to /* Timer to wake the event loop if a timeout argument is passed to
* `event_poll` */ * `event_poll` */
uv_timer_init(uv_default_loop(), &timer_req); uv_timer_init(uv_default_loop(), &timer);
/* This prepare handle that actually starts the timer */
uv_prepare_init(uv_default_loop(), &timer_prepare);
} }
/* Wait for some event */ /* Wait for some event */
@@ -33,10 +37,12 @@ bool event_poll(int32_t ms)
timed_out = false; timed_out = false;
if (ms > 0) { if (ms > 0) {
/* Timeout passed as argument, start the libuv timer to wake us up and /* Timeout passed as argument to the timer */
* set our local flag */ timer.data = &timed_out;
timer_req.data = &timed_out; /* We only start the timer after the loop is running, for that we
uv_timer_start(&timer_req, timer_cb, ms, 0); * use an prepare handle(pass the interval as data to it) */
timer_prepare.data = &ms;
uv_prepare_start(&timer_prepare, timer_prepare_cb);
} else if (ms == 0) { } else if (ms == 0) {
/* /*
* For ms == 0, we need to do a non-blocking event poll by * For ms == 0, we need to do a non-blocking event poll by
@@ -58,10 +64,11 @@ bool event_poll(int32_t ms)
input_stop(); input_stop();
if (!timed_out && ms > 0) { if (ms > 0) {
/* Timer event did not trigger, stop the watcher since we no longer /* Timer event did not trigger, stop the watcher since we no longer
* care about it */ * care about it */
uv_timer_stop(&timer_req); uv_timer_stop(&timer);
uv_prepare_stop(&timer_prepare);
} }
return input_ready(); return input_ready();
@@ -72,3 +79,8 @@ static void timer_cb(uv_timer_t *handle, int status)
{ {
*((bool *)handle->data) = true; *((bool *)handle->data) = true;
} }
static void timer_prepare_cb(uv_prepare_t *handle, int status)
{
uv_timer_start(&timer, timer_cb, *(uint32_t *)handle->data, 0);
}

View File

@@ -27,12 +27,8 @@ SCRIPTS := test1.out test2.out test3.out test4.out test5.out test6.out \
SCRIPTS_GUI := test16.out SCRIPTS_GUI := test16.out
ifdef VALGRIND_GDB ifdef USE_GDB
VGDB := --vgdb=yes --vgdb-error=0 GDB = gdb --args
endif
ifdef VALGRIND_CHECK
VALGRIND = valgrind --suppressions=../../.valgrind.supp --leak-check=full --error-exitcode=123 --log-file=valgrind.$* $(VGDB)
endif endif
ifdef TESTNUM ifdef TESTNUM
@@ -45,6 +41,9 @@ nongui: nolog $(SCRIPTS) report
gui: nolog $(SCRIPTS) $(SCRIPTS_GUI) report gui: nolog $(SCRIPTS) $(SCRIPTS_GUI) report
.gdbinit:
echo 'set $$_exitcode = -1\nrun\nif $$_exitcode != -1\n quit\nend' > .gdbinit
report: report:
@echo @echo
@echo 'Test results:' @echo 'Test results:'
@@ -57,12 +56,12 @@ $(SCRIPTS) $(SCRIPTS_GUI): $(VIMPROG)
RM_ON_RUN = test.out X* viminfo RM_ON_RUN = test.out X* viminfo
RM_ON_START = tiny.vim small.vim mbyte.vim mzscheme.vim lua.vim test.ok RM_ON_START = tiny.vim small.vim mbyte.vim mzscheme.vim lua.vim test.ok
RUN_VIM = $(VALGRIND) $(VIMPROG) -u unix.vim -U NONE --noplugin -s dotest.in RUN_VIM = $(GDB) $(VIMPROG) -u unix.vim -U NONE --noplugin -s dotest.in
clean: clean:
-rm -rf *.out *.failed *.rej *.orig test.log $(RM_ON_RUN) $(RM_ON_START) valgrind.* -rm -rf *.out *.failed *.rej *.orig test.log $(RM_ON_RUN) $(RM_ON_START) valgrind.*
test1.out: test1.in test1.out: .gdbinit test1.in
-rm -rf $*.failed $(RM_ON_RUN) $(RM_ON_START) wrongtermsize -rm -rf $*.failed $(RM_ON_RUN) $(RM_ON_START) wrongtermsize
$(RUN_VIM) $*.in $(RUN_VIM) $*.in
@/bin/sh -c "if test -e wrongtermsize; \ @/bin/sh -c "if test -e wrongtermsize; \
@@ -76,7 +75,7 @@ test1.out: test1.in
echo; exit 1; fi" echo; exit 1; fi"
-rm -rf X* viminfo -rm -rf X* viminfo
.in.out: .in.out: .gdbinit
-rm -rf $*.failed test.ok $(RM_ON_RUN) -rm -rf $*.failed test.ok $(RM_ON_RUN)
cp $*.ok test.ok cp $*.ok test.ok
# Sleep a moment to avoid that the xterm title is messed up. # Sleep a moment to avoid that the xterm title is messed up.