0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.0.0698: crash on exit when using Python function in timer.

Problem:    When a timer uses ":pyeval" or another Python command and it
            happens to be triggered while exiting a Crash may happen.
            (Ricky Zhou)
Solution:   Avoid running a Python command after python_end() was called.
            Do not trigger timers while exiting.  (closes #1824)
This commit is contained in:
Bram Moolenaar 2017-07-07 14:50:44 +02:00
parent 8858498516
commit c4f833808a
4 changed files with 17 additions and 2 deletions

View File

@ -1183,6 +1183,7 @@ timer_callback(timer_T *timer)
/* /*
* Call timers that are due. * Call timers that are due.
* Return the time in msec until the next timer is due. * Return the time in msec until the next timer is due.
* Returns -1 if there are no pending timers.
*/ */
long long
check_due_timer(void) check_due_timer(void)
@ -1197,6 +1198,10 @@ check_due_timer(void)
# ifdef WIN3264 # ifdef WIN3264
LARGE_INTEGER fr; LARGE_INTEGER fr;
/* Don't run any timers while exiting. */
if (exiting)
return next_due;
QueryPerformanceFrequency(&fr); QueryPerformanceFrequency(&fr);
# endif # endif
profile_start(&now); profile_start(&now);

View File

@ -779,6 +779,7 @@ get_exceptions(void)
static int initialised = 0; static int initialised = 0;
#define PYINITIALISED initialised #define PYINITIALISED initialised
static int python_end_called = FALSE;
#define DESTRUCTOR_FINISH(self) self->ob_type->tp_free((PyObject*)self); #define DESTRUCTOR_FINISH(self) self->ob_type->tp_free((PyObject*)self);
@ -878,6 +879,7 @@ python_end(void)
if (recurse != 0) if (recurse != 0)
return; return;
python_end_called = TRUE;
++recurse; ++recurse;
#ifdef DYNAMIC_PYTHON #ifdef DYNAMIC_PYTHON
@ -1040,6 +1042,8 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
} }
++recursive; ++recursive;
#endif #endif
if (python_end_called)
return;
#if defined(MACOS) && !defined(MACOS_X_UNIX) #if defined(MACOS) && !defined(MACOS_X_UNIX)
GetPort(&oldPort); GetPort(&oldPort);
@ -1568,7 +1572,7 @@ do_pyeval (char_u *str, typval_T *rettv)
(rangeinitializer) init_range_eval, (rangeinitializer) init_range_eval,
(runner) run_eval, (runner) run_eval,
(void *) rettv); (void *) rettv);
switch(rettv->v_type) switch (rettv->v_type)
{ {
case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break; case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break;
case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break; case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break;

View File

@ -733,8 +733,8 @@ get_py3_exceptions(void)
#endif /* DYNAMIC_PYTHON3 */ #endif /* DYNAMIC_PYTHON3 */
static int py3initialised = 0; static int py3initialised = 0;
#define PYINITIALISED py3initialised #define PYINITIALISED py3initialised
static int python_end_called = FALSE;
#define DESTRUCTOR_FINISH(self) Py_TYPE(self)->tp_free((PyObject*)self) #define DESTRUCTOR_FINISH(self) Py_TYPE(self)->tp_free((PyObject*)self)
@ -817,6 +817,7 @@ python3_end(void)
if (recurse != 0) if (recurse != 0)
return; return;
python_end_called = TRUE;
++recurse; ++recurse;
#ifdef DYNAMIC_PYTHON3 #ifdef DYNAMIC_PYTHON3
@ -938,6 +939,9 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
PyObject *cmdbytes; PyObject *cmdbytes;
PyGILState_STATE pygilstate; PyGILState_STATE pygilstate;
if (python_end_called)
goto theend;
#if defined(MACOS) && !defined(MACOS_X_UNIX) #if defined(MACOS) && !defined(MACOS_X_UNIX)
GetPort(&oldPort); GetPort(&oldPort);
/* Check if the Python library is available */ /* Check if the Python library is available */

View File

@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
698,
/**/ /**/
697, 697,
/**/ /**/