Commit Graph

142 Commits

Author SHA1 Message Date
Eliseo Martínez
31c8440fee Remove long_u: term: Enable -Wconversion. 2015-01-10 10:52:21 +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
Eliseo Martínez
885661d25b Fix warnings: syntax.c: get_id_list(): Double free: FP.
Problem    : Double free @ 5213.
Diagnostic : False positive.
Rationale  : I haven't been able to find the real reason why this is
             signaled. Nonetheless, I've been able to track down the
             introduction of this warning to commit
             77135447e0.
             The change there affecting this function is just a
             transformation maintaining semantics. So, this must be a
             FP, though I can't explain why.
Resolution : Revert changes in mentioned commmit touching this function.
2014-12-17 22:10:14 +01:00
Felipe Oliveira Carvalho
0bc40e660c Simple refatorings that didn't fit the pattern of the last commit 2014-12-13 23:36:11 -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
Felipe Oliveira Carvalho
e11a5699be Use GA_DEEP_CLEAR where appropriate 2014-12-11 20:22:37 -03:00
Thiago de Arruda
86542c6fd0 syntax: Use RGB/GUI attribute information for "abstract_ui"
Instead of using classic cterm color numbers and attributes, treat "abstract_ui"
as a GUI: Pass rgb color numbers and gui attributes when the "highlight_set" UI
method is called. The terminal UI will have to translate RGB color information
to an appropriate color number, and the "term"/"cterm" :highlight keys will
eventually be deprecated.
2014-12-08 23:44:24 -03: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
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
Eliseo Martínez
fcd5a8643c Fix warnings: syntax.c: get_id_list(): Double free: FP.
Problem    : Double free @ 5213.
Diagnostic : False positive.
Rationale  : Suggested error path contains two consecutive invocations
             of `ends_excmd(*p)` having different results, which is not
             possible. First invocation is before the while loop. Second
             invocation is the while loop condition itsef.
Resolution : Refactor while loop into do-while loop. That removes the
             impossible path from analysis, and, in addition, is a bit
             more efficient.
2014-11-15 12:49:18 +01:00
Eliseo Martínez
ce9c4e9a6f Fix warnings: syntax.c: syn_regexec(): Uninitialized arg: MI.
Problem    : Uninitialized argument value @ 2863.
Diagnostic : Multithreading issue.
Rationale  : Error can only occur if global `syn_time_on` is changed
             while the function is executing.
Resolution : Use local copy of gloval var.
2014-11-15 12:49:18 +01:00
Wayne Rowcliffe
9b6f192693 Replace FOR_ALL_WINDOWS with FOR_ALL_WINDOWS_IN_TAB(curtab) 2014-09-24 19:00:50 -05:00
Wayne Rowcliffe
fe99930c46 Convert FOR_ALL_WINDOWS to use a locally declared pointer 2014-09-08 17:27:41 -05:00
André Twupack
16a04bae0a vim-patch:7.4.318 #968
Problem:    Check for whether a highlight group has settings ignores fg and bg color settings.
Solution:   Also check cterm and GUI color settings. (Christian Brabandt)

https://code.google.com/p/vim/source/detail?r=5c47dacf397c1c65d2dfc237b3ff395c66ec3d4d
2014-08-18 01:25:17 +00:00
Florian Walch
4fa8a0c43c clang-analyzer: Reduce scope in syntax.c. 2014-08-07 15:19:59 +02:00
Nicolas Hillegeer
0564f781ab vim: move disptick_T from vim.h to syntax_defs.h
Make vim.h smaller, bit by bit.
2014-07-16 19:05:34 +02:00
Nicolas Hillegeer
db7cd61f62 profiling: implement on top of os_hrtime()
Should be better than gettimeofday() since libuv uses higher resolution
clocks on most UNIX platforms. Libuv also tries to use monotonic clocks,
kernel bugs notwithstanding, which is another win over gettimeofday().

Necessary for Windows, which doesn't have gettimeofday(). In vanilla vim,
Windows uses QueryPerformanceCounter, which is the correct primitive for
this sort of things, but that was removed when slimming up the codebase.
Libuv uses QueryPerformanceCounter to implement uv_hrtime() on Windows so
the behaviour of vim profiling on Windows should now be the same.

The behaviour on Linux should be different (better) though, libuv uses more
accurate primitives than gettimeofday().

Other misc. changes:
- Added function attributes where relevant (const, pure, ...)
- Convert functions to receive scalars: Now that proftime_T is always a
  (uint64_t) scalar (and not a struct), it's clearer to convert the
  functions to receive it as such instead of a pointer to a scalar.
- Extract profiling funcs to profile.c: make everything clearer and reduces
  the size of the "catch-all" ex_cmds2.c
- Add profile.{c,h} to clint and -Wconv:
  - Don't use sprintf, use snprintf
  - Don't use long, use int16_t/int32_t/...
2014-07-16 17:12:34 +02:00
Pavel Platto
0868818d3e Include stdbool.h in some files which use it
Done by manual inspection of the output of this script:
grep -r -l -w "bool\|true\|false" * | grep 'c$\|h$' > has_bool
grep -r -l "stdbool.h" * | grep 'c$\|h$' > has_include
grep -F -x -v -f has_include has_bool
2014-07-11 18:33:07 -04:00
Brandon Coleman
0fff487690 move errno.h include out of vim.h 2014-07-09 00:18:20 +02:00
Brandon Coleman
e69cfa6c15 move assert.h include out of vim.h 2014-07-09 00:18:19 +02:00
Brandon Coleman
bf219e1442 move <inttypes.h> include out of vim.h 2014-07-09 00:18:19 +02:00
Brandon Coleman
82b71a3056 move ascii.h include out of vim.h 2014-07-09 00:18:18 +02:00
Klemen Košir
a568e8b644 Replaced most TRUE/FALSE macros in arabic, mbyte and spell. #645 2014-07-08 17:34:08 +00:00
Klemen Košir
ef34a0ab13 Replace int with bool in some files. #654 2014-07-08 17:25:48 +00:00
Felipe Oliveira Carvalho
5ed74cfb7c Introduce ga_append_via_ptr() and GA_APPEND_VIA_PTR()
Similar to GA_APPEND(). Replaces this pattern:

    ga_grow(&ga, 1);
    item_type *p = ((item_type *)ga.ga_data) + ga.ga_len;
    p->field1 = v1;
    p->field2 = v2;
    ga.ga_len++;
2014-06-30 03:57:50 -04:00
Felipe Oliveira Carvalho
45e7814e6a Introduce GA_APPEND()
This macro is used to append an element to a growable array. It replaces this
common idiom:

   ga_grow(&ga, 1);
   ((item_type *)ga.ga_data)[ga.ga_len] = item;
   ++ga.ga_len;
2014-06-30 03:57:50 -04:00
Felipe Oliveira Carvalho
be3a4b6ca8 ga_growsize should be >= 1
I know it could be 0 sometimes. Running the tests with
`assert(gap->ga_growsize > 0)` in ga_grow() crashes nvim while running the
tests.

 - Add a setter for ga_growsize that checks whether the value passed is >=1 (log
	 in case it's not)
 - log when ga_grow() tries to use a ga_growsize that's not >=1
 - use GA_EMPTY_INIT_VALUE is many places
2014-06-30 03:57:50 -04:00
Felipe Oliveira Carvalho
f7e64c3c5f No OOM in vim_strnsave_up()
And some cleanup in strsave_up()
2014-06-16 01:36:30 -03:00
Douglas Schneider
bdf79dd619 Replace vim_strncpy calls: syntax.c 2014-06-13 18:08:21 -04:00
Nicolas Hillegeer
1a031af233 coverity/13770: add_keyword(), mark as false pos.
Also cleaned up the function a little bit.
2014-06-12 01:41:03 -04:00
Felipe Oliveira Carvalho
f39fd5b4c4 Declare garray iterators in the for() scope where possible #819 2014-06-10 14:15:21 -04:00
ZyX
70929f7e16 Add automatic generation of headers
- The 'stripdecls.py' script replaces declarations in all headers by includes to
  generated headers.
  `ag '#\s*if(?!ndef NEOVIM_).*((?!#\s*endif).*\n)*#ifdef INCLUDE_GENERATED'`
  was used for this.
- Add and integrate gendeclarations.lua into the build system to generate the
  required includes.
- Add -Wno-unused-function
- Made a bunch of old-style definitions ANSI

This adds a requirement: all type and structure definitions must be present
before INCLUDE_GENERATED_DECLARATIONS-protected include.

Warning: mch_expandpath (path.h.generated.h) was moved manually. So far it is
the only exception.
2014-06-02 11:04:17 -03:00
Hinidu
ef5d9ccefe Remove FEAT_STL_OPT
'statusline', 'rulerformat' and special format of 'titlestring' and
'iconstring' options
2014-05-28 13:08:54 -04:00
Hinidu
7c188b5498 Remove FEAT_CMDL_COMPL
Completion of mappings/abbreviations in command line mode
2014-05-28 13:08:54 -04:00
Felipe Oliveira Carvalho
21784aeb00 Replace alloc() with xmalloc() and remove immediate OOM checks 2014-05-19 14:50:23 -03:00
Felipe Oliveira Carvalho
a80d7e86c1 Remove NULL/non-NULL tests after calls to vim_str(n)save() 2014-05-19 14:50:23 -03:00
Felipe Oliveira Carvalho
bd2ab0d8a5 Replace if (ga->ga_len) with if (!GA_EMPTY(ga))
Used Coccinelle to perform the changes

```diff
@@
expression E;
statement S;
@@

(
- if (E.ga_len) S
+ if (!GA_EMPTY(&E)) S
|
- if (E->ga_len) S
+ if (!GA_EMPTY(E)) S
)
```
2014-05-17 07:02:44 -03:00
Felipe Oliveira Carvalho
5209d2271b Replace ga->ga_len == 0 checks with GA_EMPTY(ga)
Used Coccinelle to perform the changes

@@
expression E;
@@

<...
(
// E.ga_len == 0 is isomorphic to !E.ga_len
- E.ga_len == 0
+ GA_EMPTY(&E)
|
- E->ga_len == 0
+ GA_EMPTY(E)
)
...>
2014-05-17 07:02:44 -03:00
Felipe Oliveira Carvalho
b4efff6523 Replace ga->ga_len > 0 checks with !GA_EMPTY(ga)
Used Coccinelle to perform the changes

```diff
@@
expression E;
@@

<...
(
- E.ga_len > 0
+ !GA_EMPTY(&E)
|
- E->ga_len > 0
+ !GA_EMPTY(E)
)
...>
```

`spatch --in-place --sp-file ga_empty.cocci <C_FILE>`
2014-05-17 07:02:44 -03:00
Eliseo Martínez
762a8ad0f3 Introduce nvim namespace: Fix unmasked strings.h issue.
Problem:  Now that nvim/strings.h is correctly namespaced, an issue
          that had been masked until now arises:

          When compiling, we get a lot of errors because of everywhere
          the functions in nvim/strings.h are used, there's no include
          to import them.

          But, how could this compile and work previously, then? It
          turns out that:
          - In every such case, we are also including vim.h, which in
            turn includes os_unix_defs.h.
          - os_unix_defs.h includes <string.h> and also <strings.h> in
            some systems (e.g. OSX).
          - Build had been modified previously to (even when importing
            system headers), prefer equally-named local ones. That was
            in fact done as a previous attempt to solve the same issue
            we are trying to solve another way now.

          So, we were including our "strings.h" as a side-effect of
          including <strings.h> through "vim.h" --> "os_unix_defs.h".

Solution: Correctly include "nvim/strings.h" in every file needing it.
2014-05-15 20:46:02 +02:00
Eliseo Martínez
409cc138f2 Introduce nvim namespace: Fix project-local includes.
Prepend 'nvim/' in all project-local (non-system) includes.
2014-05-15 20:46:01 +02:00
Eliseo Martínez
da51dc9cf2 Introduce nvim namespace: Move files.
Move files from src/ to src/nvim/.
- src/nvim/ becomes the new root dir for nvim executable sources.
- src/libnvim/ is planned to become root dir of the neovim library.
2014-05-15 20:46:01 +02:00