aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/map.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-02-24 20:09:14 +0100
committerJustin M. Keyes <justinkz@gmail.com>2019-02-27 23:29:07 +0100
commit89515304e4eb81ff9eb65f3a582136fc658de139 (patch)
tree24b445c4aa5588772aa98f830f4646a738727810 /src/nvim/map.c
parent1d8e7683604828592bd41cdac5a351145cd93487 (diff)
downloadrneovim-89515304e4eb81ff9eb65f3a582136fc658de139.tar.gz
rneovim-89515304e4eb81ff9eb65f3a582136fc658de139.tar.bz2
rneovim-89515304e4eb81ff9eb65f3a582136fc658de139.zip
os/env: use libuv v1.12 getenv/setenv API
- Minimum required libuv is now v1.12 - Because `uv_os_getenv` requires allocating, we must manage a map (`envmap` in `env.c`) to maintain the old behavior of `os_getenv` . - free() map-items after removal. khash.h does not make copies of anything, so even its keys must be memory-managed by the caller. closes #8398 closes #9267
Diffstat (limited to 'src/nvim/map.c')
-rw-r--r--src/nvim/map.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/nvim/map.c b/src/nvim/map.c
index 53ab734802..9b6f57a56f 100644
--- a/src/nvim/map.c
+++ b/src/nvim/map.c
@@ -1,6 +1,13 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
+///
+/// map.c: khash.h wrapper
+///
+/// NOTE: Callers must manage memory (allocate) for keys and values.
+/// khash.h does not make its own copy of the key or value.
+///
+
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
@@ -72,6 +79,16 @@
return kh_get(T##_##U##_map, map->table, key) != kh_end(map->table); \
} \
\
+ T map_##T##_##U##_key(Map(T, U) *map, T key) \
+ { \
+ khiter_t k; \
+ \
+ if ((k = kh_get(T##_##U##_map, map->table, key)) == kh_end(map->table)) { \
+ abort(); /* Caller must check map_has(). */ \
+ } \
+ \
+ return kh_key(map->table, k); \
+ } \
U map_##T##_##U##_put(Map(T, U) *map, T key, U value) \
{ \
int ret; \
@@ -167,3 +184,18 @@ MAP_IMPL(String, MsgpackRpcRequestHandler, MSGPACK_HANDLER_INITIALIZER)
#define KVEC_INITIALIZER { .size = 0, .capacity = 0, .items = NULL }
MAP_IMPL(HlEntry, int, DEFAULT_INITIALIZER)
MAP_IMPL(String, handle_T, 0)
+
+
+/// Deletes a key:value pair from a string:pointer map, and frees the
+/// storage of both key and value.
+///
+void pmap_del2(PMap(cstr_t) *map, const char *key)
+{
+ if (pmap_has(cstr_t)(map, key)) {
+ void *k = (void *)pmap_key(cstr_t)(map, key);
+ void *v = pmap_get(cstr_t)(map, key);
+ pmap_del(cstr_t)(map, key);
+ xfree(k);
+ xfree(v);
+ }
+}