From b9ee68b4cb4e1f3ffb36dbf2f7bb6468dcf82716 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 7 Nov 2024 20:11:22 +0000 Subject: [PATCH 1/2] Wipe out scratch buffers Some people are really picky about their buffer numbers and not having unlisted, unloaded buffers in the buffer list. I personally don't care and like the fact that marks and stuff are retained between runs, but I don't care enough to really fight it. This is cleaner afterall. Closes #879 --- python3/vimspector/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index 57cec0cb..a74eb088 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -166,10 +166,9 @@ def CleanUpHiddenBuffer( buf ): return try: - vim.command( 'bdelete! {}'.format( buf.number ) ) + vim.command( 'bwipeout! {}'.format( buf.number ) ) except vim.error as e: - # FIXME: For now just ignore the "no buffers were deleted" error - if 'E516' not in str( e ): + if 'E517' not in str( e ): raise From a3bbebca96ad93ef163cee97d23574048b8604c9 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Thu, 7 Nov 2024 21:51:31 +0000 Subject: [PATCH 2/2] Fix referring to deleted buffer, by deleting it The comment explains, badly, that there is a bug somewhere that when we wipe out the disassembly buffers, we end up with: || Caught exception in Test_Disassembly_Open_Close(): Vim(py3):vim.error: Vim(py3):vim.error: attempt to refer to deleted buffer But I can't work out why exactly. Wiping out the buffer causes this, but deleting the buffer doesn't. --- python3/vimspector/debug_session.py | 2 +- python3/vimspector/disassembly.py | 13 ++++++++++++- python3/vimspector/utils.py | 8 +++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 941a5f4c..aa05f6fe 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -552,7 +552,7 @@ def SwitchFrom( self ): def OnChannelData( self, data ): if self._connection is None: - # Should _not_ happen, but maybe possible due to races or vim bufs? + # Should _not_ happen, but maybe possible due to races or vim bugs? return self._connection.OnData( data ) diff --git a/python3/vimspector/disassembly.py b/python3/vimspector/disassembly.py index 101258ed..15d9a2ec 100644 --- a/python3/vimspector/disassembly.py +++ b/python3/vimspector/disassembly.py @@ -173,7 +173,18 @@ def Reset( self ): self._buf = None for b in self._scratch_buffers: - utils.CleanUpHiddenBuffer( b ) + # FIXME/TODO: Unknown hack :( + # For some reason I can't work out if the buffer is wiped out here, we + # get a test failure in Test_Disassembly_Open_Close. + # Initially I thought it was because _scratch_buffers might contain + # duplicates, but changing it to a set() doesn't help, so it's not that. + # What seems to happen is we get data on the socket/channel and the + # callback tries to do something with the wiped-out buffer. + # + # Unfortunately I can't fathom what's happening, so hacking this + # wipeout=False for now to make the tests pass. Yes, I'll suffer in + # purgatory for that. + utils.CleanUpHiddenBuffer( b, wipeout=False ) self._scratch_buffers = [] diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index a74eb088..e846d306 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -161,14 +161,16 @@ def CleanUpCommand( session_id, name, api_prefix ): name ) ) -def CleanUpHiddenBuffer( buf ): +def CleanUpHiddenBuffer( buf, wipeout=True ): if not buf.valid: return + cmd = 'bwipeout' if wipeout else 'bdelete' + try: - vim.command( 'bwipeout! {}'.format( buf.number ) ) + vim.command( '{}! {}'.format( cmd, buf.number ) ) except vim.error as e: - if 'E517' not in str( e ): + if 'E517' not in str( e ) and 'E516' not in str( e ): raise