From 191fd228e247dfd07e7528e7a5ff6dc98547a578 Mon Sep 17 00:00:00 2001 From: cmagnush <34184494+cmagnush@users.noreply.github.com> Date: Sun, 27 Mar 2022 09:58:39 +0200 Subject: [PATCH] More fixes for NPP 8.3.3 plugin API compatibility Change more places to (u)intptr_t, and remove a rather obvious static_cast that prevented the previous commit to work with files > 2GB. --- src/LuaConsole.cpp | 2 +- src/NppExtensionAPI.cpp | 8 +++--- src/NppExtensionAPI.h | 6 ++-- src/SciTE/GUI.h | 2 +- src/SciTE/LuaExtension.cpp | 58 +++++++++++++++++++------------------- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/LuaConsole.cpp b/src/LuaConsole.cpp index 95f8669..ff5d700 100644 --- a/src/LuaConsole.cpp +++ b/src/LuaConsole.cpp @@ -363,7 +363,7 @@ void LuaConsole::showAutoCompletion() { // Back up past the partial word prevCh = static_cast(m_sciInput->Call(SCI_GETCHARAT, curPos - 1 - partialWord.size())); - curPos = curPos - static_cast(partialWord.size()); + curPos = curPos - partialWord.size(); } if (prevCh == '.' || prevCh == ':') { diff --git a/src/NppExtensionAPI.cpp b/src/NppExtensionAPI.cpp index d28fa2d..7c8d4c4 100644 --- a/src/NppExtensionAPI.cpp +++ b/src/NppExtensionAPI.cpp @@ -39,7 +39,7 @@ sptr_t NppExtensionAPI::Send(NppExtensionAPI::Pane p, unsigned int msg, uptr_t w return scis[p].Call(msg, wParam, lParam); } -char *NppExtensionAPI::Range(NppExtensionAPI::Pane p, int start, int end) { +char *NppExtensionAPI::Range(NppExtensionAPI::Pane p, intptr_t start, intptr_t end) { if (end <= start) return nullptr; char *dest = new char[end - start + 1]; @@ -52,14 +52,14 @@ char *NppExtensionAPI::Range(NppExtensionAPI::Pane p, int start, int end) { return dest; } -void NppExtensionAPI::Remove(NppExtensionAPI::Pane p, int start, int end) { +void NppExtensionAPI::Remove(NppExtensionAPI::Pane p, intptr_t start, intptr_t end) { if (end <= start) return; - int deleteLength = end - start; + intptr_t deleteLength = end - start; this->Send(p, SCI_DELETERANGE, start, deleteLength); } -void NppExtensionAPI::Insert(NppExtensionAPI::Pane p, int pos, const char *s) { +void NppExtensionAPI::Insert(NppExtensionAPI::Pane p, intptr_t pos, const char *s) { this->Send(p, SCI_INSERTTEXT, pos, reinterpret_cast(s)); } diff --git a/src/NppExtensionAPI.h b/src/NppExtensionAPI.h index c840820..fb98dbe 100644 --- a/src/NppExtensionAPI.h +++ b/src/NppExtensionAPI.h @@ -61,9 +61,9 @@ class NppExtensionAPI final { Pane getCurrentPane(); sptr_t Send(Pane p, unsigned int msg, uptr_t wParam = 0, sptr_t lParam = 0); - char *Range(Pane p, int start, int end); - void Remove(Pane p, int start, int end); - void Insert(Pane p, int pos, const char *s); + char *Range(Pane p, intptr_t start, intptr_t end); + void Remove(Pane p, intptr_t start, intptr_t end); + void Insert(Pane p, intptr_t pos, const char *s); void SetTextDirection(Pane p, bool rtl); void Trace(const char *s); void TraceError(const char *s); diff --git a/src/SciTE/GUI.h b/src/SciTE/GUI.h index 32f539a..97d16b6 100644 --- a/src/SciTE/GUI.h +++ b/src/SciTE/GUI.h @@ -170,7 +170,7 @@ class ScintillaWindow : public Window { status = fn(ptr, SCI_GETSTATUS, 0, 0); if (status > 0 && status < SC_STATUS_WARN_START) throw ScintillaFailure(status); - return static_cast(retVal); + return retVal; } sptr_t CallReturnPointer(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0) { sptr_t retVal = fn(ptr, msg, wParam, lParam); diff --git a/src/SciTE/LuaExtension.cpp b/src/SciTE/LuaExtension.cpp index 47b8c4d..1e143f6 100644 --- a/src/SciTE/LuaExtension.cpp +++ b/src/SciTE/LuaExtension.cpp @@ -646,8 +646,8 @@ static int cf_pane_textrange(lua_State *L) { NppExtensionAPI::Pane p = check_pane_object(L, 1); if (lua_gettop(L) >= 3) { - int cpMin = static_cast(luaL_checkinteger(L, 2)); - int cpMax = static_cast(luaL_checkinteger(L, 3)); + intptr_t cpMin = static_cast(luaL_checkinteger(L, 2)); + intptr_t cpMax = static_cast(luaL_checkinteger(L, 3)); if (cpMax >= 0) { char *range = host->Range(p, cpMin, cpMax); @@ -668,7 +668,7 @@ static int cf_pane_textrange(lua_State *L) { static int cf_pane_insert(lua_State *L) { NppExtensionAPI::Pane p = check_pane_object(L, 1); - int pos = (int)luaL_checkinteger(L, 2); + intptr_t pos = static_cast(luaL_checkinteger(L, 2)); const char *s = luaL_checkstring(L, 3); host->Insert(p, pos, s); return 0; @@ -676,8 +676,8 @@ static int cf_pane_insert(lua_State *L) { static int cf_pane_remove(lua_State *L) { NppExtensionAPI::Pane p = check_pane_object(L, 1); - int cpMin = static_cast(luaL_checkinteger(L, 2)); - int cpMax = static_cast(luaL_checkinteger(L, 3)); + intptr_t cpMin = static_cast(luaL_checkinteger(L, 2)); + intptr_t cpMax = static_cast(luaL_checkinteger(L, 3)); host->Remove(p, cpMin, cpMax); return 0; } @@ -685,7 +685,7 @@ static int cf_pane_remove(lua_State *L) { static int cf_pane_append(lua_State *L) { NppExtensionAPI::Pane p = check_pane_object(L, 1); const char *s = luaL_checkstring(L, 2); - host->Insert(p, static_cast(host->Send(p, SCI_GETLENGTH, 0, 0)), s); + host->Insert(p, host->Send(p, SCI_GETLENGTH, 0, 0), s); return 0; } @@ -719,17 +719,17 @@ static int cf_pane_findtext(lua_State *L) { if (!hasError) { if (nArgs > 3) { - ft.chrg.cpMin = static_cast(luaL_checkinteger(L, 4)); + ft.chrg.cpMin = static_cast(luaL_checkinteger(L, 4)); hasError = (lua_gettop(L) > nArgs); } } if (!hasError) { if (nArgs > 4) { - ft.chrg.cpMax = static_cast(luaL_checkinteger(L, 5)); + ft.chrg.cpMax = static_cast(luaL_checkinteger(L, 5)); hasError = (lua_gettop(L) > nArgs); } else { - ft.chrg.cpMax = static_cast(host->Send(p, SCI_GETLENGTH, 0, 0)); + ft.chrg.cpMax = host->Send(p, SCI_GETLENGTH, 0, 0); } } @@ -759,10 +759,10 @@ static int cf_pane_findtext(lua_State *L) { struct PaneMatchObject { NppExtensionAPI::Pane pane; - int startPos; - int endPos; + intptr_t startPos; + intptr_t endPos; int flags; // this is really part of the state, but is kept here for convenience - int endPosOrig; // has to do with preventing infinite loop on a 0-length match + intptr_t endPosOrig; // has to do with preventing infinite loop on a 0-length match }; static int cf_match_replace(lua_State *L) { @@ -786,7 +786,7 @@ static int cf_match_replace(lua_State *L) { host->Send(pmo->pane, SCI_SETTARGETSTART, pmo->startPos, 0); host->Send(pmo->pane, SCI_SETTARGETEND, pmo->endPos, 0); host->Send(pmo->pane, SCI_REPLACETARGET, lua_rawlen(L, 2), SptrFromString(replacement)); - pmo->endPos = static_cast(host->Send(pmo->pane, SCI_GETTARGETEND, 0, 0)); + pmo->endPos = host->Send(pmo->pane, SCI_GETTARGETEND, 0, 0); return 0; } @@ -878,7 +878,7 @@ static int cf_pane_match(lua_State *L) { if (nargs >= 3) { pmo->flags = (int)luaL_checkinteger(L, 3); if (nargs >= 4) { - pmo->endPos = pmo->endPosOrig = (int)luaL_checkinteger(L, 4); + pmo->endPos = pmo->endPosOrig = (intptr_t)luaL_checkinteger(L, 4); if (pmo->endPos < 0) { raise_error(L, "Invalid argument 3 for :match. Positive number or zero expected."); return 0; @@ -921,7 +921,7 @@ static int cf_pane_match_generator(lua_State *L) { return 0; } - int searchPos = pmo->endPos; + intptr_t searchPos = pmo->endPos; if ((pmo->startPos == pmo->endPosOrig) && (pmo->endPos == pmo->endPosOrig)) { // prevent infinite loop on zero-length match by stepping forward searchPos++; @@ -935,8 +935,8 @@ static int cf_pane_match_generator(lua_State *L) { if (ft.chrg.cpMax > ft.chrg.cpMin) { sptr_t result = host->Send(pmo->pane, SCI_FINDTEXT, static_cast(pmo->flags), SptrFromPointer(&ft)); if (result >= 0) { - pmo->startPos = static_cast(ft.chrgText.cpMin); - pmo->endPos = pmo->endPosOrig = static_cast(ft.chrgText.cpMax); + pmo->startPos = ft.chrgText.cpMin; + pmo->endPos = pmo->endPosOrig = ft.chrgText.cpMax; lua_pushvalue(L, 2); return 1; } @@ -1921,42 +1921,42 @@ struct StylingContext { void Colourize() { intptr_t end = currentPos - 1; - if (end >= static_cast(endDoc)) - end = static_cast(endDoc)-1; + if (end >= static_cast(endDoc)) + end = endDoc - 1; styler->ColourTo(end, state); } static int Line(lua_State *L) { StylingContext *context = Context(L); - int position = (int)luaL_checkinteger(L, 2); + intptr_t position = (intptr_t)luaL_checkinteger(L, 2); lua_pushinteger(L, context->styler->GetLine(position)); return 1; } static int CharAt(lua_State *L) { StylingContext *context = Context(L); - int position = (int)luaL_checkinteger(L, 2); + intptr_t position = (intptr_t)luaL_checkinteger(L, 2); lua_pushinteger(L, context->styler->SafeGetCharAt(position)); return 1; } static int StyleAt(lua_State *L) { StylingContext *context = Context(L); - int position = (int)luaL_checkinteger(L, 2); + intptr_t position = (intptr_t)luaL_checkinteger(L, 2); lua_pushinteger(L, context->styler->StyleAt(position)); return 1; } static int LevelAt(lua_State *L) { StylingContext *context = Context(L); - int line = (int)luaL_checkinteger(L, 2); + intptr_t line = (intptr_t)luaL_checkinteger(L, 2); lua_pushinteger(L, context->styler->LevelAt(line)); return 1; } static int SetLevelAt(lua_State *L) { StylingContext *context = Context(L); - int line = (int)luaL_checkinteger(L, 2); + intptr_t line = (intptr_t)luaL_checkinteger(L, 2); int level = (int)luaL_checkinteger(L, 3); context->styler->SetLevel(line, level); return 0; @@ -1964,14 +1964,14 @@ struct StylingContext { static int LineState(lua_State *L) { StylingContext *context = Context(L); - int line = (int)luaL_checkinteger(L, 2); + intptr_t line = (intptr_t)luaL_checkinteger(L, 2); lua_pushinteger(L, context->styler->GetLineState(line)); return 1; } static int SetLineState(lua_State *L) { StylingContext *context = Context(L); - int line = (int)luaL_checkinteger(L, 2); + intptr_t line = (intptr_t)luaL_checkinteger(L, 2); int stateOfLine = (int)luaL_checkinteger(L, 3); context->styler->SetLineState(line, stateOfLine); return 0; @@ -2018,7 +2018,7 @@ struct StylingContext { (currentPos >= endPos); } - void StartStyling(unsigned int startPos_, unsigned int length, int initStyle_) { + void StartStyling(uintptr_t startPos_, uintptr_t length, int initStyle_) { endDoc = styler->Length(); endPos = startPos_ + length; if (endPos == endDoc) @@ -2049,8 +2049,8 @@ struct StylingContext { static int StartStyling(lua_State *L) { StylingContext *context = Context(L); - unsigned int startPosStyle = (int)luaL_checkinteger(L, 2); - unsigned int lengthStyle = (int)luaL_checkinteger(L, 3); + uintptr_t startPosStyle = (uintptr_t)luaL_checkinteger(L, 2); + uintptr_t lengthStyle = (uintptr_t)luaL_checkinteger(L, 3); int initialStyle = (int)luaL_checkinteger(L, 4); context->StartStyling(startPosStyle, lengthStyle, initialStyle); return 0;