aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/private/helpers.c
Commit message (Collapse)AuthorAge
...
* api: api_info()['version']Justin M. Keyes2016-10-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | API level is disconnected from NVIM version. The API metadata holds the current API level, and the lowest backwards-compatible level supported by this instance. Release 0.1.6 is the first release that reports the Nvim version and API level. metadata['version'] = { major: 0, minor: 1, patch: 6, api_level: 1, api_compatible: 0, api_prerelease: false, } The API level may remain unchanged across Nvim releases if the API has not changed. When changing the API, - set NVIM_API_PRERELEASE to true - increment NVIM_API_LEVEL (at most once per Nvim version) - adjust NVIM_API_LEVEL_COMPAT if backwards-compatibility was broken api_level_0.mpack was generated from Nvim 0.1.5 with: nvim --api-info
* api: Nvim version, API level #5386Rui Abreu Ferreira2016-10-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The API level is disconnected from the NVIM version. The API metadata holds the current API level, and the lowest backwards-compatible level supported by this instance. Release 0.1.6 will be the first release reporting the Nvim version and API level. metadata['version'] = { major: 0, minor: 1, patch: 6, prerelease: true, api_level: 1, api_compatible: 0, } The API level may remain unchanged across Neovim releases if the API has not changed. When changing the API the CMake variable NVIM_API_PRERELEASE is set to true, and NVIM_API_CURRENT/NVIM_API_COMPATIBILITY are incremented accordingly. The functional tests check the API table against fixtures of past versions of Neovim. It compares all the functions in the old table with the new one, it does ignore some metadata attributes that do not alter the function signature or were removed since 0.1.5. Currently the only fixture is 0.mpack, generated from Neovim 0.1.5 with nvim --api-info.
* api: move verbatim c code out of gendispatch.lua and into c filesBjörn Linse2016-10-19
| | | | | Remove max_fname_len check, which caused false successful lookups, and was an optimization for a very rare case.
* lint: Removing dead initializations #5410Patrick Jackson2016-10-08
|
* api: make nvim[_obj]_set_var and _del_var not return the old valueBjörn Linse2016-09-15
|
* helpers.c: Fix invalid state of failed conversion result for object_to_vim() ↵oni-link2016-09-01
| | | | | | | | | | | (#5282) If a conversion for a container fails in object_to_vim(), the memory for the container in the returned/converted value is freed, but the returned value keeps a pointer to the freed memory. Calling later clear_tv() on this value leads to an invalid memory access. Set v_type to VAR_UNKNOWN in the converted value on failure, so that clear_tv() has no effect.
* api: consistently use nvim_ prefix and update documentationBjörn Linse2016-08-31
|
* api: unify buffer numbers and window ids with handlesBjörn Linse2016-08-31
| | | | also allow handle==0 meaning curbuf/curwin/curtab
* *: Fix linter errorsZyX2016-06-24
| | | | | | | | | Also adds one exception to linter rules: typedef struct { kvec_t(Object) stack; } EncodedData; is completely valid (from the style guide point of view) code.
* api/helpers: Use typval_encode.h for vim_to_objectZyX2016-06-24
| | | | | | | | | | | | | This ought to prevent stack overflow, but I do not see this actually working: *lua* code crashes with stack overflow when trying to deserialize msgpack from Neovim, Neovim is fine even if nesting level is increased 100x (though test becomes very slow); not sure how recursive function may survive this. So it looks like there are currently only two positive effects: 1. NULL lists are returned as empty (#4596). 2. Functional tests are slightly more fast. Very slightly. Checked for Release build for test/functional/eval tests because benchmarking of debug mode is not very useful.
* api: Replace set_var(name, NIL) with del_var(name)ZyX2016-04-18
|
* eval: Remove v:noneZyX2016-04-18
| | | | | To get v:none back just rever this commit. This will not make json*() functions compatible with Vim though.
* eval: Add special variables v:false, v:null, v:noneZyX2016-04-18
|
* eval: Add special variable typeZyX2016-04-18
|
* shada: Refactor history merger to use statically sized 2linked listZyX2015-10-08
| | | | | | | Also fixes the error: when writing shada files existing history items may be freed. Warning: valgrind reports some memory leaks.
* ASan: Fix "null pointer passed for argument declared to never be null". #2925Florian Walch2015-06-30
| | | | | | | | Arguments passed to xmemdupz() are sometimes NULL, but xmemdupz() has FUNC_ATTR_NONNULL_ALL. Check pointers for NULL before calling xmemdupz(). Resolves #2533.
* api: vim_set_var() should return the old value #2899Justin M. Keyes2015-06-25
| | | | Closes #2816
* object_to_vim: Recognize buffers, windows, tabpages.Scott Prager2015-04-13
|
* memory: Add `free` wrapper and refactor project to use itThiago de Arruda2015-04-13
| | | | | | We already use wrappers for allocation, the new `xfree` function is the equivalent for deallocation and provides a way to fully replace the malloc implementation used by Neovim.
* api: always return empty string as api type StringBjörn Linse2015-02-16
|
* Discard exceptions once they are converted to API errorsJake Kerr2015-02-12
| | | | Fixes: #1976
* Remove os/provider.{c,h} and all of its referencesThiago de Arruda2014-11-18
|
* msgpack-rpc: Improve logging of msgpack-rpc messagesThiago de Arruda2014-10-23
| | | | | | | | | | - Expose more logging control from the log.c module(get log stream and omit newlines) - Remove logging from the generated functions in msgpack-gen.lua - Refactor channel.c/helpers.c to log every msgpack-rpc payload using msgpack_object_print(a helper function from msgpack.h) - Remove the api_stringify function, it was only useful for logging msgpack-rpc which is now handled by msgpack_object_print.
* debug: Improve debugging of msgpack-rpc requestsThiago de Arruda2014-10-22
| | | | | | - Add the api_stringify function to display API objects - Use api_stringify to display request arguments and return values in DLOG statements.
* api/msgpack-rpc: Improve error infrastructureThiago de Arruda2014-09-18
| | | | | | | | | | | | | | | | - Add error type information to `Error` - Rename `set_api_error` to `api_set_error` for consistency with other api_* functions/macros. - Refactor the api_set_error macro to accept formatted strings and error types - Improve error messages - Wrap error messages with gettext macro - Refactor msgpack-rpc serialization to transform Error instances into [type, message] arrays - Add error type information to API metadata - Normalize nvim->client and client->nvim error handling(change channel_send_call to accept an Error pointer instead of the `errored` boolean pointer) - Use macro to initialize Error structures
* api/msgpack-rpc: Refactor metadata object constructionThiago de Arruda2014-09-12
| | | | | | | | | Instead of building all metadata from msgpack-gen.lua, we now merge the generated part with manual information(such as types and features). The metadata is accessible through the api method `vim_get_api_info`. This was done to simplify the generator while also increasing flexibility(by being able to add more metadata)
* api/msgpack-rpc: Refactor msgpack_rpc_helpers.{c,h}Thiago de Arruda2014-09-12
| | | | | | - Move helpers that are specific to API types to api/private/helpers.{c,h} - Include headers with generated declarations - Delete unused macros
* Add helper cstr_as_string()Rui Abreu Ferreira2014-08-07
| | | | - Add nocopy helper alternative to cstr_to_string
* Use strict function prototypes #945Pavel Platto2014-07-14
| | | | | | | | | | | | | | | | | | | `-Wstrict-prototypes` warn if a function is declared or defined without specifying the argument types. This warning disallow function prototypes with empty parameter list. In C, a function declared with an empty parameter list accepts an arbitrary number of arguments when being called. This is for historic reasons; originally, C functions didn't have prototypes, as C evolved from B, a typeless language. When prototypes were added, the original typeless declarations were left in the language for backwards compatibility. Instead we should provide `void` in argument list to state that function doesn't have arguments. Also this warning disallow declaring type of the parameters after the parentheses because Neovim header generator produce no declarations for old-stlyle prototypes: it expects to find `{` after prototype.
* move assert.h include out of vim.hBrandon Coleman2014-07-09
|
* move ascii.h include out of vim.hBrandon Coleman2014-07-09
|
* channel/msgpack_rpc: Refactor API dispatchingThiago de Arruda2014-06-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is how API dispatching worked before this commit: - The generated `msgpack_rpc_dispatch` function receives a the `msgpack_packer` argument. - The response is incrementally built while validating/calling the API. - Return values/errors are also packed into the `msgpack_packer` while the final response is being calculated. Now the `msgpack_packer` argument is no longer provided, and the `msgpack_rpc_dispatch` function returns `Object`/`Error` values to `msgpack_rpc_call`, which will use those values to build the response in a single pass. This was done because the new `channel_send_call` function created the possibility of having recursive API invocations, and this wasn't possible when sharing a single `msgpack_sbuffer` across call frames(it was shared implicitly through the `msgpack_packer` instance). Since we only start to build the response when the necessary information has been computed, it's now safe to share a single `msgpack_sbuffer` instance across all channels and API invocations. Some other changes also had to be performed: - Handling of the metadata discover was moved to `msgpack_rpc_call` - Expose more types as subtypes of `Object`, this was required to forward the return value from `msgpack_rpc_dispatch` to `msgpack_rpc_call` - Added more helper macros for casting API types to `Object` any
* channel: Implement the 'channel_send_call' functionThiago de Arruda2014-06-24
| | | | | | | | This function is used to send RPC calls to clients. In contrast to `channel_send_event`, this function will block until the client sends a response(But it will continue processing requests from that client). The RPC call stack has a maximum depth of 20.
* api: Rename find_{buffer,window,tabpage}Thiago de Arruda2014-06-18
| | | | | They were renamed to find_{buffer,window,tabpage}_by_handle to avoid conflicts with existing functions of the same name.
* api: unify string conversions, simplify interopNicolas Hillegeer2014-06-08
| | | | | | | | | | | | | - The data member of String's can now be passed directly to functions expecting C strings, as we now guarantee that they are NUL-terminated. This obviates the need to use xstrndup and free, simplifying code and enhancing performance. - Use xmemdupz instead of xstrndup for converting String's into C strings. It's faster because it doesn't calculate strlen(string.data) (which is unnecesary as that information is already provided in string.size anyway). - Use cstr_to_string to convert from C strings to String, it is both shorter and faster than the usual strlen/xstrndup combo, which calls strlen twice. cstr_to_string internally calls strlen and then xmemdupz.
* api: also NUL-terminate Strings made from cstrsNicolas Hillegeer2014-06-08
| | | | | | I believe we can now mostly assume that all encountered String's data members are safe to pass into functions that accept C strings. That should simplify interop with C string code.
* Add automatic generation of headersZyX2014-06-02
| | | | | | | | | | | | | | | | | - 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.
* Move documentation from function declarations to definitionsZyX2014-06-02
| | | | Uses a perl script to move it (scripts/movedocs.pl)
* Initialize Object, PositionJustin M. Keyes2014-05-31
| | | | | fix #778 thanks @genisaguilar
* Refactor: Redefine `Map(T)` as a more generic `Map(T, U)` macroThiago de Arruda2014-05-30
| | | | | To replace `Map(T)`, a new macro `PMap(T)` was defined as `Map(T, ptr_t)` for writing maps that store pointers with less boilerplate
* API: Bugfix: Remove memory leak from set_option_toThiago de Arruda2014-05-26
|
* API: Refactor: Duplicate/free string arguments coming from msgpackThiago de Arruda2014-05-26
| | | | | | | | | When receiving strings *from* msgpack, we don't need to duplicate/free since the data only lives in the msgpack parse buffer until the end of the call. But in order to reuse `msgpack_rpc_free_object` when sending event data(which is sent *to* msgpack), Strings must be freed, which means they must also be allocated separately.
* coverity: fix BUFFER_SIZE_WARNING with str{n,l}cpyNicolas Hillegeer2014-05-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Relates to issue #760 These coverity warnings are of the form: >>> CID 62602: Buffer not null terminated (BUFFER_SIZE_WARNING) >>> Calling strncpy with a maximum size argument of 256 bytes... This is caused by strncpy not alway NULL-terminated the destination buffer (for example in the case where strlen(src) >= size(dst)). It's better to replace that with (x)strlcpy, which always NULL-terminates. Most of these are related to the set_api_error macro, which uses strncpy. The error struct is used (for example) in msgpack_rpc_error, where strlen is executed on it, so it needs to be NULL-terminated. (x)strlcpy, unlike strncpy, always NULL-terminates the destination buffer. Relevant parts of the coverity report: *** CID 62602: Buffer not null terminated (BUFFER_SIZE_WARNING) /src/nvim/api/vim.c: 236 in vim_set_current_buffer() 230 if (try_end(err)) { 231 return; 232 } 233 234 char msg[256]; 235 snprintf(msg, sizeof(msg), "failed to switch to buffer %d", (int)buffer); >>> CID 62602: Buffer not null terminated (BUFFER_SIZE_WARNING) >>> Calling strncpy with a maximum size argument of 256 bytes on >>> destination array "err->msg" of size 256 bytes might leave the >>> destination string unterminated. 236 set_api_error(msg, err); 237 return; 238 } 239 240 try_end(err); 241 } *** CID 62603: Buffer not null terminated (BUFFER_SIZE_WARNING) /src/nvim/api/private/helpers.c: 70 in try_end() 64 } else if (msg_list != NULL && *msg_list != NULL) { 65 int should_free; 66 char *msg = (char *)get_exception_string(*msg_list, 67 ET_ERROR, 68 NULL, 69 &should_free); >>> CID 62603: Buffer not null terminated (BUFFER_SIZE_WARNING) >>> Calling strncpy with a maximum size argument of 256 bytes on >>> destination array "err->msg" of size 256 bytes might leave the >>> destination string unterminated. 70 strncpy(err->msg, msg, sizeof(err->msg)); 71 err->set = true; 72 free_global_msglist(); 73 74 if (should_free) { 75 free(msg); /src/nvim/api/private/helpers.c: 78 in try_end() 72 free_global_msglist(); 73 74 if (should_free) { 75 free(msg); 76 } 77 } else if (did_throw) { >>> CID 62603: Buffer not null terminated (BUFFER_SIZE_WARNING) >>> Calling strncpy with a maximum size argument of 256 bytes on >>> destination array "err->msg" of size 256 bytes might leave the >>> destination string unterminated. 78 set_api_error((char *)current_exception->value, err); 79 } 80 81 return err->set; 82 } 83 *** CID 62604: Buffer not null terminated (BUFFER_SIZE_WARNING) /src/nvim/api/private/helpers.c: 592 in set_option_value_err() 586 opt_flags))) 587 { 588 if (try_end(err)) { 589 return; 590 } 591 >>> CID 62604: Buffer not null terminated (BUFFER_SIZE_WARNING) >>> Calling strncpy with a maximum size argument of 256 bytes on >>> destination array "err->msg" of size 256 bytes might leave the >>> destination string unterminated. 592 set_api_error(errmsg, err); 593 } *** CID 62605: Buffer not null terminated (BUFFER_SIZE_WARNING) /src/nvim/os/server.c: 114 in server_start() 108 if (addr_len > sizeof(ip) - 1) { 109 // Maximum length of a ip address buffer is 15(eg: 255.255.255.255) 110 addr_len = sizeof(ip); 111 } 112 113 // Extract the address part >>> CID 62605: Buffer not null terminated (BUFFER_SIZE_WARNING) >>> Calling strncpy with a maximum size argument of 16 bytes on >>> destination array "ip" of size 16 bytes might leave the destination >>> string unterminated. 114 strncpy(ip, addr, addr_len); 115 116 int port = NEOVIM_DEFAULT_TCP_PORT; 117 118 if (*ip_end == ':') { 119 char *port_end; /src/nvim/os/server.c: 88 in server_start() 82 83 void server_start(char *endpoint, ChannelProtocol prot) 84 { 85 char addr[ADDRESS_MAX_SIZE]; 86 87 // Trim to `ADDRESS_MAX_SIZE` >>> CID 62605: Buffer not null terminated (BUFFER_SIZE_WARNING) >>> Calling strncpy with a maximum size argument of 256 bytes on >>> destination array "addr" of size 256 bytes might leave the >>> destination string unterminated. 88 strncpy(addr, endpoint, sizeof(addr)); 89 90 // Check if the server already exists 91 if (map_has(cstr_t)(servers, addr)) { 92 EMSG2("Already listening on %s", addr); 93 return; *** CID 62606: Buffer not null terminated (BUFFER_SIZE_WARNING) /src/nvim/os/server.c: 186 in server_stop() 180 void server_stop(char *endpoint) 181 { 182 Server *server; 183 char addr[ADDRESS_MAX_SIZE]; 184 185 // Trim to `ADDRESS_MAX_SIZE` >>> CID 62606: Buffer not null terminated (BUFFER_SIZE_WARNING) >>> Calling strncpy with a maximum size argument of 256 bytes on >>> destination array "addr" of size 256 bytes might leave the >>> destination string unterminated. 187 188 if ((server = map_get(cstr_t)(servers, addr)) == NULL) { 189 EMSG2("Not listening on %s", addr); 190 return; 191 }
* API: Refactor: Return handles instead of indexesThiago de Arruda2014-05-23
| | | | | | | - Define specialized arrays for each remote object type - Implement msgpack_rpc functions for dealing with the new types - Refactor all functions dealing with buffers, windows and tabpages to return/accept handles instead of list indexes.
* API: Refactor: Change the integer type of remote objects to uint64_tThiago de Arruda2014-05-23
|
* API: Refactor: Move non-public files to private subdirectoryThiago de Arruda2014-05-23