Skip to content

Commit 9f8911a

Browse files
committed
Release the GIL if necessary before calling Replace in main thread
Needed if (re)replace called in N++ callback
1 parent e1eae39 commit 9f8911a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

PythonScript/python_tests/tests/ScintillaCallbackTestCase.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ def callback_sync_disallowed_notepad_method(self, args):
208208
with self.assertRaisesRegexp(RuntimeError, "not allowed in a synchronous"):
209209
scintilla = notepad.createScintilla()
210210

211+
def test_callback_with_replace(self):
212+
editor.callback(lambda a: self.callback_with_replace(a), [SCINTILLANOTIFICATION.MODIFIED])
213+
editor.write('hello world')
214+
self.poll_for_callback()
215+
text = editor.getText()
216+
self.assertEqual(text, 'hello CHEESE')
217+
218+
def callback_with_replace(self, args):
219+
if args['modificationType'] & MODIFICATIONFLAGS.INSERTTEXT:
220+
editor.rereplace('wo[a-z]{3}', 'CHEESE')
221+
self.callbackCalled = True
222+
223+
211224
def poll_for_callback(self, timeout = 0.5, interval = 0.1):
212225
while self.callbackCalled == False and timeout > 0:
213226
time.sleep(interval)

PythonScript/src/ScintillaWrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ void ScintillaWrapper::replaceImpl(boost::python::object searchStr, boost::pytho
864864
TCHAR pluginName[] = _T("PythonScript.dll");
865865

866866
commInfo.info = reinterpret_cast<void*>(&replacementContainer);
867+
GILRelease release;
867868
::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast<WPARAM>(pluginName), reinterpret_cast<LPARAM>(&commInfo));
868869

869870
EndUndoAction();

0 commit comments

Comments
 (0)