Commit Graph

641 Commits

Author SHA1 Message Date
Florian Walch
5e542ba56e vim-patch:7.4.513
Problem:    Crash because reference count is wrong for list returned by
	    getreg().
Solution:   Increment the reference count. (Kimmy Lindvall)

https://code.google.com/p/vim/source/detail?r=v7-4-513
2014-12-23 21:48:22 +01:00
Florian Walch
598f69b05e vim-patch:7.4.491
Problem:    When winrestview() has a negative "topline" value there are
	    display errors.
Solution:   Correct a negative value to 1. (Hirohito Higashi)

https://code.google.com/p/vim/source/detail?r=v7-4-491
2014-12-23 21:17:00 +01:00
Florian Walch
2ba50a7846 vim-patch:7.4.499
Problem:    substitute() can be slow with long strings.
Solution:   Store a pointer to the end, instead of calling strlen() every
	    time. (Ozaki Kiichi)

https://code.google.com/p/vim/source/detail?r=v7-4-499
2014-12-23 21:15:31 +01:00
David Rodriguez
c824e7b2d2 vim-patch:7.4.311
Problem:    Can't use winrestview to only restore part of the view.
Solution:   Handle missing items in the dict. (Christian Brabandt)

https://code.google.com/p/vim/source/detail?r=v7-4-311
2014-12-23 10:13:13 +01:00
Justin M. Keyes
943b063290 Merge pull request #1663 from philix/array_size
Define and use the ARRAY_SIZE macro
2014-12-19 02:23:26 -05:00
Florian Walch
3f7b8199df vim-patch:7.4.442
Problem:    Using unitinialized variable.
Solution:   Pass the first window of the tabpage.

https://code.google.com/p/vim/source/detail?r=v7-4-442
2014-12-18 21:22:46 +01:00
Florian Walch
815fe28450 vim-patch:7.4.434
Problem:    gettabvar() is not consistent with getwinvar() and getbufvar().
Solution:   Return a dict with all variables when the varname is empty.
	    (Yasuhiro Matsumoto)

https://code.google.com/p/vim/source/detail?r=v7-4-434
2014-12-18 21:22:40 +01:00
Felipe Oliveira Carvalho
3c857900fe Define and use the ARRAY_SIZE macro
A similar macro is defined in the Linux kernel [1].

To refactor the code I used a slightly modified Coccinelle script I found in
[2].

```diff
// Use the macro ARRAY_SIZE when possible
//
// Confidence: High
// Copyright: (C) Gilles Muller, Julia Lawall, EMN, DIKU.  GPLv2.
// URL: http://www.emn.fr/x-info/coccinelle/rules/array.html
// Options: -I ... -all_includes can give more complete results

@@
type T;
T[] E;
@@

- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)

@@
type T;
T[] E;
@@

- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)

@@
type T;
T[] E;
@@

- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)

@n@
identifier AS,E;
@@

- #define AS(E) ARRAY_SIZE(E)

@@
expression E;
identifier n.AS;
@@

- AS(E)
+ ARRAY_SIZE(E)
```

`spatch --in-place --sp-file array_size.cocci -I src/ -I build/include/ -I build/src/nvim/auto/ src/nvim/*.c`

[1] http://lxr.free-electrons.com/source/include/linux/kernel.h#L54
[2] http://www.emn.fr/z-info/coccinelle/rules/#macros
2014-12-18 15:41:37 -03:00
Felipe Oliveira Carvalho
77135447e0 Reduce indentation level by early returning or continuing loop
Replace code like this

```c
func() {
    if (cond) {
	...
	...
	...
    }
    return ret;
}
```

```c
for (...) {
    if (cond) {
	...
	...
	...
    }
}
```

with

```c
func() {
    if (!cond) {
	return ret;
    }
    ...
    ...
    ...
}
```

```c
for (...) {
    if (!cond) {
	continue;
    }
    ...
    ...
    ...
}
```
2014-12-13 23:36:11 -03:00
Justin M. Keyes
4c7fe20bef Merge pull request #1134 from splinterofchaos/getreg-nl
vim-patch:7.4.242 + vim-patch:7.4.243
2014-12-11 21:35:34 -05:00
Scott Prager
a192865f90 Attribute/constify get_tv_string(_buf(_chk)). 2014-12-11 20:30:01 -05:00
Scott Prager
3d93e47d9a vim-patch:7.4.249
Problem:    Using setreg() with a list of numbers does not work.
Solution:   Use a separate buffer for numbers. (ZyX)

https://code.google.com/p/vim/source/detail?r=v7-4-249
2014-12-11 20:30:00 -05:00
Scott Prager
5fdca47962 vim-patch:7.4.243
Problem:    Cannot use setreg() to add text that includes a NUL.
Solution:   Make setreg() accept a list.

https://code.google.com/p/vim/source/detail?r=v7-4-243
2014-12-11 20:30:00 -05:00
Scott Prager
2f8cc3b9d5 Return void * from get_reg_contents. 2014-12-11 20:29:59 -05:00
Scott Prager
e18538f3ef vim-patch:7.4.242
Problem:    getreg() does not distinguish between a NL used for a line
            break and a NL used for a NUL character.
Solution:   Add another argument to return a list. (ZyX)

https://code.google.com/p/vim/source/detail?r=v7-4-242
2014-12-11 20:29:59 -05:00
Felipe Oliveira Carvalho
e11a5699be Use GA_DEEP_CLEAR where appropriate 2014-12-11 20:22:37 -03:00
Björn Linse
9a0ec687d9 eval_has_provider: search autoload scripts same order as call_func 2014-12-08 22:05:05 +01:00
Björn Linse
c1854d2433 clipboard: support separate '+' and '*' clipboards 2014-12-08 21:38:35 +01:00
Björn Linse
1464b0eda2 systemlist: add keepempty option to preserve final newline 2014-12-02 16:50:52 +01:00
Scott Prager
927c6a148d eval: Fix coverity false positive.
** CID 74786:  Resource leak  (RESOURCE_LEAK)
/src/nvim/eval.c: 10614 in f_jobsend()
/src/nvim/eval.c: 10616 in f_jobsend()

save_tv_as_string() should return NULL and input_len <= 0 for an empty
string or error. Callers should check that input != NULL instead of
input_len > 0 and assert(input == NULL) when the length must be checked.
2014-11-27 15:12:35 -05:00
Thiago de Arruda
bf6bb27e79 ui: Remove redundant ui.h includes
Also move read_error_exit to os/input.c
2014-11-27 15:00:30 -03:00
Thiago de Arruda
a3534138a8 ui: Extract mouse.c/mouse.h 2014-11-27 14:48:30 -03:00
Thiago de Arruda
1865b8c1c1 ui: Remove ui_delay, ui_breakcheck and ui_set_shellsize
These functions only used to call another os_* function, so remove them and
replace all occurences in the project.
2014-11-27 14:27:18 -03:00
Thiago de Arruda
541eaf598c ui: Remove ui_inchar/ui_char_avail
Also:

- Remove NO_CONSOLE_INPUT/NO_CONSULE preprocessor conditionals
- Remove ctrl_c_interrupts variable, check for mapped_ctrl_c directly in
  process_interrupts()
- Move ui_inchar profiling to input_poll which is where Nvim blocks for input.
2014-11-27 14:12:59 -03:00
Rui Abreu Ferreira
e644369f6e Add Boolean argument escape_csi to vim_feedkeys
- By default vim_feedkeys escaped all input for CSI/K_SPECIAL bytes
  before using it. However since vim_replace_termcodes() also escapes
  the input string chaining these functions together escapes input twice
- vim_feedkeys() now takes a third Boolean argument to enable/disable
  escaping
- Breaks API compatibility
2014-11-27 08:33:53 -03:00
Rui Abreu Ferreira
ea8cc88e6a Add missing refcount increment for systemlist()
- get_system_output_as_rettv() was missing a refcount increment when
  returning an empty list, i.e. when there was no output
- we now use rettv_list_aloc() instead of list_alloc()
- issue #1530
2014-11-25 20:00:27 +00:00
Eliseo Martínez
7aa7ce253d Fix warnings: eval.c: f_rpcrequest(): Garbage value: MI.
Problem    : Assigned value is garbage or undefined @ 12578.
Diagnostic : Multithreading issue.
Rationale  : Error can only occur if global `provider_call_nesting` is
             changed while function is executing.
Resolution : Use local copy of global.
2014-11-18 22:20:39 +01:00
Eliseo Martínez
5c00f8c132 Fix warnings: eval.c: do_return(): Np dereference: FP.
Problem    : Dereference of null pointer @ 18841.
Diagnostic : False positive.
Rationale  : Suggested error path takes `reanimate` branch at 18827,
             assigning `rettv = current_funccal->rettv`. Then,
             inmediately after, it supposes rettv is null, which cannot
             happen, since current_funccal->rettv should always be non
             null.
Resolution : Assert current_funccal->rettv non null.
2014-11-18 22:00:03 +01:00
Eliseo Martínez
97be8d45f4 Fix warnings: eval.c: add_nr_var(): Out of bounds: FP.
Problem    : Out-of-bound array access @ 18737.
Diagnostic : False positive.
Rationale  : Situation is intentional. `dictitem_T` is a prefix all dict
             items whill share, but actual size of each item will be
             different depending on its key length. `di_key` array field
             is declared of size 1 just to have a field name, but real
             size will vary for each item.
Resolution : Make analyzer ignore it.
             This could be refactored to use C99-allowed variable length
             arrays, but eval.c is bound to dissappear, so no effort is
             done in that sense.
2014-11-18 22:00:02 +01:00
Eliseo Martínez
3bf32fe43f Fix warnings: eval.c: call_user_func(): Out of bounds: FP.
Problem    : Out-of-bound array access @ 18429.
Diagnostic : False positive.
Rationale  : Situation is intentional. `dictitem_T` is a prefix all dict
             items whill share, but actual size of each item will be
             different depending on its key length. `di_key` array field
             is declared of size 1 just to have a field name, but real
             size will vary for each item.
Resolution : Make analyzer ignore it.
             This could be refactored to use C99-allowed variable length
             arrays, but eval.c is bound to dissappear, so no effort is
             done in that sense.
2014-11-18 22:00:02 +01:00
Eliseo Martínez
34a4a01e4e Fix warnings: eval.c: get_user_func_name(): Np dereference: FP.
Problem    : Dereference of null pointer @ 18216.
Diagnostic : False positive.
Rationale  : `hi` and `done` are static. Intended usage is for the first
             call to have idx == 0, so that they are initialized.
Resolution : Assert hi after (optional) initialization.
2014-11-18 22:00:02 +01:00
Eliseo Martínez
eb15d8777b Fix warnings: eval.c: clear_tv(): Bad free: RI.
Problem    : Bad free @ 16076.
Diagnostic : Real issue.
Rationale  : A non-allocated string is set at 4127, which later on can
             be tried to be freed if aborting.
Resolution : Detect particular case (func with empty name) and don't
             free in that case.
             Another solution (use allocated string) was tried before,
             but it produced a leak difficult to solve.
             Finally applied solution works, but it produces a new false
             positive warning (Np dereference at 13763), deactivated by
             `assert(ptrs[i].item->li_next)`.
2014-11-18 22:00:01 +01:00
Eliseo Martínez
ece19651c6 Fix warnings: eval.c: item_compare(): Garbage value: MI.
Problem    : Result of operation is garbage or undefined @ 13565.
Diagnostic : Multithreading issue.
Rationale  : Problem occurs only if global (static) variable
             `item_compare_keep_zero` changes after being used by
             `do_sort_uniq` but before being used by `item_compare` or
             `item_compare2`.
Resolution : This is not an intra-function problem, as other MI's
             before, but rather an inter-function one. Thus, it can't be
             solved by using local copy of global. Therefore, we are
             forced to do a bit refactoring. We can't simply add a bool
             param to item_compare/item_compare2, as they couldn't be
             passed to qsort() that way. So, item_compare/item_compare2
             are added a bool param and curried versions of them are
             added and used in their place.
2014-11-18 21:57:49 +01:00
Eliseo Martínez
be90cdf4f9 Fix warnings: eval.c: dictitem_alloc(): Out-of-bounds access: FP.
Problem    : Out-of-bound array access @ 5737.
Diagnostic : False positive.
Rationale  : Situation is intentional. `dictitem_T` is a prefix all dict
             items whill share, but actual size of each item will be
             different depending on its key length. `di_key` array field
             is declared of size 1 just to have a field name, but real
             size will vary for each item.
Resolution : Make analyzer ignore it.
             This could be refactored to use C99-allowed variable length
             arrays, but eval.c is bound to dissappear, so no effort is
             done in that sense.
2014-11-18 21:57:48 +01:00
Eliseo Martínez
d3f413ba6a Fix warnings: eval.c: set_var_lval(): Np dereference: FP.
Problem    : Dereference of null pointer @ 2273.
Diagnostic : False positive.
Rationale  : Suggested error would happen when assigning an rvalue with
             more items than the lvalue. Then we would enter conditional
             at:
             ```
             if (lp->ll_li->li_next == NULL) {
               /* Need to add an empty item. */
               list_append_number(lp->ll_list, 0);
             }
             lp->ll_li = lp->ll_li->li_next;
             ```
             Analyzer thinks the value assigned to lp->ll_li is still
             NULL and is hit on the next iteration.
Resolution : Assert lp->ll_li->li_next is not null anymore after
             list_append_number().
2014-11-18 21:57:48 +01:00
Thiago de Arruda
17a4bfe007 Remove os/provider.{c,h} and all of its references 2014-11-18 07:56:58 -03:00
Thiago de Arruda
375db3b19a eval/ex_cmds2/ops: Implement providers with eval_call_provider
Replace references to provider_call/provider_has with the new functions
eval_call_provider/eval_has_provider.
2014-11-18 07:56:58 -03:00
Thiago de Arruda
268b2eff4a eval: Add eval_call_provider/eval_has_provider functions
These use autoloaded vimscript to replace the provider_call/provider_has
functions, moving the implementation of providers to pure vimscript(we lose
nothing since vimscript can also call msgpack-rpc functions).

When calling the rpcrequest function from a provider, temporarily switch to the
caller scope. This is required for compatibility with legacy plugins, because
they may depend on scope information that changes when "leaving" the C stack to
enter the vimscript stack.
2014-11-18 07:56:58 -03:00
Justin M. Keyes
7465fc6ee9 Merge pull request #1471 from splinterofchaos/fix-jobstart
jobstart: Check prg arguments for NULL.
2014-11-15 17:10:47 -05:00
Scott Prager
fa74c1ea71 jobstart: Check prg arguments for NULL. 2014-11-13 19:21:49 -05:00
Scott Prager
96be11f609 vim-patch:7.4.419
Problem:    Whan part of a list is locked it's possible to make changes.
Solution:   Check if any of the list items is locked before make a change.
            (ZyX)

https://code.google.com/p/vim/source/detail?r=v7-4-419
2014-11-11 12:05:51 -05:00
Thiago de Arruda
ab826d88f6 eval: Return an empty list from systemlist() when there's no output
This is the behavior on vim's `systemlist()`.
2014-11-10 18:47:03 -03:00
Scott Prager
fd36dc208e job: Let vimL jobsend() accept a list.
Use save_tv_as_string(), same as vimL system(). This also makes
jobsend() more liberal in what it can accept. For example,
`jobsend(j, 123)` is now valid.

Closes #1176
2014-11-07 13:34:56 -03:00
Scott Prager
e90973e035 job: Make v:job_data[2] a list.
Factor out string_to_list() from f_system()'s implementation
and use that to set job_data. This has the technical advantage of
preserving NULs, and may be more convenient for users.

Required for #1176.
2014-11-07 13:34:56 -03:00
Scott Prager
37cbafa5bb job: Read job data line-wise.
Only read up to the last newline in push_job_event().
2014-11-07 13:34:56 -03:00
Eliseo Martínez
e7a863e12c Remove long_u: eval: Replace with size_t.
Note: No effort is done on refactoring anything in eval module, as it
      will be eventually dropped.
2014-11-06 22:19:33 +01:00
Nicolas Hillegeer
8c5efd62ac iconv: re-enable
This seems to have been disabled in the transition from vim to neovim,
re-enable it.
2014-11-06 00:18:26 +01:00
Thiago de Arruda
a1dd70b1d0 event: Reintroduce the immediate event queue
Commit @264e0d872c("Remove automatic event deferral") removed the immediate
event queue because event deferral now had to be explicit. The problem is that
while some events don't need to be deferred, they still can result in recursive
`event_poll` calls, and recursion is not supported by libuv. Examples of those
are msgpack-rpc requests while a server->client request is pending, or signals
which can call `mch_exit`(and that will result in `uv_run` calls).

To fix the problem, this reintroduces the immediate event queue for events that
can potentially result in event loop recursion. The non-deferred events are
still processed in `event_poll`, but only after `uv_run` returns.
2014-11-02 16:47:50 -03:00
Thiago de Arruda
c92d17b4aa job: Let job_start callers to selectively ignore stdio
Passing NULL as the callback for stdout/stderr will result in job_start ignoring
stdout/stderr, respectively. A 'writable' boolean argument was also added, and
when false `job_start` will ignore stdin.

Also, refactor os_system to allow passing NULL as the `output` argument.
2014-10-31 22:52:10 -03:00
Justin M. Keyes
181e652ee1 Merge pull request #1312 from GokuITA/coverity1289
coverity/71507: Unchecked return value (CHECKED_RETURN)
2014-10-30 02:12:28 -04:00