Commit Graph

641 Commits

Author SHA1 Message Date
Eliseo Martínez
bddba93949 Fix warnings: eval.c: f_termopen(): Use-after-free: MI.
Problem    : Use-after-free @ 15081.
Diagnostic : Multithreading issue.
Rationale  : `get_dict_callback` can return NULL on two different
             cases: 1) when the dict doesn't contain the given key;
             this case is not considered an error. 2) when the key
             exists but there's some problem with its value; this is
             considered an error.
             Then, code calling `get_dict_callback` in
             `common_job_callbacks`, as well as code calling
             `common_job_callbacks`, uses `did_emsg` to distinguish
             between error/non-error cases.
             Suggested error path presumes an error condition within
             `common_job_callbacks`, with `did_emsg` being true, but
             then being false just after returning to calling code in
             `f_termopen`.
             That, clearly, could only happen if another thread run in
             between those points.
Resolution : Refactor `get_dict_callback` and `common_job_callbacks`, so
             that they clearly distinguish between error/non-error
             situations, without recurring to globals.
2015-04-07 20:04:33 -04:00
Eliseo Martínez
31581bd750 Fix warnings: eval.c: f_jobstart(): Np dereference: FP.
Problem    : Dereference of null pointer @ 10812.
Diagnostic : False positive.
Rationale  : `args->lv_first` can't be NULL, as we have just stated
             above that that there's at least one item.
Resolution : Assert.
2015-04-07 20:04:33 -04:00
Thiago de Arruda
d487dc1a9a eval: Ensure all job callbacks are invoked by jobwait()
A call to `event_poll` is required to ensure the exit callback from the last job
is invoked.
2015-04-02 11:33:48 -03:00
Thiago de Arruda
2b7f460716 eval: Add internal_refcount field to dict_T
Due to the way vimscript garbage collection handles cyclic references, its not
possible to rely on incrementing `dv_refcount` to prevent dicts still used
internally from being collected: If a object with dv_refcount > 0 isn't
reachable by vimscript code, it will be freed when `garbage_collect()` is
called. Add the `internal_refcount` field to prevent this.
2015-04-02 11:33:48 -03:00
Scott Prager
0f4976687d os_scandir: fname_case -> path_fix_case
Use os_scandir().

fname_case() only gets used when `defined(USE_FNAME_CASE)` (on operating
systems with case-insensitive file systems), but may be useful in other
contexts, so move it to path.c. (See the TODO.)

Remove the unused parameter, len.
2015-03-31 11:20:23 -03:00
Harm te Hennepe
27ead64da0 Create new mode() value for terminal-mode ('t') #2287 2015-03-27 05:25:28 -04:00
Thiago de Arruda
88d8ca73f9 eval: Improve validation of ids passed to job functions
Use the `is_user_job` to ensure that the job was started by `jobstart` or
`termopen`.
2015-03-29 20:35:45 -03:00
Thiago de Arruda
b8b9e5ebad eval: Implement jobclose() vimscript function 2015-03-29 20:35:44 -03:00
Thiago de Arruda
028f6d7d3f eval: Implement jobwait() vimscript function 2015-03-29 20:35:44 -03:00
Thiago de Arruda
6e7757ad51 eval: Refactor vimscript job control API
- Remove JobActivity autocmd and v:job_data variable
- Simplify `jobstart` to receive:
  - An argument vector
  - An optional dictionary which may contain any of the current `jobstart`
    options plus `on_stdout`, `on_stderr` and `on_exit` callbacks.
- Refactor and add more job tests
- Update documentation
2015-03-29 20:35:44 -03:00
Thiago de Arruda
4b98ea1e80 eval: Refactor call_func and func_unref
- Make it possible to call or unref ufunc_T pointers directly.
- Keep refcount of named functions, and stop them from being deleted if the
  refcount is greater than 1.
2015-03-29 20:35:44 -03:00
oni-link
727f524167 job: Fix memory errors
- Free memory allocated for job data when the job table is full.
2015-03-25 18:57:35 -03:00
Thiago de Arruda
cdedd89d22 terminal: New module that implements a terminal emulator
This commit integrates libvterm with Neovim and implements a terminal emulator
with nvim buffers as the display mechanism. Terminal buffers can be created
using any of the following methods:

- Opening a file with name following the "term://[${cwd}//[${pid}:]]${cmd}"
  URI pattern where:
  - cwd is the working directory of the process
  - pid is the process id. This is just for use in session files where a pid
    would have been assigned to the saved buffer title.
  - cmd is the command to run
- Invoking the `:terminal` ex command
- Invoking the `termopen` function which returns a job id for automating the
  terminal window.

Some extra changes were also implemented to adapt with terminal buffers. Here's
an overview:

- The `main` function now sets a BufReadCmd autocmd to intercept the term:// URI
  and spawn the terminal buffer instead of reading the file.
- terminal buffers behave as if the following local buffer options were set:
  - `nomodifiable`
  - `swapfile`
  - `undolevels=-1`
  - `bufhidden=hide`
- All commands that delete buffers(`:bun`, `:bd` and `:bw`) behave the same for
  terminal buffers, but only work when bang is passed(eg: `:bwipeout!`)
- A new "terminal" mode was added. A consequence is that a new set of mapping
  commands were implemented with the "t" prefix(tmap, tunmap, tnoremap...)
- The `edit` function(which enters insert mode) will actually enter terminal
  mode if the current buffer is a terminal
- The `put` operator was adapted to send data to the terminal instead of
  modifying the buffer directly.
- A window being resized will also trigger a terminal resize if the window
  displays the terminal.
2015-03-25 18:57:35 -03:00
Justin M. Keyes
adfc8cf50a doc: Misc. cleanup
Add missing parentheses and whatnot, move dangling comment, etc. Some
specific items worth mentioning:

Fixed some references to non-existent tags, found via `make html`

msgpack_rpc/channel.c:
  ELOG already prefixes each line with "error @ ..."
2015-03-24 19:29:29 -04:00
bobtwinkles
03d47965c0 refactor: split some more functions from misc1.c
This commit pulls the some environment-variable handling functions out of
misc1.c and in to os/env.c. Previously submited as #1231, this is the start of
a patch series that does that work based on a more up-to-date master branch.

Major tasks accomplished:
  - move functions and fix includes
  - fix clint/clang analysis warnings
  - correct documentation comments
2015-03-24 16:13:00 -04:00
Michael Reed
eea804ab59 Remove *_BUILTIN_TCAPS & 'ttybuiltin'
'ttybuiltin' was removed and *_BUILTIN_TCAPS was made into dead code in
PR #1820.
2015-03-22 15:41:29 -04:00
Perry Hung
26e6bca769 vim-patch:7.4.503 #2178
Problem:    Cannot append a list of lines to a file.
Solution:   Add the append option to writefile(). (Yasuhiro Matsumoto)

https://code.google.com/p/vim/source/detail?r=v7-4-503

-Ported old legacy test over to
    test/functional/legacy/writefile_spec.lua
-Tests for mapping and signs from the original patch were removed since
    they have nothing to do this with feature

Tested with: make oldtest, make test on OS X.

Signed-off-by: Perry Hung <iperry@gmail.com>
2015-03-20 17:54:28 -04:00
Anton Ovchinnikov
4fd8c3cbbb Reuse f_browse function from f_browsedir
The bodies of f_browse() and f_browsedir() were identical.
2015-03-16 11:01:09 -04:00
Björn Linse
4f92178a75 config: split out versiondef.h from config.h
This avoids recompiling every c file after comitting.
2015-03-08 21:54:57 -04:00
oni-link
0dd1ad0760 vim-patch:7.4.578
Problem:    Using getcurpos() after "$" in an empty line returns a negative
            number.
Solution:   Don't add one when this would overflow. (Hirohito Higashi)

https://code.google.com/p/vim/source/detail?r=v7-4-578
2015-03-04 18:25:52 +01:00
Björn Linse
5be040ffe4 jobsend: Don't append extra newline after last item
This allows sending binary data that is not newline terminated
2015-03-03 20:18:24 +01:00
Mike Zeller
f28941b96d illumos requires the use of limits.h for things like INT_MAX #2049 2015-02-26 11:42:05 -05:00
Thiago de Arruda
d7e560e5b3 job: Allow spawning jobs connected to pseudo terminals 2015-02-23 21:43:33 -03:00
Thiago de Arruda
1ec7db70ec job: Refactor process spawning and startup arguments
- process spawning was decoupled from the rest of the job control logic.  The
  goal is reusing it for spawning processes connected to pseudo terminal file
  descriptors.
- job_start now receives a JobOptions structure containing all the startup
  options.
2015-02-23 21:43:33 -03:00
Thiago de Arruda
d28011ee1c eval: Fix buffering of data in job autocommands
Job autocommands will no longer buffer data chunks that don't end in newlines
characters.
2015-02-23 21:43:33 -03:00
Thiago de Arruda
3baba1e7bc refactor: Remove term modules and termcap options
- Removed term.c, term.h and term_defs.h
- Tests for T_* values were removed. screen.c was simplified as a
  consequence(the best strategy for drawing is implemented in the UI layer)
- Redraw functions now call ui.c functions directly. Updates are flushed with
  `ui_flush()`
- Removed all termcap options(they now return empty strings for compatibility)
- &term/&ttybuiltin options return a constant value(nvim)
- &t_Co is still available, but it mirrors t_colors directly
- Remove cursor tracking from screen.c and the `screen_start` function. Now the
  UI is expected to maintain cursor state across any call, and reset it when
  resized.
- Remove unused code
2015-02-21 05:08:21 -03:00
Fabian Brosda
0a7cd65cbc vim-patch:7.4.525 #1988
Problem:    map() leaks memory when there is an error in the expression.
Solution:   Call clear_tv(). (Christian Brabandt)

https://code.google.com/p/vim/source/detail?r=v7-4-525
2015-02-19 17:08:43 -05:00
Eliseo Martínez
7dd48d7af0 Enable -Wconversion: mark.c.
Refactoring summary:
- MB_STRNICMP: Inlined.
- MB_STRNCMP: Inlined.
2015-02-18 20:54:13 -05:00
Thiago de Arruda
d8f3458ec7 syntax: Refactor to store all term and gui attributes independently
Now the attrentry_T structure will store all attributes in separate fields for
cterm and rgb UIs.
2015-02-16 23:17:39 -03:00
Thiago de Arruda
e0e41b30c6 ui: Remove/adapt some old code for a big UI refactor
- Remove abstract_ui global, now it is always active
- Remove some terminal handling code
- Remove unused functions
- Remove HAVE_TGETENT/TERMINFO/TERMIOS/IOCTL #ifdefs
- Remove tgetent/terminfo from version.c
- Remove curses/terminfo dependencies
- Only start/stop termcap when starting/exiting the program
- msg_use_printf will return true if there are no attached UIs(
  messages will be written to stdout)
- Remove `ex_winpos`(implement `:winpos` with `ex_ni`)
2015-02-16 23:17:39 -03:00
Eliseo Martínez
00f18e2e09 Remove nonnullret deadcode: xmalloc. 2015-01-27 01:33:34 +01:00
Eliseo Martínez
d228b8a93e Remove nonnullret deadcode: vim_strsave. 2015-01-27 01:33:33 +01:00
Pavel Platto
85f342a110 vim-patch:7.4.446
Problem:    In some situations, when setting up an environment to trigger an
	    autocommand, the environment is not properly restored.
Solution:   Check the return value of switch_win() and call restore_win()
	    always.  (Daniel Hahler)

https://code.google.com/p/vim/source/detail?r=v7-4-446
2015-01-20 21:09:45 +02:00
Eliseo Martínez
b716b047e0 Remove long_u: ex_docmd.c: Refactor long_u. 2015-01-19 19:47:27 +01:00
Justin M. Keyes
5c6348e999 Merge pull request #1816 from Pyrohh/macro_cleanup
Macro cleanup
2015-01-15 09:59:45 -05:00
Michael Reed
d86ebc7afb Macro cleanup: PROTO
Regarding dict_lookup() in eval.c: both definitions are the same, the
only difference being the spacing between the indirection operator and
the indentation level.
2015-01-14 15:07:16 -05:00
Thiago de Arruda
3e9c55b51b main: Fix color schemes for abstract_ui
- Set 't_Co' to 256 at startup. The value can be changed by the user for
  compatibility with terminals that are less capable.
- `has('gui_running')` will return 1 if at least one rgb UI is attached.

Even though these changes are hacky, they are necessary to make the transition
to the new UI architecture smoother.
2015-01-13 21:21:20 -03:00
Justin M. Keyes
d7e18b5c95 Revert "[WIP] "abstract_ui" fixes and improvements" 2015-01-12 10:14:52 -05:00
Justin M. Keyes
4c55c34efa Merge pull request #1657 from tarruda/abstract-ui-fixes
[WIP] "abstract_ui" fixes and improvements
2015-01-12 10:13:51 -05:00
Eliseo Martínez
7f7262e933 Cleanup: Rename getdigits() family functions. 2015-01-11 21:04:08 +01:00
Eliseo Martínez
04c0658024 Cleanup: Refactor getdigits().
Problem  : getdigits() currently returns a long, but at most places,
           return value is casted (unsafely) into an int. Making casts
           safe would introduce a lot of fuss in the form of assertions
           checking for limits.
Note     : We cannot just change return type to int, because, at some
           places, legitimate long values are used. For example, in
           diff.c, for line numbers.
Solution : Introduce new functions:
           - get_digits()      : Gets an intmax_t from a string.
           - get_int_digits()  : Wrapper for ints.
           - get_long_digits() : Wrapper for longs.
           And replace getdigits() invocations by the appropiate
           wrapper invocations.
2015-01-11 17:18:39 +01:00
Thiago de Arruda
748920d505 ui: Test for abstract_ui whenever a minimal t_colors value is required
t_colors should not be checked when abstract_ui is active, because nvim UI is
not limited to a terminal.
2015-01-10 21:41:32 -03:00
Justin M. Keyes
a684cc175a Merge pull request #1761 from oni-link/speed.up.gc
Speed up garbage collection (Issue 1687).
2015-01-10 09:55:55 -05:00
Eliseo Martínez
31c8440fee Remove long_u: term: Enable -Wconversion. 2015-01-10 10:52:21 +01:00
Björn Linse
40d77a3d2b eval: fix incorrect refcount in list_append_list 2015-01-07 17:38:41 +01:00
oni-link
36ba1d9fba Speed up garbage collection.
For garbage collection all lists are kept in first_list, a list of all
lists.

free_unref_items() searches through first_list and removes unreferenced
lists from it (by calling list_free(..., FALSE)). But after a list was
removed, the search continues from the beginning of first_list (not sure
how many lists were really removed and where to continue in first_list).

This is not necessary anymore since vim-patch 7.0.135, because a call to
list_free(...,FALSE) makes sure, that no other lists (and dictionaries)
are freed. So we always know, that the next list in first_list is
still valid (allocated or NULL) and can be used to continue the search.

Likewise for dictionaries.

Original patch by Ariya Mizutani
https://groups.google.com/forum/#!searchin/vim_dev/GC/vim_dev/DBYOdHQWvqY/1WH04_dwETIJ
2014-12-31 17:08:26 +01:00
Justin M. Keyes
13d950f6ed Merge pull request #1738 from fwalch/vim-7.4.549
vim-patch:7.4.549
2014-12-30 00:03:44 -05:00
Florian Walch
898f01dee1 vim-patch:7.4.549
Problem:    Function name not recognized correctly when inside a function.
Solution:   Don't check for an alpha character.

https://code.google.com/p/vim/source/detail?r=v7-4-549
2014-12-27 11:38:32 +01:00
Florian Walch
4ad5b245f0 vim-patch:7.4.541
Problem:    Crash when doing a range assign.
Solution:   Check for NULL poiter. (Yukihiro Nakadaira)

https://code.google.com/p/vim/source/detail?r=v7-4-541
2014-12-25 18:54:12 +01:00
Florian Walch
3286176406 vim-patch:7.4.516
Problem:    Completing a function name containing a # does not work.  Issue
	    253.
Solution:   Recognize the # character. (Christian Brabandt)

https://code.google.com/p/vim/source/detail?r=v7-4-516
2014-12-24 00:32:53 +01:00