diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-04-13 09:30:57 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-04-13 09:30:57 -0300 |
commit | a9ee85b9fc2d4e3faa466e9c3062cd41315f8456 (patch) | |
tree | e45187575c9f0397c5d717780b61adf5b3976a62 /src/nvim/os | |
parent | 0248c75bc190ec2fbc8f3af3d61f771e76d628d6 (diff) | |
parent | 2d104f14dbd2c60a30e9e1e0fef098b39db087db (diff) | |
download | rneovim-a9ee85b9fc2d4e3faa466e9c3062cd41315f8456.tar.gz rneovim-a9ee85b9fc2d4e3faa466e9c3062cd41315f8456.tar.bz2 rneovim-a9ee85b9fc2d4e3faa466e9c3062cd41315f8456.zip |
Merge PR #2415 'Use jemalloc instead of libc allocator'
Diffstat (limited to 'src/nvim/os')
-rw-r--r-- | src/nvim/os/env.c | 22 | ||||
-rw-r--r-- | src/nvim/os/event.c | 1 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 4 | ||||
-rw-r--r-- | src/nvim/os/job_private.h | 9 | ||||
-rw-r--r-- | src/nvim/os/pipe_process.c | 4 | ||||
-rw-r--r-- | src/nvim/os/pty_process.c | 4 | ||||
-rw-r--r-- | src/nvim/os/rstream.c | 10 | ||||
-rw-r--r-- | src/nvim/os/shell.c | 10 | ||||
-rw-r--r-- | src/nvim/os/signal.c | 16 | ||||
-rw-r--r-- | src/nvim/os/wstream.c | 36 |
10 files changed, 46 insertions, 70 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index fd6237c5b0..37158f4d3c 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -113,7 +113,7 @@ void init_homedir(void) char_u *var; /* In case we are called a second time (when 'encoding' changes). */ - free(homedir); + xfree(homedir); homedir = NULL; var = (char_u *)os_getenv("HOME"); @@ -144,7 +144,7 @@ void init_homedir(void) void free_homedir(void) { - free(homedir); + xfree(homedir); } #endif @@ -304,7 +304,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, char_u *p = vim_strsave(var); if (mustfree) { - free(var); + xfree(var); } var = p; mustfree = true; @@ -318,7 +318,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, char_u *p = vim_strsave_escaped(var, (char_u *)" \t"); if (mustfree) - free(var); + xfree(var); var = p; mustfree = true; } @@ -341,7 +341,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, copy_char = false; } if (mustfree) - free(var); + xfree(var); } if (copy_char) { /* copy at least one char */ @@ -380,11 +380,11 @@ static char *vim_version_dir(char *vimdir) p = concat_fnames((char_u *)vimdir, (char_u *)VIM_VERSION_NODOT, true); if (os_isdir(p)) return (char *)p; - free(p); + xfree(p); p = concat_fnames((char_u *)vimdir, (char_u *)RUNTIME_DIRNAME, true); if (os_isdir(p)) return (char *)p; - free(p); + xfree(p); return NULL; } @@ -483,7 +483,7 @@ char_u *vim_getenv(char_u *name, bool *mustfree) p = vim_strnsave(p, (size_t)(pend - p)); if (!os_isdir(p)) { - free(p); + xfree(p); p = NULL; } else { *mustfree = true; @@ -634,7 +634,7 @@ void home_replace(buf_T *buf, char_u *src, char_u *dst, int dstlen, bool one) *dst = NUL; if (homedir_env != homedir_env_orig) - free(homedir_env); + xfree(homedir_env); } /// Like home_replace, store the replaced string in allocated memory. @@ -663,7 +663,7 @@ void vim_setenv(char_u *name, char_u *val) if (*val != NUL && STRICMP(name, "VIMRUNTIME") == 0) { char_u *buf = concat_str(val, (char_u *)"/lang"); bindtextdomain(VIMPACKAGE, (char *)buf); - free(buf); + xfree(buf); } } @@ -678,7 +678,7 @@ char_u *get_env_name(expand_T *xp, int idx) char *envname = os_getenvname_at_index((size_t)idx); if (envname) { STRLCPY(name, envname, ENVNAMELEN); - free(envname); + xfree(envname); return name; } else { return NULL; diff --git a/src/nvim/os/event.c b/src/nvim/os/event.c index dbb9d337cf..0560da1e2e 100644 --- a/src/nvim/os/event.c +++ b/src/nvim/os/event.c @@ -46,7 +46,6 @@ void event_init(void) // early msgpack-rpc initialization msgpack_rpc_init_method_table(); msgpack_rpc_helpers_init(); - wstream_init(); // Initialize input events input_init(); // Timer to wake the event loop if a timeout argument is passed to diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index d583323b1f..2a41001cde 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -152,14 +152,14 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath) *abspath = save_absolute_path(buf); } - free(buf); + xfree(buf); return true; } if (*e != ':') { // End of $PATH without finding any executable called name. - free(buf); + xfree(buf); return false; } diff --git a/src/nvim/os/job_private.h b/src/nvim/os/job_private.h index af13d2e636..983106d918 100644 --- a/src/nvim/os/job_private.h +++ b/src/nvim/os/job_private.h @@ -11,6 +11,7 @@ #include "nvim/os/pty_process.h" #include "nvim/os/shell.h" #include "nvim/log.h" +#include "nvim/memory.h" struct job { // Job id the index in the job table plus one. @@ -104,12 +105,12 @@ static inline void job_decref(Job *job) // Invoke the exit_cb job_exit_callback(job); // Free all memory allocated for the job - free(job->proc_stdin->data); - free(job->proc_stdout->data); - free(job->proc_stderr->data); + xfree(job->proc_stdin->data); + xfree(job->proc_stdout->data); + xfree(job->proc_stderr->data); shell_free_argv(job->opts.argv); process_destroy(job); - free(job); + xfree(job); } } diff --git a/src/nvim/os/pipe_process.c b/src/nvim/os/pipe_process.c index 5535c3fe93..2ac305e967 100644 --- a/src/nvim/os/pipe_process.c +++ b/src/nvim/os/pipe_process.c @@ -72,8 +72,8 @@ void pipe_process_init(Job *job) void pipe_process_destroy(Job *job) { UvProcess *pipeproc = job->process; - free(pipeproc->proc.data); - free(pipeproc); + xfree(pipeproc->proc.data); + xfree(pipeproc); job->process = NULL; } diff --git a/src/nvim/os/pty_process.c b/src/nvim/os/pty_process.c index 9a2721f769..c64f3f9932 100644 --- a/src/nvim/os/pty_process.c +++ b/src/nvim/os/pty_process.c @@ -65,8 +65,8 @@ void pty_process_init(Job *job) FUNC_ATTR_NONNULL_ALL void pty_process_destroy(Job *job) FUNC_ATTR_NONNULL_ALL { - free(job->opts.term_name); - free(job->process); + xfree(job->opts.term_name); + xfree(job->process); job->process = NULL; } diff --git a/src/nvim/os/rstream.c b/src/nvim/os/rstream.c index 29b8a5a9e1..702f282d53 100644 --- a/src/nvim/os/rstream.c +++ b/src/nvim/os/rstream.c @@ -162,8 +162,8 @@ size_t rbuffer_available(RBuffer *rbuffer) void rbuffer_free(RBuffer *rbuffer) { - free(rbuffer->data); - free(rbuffer); + xfree(rbuffer->data); + xfree(rbuffer); } /// Creates a new RStream instance. A RStream encapsulates all the boilerplate @@ -216,7 +216,7 @@ void rstream_free(RStream *rstream) } rbuffer_free(rstream->buffer); - free(rstream); + xfree(rstream); } /// Sets the underlying `uv_stream_t` instance @@ -401,8 +401,8 @@ static void fread_idle_cb(uv_idle_t *handle) static void close_cb(uv_handle_t *handle) { - free(handle->data); - free(handle); + xfree(handle->data); + xfree(handle); } static void rbuffer_relocate(RBuffer *rbuffer) diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 6fcb62a5f3..4f5928ba8a 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -80,11 +80,11 @@ void shell_free_argv(char **argv) while (*p != NULL) { // Free each argument - free(*p); + xfree(*p); p++; } - free(argv); + xfree(argv); } /// Calls the user-configured 'shell' (p_sh) for running a command or wildcard @@ -128,11 +128,11 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args) emsg_silent, forward_output); - free(input.data); + xfree(input.data); if (output) { (void)write_output(output, nread, true, true); - free(output); + xfree(output); } if (!emsg_silent && status != 0 && !(opts & kShellOptSilent)) { @@ -250,7 +250,7 @@ static int shell(const char *cmd, if (buf.len == 0) { // no data received from the process, return NULL *output = NULL; - free(buf.data); + xfree(buf.data); } else { // NUL-terminate to make the output directly usable as a C string buf.data[buf.len] = NUL; diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index a332ad2314..f824543003 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -1,9 +1,8 @@ +#include <assert.h> #include <stdbool.h> #include <uv.h> -#include "nvim/lib/klist.h" - #include "nvim/ascii.h" #include "nvim/vim.h" #include "nvim/globals.h" @@ -15,10 +14,6 @@ #include "nvim/os/signal.h" #include "nvim/os/event.h" -#define SignalEventFreer(x) -KMEMPOOL_INIT(SignalEventPool, int, SignalEventFreer) -kmempool_t(SignalEventPool) *signal_event_pool = NULL; - static uv_signal_t spipe, shup, squit, sterm; #ifdef SIGPWR static uv_signal_t spwr; @@ -32,7 +27,6 @@ static bool rejecting_deadly; void signal_init(void) { - signal_event_pool = kmp_init(SignalEventPool); uv_signal_init(uv_default_loop(), &spipe); uv_signal_init(uv_default_loop(), &shup); uv_signal_init(uv_default_loop(), &squit); @@ -119,18 +113,16 @@ static void deadly_signal(int signum) static void signal_cb(uv_signal_t *handle, int signum) { - int *n = kmp_alloc(SignalEventPool, signal_event_pool); - *n = signum; + assert(signum >= 0); event_push((Event) { .handler = on_signal_event, - .data = n + .data = (void *)(uintptr_t)signum }, false); } static void on_signal_event(Event event) { - int signum = *((int *)event.data); - kmp_free(SignalEventPool, signal_event_pool, event.data); + int signum = (int)(uintptr_t)event.data; switch (signum) { #ifdef SIGPWR diff --git a/src/nvim/os/wstream.c b/src/nvim/os/wstream.c index 13c6c0429f..73896c381d 100644 --- a/src/nvim/os/wstream.c +++ b/src/nvim/os/wstream.c @@ -5,8 +5,6 @@ #include <uv.h> -#include "nvim/lib/klist.h" - #include "nvim/os/uv_helpers.h" #include "nvim/os/wstream.h" #include "nvim/os/wstream_defs.h" @@ -41,24 +39,10 @@ typedef struct { uv_write_t uv_req; } WRequest; -#define WRequestFreer(x) -KMEMPOOL_INIT(WRequestPool, WRequest, WRequestFreer) -kmempool_t(WRequestPool) *wrequest_pool = NULL; -#define WBufferFreer(x) -KMEMPOOL_INIT(WBufferPool, WBuffer, WBufferFreer) -kmempool_t(WBufferPool) *wbuffer_pool = NULL; - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/wstream.c.generated.h" #endif -/// Initialize pools for reusing commonly created objects -void wstream_init(void) -{ - wrequest_pool = kmp_init(WRequestPool); - wbuffer_pool = kmp_init(WBufferPool); -} - /// Creates a new WStream instance. A WStream encapsulates all the boilerplate /// necessary for writing to a libuv stream. /// @@ -92,7 +76,7 @@ void wstream_free(WStream *wstream) { uv_close((uv_handle_t *)wstream->stream, close_cb); } else { handle_set_wstream((uv_handle_t *)wstream->stream, NULL); - free(wstream); + xfree(wstream); } } else { wstream->freed = true; @@ -163,7 +147,7 @@ bool wstream_write(WStream *wstream, WBuffer *buffer) wstream->curmem += buffer->size; - WRequest *data = kmp_alloc(WRequestPool, wrequest_pool); + WRequest *data = xmalloc(sizeof(WRequest)); data->wstream = wstream; data->buffer = buffer; data->uv_req.data = data; @@ -173,7 +157,7 @@ bool wstream_write(WStream *wstream, WBuffer *buffer) uvbuf.len = buffer->size; if (uv_write(&data->uv_req, wstream->stream, &uvbuf, 1, write_cb)) { - kmp_free(WRequestPool, wrequest_pool, data); + xfree(data); goto err; } @@ -202,7 +186,7 @@ WBuffer *wstream_new_buffer(char *data, size_t refcount, wbuffer_data_finalizer cb) { - WBuffer *rv = kmp_alloc(WBufferPool, wbuffer_pool); + WBuffer *rv = xmalloc(sizeof(WBuffer)); rv->size = size; rv->refcount = refcount; rv->cb = cb; @@ -232,11 +216,11 @@ static void write_cb(uv_write_t *req, int status) if (data->wstream->free_handle) { uv_close((uv_handle_t *)data->wstream->stream, close_cb); } else { - free(data->wstream); + xfree(data->wstream); } } - kmp_free(WRequestPool, wrequest_pool, data); + xfree(data); } void wstream_release_wbuffer(WBuffer *buffer) @@ -246,14 +230,14 @@ void wstream_release_wbuffer(WBuffer *buffer) buffer->cb(buffer->data); } - kmp_free(WBufferPool, wbuffer_pool, buffer); + xfree(buffer); } } static void close_cb(uv_handle_t *handle) { - free(handle_get_wstream(handle)); - free(handle->data); - free(handle); + xfree(handle_get_wstream(handle)); + xfree(handle->data); + xfree(handle); } |