Skip to content

Commit

Permalink
patch 7.4.1238
Browse files Browse the repository at this point in the history
Problem:    Can't handle two messages right after each other.
Solution:   Find the end of the JSON.  Read more when incomplete.  Add a C
            test for the JSON decoding.
  • Loading branch information
brammool committed Feb 2, 2016
1 parent d9ea906 commit 56ead34
Show file tree
Hide file tree
Showing 9 changed files with 533 additions and 138 deletions.
28 changes: 25 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1545,11 +1545,13 @@ EXTRA_SRC = hangulin.c if_lua.c if_mzsch.c auto/if_perl.c if_perlsfio.c \
$(GRESOURCE_SRC)

# Unittest files
JSON_TEST_SRC = json_test.c
JSON_TEST_TARGET = json_test$(EXEEXT)
MEMFILE_TEST_SRC = memfile_test.c
MEMFILE_TEST_TARGET = memfile_test$(EXEEXT)

UNITTEST_SRC = $(MEMFILE_TEST_SRC)
UNITTEST_TARGETS = $(MEMFILE_TEST_TARGET)
UNITTEST_SRC = $(JSON_TEST_SRC) $(MEMFILE_TEST_SRC)
UNITTEST_TARGETS = $(JSON_TEST_TARGET) $(MEMFILE_TEST_TARGET)

# All sources, also the ones that are not configured
ALL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(UNITTEST_SRC) $(EXTRA_SRC)
Expand Down Expand Up @@ -1588,7 +1590,6 @@ OBJ_COMMON = \
$(HANGULIN_OBJ) \
objects/if_cscope.o \
objects/if_xcmdsrv.o \
objects/json.o \
objects/mark.o \
objects/memline.o \
objects/menu.o \
Expand Down Expand Up @@ -1914,6 +1915,7 @@ types.vim: $(TAGS_SRC) $(TAGS_INCL)
ctags --c-kinds=gstu -o- $(TAGS_SRC) $(TAGS_INCL) |\
awk 'BEGIN{printf("syntax keyword Type\t")}\
{printf("%s ", $$1)}END{print ""}' > $@
echo "syn keyword Constant OK FAIL TRUE FALSE MAYBE" >> $@

# Execute the test scripts. Run these after compiling Vim, before installing.
# This doesn't depend on $(VIMTARGET), because that won't work when configure
Expand Down Expand Up @@ -1948,6 +1950,12 @@ unittest unittests: $(UNITTEST_TARGETS)
./$$t || exit 1; echo $$t passed; \
done

run_json_test: $(JSON_TEST_TARGET)
./$(JSON_TEST_TARGET)

run_memfile_test: $(MEMFILE_TEST_TARGET)
./$(MEMFILE_TEST_TARGET)

# Run individual OLD style test, assuming that Vim was already compiled.
test1 \
test_autocmd_option \
Expand Down Expand Up @@ -2040,6 +2048,13 @@ testclean:

# Unittests
# It's build just like Vim to satisfy all dependencies.
$(JSON_TEST_TARGET): auto/config.mk objects $(JSON_TEST_OBJ)
$(CCC) version.c -o objects/version.o
@LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
-o $(JSON_TEST_TARGET) $(JSON_TEST_OBJ) $(ALL_LIBS)" \
MAKE="$(MAKE)" LINK_AS_NEEDED=$(LINK_AS_NEEDED) \
sh $(srcdir)/link.sh

$(MEMFILE_TEST_TARGET): auto/config.mk objects $(MEMFILE_TEST_OBJ)
$(CCC) version.c -o objects/version.o
@LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
Expand Down Expand Up @@ -2811,6 +2826,9 @@ objects/integration.o: integration.c
objects/json.o: json.c
$(CCC) -o $@ json.c

objects/json_test.o: json_test.c
$(CCC) -o $@ json_test.c

objects/main.o: main.c
$(CCC) -o $@ main.c

Expand Down Expand Up @@ -3301,6 +3319,10 @@ objects/gui_at_fs.o: gui_at_fs.c vim.h auto/config.h feature.h os_unix.h \
objects/pty.o: pty.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h ascii.h \
keymap.h term.h macros.h option.h structs.h regexp.h gui.h gui_beval.h \
proto/gui_beval.pro alloc.h ex_cmds.h proto.h globals.h farsi.h arabic.h
objects/json_test.o: json_test.c main.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h ex_cmds.h proto.h \
globals.h farsi.h arabic.h farsi.c arabic.c json.c
objects/memfile_test.o: memfile_test.c main.c vim.h auto/config.h feature.h \
os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h \
structs.h regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h \
Expand Down
3 changes: 1 addition & 2 deletions src/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,8 @@ channel_read_json(int ch_idx)
/* TODO: make reader work properly */
/* reader.js_buf = channel_peek(ch_idx); */
reader.js_buf = channel_get_all(ch_idx);
reader.js_eof = TRUE;
/* reader.js_eof = FALSE; */
reader.js_used = 0;
reader.js_fill = NULL;
/* reader.js_fill = channel_fill; */
reader.js_cookie = &ch_idx;
if (json_decode(&reader, &listtv) == OK)
Expand Down
4 changes: 2 additions & 2 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -14100,9 +14100,9 @@ f_jsondecode(typval_T *argvars, typval_T *rettv)
js_read_T reader;

reader.js_buf = get_tv_string(&argvars[0]);
reader.js_eof = TRUE;
reader.js_fill = NULL;
reader.js_used = 0;
if (json_decode(&reader, rettv) == FAIL)
if (json_decode_all(&reader, rettv) != OK)
EMSG(_(e_invarg));
}

Expand Down
Loading

0 comments on commit 56ead34

Please sign in to comment.