Skip to content

Commit

Permalink
More fixes for NPP 8.3.3 plugin API compatibility
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cmagnush committed Mar 27, 2022
1 parent b39e09f commit 191fd22
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/LuaConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void LuaConsole::showAutoCompletion() {

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

if (prevCh == '.' || prevCh == ':') {
Expand Down
8 changes: 4 additions & 4 deletions src/NppExtensionAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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<LPARAM>(s));
}

Expand Down
6 changes: 3 additions & 3 deletions src/NppExtensionAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/SciTE/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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);
Expand Down
58 changes: 29 additions & 29 deletions src/SciTE/LuaExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(luaL_checkinteger(L, 2));
int cpMax = static_cast<int>(luaL_checkinteger(L, 3));
intptr_t cpMin = static_cast<intptr_t>(luaL_checkinteger(L, 2));
intptr_t cpMax = static_cast<intptr_t>(luaL_checkinteger(L, 3));

if (cpMax >= 0) {
char *range = host->Range(p, cpMin, cpMax);
Expand All @@ -668,24 +668,24 @@ 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<intptr_t>(luaL_checkinteger(L, 2));
const char *s = luaL_checkstring(L, 3);
host->Insert(p, pos, s);
return 0;
}

static int cf_pane_remove(lua_State *L) {
NppExtensionAPI::Pane p = check_pane_object(L, 1);
int cpMin = static_cast<int>(luaL_checkinteger(L, 2));
int cpMax = static_cast<int>(luaL_checkinteger(L, 3));
intptr_t cpMin = static_cast<intptr_t>(luaL_checkinteger(L, 2));
intptr_t cpMax = static_cast<intptr_t>(luaL_checkinteger(L, 3));
host->Remove(p, cpMin, cpMax);
return 0;
}

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<int>(host->Send(p, SCI_GETLENGTH, 0, 0)), s);
host->Insert(p, host->Send(p, SCI_GETLENGTH, 0, 0), s);
return 0;
}

Expand Down Expand Up @@ -719,17 +719,17 @@ static int cf_pane_findtext(lua_State *L) {

if (!hasError) {
if (nArgs > 3) {
ft.chrg.cpMin = static_cast<int>(luaL_checkinteger(L, 4));
ft.chrg.cpMin = static_cast<intptr_t>(luaL_checkinteger(L, 4));
hasError = (lua_gettop(L) > nArgs);
}
}

if (!hasError) {
if (nArgs > 4) {
ft.chrg.cpMax = static_cast<int>(luaL_checkinteger(L, 5));
ft.chrg.cpMax = static_cast<intptr_t>(luaL_checkinteger(L, 5));
hasError = (lua_gettop(L) > nArgs);
} else {
ft.chrg.cpMax = static_cast<long>(host->Send(p, SCI_GETLENGTH, 0, 0));
ft.chrg.cpMax = host->Send(p, SCI_GETLENGTH, 0, 0);
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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<int>(host->Send(pmo->pane, SCI_GETTARGETEND, 0, 0));
pmo->endPos = host->Send(pmo->pane, SCI_GETTARGETEND, 0, 0);
return 0;
}

Expand Down Expand Up @@ -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 <pane>:match. Positive number or zero expected.");
return 0;
Expand Down Expand Up @@ -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++;
Expand All @@ -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<uptr_t>(pmo->flags), SptrFromPointer(&ft));
if (result >= 0) {
pmo->startPos = static_cast<int>(ft.chrgText.cpMin);
pmo->endPos = pmo->endPosOrig = static_cast<int>(ft.chrgText.cpMax);
pmo->startPos = ft.chrgText.cpMin;
pmo->endPos = pmo->endPosOrig = ft.chrgText.cpMax;
lua_pushvalue(L, 2);
return 1;
}
Expand Down Expand Up @@ -1921,57 +1921,57 @@ struct StylingContext {

void Colourize() {
intptr_t end = currentPos - 1;
if (end >= static_cast<int>(endDoc))
end = static_cast<int>(endDoc)-1;
if (end >= static_cast<intptr_t>(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;
}

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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 191fd22

Please sign in to comment.