Skip to content

Commit 191fd22

Browse files
committed
More fixes for NPP 8.3.3 plugin API compatibility
Change more places to (u)intptr_t, and remove a rather obvious static_cast<intptr_t> that prevented the previous commit to work with files > 2GB.
1 parent b39e09f commit 191fd22

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

src/LuaConsole.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ void LuaConsole::showAutoCompletion() {
363363

364364
// Back up past the partial word
365365
prevCh = static_cast<int>(m_sciInput->Call(SCI_GETCHARAT, curPos - 1 - partialWord.size()));
366-
curPos = curPos - static_cast<int>(partialWord.size());
366+
curPos = curPos - partialWord.size();
367367
}
368368

369369
if (prevCh == '.' || prevCh == ':') {

src/NppExtensionAPI.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sptr_t NppExtensionAPI::Send(NppExtensionAPI::Pane p, unsigned int msg, uptr_t w
3939
return scis[p].Call(msg, wParam, lParam);
4040
}
4141

42-
char *NppExtensionAPI::Range(NppExtensionAPI::Pane p, int start, int end) {
42+
char *NppExtensionAPI::Range(NppExtensionAPI::Pane p, intptr_t start, intptr_t end) {
4343
if (end <= start) return nullptr;
4444

4545
char *dest = new char[end - start + 1];
@@ -52,14 +52,14 @@ char *NppExtensionAPI::Range(NppExtensionAPI::Pane p, int start, int end) {
5252
return dest;
5353
}
5454

55-
void NppExtensionAPI::Remove(NppExtensionAPI::Pane p, int start, int end) {
55+
void NppExtensionAPI::Remove(NppExtensionAPI::Pane p, intptr_t start, intptr_t end) {
5656
if (end <= start) return;
5757

58-
int deleteLength = end - start;
58+
intptr_t deleteLength = end - start;
5959
this->Send(p, SCI_DELETERANGE, start, deleteLength);
6060
}
6161

62-
void NppExtensionAPI::Insert(NppExtensionAPI::Pane p, int pos, const char *s) {
62+
void NppExtensionAPI::Insert(NppExtensionAPI::Pane p, intptr_t pos, const char *s) {
6363
this->Send(p, SCI_INSERTTEXT, pos, reinterpret_cast<LPARAM>(s));
6464
}
6565

src/NppExtensionAPI.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class NppExtensionAPI final {
6161
Pane getCurrentPane();
6262

6363
sptr_t Send(Pane p, unsigned int msg, uptr_t wParam = 0, sptr_t lParam = 0);
64-
char *Range(Pane p, int start, int end);
65-
void Remove(Pane p, int start, int end);
66-
void Insert(Pane p, int pos, const char *s);
64+
char *Range(Pane p, intptr_t start, intptr_t end);
65+
void Remove(Pane p, intptr_t start, intptr_t end);
66+
void Insert(Pane p, intptr_t pos, const char *s);
6767
void SetTextDirection(Pane p, bool rtl);
6868
void Trace(const char *s);
6969
void TraceError(const char *s);

src/SciTE/GUI.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class ScintillaWindow : public Window {
170170
status = fn(ptr, SCI_GETSTATUS, 0, 0);
171171
if (status > 0 && status < SC_STATUS_WARN_START)
172172
throw ScintillaFailure(status);
173-
return static_cast<int>(retVal);
173+
return retVal;
174174
}
175175
sptr_t CallReturnPointer(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0) {
176176
sptr_t retVal = fn(ptr, msg, wParam, lParam);

src/SciTE/LuaExtension.cpp

+29-29
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ static int cf_pane_textrange(lua_State *L) {
646646
NppExtensionAPI::Pane p = check_pane_object(L, 1);
647647

648648
if (lua_gettop(L) >= 3) {
649-
int cpMin = static_cast<int>(luaL_checkinteger(L, 2));
650-
int cpMax = static_cast<int>(luaL_checkinteger(L, 3));
649+
intptr_t cpMin = static_cast<intptr_t>(luaL_checkinteger(L, 2));
650+
intptr_t cpMax = static_cast<intptr_t>(luaL_checkinteger(L, 3));
651651

652652
if (cpMax >= 0) {
653653
char *range = host->Range(p, cpMin, cpMax);
@@ -668,24 +668,24 @@ static int cf_pane_textrange(lua_State *L) {
668668

669669
static int cf_pane_insert(lua_State *L) {
670670
NppExtensionAPI::Pane p = check_pane_object(L, 1);
671-
int pos = (int)luaL_checkinteger(L, 2);
671+
intptr_t pos = static_cast<intptr_t>(luaL_checkinteger(L, 2));
672672
const char *s = luaL_checkstring(L, 3);
673673
host->Insert(p, pos, s);
674674
return 0;
675675
}
676676

677677
static int cf_pane_remove(lua_State *L) {
678678
NppExtensionAPI::Pane p = check_pane_object(L, 1);
679-
int cpMin = static_cast<int>(luaL_checkinteger(L, 2));
680-
int cpMax = static_cast<int>(luaL_checkinteger(L, 3));
679+
intptr_t cpMin = static_cast<intptr_t>(luaL_checkinteger(L, 2));
680+
intptr_t cpMax = static_cast<intptr_t>(luaL_checkinteger(L, 3));
681681
host->Remove(p, cpMin, cpMax);
682682
return 0;
683683
}
684684

685685
static int cf_pane_append(lua_State *L) {
686686
NppExtensionAPI::Pane p = check_pane_object(L, 1);
687687
const char *s = luaL_checkstring(L, 2);
688-
host->Insert(p, static_cast<int>(host->Send(p, SCI_GETLENGTH, 0, 0)), s);
688+
host->Insert(p, host->Send(p, SCI_GETLENGTH, 0, 0), s);
689689
return 0;
690690
}
691691

@@ -719,17 +719,17 @@ static int cf_pane_findtext(lua_State *L) {
719719

720720
if (!hasError) {
721721
if (nArgs > 3) {
722-
ft.chrg.cpMin = static_cast<int>(luaL_checkinteger(L, 4));
722+
ft.chrg.cpMin = static_cast<intptr_t>(luaL_checkinteger(L, 4));
723723
hasError = (lua_gettop(L) > nArgs);
724724
}
725725
}
726726

727727
if (!hasError) {
728728
if (nArgs > 4) {
729-
ft.chrg.cpMax = static_cast<int>(luaL_checkinteger(L, 5));
729+
ft.chrg.cpMax = static_cast<intptr_t>(luaL_checkinteger(L, 5));
730730
hasError = (lua_gettop(L) > nArgs);
731731
} else {
732-
ft.chrg.cpMax = static_cast<long>(host->Send(p, SCI_GETLENGTH, 0, 0));
732+
ft.chrg.cpMax = host->Send(p, SCI_GETLENGTH, 0, 0);
733733
}
734734
}
735735

@@ -759,10 +759,10 @@ static int cf_pane_findtext(lua_State *L) {
759759

760760
struct PaneMatchObject {
761761
NppExtensionAPI::Pane pane;
762-
int startPos;
763-
int endPos;
762+
intptr_t startPos;
763+
intptr_t endPos;
764764
int flags; // this is really part of the state, but is kept here for convenience
765-
int endPosOrig; // has to do with preventing infinite loop on a 0-length match
765+
intptr_t endPosOrig; // has to do with preventing infinite loop on a 0-length match
766766
};
767767

768768
static int cf_match_replace(lua_State *L) {
@@ -786,7 +786,7 @@ static int cf_match_replace(lua_State *L) {
786786
host->Send(pmo->pane, SCI_SETTARGETSTART, pmo->startPos, 0);
787787
host->Send(pmo->pane, SCI_SETTARGETEND, pmo->endPos, 0);
788788
host->Send(pmo->pane, SCI_REPLACETARGET, lua_rawlen(L, 2), SptrFromString(replacement));
789-
pmo->endPos = static_cast<int>(host->Send(pmo->pane, SCI_GETTARGETEND, 0, 0));
789+
pmo->endPos = host->Send(pmo->pane, SCI_GETTARGETEND, 0, 0);
790790
return 0;
791791
}
792792

@@ -878,7 +878,7 @@ static int cf_pane_match(lua_State *L) {
878878
if (nargs >= 3) {
879879
pmo->flags = (int)luaL_checkinteger(L, 3);
880880
if (nargs >= 4) {
881-
pmo->endPos = pmo->endPosOrig = (int)luaL_checkinteger(L, 4);
881+
pmo->endPos = pmo->endPosOrig = (intptr_t)luaL_checkinteger(L, 4);
882882
if (pmo->endPos < 0) {
883883
raise_error(L, "Invalid argument 3 for <pane>:match. Positive number or zero expected.");
884884
return 0;
@@ -921,7 +921,7 @@ static int cf_pane_match_generator(lua_State *L) {
921921
return 0;
922922
}
923923

924-
int searchPos = pmo->endPos;
924+
intptr_t searchPos = pmo->endPos;
925925
if ((pmo->startPos == pmo->endPosOrig) && (pmo->endPos == pmo->endPosOrig)) {
926926
// prevent infinite loop on zero-length match by stepping forward
927927
searchPos++;
@@ -935,8 +935,8 @@ static int cf_pane_match_generator(lua_State *L) {
935935
if (ft.chrg.cpMax > ft.chrg.cpMin) {
936936
sptr_t result = host->Send(pmo->pane, SCI_FINDTEXT, static_cast<uptr_t>(pmo->flags), SptrFromPointer(&ft));
937937
if (result >= 0) {
938-
pmo->startPos = static_cast<int>(ft.chrgText.cpMin);
939-
pmo->endPos = pmo->endPosOrig = static_cast<int>(ft.chrgText.cpMax);
938+
pmo->startPos = ft.chrgText.cpMin;
939+
pmo->endPos = pmo->endPosOrig = ft.chrgText.cpMax;
940940
lua_pushvalue(L, 2);
941941
return 1;
942942
}
@@ -1921,57 +1921,57 @@ struct StylingContext {
19211921

19221922
void Colourize() {
19231923
intptr_t end = currentPos - 1;
1924-
if (end >= static_cast<int>(endDoc))
1925-
end = static_cast<int>(endDoc)-1;
1924+
if (end >= static_cast<intptr_t>(endDoc))
1925+
end = endDoc - 1;
19261926
styler->ColourTo(end, state);
19271927
}
19281928

19291929
static int Line(lua_State *L) {
19301930
StylingContext *context = Context(L);
1931-
int position = (int)luaL_checkinteger(L, 2);
1931+
intptr_t position = (intptr_t)luaL_checkinteger(L, 2);
19321932
lua_pushinteger(L, context->styler->GetLine(position));
19331933
return 1;
19341934
}
19351935

19361936
static int CharAt(lua_State *L) {
19371937
StylingContext *context = Context(L);
1938-
int position = (int)luaL_checkinteger(L, 2);
1938+
intptr_t position = (intptr_t)luaL_checkinteger(L, 2);
19391939
lua_pushinteger(L, context->styler->SafeGetCharAt(position));
19401940
return 1;
19411941
}
19421942

19431943
static int StyleAt(lua_State *L) {
19441944
StylingContext *context = Context(L);
1945-
int position = (int)luaL_checkinteger(L, 2);
1945+
intptr_t position = (intptr_t)luaL_checkinteger(L, 2);
19461946
lua_pushinteger(L, context->styler->StyleAt(position));
19471947
return 1;
19481948
}
19491949

19501950
static int LevelAt(lua_State *L) {
19511951
StylingContext *context = Context(L);
1952-
int line = (int)luaL_checkinteger(L, 2);
1952+
intptr_t line = (intptr_t)luaL_checkinteger(L, 2);
19531953
lua_pushinteger(L, context->styler->LevelAt(line));
19541954
return 1;
19551955
}
19561956

19571957
static int SetLevelAt(lua_State *L) {
19581958
StylingContext *context = Context(L);
1959-
int line = (int)luaL_checkinteger(L, 2);
1959+
intptr_t line = (intptr_t)luaL_checkinteger(L, 2);
19601960
int level = (int)luaL_checkinteger(L, 3);
19611961
context->styler->SetLevel(line, level);
19621962
return 0;
19631963
}
19641964

19651965
static int LineState(lua_State *L) {
19661966
StylingContext *context = Context(L);
1967-
int line = (int)luaL_checkinteger(L, 2);
1967+
intptr_t line = (intptr_t)luaL_checkinteger(L, 2);
19681968
lua_pushinteger(L, context->styler->GetLineState(line));
19691969
return 1;
19701970
}
19711971

19721972
static int SetLineState(lua_State *L) {
19731973
StylingContext *context = Context(L);
1974-
int line = (int)luaL_checkinteger(L, 2);
1974+
intptr_t line = (intptr_t)luaL_checkinteger(L, 2);
19751975
int stateOfLine = (int)luaL_checkinteger(L, 3);
19761976
context->styler->SetLineState(line, stateOfLine);
19771977
return 0;
@@ -2018,7 +2018,7 @@ struct StylingContext {
20182018
(currentPos >= endPos);
20192019
}
20202020

2021-
void StartStyling(unsigned int startPos_, unsigned int length, int initStyle_) {
2021+
void StartStyling(uintptr_t startPos_, uintptr_t length, int initStyle_) {
20222022
endDoc = styler->Length();
20232023
endPos = startPos_ + length;
20242024
if (endPos == endDoc)
@@ -2049,8 +2049,8 @@ struct StylingContext {
20492049

20502050
static int StartStyling(lua_State *L) {
20512051
StylingContext *context = Context(L);
2052-
unsigned int startPosStyle = (int)luaL_checkinteger(L, 2);
2053-
unsigned int lengthStyle = (int)luaL_checkinteger(L, 3);
2052+
uintptr_t startPosStyle = (uintptr_t)luaL_checkinteger(L, 2);
2053+
uintptr_t lengthStyle = (uintptr_t)luaL_checkinteger(L, 3);
20542054
int initialStyle = (int)luaL_checkinteger(L, 4);
20552055
context->StartStyling(startPosStyle, lengthStyle, initialStyle);
20562056
return 0;

0 commit comments

Comments
 (0)