From 521e45f2a8c0619335288accdda0f0aaa1fc6513 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Mon, 24 Oct 2016 23:53:07 -0700 Subject: vim-patch:7.4.1559 Problem: Passing cookie to a callback is clumsy. Solution: Change function() to take arguments and return a partial. https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710 --- src/nvim/eval/encode.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/nvim/eval/encode.c') diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 869eae74a3..57507f4430 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -315,6 +315,13 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, ga_append(gap, ')'); \ } while (0) +#define TYPVAL_ENCODE_CONV_PARTIAL(partial) \ + do { \ + ga_concat(gap, "partial("); \ + TYPVAL_ENCODE_CONV_STRING(partial, STRLEN(partial)); \ + ga_append(gap, ')'); \ + } while (0) + #define TYPVAL_ENCODE_CONV_EMPTY_LIST() \ ga_concat(gap, "[]") @@ -661,6 +668,12 @@ static inline int convert_to_json_string(garray_T *const gap, "attempt to dump function reference"), \ mpstack, objname) +#undef TYPVAL_ENCODE_CONV_PARTIAL +#define TYPVAL_ENCODE_CONV_PARTIAL(partial) \ + return conv_error(_("E474: Error while dumping %s, %s: " \ + "attempt to dump partial"), \ + mpstack, objname) + /// Check whether given key can be used in json_encode() /// /// @param[in] tv Key to check. @@ -718,6 +731,7 @@ TYPVAL_ENCODE_DEFINE_CONV_FUNCTIONS(static, json, garray_T *const, gap) #undef TYPVAL_ENCODE_CONV_NUMBER #undef TYPVAL_ENCODE_CONV_FLOAT #undef TYPVAL_ENCODE_CONV_FUNC +#undef TYPVAL_ENCODE_CONV_PARTIAL #undef TYPVAL_ENCODE_CONV_EMPTY_LIST #undef TYPVAL_ENCODE_CONV_LIST_START #undef TYPVAL_ENCODE_CONV_EMPTY_DICT @@ -846,6 +860,11 @@ char *encode_tv2json(typval_T *tv, size_t *len) "attempt to dump function reference"), \ mpstack, objname) +#define TYPVAL_ENCODE_CONV_PARTIAL(partial) \ + return conv_error(_("E951: Error while dumping %s, %s: " \ + "attempt to dump partial"), \ + mpstack, objname) + #define TYPVAL_ENCODE_CONV_EMPTY_LIST() \ msgpack_pack_array(packer, 0) @@ -902,6 +921,7 @@ TYPVAL_ENCODE_DEFINE_CONV_FUNCTIONS(, msgpack, msgpack_packer *const, packer) #undef TYPVAL_ENCODE_CONV_NUMBER #undef TYPVAL_ENCODE_CONV_FLOAT #undef TYPVAL_ENCODE_CONV_FUNC +#undef TYPVAL_ENCODE_CONV_PARTIAL #undef TYPVAL_ENCODE_CONV_EMPTY_LIST #undef TYPVAL_ENCODE_CONV_LIST_START #undef TYPVAL_ENCODE_CONV_EMPTY_DICT -- cgit From bae31b764a5607fad5d914f271e93e10c2d0bfbe Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Fri, 28 Oct 2016 22:44:42 -0700 Subject: vim-patch:7.4.1608 Problem: string() doesn't handle a partial. Solution: Make a string from a partial. https://github.com/vim/vim/commit/5c29154b521e9948190be653cfda666ecbb63b5b --- src/nvim/eval/encode.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/nvim/eval/encode.c') diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 57507f4430..65570a6f30 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -317,9 +317,32 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, #define TYPVAL_ENCODE_CONV_PARTIAL(partial) \ do { \ - ga_concat(gap, "partial("); \ - TYPVAL_ENCODE_CONV_STRING(partial, STRLEN(partial)); \ - ga_append(gap, ')'); \ + partial_T *pt = tv->vval.v_partial; \ + garray_T ga; \ + int i; \ + ga_init(&ga, 1, 100); \ + ga_concat(&ga, (char_u *)"function("); \ + if (&pt->pt_name != NULL) { \ + TYPVAL_ENCODE_CONV_STRING((char *)pt->pt_name, sizeof(pt->pt_name)); \ + } \ + if (pt != NULL && pt->pt_argc > 0) { \ + ga_concat(&ga, (char_u *)", ["); \ + for (i = 0; i < pt->pt_argc; i++) { \ + if (i > 0) { \ + ga_concat(&ga, (char_u *)", "); \ + } \ + ga_concat(&ga, encode_tv2string(&pt->pt_argv[i], NULL)); \ + } \ + ga_concat(&ga, (char_u *)"]"); \ + } \ + if (pt != NULL && pt->pt_dict != NULL) { \ + typval_T dtv; \ + ga_concat(&ga, (char_u *)", "); \ + dtv.v_type = VAR_DICT; \ + dtv.vval.v_dict = pt->pt_dict; \ + ga_concat(&ga, encode_tv2string(&dtv, NULL)); \ + } \ + ga_concat(&ga, (char_u *)")"); \ } while (0) #define TYPVAL_ENCODE_CONV_EMPTY_LIST() \ -- cgit From a21c687661eac61702fe492264a3c9036bc62f41 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Sat, 29 Oct 2016 14:55:53 -0700 Subject: Fixes. --- src/nvim/eval/encode.c | 56 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 16 deletions(-) (limited to 'src/nvim/eval/encode.c') diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 65570a6f30..51393e5337 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -315,34 +315,58 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, ga_append(gap, ')'); \ } while (0) -#define TYPVAL_ENCODE_CONV_PARTIAL(partial) \ +#define TYPVAL_ENCODE_CONV_PARTIAL(pt) \ do { \ - partial_T *pt = tv->vval.v_partial; \ - garray_T ga; \ int i; \ - ga_init(&ga, 1, 100); \ - ga_concat(&ga, (char_u *)"function("); \ + ga_concat(gap, "function("); \ if (&pt->pt_name != NULL) { \ - TYPVAL_ENCODE_CONV_STRING((char *)pt->pt_name, sizeof(pt->pt_name)); \ + size_t len; \ + char_u *p; \ + len = 3; \ + len += STRLEN(pt->pt_name); \ + for (p = pt->pt_name; *p != NUL; mb_ptr_adv(p)) { \ + if (*p == '\'') { \ + len++; \ + } \ + } \ + char_u *r, *s; \ + s = r = xmalloc(len); \ + if (r != NULL) { \ + *r++ = '\''; \ + for (p = pt->pt_name; *p != NUL; ) { \ + if (*p == '\'') { \ + *r++ = '\''; \ + } \ + MB_COPY_CHAR(p, r); \ + } \ + *r++ = '\''; \ + *r++ = NUL; \ + } \ + ga_concat(gap, s); \ + xfree(s); \ } \ - if (pt != NULL && pt->pt_argc > 0) { \ - ga_concat(&ga, (char_u *)", ["); \ + if (pt->pt_argc > 0) { \ + ga_concat(gap, ", ["); \ for (i = 0; i < pt->pt_argc; i++) { \ if (i > 0) { \ - ga_concat(&ga, (char_u *)", "); \ + ga_concat(gap, ", "); \ } \ - ga_concat(&ga, encode_tv2string(&pt->pt_argv[i], NULL)); \ + char *tofree = encode_tv2string(&pt->pt_argv[i], NULL); \ + ga_concat(gap, tofree); \ + xfree(tofree); \ } \ - ga_concat(&ga, (char_u *)"]"); \ + ga_append(gap, ']'); \ } \ - if (pt != NULL && pt->pt_dict != NULL) { \ + if (pt->pt_dict != NULL) { \ typval_T dtv; \ - ga_concat(&ga, (char_u *)", "); \ + ga_concat(gap, ", "); \ dtv.v_type = VAR_DICT; \ dtv.vval.v_dict = pt->pt_dict; \ - ga_concat(&ga, encode_tv2string(&dtv, NULL)); \ + char *tofree = encode_tv2string(&dtv, NULL); \ + ga_concat(gap, tofree); \ + xfree(tofree); \ } \ - ga_concat(&ga, (char_u *)")"); \ + ga_append(gap, ')'); \ } while (0) #define TYPVAL_ENCODE_CONV_EMPTY_LIST() \ @@ -692,7 +716,7 @@ static inline int convert_to_json_string(garray_T *const gap, mpstack, objname) #undef TYPVAL_ENCODE_CONV_PARTIAL -#define TYPVAL_ENCODE_CONV_PARTIAL(partial) \ +#define TYPVAL_ENCODE_CONV_PARTIAL(pt) \ return conv_error(_("E474: Error while dumping %s, %s: " \ "attempt to dump partial"), \ mpstack, objname) -- cgit From 5e4eb18eb0242794c0b3a622f7acf0d3e6856c05 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Fri, 11 Nov 2016 13:13:55 -0700 Subject: Add some tests and cleanup. --- src/nvim/eval/encode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval/encode.c') diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 51393e5337..61d7a38007 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -908,7 +908,7 @@ char *encode_tv2json(typval_T *tv, size_t *len) mpstack, objname) #define TYPVAL_ENCODE_CONV_PARTIAL(partial) \ - return conv_error(_("E951: Error while dumping %s, %s: " \ + return conv_error(_("E5004: Error while dumping %s, %s: " \ "attempt to dump partial"), \ mpstack, objname) -- cgit