From 7224c889e0d5d70b99ae377036baa6377c33a568 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:25:24 +0100 Subject: build: enable MSVC level 3 warnings (#21934) MSVC has 4 different warning levels: 1 (severe), 2 (significant), 3 (production quality) and 4 (informational). Enabling level 3 warnings mostly revealed conversion problems, similar to GCC/clang -Wconversion flag. --- src/nvim/lua/xdiff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 857b159af5..9a7ae5c146 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -257,13 +257,13 @@ static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, if (check_xdiff_opt(v->type, kObjectTypeInteger, "ctxlen", err)) { goto exit_1; } - cfg->ctxlen = v->data.integer; + cfg->ctxlen = (long)v->data.integer; } else if (strequal("interhunkctxlen", k.data)) { if (check_xdiff_opt(v->type, kObjectTypeInteger, "interhunkctxlen", err)) { goto exit_1; } - cfg->interhunkctxlen = v->data.integer; + cfg->interhunkctxlen = (long)v->data.integer; } else if (strequal("linematch", k.data)) { *linematch = api_object_to_bool(*v, "linematch", false, err); if (ERROR_SET(err)) { -- cgit From 9e7426718b678e299f3fd03ef94f81b1e2d01ab0 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 4 Apr 2023 23:59:39 +0100 Subject: feat(vim.diff): allow passing an integer for linematch --- src/nvim/lua/xdiff.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 9a7ae5c146..e0bbdb8942 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -32,7 +32,7 @@ typedef struct { Error *err; mmfile_t *ma; mmfile_t *mb; - bool linematch; + int64_t linematch; bool iwhite; } hunkpriv_t; @@ -128,7 +128,7 @@ static int hunk_locations_cb(long start_a, long count_a, long start_b, long coun { hunkpriv_t *priv = (hunkpriv_t *)cb_data; lua_State *lstate = priv->lstate; - if (priv->linematch) { + if (priv->linematch > 0 && count_a + count_b <= priv->linematch) { get_linematch_results(lstate, priv->ma, priv->mb, start_a, count_a, start_b, count_b, priv->iwhite); } else { @@ -208,7 +208,7 @@ static bool check_xdiff_opt(ObjectType actType, ObjectType expType, const char * } static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, xpparam_t *params, - bool *linematch, Error *err) + int64_t *linematch, Error *err) { const DictionaryOf(LuaRef) opts = nlua_pop_Dictionary(lstate, true, err); @@ -265,8 +265,12 @@ static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, } cfg->interhunkctxlen = (long)v->data.integer; } else if (strequal("linematch", k.data)) { - *linematch = api_object_to_bool(*v, "linematch", false, err); - if (ERROR_SET(err)) { + if (v->type == kObjectTypeBoolean) { + *linematch = v->data.boolean ? INT64_MAX : 0; + } else if (v->type == kObjectTypeInteger) { + *linematch = v->data.integer; + } else { + api_set_error(err, kErrorTypeValidation, "linematch must be a boolean or integer"); goto exit_1; } } else { @@ -330,7 +334,7 @@ int nlua_xdl_diff(lua_State *lstate) xdemitconf_t cfg; xpparam_t params; xdemitcb_t ecb; - bool linematch = false; + int64_t linematch = 0; CLEAR_FIELD(cfg); CLEAR_FIELD(params); -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/lua/xdiff.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index e0bbdb8942..b5575fe202 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -193,10 +193,10 @@ static bool check_xdiff_opt(ObjectType actType, ObjectType expType, const char * { if (actType != expType) { const char *type_str = - expType == kObjectTypeString ? "string" : - expType == kObjectTypeInteger ? "integer" : - expType == kObjectTypeBoolean ? "boolean" : - expType == kObjectTypeLuaRef ? "function" : + expType == kObjectTypeString ? "string" : + expType == kObjectTypeInteger ? "integer" : + expType == kObjectTypeBoolean ? "boolean" : + expType == kObjectTypeLuaRef ? "function" : "NA"; api_set_error(err, kErrorTypeValidation, "%s is not a %s", name, -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/lua/xdiff.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index b5575fe202..000aad85d1 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "luaconf.h" -- cgit From 8e932480f61d6101bf8bea1abc07ed93826221fd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/lua/xdiff.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 000aad85d1..5aba1b839b 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -71,8 +71,8 @@ static void get_linematch_results(lua_State *lstate, mmfile_t *ma, mmfile_t *mb, const char *diff_begin[2] = { ma->ptr, mb->ptr }; int diff_length[2] = { (int)count_a, (int)count_b }; - fastforward_buf_to_lnum(&diff_begin[0], start_a + 1); - fastforward_buf_to_lnum(&diff_begin[1], start_b + 1); + fastforward_buf_to_lnum(&diff_begin[0], (linenr_T)start_a + 1); + fastforward_buf_to_lnum(&diff_begin[1], (linenr_T)start_b + 1); int *decisions = NULL; size_t decisions_length = linematch_nbuffers(diff_begin, diff_length, 2, &decisions, iwhite); @@ -125,7 +125,7 @@ static int write_string(void *priv, mmbuffer_t *mb, int nbuf) } // hunk_func callback used when opts.hunk_lines = true -static int hunk_locations_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data) +static int hunk_locations_cb(int start_a, int count_a, int start_b, int count_b, void *cb_data) { hunkpriv_t *priv = (hunkpriv_t *)cb_data; lua_State *lstate = priv->lstate; @@ -140,7 +140,7 @@ static int hunk_locations_cb(long start_a, long count_a, long start_b, long coun } // hunk_func callback used when opts.on_hunk is given -static int call_on_hunk_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data) +static int call_on_hunk_cb(int start_a, int count_a, int start_b, int count_b, void *cb_data) { // Mimic extra offsets done by xdiff, see: // src/xdiff/xemit.c:284 -- cgit From 5f03a1eaabfc8de2b3a9c666fcd604763f41e152 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 20 Oct 2023 15:10:33 +0200 Subject: build(lint): remove unnecessary clint.py rules Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. --- src/nvim/lua/xdiff.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 5aba1b839b..56d1fdb8ab 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -367,18 +367,18 @@ int nlua_xdl_diff(lua_State *lstate) cfg.hunk_func = call_on_hunk_cb; priv = (hunkpriv_t) { .lstate = lstate, - .err = &err, + .err = &err, }; ecb.priv = &priv; break; case kNluaXdiffModeLocations: cfg.hunk_func = hunk_locations_cb; priv = (hunkpriv_t) { - .lstate = lstate, - .ma = &ma, - .mb = &mb, + .lstate = lstate, + .ma = &ma, + .mb = &mb, .linematch = linematch, - .iwhite = (params.flags & XDF_IGNORE_WHITESPACE) > 0 + .iwhite = (params.flags & XDF_IGNORE_WHITESPACE) > 0 }; ecb.priv = &priv; lua_createtable(lstate, 0, 0); -- cgit From acc646ad8fc3ef11fcc63b69f3d8484e4a91accd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/lua/xdiff.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 56d1fdb8ab..e131bbb586 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -64,12 +64,12 @@ static void lua_pushhunk(lua_State *lstate, long start_a, long count_a, long sta lua_rawseti(lstate, -2, (signed)lua_objlen(lstate, -2) + 1); } -static void get_linematch_results(lua_State *lstate, mmfile_t *ma, mmfile_t *mb, long start_a, - long count_a, long start_b, long count_b, bool iwhite) +static void get_linematch_results(lua_State *lstate, mmfile_t *ma, mmfile_t *mb, int start_a, + int count_a, int start_b, int count_b, bool iwhite) { // get the pointer to char of the start of the diff to pass it to linematch algorithm const char *diff_begin[2] = { ma->ptr, mb->ptr }; - int diff_length[2] = { (int)count_a, (int)count_b }; + int diff_length[2] = { count_a, count_b }; fastforward_buf_to_lnum(&diff_begin[0], (linenr_T)start_a + 1); fastforward_buf_to_lnum(&diff_begin[1], (linenr_T)start_b + 1); @@ -77,12 +77,12 @@ static void get_linematch_results(lua_State *lstate, mmfile_t *ma, mmfile_t *mb, int *decisions = NULL; size_t decisions_length = linematch_nbuffers(diff_begin, diff_length, 2, &decisions, iwhite); - long lnuma = start_a, lnumb = start_b; + int lnuma = start_a, lnumb = start_b; - long hunkstarta = lnuma; - long hunkstartb = lnumb; - long hunkcounta = 0; - long hunkcountb = 0; + int hunkstarta = lnuma; + int hunkstartb = lnumb; + int hunkcounta = 0; + int hunkcountb = 0; for (size_t i = 0; i < decisions_length; i++) { if (i && (decisions[i - 1] != decisions[i])) { lua_pushhunk(lstate, hunkstarta, hunkcounta, hunkstartb, hunkcountb); @@ -110,8 +110,8 @@ static int write_string(void *priv, mmbuffer_t *mb, int nbuf) { luaL_Buffer *buf = (luaL_Buffer *)priv; for (int i = 0; i < nbuf; i++) { - const long size = mb[i].size; - for (long total = 0; total < size; total += LUAL_BUFFERSIZE) { + const int size = mb[i].size; + for (int total = 0; total < size; total += LUAL_BUFFERSIZE) { const int tocopy = MIN((int)(size - total), LUAL_BUFFERSIZE); char *p = luaL_prepbuffer(buf); if (!p) { -- 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/xdiff.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index e131bbb586..f3f78b79f5 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.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/xdiff.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index f3f78b79f5..29e3bbefd0 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -13,6 +13,7 @@ #include "nvim/lua/xdiff.h" #include "nvim/macros.h" #include "nvim/memory.h" +#include "nvim/pos.h" #include "nvim/vim.h" #include "xdiff/xdiff.h" -- cgit From a6e3d93421ba13c407a96fac9cc01fa41ec7ad98 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 Nov 2023 10:59:11 +0100 Subject: refactor: enable formatting for ternaries This requires removing the "Inner expression should be aligned" rule from clint as it prevents essentially any formatting regarding ternary operators. --- src/nvim/lua/xdiff.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 29e3bbefd0..bf52ae4232 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -192,11 +192,11 @@ static bool check_xdiff_opt(ObjectType actType, ObjectType expType, const char * { if (actType != expType) { const char *type_str = - expType == kObjectTypeString ? "string" : - expType == kObjectTypeInteger ? "integer" : - expType == kObjectTypeBoolean ? "boolean" : - expType == kObjectTypeLuaRef ? "function" : - "NA"; + expType == kObjectTypeString + ? "string" : (expType == kObjectTypeInteger + ? "integer" : (expType == kObjectTypeBoolean + ? "boolean" : (expType == kObjectTypeLuaRef + ? "function" : "NA"))); api_set_error(err, kErrorTypeValidation, "%s is not a %s", name, type_str); -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/lua/xdiff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index bf52ae4232..6ce88400d1 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -13,7 +13,7 @@ #include "nvim/lua/xdiff.h" #include "nvim/macros.h" #include "nvim/memory.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/vim.h" #include "xdiff/xdiff.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/lua/xdiff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 6ce88400d1..93c8933649 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -11,10 +11,10 @@ #include "nvim/lua/converter.h" #include "nvim/lua/executor.h" #include "nvim/lua/xdiff.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/memory.h" #include "nvim/pos_defs.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "xdiff/xdiff.h" #define COMPARED_BUFFER0 (1 << 0) -- cgit From 86cc791debba09c8ed1aa0d863be844108866a38 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 23:10:21 +0800 Subject: refactor: move function macros out of vim_defs.h (#26300) --- src/nvim/lua/xdiff.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/lua/xdiff.c') diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 93c8933649..16c3aa5e11 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -14,7 +14,6 @@ #include "nvim/macros_defs.h" #include "nvim/memory.h" #include "nvim/pos_defs.h" -#include "nvim/vim_defs.h" #include "xdiff/xdiff.h" #define COMPARED_BUFFER0 (1 << 0) -- cgit