Mercurial > vim
comparison src/if_py_both.h @ 10751:27b42717662b v8.0.0265
patch 8.0.0265: may get ml_get error when :pydo deletes lines
commit https://github.com/vim/vim/commit/a58883b4ea0bbb813fd4dd7eb49dd6f03e3e5387
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 29 21:31:09 2017 +0100
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Problem: May get ml_get error when :pydo deletes lines or switches to
another buffer. (Nikolai Pavlov, issue https://github.com/vim/vim/issues/1421)
Solution: Check the buffer and line every time.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 29 Jan 2017 21:45:04 +0100 |
parents | 45098d7f72b6 |
children | e05695e59f6d |
comparison
equal
deleted
inserted
replaced
10750:bc18332a39a1 | 10751:27b42717662b |
---|---|
5617 size_t len; | 5617 size_t len; |
5618 char *code; | 5618 char *code; |
5619 int status; | 5619 int status; |
5620 PyObject *pyfunc, *pymain; | 5620 PyObject *pyfunc, *pymain; |
5621 PyObject *run_ret; | 5621 PyObject *run_ret; |
5622 buf_T *was_curbuf = curbuf; | |
5622 | 5623 |
5623 if (u_save((linenr_T)RangeStart - 1, (linenr_T)RangeEnd + 1) != OK) | 5624 if (u_save((linenr_T)RangeStart - 1, (linenr_T)RangeEnd + 1) != OK) |
5624 { | 5625 { |
5625 EMSG(_("cannot save undo information")); | 5626 EMSG(_("cannot save undo information")); |
5626 return; | 5627 return; |
5669 PyObject *ret; | 5670 PyObject *ret; |
5670 | 5671 |
5671 #ifdef PY_CAN_RECURSE | 5672 #ifdef PY_CAN_RECURSE |
5672 *pygilstate = PyGILState_Ensure(); | 5673 *pygilstate = PyGILState_Ensure(); |
5673 #endif | 5674 #endif |
5674 if (!(line = GetBufferLine(curbuf, lnum))) | 5675 /* Check the line number, the command my have deleted lines. */ |
5676 if (lnum > curbuf->b_ml.ml_line_count | |
5677 || !(line = GetBufferLine(curbuf, lnum))) | |
5675 goto err; | 5678 goto err; |
5676 if (!(linenr = PyInt_FromLong((long) lnum))) | 5679 if (!(linenr = PyInt_FromLong((long) lnum))) |
5677 { | 5680 { |
5678 Py_DECREF(line); | 5681 Py_DECREF(line); |
5679 goto err; | 5682 goto err; |
5682 Py_DECREF(line); | 5685 Py_DECREF(line); |
5683 Py_DECREF(linenr); | 5686 Py_DECREF(linenr); |
5684 if (!ret) | 5687 if (!ret) |
5685 goto err; | 5688 goto err; |
5686 | 5689 |
5690 /* Check that the command didn't switch to another buffer. */ | |
5691 if (curbuf != was_curbuf) | |
5692 { | |
5693 Py_XDECREF(ret); | |
5694 goto err; | |
5695 } | |
5696 | |
5687 if (ret != Py_None) | 5697 if (ret != Py_None) |
5688 if (SetBufferLine(curbuf, lnum, ret, NULL) == FAIL) | 5698 if (SetBufferLine(curbuf, lnum, ret, NULL) == FAIL) |
5699 { | |
5700 Py_XDECREF(ret); | |
5689 goto err; | 5701 goto err; |
5702 } | |
5690 | 5703 |
5691 Py_XDECREF(ret); | 5704 Py_XDECREF(ret); |
5692 PythonIO_Flush(); | 5705 PythonIO_Flush(); |
5693 #ifdef PY_CAN_RECURSE | 5706 #ifdef PY_CAN_RECURSE |
5694 PyGILState_Release(*pygilstate); | 5707 PyGILState_Release(*pygilstate); |