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.
This commit is contained in:
dundargoc
2023-09-29 14:58:48 +02:00
committed by dundargoc
parent c513cbf361
commit acc646ad8f
57 changed files with 362 additions and 367 deletions

View File

@@ -619,7 +619,7 @@ static bool nlua_init_packages(lua_State *lstate, bool is_standalone)
lua_getfield(lstate, -1, "preload"); // [package, preload]
for (size_t i = 0; i < ARRAY_SIZE(builtin_modules); i++) {
ModuleDef def = builtin_modules[i];
lua_pushinteger(lstate, (long)i); // [package, preload, i]
lua_pushinteger(lstate, (lua_Integer)i); // [package, preload, i]
lua_pushcclosure(lstate, nlua_module_preloader, 1); // [package, preload, cclosure]
lua_setfield(lstate, -2, def.name); // [package, preload]

View File

@@ -80,7 +80,7 @@ int nlua_spell_check(lua_State *lstate)
lua_rawseti(lstate, -2, 2);
// +1 for 1-indexing
lua_pushinteger(lstate, (long)pos + 1);
lua_pushinteger(lstate, (lua_Integer)pos + 1);
lua_rawseti(lstate, -2, 3);
lua_rawseti(lstate, -2, ++no_res);

View File

@@ -183,8 +183,8 @@ int nlua_str_utfindex(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
size_t codepoints = 0, codeunits = 0;
mb_utflen(s1, (size_t)idx, &codepoints, &codeunits);
lua_pushinteger(lstate, (long)codepoints);
lua_pushinteger(lstate, (long)codeunits);
lua_pushinteger(lstate, (lua_Integer)codepoints);
lua_pushinteger(lstate, (lua_Integer)codeunits);
return 2;
}
@@ -204,7 +204,7 @@ static int nlua_str_utf_pos(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
size_t clen;
for (size_t i = 0; i < s1_len && s1[i] != NUL; i += clen) {
clen = (size_t)utf_ptr2len_len(s1 + i, (int)(s1_len - i));
lua_pushinteger(lstate, (long)i + 1);
lua_pushinteger(lstate, (lua_Integer)i + 1);
lua_rawseti(lstate, -2, (int)idx);
idx++;
}
@@ -276,7 +276,7 @@ int nlua_str_byteindex(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
return luaL_error(lstate, "index out of range");
}
lua_pushinteger(lstate, (long)byteidx);
lua_pushinteger(lstate, (lua_Integer)byteidx);
return 1;
}

View File

@@ -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) {