From 224f303ee54c54d2147f03010385e8cc48e42869 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:15:32 -0500 Subject: feat(stdlib): add vim.base64 module (#25843) Add base64 encode() and decode() functions to a vim.base64 module. --- src/nvim/lua/base64.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/nvim/lua/base64.c (limited to 'src/nvim/lua/base64.c') diff --git a/src/nvim/lua/base64.c b/src/nvim/lua/base64.c new file mode 100644 index 0000000000..3f246839d5 --- /dev/null +++ b/src/nvim/lua/base64.c @@ -0,0 +1,65 @@ +#include +#include +#include + +#include "nvim/base64.h" +#include "nvim/lua/base64.h" +#include "nvim/memory.h" + +static int nlua_base64_encode(lua_State *L) +{ + if (lua_gettop(L) < 1) { + return luaL_error(L, "Expected 1 argument"); + } + + if (lua_type(L, 1) != LUA_TSTRING) { + luaL_argerror(L, 1, "expected string"); + } + + size_t src_len = 0; + const char *src = lua_tolstring(L, 1, &src_len); + + const char *ret = base64_encode(src, src_len); + assert(ret != NULL); + lua_pushstring(L, ret); + xfree((void *)ret); + + return 1; +} + +static int nlua_base64_decode(lua_State *L) +{ + if (lua_gettop(L) < 1) { + return luaL_error(L, "Expected 1 argument"); + } + + if (lua_type(L, 1) != LUA_TSTRING) { + luaL_argerror(L, 1, "expected string"); + } + + size_t src_len = 0; + const char *src = lua_tolstring(L, 1, &src_len); + + const char *ret = base64_decode(src, src_len); + if (ret == NULL) { + return luaL_error(L, "Invalid input"); + } + + lua_pushstring(L, ret); + xfree((void *)ret); + + return 1; +} + +static const luaL_Reg base64_functions[] = { + { "encode", nlua_base64_encode }, + { "decode", nlua_base64_decode }, + { NULL, NULL }, +}; + +int luaopen_base64(lua_State *L) +{ + lua_newtable(L); + luaL_register(L, NULL, base64_functions); + return 1; +} -- cgit From c4ad15ae324f6460c683a64c44d65e693e1f39bb Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 11 Nov 2023 10:59:02 +0100 Subject: fix(PVS/V009): add top-level message --- src/nvim/lua/base64.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/lua/base64.c') diff --git a/src/nvim/lua/base64.c b/src/nvim/lua/base64.c index 3f246839d5..b6382f6eab 100644 --- a/src/nvim/lua/base64.c +++ b/src/nvim/lua/base64.c @@ -1,3 +1,6 @@ +// 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 + #include #include #include -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/lua/base64.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/lua/base64.c') diff --git a/src/nvim/lua/base64.c b/src/nvim/lua/base64.c index b6382f6eab..3f246839d5 100644 --- a/src/nvim/lua/base64.c +++ b/src/nvim/lua/base64.c @@ -1,6 +1,3 @@ -// 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 - #include #include #include -- cgit From bb4b4576e384c71890b4df4fa4f1ae76fad3a59d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Nov 2023 10:55:54 +0800 Subject: refactor: iwyu (#26062) --- src/nvim/lua/base64.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/lua/base64.c') diff --git a/src/nvim/lua/base64.c b/src/nvim/lua/base64.c index 3f246839d5..c1f43a37d7 100644 --- a/src/nvim/lua/base64.c +++ b/src/nvim/lua/base64.c @@ -1,11 +1,16 @@ #include #include #include +#include #include "nvim/base64.h" #include "nvim/lua/base64.h" #include "nvim/memory.h" +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "lua/base64.c.generated.h" +#endif + static int nlua_base64_encode(lua_State *L) { if (lua_gettop(L) < 1) { -- cgit