Re: Patch 7.4.2304

2016-09-05 Fir de Conversatie Bram Moolenaar

Ozaki Kiichi wrote:

> Calling timer_stop in timer-callback causes SEGV.
> 
> [repro steps]
> 
> test.vim:
> 
> function! StopTimer1(timer)
>   let g:timer2 = timer_start(50, 'StopTimer2')
>   " avoid bothersome maxfuncdepth error
>   call timer_pause(g:timer1, 1)
>   sleep 100m
> endfunction
> 
> function! StopTimer2(timer)
>   let g:timer3 = timer_start(50, 'StopTimer3')
>   call timer_stop(g:timer1)
> endfunction
> 
> function! StopTimer3(timer)
>   " Do nothing
> endfunction
> 
> function! TimerStart()
>   let g:timer1 = timer_start(50, 'StopTimer1')
>   sleep 100m
> endfunction
> 
> 
> vim -Nu NONE -S test.vim
> 
> :call TimerStart()
> 
> then vim aborts.
> 
> [other problem]
> 
> Vim hangs up when timer is firing frequently.
> 
> test.vim:
> 
> function! TimerStart()
>   call timer_start(0, 'TimerCallback', {'repeat' : -1})
> endfunction
> function! TimerCallback(...)
> endfunction
> 
> 
> vim -Nu NONE -S test.vim
> 
> :call TimerStart()
> 
> then vim hangs up and we can't intercept by Ctrl-C.
> 
> [patch]
> 
> https://gist.github.com/ichizok/d6637a6d368bbf1353a35441c34039a7
> 
> * evalfunc.c patch is not concerned with those problems, this modifies 
> efficiency of timer_start() slightly.

Thanks, nice solution.

-- 
hundred-and-one symptoms of being an internet addict:
173. You keep tracking down the email addresses of all your friends
 (even childhood friends).

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Patch 7.4.2304

2016-09-05 Fir de Conversatie Ozaki Kiichi
[complement]

> then vim hangs up and we can't intercept by Ctrl-C.

Sorry, 'hang up' is incorrect. Vim accepts key input and redraws screen,
but we can't leave from normal mode.

> https://gist.github.com/ichizok/d6637a6d368bbf1353a35441c34039a7

This patch changes:

* add 'tr_firing' variable to timer_S, this indicates timer-callback firing 
state.

* last_timer_id is non-negative value. tr_id == -1 means deleted timer.

* in check_due_timer(), remove while loop in order to fix above problem.

* stop_timer() sets tr_id to -1 when tr_firing is TRUE, and timer is actually 
deleted after its callback has finished.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Patch 7.4.2304

2016-09-04 Fir de Conversatie Ozaki Kiichi
Calling timer_stop in timer-callback causes SEGV.

[repro steps]

test.vim:

function! StopTimer1(timer)
  let g:timer2 = timer_start(50, 'StopTimer2')
  " avoid bothersome maxfuncdepth error
  call timer_pause(g:timer1, 1)
  sleep 100m
endfunction

function! StopTimer2(timer)
  let g:timer3 = timer_start(50, 'StopTimer3')
  call timer_stop(g:timer1)
endfunction

function! StopTimer3(timer)
  " Do nothing
endfunction

function! TimerStart()
  let g:timer1 = timer_start(50, 'StopTimer1')
  sleep 100m
endfunction


vim -Nu NONE -S test.vim

:call TimerStart()

then vim aborts.

[other problem]

Vim hangs up when timer is firing frequently.

test.vim:

function! TimerStart()
  call timer_start(0, 'TimerCallback', {'repeat' : -1})
endfunction
function! TimerCallback(...)
endfunction


vim -Nu NONE -S test.vim

:call TimerStart()

then vim hangs up and we can't intercept by Ctrl-C.

[patch]

https://gist.github.com/ichizok/d6637a6d368bbf1353a35441c34039a7

* evalfunc.c patch is not concerned with those problems, this modifies 
efficiency of timer_start() slightly.

Thank you.
- Ozaki Kiichi

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Patch 7.4.2304

2016-09-01 Fir de Conversatie Bram Moolenaar

Patch 7.4.2304
Problem:In a timer callback the timer itself can't be found or stopped.
(Thinca)
Solution:   Do not remove the timer from the list, remember whether it was
freed.
Files:  src/ex_cmds2.c, src/testdir/test_timers.vim


*** ../vim-7.4.2303/src/ex_cmds2.c  2016-08-29 22:48:12.125106388 +0200
--- src/ex_cmds2.c  2016-09-01 21:09:54.394328936 +0200
***
*** 1090,1095 
--- 1090,1098 
  static timer_T*first_timer = NULL;
  static intlast_timer_id = 0;
  
+ static timer_T*current_timer = NULL;
+ static intfree_current_timer = FALSE;
+ 
  /*
   * Insert a timer in the list of timers.
   */
***
*** 1121,1128 
  static void
  free_timer(timer_T *timer)
  {
! free_callback(timer->tr_callback, timer->tr_partial);
! vim_free(timer);
  }
  
  /*
--- 1124,1136 
  static void
  free_timer(timer_T *timer)
  {
! if (timer == current_timer)
!   free_current_timer = TRUE;
! else
! {
!   free_callback(timer->tr_callback, timer->tr_partial);
!   vim_free(timer);
! }
  }
  
  /*
***
*** 1200,1217 
  # endif
if (this_due <= 1)
{
!   remove_timer(timer);
timer_callback(timer);
did_one = TRUE;
!   if (timer->tr_repeat != 0)
{
profile_setlimit(timer->tr_interval, &timer->tr_due);
if (timer->tr_repeat > 0)
--timer->tr_repeat;
-   insert_timer(timer);
}
else
free_timer(timer);
/* the callback may do anything, start all over */
break;
}
--- 1208,1230 
  # endif
if (this_due <= 1)
{
!   current_timer = timer;
!   free_current_timer = FALSE;
timer_callback(timer);
+   current_timer = NULL;
+ 
did_one = TRUE;
!   if (timer->tr_repeat != 0 && !free_current_timer)
{
profile_setlimit(timer->tr_interval, &timer->tr_due);
if (timer->tr_repeat > 0)
--timer->tr_repeat;
}
else
+   {
free_timer(timer);
+   remove_timer(timer);
+   }
/* the callback may do anything, start all over */
break;
}
*** ../vim-7.4.2303/src/testdir/test_timers.vim 2016-08-28 16:06:01.407721837 
+0200
--- src/testdir/test_timers.vim 2016-09-01 21:26:08.546370746 +0200
***
*** 128,131 
--- 128,146 
endif
  endfunc
  
+ func StopMyself(timer)
+   let g:called += 1
+   if g:called == 2
+ call timer_stop(a:timer)
+   endif
+ endfunc
+ 
+ func Test_delete_myself()
+   let g:called = 0
+   let t = timer_start(10, 'StopMyself', {'repeat': -1})
+   call WaitFor('g:called == 2')
+   call assert_equal(2, g:called)
+   call assert_equal([], timer_info(t))
+ endfunc
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-7.4.2303/src/version.c   2016-09-01 20:58:17.640011363 +0200
--- src/version.c   2016-09-01 21:09:04.010740607 +0200
***
*** 765,766 
--- 765,768 
  {   /* Add new patch number below this line */
+ /**/
+ 2304,
  /**/


-- 
hundred-and-one symptoms of being an internet addict:
127. You bring your laptop and cellular phone to church.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.