Skip to content

Commit e1eae39

Browse files
committed
Releases in NppWrapper always needed
In the case of a sync Scintilla callback making N++ calls, the GIL needs to be released before calling N++, otherwise main thread could be sat waiting for the GIL, and can't process normal calls, even if they're just "get" calls. Reported by skrell - https://sourceforge.net/p/npppythonscript/discussion/1188886/thread/55cce926/?limit=25#a167
1 parent ea5dbb4 commit e1eae39

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

PythonScript/src/NotepadPlusWrapper.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,18 +809,22 @@ void NotepadPlusWrapper::activateBufferID(int bufferID)
809809
}
810810
boost::python::str NotepadPlusWrapper::getBufferFilename(int bufferID)
811811
{
812+
GILRelease release;
812813
TCHAR buffer[MAX_PATH];
813814
callNotepad(NPPM_GETFULLPATHFROMBUFFERID, static_cast<WPARAM>(bufferID), reinterpret_cast<LPARAM>(buffer));
814815
std::shared_ptr<char> filename = WcharMbcsConverter::tchar2char(buffer);
816+
release.reacquire();
815817
return boost::python::str(const_cast<const char *>(filename.get()));
816818
}
817819

818820
boost::python::str NotepadPlusWrapper::getCurrentFilename()
819821
{
822+
GILRelease release;
820823
idx_t bufferID = callNotepad(NPPM_GETCURRENTBUFFERID);
821824
TCHAR buffer[MAX_PATH];
822825
callNotepad(NPPM_GETFULLPATHFROMBUFFERID, bufferID, reinterpret_cast<LPARAM>(buffer));
823826
std::shared_ptr<char> filename = WcharMbcsConverter::tchar2char(buffer);
827+
release.reacquire();
824828
return boost::python::str(const_cast<const char *>(filename.get()));
825829
}
826830

@@ -872,7 +876,9 @@ bool NotepadPlusWrapper::runMenuCommand(boost::python::str menuName, boost::pyth
872876
boost::python::str NotepadPlusWrapper::getNppDir()
873877
{
874878
TCHAR buffer[MAX_PATH];
879+
GILRelease release;
875880
::SendMessage(m_nppHandle, NPPM_GETNPPDIRECTORY, MAX_PATH, reinterpret_cast<LPARAM>(buffer));
881+
release.reacquire();
876882
return boost::python::str(const_cast<const char *>(WcharMbcsConverter::tchar2char(buffer).get()));
877883
}
878884

@@ -883,13 +889,16 @@ boost::python::str NotepadPlusWrapper::getCommandLine()
883889

884890
bool NotepadPlusWrapper::allocateSupported()
885891
{
892+
GILRelease release;
886893
return 1 == ::SendMessage(m_nppHandle, NPPM_ALLOCATESUPPORTED, 0, 0);
887894
}
888895

889896
boost::python::object NotepadPlusWrapper::allocateCmdID(int quantity)
890897
{
891898
int startID;
899+
GILRelease release;
892900
bool result = 1 == ::SendMessage(m_nppHandle, NPPM_ALLOCATECMDID, static_cast<WPARAM>(quantity), reinterpret_cast<LPARAM>(&startID));
901+
release.reacquire();
893902
if (result)
894903
{
895904
return boost::python::object(startID);
@@ -903,7 +912,9 @@ boost::python::object NotepadPlusWrapper::allocateCmdID(int quantity)
903912
boost::python::object NotepadPlusWrapper::allocateMarker(int quantity)
904913
{
905914
int startID;
915+
GILRelease release;
906916
bool result = 1 == ::SendMessage(m_nppHandle, NPPM_ALLOCATEMARKER, static_cast<WPARAM>(quantity), reinterpret_cast<LPARAM>(&startID));
917+
release.reacquire();
907918
if (result)
908919
{
909920
return boost::python::object(startID);

0 commit comments

Comments
 (0)